-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Race in computing initial value for reductions under free-threading #28041
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 &l 8000 dquo;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
Doesn't seem too worrying in practice. Anyway, without diving in, my guess is that we can move this to |
Unfortunately I'm not able to build NumPy with TSAN support on my Mac because of #28087. I'm guessing Linux doesn't hit that for whatever reason? Will try again on my Linux machine... |
Thanks to some help from @Mousius I was able to fix the build issue and reproduce this. Thanks for the detailed reproducer and thanks also to @vfdev-5 for the detailed instructions on how to setup CPython and NumPy to reproduce this. I'm planning to look through all the issues @hawkinsp opened using tsan and fix the most pressing issues. I'd also like to add new tests and a thread sanitizer CI run if there's appetite to do that. It seems pretty straightforward to do this on an ARM Mac and I think it would be nice to run thread sanitizer tests on a machine with weak memory ordering. |
Here's the same warning with line numbers in NumPy, as reported by clang 19:
And indeed we're writing to global state on the numpy/numpy/_core/src/umath/legacy_array_method.c Lines 328 to 330 in 206f697
I agree it's probably best to do this when you create the ArrayMethod. |
I opened #28123 |
Describe the issue:
With:
thread sanitizer reports a race constructing the cached initial value for a reducer.
You may need to run the example a few times, but it reproduced first time for me.
Reproduce the code example:
Error message:
Python and NumPy Versions:
2.3.0.dev0+git20241219.35b2c4a
3.13.1 experimental free-threading build (tags/v3.13.1:06714517797, Dec 15 2024, 15:38:01) [Clang 18.1.8 (11)]
Runtime Environment:
[{'numpy_version': '2.3.0.dev0+git20241219.35b2c4a',
'python': '3.13.1 experimental free-threading build '
'(tags/v3.13.1:06714517797, Dec 15 2024, 15:38:01) [Clang 18.1.8 '
'(11)]',
'uname': uname_result(system='Linux', node='', release='', version='#1 SMP PREEMPT_DYNAMIC Debian 6.redacted (2024-10-16)', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Zen',
'filepath': '/usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.27.so',
'internal_api': 'openblas',
'num_threads': 128,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.27'}]
Context for the issue:
Found when working on free-threading support in JAX.
The text was updated successfully, but these errors were encountered: