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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ meson:
cd builddir && ninja

clean:
$(RM) -rf $(TESTDIR)/*.o $(UTILS)/*.o testexe benchexe builddir
$(RM) -rf $(TESTDIR)/*.o $(BENCHDIR)/*.o $(UTILS)/*.o testexe benchexe builddir
11 changes: 11 additions & 0 deletions benchmarks/bench-qsort-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef AVX512_BENCH_COMMON
#define AVX512_BENCH_COMMON

#include <benchmark/benchmark.h>
#include "rand_array.h"
#include "cpuinfo.h"
#include "avx512-16bit-qsort.hpp"
#include "avx512-32bit-qsort.hpp"
#include "avx512-64bit-qsort.hpp"

#endif
72 changes: 72 additions & 0 deletions benchmarks/bench_partial_qsort.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "bench-qsort-common.h"

template <typename T>
static void avx512_partial_qsort(benchmark::State& state) {
if (!cpu_has_avx512bw()) {
state.SkipWithMessage("Requires AVX512 BW ISA");
}
if ((sizeof(T) == 2) && (!cpu_has_avx512_vbmi2())) {
state.SkipWithMessage("Requires AVX512 VBMI2 ISA");
}
// Perform setup here
int64_t K = state.range(0);
size_t ARRSIZE = 10000;
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call avx512_partial_qsort */
for (auto _ : state) {
avx512_partial_qsort<T>(arr.data(), K, ARRSIZE);

state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

template <typename T>
static void stdpartialsort(benchmark::State& state) {
// Perform setup here
int64_t K = state.range(0);
size_t ARRSIZE = 10000;
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call std::partial_sort */
for (auto _ : state) {
std::partial_sort(arr.begin(), arr.begin() + K, arr.end());

state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

// Register the function as a benchmark
BENCHMARK(avx512_partial_qsort<float>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<float>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_partial_qsort<uint32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<uint32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_partial_qsort<int32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<int32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);

BENCHMARK(avx512_partial_qsort<double>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<double>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_partial_qsort<uint64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<uint64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_partial_qsort<int64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<int64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);

//BENCHMARK(avx512_partial_qsort<float16>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_partial_qsort<uint16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<uint16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_partial_qsort<int16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdpartialsort<int16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
72 changes: 72 additions & 0 deletions benchmarks/bench_qselect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "bench-qsort-common.h"

template <typename T>
static void avx512_qselect(benchmark::State& state) {
if (!cpu_has_avx512bw()) {
state.SkipWithMessage("Requires AVX512 BW ISA");
}
if ((sizeof(T) == 2) && (!cpu_has_avx512_vbmi2())) {
state.SkipWithMessage("Requires AVX512 VBMI2 ISA");
}
// Perform setup here
int64_t K = state.range(0);
size_t ARRSIZE = 10000;
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call avx512 quickselect */
for (auto _ : state) {
avx512_qselect<T>(arr.data(), K, ARRSIZE);

state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

template <typename T>
static void stdnthelement(benchmark::State& state) {
// Perform setup here
int64_t K = state.range(0);
size_t ARRSIZE = 10000;
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call std::nth_element */
for (auto _ : state) {
std::nth_element(arr.begin(), arr.begin() + K, arr.end());

state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

// Register the function as a benchmark
BENCHMARK(avx512_qselect<float>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<float>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_qselect<uint32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<uint32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_qselect<int32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<int32_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);

BENCHMARK(avx512_qselect<double>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<double>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_qselect<uint64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<uint64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_qselect<int64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<int64_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);

//BENCHMARK(avx512_qselect<float16>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_qselect<uint16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<uint16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(avx512_qselect<int16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
BENCHMARK(stdnthelement<int16_t>)->Arg(10)->Arg(100)->Arg(1000)->Arg(5000);
76 changes: 3 additions & 73 deletions benchmarks/bench_qsort.cpp
Original file line number Diff line number Diff line change
@@ -1,73 +1,3 @@
#include <benchmark/benchmark.h>
#include "rand_array.h"
#include "cpuinfo.h"
#include "avx512-16bit-qsort.hpp"
#include "avx512-32bit-qsort.hpp"
#include "avx512-64bit-qsort.hpp"

template <typename T>
static void avx512_qsort(benchmark::State& state) {
if (!cpu_has_avx512bw()) {
state.SkipWithMessage("Requires AVX512 BW ISA");
}
if ((sizeof(T) == 2) && (!cpu_has_avx512_vbmi2())) {
state.SkipWithMessage("Requires AVX512 VBMI2 ISA");
}
// Perform setup here
size_t ARRSIZE = state.range(0);
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements is reverse order */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call avx512 quicksort */
for (auto _ : state) {
avx512_qsort<T>(arr.data(), ARRSIZE);
state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

template <typename T>
static void stdsort(benchmark::State& state) {
// Perform setup here
size_t ARRSIZE = state.range(0);
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements is reverse order */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call avx512 quicksort */
for (auto _ : state) {
std::sort(arr.begin(), arr.end());
state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

// Register the function as a benchmark
BENCHMARK(avx512_qsort<float>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<float>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<uint32_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<uint32_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<int32_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<int32_t>)->Arg(10000)->Arg(1000000);

BENCHMARK(avx512_qsort<double>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<double>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<uint64_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<uint64_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<int64_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<int64_t>)->Arg(10000)->Arg(10000000);

//BENCHMARK(avx512_qsort<float16>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<uint16_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<uint16_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<int16_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<int16_t>)->Arg(10000)->Arg(10000000);
#include "bench_qsort.hpp"
#include "bench_qselect.hpp"
#include "bench_partial_qsort.hpp"
68 changes: 68 additions & 0 deletions benchmarks/bench_qsort.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "bench-qsort-common.h"

template <typename T>
static void avx512_qsort(benchmark::State& state) {
if (!cpu_has_avx512bw()) {
state.SkipWithMessage("Requires AVX512 BW ISA");
}
if ((sizeof(T) == 2) && (!cpu_has_avx512_vbmi2())) {
state.SkipWithMessage("Requires AVX512 VBMI2 ISA");
}
// Perform setup here
size_t ARRSIZE = state.range(0);
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call avx512 quicksort */
for (auto _ : state) {
avx512_qsort<T>(arr.data(), ARRSIZE);
state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

template <typename T>
static void stdsort(benchmark::State& state) {
// Perform setup here
size_t ARRSIZE = state.range(0);
std::vector<T> arr;
std::vector<T> arr_bkp;

/* Initialize elements */
arr = get_uniform_rand_array<T>(ARRSIZE);
arr_bkp = arr;

/* call std::sort */
for (auto _ : state) {
std::sort(arr.begin(), arr.end());
state.PauseTiming();
arr = arr_bkp;
state.ResumeTiming();
}
}

// Register the function as a benchmark
BENCHMARK(avx512_qsort<float>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<float>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<uint32_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<uint32_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<int32_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<int32_t>)->Arg(10000)->Arg(1000000);

BENCHMARK(avx512_qsort<double>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<double>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<uint64_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<uint64_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<int64_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<int64_t>)->Arg(10000)->Arg(1000000);

//BENCHMARK(avx512_qsort<float16>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<uint16_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<uint16_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(avx512_qsort<int16_t>)->Arg(10000)->Arg(1000000);
BENCHMARK(stdsort<int16_t>)->Arg(10000)->Arg(1000000);
Loading