You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[EPIC] Consistently use the new CUB tuning APIs internally #7464
After the new tuning API has been (internally) implemented for a CUB algorithm and the correspond env-overloads are available, we can replace all internal dispatch layer access by public CUB API calls. This should mostly affect any remaining benchmarks or tests that still use a (legacy) policy_hub or target a (legacy) Dispatcher struct directly. The following tasks are necessary:
Benchmarks: Make sure any benchmark is using the public CUB API, passing the nvbench stream, a memory resource, and an optional policy selector through the environment argument
Device layer: Make sure all public CUB device APIs extract a policy selector from the tuning environment, providing a default policy selector, and forwarding it to the internal dispatch function. Remove any obsolete get_tuning_query_t, struct tuning, and struct default_tuning from the previous design prototype.
Dispatch function: Remove the default value for typename PolicySelector since the device layer and CCCL.C should all explicitly specify the policy selector
Thrust usage: Any thrust API should be rewritten to use the public CUB device API instead of the internal dispatch function.
Add a test for each public CUB device API passing a custom policy selector to ensure tunings are correctly extracted.
Those tasks should be applied to all usages of CUB dispatch functions attached as sub issues.
changed the title [-]Consistently use the new CUB tuning APIs internally[/-][+][EPIC] Consistently use the new CUB tuning APIs internally[/+]on Mar 9, 2026
Let's look at commit 06ba38f.
It replaces most uses of a CUB dispatch function (cub::detail::merge::dispatch) by the public API (cub::DeviceMerge::MergePairs and cub::DeviceMerge::MergeKeys).
Additionally, it can now extract tunings from the public API's env parameter.
As a second example, the same refactoring was applied in 68c62601734e28424597e49d3a569cf2aa38f09a, but for cub::detail::merge_sort::dispatch.
Let's apply this refactoring now to cub::detail::XXXXX::dispatch.
You should refactor:
* All benchmarks using the dispatch function should now call the public API.
It is no longer necessary to call the dispatch function to query the temp_size and create a device_vector for temporary storage.
Just call the public CUB API directly once inside the state.exec lambda and use a caching_allocator_t alloc.
Build the environment using the function cub_bench_env.
* All public APIs must extract the policy selector from the env parameter.
The dispatch_with_env function already does part of the job and should be replaced by dispatch_with_env_and_tuning.
Create the default policy selector from the default parameter of the PolicySelector template parameter of the dispatch function and pass it to dispatch_with_env_and_tuning.
* Add a test for each public API that passes a custom policy selector and check that it was successfully applied.
There are multiple strategies on how to do that.
If the CUB API accepts some kind of user-provided functor, you can pass a policy selector that sets the block size, and a functor that extracts the block size, and have the test check that.
Make sure to test 2 different block sizes.
The data type of the block size is always `unsigned int`.
But you can come up with a different kind of test entirely.
Try to be creative, but aim for a simple test.
The tests should be added to the file catch2_test_device_ALGNAME_env.cu (not the file catch2_test_device_ALGNAME_env_api.cu file).
The tests should call the the launch wrappers declared with DECLARE_LAUNCH_WRAPPER, not the public CUB APIs.
The tests need to be guarded with `#if TEST_LAUNCH != 1`.
* All uses of the dispatch function in any file inside the `thrust/thrust` directory must also be rewritten to use the public API.
Retain the THRUST_***_INDEX_TYPE_DISPATCH if the public CUB API has a templated parameter that accepts the problem size/number of items,
otherwise remove the index type dispatch.
* Furthermore:
cuda::execution::__tune was renamed to cuda::execution::tune in the meantime.
I am getting increasingly convinced that dispatch_with_env_and_tuning is the wrong abstraction. It forces us the form the default policy selector in the device layer, which is very repetitive. I think it should remain inside the dispatch function and we should forward the tuning env to the dispatch function instead.
Activity
[-]Use the new CUB tuning APIs internally[/-][+]Consistently use the new CUB tuning APIs internally[/+]Use the new tuning API internally for DeviceTransform
Use the new tuning API internally for DeviceTransform
Use the new tuning API internally for `DeviceTransform` (#7810)
detail::radix_sort::dispatch#7947detail::reduce::dispatch#7948[-]Consistently use the new CUB tuning APIs internally[/-][+][EPIC] Consistently use the new CUB tuning APIs internally[/+]detail::segmented_reduce::dispatch#7950detail::reduce::dispatch_nondeterministic#7951detail::adjacent_difference::dispatch#795215 remaining items
detail::select::dispatch+DeviceSelect#8379detail::three_way_partition::dispatch#8380detail::scan_by_key::dispatch#8436detail::unique_by_key::dispatch#8480detail::segmented_scan::dispatch#8481detail::batched_topk::dispatch#8482detail::scan::dispatch#8377bernhardmgruber commentedon May 6, 2026
I currently use this prompt to start the rewrite:
detail::select::dispatch+DevicePartition#8879detail::segmented_radix_sort::dispatch#8926bernhardmgruber commentedon May 13, 2026
I am getting increasingly convinced that
dispatch_with_env_and_tuningis the wrong abstraction. It forces us the form the default policy selector in the device layer, which is very repetitive. I think it should remain inside the dispatch function and we should forward the tuning env to the dispatch function instead.bernhardmgruber commentedon May 13, 2026
It doesn't work because CCCL.C needs to pass a statefull policy selector to the dispatch function.
detail::find::dispatch#9237