8000 MAINT: use an atomic load/store and a mutex to initialize the argparse and runtime import caches by ngoldbaum · Pull Request #26780 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: use an atomic load/store and a mutex to initialize the argparse and runtime import caches #26780

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

Merged
merged 8 commits into from
Jul 12, 2024
Prev Previous commit
Next Next commit
MAINT: re-add libatomic link test to meson.build
  • Loading branch information
ngoldbaum committed Jul 9, 2024
commit 6ea18a4ea18e0a522a73cb86d11fbb630bdac0fa
45 changes: 45 additions & 0 deletions numpy/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,51 @@ else
lapack_dep = declare_dependency(dependencies: [lapack, blas_dep])
endif

# Determine whether it is necessary to link libatomic. This could be the
# case on 32-bit platforms when atomic operations are used on 64-bit
# types or on RISC-V using 8-bit atomics, so we explicitly check for
# both 64 bit and 8 bit operations. The check is adapted from SciPy,
# who copied it from Mesa.
null_dep = dependency('', required : false)
atomic_dep = null_dep
code_non_lockfree = '''
#include <stdint.h>
int main() {
struct {
uint64_t *u64v;
uint8_t *u8v;
} x;
x.u8v = 0;
x.u64v = 0;
uint64_t res1 = __atomic_load_n(x.u64v, __ATOMIC_ACQUIRE) &
__atomic_add_fetch(x.u64v, (uint64_t)1, __ATOMIC_ACQ_REL);
uint8_t res2 = __atomic_load_n(x.u8v, __ATOMIC_ACQUIRE) &
__atomic_add_fetch(x.u8v, (uint8_t)1, __ATOMIC_ACQ_REL);
return 0;
}
'''
if cc.get_id() != 'msvc'
if not cc.links(
code_non_lockfree,
name : 'Check atomic builtins without -latomic'
)
atomic_dep = cc.find_library('atomic', required: false)
if atomic_dep.found()
# We're not sure that with `-latomic` things will work for all compilers,
# so verify and only keep libatomic as a dependency if this works. It is
# possible the build will fail later otherwise - unclear under what
# circumstances (compilers, runtimes, etc.) exactly and this may need to
# be extended when support is added for new CPUs
if not cc.links(
code_non_lockfree,
dependencies: atomic_dep,
name : 'Check atomic builtins with -latomic'
)
atomic_dep = null_dep
endif
endif
endif
endif

# Copy the main __init__.py|pxd files to the build dir (needed for Cython)
__init__py = fs.copyfile('__init__.py')
Expand Down
0