-
Notifications
You must be signed in to change notification settings - Fork 106
Add static_map::insert_or_apply aka reduce-by-key #515
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
84fd0b1
WIP add insert_or_apply
sleeepyjack 0d76d1e
Fix unit test
sleeepyjack 54e2697
Add benchmark
sleeepyjack 4dd73b2
Merge branch 'dev' into insert-or-apply
srinivasyadav18 2561965
Update insert_or_apply to latest dev
srinivasyadav18 5e94f06
Update insert_or_apply to accept Op of a specific signature
srinivasyadav18 e7bca30
Clean up and add docs
srinivasyadav18 df3cd87
doxygen fixes
srinivasyadav18 01fa6c3
minor fixes based on review comments
srinivasyadav18 45adafc
Add identity element
srinivasyadav18 e00abec
Revert "Add identity element"
srinivasyadav18 5a9a31c
use insert_stable and update tests
srinivasyadav18 89cee5c
Merge remote-tracking branch 'origin/dev' into insert-or-apply
srinivasyadav18 a936ab2
minor improvements
srinivasyadav18 2eadddb
[pre-commit.ci] auto code formatting
pre-commit-ci[bot] 0568e65
more minor fixes
srinivasyadav18 8e6bf45
Merge branch 'insert-or-apply' of https://github.com/srinivasyadav18/…
srinivasyadav18 4ae274d
more minor cleanup
srinivasyadav18 0366e15
Merge remote-tracking branch 'origin/dev' into insert-or-apply
srinivasyadav18 f5adcad
replace cuda_stream_ref with cuda::stream_ref
srinivasyadav18 1c6a20e
Merge remote-tracking branch 'origin/dev' into insert-or-apply
srinivasyadav18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,93 @@ | ||
| /* | ||
| * Copyright (c) 2023-2024, 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 <benchmark_defaults.hpp> | ||
| #include <benchmark_utils.hpp> | ||
|
|
||
| #include <cuco/static_map.cuh> | ||
| #include <cuco/utility/key_generator.cuh> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| #include <thrust/device_vector.h> | ||
| #include <thrust/transform.h> | ||
|
|
||
| using namespace cuco::benchmark; | ||
| using namespace cuco::utility; | ||
|
|
||
| /** | ||
| * @brief A benchmark evaluating `cuco::static_map::insert_or_apply` performance | ||
| */ | ||
| template <typename Key, typename Value, typename Dist> | ||
| std::enable_if_t<(sizeof(Key) == sizeof(Value)), void> static_map_insert_or_apply( | ||
| nvbench::state& state, nvbench::type_list<Key, Value, Dist>) | ||
| { | ||
| using pair_type = cuco::pair<Key, Value>; | ||
|
|
||
| auto const num_keys = state.get_int64_or_default("NumInputs", defaults::N); | ||
| auto const occupancy = state.get_float64_or_default("Occupancy", defaults::OCCUPANCY); | ||
| auto const multiplicity = state.get_int64_or_default("Multiplicity", defaults::MULTIPLICITY); | ||
|
|
||
| std::size_t const size = cuco::detail::int_div_ceil(num_keys, multiplicity) / occupancy; | ||
|
|
||
| thrust::device_vector<Key> keys(num_keys); | ||
|
|
||
| key_generator gen; | ||
| gen.generate(dist_from_state<Dist>(state), keys.begin(), keys.end()); | ||
|
|
||
| thrust::device_vector<pair_type> pairs(num_keys); | ||
| thrust::transform(keys.begin(), keys.end(), pairs.begin(), [] __device__(Key const& key) { | ||
| return pair_type(key, static_cast<Value>(key)); | ||
| }); | ||
|
|
||
| state.add_element_count(num_keys); | ||
|
|
||
| cuco::static_map map{size, cuco::empty_key<Key>{-1}, cuco::empty_value<Value>{0}}; | ||
|
|
||
| state.exec(nvbench::exec_tag::timer, [&](nvbench::launch& launch, auto& timer) { | ||
| map.clear_async({launch.get_stream()}); | ||
|
|
||
| timer.start(); | ||
| map.insert_or_apply_async( | ||
| pairs.begin(), pairs.end(), cuco::op::reduce::sum, {launch.get_stream()}); | ||
| timer.stop(); | ||
| }); | ||
| } | ||
|
|
||
| template <typename Key, typename Value, typename Dist> | ||
| std::enable_if_t<(sizeof(Key) != sizeof(Value)), void> static_map_insert_or_apply( | ||
| nvbench::state& state, nvbench::type_list<Key, Value, Dist>) | ||
| { | ||
| state.skip("Key should be the same type as Value."); | ||
| } | ||
|
|
||
| NVBENCH_BENCH_TYPES(static_map_insert_or_apply, | ||
| NVBENCH_TYPE_AXES(defaults::KEY_TYPE_RANGE, | ||
| defaults::VALUE_TYPE_RANGE, | ||
| nvbench::type_list<distribution::uniform>)) | ||
| .set_name("static_map_insert_or_apply_uniform_multiplicity") | ||
| .set_type_axes_names({"Key", "Value", "Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE) | ||
| .add_int64_axis("Multiplicity", defaults::MULTIPLICITY_RANGE); | ||
|
|
||
| NVBENCH_BENCH_TYPES(static_map_insert_or_apply, | ||
| NVBENCH_TYPE_AXES(defaults::KEY_TYPE_RANGE, | ||
| defaults::VALUE_TYPE_RANGE, | ||
| nvbench::type_list<distribution::uniform>)) | ||
| .set_name("static_map_insert_or_apply_uniform_occupancy") | ||
| .set_type_axes_names({"Key", "Value", "Distribution"}) | ||
| .set_max_noise(defaults::MAX_NOISE) | ||
| .add_float64_axis("Occupancy", defaults::OCCUPANCY_RANGE); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.