Skip to content

Allow public tuning of cub::DeviceTransform - #8745

Merged
bernhardmgruber merged 14 commits into
NVIDIA:mainfrom
bernhardmgruber:transform_tune_prod
Jun 8, 2026
Merged

bernhardmgruber merged 14 commits into
NVIDIA:mainfrom
bernhardmgruber:transform_tune_prod

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #8585
Fixes: #5570

New public entities for cub::DeviceTransform

Entity Enumerators / Data Members
cub::TransformAlgorithm prefetch, vectorized, ldgsts, ublkcp
cub::TransformPrefetchPolicy threads_per_block, items_per_thread_no_input, min_items_per_thread, max_items_per_thread, prefetch_byte_stride, unroll_factor
cub::TransformVectorizedPolicy threads_per_block, items_per_thread, vec_size
cub::TransformAsyncCopyPolicy threads_per_block, min_items_per_thread, max_items_per_thread, unroll_factor
cub::TransformPolicy min_bytes_in_flight, algorithm (TransformAlgorithm), prefetch (TransformPrefetchPolicy), vectorized (TransformVectorizedPolicy), async_copy (TransformAsyncCopyPolicy)

@bernhardmgruber
bernhardmgruber requested review from a team as code owners April 29, 2026 21:02
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 29, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Apr 29, 2026
@bernhardmgruber bernhardmgruber changed the title Allow public tuning of cub::DeviceTransform Allow public tuning of cub::DeviceTransform Apr 29, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

ok, what is happening here:

 /home/coder/cccl/cub/test/catch2_test_device_transform_env_api.cu:23:9: error: use of GNU old-style field designator extension [-Werror,-Wgnu-designator]
     23 | return {min_bytes_in_flight: 64 * 1024, algorithm: cub::TransformAlgorithm::prefetch, prefetch: {block_threads: 256, }, vectorized: {}, async_copy: {}}; 
        |         ^~~~~~~~~~~~~~~~~~~~
        |         .min_bytes_in_flight = 
  /home/coder/cccl/cub/test/catch2_test_device_transform_env_api.cu:23:41: error: use of GNU old-style field designator extension [-Werror,-Wgnu-designator]
     23 | return {min_bytes_in_flight: 64 * 1024, algorithm: cub::TransformAlgorithm::prefetch, prefetch: {block_threads: 256, }, vectorized: {}, async_copy: {}}; 
        |                                         ^~~~~~~~~~
        |                                         .algorithm = 
  /home/coder/cccl/cub/test/catch2_test_device_transform_env_api.cu:23:87: error: use of GNU old-style field designator extension [-Werror,-Wgnu-designator]
     23 | return {min_bytes_in_flight: 64 * 1024, algorithm: cub::TransformAlgorithm::prefetch, prefetch: {block_threads: 256, }, vectorized: {}, async_copy: {}}; 
        |                                                                                       ^~~~~~~~~
        |                                                                                       .prefetch = 
  /home/coder/cccl/cub/test/catch2_test_device_transform_env_api.cu:23:98: error: use of GNU old-style field designator extension [-Werror,-Wgnu-designator]
     23 | return {min_bytes_in_flight: 64 * 1024, algorithm: cub::TransformAlgorithm::prefetch, prefetch: {block_threads: 256, }, vectorized: {}, async_copy: {}}; 
        |                                                                                                  ^~~~~~~~~~~~~~
        |                                                                                                  .block_threads = 
  /home/coder/cccl/cub/test/catch2_test_device_transform_env_api.cu:23:121: error: use of GNU old-style field designator extension [-Werror,-Wgnu-designator]
     23 | return {min_bytes_in_flight: 64 * 1024, algorithm: cub::TransformAlgorithm::prefetch, prefetch: {block_threads: 256, }, vectorized: {}, async_copy: {}}; 
        |                                                                                                                         ^~~~~~~~~~~
        |                                                                                                                         .vectorized = 
  /home/coder/cccl/cub/test/catch2_test_device_transform_env_api.cu:23:137: error: use of GNU old-style field designator extension [-Werror,-Wgnu-designator]
     23 | return {min_bytes_in_flight: 64 * 1024, algorithm: cub::TransformAlgorithm::prefetch, prefetch: {block_threads: 256, }, vectorized: {}, async_copy: {}}; 
        |                                                                                                                                         ^~~~~~~~~~~
        |                                                                                                                                         .async_copy = 
  6 errors generated.

The corresponding source code:

    return {.min_bytes_in_flight = 64 * 1024,
            .algorithm           = cub::TransformAlgorithm::prefetch,
            .prefetch            = {.block_threads = 256},
            .vectorized          = {},
            .async_copy          = {}};

