You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenBLAS can now be built for Apple chips using the port at https://github.com/iains/gcc-darwin-arm64.
The build succeeds and seems to run fine, so it might be time to think about tuning for this microarchitecture.
If anybody is interested in working on this issue, I can probably facilitate hardware access.
There is no specific code for Apple's desktop-to-be processor over there. As far as internets tell - there is ISA profile present already.
Instruction set A64 – ARMv8.4-A
There is no specific support for big.LITTLE configuration, apple or no apples.
If you find apple's accelerate framework outperforming openblas, describe regression here, as usual. As hardware becomes available more people will actually use it and report what they find unfair.
Does sysctl -n machdep.cpu.brand_string (as search engines tell me) return anything usable for identification ? (For #2804,I just made the code return ARMV8 by default). If it does, we could start with giving it its unique TARGET (which would allow assigning appropriate compiler options). Next trivial step could be to repurpose the ThunderX2T99 kernels (as they should be the most advanced we have right now) and see how they fare compared to generic ARMV8 or CortexA57.
Apple's M1 appears to offer Intel AMX-like capabilities accessed via an arm64 ISA extension. This extension is in use by Apple's own Accelerate framework. Prototype code for using these matrix intrinsics may be found here: https://gist.github.com/dougallj/7a75a3be1ec69ca550e7c36dc75e0d6f
Uh thanks, a deep link into a gist that looks as if it was supposed to be private, and has comments about being reverse-engineered from Apple's intellectual property ? I am not sure I would want to go there, least of all when nobody has even attempted to make proper use of what is openly available e.g. through benchmarking.
Uh thanks, a deep link into a gist that looks as if it was supposed to be private, and has comments about being reverse-engineered from Apple's intellectual property ? I am not sure I would want to go there, least of all when nobody has even attempted to make proper use of what is openly available e.g. through benchmarking.
@brada4 as I understand it Rosetta is more like a runtime x86 emulation environment to make x86 binaries run at all - I do not see how this would provide any insight compared to benchmarking the existing ARMV8 (and potentially thunderx2) kernels and working from there.
One trivial change to try (if you can spare the time) would be to edit kernel/arm64/KERNEL.VORTEX so that it includes either KERNEL.NEOVERSEN1 or KERNEL.THUNDERX3T110 instead of the more generic KERNEL.ARMV8 .
This is just a stab in the dark though - no guarantees that this will actually make OpenBLAS faster, just that it would then use more recent BLAS kernels for server-class cpus rather than a smallest common denominator capable of running on old phones.
right, @danielchalef can you move that line mach_timebase_info(&info); into the getsec() function immediately after the #elif defined(__APPLE__) there, please ?
The tests compiled. However, the math now appears off: dgemm.goto
@fxcoudert from pocoproject/poco#1453 apparently clock_gettime was added in OSX 10.12 but the presence of _POSIX_TIMERS may depend on the minimum SDK version setting at compile time (?) Anyway we'd probably want this to work with OSX < 10.12
dgemm results on a MacBook Pro M1. OpenBLAS compiled with Xcode / clang version 12.0.0. The test was run 10 times with the first run discarded. OPENBLAS_LOOPS was set to 20 in order to avoid the underflow discussed above.
OpenBLAS (with VORTEX/ ARMV8 kernel) vs Veclib
OpenBLAS VORTEX/ ARMV8 vs NEOVERSEN1 vs THUNDERX3T110 kernels (all on the M1):
A little difficult to see given the similarity in results and scale. See charts below for some interesting matrix dimension results.
to;dr Veclib significantly outperforms OpenBLAS, likely as it is using native, hardware-based matrix multiplication acceleration. The NEOVERSEN1 kernel appears to offer better results for the M1 than the default ARMV8 kernel.
In float64, OpenBLAS VORTEX is not too bad. But for float32 Accelerate/vecLib is really impressive (~2.6x faster).
I also noticed that OpenBLAS / OpenMP detects 8 cores on Apple M1 (it has 4 performance cores and 4 efficiency cores) but apparently I get better performance by setting OMP_NUM_THREADS=4. So I suspect a bit of oversubscription when using the "efficiency cores". Maybe they do not support the vortex instructions?
I can open a dedicated issue for the oversubscription problem.
Edit: a first version of this post / bench results used OPENBLAS_NUM_THREADS=4 instead of OMP_NUM_THREADS=4. Only the latter works with the openblas build from conda-forge. I fixed the numbers accordingly.
Command I used to introspect the number of cores actually used:
Numpy is fine with Apple's cblas.h + Accelerate alone
I am not sure I understand. Here I used this setup to get numpy to use Accelerate for BLAS calls and netlib for LAPACK calls. This is using isuruf/vecLibFort.
Please try with bigger data sets, 4/8MB is crumbles for modern CoD CPUs or multi-socket ones. Probably fits in M1 cache so that BLAS L1 is faster than any RAM chip made so far.
Good remark, here are the GEMM results with m, n, k = 4096:
I'd let big boys play and wait for R to ship official release where user can switch between default Accelerate and NetLib BLAS, then sneak OpenBLAS in place of NetLib one.
It is hard to impossible to believe that much touted extra piece of silicon meant for matrix acceleration turns out such a flop.
Activity
brada4 commentedon Sep 2, 2020
There is no specific code for Apple's desktop-to-be processor over there. As far as internets tell - there is ISA profile present already.
There is no specific support for big.LITTLE configuration, apple or no apples.
If you find apple's accelerate framework outperforming openblas, describe regression here, as usual. As hardware becomes available more people will actually use it and report what they find unfair.
Keno commentedon Sep 2, 2020
Well, that is why I said microarchitectural tuning, not architectural tuning ;) Accelerate will obviously be a good point of comparison.
martin-frbg commentedon Sep 2, 2020
Does
sysctl -n machdep.cpu.brand_string(as search engines tell me) return anything usable for identification ? (For #2804,I just made the code return ARMV8 by default). If it does, we could start with giving it its unique TARGET (which would allow assigning appropriate compiler options). Next trivial step could be to repurpose the ThunderX2T99 kernels (as they should be the most advanced we have right now) and see how they fare compared to generic ARMV8 or CortexA57.Keno commentedon Sep 2, 2020
feature detection is in the
hwsysctl though:martin-frbg commentedon Sep 2, 2020
Thanks for the data, rough first draft is in #2816
danielchalef commentedon Dec 28, 2020
Apple's M1 appears to offer Intel AMX-like capabilities accessed via an arm64 ISA extension. This extension is in use by Apple's own Accelerate framework. Prototype code for using these matrix intrinsics may be found here: https://gist.github.com/dougallj/7a75a3be1ec69ca550e7c36dc75e0d6f
brada4 commentedon Dec 28, 2020
Thats not prototype code, nor intrimsic header of sorts, that is an earlu attempt to document an undocumented co-processor.
martin-frbg commentedon Dec 28, 2020
Uh thanks, a deep link into a gist that looks as if it was supposed to be private, and has comments about being reverse-engineered from Apple's intellectual property ? I am not sure I would want to go there, least of all when nobody has even attempted to make proper use of what is openly available e.g. through benchmarking.
danielchalef commentedon Dec 28, 2020
Ulp. You're right. I scanned the gist too quickly. That's not prototype code, rather a documentation effort.
danielchalef commentedon Dec 28, 2020
Fair enough regarding the IP concern.
brada4 commentedon Dec 29, 2020
If anyone could benchmark rosetta2 roughly and tell what works best from x86 world https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616843
martin-frbg commentedon Dec 29, 2020
@brada4 as I understand it Rosetta is more like a runtime x86 emulation environment to make x86 binaries run at all - I do not see how this would provide any insight compared to benchmarking the existing ARMV8 (and potentially thunderx2) kernels and working from there.
brada4 commentedon Dec 29, 2020
That emulated x86 will be around for 3-5 years (looking at "smooth" ppc to x86 transition years ago)
dengemann commentedon Dec 30, 2020
Hello everyone, I had some fun the past days benchmarking R and Python, lately also compiled with openblas. See threads here https://twitter.com/dngman/status/1342580260815200257?s=20 and https://twitter.com/fxcoudert/status/1342598509418176514?s=20
If there is anything that I can do to accelerate this effort e.g. with testing etc. please let me know.
martin-frbg commentedon Dec 30, 2020
One trivial change to try (if you can spare the time) would be to edit
kernel/arm64/KERNEL.VORTEXso that it includes either KERNEL.NEOVERSEN1 or KERNEL.THUNDERX3T110 instead of the more generic KERNEL.ARMV8 .This is just a stab in the dark though - no guarantees that this will actually make OpenBLAS faster, just that it would then use more recent BLAS kernels for server-class cpus rather than a smallest common denominator capable of running on old phones.
9 remaining items
fxcoudert commentedon Dec 30, 2020
CLOCK_REALTIMEshould be available, though, with microsecond resolution:Why it doesn't define
_POSIX_TIMERSis beyond me…danielchalef commentedon Dec 30, 2020
The tests compiled. However, the math now appears off:
dgemm.gotomartin-frbg commentedon Dec 30, 2020
Off by only 1e9 probably (reporting nanoseconds instead of seconds), though something else seems to affect the very first call.
danielchalef commentedon Dec 30, 2020
@martin-frbg Your suggestion to set
OPENBLAS_LOOPSto a larger number works. I'll uploaddgemmresults later today.martin-frbg commentedon Dec 30, 2020
@fxcoudert from pocoproject/poco#1453 apparently clock_gettime was added in OSX 10.12 but the presence of _POSIX_TIMERS may depend on the minimum SDK version setting at compile time (?) Anyway we'd probably want this to work with OSX < 10.12
danielchalef commentedon Dec 30, 2020
dgemm results on a MacBook Pro M1. OpenBLAS compiled with Xcode / clang version 12.0.0. The test was run 10 times with the first run discarded.
OPENBLAS_LOOPSwas set to 20 in order to avoid the underflow discussed above.OpenBLAS (with VORTEX/ ARMV8 kernel) vs Veclib
OpenBLAS VORTEX/ ARMV8 vs NEOVERSEN1 vs THUNDERX3T110 kernels (all on the M1):
A little difficult to see given the similarity in results and scale. See charts below for some interesting matrix dimension results.
to;dr Veclib significantly outperforms OpenBLAS, likely as it is using native, hardware-based matrix multiplication acceleration. The NEOVERSEN1 kernel appears to offer better results for the M1 than the default ARMV8 kernel.
xianyi commentedon Dec 31, 2020
Does anybody work on optimizing gemm on M1? Actually, I have the interest on it.
ogrisel commentedon Feb 1, 2021
I also ran some quick benchmarks in the context of the numpy / scipy stack. Here are the results:
https://gist.github.com/ogrisel/87dcf2c3ab8a304ededf75934b116b61#gistcomment-3614885
In float64, OpenBLAS VORTEX is not too bad. But for float32 Accelerate/vecLib is really impressive (~2.6x faster).
I also noticed that OpenBLAS / OpenMP detects 8 cores on Apple M1 (it has 4 performance cores and 4 efficiency cores) but apparently I get better performance by setting
OMP_NUM_THREADS=4. So I suspect a bit of oversubscription when using the "efficiency cores". Maybe they do not support the vortex instructions?I can open a dedicated issue for the oversubscription problem.
Edit: a first version of this post / bench results used
OPENBLAS_NUM_THREADS=4instead ofOMP_NUM_THREADS=4. Only the latter works with the openblas build from conda-forge. I fixed the numbers accordingly.Command I used to introspect the number of cores actually used:
brada4 commentedon Feb 1, 2021
Something is not right. Numpy is fine with Apple's
cblas.h+ Accelerate alone , and same netlib SVD is used in both cases (-O2 desirable).It is rumoured/known that Apple uses proprietary co-processor in M1 Accelerate than no other can reach. It should be much better at either GEMM.
ogrisel commentedon Feb 1, 2021
I am not sure I understand. Here I used this setup to get numpy to use Accelerate for BLAS calls and netlib for LAPACK calls. This is using isuruf/vecLibFort.
brada4 commentedon Feb 1, 2021
R is a bit more evolved towards supporting your laptop:
https://developer.r-project.org/Blog/public/2020/11/02/will-r-work-on-apple-silicon/index.html
Please try with bigger data sets, 4/8MB is crumbles for modern CoD CPUs or multi-socket ones. Probably fits in M1 cache so that BLAS L1 is faster than any RAM chip made so far.
brada4 commentedon Feb 1, 2021
Would be interesting (in short, like 2 years term) to select optimal core type for rosetta, no AVX supported, like 5 remaining.
ogrisel commentedon Feb 2, 2021
Good remark, here are the GEMM results with m, n, k = 4096:
OpenBLAS (4 threads)
OpenBLAS (8 threads)
Accelerate / vecLib
Comments:
brada4 commentedon Feb 2, 2021
I'd let big boys play and wait for R to ship official release where user can switch between default Accelerate and NetLib BLAS, then sneak OpenBLAS in place of NetLib one.
It is hard to impossible to believe that much touted extra piece of silicon meant for matrix acceleration turns out such a flop.