-
Notifications
You must be signed in to change notification settings - Fork 353
Test passing a custom policy to DispatchReduceByKey #7310
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
99 changes: 99 additions & 0 deletions
99
cub/test/catch2_test_device_reduce_by_key_custom_policy_hub.cu
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,99 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include "insert_nested_NVTX_range_guard.h" | ||
|
|
||
| #include <cub/device/dispatch/dispatch_reduce_by_key.cuh> | ||
|
|
||
| #include <cuda/std/functional> | ||
|
|
||
| #include <c2h/catch2_test_helper.h> | ||
|
|
||
| using namespace cub; | ||
|
|
||
| // TODO(bgruber): drop this test with CCCL 4.0 when we drop the reduce-by-key dispatcher after publishing the tuning API | ||
|
|
||
| template <class ReductionOpT, class AccumT, class KeyT> | ||
| struct my_policy_hub | ||
| { | ||
| // from Policy500 of the CUB reduce-by-key tunings | ||
| struct MaxPolicy : ChainedPolicy<500, MaxPolicy, MaxPolicy> | ||
| { | ||
| using ReduceByKeyPolicyT = | ||
| AgentReduceByKeyPolicy<128, | ||
| 6, | ||
| BLOCK_LOAD_DIRECT, | ||
| LOAD_LDG, | ||
| BLOCK_SCAN_WARP_SCANS, | ||
| cub::detail::default_reduce_by_key_delay_constructor_t<AccumT, int>>; | ||
| }; | ||
| }; | ||
|
|
||
| C2H_TEST("DispatchReduceByKey::Dispatch: custom policy hub", "[reduce_by_key][device]") | ||
| { | ||
| using key_t = int; | ||
| using value_t = int; | ||
| using offset_t = int; | ||
| using equality_op_t = ::cuda::std::equal_to<>; | ||
| using reduction_op_t = ::cuda::std::plus<>; | ||
| using accum_t = ::cuda::std::__accumulator_t<reduction_op_t, value_t, value_t>; | ||
|
|
||
| const c2h::host_vector<key_t> h_keys_in{1, 1, 2, 2, 2, 3, 3}; | ||
| const c2h::host_vector<value_t> h_values_in{1, 2, 3, 4, 5, 6, 7}; | ||
|
|
||
| c2h::device_vector<key_t> d_keys_in = h_keys_in; | ||
| c2h::device_vector<value_t> d_values_in = h_values_in; | ||
| c2h::device_vector<key_t> d_keys_out(h_keys_in.size()); | ||
| c2h::device_vector<value_t> d_aggregates_out(h_values_in.size()); | ||
| c2h::device_vector<offset_t> d_num_runs(1); | ||
|
|
||
| c2h::host_vector<key_t> expected_keys{1, 2, 3}; | ||
| c2h::host_vector<value_t> expected_values{3, 12, 13}; | ||
|
|
||
| using policy_hub_t = my_policy_hub<reduction_op_t, accum_t, key_t>; | ||
| using dispatch_t = cub::DispatchReduceByKey< | ||
| key_t*, | ||
| key_t*, | ||
| value_t*, | ||
| value_t*, | ||
| offset_t*, | ||
| equality_op_t, | ||
| reduction_op_t, | ||
| offset_t, | ||
| accum_t, | ||
| policy_hub_t>; | ||
|
|
||
| size_t temp_size = 0; | ||
| dispatch_t::Dispatch( | ||
| nullptr, | ||
| temp_size, | ||
| thrust::raw_pointer_cast(d_keys_in.data()), | ||
| thrust::raw_pointer_cast(d_keys_out.data()), | ||
| thrust::raw_pointer_cast(d_values_in.data()), | ||
| thrust::raw_pointer_cast(d_aggregates_out.data()), | ||
| thrust::raw_pointer_cast(d_num_runs.data()), | ||
| equality_op_t{}, | ||
| reduction_op_t{}, | ||
| static_cast<offset_t>(h_keys_in.size()), | ||
| /* stream */ nullptr); | ||
| c2h::device_vector<unsigned char> temp_storage(temp_size, thrust::no_init); | ||
| dispatch_t::Dispatch( | ||
| thrust::raw_pointer_cast(temp_storage.data()), | ||
| temp_size, | ||
| thrust::raw_pointer_cast(d_keys_in.data()), | ||
| thrust::raw_pointer_cast(d_keys_out.data()), | ||
| thrust::raw_pointer_cast(d_values_in.data()), | ||
| thrust::raw_pointer_cast(d_aggregates_out.data()), | ||
| thrust::raw_pointer_cast(d_num_runs.data()), | ||
| equality_op_t{}, | ||
| reduction_op_t{}, | ||
| static_cast<offset_t>(h_keys_in.size()), | ||
| /* stream */ nullptr); | ||
|
|
||
| const auto num_runs = static_cast<std::size_t>(d_num_runs[0]); | ||
| d_keys_out.resize(num_runs); | ||
| d_aggregates_out.resize(num_runs); | ||
|
|
||
| REQUIRE(d_keys_out == expected_keys); | ||
| REQUIRE(d_aggregates_out == expected_values); | ||
| } | ||
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.