Skip to content

Document public CUB tuning API - #8623

Merged
bernhardmgruber merged 8 commits into
NVIDIA:mainfrom
bernhardmgruber:tuning_docs
May 5, 2026
Merged

bernhardmgruber merged 8 commits into
NVIDIA:mainfrom
bernhardmgruber:tuning_docs

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

I let claude rewrite the documentation and did a lot of manual editing on top. Here is a summary by claude claude:

  • Updated docs/cub/developer/device_scope.rst to document the new dispatch architecture: policy_selector + dispatch_arch replacing ChainedPolicy/MaxPolicy/PolicyHub
  • Created docs/cub/policy_selectors.rst explaining how users define and pass custom policy selectors via cuda::execution::tune
  • Updated docs/cub/tuning.rst so benchmarks call the public CUB API with an environment instead of instantiating dispatch structs with custom policy hubs

This follows the roll-out of the new tuning API across ~20 CUB dispatchers (#7165). The old docs described ChainedPolicy linked lists, the MaxPolicy kernel trick, and template-specialization-based tunings.
The new architecture uses stateless constexpr callables returning plain aggregate policy structs, dispatch_arch for runtime-to-compile-time arch dispatch, and kernels querying
PolicySelector{}(arch_id{CUB_PTX_ARCH / 10}) directly

After some design reconsideration, I changed all uses of the term architecture by compute capability.

Prompts:

Please look at the github issue #7165.
It has many sub issues attached that are named something like "Implement the new tuning API for".
I paste the list here as well:

Implement the new tuning API for DispatchAdjacentDifference #7522
bernhardmgruber
Implement the new tuning API for detail::for_each::dispatch_t #7525
bernhardmgruber
Implement the new tuning API for DeviceRleDispatch #7532
bernhardmgruber
Implement the new tuning API for detail::merge::dispatch_t #7638
bernhardmgruber
Implement the new tuning API for detail::reduce::dispatch_streaming_arg_reduce_t #7645
bernhardmgruber
Implement the new tuning API for DispatchReduceByKey #7531
bernhardmgruber
Implement the new tuning API for detail::find::dispatch_t #7812
bernhardmgruber
Implement the new tuning API for DispatchSegmentedRadixSort #7642
bernhardmgruber
Implement the new tuning API for DispatchStreamingReduceByKey #7533
bernhardmgruber
Implement the new tuning API for DispatchTopK #7648
bernhardmgruber
Implement the new tuning API for DispatchSegmentedSort #7643
bernhardmgruber
Implement the new tuning API for DispatchThreeWayPartitionIf #7646
bernhardmgruber
Implement the new tuning API for DeviceScan #7521
griwes
Implement the new tuning API for DispatchMergeSort #7639
bernhardmgruber
Implement the new tuning API for DispatchBatchMemcpy #7636
bernhardmgruber
Implement the new tuning API for DispatchHistogram #7637
bernhardmgruber
Implement the new tuning API for DispatchSelectIf #7644
bernhardmgruber
Implement the new tuning API for DispatchScanByKey #7640
griwes
Implement the new tuning API for DispatchUniqueByKey #7647
griwes
Implement the new tuning API for detail::batched_topk::dispatch_batched_topk #8479
bernhardmgruber
Implement the new tuning API for DispatchFixedSizeSegmentedReduce #7641
srinivasyadav18
Implement the new tuning API for detail::segmented_scan::dispatch_segmented_scan #8424
oleksandr-pavlyk

Go to each of the linked issues and find the linked pull request. if it's merged, get the git SHA of the commit that resulted from the merge. Please print the list of commit SHAs.

Now, please look at the documentation page docs/cub/developer/device_scope.rst. It documents how the CUB device level API looks like, and how it calls through the dispatch layer to a kernel. It also documents how tuning policies work, etc. This documentation is mostly obsolete based on all the pull requests above. Please look at the changes of all the git SHAs above and try to understand how the new dispatch logic works. Then please update the device_scope.rst documentation page to reflect the new architecture of CUB.

Before all the changes, I drafted a document describing the new API (a design document). I placed a copy for you into ./new_api.md. Please read that document as well. It should help you understand the changes to the documentation.

Please also update docs/cub/tuning.rst, the section titled Policy Hub. It should discuss policy selectors instead. Instead of showing how to instantiate the Dispatch struct, show how to pass a policy selector to the public CUB API. An example can be found in this PR: #8495. Just show calling the public API like cub::DeviceScan::InclusiveScan(..., /* env = */ cuda::execution::tune(policy_selector{}));. Please also update the sections titled Main Body to call the public API instead. Also the section titled Creating tuning policies.

Please move the section "Policy Selector" to a new page between the TOC entries "CUB Benchmarks" and "CUB Tunings". Add a link to that page where the section was.

I have reworded some things. See the last two commits. I have not touched the device_scope.rst changes yet. They go to a different PR. Please check what is added by the last two commits only and suggest improvements and reword where necessary.

Just apply the changes, I can look at the diff

I also let claude rewrite the developer documentation, but that will come as a separate PR.

Fixes: #8593

@copy-pr-bot

copy-pr-bot Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL Apr 22, 2026
@bernhardmgruber
bernhardmgruber marked this pull request as ready for review April 22, 2026 14:46
@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner April 22, 2026 14:46
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Apr 22, 2026
Comment thread docs/cub/policy_selectors.rst Outdated
Comment on lines +8 to +11
A policy selector is a stateless callable that maps a :code:`cuda::arch_id` to a policy struct
containing the tuning values for that architecture.
Each set of CUB algorithms using a common underlying implementation defines a common policy struct,
e.g. :code:`cub::ReducePolicy`, which must be returned by a policy selector passed to those algorithms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wait with this PR until we agree on how exactly the tuning policy selector should look like?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I see the necessity to wait on that design decision.

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in CCCL Apr 22, 2026
Comment thread docs/cub/policy_selectors.rst Outdated
Comment on lines +13 to +14
CUB provides default policy selectors providing tunings for known architectures and workloads,
which are not publicly accessible to users, but used internally by CUB to select tunings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence repeats "provides"/"providing" and "tunings" quite a bit, it's a little tricky to read. I would suggest rewording this slightly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded.

Comment thread docs/cub/policy_selectors.rst Outdated
Defining a policy selector
--------------------------------------------------------------------------------

A policy selector is any type with a :code:`__host__`, :code:`__device__`, and :code:`constexpr` call operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the call operator have to be __host__ __device__ or can you have separate call operators for __host__ and __device__? This should clarify this (and ideally show an example if the latter).

Should also clarify whether the call operator must be const or not. I suspect it probably doesn't matter because these are just used as stateless functors, but the example has const so it kind of implies it's required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a single one being __host__ __device__ constexpr and const annotated.

as long as they can be evaluated at compile-time.
The returned tuning policy can, and probably should, contain different values for different CUDA architectures or workloads.

Each CUB algorithm with an environment parameter searches the environment for a policy selector returning a matching policy struct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider explaining how this matching is actually done. In particular:

  1. Does the user need to do any additional work (for example declare any additional specializations) to enable this matching?
  2. Does the user need to modify the environment itself to make it match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would say the user does not need to know exactly how the machinery works. I provide a few examples later that show how a user composes such an environment. Furthermore, @gevtushenko will write ample documentation about how environments and their properties will work (#7712) ;)


The policy structs themselves aim to be simple aggregates without special member functions (constructors, assignment operators, etc.),
thus supporting C++20 designated initializers (i.e., the syntax :code:`{ .block_threads = 512, ... }`).
They may occasionally contain member functions that compute derived values from the contained tuning values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether they contain member functions is irrelevant for users, the only guaranteed interaction they have is with the constructor, the existence of any other functions should be considered an implementation detail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Policy structs are fully public, so any member function they have is part of the public API. I am trying to minimize such member functions, so maybe I can eventually get away with none.

Comment thread docs/cub/policy_selectors.rst Outdated
Comment on lines +79 to +80
All policy structs are public types and will try to evolve in a non-breaking way,
by only adding new data members at the end of the struct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little wishy-washy. Committing to backwards compat is relevant, but how we do that is not. Perhaps this is best left out, since it's not clear whether we can expect these types to be fully API or ABI compatible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is relevant how we plan to extend then, because users need to know in which ways they are allowed to use policy structs. I rephrased the paragraph a little.

Comment on lines +125 to +126
CUB's benchmarks also make heavy use of policy selectors for tuning.
For more details on authoring benchmarks and their policy selectors, see :ref:`cub-tuning`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like developer-facing text, not user-facing. Consider rewording this to the effect of "for detailed examples of policy selectors, see benchmarks...". But perhaps better if we can point to examples instead. Benchmarks aren't so pedagogically useful as they tend to be pretty dense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to link to the benchmark documentation here because it provides further examples of how policy selectors can be used, and emphasize that they take the role of tuning there. Do you think this would be better:

Further examples for how to use policy selectors can be found in the tuning documentation.

Comment thread docs/cub/tuning.rst Resolved
@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

@davebayer I made the changes to use the term compute capability. Please re-review. Thx!

================================================================================

Policy selectors are the mechanism by which CUB's device algorithms and kernels select
tuning parameters for a given workload and GPU compute capability.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think we need a higher-level preamble here that explains what tuning parameters are in the first place. If this is intended to be the starting point for users to learn about user-defined tuning, we need some higher level prose that explains what tuning parameters are, how they intersect with algorithm implementations, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot in the Tuning documentation we already have: https://nvidia.github.io/cccl/unstable/cub/tuning.html. But maybe we need another rework to streamline how the information is presented. The current docs (without this PR) are very focused on the tuning process. This PR mainly tries to introduce the new tuning aspect of CUB's API.

@bernhardmgruber bernhardmgruber Apr 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's address this as a follow-up: #8731

@github-project-automation github-project-automation Bot moved this from In Progress to In Review in CCCL May 5, 2026
@bernhardmgruber
bernhardmgruber merged commit 8463f64 into NVIDIA:main May 5, 2026
26 of 28 checks passed
@bernhardmgruber
bernhardmgruber deleted the tuning_docs branch May 5, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Document public tuning of CUB algorithms

4 participants