Skip to content
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

Use uint32_t instead of size_t for object sort #126

Merged
merged 3 commits into from
Feb 1, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/build-numpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
- name: Install NumPy dependencies
working-directory: ${{ github.workspace }}/numpy
run: |
pip install -r build_requirements.txt
pip install -r test_requirements.txt
pip install -r requirements/build_requirements.txt
pip install -r requirements/test_requirements.txt

- name: Update x86-simd-sort
working-directory: ${{ github.workspace }}/numpy
Expand Down Expand Up @@ -116,8 +116,8 @@ jobs:
- name: Install NumPy dependencies
working-directory: ${{ github.workspace }}/numpy
run: |
pip install -r build_requirements.txt
pip install -r test_requirements.txt
pip install -r requirements/build_requirements.txt
pip install -r requirements/test_requirements.txt

- name: Update x86-simd-sort
working-directory: ${{ github.workspace }}/numpy
Expand Down
24 changes: 13 additions & 11 deletions benchmarks/bench-objsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Point3D {
return std::sqrt(x * x + y * y + z * z);
}
else if constexpr (name == "taxicab") {
return abs(x) + abs(y) + abs(z);
return std::abs(x) + std::abs(y) + std::abs(z);
}
else if constexpr (name == "chebyshev") {
return std::max(std::max(x, y), z);
Expand Down Expand Up @@ -98,13 +98,15 @@ static void simdobjsort(benchmark::State &state)
->Arg(10e5) \
->Arg(10e6);

BENCHMARK_OBJSORT(simdobjsort, Point3D, double, x)
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, x)
BENCHMARK_OBJSORT(simdobjsort, Point3D, float, x)
BENCHMARK_OBJSORT(scalarobjsort, Point3D, float, x)
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, taxicab )
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, taxicab)
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, euclidean)
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, euclidean)
BENCHMARK_OBJSORT(simdobjsort, Point3D, double, chebyshev)
BENCHMARK_OBJSORT(scalarobjsort, Point3D, double, chebyshev)
#define BENCH_ALL(dtype) \
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, x) \
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, x) \
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, taxicab ) \
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, taxicab) \
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, euclidean) \
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, euclidean) \
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, chebyshev) \
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, chebyshev) \

BENCH_ALL(double)
BENCH_ALL(float)
6 changes: 3 additions & 3 deletions lib/x86simdsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);

// sort an object
template <typename T, typename Func>
XSS_EXPORT_SYMBOL void object_qsort(T *arr, size_t arrsize, Func key_func)
XSS_EXPORT_SYMBOL void object_qsort(T *arr, uint32_t arrsize, Func key_func)
{
/* (1) Create a vector a keys */
using return_type_of =
Expand All @@ -55,9 +55,9 @@ XSS_EXPORT_SYMBOL void object_qsort(T *arr, size_t arrsize, Func key_func)
}

/* (2) Call arg based on keys using the keyvalue sort */
std::vector<size_t> arg(arrsize);
std::vector<uint32_t> arg(arrsize);
std::iota(arg.begin(), arg.end(), 0);
keyvalue_qsort(keys.data(), arg.data(), arrsize);
x86simdsort::keyvalue_qsort(keys.data(), arg.data(), arrsize);

/* (3) Permute obj array in-place */
std::vector<bool> done(arrsize);
Expand Down
Loading