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
BLD: Do not use clang default to ignore floating point exceptions #18005
Remarkably numpy.log() gives a runtime overflow warning on a float32 array containing values larger than 1e9. Numpy 1.19.4, macOS 10.15.7, MacBookPro15,3. Warning does not appear for float64 array even for much larger values (e.g. 1e35).
@tomgoddard, I cannot reproduce this on linux. Since you are on 1.19.x, could you print:
np.core._multiarray_umath.__cpu_features__
Just so we have the information?
The most likely cause will be that you have AVX512 instructions available and our AVX512 code has an error here. If it is in the AV512 path, @r-devulap could you have a look?
Of course it could also be a clang bug in the glibc version...
could you run np.log(np.array([1e9]*8, np.float32)) and check if the overflow error still remains? newest versions of clang committing aggressive optimization to partial load operations lead to undefined the vector tail on AVX2.
I don't see this problem when using NumPy built with gcc 9.3 or clang 10.0. Makes me think it has to something to do with clang 12. Still figuring out how to install clang 12 on my Ubuntu to reproduce the error :/
could you run a = np.array([1e9]*8, np.float32) and check if the overflow error still remains? newest versions of clang committing aggressive optimization to partial load operations lead to undefined the vector tail on AVX2.
confirmed that this behavior is only with clang (clang 10 and clang 12), and does not happen with gcc. It decides to set an overflow flag for a blend instruction (which is weird and incorrect) x = _mm256_blendv_ps(x, temp, denormal_mask); here:
@r-devulap thanks for digging this down, I am assuming it is a clang bug. Can we file it there? I am not sure there is a good way for us to work around it in NumPy to begin with...
Found the culprit! clang optimizes out a blend instruction which was precisely meant to avoid this reported issue of an overflow warning. While the compiler was being clever, it is still a bug.
PR #18030 has a simple work around for this issue. Let me know if that works.
changed the title [-]log(1e9) gives RuntimeWarning: overflow encountered in log[/-][+]BLD: Do not use clang default to ignore floating point exceptions[/+]on Dec 21, 2020
Reopened and changed title. We should probably have a quick look around for clang workaround, but I don't think we need to backport getting rid of those.
Hmmm, I thought I would look into this. But I am honestly not sure where we should be adding this flag, or if we actually should (additionally) even prod Python itself to add this flag. Am I right to think that most clang specific flags currently are inherited from Python itself?
I think this is important, but I am not very familiar with distutils, and am not sure where this flag should be inserted correctly. (It probably is also correct for SciPy, but do we want to set it by default for scipy as well?).
I am happy to check for the related code cleanups, but not too fond of digging through distutils to find the right place.
It shouldn't matter too much to push it off to 1.21 all known issues due to this are fixed after all. While the flag change is something we could do, the (probably) related code cleanup we do not want to backport anyway probably.
@rgommers I somewhat assume you just know where to put this. Can you point where we would add a clang specific compiler flag to distutils (maybe NumPy specific, although this flag is really also necessary for scipy, I bet).
Activity
seberg commentedon Dec 16, 2020
@tomgoddard, I cannot reproduce this on linux. Since you are on 1.19.x, could you print:
Just so we have the information?
The most likely cause will be that you have AVX512 instructions available and our AVX512 code has an error here. If it is in the AV512 path, @r-devulap could you have a look?
Of course it could also be a clang bug in the glibc version...
tomgoddard commentedon Dec 16, 2020
tomgoddard commentedon Dec 16, 2020
Numpy 1.19.4 was installed using brew on macOS 10.15.7.
seiko2plus commentedon Dec 16, 2020
could you run
np.log(np.array([1e9]*8, np.float32))and check if the overflow error still remains? newest versions of clang committing aggressive optimization to partial load operations lead to undefined the vector tail on AVX2.r-devulap commentedon Dec 16, 2020
I don't see this problem when using NumPy built with gcc 9.3 or clang 10.0. Makes me think it has to something to do with clang 12. Still figuring out how to install clang 12 on my Ubuntu to reproduce the error :/
tomgoddard commentedon Dec 16, 2020
tomgoddard commentedon Dec 16, 2020
r-devulap commentedon Dec 16, 2020
confirmed that this behavior is only with clang (clang 10 and clang 12), and does not happen with gcc. It decides to set an overflow flag for a blend instruction (which is weird and incorrect)
x = _mm256_blendv_ps(x, temp, denormal_mask);here:numpy/numpy/core/src/umath/simd.inc.src
Line 1554 in d7a75e8
seberg commentedon Dec 17, 2020
@r-devulap thanks for digging this down, I am assuming it is a clang bug. Can we file it there? I am not sure there is a good way for us to work around it in NumPy to begin with...
r-devulap commentedon Dec 18, 2020
Trying to narrow down to a simple C program to replicate the bug, unsuccessful so far ..
r-devulap commentedon Dec 19, 2020
Found the culprit! clang optimizes out a blend instruction which was precisely meant to avoid this reported issue of an overflow warning. While the compiler was being clever, it is still a bug.
PR #18030 has a simple work around for this issue. Let me know if that works.
EDIT: didn't mean to include the code snippet.
15 remaining items
[-]log(1e9) gives RuntimeWarning: overflow encountered in log[/-][+]BLD: Do not use clang default to ignore floating point exceptions[/+]seberg commentedon Dec 21, 2020
Reopened and changed title. We should probably have a quick look around for clang workaround, but I don't think we need to backport getting rid of those.
r-devulap commentedon Dec 21, 2020
This was the other time clang give me an incorrect FP flag: #13586 (comment) and the associated PR #13623
seberg commentedon Jan 25, 2021
Hmmm, I thought I would look into this. But I am honestly not sure where we should be adding this flag, or if we actually should (additionally) even prod Python itself to add this flag. Am I right to think that most clang specific flags currently are inherited from Python itself?
charris commentedon Jan 29, 2021
What is the status of this?
seberg commentedon Jan 29, 2021
I think this is important, but I am not very familiar with distutils, and am not sure where this flag should be inserted correctly. (It probably is also correct for SciPy, but do we want to set it by default for scipy as well?).
I am happy to check for the related code cleanups, but not too fond of digging through distutils to find the right place.
It shouldn't matter too much to push it off to 1.21 all known issues due to this are fixed after all. While the flag change is something we could do, the (probably) related code cleanup we do not want to backport anyway probably.
seberg commentedon Mar 18, 2021
@rgommers I somewhat assume you just know where to put this. Can you point where we would add a clang specific compiler flag to distutils (maybe NumPy specific, although this flag is really also necessary for scipy, I bet).
rgommers commentedon Mar 18, 2021
In
CCompiler_customize: https://github.com/numpy/numpy/blob/main/numpy/distutils/ccompiler.py#L366It's hard to make it NumPy-specific, and I think other libraries should get this flag too, so I'd say just add it unconditionally.
seiko2plus commentedon Mar 18, 2021
@seberb,
for a quickfix, we can link the flag with one of baseline features flags, etc
SSEon x86.`numpy/numpy/distutils/ccompiler_opt.py
Lines 309 to 314 in ddbff08