-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from r-devulap/key-value
Add key-value sort to runtime dispatch
- Loading branch information
Showing
12 changed files
with
244 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "x86simdsort-scalar.h" | ||
|
||
template <typename T, class... Args> | ||
static void scalarkvsort(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> key = get_array<T>(arrtype, arrsize); | ||
std::vector<T> val = get_array<T>("random", arrsize); | ||
std::vector<T> key_bkp = key; | ||
// benchmark | ||
for (auto _ : state) { | ||
xss::scalar::keyvalue_qsort(key.data(), val.data(), arrsize, false); | ||
state.PauseTiming(); | ||
key = key_bkp; | ||
state.ResumeTiming(); | ||
} | ||
} | ||
|
||
template <typename T, class... Args> | ||
static void simdkvsort(benchmark::State &state, Args &&...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> key = get_array<T>(arrtype, arrsize); | ||
std::vector<T> val = get_array<T>("random", arrsize); | ||
std::vector<T> key_bkp = key; | ||
// benchmark | ||
for (auto _ : state) { | ||
x86simdsort::keyvalue_qsort(key.data(), val.data(), arrsize); | ||
state.PauseTiming(); | ||
key = key_bkp; | ||
state.ResumeTiming(); | ||
} | ||
} | ||
|
||
#define BENCH_BOTH_KVSORT(type) \ | ||
BENCH_SORT(simdkvsort, type) \ | ||
BENCH_SORT(scalarkvsort, type) | ||
|
||
BENCH_BOTH_KVSORT(uint64_t) | ||
BENCH_BOTH_KVSORT(int64_t) | ||
BENCH_BOTH_KVSORT(double) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************* | ||
* * Copyright (C) 2022-2023 Intel Corporation | ||
* * SPDX-License-Identifier: BSD-3-Clause | ||
* *******************************************/ | ||
|
||
#include "rand_array.h" | ||
#include "x86simdsort.h" | ||
#include "x86simdsort-scalar.h" | ||
#include <gtest/gtest.h> | ||
|
||
template <typename T> | ||
class simdkvsort : public ::testing::Test { | ||
public: | ||
simdkvsort() | ||
{ | ||
std::iota(arrsize.begin(), arrsize.end(), 1); | ||
arrtype = {"random", | ||
"constant", | ||
"sorted", | ||
"reverse", | ||
"smallrange", | ||
"max_at_the_end", | ||
"rand_max"}; | ||
} | ||
std::vector<std::string> arrtype; | ||
std::vector<size_t> arrsize = std::vector<size_t>(1024); | ||
}; | ||
|
||
TYPED_TEST_SUITE_P(simdkvsort); | ||
|
||
TYPED_TEST_P(simdkvsort, test_kvsort) | ||
{ | ||
using T1 = typename std::tuple_element<0, decltype(TypeParam())>::type; | ||
using T2 = typename std::tuple_element<1, decltype(TypeParam())>::type; | ||
for (auto type : this->arrtype) { | ||
bool hasnan = (type == "rand_with_nan") ? true : false; | ||
for (auto size : this->arrsize) { | ||
std::vector<T1> key = get_array<T1>(type, size); | ||
std::vector<T2> val = get_array<T2>(type, size); | ||
std::vector<T1> key_bckp = key; | ||
std::vector<T2> val_bckp = val; | ||
x86simdsort::keyvalue_qsort(key.data(), val.data(), size, hasnan); | ||
xss::scalar::keyvalue_qsort(key_bckp.data(), val_bckp.data(), size, hasnan); | ||
ASSERT_EQ(key, key_bckp); | ||
const bool hasDuplicates = std::adjacent_find(key.begin(), key.end()) != key.end(); | ||
if (!hasDuplicates) { | ||
ASSERT_EQ(val, val_bckp); | ||
} | ||
key.clear(); val.clear(); | ||
key_bckp.clear(); val_bckp.clear(); | ||
} | ||
} | ||
} | ||
|
||
REGISTER_TYPED_TEST_SUITE_P(simdkvsort, test_kvsort); | ||
|
||
using QKVSortTestTypes = testing::Types<std::tuple<double, double>, | ||
std::tuple<double, uint64_t>, | ||
std::tuple<double, int64_t>, | ||
std::tuple<uint64_t, double>, | ||
std::tuple<uint64_t, uint64_t>, | ||
std::tuple<uint64_t, int64_t>, | ||
std::tuple<int64_t, double>, | ||
std::tuple<int64_t, uint64_t>, | ||
std::tuple<int64_t, int64_t>>; | ||
|
||
INSTANTIATE_TYPED_TEST_SUITE_P(xss, simdkvsort, QKVSortTestTypes); |
Oops, something went wrong.