8000 BLD: Add openmp flags to build x86-simd-sort · r-devulap/numpy@7fd938b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fd938b

Browse files
committed
BLD: Add openmp flags to build x86-simd-sort
Also adds a simple unit test to stress the openmp code paths
1 parent 130cac5 commit 7fd938b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

numpy/_core/meson.build

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ if use_intel_sort and not fs.exists('src/npysort/x86-simd-sort/README.md')
128128
error('Missing the `x86-simd-sort` git submodule! Run `git submodule update --init` to fix this.')
129129
endif
130130

131+
# Setup openmp flags for x86-simd-sort:
132+
omp_cflags = []
133+
omp = []
134+
if use_intel_sort and cpp.has_argument('-fopenmp')
135+
omp = dependency('openmp', required : false)
136+
if omp.found()
137+
omp_cflags = ['-fopenmp', '-DXSS_USE_OPENMP']
138+
endif
139+
endif
140+
131141
if not fs.exists('src/common/pythoncapi-compat')
132142
error('Missing the `pythoncapi-compat` git submodule! ' +
133143
'Run `git submodule update --init` to fix this.')
@@ -867,14 +877,17 @@ foreach gen_mtargets : [
867877
] : []
868878
],
869879
]
880+
881+
882+
870883
mtargets = mod_features.multi_targets(
871884
gen_mtargets[0], multiarray_gen_headers + gen_mtargets[1],
872885
dispatch: gen_mtargets[2],
873886
# baseline: CPU_BASELINE, it doesn't provide baseline fallback
874887
prefix: 'NPY_',
875888
dependencies: [py_dep, np_core_dep],
876889
c_args: c_args_common + max_opt,
877-
cpp_args: cpp_args_common + max_opt,
890+
cpp_args: cpp_args_common + max_opt + omp_cflags,
878891
include_directories: [
879892
'include',
880893
'src/common',
@@ -1286,7 +1299,7 @@ py.extension_module('_multiarray_umath',
12861299
'src/umath',
12871300
'src/highway'
12881301
],
1289-
dependencies: [blas_dep],
1302+
dependencies: [blas_dep, omp],
12901303
link_with: [
12911304
npymath_lib,
12921305
unique_hash_so,

numpy/_core/tests/test_multiarray.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10292,6 +10292,12 @@ def test_argsort_int(N, dtype):
1029210292
arr[N - 1] = maxv
1029310293
assert_arg_sorted(arr, np.argsort(arr, kind='quick'))
1029410294

10295+
# Test large arrays that leverage openMP implementations from x86-simd-sort:
10296+
@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64])
10297+
def test_sort_largearrays(dtype):
10298+
N = 1000000
10299+
arr = np.random.rand(N)
10300+
assert_equal(np.sort(arr, kind='quick'), np.sort(arr, kind='heap'))
1029510301

1029610302
@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
1029710303
def test_gh_22683():

0 commit comments

Comments
 (0)
0