Skip to content

Commit

Permalink
Merge pull request #143 from r-devulap/maint
Browse files Browse the repository at this point in the history
Simplify use of ISA specific routines through a unified API for static methods
  • Loading branch information
sterrettm2 authored Apr 23, 2024
2 parents 8cc37bd + 3a2bde3 commit 4c3ade9
Show file tree
Hide file tree
Showing 37 changed files with 284 additions and 292 deletions.
32 changes: 13 additions & 19 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
CXX ?= g++-12
CFLAGS = -I../src -std=c++17 -O3 $(if $(CXXFLAGS),$(CXXFLAGS),)
EXE = qsort32avx2 argsort kvsort qsortfp16 qsort16 qsort32 qsort64
CXX ?= g++-13
CFLAGS = -I../src -std=c++17 -O3
EXE = kvsort qsortavx2 qsortavx512 qsortspr qsorticl

default: all
all : $(EXE)

qsortfp16: avx512fp-16bit-qsort.cpp
$(CXX) -o qsortfp16 -march=sapphirerapids $(CFLAGS) avx512fp-16bit-qsort.cpp

qsort16: avx512-16bit-qsort.cpp
$(CXX) -o qsort16 -march=icelake-client $(CFLAGS) avx512-16bit-qsort.cpp

qsort32: avx512-32bit-qsort.cpp
$(CXX) -o qsort32 -march=skylake-avx512 $(CFLAGS) avx512-32bit-qsort.cpp
kvsort: avx512-kv.cpp
$(CXX) -o kvsort -mavx512vl -mavx512dq $(CFLAGS) avx512-kv.cpp

qsort32avx2: avx2-32bit-qsort.cpp
$(CXX) -o qsort32avx2 -march=haswell $(CFLAGS) avx2-32bit-qsort.cpp
qsortavx512: skx-avx2.cpp
$(CXX) -o qsortavx512 -mavx512vl -mavx512dq $(CFLAGS) skx-avx2.cpp

qsort64: avx512-64bit-qsort.cpp
$(CXX) -o qsort64 -march=skylake-avx512 $(CFLAGS) avx512-64bit-qsort.cpp
qsortavx2: skx-avx2.cpp
$(CXX) -o qsortavx2 -mavx2 $(CFLAGS) skx-avx2.cpp

argsort: avx512-argsort.cpp
$(CXX) -o argsort -march=skylake-avx512 $(CFLAGS) avx512-argsort.cpp
qsorticl: icl-16bit.cpp
$(CXX) -o qsorticl -mavx512vl -mavx512bw -mavx512dq -mavx512vbmi2 $(CFLAGS) icl-16bit.cpp

kvsort: avx512-kv.cpp
$(CXX) -o kvsort -march=skylake-avx512 $(CFLAGS) avx512-kv.cpp
qsortspr: spr-16bit.cpp
$(CXX) -o qsortspr -mavx512vl -mavx512dq -mavx512vbmi2 -mavx512fp16 $(CFLAGS) spr-16bit.cpp

clean:
$(RM) $(EXE)
11 changes: 0 additions & 11 deletions examples/avx2-32bit-qsort.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions examples/avx512-16bit-qsort.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions examples/avx512-32bit-qsort.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions examples/avx512-64bit-qsort.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions examples/avx512-argsort.cpp

This file was deleted.

24 changes: 12 additions & 12 deletions examples/avx512-kv.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "avx512-64bit-keyvaluesort.hpp"
#include "x86simdsort-static-incl.h"

int main()
{
Expand All @@ -7,17 +7,17 @@ int main()
uint64_t arr2[size];
double arr3[size];
float arr4[size];
avx512_qsort_kv(arr1, arr1, size);
avx512_qsort_kv(arr1, arr2, size);
avx512_qsort_kv(arr1, arr3, size);
avx512_qsort_kv(arr2, arr1, size);
avx512_qsort_kv(arr2, arr2, size);
avx512_qsort_kv(arr2, arr3, size);
avx512_qsort_kv(arr3, arr1, size);
avx512_qsort_kv(arr3, arr2, size);
avx512_qsort_kv(arr1, arr4, size);
avx512_qsort_kv(arr2, arr4, size);
avx512_qsort_kv(arr3, arr4, size);
x86simdsortStatic::keyvalue_qsort(arr1, arr1, size);
x86simdsortStatic::keyvalue_qsort(arr1, arr2, size);
x86simdsortStatic::keyvalue_qsort(arr1, arr3, size);
x86simdsortStatic::keyvalue_qsort(arr2, arr1, size);
x86simdsortStatic::keyvalue_qsort(arr2, arr2, size);
x86simdsortStatic::keyvalue_qsort(arr2, arr3, size);
x86simdsortStatic::keyvalue_qsort(arr3, arr1, size);
x86simdsortStatic::keyvalue_qsort(arr3, arr2, size);
x86simdsortStatic::keyvalue_qsort(arr1, arr4, size);
x86simdsortStatic::keyvalue_qsort(arr2, arr4, size);
x86simdsortStatic::keyvalue_qsort(arr3, arr4, size);
return 0;
return 0;
}
11 changes: 0 additions & 11 deletions examples/avx512fp-16bit-qsort.cpp

