-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New hash function alternatives #310
Changes from all commits
d0ffc9f
8eff298
1b2e6ce
83ebf3a
d43cf3a
66e0887
16b17b2
f6b102a
23e97d5
0833638
01f7120
8d59538
fb43c0f
311c831
ff2ce08
216064c
cd7469b
3b58127
ef5d850
d51a972
d72bd38
d550741
339f907
8b1cf87
5d468d5
3d3f730
3d05d30
73e8412
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <defaults.hpp> | ||
#include <utils.hpp> | ||
|
||
#include <cuco/detail/utils.hpp> | ||
#include <cuco/hash_functions.cuh> | ||
|
||
#include <nvbench/nvbench.cuh> | ||
|
||
#include <thrust/device_vector.h> | ||
|
||
#include <cstdint> | ||
|
||
using namespace cuco::benchmark; | ||
using namespace cuco::utility; | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, we consider benchmarks as user-facing code so we should not make these kinds of shortcuts. Since these namespaces are a bit wordy, how about two-character namespace aliases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind the verbosity at all, honestly. 😄 I'd vote |
||
|
||
template <int32_t Words> | ||
struct large_key { | ||
constexpr __host__ __device__ large_key(int32_t seed) noexcept | ||
{ | ||
#pragma unroll Words | ||
for (int32_t i = 0; i < Words; ++i) { | ||
data_[i] = seed; | ||
} | ||
} | ||
|
||
private: | ||
int32_t data_[Words]; | ||
}; | ||
|
||
template <int32_t BlockSize, typename Hasher, typename OutputIt> | ||
__global__ void hash_bench_kernel(Hasher hash, | ||
cuco::detail::index_type n, | ||
OutputIt out, | ||
bool materialize_result) | ||
{ | ||
cuco::detail::index_type const gid = BlockSize * blockIdx.x + threadIdx.x; | ||
cuco::detail::index_type const loop_stride = gridDim.x * BlockSize; | ||
cuco::detail::index_type idx = gid; | ||
typename Hasher::result_type agg = 0; | ||
|
||
while (idx < n) { | ||
typename Hasher::argument_type key(idx); | ||
for (int32_t i = 0; i < 100; ++i) { // execute hash func 100 times | ||
agg += hash(key); | ||
} | ||
idx += loop_stride; | ||
} | ||
|
||
if (materialize_result) { out[gid] = agg; } | ||
} | ||
|
||
/** | ||
* @brief A benchmark evaluating performance of various hash functions | ||
*/ | ||
template <typename Hash> | ||
void hash_eval(nvbench::state& state, nvbench::type_list<Hash>) | ||
{ | ||
bool const materialize_result = false; | ||
constexpr auto block_size = 128; | ||
auto const num_keys = state.get_int64_or_default("NumInputs", defaults::N * 10); | ||
auto const grid_size = SDIV(num_keys, block_size * 16); | ||
|
||
thrust::device_vector<typename Hash::result_type> hash_values((materialize_result) ? num_keys | ||
: 1); | ||
|
||
state.add_element_count(num_keys); | ||
|
||
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
hash_bench_kernel<block_size><<<grid_size, block_size, 0, launch.get_stream()>>>( | ||
Hash{}, num_keys, hash_values.begin(), materialize_result); | ||
}); | ||
} | ||
|
||
NVBENCH_BENCH_TYPES( | ||
hash_eval, | ||
NVBENCH_TYPE_AXES(nvbench::type_list<cuco::murmurhash3_32<nvbench::int32_t>, | ||
cuco::murmurhash3_32<nvbench::int64_t>, | ||
cuco::murmurhash3_32<large_key<32>>, // 32*4bytes | ||
cuco::xxhash_32<nvbench::int32_t>, | ||
cuco::xxhash_32<nvbench::int64_t>, | ||
cuco::xxhash_32<large_key<32>>, | ||
cuco::xxhash_64<nvbench::int32_t>, | ||
cuco::xxhash_64<nvbench::int64_t>, | ||
cuco::xxhash_64<large_key<32>>, | ||
cuco::murmurhash3_fmix_32<nvbench::int32_t>, | ||
cuco::murmurhash3_fmix_64<nvbench::int64_t>>)) | ||
.set_name("hash_function_eval") | ||
.set_type_axes_names({"Hash"}) | ||
.set_max_noise(defaults::MAX_NOISE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Match existing style so this doesn't look like it belongs under the dynamic map benchmarks: