Skip to content

Commit 4282fc6

Browse files
authored
[enh] Add clang-format check to github CI (#132)
1 parent 87955f6 commit 4282fc6

25 files changed

+148
-121
lines changed
File renamed without changes.

.github/workflows/linting.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
clang-format:
11+
12+
runs-on: intel-ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Install dependencies
18+
run: |
19+
sudo apt update
20+
sudo apt -y install clang-format
21+
22+
- name: Lint
23+
run: |
24+
find . -type f | grep -P ".*\.(c|cpp|h|hpp)\b" | xargs clang-format -style=file --dry-run -Werror

benchmarks/bench-ipp.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ static void ippargsort(benchmark::State &state, Args &&...args)
6363
// benchmark
6464
for (auto _ : state) {
6565
if constexpr (std::is_same_v<T, float>) {
66-
ippsSortRadixIndexAscend_32f(arr.data(), 4, arg.data(), arrsize, temp);
66+
ippsSortRadixIndexAscend_32f(
67+
arr.data(), 4, arg.data(), arrsize, temp);
6768
}
6869
else if constexpr (std::is_same_v<T, double>) {
69-
ippsSortRadixIndexAscend_64f(arr.data(), 8, arg.data(), arrsize, temp);
70+
ippsSortRadixIndexAscend_64f(
71+
arr.data(), 8, arg.data(), arrsize, temp);
7072
}
7173
else if constexpr (std::is_same_v<T, int32_t>) {
72-
ippsSortRadixIndexAscend_32s(arr.data(), 4, arg.data(), arrsize, temp);
74+
ippsSortRadixIndexAscend_32s(
75+
arr.data(), 4, arg.data(), arrsize, temp);
7376
}
7477
state.PauseTiming();
7578
arr = arr_bkp;

benchmarks/bench-objsort.hpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static constexpr char euclidean[] = "euclidean";
55
static constexpr char taxicab[] = "taxicab";
66
static constexpr char chebyshev[] = "chebyshev";
77

8-
template <typename T, const char* val>
8+
template <typename T, const char *val>
99
struct Point3D {
1010
T x;
1111
T y;
@@ -19,9 +19,7 @@ struct Point3D {
1919
}
2020
T distance()
2121
{
22-
if constexpr (name == "x") {
23-
return x;
24-
}
22+
if constexpr (name == "x") { return x; }
2523
else if constexpr (name == "euclidean") {
2624
return std::sqrt(x * x + y * y + z * z);
2725
}
@@ -77,9 +75,8 @@ static void simdobjsort(benchmark::State &state)
7775
std::vector<T> arr_bkp = arr;
7876
// benchmark
7977
for (auto _ : state) {
80-
x86simdsort::object_qsort(arr.data(), arr.size(), [](T p) {
81-
return p.distance();
82-
});
78+
x86simdsort::object_qsort(
79+
arr.data(), arr.size(), [](T p) { return p.distance(); });
8380
state.PauseTiming();
8481
if (!std::is_sorted(arr.begin(), arr.end(), less_than_key<T>())) {
8582
std::cout << "sorting failed \n";
@@ -90,7 +87,7 @@ static void simdobjsort(benchmark::State &state)
9087
}
9188

9289
#define BENCHMARK_OBJSORT(func, T, type, dist) \
93-
BENCHMARK_TEMPLATE(func, T<type,dist>) \
90+
BENCHMARK_TEMPLATE(func, T<type, dist>) \
9491
->Arg(10e1) \
9592
->Arg(10e2) \
9693
->Arg(10e3) \
@@ -101,12 +98,12 @@ static void simdobjsort(benchmark::State &state)
10198
#define BENCH_ALL(dtype) \
10299
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, x) \
103100
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, x) \
104-
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, taxicab ) \
101+
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, taxicab) \
105102
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, taxicab) \
106103
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, euclidean) \
107104
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, euclidean) \
108105
BENCHMARK_OBJSORT(simdobjsort, Point3D, dtype, chebyshev) \
109-
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, chebyshev) \
106+
BENCHMARK_OBJSORT(scalarobjsort, Point3D, dtype, chebyshev)
110107

111108
BENCH_ALL(double)
112109
BENCH_ALL(float)

benchmarks/bench-qsort.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ static void simdsort(benchmark::State &state, Args &&...args)
3636
}
3737
}
3838

39-
4039
#define BENCH_BOTH_QSORT(type) \
4140
BENCH_SORT(simdsort, type) \
42-
BENCH_SORT(scalarsort, type) \
41+
BENCH_SORT(scalarsort, type)
4342

4443
BENCH_BOTH_QSORT(uint64_t)
4544
BENCH_BOTH_QSORT(int64_t)

benchmarks/bench-vqsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ static void vqsort(benchmark::State &state, Args &&...args)
1414
std::vector<T> arr_bkp = arr;
1515
// benchmark
1616
for (auto _ : state) {
17-
hwy::HWY_NAMESPACE::VQSortStatic(arr.data(), arrsize, hwy::SortAscending());
17+
hwy::HWY_NAMESPACE::VQSortStatic(
18+
arr.data(), arrsize, hwy::SortAscending());
1819
state.PauseTiming();
1920
arr = arr_bkp;
2021
state.ResumeTiming();

benchmarks/bench.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
})))
1313

1414
#define BENCH_SORT(func, type) \
15-
MY_BENCHMARK_CAPTURE( \
16-
func, type, random_128, 128, std::string("random")); \
17-
MY_BENCHMARK_CAPTURE( \
18-
func, type, random_256, 256, std::string("random")); \
19-
MY_BENCHMARK_CAPTURE( \
20-
func, type, random_512, 512, std::string("random")); \
21-
MY_BENCHMARK_CAPTURE( \
22-
func, type, random_1k, 1024, std::string("random")); \
15+
MY_BENCHMARK_CAPTURE(func, type, random_128, 128, std::string("random")); \
16+
MY_BENCHMARK_CAPTURE(func, type, random_256, 256, std::string("random")); \
17+
MY_BENCHMARK_CAPTURE(func, type, random_512, 512, std::string("random")); \
18+
MY_BENCHMARK_CAPTURE(func, type, random_1k, 1024, std::string("random")); \
2319
MY_BENCHMARK_CAPTURE(func, type, random_5k, 5000, std::string("random")); \
2420
MY_BENCHMARK_CAPTURE( \
2521
func, type, random_100k, 100000, std::string("random")); \
@@ -37,7 +33,8 @@
3733
func, type, smallrange_512, 512, std::string("smallrange")); \
3834
MY_BENCHMARK_CAPTURE( \
3935
func, type, smallrange_1k, 1024, std::string("smallrange")); \
40-
MY_BENCHMARK_CAPTURE(func, type, smallrange_5k, 5000, std::string("smallrange")); \
36+
MY_BENCHMARK_CAPTURE( \
37+
func, type, smallrange_5k, 5000, std::string("smallrange")); \
4138
MY_BENCHMARK_CAPTURE( \
4239
func, type, smallrange_100k, 100000, std::string("smallrange")); \
4340
MY_BENCHMARK_CAPTURE( \

examples/avx2-32bit-qsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx2-32bit-qsort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
float arr[size];
67
avx2_qsort(arr, size);

examples/avx512-16bit-qsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx512-16bit-qsort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
short arr[size];
67
avx512_qsort(arr, size);

examples/avx512-32bit-qsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx512-32bit-qsort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
float arr[size];
67
avx512_qsort(arr, size);

examples/avx512-64bit-qsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx512-64bit-qsort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
double arr[size];
67
avx512_qsort(arr, size);

examples/avx512-argsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx512-64bit-argsort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
float arr[size];
67
std::vector<size_t> arg1 = avx512_argsort(arr, size);

examples/avx512-kv.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx512-64bit-keyvaluesort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
int64_t arr1[size];
67
uint64_t arr2[size];

examples/avx512fp-16bit-qsort.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "avx512fp16-16bit-qsort.hpp"
22

3-
int main() {
3+
int main()
4+
{
45
const int size = 1000;
56
_Float16 arr[size];
67
avx512_qsort(arr, size);

lib/x86simdsort-avx2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
void partial_qsort(type *arr, size_t k, size_t arrsize, bool hasnan) \
2121
{ \
2222
avx2_partial_qsort(arr, k, arrsize, hasnan); \
23-
}\
23+
} \
2424
template <> \
2525
std::vector<size_t> argsort(type *arr, size_t arrsize, bool hasnan) \
2626
{ \

lib/x86simdsort-internal.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace avx512 {
1111
XSS_HIDE_SYMBOL void qsort(T *arr, size_t arrsize, bool hasnan = false);
1212
// key-value quicksort
1313
template <typename T1, typename T2>
14-
XSS_EXPORT_SYMBOL void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);
14+
XSS_EXPORT_SYMBOL void
15+
keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan = false);
1516
// quickselect
1617
template <typename T>
1718
XSS_HIDE_SYMBOL void
@@ -35,7 +36,8 @@ namespace avx2 {
3536
XSS_HIDE_SYMBOL void qsort(T *arr, size_t arrsize, bool hasnan = false);
3637
// key-value quicksort
3738
template <typename T1, typename T2>
38-
XSS_EXPORT_SYMBOL void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);
39+
XSS_EXPORT_SYMBOL void
40+
keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan = false);
3941
// quickselect
4042
template <typename T>
4143
XSS_HIDE_SYMBOL void
@@ -59,7 +61,8 @@ namespace scalar {
5961
XSS_HIDE_SYMBOL void qsort(T *arr, size_t arrsize, bool hasnan = false);
6062
// key-value quicksort
6163
template <typename T1, typename T2>
62-
XSS_EXPORT_SYMBOL void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan = false);
64+
XSS_EXPORT_SYMBOL void
65+
keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan = false);
6366
// quickselect
6467
template <typename T>
6568
XSS_HIDE_SYMBOL void

