8000 BLD: import libatomic linking code from scipy · numpy/numpy@9293a4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9293a4d

Browse files
committed
BLD: import libatomic linking code from scipy
1 parent e5c8711 commit 9293a4d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

numpy/_core/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ py.extension_module('_multiarray_umath',
12171217
'src/npymath',
12181218
'src/umath',
12191219
],
1220-
dependencies: [blas_dep],
1220+
dependencies: [blas_dep, atomic_dep],
12211221
link_with: [npymath_lib, multiarray_umath_mtargets.static_lib('_multiarray_umath_mtargets')] + highway_lib,
12221222
install: true,
12231223
subdir: 'numpy/_core',

numpy/meson.build

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,43 @@ else
214214
lapack_dep = declare_dependency(dependencies: [lapack, blas_dep])
215215
endif
216216

217+
# Determine whether it is necessary to link libatomic. This could be the case
218+
# e.g. on 32-bit platforms when atomic operations are used on 64-bit types.
219+
# The check is copied from SciPy, who copied it from Mesa
220+
# <https://www.mesa3d.org/>.
221+
null_dep = dependency('', required : false)
222+
atomic_dep = null_dep
223+
code_non_lockfree = '''
224+
#include <stdint.h>
225+
int main() {
226+
struct {
227+
uint64_t *v;
228+
} x;
229+
return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
230+
(int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
231+
}
232+
'''
233+
if cc.get_id() != 'msvc'
234+
if not cc.links(
235+
code_non_lockfree,
236+
name : 'Check atomic builtins without -latomic'
237+
)
238+
atomic_dep = cc.find_library('atomic', required: false)
239+
if atomic_dep.found()
240+
# We're not sure that with `-latomic` things will work for all compilers,
241+
# so verify and only keep libatomic as a dependency if this works. It is
242+
# possible the build will fail later otherwise - unclear under what
243+
# circumstances (compilers, runtimes, etc.) exactly.
244+
if not cc.links(
245+
code_non_lockfree,
246+
dependencies: atomic_dep,
247+
name : 'Check atomic builtins with -latomic'
248+
)
249+
atomic_dep = null_dep
250+
endif
251+
endif
252+
endif
253+
endif
217254

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

0 commit comments

Comments
 (0)
0