Skip to content

Commit

Permalink
[enh] Add clang-format check to github CI (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
icfaust authored Feb 26, 2024
1 parent 87955f6 commit 4282fc6
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 121 deletions.
File renamed without changes.
24 changes: 24 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
clang-format:

runs-on: intel-ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt update
sudo apt -y install clang-format
- name: Lint
run: |
find . -type f | grep -P ".*\.(c|cpp|h|hpp)\b" | xargs clang-format -style=file --dry-run -Werror
9 changes: 6 additions & 3 deletions benchmarks/bench-ipp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ static void ippargsort(benchmark::State &state, Args &&...args)
// benchmark
for (auto _ : state) {
if constexpr (std::is_same_v<T, float>) {
ippsSortRadixIndexAscend_32f(arr.data(), 4, arg.data(), arrsize, temp);
ippsSortRadixIndexAscend_32f(
arr.data(), 4, arg.data(), arrsize, temp);
}
else if constexpr (std::is_same_v<T, double>) {
ippsSortRadixIndexAscend_64f(arr.data(), 8, arg.data(), arrsize, temp);
ippsSortRadixIndexAscend_64f(
arr.data(), 8, arg.data(), arrsize, temp);
}
else if constexpr (std::is_same_v<T, int32_t>) {
ippsSortRadixIndexAscend_32s(arr.data(), 4, arg.data(), arrsize, temp);
ippsSortRadixIndexAscend_32s(
arr.data(), 4, arg.data(), arrsize, temp);
}
state.PauseTiming();
arr = arr_bkp;
Expand Down
17 changes: 7 additions & 10 deletions benchmarks/bench-objsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static constexpr char euclidean[] = "euclidean";
static constexpr char taxicab[] = "taxicab";
static constexpr char chebyshev[] = "chebyshev";

template <typename T, const char* val>
template <typename T, const char *val>
struct Point3D {
T x;
T y;
Expand All @@ -19,9 +19,7 @@ struct Point3D {
}
T distance()
{
if constexpr (name == "x") {
return x;
}
if constexpr (name == "x") { return x; }
else if constexpr (name == "euclidean") {
return std::sqrt(x * x + y * y + z * z);
}
Expand Down Expand Up @@ -77,9 +75,8 @@ static void simdobjsort(benchmark::State &state)
std::vector<T> arr_bkp = arr;
// benchmark
for (auto _ : state) {
x86simdsort::object_qsort(arr.data(), arr.size(), [](T p) {
return p.distance();
});
x86simdsort::object_qsort(
arr.data(), arr.size(), [](T p) { return p.distance(); });
state.PauseTiming();
if (!std::is_sorted(arr.begin(), arr.end(), less_than_key<T>())) {
std::cout << "sorting failed \n";
Expand All @@ -90,7 +87,7 @@ static void simdobjsort(benchmark::State &state)
}

#define BENCHMARK_OBJSORT(func, T, type, dist) \
BENCHMARK_TEMPLATE(func, T<type,dist>) \
BENCHMARK_TEMPLATE(func, T<type, dist>) \
->Arg(10e1) \
->Arg(10e2) \
->Arg(10e3) \
Expand All @@ -101,12 +98,12 @@ static void simdobjsort(benchmark::State &state)
#define BENCH_ALL(dtype) \
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, x) \
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, x) \
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, taxicab ) \
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) \
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, chebyshev)

BENCH_ALL(double)
BENCH_ALL(float)
3 changes: 1 addition & 2 deletions benchmarks/bench-qsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ static void simdsort(benchmark::State &state, Args &&...args)
}
}


#define BENCH_BOTH_QSORT(type) \
BENCH_SORT(simdsort, type) \
BENCH_SORT(scalarsort, type) \
BENCH_SORT(scalarsort, type)

BENCH_BOTH_QSORT(uint64_t)
BENCH_BOTH_QSORT(int64_t)
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/bench-vqsort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static void vqsort(benchmark::State &state, Args &&...args)
std::vector<T> arr_bkp = arr;
// benchmark
for (auto _ : state) {
hwy::HWY_NAMESPACE::VQSortStatic(arr.data(), arrsize, hwy::SortAscending());
hwy::HWY_NAMESPACE::VQSortStatic(
arr.data(), arrsize, hwy::SortAscending());
state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
Expand Down
15 changes: 6 additions & 9 deletions benchmarks/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
})))