This file was deleted.

11 changes: 11 additions & 0 deletions examples/icl-16bit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "x86simdsort-static-incl.h"

int main()
{
const int size = 1000;
short arr[size];
x86simdsortStatic::qsort(arr, size);
x86simdsortStatic::qselect(arr, 10, size);
x86simdsortStatic::partial_qsort(arr, 10, size);
return 0;
}
19 changes: 19 additions & 0 deletions examples/skx-avx2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "x86simdsort-static-incl.h"

int main()
{
const int size = 1000;
double arrd[size];
float arrf[size];
x86simdsortStatic::qsort(arrf, size);
x86simdsortStatic::qsort(arrd, size);
x86simdsortStatic::qselect(arrf, 10, size);
x86simdsortStatic::qselect(arrd, 10, size);
x86simdsortStatic::partial_qsort(arrf, 10, size);
x86simdsortStatic::partial_qsort(arrd, 10, size);
auto arg1 = x86simdsortStatic::argsort(arrf, size);
auto arg2 = x86simdsortStatic::argselect(arrf, 10, size);
auto arg3 = x86simdsortStatic::argsort(arrd, size);
auto arg4 = x86simdsortStatic::argselect(arrd, 10, size);
return 0;
}
11 changes: 11 additions & 0 deletions examples/spr-16bit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "x86simdsort-static-incl.h"

int main()
{
const int size = 1000;
_Float16 arr[size];
x86simdsortStatic::qsort(arr, size);
x86simdsortStatic::qselect(arr, 10, size);
x86simdsortStatic::partial_qsort(arr, 10, size);
return 0;
}
15 changes: 6 additions & 9 deletions lib/x86simdsort-avx2.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
// AVX2 specific routines:
#include "avx2-32bit-qsort.hpp"
#include "avx2-64bit-qsort.hpp"
#include "avx2-32bit-half.hpp"
#include "xss-common-argsort.h"
#include "x86simdsort-static-incl.h"
#include "x86simdsort-internal.h"

#define DEFINE_ALL_METHODS(type) \
template <> \
void qsort(type *arr, size_t arrsize, bool hasnan, bool descending) \
{ \
avx2_qsort(arr, arrsize, hasnan, descending); \
x86simdsortStatic::qsort(arr, arrsize, hasnan, descending); \
} \
template <> \
void qselect( \
type *arr, size_t k, size_t arrsize, bool hasnan, bool descending) \
{ \
avx2_qselect(arr, k, arrsize, hasnan, descending); \
x86simdsortStatic::qselect(arr, k, arrsize, hasnan, descending); \
} \
template <> \
void partial_qsort( \
type *arr, size_t k, size_t arrsize, bool hasnan, bool descending) \
{ \
avx2_partial_qsort(arr, k, arrsize, hasnan, descending); \
x86simdsortStatic::partial_qsort(arr, k, arrsize, hasnan, descending); \
} \
template <> \
std::vector<size_t> argsort( \
type *arr, size_t arrsize, bool hasnan, bool descending) \
{ \
return avx2_argsort(arr, arrsize, hasnan, descending); \
return x86simdsortStatic::argsort(arr, arrsize, hasnan, descending); \
} \
template <> \
std::vector<size_t> argselect( \
type *arr, size_t k, size_t arrsize, bool hasnan) \
{ \
return avx2_argselect(arr, k, arrsize, hasnan); \
return x86simdsortStatic::argselect(arr, k, arrsize, hasnan); \
}

