Skip to content

Commit aad3db1

Browse files
author
Raghuveer Devulapalli
authored
Merge pull request #146 from sterrettm2/kv-base_case_tests
Adds testing for kv-sort base case and fixes the current bug with it
2 parents 4c3ade9 + 478398c commit aad3db1

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

.github/workflows/c-cpp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
- name: Run test suite on SPR
136136
run: sde -spr -- ./builddir/testexe
137137

138-
SPR-gcc13-min-networksort:
138+
SPR-gcc13-special-cases:
139139

140140
runs-on: intel-ubuntu-latest
141141

@@ -156,7 +156,7 @@ jobs:
156156
- name: Build
157157
env:
158158
CXX: g++-13
159-
CXXFLAGS: -DXSS_MINIMAL_NETWORK_SORT
159+
CXXFLAGS: "-DXSS_MINIMAL_NETWORK_SORT -DXSS_TEST_KEYVALUE_BASE_CASE"
160160
run: |
161161
make clean
162162
meson setup -Dbuild_tests=true --warnlevel 2 --werror --buildtype release builddir

src/avx512-64bit-keyvaluesort.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ template <typename vtype1,
347347
X86_SIMD_SORT_INLINE void
348348
heap_sort(type1_t *keys, type2_t *indexes, arrsize_t size)
349349
{
350+
if (size <= 1) return;
350351
for (arrsize_t i = size / 2 - 1;; i--) {
351352
heapify<vtype1, vtype2>(keys, indexes, i, size);
352353
if (i == 0) { break; }
@@ -366,13 +367,12 @@ X86_SIMD_SORT_INLINE void qsort_64bit_(type1_t *keys,
366367
type2_t *indexes,
367368
arrsize_t left,
368369
arrsize_t right,
369-
arrsize_t max_iters)
370+
int max_iters)
370371
{
371372
/*
372373
* Resort to std::sort if quicksort isnt making any progress
373374
*/
374375
if (max_iters <= 0) {
375-
//std::sort(keys+left,keys+right+1);
376376
heap_sort<vtype1, vtype2>(
377377
keys + left, indexes + left, right - left + 1);
378378
return;
@@ -416,28 +416,29 @@ avx512_qsort_kv(T1 *keys, T2 *indexes, arrsize_t arrsize, bool hasnan = false)
416416
&& sizeof(T2) == sizeof(int32_t),
417417
ymm_vector<T2>,
418418
zmm_vector<T2>>::type;
419+
/*
420+
* Enable testing the heapsort key-value sort in the CI:
421+
*/
422+
#ifdef XSS_TEST_KEYVALUE_BASE_CASE
423+
int maxiters = -1;
424+
bool minarrsize = true;
425+
#else
426+
int maxiters = 2 * log2(arrsize);
427+
bool minarrsize = arrsize > 1 ? true : false;
428+
#endif // XSS_TEST_KEYVALUE_BASE_CASE
419429

420-
if (arrsize > 1) {
430+
if (minarrsize) {
431+
arrsize_t nan_count = 0;
421432
if constexpr (xss::fp::is_floating_point_v<T1>) {
422-
arrsize_t nan_count = 0;
423433
if (UNLIKELY(hasnan)) {
424434
nan_count = replace_nan_with_inf<zmm_vector<T1>>(keys, arrsize);
425435
}
426-
qsort_64bit_<keytype, valtype>(keys,
427-
indexes,
428-
0,
429-
arrsize - 1,
430-
2 * (arrsize_t)log2(arrsize));
431-
replace_inf_with_nan(keys, arrsize, nan_count);
432436
}
433437
else {
434438
UNUSED(hasnan);
435-
qsort_64bit_<keytype, valtype>(keys,
436-
indexes,
437-
0,
438-
arrsize - 1,
439-
2 * (arrsize_t)log2(arrsize));
440439
}
440+
qsort_64bit_<keytype, valtype>(keys, indexes, 0, arrsize - 1, maxiters);
441+
replace_inf_with_nan(keys, arrsize, nan_count);
441442
}
442443
}
443444
#endif // AVX512_QSORT_64BIT_KV

0 commit comments

Comments
 (0)