10000 SIMD: Fix Highway QSort symbol linking error on aarch32/ASIMD by seiko2plus · Pull Request #28671 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

SIMD: Fix Highway QSort symbol linking error on aarch32/ASIMD #28671

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 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions numpy/_core/src/npysort/highway_qsort.dispatch.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#define VQSORT_ONLY_STATIC 1
#include "hwy/highway.h"
#include "hwy/contrib/sort/vqsort-inl.h"

#include "highway_qsort.hpp"
#include "quicksort.hpp"

namespace np::highway::qsort_simd {
template <typename T>
void NPY_CPU_DISPATCH_CURFX(QSort)(T *arr, npy_intp size)
{
#if VQSORT_ENABLED
hwy::HWY_NAMESPACE::VQSortStatic(arr, size, hwy::SortAscending());
#else
sort::Quick(arr, size);
#endif
}

#define DISPATCH_VQSORT(TYPE) \
template<> void NPY_CPU_DISPATCH_CURFX(QSort)(TYPE *arr, intptr_t size) \
{ \
hwy::HWY_NAMESPACE::VQSortStatic(arr, size, hwy::SortAscending()); \
} \

namespace np { namespace highway { namespace qsort_simd {

DISPATCH_VQSORT(int32_t)
DISPATCH_VQSORT(uint32_t)
DISPATCH_VQSORT(int64_t)
DISPATCH_VQSORT(uint64_t)
DISPATCH_VQSORT(double)
DISPATCH_VQSORT(float)
template void NPY_CPU_DISPATCH_CURFX(QSort)<int32_t>(int32_t*, npy_intp);
template void NPY_CPU_DISPATCH_CURFX(QSort)<uint32_t>(uint32_t*, npy_intp);
template void NPY_CPU_DISPATCH_CURFX(QSort)<int64_t>(int64_t*, npy_intp);
template void NPY_CPU_DISPATCH_CURFX(QSort)<uint64_t>(uint64_t*, npy_intp);
template void NPY_CPU_DISPATCH_CURFX(QSort)<float>(float*, npy_intp);
template void NPY_CPU_DISPATCH_CURFX(QSort)<double>(double*, npy_intp);

} } } // np::highway::qsort_simd
} // np::highway::qsort_simd

#endif // VQSORT_ENABLED
17 changes: 2 additions & 15 deletions numpy/_core/src/npysort/highway_qsort.hpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
#ifndef NUMPY_SRC_COMMON_NPYSORT_HWY_SIMD_QSORT_HPP
#define NUMPY_SRC_COMMON_NPYSORT_HWY_SIMD_QSORT_HPP

#define VQSORT_ONLY_STATIC 1
#include "hwy/highway.h"
#include "hwy/contrib/sort/vqsort-inl.h"

#include "common.hpp"

#if !VQSORT_COMPILER_COMPATIBLE
#define NPY_DISABLE_HIGHWAY_SORT
#endif

#ifndef NPY_DISABLE_HIGHWAY_SORT
namespace np { namespace highway { namespace qsort_simd {
namespace np::highway::qsort_simd {

#ifndef NPY_DISABLE_OPTIMIZATION
#include "highway_qsort.dispatch.h"
#endif
NPY_CPU_DISPATCH_DECLARE(template <typename T> void QSort, (T *arr, npy_intp size))
NPY_CPU_DISPATCH_DECLARE(template <typename T> void QSelect, (T* arr, npy_intp num, npy_intp kth))


#ifndef NPY_DISABLE_OPTIMIZATION
#include "highway_qsort_16bit.dispatch.h"
#endif
NPY_CPU_DISPATCH_DECLARE(template <typename T> void QSort, (T *arr, npy_intp size))
NPY_CPU_DISPATCH_DECLARE(template <typename T> void QSelect, (T* arr, npy_intp num, npy_intp kth))

} } } // np::highway::qsort_simd
} // np::highway::qsort_simd

