Repository navigation
Description
Describe the issue:
numpy.power result is nondeterministic when the exponent is a view with certain strides and AVX512 is available. Problem goes away with NPY_DISABLE_CPU_FEATURES="AVX512F"
Reproduce the code example:
import numpy as np
for r in range(1000):
for c in range(1, 10):
src = np.linspace(0, 1, num=r * c).reshape(r, c)
for j in range(0, c):
x = src[:, j]
if not np.array_equal(np.power(1.2, x), np.power(1.2, x)):
print(f"diff! {(r,c,j)=}; {x.__array_interface__=}")
breakError message:
Snippet of results:
diff! (r,c,j)=(3, 3, 1); x.__array_interface__={'data': (94083650133912, False), 'strides': (24,), 'descr': [('', '<f8')], 'typestr': '<f8', 'shape': (3,), 'version': 3}
diff! (r,c,j)=(134, 5, 4); x.__array_interface__={'data': (94083654872944, False), 'strides': (40,), 'descr': [('', '<f8')], 'typestr': '<f8', 'shape': (134,), 'version': 3}
diff! (r,c,j)=(134, 8, 2); x.__array_interface__={'data': (94083654872928, False), 'strides': (64,), 'descr': [('', '<f8')], 'typestr': '<f8', 'shape': (134,), 'version': 3}Python and NumPy Versions:
1.26.4
3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) [GCC 12.3.0]
Runtime Environment:
[{'numpy_version': '1.26.4',
'python': '3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) '
'[GCC 12.3.0]',
'uname': uname_result(system='Linux', node=', release='6.1.0-18-cloud-amd64', version='#1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01)', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL'],
'not_found': ['AVX512_KNL', 'AVX512_KNM', 'AVX512_SPR']}},
{'filepath': '/conda_package_mkl/lib/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': 48,
'prefix': 'libmkl_rt',
'threading_layer': 'intel',
'user_api': 'blas',
'version': '2023.2-Product'},
{'filepath': '/conda_package_llvm_openmp/lib/libomp.so',
'internal_api': 'openmp',
'num_threads': 96,
'prefix': 'libomp',
'user_api': 'openmp',
'version': None}]
Context for the issue:
The result is unexpectedly nondeterministic and causes flaky tests.
Activity
[-]BUG: <Please write a comprehensive title after the 'BUG: ' prefix>[/-][+]BUG: numpy.power result is nondeterministic when AVX512 enabled[/+]r-devulap commentedon Mar 20, 2024
Occasionally, the strided input array overlaps in memory with the output/destination array, preventing SIMD from being used. The output of SIMD can differ from the scalar version by at most 4 ULP. You could adjust your test to account this for this difference.
r-devulap commentedon Mar 20, 2024
@seberg is it concerning to see this check fail?
numpy/numpy/_core/src/umath/loops_umath_fp.dispatch.c.src
Line 247 in 71ab906
I always assumed we never hit these conditions and they were there just as a sanity check.
seberg commentedon Mar 21, 2024
Accumulations do hit it, although we know that ahead of time really and it should be a very clear pattern of 1 stride/step difference between inputs.
What I have been saying about that part is that it would be plausible to explicitly pick a different loop ahead of time for accumulations.
seberg commentedon Mar 21, 2024
If it fails with the above code, then I would assume
npyv_loadable_stride_is failing, which seems acceptable (not sure about the conditions).charris commentedon Apr 29, 2024
Can this be solved for 1.26.x?