Does nvcc translate designated initializers into a GNU extension syntax?

@github-actions

This comment has been minimized.

Comment thread cub/cub/detail/cc_dispatch.cuh Resolved
@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber marked this pull request as draft May 6, 2026 19:23
@copy-pr-bot

copy-pr-bot Bot commented May 6, 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.

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

Converting to draft to prevent accidental merging until #7671 is resolved.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Review to In Progress in CCCL May 6, 2026
@bernhardmgruber
bernhardmgruber marked this pull request as ready for review June 2, 2026 16:14
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Jun 2, 2026
@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7dd33c20-cd46-4d3b-856c-ac65bea3dae5

📥 Commits

Reviewing files that changed from the base of the PR and between 7383f8e and 9433da7.

📒 Files selected for processing (8)
  • cub/benchmarks/bench/transform/common.h
  • cub/cub/detail/cc_dispatch.cuh
  • cub/cub/device/device_transform.cuh
  • cub/cub/device/dispatch/dispatch_transform.cuh
  • cub/cub/device/dispatch/kernels/kernel_transform.cuh
  • cub/cub/device/dispatch/tuning/tuning_transform.cuh
  • cub/test/catch2_test_device_transform_env.cu
  • cub/test/catch2_test_device_transform_env_api.cu
🚧 Files skipped from review as they are similar to previous changes (7)
  • cub/cub/device/device_transform.cuh
  • cub/test/catch2_test_device_transform_env.cu
  • cub/cub/device/dispatch/dispatch_transform.cuh
  • cub/test/catch2_test_device_transform_env_api.cu
  • cub/cub/device/dispatch/kernels/kernel_transform.cuh
  • cub/cub/detail/cc_dispatch.cuh
  • cub/cub/device/dispatch/tuning/tuning_transform.cuh

Note: CodeRabbit is enabled on this repository as a convenience for maintainers
and contributors. Use your best judgment when considering its review comments and
suggestions — a suggested change may be inadequate, unnecessary, or safe to ignore.
Contributors are not expected to address every comment. Human reviews are what
ultimately matter for merging.

High-level summary

This PR exposes the transform tuning surface for cub::DeviceTransform by replacing internal/detail tuning types with public policy types and a public algorithm enum, updates dispatch and kernel code to use those types, adjusts C++20 dispatch compatibility for older GCC, expands DeviceTransform docs, and adds tests for the public tuning API.

Notable changes

  • Public API additions (new entities)

    • enum class cub::TransformAlgorithm { prefetch, vectorized, ldgsts, ublkcp }
    • struct cub::TransformPrefetchPolicy { threads_per_block, items_per_thread_no_input, min_items_per_thread, max_items_per_thread, prefetch_byte_stride, unroll_factor }
      • default unroll_factor changed to 0 (was previously -1 in internals)
    • struct cub::TransformVectorizedPolicy { threads_per_block, items_per_thread, vec_size }
    • struct cub::TransformAsyncCopyPolicy { threads_per_block, min_items_per_thread, max_items_per_thread, unroll_factor }
      • removed bulk_copy_alignment from public async-copy policy
    • struct cub::TransformPolicy { min_bytes_in_flight, algorithm, prefetch, vectorized, async_copy }
  • Internal → public tuning surface

    • Tuning selection and policy construction now return cub::TransformPolicy instead of cub::detail::transform::transform_policy across benchmarks, DeviceTransform internals, dispatch, and tuning headers.
    • Algorithm selection updated to use TransformAlgorithm::ldgsts (replacing the old memcpy_async/internal name) and TransformAlgorithm::ublkcp where appropriate; prefetch/vectorized logic preserved with updated types.
  • Kernel/dispatch adjustments

    • Dispatch and kernel code updated to branch on TransformAlgorithm enum values.
    • For ublkcp, bulk_copy_alignment is now derived at compile site from transform::bulk_copy_alignment(current_tuning_cc()) instead of being exposed via the async-copy policy.
  • C++20/GCC compatibility

    • Added detail::policy_constant helper to work around GCC < 12 issues when materializing policies as integral constants used by the C++20 compute-capability dispatch path.
  • Documentation

    • Expanded Doxygen for DeviceTransform, including environment-based tuning examples.
  • Tests

    • New/updated Catch2 tests:
      • Tests validating cub::TransformPolicy is semiregular/aggregate and comparisons between aggregate and designated init (where supported).
      • Tests exercising DeviceTransform::Transform via cuda::execution::tune(...) with a TransformPolicySelector returning the public cub::TransformPolicy.

Behavioral/ABI notes

  • Public tuning types and enum values are added (listed above). These are additive API changes intended to replace internal detail types used by the environment tuning path.
  • The async-copy policy no longer exposes bulk_copy_alignment to users; alignment is determined at compile/site usage for ublkcp.
  • Default for prefetch.unroll_factor changed to 0.

Fixes / Related issues / Dependencies

  • Fixes references: Fixes #8585, Fixes #5570.
  • Merge-first dependencies: #8757, #8728, #8835, #8836.
  • Issue #7671 considered sufficiently approved to proceed; further discussion postponed to this PR.

Author checklist / completed items

  • Renamed memcpy_async → ldgsts (public enum)
  • Finalized unroll_factor design
  • Removed bulk_copy_alignment from public TransformAsyncCopyPolicy
  • Updated tuning selection to return public TransformPolicy
  • Added tests and documentation
  • Converted PR to draft to avoid accidental merge until remaining discussion resolved

Open questions / items remaining (require review / bikeshedding)

  • Bikeshedding on naming and public API surface:
    • Whether to split TransformAsyncCopyPolicy into separate policies for ldgsts vs ublkcp (currently a single async_copy policy used for both).
    • Confirmation of TransformAlgorithm enumerator names (ldgsts / ublkcp vs alternatives).
  • Whether to expose any mechanism to allow user-enforced compile-time failure when the bulk-copy path is not selected (requested in #5570) — related design/implementation for an environment API overload remains to be discussed.
  • Compilation/test issue: A reported Clang compile error in test/catch2_test_device_transform_env_api.cu when using designated initializers for a TransformPolicy-like return value. Diagnostics show Clang treating designated initializers as GNU old-style field designators; investigation needed whether nvcc translates designated initializers into GNU-extension syntax or if test needs different initialization style.

Estimated review effort

  • Impact: High (public API additions, tuning surface changes, and multiple callsites updated).
  • Areas to review closely:
    • Public API shapes and defaults (unroll_factor default, removal of bulk_copy_alignment).
    • Names for TransformAlgorithm and policy members.
    • Tests and the designated-initializer/Clang interaction.
    • Interaction with the listed merge-first PRs and with issue #7671 follow-ups.

important:

Walkthrough

Replace internal transform tuning types with public TransformAlgorithm and Transform*Policy/TransformPolicy, move bulk_copy_alignment computation into device code, add a C++20 dispatch helper, and update kernels, dispatch, docs, benchmarks, and tests to the public API.

Changes

Transform Tuning Policy Publicization

Layer / File(s) Summary
Public policy type definitions and algorithm enum
cub/cub/device/dispatch/tuning/tuning_transform.cuh
Add TransformAlgorithm and TransformPrefetchPolicy/TransformVectorizedPolicy/TransformAsyncCopyPolicy and aggregate TransformPolicy with equality and formatters.
Policy selector tuning logic
cub/cub/device/dispatch/tuning/tuning_transform.cuh, cub/benchmarks/bench/transform/common.h
Make tuned_vectorized_policy return TransformVectorizedPolicy; update policy_selector and selectors in benchmarks to return TransformPolicy with cc-dependent subpolicies and algorithm selection.
Kernel template updates: bulk_copy_alignment handling and dispatch refactoring
cub/cub/device/dispatch/kernels/kernel_transform.cuh
Route compile-time dispatch on TransformPolicy/TransformAlgorithm, compute ublkcp alignment from current_tuning_cc(), and add UnrollFactor static_assert.
Dispatch integration and C++20 workaround
cub/cub/detail/cc_dispatch.cuh, cub/cub/device/dispatch/dispatch_transform.cuh, cub/cub/device/device_transform.cuh
Introduce policy_constant helper for C++20 dispatch; update dispatch code to accept TransformPolicy and branch on TransformAlgorithm; update DeviceTransform to use the public tuning policy and add Doxygen docs.
Docs, tests, and benchmarks
cub/benchmarks/bench/transform/common.h, cub/test/catch2_test_device_transform_env.cu, cub/test/catch2_test_device_transform_env_api.cu
Update benchmark/test policy selectors to public API; add compile-time trait/aggregate initialization tests for TransformPolicy; add runtime Catch2 test exercising env-based tuning via cuda::execution::tune.

Assessment against linked issues

Objective Addressed Explanation
Productize the cub::DeviceTransform tuning API [#8585] ✅
Provide mechanism to verify bulk copy path is used [#5570] ❓ PR moves bulk_copy_alignment into device code and updates policy types but does not add a compile-time fail/verification API that forces compilation to fail when the bulk-copy path is not selected.

Suggested follow-up: add a compile-time assertion or test hook that can be enabled by users/tests to require the bulk-copy algorithm and fail build when not selected.

  • Suggested reviewers:
    • shwina
    • pauleonix

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread cub/cub/detail/cc_dispatch.cuh Resolved

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
cub/cub/device/dispatch/kernels/kernel_transform.cuh (1)

710-730: important: This changes the generated ublkcp device path, so please attach before/after benchmark data for the tuned architectures before merge. As per coding guidelines, **/*.{cpp,cu,cuh}: Do not commit SASS code changes without running benchmarks to check for performance regressions.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6d59960a-523b-4eb4-86a2-3f945359cce2

📥 Commits

Reviewing files that changed from the base of the PR and between 9a8f7f6 and 25754d9.

📒 Files selected for processing (8)
  • cub/benchmarks/bench/transform/common.h
  • cub/cub/detail/cc_dispatch.cuh
  • cub/cub/device/device_transform.cuh
  • cub/cub/device/dispatch/dispatch_transform.cuh
  • cub/cub/device/dispatch/kernels/kernel_transform.cuh
  • cub/cub/device/dispatch/tuning/tuning_transform.cuh
  • cub/test/catch2_test_device_transform_env.cu
  • cub/test/catch2_test_device_transform_env_api.cu

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

return os << "TransformAlgorithm::ldgsts";
case TransformAlgorithm::ublkcp:
return os << "TransformAlgorithm::ublkcp";
default:

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.

Don't add a default: case here (or in any switch-over-enum in general). If nothing matches a switch-case, it will fall through anyways, whilst adding a default case will stop compilers warning about uncovered cases. So for example:

enum Enum {
  FOO, BAR
};

// No compiler warning
switch (e) {
  case Enum::FOO: // ...
  default: // ...
  // oops, BAR not handled
}

// Compiler will warn "unhandled case BAR"
switch (e) {
  case Enum::FOO: // ...
  // oops, BAR not handled
}

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.

Hmm, but maybe I want to print "TransformAlgorithm::" if the user casts an unknown integer to my enum? Or is that bad practice as well?

I know what you are referring to above, but that applies when the default: does not contain any code itself.

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.

Hmm, but maybe I want to print "TransformAlgorithm::" if the user casts an unknown integer to my enum?

You should handle this outside the switch. If no case matches in a switch-case, it simply skips the entire expression as if you had a default: break;.

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.

Please show a code example. What scalable condition should it put into the conditional

  switch (algorithm)
  {
    case TransformAlgorithm::prefetch:
      return os << "TransformAlgorithm::prefetch";
    case TransformAlgorithm::vectorized:
      return os << "TransformAlgorithm::vectorized";
    case TransformAlgorithm::ldgsts:
      return os << "TransformAlgorithm::ldgsts";
    case TransformAlgorithm::ublkcp:
      return os << "TransformAlgorithm::ublkcp";
  }
  if (/* HERE */) {
      return os << "TransformAlgorithm::<unknown>";
  }

Without mentioning all of the above enumerators again?

<< policy.items_per_thread_no_input << ", .min_items_per_thread = " << policy.min_items_per_thread
<< ", .max_items_per_thread = " << policy.max_items_per_thread << ", .prefetch_byte_stride = "
<< policy.prefetch_byte_stride << ", .unroll_factor = " << policy.unroll_factor << " }";
<< "TransformPrefetchPolicy { .threads_per_block = " << policy.threads_per_block

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: it may be worth adding a local // clang-tidy: off here and formatting this line by line:

os << "prefetch_policy {"
   << ".threads_per_block = " << policy.threads_per_block << ", "
   << ...

the current for is... quite unreadable and easy to miss added members :)

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 would rather try to have clang-format be enabled as much as possible. Also, do people still add data members by hand and not have an agent do it? ;)

{
return {.min_bytes_in_flight = 64 * 1024,
.algorithm = cub::TransformAlgorithm::prefetch,
.prefetch = {.threads_per_block = 256},

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.

I assume that if we want to retune sth in the future we will just modify our policy-selector while the tuning parameter defaults implicit in the policy can just stay the same even if that means they are bad?

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 can now change ANYTHING we want in the future. Users will now have the ability to set their own tuning parameters, so any change we do that regresses a user can be reverted by the user specifying the old tuning policy manually.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 17m: Pass: 100%/284 | Total: 11d 06h | Max: 2h 15m | Hits: 18%/1026870

See results here.

@bernhardmgruber
bernhardmgruber merged commit 4be2ca2 into NVIDIA:main Jun 8, 2026
304 checks passed
@bernhardmgruber
bernhardmgruber deleted the transform_tune_prod branch June 8, 2026 13:56
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jun 8, 2026
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.

Productize the cub::DeviceTransform tuning API Verify DeviceTransform is using the bulk copy path

7 participants