Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions benchmarks/bench-argsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,30 @@ static void simdargsort(benchmark::State &state, Args &&...args)
}
}

template <typename T, class... Args>
static void simd_ordern_argsort(benchmark::State &state, Args &&...args)
{
// get args
auto args_tuple = std::make_tuple(std::move(args)...);
size_t arrsize = std::get<0>(args_tuple);
std::string arrtype = std::get<1>(args_tuple);
// set up array
std::vector<T> arr = get_array<T>(arrtype, arrsize);
std::vector<int32_t> arg(arrsize);
std::iota(arg.begin(), arg.end(), 0);
// benchmark
for (auto _ : state) {
std::vector<T> arr_bkp = arr;
x86simdsort::keyvalue_qsort(arr_bkp.data(), arg.data(), arrsize);
state.PauseTiming();
std::iota(arg.begin(), arg.end(), 0);
state.ResumeTiming();
}
}

#define BENCH_BOTH(type) \
BENCH_SORT(simdargsort, type) \
BENCH_SORT(simd_ordern_argsort, type) \
BENCH_SORT(scalarargsort, type)

BENCH_BOTH(int64_t)
Expand Down
85 changes: 85 additions & 0 deletions benchmarks/bench-ipp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "bench.h"
#include "ipp.h"

template <typename T, class... Args>
static void ippsort(benchmark::State &state, Args &&...args)
{
auto args_tuple = std::make_tuple(std::move(args)...);
size_t arrsize = std::get<0>(args_tuple);
/* IPP set up */
int bufsize = 10;
if constexpr (std::is_same_v<T, float>) {
ippsSortRadixGetBufferSize(arrsize, ipp32f, &bufsize);
}
else if constexpr (std::is_same_v<T, double>) {
ippsSortRadixGetBufferSize(arrsize, ipp64f, &bufsize);
}
unsigned char *temp = new unsigned char[bufsize];

// Get args
std::string arrtype = std::get<1>(args_tuple);
// set up array
std::vector<T> arr = get_array<T>(arrtype, arrsize);
std::vector<T> arr_bkp = arr;
// benchmark
for (auto _ : state) {
if constexpr (std::is_same_v<T, float>) {
ippsSortRadixAscend_32f_I(arr.data(), arrsize, temp);
}
else if constexpr (std::is_same_v<T, double>) {
ippsSortRadixAscend_64f_I(arr.data(), arrsize, temp);
}
state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

template <typename T, class... Args>
static void ippargsort(benchmark::State &state, Args &&...args)
{
auto args_tuple = std::make_tuple(std::move(args)...);
size_t arrsize = std::get<0>(args_tuple);
/* IPP set up */
int bufsize = 10;
if constexpr (std::is_same_v<T, float>) {
ippsSortRadixIndexGetBufferSize(arrsize, ipp32f, &bufsize);
}
else if constexpr (std::is_same_v<T, double>) {
ippsSortRadixIndexGetBufferSize(arrsize, ipp64f, &bufsize);
}
else if constexpr (std::is_same_v<T, int32_t>) {
ippsSortRadixIndexGetBufferSize(arrsize, ipp32s, &bufsize);
}
unsigned char *temp = new unsigned char[bufsize];

// set up array
std::string arrtype = std::get<1>(args_tuple);
std::vector<T> arr = get_array<T>(arrtype, arrsize);
std::vector<T> arr_bkp = arr;
std::vector<int32_t> arg(arrsize);
std::iota(arg.begin(), arg.end(), 0);

// benchmark
for (auto _ : state) {
if constexpr (std::is_same_v<T, float>) {
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);
}
else if constexpr (std::is_same_v<T, int32_t>) {
ippsSortRadixIndexAscend_32s(arr.data(), 4, arg.data(), arrsize, temp);
}
state.PauseTiming();
arr = arr_bkp;
std::iota(arg.begin(), arg.end(), 0);
state.ResumeTiming();
}
}

BENCH_SORT(ippsort, double)
BENCH_SORT(ippsort, float)
BENCH_SORT(ippargsort, double)
BENCH_SORT(ippargsort, float)
BENCH_SORT(ippargsort, int32_t)
3 changes: 2 additions & 1 deletion benchmarks/bench-qsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ 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
2 changes: 2 additions & 0 deletions benchmarks/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
func, type, random_1m, 1000000, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, random_10m, 10000000, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, random_100m, 100000000, std::string("random")); \
MY_BENCHMARK_CAPTURE( \
func, type, smallrange_128, 128, std::string("smallrange")); \
MY_BENCHMARK_CAPTURE( \
Expand Down
15 changes: 13 additions & 2 deletions benchmarks/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ libbench += static_library('bench_qsort',
cpp_args : ['-O3'],
)

if fs.is_file('highway/hwy/contrib/sort/vqsort-inl.h')
hwy = include_directories('highway')
if benchvq and fs.is_file('../highway/hwy/contrib/sort/vqsort-inl.h')
hwy = include_directories('../highway')
libbench += static_library('bench_vqsort',
files(
'bench-vqsort.cpp',
Expand All @@ -20,3 +20,14 @@ if fs.is_file('highway/hwy/contrib/sort/vqsort-inl.h')
cpp_args : ['-O3', '-march=native'],
)
endif

if benchipp
libbench += static_library('bench_ippsort',
files(
'bench-ipp.cpp',
),
dependencies: gbench_dep,
include_directories : [src, lib, utils],
cpp_args : ['-O3', '-march=native'],
)
endif
17 changes: 16 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ bench = include_directories('benchmarks')
utils = include_directories('utils')
tests = include_directories('tests')

# Add IPP sort to benchmarks:
benchipp = false
ipplink = []
if get_option('build_ippbench')
benchipp = true
ipplink = ['-lipps', '-lippcore']
endif

# Add google vqsort to benchmarks:
benchvq = false
if get_option('build_vqsortbench')
benchvq = true
endif

fp16code = '''#include<immintrin.h>
int main() {
__m512h temp = _mm512_set1_ph(1.0f);
Expand Down Expand Up @@ -50,13 +64,14 @@ if get_option('build_tests')
endif

# Build benchmarking suite if option build_benchmarks is set to true

if get_option('build_benchmarks')
gbench_dep = dependency('benchmark', required : true, static: false)
subdir('benchmarks')
benchexe = executable('benchexe',
include_directories : [src, lib, utils, bench],
dependencies : [gbench_dep],
link_args: ['-lbenchmark_main'],
link_args: ['-lbenchmark_main', ipplink],
link_whole : [libbench],
link_with : libsimdsort,
)
Expand Down
4 changes: 4 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ option('build_tests', type : 'boolean', value : false,
description : 'Build test suite (default: "false").')
option('build_benchmarks', type : 'boolean', value : false,
description : 'Build benchmarking suite (default: "false").')
option('build_ippbench', type : 'boolean', value : false,
description : 'Add IPP sort to benchmarks (default: "false").')
option('build_vqsortbench', type : 'boolean', value : false,
description : 'Add google vqsort to benchmarks (default: "false").')
8 changes: 7 additions & 1 deletion run-bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
if args.benchcompare:
baseline = ""
contender = ""
if "vqsort" in args.benchcompare:
if "ippsort" in args.benchcompare:
baseline = "ippsort.*" + filterb
contender = "simdsort.*" + filterb
elif "ippargsort" in args.benchcompare:
baseline = "ippargsort.*" + filterb
contender = "simd_ordern_argsort.*" + filterb
elif "vqsort" in args.benchcompare:
baseline = "vqsort.*" + filterb
contender = "simdsort.*" + filterb
elif "qsort" in args.benchcompare:
Expand Down
2 changes: 1 addition & 1 deletion scripts/bench-compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [ ! -d .bench/google-benchmark ]; then
fi
compare=$(realpath .bench/google-benchmark/tools/compare.py)

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