8000 Better gating of Highway · numpy/numpy@4a6edf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a6edf9

Browse files
committed
Better gating of Highway
1 parent 7612fe5 commit 4a6edf9

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

numpy/core/src/npysort/quicksort.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#include <utility>
6161

6262
#define NOT_USED NPY_UNUSED(unused)
63+
#define DISABLE_HIGHWAY_OPTIMIZATION (defined(NPY_HAVE_ASIMD) && (!defined(__aarch64__) || !defined(NPY_CAN_LINK_HIGHWAY)))
64+
6365
/*
6466
* pushing largest partition has upper bound of log2(n) space
6567
* we store two pointers each time
@@ -94,12 +96,14 @@ inline bool quicksort_dispatch(T *start, npy_intp num)
9496
#endif
9597
NPY_CPU_DISPATCH_CALL_XB(dispfunc = np::qsort_simd::template QSort, <TF>);
9698
}
99+
#if !DISABLE_HIGHWAY_OPTIMIZATION
97100
else if (sizeof(T) == sizeof(uint32_t) || sizeof(T) == sizeof(uint64_t)) {
98-
#if !defined(NPY_DISABLE_OPTIMIZATION) && !(defined(NPY_HAVE_ASIMD) && !defined(NPY_CAN_LINK_HIGHWAY))
101+
#if !defined(NPY_DISABLE_OPTIMIZATION)
99102
#include "simd_qsort.dispatch.h"
100103
#endif
101104
NPY_CPU_DISPATCH_CALL_XB(dispfunc = np::qsort_simd::template QSort, <TF>);
102105
}
106+
#endif
103107
if (dispfunc) {
104108
(*dispfunc)(reinterpret_cast<TF*>(start), static_cast<intptr_t>(num));
105109
return true;

numpy/core/src/npysort/simd_qsort.dispatch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
#include "simd_qsort.hpp"
1111

12+
#define USE_HIGHWAY defined(__aarch64__) && defined(NPY_HAVE_ASIMD) && defined(NPY_CAN_LINK_HIGHWAY)
13+
1214
#if defined(NPY_HAVE_AVX512_SKX) && !defined(_MSC_VER)
1315
#include "x86-simd-sort/src/avx512-32bit-qsort.hpp"
1416
#include "x86-simd-sort/src/avx512-64bit-qsort.hpp"
15-
#elif defined(NPY_HAVE_ASIMD)
17+
#elif USE_HIGHWAY
1618
#include "hwy/contrib/sort/vqsort.h"
1719
#endif
1820

@@ -43,7 +45,7 @@ template<> void NPY_CPU_DISPATCH_CURFX(QSort)(double *arr, intptr_t size)
4345
{
4446
avx512_qsort(arr, size);
4547
}
46-
#elif defined(NPY_HAVE_ASIMD) && defined(NPY_CAN_LINK_HIGHWAY)
48+
#elif USE_HIGHWAY
4749
template<> void NPY_CPU_DISPATCH_CURFX(QSort)(int32_t *arr, intptr_t size)
4850
{
4951
hwy::VQSort(arr, size, hwy::SortAscending());

numpy/core/src/npysort/simd_qsort.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
#include "common.hpp"
55

6+
#define DISABLE_HIGHWAY_OPTIMIZATION (defined(__arm__) || (defined(__aarch64__) && !defined(NPY_CAN_LINK_HIGHWAY)))
7+
68
namespace np { namespace qsort_simd {
79

10+
#if !DISABLE_HIGHWAY_OPTIMIZATION
811
#ifndef NPY_DISABLE_OPTIMIZATION
912
#include "simd_qsort.dispatch.h"
1013
#endif
1114
NPY_CPU_DISPATCH_DECLARE(template <typename T> void QSort, (T *arr, intptr_t size))
15+
#endif
1216

1317
#ifndef NPY_DISABLE_OPTIMIZATION
1418
#include "simd_argsort.dispatch.h"
@@ -21,4 +25,7 @@ NPY_CPU_DISPATCH_DECLARE(template <typename T> void ArgQSort, (T *arr, npy_intp*
2125
NPY_CPU_DISPATCH_DECLARE(template <typename T> void QSort, (T *arr, intptr_t size))
2226

2327
} } // np::qsort_simd
28+
29+
#undef DISABLE_HIGHWAY_OPTIMIZATION
30+
2431
#endif // NUMPY_SRC_COMMON_NPYSORT_SIMD_QSORT_HPP

0 commit comments

Comments
 (0)
0