-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: numpy.any returns True given a boolean array of all False with the intel compiler #26197
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
Comments
I can't reproduce this with numpy 1.26.4:
|
On a debian installation with a virtual environment in which I install 1.26.2, I also cannot reproduce this:
Given that the break occurs at 64, one would suspect some kind of vectorization issue -- very weird! |
Could also be an issue building numpy with the intel compilers. |
@AgilentGCMS any chance you can upgrade to 1.26.4, just to see if there was a recent related fix? Also, I am curious where you installed numpy from (might be important, but not sure). You can also try defining:
or similar (add only features lower in the list you gave above, or add @seiko2plus does this issue ring a bell? This certainly must be SIMD dependent. |
@seberg I installed numpy by compiling from source because I wanted to link to Intel MKL. I tried disabling different CPU features, and found out that the following
solves this problem. I tried all the way up to arrays of length 2147483648 (2^32), and |
Thanks for trying that, I think that is useful. I don't know how to solve this, but if it has to do with
Well, not without figuring out the root cause and the root cause might even be a compiler bug at this point. (No idea if that is likely, but it does seem like a bug that the test suite should normally notice.) Also ping @rdevulap. |
That is correct, I used the Intel compiler. |
Have you tried building numpy with gcc instead of the intel compilers? I don't think we test with the intel compilers in our CI. That would also help narrow down where the issue is. |
@seberg I tried updating to numpy 1.26.4, however I could not perform the same test of excluding AVX512_SKX. Somehow it became part of the "baseline" optimizations,
and when I tried to disable it I got the error
On numpy 1.26.4 with intel compilers, the test with |
Who/what decides which features are part of baseline optimizations? |
OK I figured out how to move the AVX512 features from |
I have not. You mean compile with |
Both would provide useful debugging information probably. |
I also noted that disabling AVX512_SKX actually slows down the evaluation of import time
Y = np.zeros(2**32, bool)
t1 = time.time()
for i in range(50):
_ = np.any(Y)
t2 = time.time()
print('Time for 50 calls to np.any on an array length 2**32 = %.3f s'%(t2-t1)) and the times were significantly different:
So disabling gives the correct answer but is slower. I haven't checked if other operations like |
I don't see this error with 1.26.2 or 1.26.4 when I run with numpy installed via with pip (built with gcc). This looks like a bug in Intel compiler. Let me try building with intel compiler. |
Thanks! I am not sure if this is specific to a particular version of the intel compiler. I am using a more recent version of openapi than I would like because of this issue which precludes me from compiling scipy with an older oneapi version. |
I've been so far compiling with intel oneapi 2023.1.0. I switched to oneapi 2022.2.1, recompiled python and numpy, and I still see the same bug (and the same workaround, i.e., disabling AVX512_SKX). I understand that switching to GCC would probably solve this problem, but unfortunately I can't afford to do that. I do a lot of linear algebra operations for my work, and using architecture-optimized linear algebra libraries (i.e., MKL) makes a huge difference in execution times. |
Can’t you compile numpy with gcc and still link against MKL? |
In principle yes. In practice, I don't know how to set compiler and linker flags when I compile numpy with gcc. As in, I know what those flags should be, I just don't know how to tell numpy that since it's not an autoconf/automake build. |
Editing the issue title to reflect it uses the intel compiler. Maybe related to #25044 to build NumPy on windows with the intel compiler. The BLAS/LAPACK detection machinery should JustWork to detect MKL at build time. You can give meson hints if the wrong BLAS/LAPACK are chosen. |
@AgilentGCMS could you list the steps to build with Intel compiler? I am using icpx (Intel(R) oneAPI DPC++/C++ Compiler 2024.1.0 (2024.1.0.20240308)) and keep seeing a missing symbol error:
|
I have found that if I build with
|
I should also say that I've been able to reproduce this on another computer with intel oneapi 2022.1 compilers. The same workaround of disabling AVX512_SKX works. |
@mattip I tried your suggestion. I do have several pkgconfig files for the MKL libraries, so I tried a couple. Unfortunately they all fail without telling me why.
I have to say I find the new-fangled meson build process quite frustrating. At least with distutils I could look at the console output and get a clue as to what failed and why. This question on reddit sums up my feelings perfectly. |
We should probably be pushing
|
There is this section about choosing a blas/lapack implementation, which uses |
@mattip Thanks, but that route failed too. At least now I have an error message:
|
I think that echoes the failures fixed in the WIP PR #25044. What version of NumPy are you building? |
I was able to build it with icpx and don't see this failure. My oneAPI basekit installation does not seem to include icc though :/ |
@r-devulap It's my turn to ask you how you built with icpx/icx :-) Perhaps I can follow those same steps on my cluster. |
hah, it was chaotic to say the least. Let me try and reproduce the steps and document it. Might need a day or two to get to it. |
@r-devulap Thanks! Also, more importantly, once you compiled successfully, did numpy show that AVX512_SKX was available and in use? It depends on the processor type on which you compiled and ran, so if AVX512_SKX instructions were not used, it would make sense that the test succeeded. |
Found a nice minimal way to build it, but with the caveat that I had to disable building SVML (looks like ipcx compiler fails to build SVML correctly, which is very ironic). Here are the steps:
NumPy show config does show that it supports AVX512_SKX extensions:
|
See #26257 for tracking problems with SVML/ICPX compiler |
|
@r-devulap Sadly, that process did not work for me :-(
Since this does not show exactly what went wrong, I tried
Here's the full output of
|
OK, I now have a version of numpy compiled with intel compilers which does not fail the
|
I confirm it, it's a compiler-specific issue with the Intel Compiler Classic across all versions, The underlying issue arises from the compiler's optimizer. When the last vector comparison The bug should be triggered by the SIMD testing unit and it can reproduced by: >>> from numpy._core import _simd; v = _simd.AVX512_SKX
>>> v.any_u8(v.setall_u8(0))
1 Proof of the bug and a suggested workaround: |
Describe the issue:
np.any
on a boolean array where all elements areFalse
should returnFalse
. This has been the case for the past decade or so, across numerousnumpy
versions. However, I recently installednumpy 1.26.2
, and that is not working as expected. For a 1D boolean array of 63 or less elements, allFalse
,np.any
returnsFalse
. However, if the length is 64 or more,np.any
returns True.Reproduce the code example:
Error message:
No response
Python and NumPy Versions:
Runtime Environment:
Context for the issue:
np.any()
on an array ofFalse
elements returningFalse
is a pretty basic functionality of numpy, and behaves as expected in multiple other versions ofnumpy
across platforms. I rely on that to filter data regularly. So the fact that this breaks in 1.26.2 is very strange and unexpected.The text was updated successfully, but these errors were encountered: