Skip to content

Commit 978731d

Browse files
author
Raghuveer Devulapalli
authored
Merge pull request #121 from r-devulap/ipp
Add IPP sort to benchmarks
2 parents 4615c11 + a9f1ab7 commit 978731d

File tree

9 files changed

+152
-6
lines changed

9 files changed

+152
-6
lines changed

benchmarks/bench-argsort.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,30 @@ static void simdargsort(benchmark::State &state, Args &&...args)
4545
}
4646
}
4747

48+
template <typename T, class... Args>
49+
static void simd_ordern_argsort(benchmark::State &state, Args &&...args)
50+
{
51+
// get args
52+
auto args_tuple = std::make_tuple(std::move(args)...);
53+
size_t arrsize = std::get<0>(args_tuple);
54+
std::string arrtype = std::get<1>(args_tuple);
55+
// set up array
56+
std::vector<T> arr = get_array<T>(arrtype, arrsize);
57+
std::vector<int32_t> arg(arrsize);
58+
std::iota(arg.begin(), arg.end(), 0);
59+
// benchmark
60+
for (auto _ : state) {
61+
std::vector<T> arr_bkp = arr;
62+
x86simdsort::keyvalue_qsort(arr_bkp.data(), arg.data(), arrsize);
63+
state.PauseTiming();
64+
std::iota(arg.begin(), arg.end(), 0);
65+
state.ResumeTiming();
66+
}
67+
}
68+
4869
#define BENCH_BOTH(type) \
4970
BENCH_SORT(simdargsort, type) \
71+
BENCH_SORT(simd_ordern_argsort, type) \
5072
BENCH_SORT(scalarargsort, type)
5173

5274
BENCH_BOTH(int64_t)

benchmarks/bench-ipp.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "bench.h"
2+
#include "ipp.h"
3+
4+
template <typename T, class... Args>
5+
static void ippsort(benchmark::State &state, Args &&...args)
6+
{
7+
auto args_tuple = std::make_tuple(std::move(args)...);
8+
size_t arrsize = std::get<0>(args_tuple);
9+
/* IPP set up */
10+
int bufsize = 10;
11+
if constexpr (std::is_same_v<T, float>) {
12+
ippsSortRadixGetBufferSize(arrsize, ipp32f, &bufsize);
13+
}
14+
else if constexpr (std::is_same_v<T, double>) {
15+
ippsSortRadixGetBufferSize(arrsize, ipp64f, &bufsize);
16+
}
17+
unsigned char *temp = new unsigned char[bufsize];
18+
19+
// Get args
20+
std::string arrtype = std::get<1>(args_tuple);
21+
// set up array
22+
std::vector<T> arr = get_array<T>(arrtype, arrsize);
23+
std::vector<T> arr_bkp = arr;
24+
// benchmark
25+
for (auto _ : state) {
26+
if constexpr (std::is_same_v<T, float>) {
27+
ippsSortRadixAscend_32f_I(arr.data(), arrsize, temp);
28+
}
29+
else if constexpr (std::is_same_v<T, double>) {
30+
ippsSortRadixAscend_64f_I(arr.data(), arrsize, temp);
31+
}
32+
state.PauseTiming();
33+
arr = arr_bkp;
34+
state.ResumeTiming();
35+
}
36+
}
37+
38+
template <typename T, class... Args>
39+
static void ippargsort(benchmark::State &state, Args &&...args)
40+
{
41+
auto args_tuple = std::make_tuple(std::move(args)...);
42+
size_t arrsize = std::get<0>(args_tuple);
43+
/* IPP set up */
44+
int bufsize = 10;
45+
if constexpr (std::is_same_v<T, float>) {
46+
ippsSortRadixIndexGetBufferSize(arrsize, ipp32f, &bufsize);
47+
}
48+
else if constexpr (std::is_same_v<T, double>) {
49+
ippsSortRadixIndexGetBufferSize(arrsize, ipp64f, &bufsize);
50+
}
51+
else if constexpr (std::is_same_v<T, int32_t>) {
52+
ippsSortRadixIndexGetBufferSize(arrsize, ipp32s, &bufsize);
53+
}
54+
unsigned char *temp = new unsigned char[bufsize];
55+
56+
// set up array
57+
std::string arrtype = std::get<1>(args_tuple);
58+
std::vector<T> arr = get_array<T>(arrtype, arrsize);
59+
std::vector<T> arr_bkp = arr;
60+
std::vector<int32_t> arg(arrsize);
61+
std::iota(arg.begin(), arg.end(), 0);
62+
63+
// benchmark
64+
for (auto _ : state) {
65+
if constexpr (std::is_same_v<T, float>) {
66+
ippsSortRadixIndexAscend_32f(arr.data(), 4, arg.data(), arrsize, temp);
67+
}
68+
else if constexpr (std::is_same_v<T, double>) {
69+
ippsSortRadixIndexAscend_64f(arr.data(), 8, arg.data(), arrsize, temp);
70+
}
71+
else if constexpr (std::is_same_v<T, int32_t>) {
72+
ippsSortRadixIndexAscend_32s(arr.data(), 4, arg.data(), arrsize, temp);
73+
}
74+
state.PauseTiming();
75+
arr = arr_bkp;
76+
std::iota(arg.begin(), arg.end(), 0);
77+
state.ResumeTiming();
78+
}
79+
}
80+
81+
BENCH_SORT(ippsort, double)
82+
BENCH_SORT(ippsort, float)
83+
BENCH_SORT(ippargsort, double)
84+
BENCH_SORT(ippargsort, float)
85+
BENCH_SORT(ippargsort, int32_t)

benchmarks/bench-qsort.hpp

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

39+
3940
#define BENCH_BOTH_QSORT(type) \
4041
BENCH_SORT(simdsort, type) \
41-
BENCH_SORT(scalarsort, type)
42+
BENCH_SORT(scalarsort, type) \
4243

4344
BENCH_BOTH_QSORT(uint64_t)
4445
BENCH_BOTH_QSORT(int64_t)

benchmarks/bench.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
func, type, random_1m, 1000000, std::string("random")); \
2828
MY_BENCHMARK_CAPTURE( \
2929
func, type, random_10m, 10000000, std::string("random")); \
30+
MY_BENCHMARK_CAPTURE( \
31+
func, type, random_100m, 100000000, std::string("random")); \
3032
MY_BENCHMARK_CAPTURE( \
3133
func, type, smallrange_128, 128, std::string("smallrange")); \
3234
MY_BENCHMARK_CAPTURE( \

benchmarks/meson.build

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ libbench += static_library('bench_qsort',
99
cpp_args : ['-O3'],
1010
)
1111

12-
if fs.is_file('highway/hwy/contrib/sort/vqsort-inl.h')
13-
hwy = include_directories('highway')
12+
if benchvq and fs.is_file('../highway/hwy/contrib/sort/vqsort-inl.h')
13+
hwy = include_directories('../highway')
1414
libbench += static_library('bench_vqsort',
1515
files(
1616
'bench-vqsort.cpp',
@@ -20,3 +20,14 @@ if fs.is_file('highway/hwy/contrib/sort/vqsort-inl.h')
2020
cpp_args : ['-O3', '-march=native'],
2121
)
2222
endif
23+
24+
if benchipp
25+
libbench += static_library('bench_ippsort',
26+
files(
27+
'bench-ipp.cpp',
28+
),
29+
dependencies: gbench_dep,
30+
include_directories : [src, lib, utils],
31+
cpp_args : ['-O3', '-march=native'],
32+
)
33+
endif

meson.build

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ bench = include_directories('benchmarks')
1010
utils = include_directories('utils')
1111
tests = include_directories('tests')
1212

13+
# Add IPP sort to benchmarks:
14+
benchipp = false
15+
ipplink = []
16+
if get_option('build_ippbench')
17+
benchipp = true
18+
ipplink = ['-lipps', '-lippcore']
19+
endif
20+
21+
# Add google vqsort to benchmarks:
22+
benchvq = false
23+
if get_option('build_vqsortbench')
24+
benchvq = true
25+
endif
26+
1327
fp16code = '''#include<immintrin.h>
1428
int main() {
1529
__m512h temp = _mm512_set1_ph(1.0f);
@@ -50,13 +64,14 @@ if get_option('build_tests')
5064
endif
5165

5266
# Build benchmarking suite if option build_benchmarks is set to true
67+
5368
if get_option('build_benchmarks')
5469
gbench_dep = dependency('benchmark', required : true, static: false)
5570
subdir('benchmarks')
5671
benchexe = executable('benchexe',
5772
include_directories : [src, lib, utils, bench],
5873
dependencies : [gbench_dep],
59-
link_args: ['-lbenchmark_main'],
74+
link_args: ['-lbenchmark_main', ipplink],
6075
link_whole : [libbench],
6176
link_with : libsimdsort,
6277
)

meson_options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ option('build_tests', type : 'boolean', value : false,
22
description : 'Build test suite (default: "false").')
33
option('build_benchmarks', type : 'boolean', value : false,
44
description : 'Build benchmarking suite (default: "false").')
5+
option('build_ippbench', type : 'boolean', value : false,
6+
description : 'Add IPP sort to benchmarks (default: "false").')
7+
option('build_vqsortbench', type : 'boolean', value : false,
8+
description : 'Add google vqsort to benchmarks (default: "false").')

run-bench.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
if args.benchcompare:
2424
baseline = ""
2525
contender = ""
26-
if "vqsort" in args.benchcompare:
26+
if "ippsort" in args.benchcompare:
27+
baseline = "ippsort.*" + filterb
28+
contender = "simdsort.*" + filterb
29+
elif "ippargsort" in args.benchcompare:
30+
baseline = "ippargsort.*" + filterb
31+
contender = "simd_ordern_argsort.*" + filterb
32+
elif "vqsort" in args.benchcompare:
2733
baseline = "vqsort.*" + filterb
2834
contender = "simdsort.*" + filterb
2935
elif "qsort" in args.benchcompare:

scripts/bench-compare.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if [ ! -d .bench/google-benchmark ]; then
1111
fi
1212
compare=$(realpath .bench/google-benchmark/tools/compare.py)
1313

14-
meson setup -Dbuild_benchmarks=true --warnlevel 0 --buildtype release builddir-${branch}
14+
meson setup -Dbuild_benchmarks=true -Dbuild_ippbench=true --warnlevel 0 --buildtype release builddir-${branch}
1515
cd builddir-${branch}
1616
ninja
1717
$compare filters ./benchexe $1 $2 --benchmark_repetitions=$3

0 commit comments

Comments
 (0)