#define BENCH_SORT(func, type) \
MY_BENCHMARK_CAPTURE( \
func, type, random_128, 128, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, random_256, 256, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, random_512, 512, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, random_1k, 1024, std::string("random")); \
MY_BENCHMARK_CAPTURE(func, type, random_128, 128, std::string("random")); \
MY_BENCHMARK_CAPTURE(func, type, random_256, 256, std::string("random")); \
MY_BENCHMARK_CAPTURE(func, type, random_512, 512, std::string("random")); \
MY_BENCHMARK_CAPTURE(func, type, random_1k, 1024, std::string("random")); \
MY_BENCHMARK_CAPTURE(func, type, random_5k, 5000, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, random_100k, 100000, std::string("random")); \
Expand All @@ -37,7 +33,8 @@
func, type, smallrange_512, 512, std::string("smallrange")); \
MY_BENCHMARK_CAPTURE( \
func, type, smallrange_1k, 1024, std::string("smallrange")); \
MY_BENCHMARK_CAPTURE(func, type, smallrange_5k, 5000, std::string("smallrange")); \
MY_BENCHMARK_CAPTURE( \
func, type, smallrange_5k, 5000, std::string("smallrange")); \
MY_BENCHMARK_CAPTURE( \
func, type, smallrange_100k, 100000, std::string("smallrange")); \
MY_BENCHMARK_CAPTURE( \
Expand Down
3 changes: 2 additions & 1 deletion examples/avx2-32bit-qsort.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx2-32bit-qsort.hpp"

int main() {
int main()
{
const int size = 1000;
float arr[size];
avx2_qsort(arr, size);
Expand Down
3 changes: 2 additions & 1 deletion examples/avx512-16bit-qsort.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx512-16bit-qsort.hpp"

int main() {
int main()
{
const int size = 1000;
short arr[size];
avx512_qsort(arr, size);
Expand Down
3 changes: 2 additions & 1 deletion examples/avx512-32bit-qsort.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx512-32bit-qsort.hpp"

int main() {
int main()
{
const int size = 1000;
float arr[size];
avx512_qsort(arr, size);
Expand Down
3 changes: 2 additions & 1 deletion examples/avx512-64bit-qsort.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx512-64bit-qsort.hpp"

int main() {
int main()
{
const int size = 1000;
double arr[size];
avx512_qsort(arr, size);
Expand Down
3 changes: 2 additions & 1 deletion examples/avx512-argsort.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx512-64bit-argsort.hpp"

int main() {
int main()
{
const int size = 1000;
float arr[size];
std::vector<size_t> arg1 = avx512_argsort(arr, size);
Expand Down
3 changes: 2 additions & 1 deletion examples/avx512-kv.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx512-64bit-keyvaluesort.hpp"

int main() {
int main()
{
const int size = 1000;
int64_t arr1[size];
uint64_t arr2[size];
Expand Down
3 changes: 2 additions & 1 deletion examples/avx512fp-16bit-qsort.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "avx512fp16-16bit-qsort.hpp"

int main() {
int main()
{
const int size = 1000;
_Float16 arr[size];
avx512_qsort(arr, size);
Expand Down
2 changes: 1 addition & 1 deletion lib/x86simdsort-avx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
void partial_qsort(type *arr, size_t k, size_t arrsize, bool hasnan) \
{ \
avx2_partial_qsort(arr, k, arrsize, hasnan); \
}\
} \
template <> \
std::vector<size_t> argsort(type *arr, size_t arrsize, bool hasnan) \
{ \
Expand Down
9 changes: 6 additions & 3 deletions lib/x86simdsort-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace avx512 {
XSS_HIDE_SYMBOL void qsort(T *arr, size_t arrsize, bool hasnan = false);
// key-value quicksort
template <typename T1, typename T2>
XSS_EXPORT_SYMBOL void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);
XSS_EXPORT_SYMBOL void
keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan = false);
// quickselect
template <typename T>
XSS_HIDE_SYMBOL void
Expand All @@ -35,7 +36,8 @@ namespace avx2 {
XSS_HIDE_SYMBOL void qsort(T *arr, size_t arrsize, bool hasnan = false);
// key-value quicksort
template <typename T1, typename T2>
XSS_EXPORT_SYMBOL void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);
XSS_EXPORT_SYMBOL void
keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan = false);
// quickselect
template <typename T>
XSS_HIDE_SYMBOL void
Expand All @@ -59,7 +61,8 @@ namespace scalar {
XSS_HIDE_SYMBOL void qsort(T *arr, size_t arrsize, bool hasnan = false);
// key-value quicksort
template <typename T1, typename T2>
XSS_EXPORT_SYMBOL void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);
XSS_EXPORT_SYMBOL void
keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan = false);
// quickselect
template <typename T>
XSS_HIDE_SYMBOL void
Expand Down
31 changes: 15 additions & 16 deletions lib/x86simdsort-scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

namespace xss {
namespace utils {
/* O(1) permute array in place: stolen from
/* O(1) permute array in place: stolen from
* http://www.davidespataro.it/apply-a-permutation-to-a-vector */
template<typename T>
void apply_permutation_in_place(T* arr, std::vector<size_t> arg)
{
for(size_t i = 0 ; i < arg.size() ; i++) {
size_t curr = i;
size_t next = arg[curr];
while(next != i)
{
std::swap(arr[curr], arr[next]);
template <typename T>
void apply_permutation_in_place(T *arr, std::vector<size_t> arg)
{
for (size_t i = 0; i < arg.size(); i++) {
size_t curr = i;
size_t next = arg[curr];
while (next != i) {
std::swap(arr[curr], arr[next]);
arg[curr] = curr;
curr = next;
next = arg[next];
}
arg[curr] = curr;
curr = next;
next = arg[next];
}
arg[curr] = curr;
}
}
} // utils
} // namespace utils

namespace scalar {
template <typename T>
Expand Down Expand Up @@ -79,7 +78,7 @@ namespace scalar {
return arg;
}
template <typename T1, typename T2>
void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan)
void keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan)
{
std::vector<size_t> arg = argsort(key, arrsize, hasnan);
utils::apply_permutation_in_place(key, arg);
Expand Down
15 changes: 7 additions & 8 deletions lib/x86simdsort-skx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,35 @@

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

}

namespace xss {
namespace avx512 {
Expand Down
Loading

0 comments on commit 4282fc6

Please sign in to comment.