-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
rebase-gh-5237 - BUG: Workaround segfault in Apple Accelerate framework SGEMV #5831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
SGEMV in Accelerate framework will segfault on MacOS X version 10.9 (aka Mavericks) if arrays are not aligned to 32 byte boundaries and the CPU supports AVX instructions. This can produce segfaults in np.dot. This patch overshadows the symbols cblas_sgemv, sgemv_ and sgemv exported by Accelerate to produce the correct behavior. The MacOS X version and CPU specs are checked on module import. If Mavericks and AVX are detected the call to SGEMV is emulated with a call to SGEMM if the arrays are not 32 byte aligned. If the exported symbols cannot be overshadowed on module import, a fatal error is produced and the process aborts. All the fixes are in a self-contained C file and do not alter the multiarray C code. The patch is not applied unless NumPy is configured to link with Apple's Accelerate framework.
@matthew-brett Could you test this to see if it works on OS X 10.9? |
Compiles, links to Accelerate, tests pass. Test from #4007
runs OK. |
Looks ok to me (on OSX 10.9 with Python 3.4). Accelerate is used by default when no BLAS/LAPACK is specified. |
Thanks Matthew and Sturla. I'll put this in now. One more step towards 1.10.0. |
rebase-gh-5237 - BUG: Workaround segfault in Apple Accelerate framework SGEMV
@rgommers Note that this isn't part of the bento build. Not sure how to add that. |
SciPy has the same issue with the Bento build as well. Currently the fix is not used when building with Bento. Bento has a static list of files to build, but here we have to conditionally add a file to the build depending on the OS and the BLAS library. I am sorry I don't know how to do this with Bento either. |
No worries, I'll have a look. Note that the |
Hm, the fix should perhaps/probably also be added to the https://github.com/numpy/numpy/blob/master/numpy/linalg/setup.py |
|
Bento build updated in gh-5836. Didn't touch |
BLD: use fix for Accelerate SGEMV issue in Bento build. See gh-5831.
Hmm, I didn't even think of the |
I'm not sure. Obviously numpy.linalg can call Fortran sgemv internally in LAPACK and segfault. But if we overshadow sgemv, which sgemv will then be called from within the framework? It might not be a fixable issue, so we should perhaps just leave it and hope that OSX 10.9 is abandoned before it becomes a problem. |
Rebased #5237.
SGEMV in Accelerate framework will segfault on MacOS X version 10.9
(aka Mavericks) if arrays are not aligned to 32 byte boundaries and the
CPU supports AVX instructions. This can produce segfaults in np.dot.
This patch overshadows the symbols cblas_sgemv, sgemv_ and sgemv
exported by Accelerate to produce the correct behavior. The MacOS X
version and CPU specs are checked on module import. If Mavericks and AVX
are detected the call to SGEMV is emulated with a call to SGEMM if the
arrays are not 32 byte aligned. If the exported symbols cannot be
overshadowed on module import, a fatal error is produced and the process
aborts. All the fixes are in a self-contained C file and do not alter
the multiarray C code. The patch is not applied unless NumPy is
configured to link with Apple's Accelerate framework.