namespace xss {
Expand Down
14 changes: 7 additions & 7 deletions lib/x86simdsort-icl.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// ICL specific routines:
#include "avx512-16bit-qsort.hpp"
#include "x86simdsort-static-incl.h"
#include "x86simdsort-internal.h"

namespace xss {
namespace avx512 {
template <>
void qsort(uint16_t *arr, size_t size, bool hasnan, bool descending)
{
avx512_qsort(arr, size, hasnan, descending);
x86simdsortStatic::qsort(arr, size, hasnan, descending);
}
template <>
void qselect(uint16_t *arr,
Expand All @@ -16,7 +16,7 @@ namespace avx512 {
bool hasnan,
bool descending)
{
avx512_qselect(arr, k, arrsize, hasnan, descending);
x86simdsortStatic::qselect(arr, k, arrsize, hasnan, descending);
}
template <>
void partial_qsort(uint16_t *arr,
Expand All @@ -25,12 +25,12 @@ namespace avx512 {
bool hasnan,
bool descending)
{
avx512_partial_qsort(arr, k, arrsize, hasnan, descending);
x86simdsortStatic::partial_qsort(arr, k, arrsize, hasnan, descending);
}
template <>
void qsort(int16_t *arr, size_t size, bool hasnan, bool descending)
{
avx512_qsort(arr, size, hasnan, descending);
x86simdsortStatic::qsort(arr, size, hasnan, descending);
}
template <>
void qselect(int16_t *arr,
Expand All @@ -39,7 +39,7 @@ namespace avx512 {
bool hasnan,
bool descending)
{
avx512_qselect(arr, k, arrsize, hasnan, descending);
x86simdsortStatic::qselect(arr, k, arrsize, hasnan, descending);
}
template <>
void partial_qsort(int16_t *arr,
Expand All @@ -48,7 +48,7 @@ namespace avx512 {
bool hasnan,
bool descending)
{
avx512_partial_qsort(arr, k, arrsize, hasnan, descending);
x86simdsortStatic::partial_qsort(arr, k, arrsize, hasnan, descending);
}
} // namespace avx512
} // namespace xss
27 changes: 12 additions & 15 deletions lib/x86simdsort-skx.cpp
Original file line number Diff line number Diff line change
@@ -1,71 +1,68 @@
// SKX specific routines:
#include "avx512-32bit-qsort.hpp"
#include "avx512-64bit-keyvaluesort.hpp"
#include "avx512-64bit-argsort.hpp"
#include "avx512-64bit-qsort.hpp"
#include "x86simdsort-static-incl.h"
#include "x86simdsort-internal.h"

#define DEFINE_ALL_METHODS(type) \
template <> \
void qsort(type *arr, size_t arrsize, bool hasnan, bool descending) \
{ \
avx512_qsort(arr, arrsize, hasnan, descending); \
x86simdsortStatic::qsort(arr, arrsize, hasnan, descending); \
} \
template <> \
void qselect( \
type *arr, size_t k, size_t arrsize, bool hasnan, bool descending) \
{ \
avx512_qselect(arr, k, arrsize, hasnan, descending); \
x86simdsortStatic::qselect(arr, k, arrsize, hasnan, descending); \
} \
template <> \
void partial_qsort( \
type *arr, size_t k, size_t arrsize, bool hasnan, bool descending) \
{ \
avx512_partial_qsort(arr, k, arrsize, hasnan, descending); \
x86simdsortStatic::partial_qsort(arr, k, arrsize, hasnan, descending); \
} \
template <> \
std::vector<size_t> argsort( \
type *arr, size_t arrsize, bool hasnan, bool descending) \
{ \
return avx512_argsort(arr, arrsize, hasnan, descending); \
return x86simdsortStatic::argsort(arr, arrsize, hasnan, descending); \
} \
template <> \
std::vector<size_t> argselect( \
type *arr, size_t k, size_t arrsize, bool hasnan) \
{ \
return avx512_argselect(arr, k, arrsize, hasnan); \
return x86simdsortStatic::argselect(arr, k, arrsize, hasnan); \
}

#define DEFINE_KEYVALUE_METHODS(type) \
template <> \
void keyvalue_qsort(type *key, uint64_t *val, size_t arrsize, bool hasnan) \
{ \
avx512_qsort_kv(key, val, arrsize, hasnan); \
x86simdsortStatic::keyvalue_qsort(key, val, arrsize, hasnan); \
} \
template <> \
void keyvalue_qsort(type *key, int64_t *val, size_t arrsize, bool hasnan) \
{ \
avx512_qsort_kv(key, val, arrsize, hasnan); \
x86simdsortStatic::keyvalue_qsort(key, val, arrsize, hasnan); \
} \
template <> \
void keyvalue_qsort(type *key, double *val, size_t arrsize, bool hasnan) \
{ \
avx512_qsort_kv(key, val, arrsize, hasnan); \
x86simdsortStatic::keyvalue_qsort(key, val, arrsize, hasnan); \
} \
template <> \
void keyvalue_qsort(type *key, uint32_t *val, size_t arrsize, bool hasnan) \
{ \
avx512_qsort_kv(key, val, arrsize, hasnan); \
x86simdsortStatic::keyvalue_qsort(key, val, arrsize, hasnan); \
} \
template <> \
void keyvalue_qsort(type *key, int32_t *val, size_t arrsize, bool hasnan) \
{ \
avx512_qsort_kv(key, val, arrsize, hasnan); \
x86simdsortStatic::keyvalue_qsort(key, val, arrsize, hasnan); \
} \
template <> \
void keyvalue_qsort(type *key, float *val, size_t arrsize, bool hasnan) \
{ \
avx512_qsort_kv(key, val, arrsize, hasnan); \
x86simdsortStatic::keyvalue_qsort(key, val, arrsize, hasnan); \
}

namespace xss {
Expand Down
Loading

0 comments on commit 4c3ade9

Please sign in to comment.