Repository navigation
Document public CUB tuning API - #8623
Conversation
|
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. |
| 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. |
There was a problem hiding this comment.
Can we wait with this PR until we agree on how exactly the tuning policy selector should look like?
There was a problem hiding this comment.
Alright, I see the necessity to wait on that design decision.
| 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. |
There was a problem hiding this comment.
This sentence repeats "provides"/"providing" and "tunings" quite a bit, it's a little tricky to read. I would suggest rewording this slightly.
| Defining a policy selector | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| A policy selector is any type with a :code:`__host__`, :code:`__device__`, and :code:`constexpr` call operator |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Consider explaining how this matching is actually done. In particular:
- Does the user need to do any additional work (for example declare any additional specializations) to enable this matching?
- Does the user need to modify the environment itself to make it match?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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`. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
f35f968 to
471f795
Compare
5fd6133 to
5c56b90
Compare
5c56b90 to
b245532
Compare
|
@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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Let's address this as a follow-up: #8731
I let claude rewrite the documentation and did a lot of manual editing on top. Here is a summary by claude claude:
docs/cub/developer/device_scope.rstto document the new dispatch architecture:policy_selector+dispatch_archreplacingChainedPolicy/MaxPolicy/PolicyHubdocs/cub/policy_selectors.rstexplaining how users define and pass custom policy selectors viacuda::execution::tunedocs/cub/tuning.rstso benchmarks call the public CUB API with an environment instead of instantiating dispatch structs with custom policy hubsThis follows the roll-out of the new tuning API across ~20 CUB dispatchers (#7165). The old docs described
ChainedPolicylinked lists, theMaxPolicykernel trick, and template-specialization-based tunings.The new architecture uses stateless
constexprcallables returning plain aggregate policy structs,dispatch_archfor runtime-to-compile-time arch dispatch, and kernels queryingPolicySelector{}(arch_id{CUB_PTX_ARCH / 10})directlyAfter 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.
arch_idwithcompute_capability#8728Fixes: #8593