Repository navigation
Description
Before we make any tuning API features public we should carefully review all CUB algorithm's policies, their names and data members. The main goal is consistency, good user experience, and allowing future evolution (e.g. instead of a bool use_warpspeed_scan we should rather store an enum that can be extended by more algorithms in the future).
Here is a list of all current tuning policies and there data members: https://docs.google.com/spreadsheets/d/1EUdwvmv2n7-WRp30-lt7CQxyu8r6atdfJJx3O6Pf1Ag
We should carefully review how API entry points, dispatch functions and kernels relate to their tuning policies. We may want to split some tuning policies. For example, tuning policies for segmented algorithms should probably be separate from those for device-wide single problem algorithms, since they use different API entry points, dispatches, and often kernels. We should also review how a single API entrypoint should handle multiple policies in the background (e.g. rfa, non-deterministic, and ordinary DeviceReduce have different tuning policies but the same API entrypoint).
Furthermore, tuning policies may be specified not only at the CUB API but also for APIs in Thrust or libcu++, so we should have an idea how they can be used across our entire libraries.
We must have a complete picture about the API surface before going public with any tuning APIs.
There is now a section "Public API exposure" in the tuning design document: https://docs.google.com/document/d/1KtrSsMk2LAXSB5cdAUnmn3BMow5y6B8BhC5-XVA434g
Current design direction and guidelines for the exposure:
- Tuning policies remain in their tuning headers and are named
cub::AlgorithmXYZPolicy. E.g.cub::TransformPolicy. - Any nested types needed by the public exposure also become public. E.g.
cub::ScanPolicymakescub::ScanLookbackPolicy, and transitivelycub::LookbackDelayPolicypublic. - Tuning policies are spelled in CamelCase with members in snake_case, just like anything else in CUB's public API
- The default policy selectors in the tuning headers will remain internal. There are ideas on how to expose this functionality in the future.
- Document the tuning policy to use at the
struct DeviceAlgorithmlevel, including an API example. We discussed having a per-overload alias, e.g.struct DeviceScan { ... using InclusiveScanInitPolicy = cub::ScanPolicy; ... }for thecub::DeviceScan::InclusiveScanInitfunction, but most device layer structs use only one or two policies, so it seems too redundant. Plus, we can easily add this later. - The API example should show how the public CUB API is called with a user defined policy selector.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
bernhardmgruber commentedon May 5, 2026
I think we need to essentially solve how the public tuning API for
DeviceReducewill look like: #7577. That is, how policy selectors interplay with requirements at the public API that change the underlying dispatch/kernel/algorithm.bernhardmgruber commentedon May 7, 2026
Based on the following PRs:
cub::DeviceTransform#8745cub::DeviceMergeSort#8600cub::DeviceScan#8853cub::DeviceReduce#8863which serve as examples, here is my current design proposal (summarized by claude based on the above PRs):
Summary and open questions
All four PRs make CUB's internal tuning policies public so users can customize algorithm behavior per compute capability. The mechanism is:
cubnamespace) holds tuning knobs (threads per block, items per thread, algorithm choice, etc.)cuda::compute_capabilityand returning the policy structcuda::execution::tune(selector)as an environment to the existingDeviceXxxAPI methodsNew public entities for
cub::DeviceMergeSortcub::MergeSortPolicythreads_per_block,items_per_thread,load_algorithm,load_modifier,store_algorithmExample:
cuda::execution::tunetocuda::execution::tune_with? @gevtushenko: nocub::MergeSortPolicy? Is it clear that this belongs tocub::DeviceMergeSortalgorithms? It was previously suggested to nest the policies intocub::DeviceMergeSort::Policy, but this is not possible, since the definitions for the policy are needed far beforestruct DeviceMergeSortis defined.New public entities for
cub::DeviceTransformcub::TransformAlgorithmprefetch,vectorized,ldgsts,ublkcpcub::TransformPrefetchPolicythreads_per_block,items_per_thread_no_input,min_items_per_thread,max_items_per_thread,prefetch_byte_stride,unroll_factorcub::TransformVectorizedPolicythreads_per_block,items_per_thread,vec_sizecub::TransformAsyncCopyPolicythreads_per_block,min_items_per_thread,max_items_per_thread,unroll_factorcub::TransformPolicymin_bytes_in_flight,algorithm(TransformAlgorithm),prefetch(TransformPrefetchPolicy),vectorized(TransformVectorizedPolicy),async_copy(TransformAsyncCopyPolicy)TransformAsyncCopyPolicyinto two, one forldgstsand one forublkcp? Then they could evolve independentlyNew public entities for
cub::DeviceScancub::LookbackDelayAlgorithmno_delay,fixed_delay,exponential_backoff,exponential_backoff_jitter,exponential_backoff_jitter_window,exponential_backon_jitter_window,exponential_backon_jitter,exponential_backon,reduce_by_keycub::LookbackDelayPolicykind(LookbackDelayAlgorithm),delay,l2_write_latencycub::ScanAlgorithmlookback,warpspeedcub::ScanLookbackPolicythreads_per_block,items_per_thread,load_algorithm,load_modifier,store_algorithm,scan_algorithm,delay_constructor(LookbackDelayPolicy)cub::ScanWarpspeedPolicynum_reduce_and_scan_warps,look_ahead_items_per_thread,items_per_threadcub::ScanPolicyalgorithm(ScanAlgorithm),lookback(ScanLookbackPolicy),warpspeed(ScanWarpspeedPolicy)LookbackDelayPolicyandLookbackDelayAlgorithm?LookbackDelayAlgorithm::reduce_by_key. Should we keep that internal by renaming it to__reduce_by_key? Answer: yesScanWarpspeedPolicy?New public entities for
cub::DeviceReducecub::ReducePassPolicythreads_per_block,items_per_thread,vec_size,block_algorithm,load_modifiercub::ReducePolicymulti_tile(ReducePassPolicy),single_tile(ReducePassPolicy)cub::ReduceDeterministicPassPolicythreads_per_block,items_per_thread,block_algorithmcub::ReduceDeterministicPolicymulti_tile(ReduceDeterministicPassPolicy),single_tile(ReduceDeterministicPassPolicy)cub::ReduceNondeterministicPolicymulti_tile(ReducePassPolicy)ReducePassPolicy?ReducePassPolicyfor the multi and single tile pass, so they could evolve independently? In both cases, they use the same backendAgentReduceso there is currently no need for itReduceNondeterministicPolicyjust contain the members ofReducePassPolicydirectly instead of a single data member?Example with multiple policy selectors:
DeviceTransformalso has multiple backend algorithms but they are all contained in a singleTransformPolicybecause the choice of algorithm is a tuning value and not up to the user. ForDeviceRadixSortthere is also a scan pass involved which is just a data member in theRadixSortPolicy.Inconvenience/Pitfall: When the user requests a
gpu_to_gpudeterministic reduction and passes a policy selector generating aReduceDeterministicPolicy, but passes a buffer of non-FP types, the CUB device layer falls back torun_to_rundeterminism internally since that also gives a GPU to GPU deterministic result, however, theReduceDeterministicPolicywill then be ignored in this case and a the ordinaryReducePolicyis queried from the env. This may be surprising.bernhardmgruber commentedon May 11, 2026
We discussed the state of the tuning API design briefly during the Monday Code Review Hour and here are some notes:
DeviceTransformwithint unroll_factorand a for loop with runtime trip count. It was argued that it will likely look differently inDeviceMergeSortwhere we have multiple loops with static trip count. It was suggested that abool unrollcould be enough, but we should do the test and implement it. Resolution: Expose unrolling control incub::DeviceMergeSortto tuning #9052cub::DeviceMerge[Sort]via tuning #9181, where the merge[sort] policies where extended by a new data member with a default value. Unit tests were not modified (using those policies) and compiled without warnings.cub::DeviceMerge[Sort]via tuning #9181validate_policy(const transform_policy& active_policy)forDeviceTransformand had it populated by claude. I initially wanted to validate on the host, but there we ideally keep the tuning policy a runtime value to save compilation time. Validating in device code is fine as well. However,DeviceTransformalready has several validations in place, like whether the vector size is a power of two, so why should we move away or duplicate these conditions to the start of the kernel away from the code that relies on those conditions. When removing all conditions checked later in the kernel, there is actually nothing remaining that should be checked early. Arguable the block size could be validated, but that will just give a clear error message when launching the kernel at runtime. So I am included to not any additional validation.DeviceReduce::Sumand rather use a struct with appropriate sub members, likeDeviceTransform. There is not actually a difference between the two cases (as I tried to argue). Resolution: moved to the specific PR.MyReducePolicySelector). Answer: will be done at the PRs.cub::DeviceMergeSortto tuning #9052bernhardmgruber commentedon Jun 2, 2026
I discussed the state of this work with @gevtushenko yesterday and we concluded that there no fundamental blockers anymore with the current design (tuning polices are extensible without errors/warnings on the user side). #9052 shows that controlling unrolling via tuning is possible, but we do not need to ship it at the same time as the public
DeviceMerge[Sort]tunings. ForDeviceReducewe can just offer a product type containing the policies for the various backend algorithms. Therefore, any remaining problem can be discussed at the respective PR. Those should be mostly naming discussions now.cub::DeviceMergeSortto tuning #9052bernhardmgruber commentedon Jun 30, 2026
I sent a bunch of refactorings for
DeviceReduceand only a single policy is needed now. This removes the complexity of exposing tuning forDeviceReduceand there are no more open questions.