lib/x86simdsort-scalar.h

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44

55
namespace xss {
66
namespace utils {
7-
/* O(1) permute array in place: stolen from
7+
/* O(1) permute array in place: stolen from
88
* http://www.davidespataro.it/apply-a-permutation-to-a-vector */
9-
template<typename T>
10-
void apply_permutation_in_place(T* arr, std::vector<size_t> arg)
11-
{
12-
for(size_t i = 0 ; i < arg.size() ; i++) {
13-
size_t curr = i;
14-
size_t next = arg[curr];
15-
while(next != i)
16-
{
17-
std::swap(arr[curr], arr[next]);
9+
template <typename T>
10+
void apply_permutation_in_place(T *arr, std::vector<size_t> arg)
11+
{
12+
for (size_t i = 0; i < arg.size(); i++) {
13+
size_t curr = i;
14+
size_t next = arg[curr];
15+
while (next != i) {
16+
std::swap(arr[curr], arr[next]);
17+
arg[curr] = curr;
18+
curr = next;
19+
next = arg[next];
20+
}
1821
arg[curr] = curr;
19-
curr = next;
20-
next = arg[next];
2122
}
22-
arg[curr] = curr;
2323
}
24-
}
25-
} // utils
24+
} // namespace utils
2625

2726
namespace scalar {
2827
template <typename T>
@@ -79,7 +78,7 @@ namespace scalar {
7978
return arg;
8079
}
8180
template <typename T1, typename T2>
82-
void keyvalue_qsort(T1 *key, T2* val, size_t arrsize, bool hasnan)
81+
void keyvalue_qsort(T1 *key, T2 *val, size_t arrsize, bool hasnan)
8382
{
8483
std::vector<size_t> arg = argsort(key, arrsize, hasnan);
8584
utils::apply_permutation_in_place(key, arg);

lib/x86simdsort-skx.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,35 @@
3535

3636
#define DEFINE_KEYVALUE_METHODS(type) \
3737
template <> \
38-
void keyvalue_qsort(type *key, uint64_t* val, size_t arrsize, bool hasnan) \
38+
void keyvalue_qsort(type *key, uint64_t *val, size_t arrsize, bool hasnan) \
3939
{ \
4040
avx512_qsort_kv(key, val, arrsize, hasnan); \
4141
} \
4242
template <> \
43-
void keyvalue_qsort(type *key, int64_t* val, size_t arrsize, bool hasnan) \
43+
void keyvalue_qsort(type *key, int64_t *val, size_t arrsize, bool hasnan) \
4444
{ \
4545
avx512_qsort_kv(key, val, arrsize, hasnan); \
4646
} \
4747
template <> \
48-
void keyvalue_qsort(type *key, double* val, size_t arrsize, bool hasnan) \
48+
void keyvalue_qsort(type *key, double *val, size_t arrsize, bool hasnan) \
4949
{ \
5050
avx512_qsort_kv(key, val, arrsize, hasnan); \
5151
} \
5252
template <> \
53-
void keyvalue_qsort(type *key, uint32_t* val, size_t arrsize, bool hasnan) \
53+
void keyvalue_qsort(type *key, uint32_t *val, size_t arrsize, bool hasnan) \
5454
{ \
5555
avx512_qsort_kv(key, val, arrsize, hasnan); \
5656
} \
5757
template <> \
58-
void keyvalue_qsort(type *key, int32_t* val, size_t arrsize, bool hasnan) \
58+
void keyvalue_qsort(type *key, int32_t *val, size_t arrsize, bool hasnan) \
5959
{ \
6060
avx512_qsort_kv(key, val, arrsize, hasnan); \
6161
} \
6262
template <> \
63-
void keyvalue_qsort(type *key, float* val, size_t arrsize, bool hasnan) \
63+
void keyvalue_qsort(type *key, float *val, size_t arrsize, bool hasnan) \
6464
{ \
6565
avx512_qsort_kv(key, val, arrsize, hasnan); \
66-
} \
67-
66+
}
6867

6968
namespace xss {
7069
namespace avx512 {

0 commit comments

Comments
 (0)