Skip to content

Document the new CUB tuning API for developers - #8643

Merged
bernhardmgruber merged 9 commits into
NVIDIA:mainfrom
bernhardmgruber:tuning_doc_dev
May 5, 2026
Merged

bernhardmgruber merged 9 commits into
NVIDIA:mainfrom
bernhardmgruber:tuning_doc_dev

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

@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
* :ref:`tuning policy selectors <cub-policy-selectors>`

from the environment argument, or provide default values in case the environment does not contain them.
They typically use helper functions like ``dispatch_with_env`` and ``dispatch_with_env_and_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.

We should document those defaults

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.

We still have this issue: #7712. I am trying to focus on the tuning aspect in my documentation changes and will leave all general environment documentation to #7712.

@bernhardmgruber bernhardmgruber changed the title Document the new tuning API for developers Document the new CUB tuning API for developers Apr 23, 2026
@bernhardmgruber
bernhardmgruber marked this pull request as ready for review April 29, 2026 14:37
@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner April 29, 2026 14:37
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Apr 29, 2026
Comment thread docs/cub/developer/device_scope.rst Resolved
Comment thread docs/cub/developer/device_scope.rst Resolved
Comment on lines +36 to 42
Device-scope APIs come in two flavors, two step APIs and environment APIs,
both return ``cudaError_t`` and take algorithm specific arguments.
The two step API accepts a ``stream`` as the last parameter (``NULL`` stream by default)
and the first two parameters are always ``void *d_temp_storage, size_t &temp_storage_bytes``.
The environment API just takes an environment as the last parameter (empty environment by default).
The implementation may consist of some minimal argument checking, but should forward as soon as possible to the dispatch layer.
Device-scope algorithms are implemented in files located in `cub/device/device_***.cuh`.

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 section buries the lede a little bit. The primary relationship (at least as advertised in the blog post) is that single-phase is more or less a convenience wrapper over dual-phase.

I might lead with that, as it makes the following discussion much easier to follow. Once the reader appreciates that they functionally achieve the same thing, you can dive deeper into the nuts and bolts of how they differ.

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.

single-phase is more or less a convenience wrapper over dual-phase.

Unfortunately not. Determinism requirements and tuning are only exposed via env-overloads. The single-phase APIs cannot express this or call the corresponding algorithms (like RFA or atomic reduction).

Comment thread docs/cub/developer/device_scope.rst Resolved
Comment on lines +75 to +76
cuda::execution::require(requirements...),
cuda::execution::tune(policy_selectors....)

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.

Likewise, I might add some inline comments here to the execution arguments. It may not be immediately obvious what they do

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 don't think this matters here, since the arguments to env are unordered, and the functions require and tune are well enough named IMO to explain what they do.

Comment thread docs/cub/developer/device_scope.rst Resolved
Comment on lines +157 to +162
The dispatch function is typically a simple function template called ``dispatch`` inside an algorithm-specific namespace.
It basically receives the same parameters as the public API entry point,
but they may have already been modified, extended, or generalized (to map many public APIs to the same dispatch function).
The goal of the dispatch function is to setup the execution of the algorithm on the device
by selecting the appropriate policy for the current GPU's compute capability,
preparing temporary storage and shared memory, configuring kernel launches, launching kernels, etc.

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.

Nit: I would reorder this to discuss the goal of the dispatcher first, then discuss the mechanics afterwards. Consider also making those goals as a list, otherwise it's easy to lose them in the text.

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.

The wording here tries to be loose on purpose, since dispatch functions are just a convention we seem to follow, but nobody is forced to follow it and it may change in the future. I have ideas myself about how to change them. I don't want the docs here to get out of sync to fast.

Comment thread docs/cub/developer/device_scope.rst Resolved
Comment thread docs/cub/developer/device_scope.rst Outdated
Comment on lines +269 to +270
Since the policy selector is stateless, we can default-construct it from its type alone
and always retrieve the ``policy`` as a compile-time value.

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.

You kind of already say this 4 lines above.

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.

Right. Removed the second occurrence.

Comment thread docs/cub/developer/device_scope.rst Resolved
Comment on lines +298 to +301
Because many dispatch functions are also used by CCCL.C,
which compiles them without proper type information,
we have to provide them in two forms,
a typeless and a typeful version.

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.

Do we need to keep this documented now that hostjit is on the horizon? Is that not replacing CCCL.C entirely?

@bernhardmgruber bernhardmgruber May 5, 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.

I will happy delete it once hostjit is merged and all of CCCL.C has been rewritten ;) Until then, I can point people here when they ask me why we have multiple flavors of policy selectors.

Comment thread docs/cub/developer/device_scope.rst Resolved
@bernhardmgruber
bernhardmgruber enabled auto-merge (squash) May 5, 2026 15:45
@bernhardmgruber
bernhardmgruber merged commit 551e6bc into NVIDIA:main May 5, 2026
19 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL May 5, 2026
@bernhardmgruber
bernhardmgruber deleted the tuning_doc_dev branch May 5, 2026 20:05
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 the internal tuning API/design in CUB's developer guide

4 participants