Skip to content
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

Erase Functionality for static_map #142

Merged
merged 28 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0215463
basic erase functionality added, still need to modify insert/find
niskos99 Feb 22, 2022
26dd44f
erase appears to be working
niskos99 Feb 23, 2022
9e0821c
cg erase
niskos99 Feb 23, 2022
1777a51
cg erase bug fix
niskos99 Feb 23, 2022
d84e3b8
minor changes
niskos99 Feb 23, 2022
acc7941
fix to CG insert
niskos99 Feb 25, 2022
19aa8bb
insert benchmarking fix
niskos99 Feb 25, 2022
0e66d28
API improvements
niskos99 Mar 10, 2022
364fb1d
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Mar 10, 2022
7f84d3d
typo fix for non-CG contains
niskos99 Mar 10, 2022
c2bcc25
style changes
niskos99 Mar 18, 2022
9deba51
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Mar 18, 2022
2872f1d
style and documentation, strong-type wrappers for sentinel values
niskos99 Mar 18, 2022
666ff5b
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Mar 18, 2022
9781a6b
copyright notices corrected
niskos99 Mar 18, 2022
7faef67
sentinel wrappers moved to separate file
niskos99 Mar 21, 2022
c9a7014
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Mar 21, 2022
c0d713c
sentinel constructors added for ctad support
niskos99 Mar 22, 2022
d92898c
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Mar 22, 2022
5bca985
CI fix
niskos99 Mar 23, 2022
60e4b73
switch to fetch_add for erase kernels
niskos99 Mar 24, 2022
4feef9c
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Mar 24, 2022
a429d8d
minor doc/style changes
niskos99 Apr 2, 2022
dc61121
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Apr 2, 2022
753641c
prevent implicit conversion of sentinels during construction
niskos99 Apr 5, 2022
03c089c
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] Apr 5, 2022
02e861e
Merge remote-tracking branch 'upstream/dev' into static_map_erase
PointKernel May 6, 2022
7b841a8
Fix a sentinel bug in test
PointKernel May 6, 2022
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
89 changes: 53 additions & 36 deletions benchmarks/hash_table/static_map_bench.cu
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,24 @@ static void BM_static_map_insert(::benchmark::State& state)
}

thrust::device_vector<cuco::pair_type<Key, Value>> d_pairs(h_pairs);
thrust::device_vector<Key> d_keys(h_keys);

for (auto _ : state) {
state.ResumeTiming();
state.PauseTiming();
map_type map{size, -1, -1};
state.ResumeTiming();

cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);

cudaEventRecord(start);
map.insert(d_pairs.begin(), d_pairs.end());
cudaEventRecord(stop);
cudaEventSynchronize(stop);

state.PauseTiming();
float ms;
cudaEventElapsedTime(&ms, start, stop);

state.SetIterationTime(ms / 1000);
}

state.SetBytesProcessed((sizeof(Key) + sizeof(Value)) * int64_t(state.iterations()) *
Expand Down Expand Up @@ -143,50 +151,59 @@ static void BM_static_map_search_all(::benchmark::State& state)
int64_t(state.range(0)));
}

BENCHMARK_TEMPLATE(BM_static_map_insert, int32_t, int32_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
template <typename Key, typename Value, dist_type Dist>
static void BM_static_map_erase_all(::benchmark::State& state)
{
using map_type = cuco::static_map<Key, Value>;

BENCHMARK_TEMPLATE(BM_static_map_search_all, int32_t, int32_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
std::size_t num_keys = state.range(0);
float occupancy = state.range(1) / float{100};
std::size_t size = num_keys / occupancy;

BENCHMARK_TEMPLATE(BM_static_map_insert, int32_t, int32_t, dist_type::UNIFORM)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
// static map with erase support
map_type map{size, -1, -1, -2};
auto view = map.get_device_mutable_view();

BENCHMARK_TEMPLATE(BM_static_map_search_all, int32_t, int32_t, dist_type::UNIFORM)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
std::vector<Key> h_keys(num_keys);
std::vector<Value> h_values(num_keys);
std::vector<cuco::pair_type<Key, Value>> h_pairs(num_keys);
std::vector<Value> h_results(num_keys);

BENCHMARK_TEMPLATE(BM_static_map_insert, int32_t, int32_t, dist_type::GAUSSIAN)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
generate_keys<Dist, Key>(h_keys.begin(), h_keys.end());

BENCHMARK_TEMPLATE(BM_static_map_search_all, int32_t, int32_t, dist_type::GAUSSIAN)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
for (auto i = 0; i < num_keys; ++i) {
Key key = h_keys[i];
Value val = h_keys[i];
h_pairs[i].first = key;
h_pairs[i].second = val;
}

BENCHMARK_TEMPLATE(BM_static_map_insert, int64_t, int64_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
thrust::device_vector<Key> d_keys(h_keys);
thrust::device_vector<bool> d_results(num_keys);
thrust::device_vector<cuco::pair_type<Key, Value>> d_pairs(h_pairs);

BENCHMARK_TEMPLATE(BM_static_map_search_all, int64_t, int64_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
for (auto _ : state) {
state.PauseTiming();
map.insert(d_pairs.begin(), d_pairs.end());
state.ResumeTiming();

BENCHMARK_TEMPLATE(BM_static_map_insert, int64_t, int64_t, dist_type::UNIFORM)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
map.erase(d_keys.begin(), d_keys.end());
}

BENCHMARK_TEMPLATE(BM_static_map_search_all, int64_t, int64_t, dist_type::UNIFORM)
state.SetBytesProcessed((sizeof(Key) + sizeof(Value)) * int64_t(state.iterations()) *
int64_t(state.range(0)));
}
PointKernel marked this conversation as resolved.
Show resolved Hide resolved

BENCHMARK_TEMPLATE(BM_static_map_insert, int32_t, int32_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
->Apply(generate_size_and_occupancy)
->UseManualTime();

BENCHMARK_TEMPLATE(BM_static_map_insert, int64_t, int64_t, dist_type::GAUSSIAN)
BENCHMARK_TEMPLATE(BM_static_map_erase_all, int32_t, int32_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);

BENCHMARK_TEMPLATE(BM_static_map_search_all, int64_t, int64_t, dist_type::GAUSSIAN)
BENCHMARK_TEMPLATE(BM_static_map_insert, int32_t, int32_t, dist_type::UNIQUE)
->Unit(benchmark::kMillisecond)
->Apply(generate_size_and_occupancy);
->Apply(generate_size_and_occupancy)
->UseManualTime();
22 changes: 21 additions & 1 deletion include/cuco/detail/error.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2022, NVIDIA CORPORATION.
PointKernel marked this conversation as resolved.
Show resolved Hide resolved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,3 +80,23 @@ struct cuda_error : public std::runtime_error {
cudaError_t const status = (expr); \
assert(cudaSuccess == status); \
} while (0)

/**
* @brief Macro for checking runtime conditions that throws an exception when
* a condition is violated.
*
* Example usage:
*
* @code
* CUCO_RUNTIME_EXPECTS(key == value, "Key value mismatch");
* @endcode
*
* @param[in] cond Expression that evaluates to true or false
* @param[in] reason String literal description of the reason that cond is
* expected to be true
* @throw std::runtime_error if the condition evaluates to false.
*/
#define CUCO_RUNTIME_EXPECTS(cond, reason) \
(!!(cond)) ? static_cast<void>(0) \
: throw std::runtime_error("cuco failure at: " __FILE__ \
":" CUCO_STRINGIFY(__LINE__) ": " reason)
Loading