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
{{ message }}
Repository navigation
import numpy crashes at xgetbv instruction in npy_cpu_supports on a VM #15342
Hi, I run the MacPorts automated build system and we have been experiencing an issue for awhile where import numpy causes Python to crash. I don't know if this happens for any users running macOS directly on their Macs but it does happen on one of our build machines—the one running macOS Sierra 10.12. The other build machines (which run earlier and later macOS versions) don't experience the problem. All the build machines are virtual machines running under VMware ESXi 6 on 2009-model Xserves.
I believe this is similar to or the same as #13059 but in case it's not I didn't want to mix up my information in that issue. In that issue, @eric-wieser speculated that HAVE_XGETBV is being set incorrectly. As my lldb trace below shows, we are crashing at the xgetbv instruction.
@seberg asked in #13059 if the problem was the VM claiming to support AVX when it does not. I have used the sample program posted by @ulido in #10330 to check whether the machine claims to have avx support (using __builtin_cpu_supports("avx")). In my case here in this macOS 10.12 VM, the sample program says "AVX not supported!"
Reproducing code example:
importnumpy
Error message:
I am sorry, I am not familiar with gdb, but here's what happens under lldb:
Process 3114 resuming
Python 3.7.6 (default, Jan 17 2020, 18:32:15)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Process 3114 stopped
* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x000000010391c691 _multiarray_umath.cpython-37m-darwin.so`npy_cpu_supports + 118
_multiarray_umath.cpython-37m-darwin.so`npy_cpu_supports:
-> 0x10391c691 <+118>: xgetbv
0x10391c694 <+121>: andl $0x76, %eax
0x10391c697 <+124>: movl $0x76, %ecx
0x10391c69c <+129>: jmp 0x10391c6dc ; <+193>
Target 0: (Python) stopped.
Numpy/Python version information:
Python 3.7.6
Numpy 1.18.1
macOS 10.12.6 Build version 16G2136
Xcode 9.2 Build version 9C40b
Apple LLVM version 9.0.0 (clang-900.0.39.2)
While trying to learn more about this problem, I found a bug report at another project where there was a crash at xgetbv on a machine that had avx support disabled. The fix there was to check that the CPUID.1:ECX.OSXSAVE bit is set first. I wasn't sure if something like that might be applicable for numpy too.
Note: It is unwise for an application to rely exclusively on CPUID.1:ECX.AVX[bit 28]
or at all on CPUID.1:ECX.XSAVE[bit 26]: These indicate hardware support but not
operating system support. If YMM state management is not enabled by an operating
systems, AVX instructions will #UD regardless of CPUID.1:ECX.AVX[bit 28].
@mattip, @seiko2plus does the new/proposed cpu detection code solve this issue? And @qfan is there a simple fix you can suggest to our current cpu detection functionality?
@mattip, @seiko2plus does the new/proposed cpu detection code solve this issue? And @qfan is there a simple fix you can suggest to our current cpu detection functionality?
I do not know any x86 assembly. But the "Intel(R) Advanced Vector Extensions Programming Reference" PDF (you can google it, but intel does not provide a direct link) has a 17-line pseudo-code for checking this, near the "note" I quoted in previous comment.
@ryandesign, yes that's right, OSXSAVE bit must be checked first before executing xgetbv, @seberg, @qfan, gh-13421 should fix this issue, please could you try it? also you can dump the new module attribute __cpu_features__ that come with it. it should contain the runtime detection result.
@ryandesign, yes that's right, OSXSAVE bit must be checked first before executing xgetbv, @seberg, @qfan, gh-13421 should fix this issue, please could you try it? also you can dump the new module attribute __cpu_features__ that come with it. it should contain the runtime detection result.
I applied your pull request to numpy/master and it does work on that Westmere CPU. Great Job!
Activity
ryandesign commentedon Jan 18, 2020
While trying to learn more about this problem, I found a bug report at another project where there was a crash at xgetbv on a machine that had avx support disabled. The fix there was to check that the CPUID.1:ECX.OSXSAVE bit is set first. I wasn't sure if something like that might be applicable for numpy too.
qfan commentedon Jan 23, 2020
I got the same error on a Google Cloud VM.
The /proc/cpuinfo I got is:
So it appears that this thing does have avx and avx2 support in general, but not the
xgetbvinstruction.In my case the crash points to the specific version and line:
https://github.com/numpy/numpy/blob/v1.17.3/numpy/core/src/umath/cpuid.c#L30
It seems that the
xgetbvinstruction is called without first checking whether it is available.According to "Intel(R) Advanced Vector Extensions Programming Reference", Ref. # 319433-011
seberg commentedon Jan 23, 2020
@mattip, @seiko2plus does the new/proposed cpu detection code solve this issue? And @qfan is there a simple fix you can suggest to our current cpu detection functionality?
qfan commentedon Jan 23, 2020
I do not know any x86 assembly. But the "Intel(R) Advanced Vector Extensions Programming Reference" PDF (you can google it, but intel does not provide a direct link) has a 17-line pseudo-code for checking this, near the "note" I quoted in previous comment.
seiko2plus commentedon Jan 24, 2020
@ryandesign, yes that's right,
OSXSAVEbit must be checked first before executingxgetbv,@seberg, @qfan, gh-13421 should fix this issue, please could you try it? also you can dump the new module attribute
__cpu_features__that come with it. it should contain the runtime detection result.qfan commentedon Jan 24, 2020
I applied your pull request to numpy/master and it does work on that Westmere CPU. Great Job!
I'm going to lose access to this VM tomorrow, though. So I probably won't be able to test this again if you make any change later.
ryandesign commentedon Jan 24, 2020
It does on my macOS Sierra VM, thank you.
ryandesign commentedon Jun 26, 2020
1.19.0 fixes this. Thanks.