#endif // NUMPY_SRC_COMMON_NPYSORT_HWY_SIMD_QSORT_HPP
#endif // NPY_DISABLE_HIGHWAY_SORT
37 changes: 21 additions & 16 deletions numpy/_core/src/npysort/highway_qsort_16bit.dispatch.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
#include "highway_qsort.hpp"
#define VQSORT_ONLY_STATIC 1
#include "hwy/highway.h"
#include "hwy/contrib/sort/vqsort-inl.h"

#include "highway_qsort.hpp"
#include "quicksort.hpp"

#if VQSORT_ENABLED

namespace np { namespace highway { namespace qsort_simd {

template<> void NPY_CPU_DISPATCH_CURFX(QSort)(Half *arr, intptr_t size)
namespace np::highway::qsort_simd {
template <typename T>
void NPY_CPU_DISPATCH_CURFX(QSort)(T *arr, npy_intp size)
{
#if HWY_HAVE_FLOAT16
hwy::HWY_NAMESPACE::VQSortStatic(reinterpret_cast<hwy::float16_t*>(arr), size, hwy::SortAscending());
#if VQSORT_ENABLED
using THwy = std::conditional_t<std::is_same_v<T, Half>, hwy::float16_t, T>;
hwy::HWY_NAMESPACE::VQSortStatic(reinterpret_cast<THwy*>(arr), size, hwy::SortAscending());
#else
sort::Quick(arr, size);
#endif
}
template<> void NPY_CPU_DISPATCH_CURFX(QSort)(uint16_t *arr, intptr_t size)
{
hwy::HWY_NAMESPACE::VQSortStatic(arr, size, hwy::SortAscending());
}
template<> void NPY_CPU_DISPATCH_CURFX(QSort)(int16_t *arr, intptr_t size)
#if !HWY_HAVE_FLOAT16
template <>
void NPY_CPU_DISPATCH_CURFX(QSort)<Half>(Half *arr, npy_intp size)
{
hwy::HWY_NAMESPACE::VQSortStatic(arr, size, hwy::SortAscending());
sort::Quick(arr, size);
}
#endif // !HWY_HAVE_FLOAT16

} } } // np::highway::qsort_simd
template void NPY_CPU_DISPATCH_CURFX(QSort)<int16_t>(int16_t*, npy_intp);
template void NPY_CPU_DISPATCH_CURFX(QSort)<uint16_t>(uint16_t*, npy_intp);
#if HWY_HAVE_FLOAT16
template void NPY_CPU_DISPATCH_CURFX(QSort)<Half>(Half*, npy_intp);
#endif

#endif // VQSORT_ENABLED
} // np::highway::qsort_simd
4 changes: 2 additions & 2 deletions numpy/_core/src/npysort/quicksort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ inline bool quicksort_dispatch(T *start, npy_intp num)
#if defined(NPY_CPU_AMD64) || defined(NPY_CPU_X86) // x86 32-bit and 64-bit
#include "x86_simd_qsort_16bit.dispatch.h"
NPY_CPU_DISPATCH_CALL_XB(dispfunc = np::qsort_simd::template QSort, <TF>);
#elif !defined(NPY_DISABLE_HIGHWAY_SORT)
#else
#include "highway_qsort_16bit.dispatch.h"
NPY_CPU_DISPATCH_CALL_XB(dispfunc = np::highway::qsort_simd::template QSort, <TF>);
#endif
Expand All @@ -95,7 +95,7 @@ inline bool quicksort_dispatch(T *start, npy_intp num)
#if defined(NPY_CPU_AMD64) || defined(NPY_CPU_X86) // x86 32-bit and 64-bit
#include "x86_simd_qsort.dispatch.h"
NPY_CPU_DISPATCH_CALL_XB(dispfunc = np::qsort_simd::template QSort, <TF>);
#elif !defined(NPY_DISABLE_HIGHWAY_SORT)
#else
#include "highway_qsort.dispatch.h"
NPY_CPU_DISPATCH_CALL_XB(dispfunc = np::highway::qsort_simd::template QSort, <TF>);
#endif
Expand Down
Loading
0