Skip to content

Allow public tuning of non-ByKey cub::DeviceReduce - #8863

Merged
bernhardmgruber merged 9 commits into
NVIDIA:mainfrom
bernhardmgruber:reduce_public
Jul 3, 2026
Merged

bernhardmgruber merged 9 commits into
NVIDIA:mainfrom
bernhardmgruber:reduce_public

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #7577

@copy-pr-bot

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

@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 7, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL May 7, 2026
@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

/ok to test 8cb51b7

@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber force-pushed the reduce_public branch 2 times, most recently from 21e13d1 to 981733f Compare May 12, 2026 13:38
@bernhardmgruber
bernhardmgruber force-pushed the reduce_public branch 2 times, most recently from d83c423 to d9b1bea Compare June 2, 2026 17:18
@bernhardmgruber
bernhardmgruber force-pushed the reduce_public branch 2 times, most recently from 3a79d69 to c448335 Compare July 2, 2026 09:16
@bernhardmgruber
bernhardmgruber marked this pull request as ready for review July 2, 2026 09:17
@bernhardmgruber
bernhardmgruber requested review from a team as code owners July 2, 2026 09:17
@bernhardmgruber
bernhardmgruber requested review from fbusato and shwina July 2, 2026 09:17
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 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: 75beab6e-0624-4cd6-a60b-fdb3e9784425

📥 Commits

Reviewing files that changed from the base of the PR and between 5027a2c and a58c441.

📒 Files selected for processing (24)
  • cub/benchmarks/bench/reduce/arg_extrema.cu
  • cub/benchmarks/bench/reduce/base.cuh
  • cub/benchmarks/bench/reduce/deterministic.cu
  • cub/benchmarks/bench/reduce/nondeterministic.cu
  • cub/benchmarks/bench/segmented_reduce/base.cuh
  • cub/benchmarks/bench/transform_reduce/sum.cu
  • cub/cub/agent/agent_reduce.cuh
  • cub/cub/device/device_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
  • cub/cub/device/dispatch/kernels/kernel_reduce.cuh
  • cub/cub/device/dispatch/kernels/kernel_reduce_deterministic.cuh
  • cub/cub/device/dispatch/kernels/kernel_segmented_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_segmented_reduce.cuh
  • cub/test/catch2_test_device_reduce_deterministic.cu
  • cub/test/catch2_test_device_reduce_dispatcher.cu
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/test/catch2_test_device_reduce_env_api.cu
  • cub/test/catch2_test_device_reduce_nondeterministic.cu
  • cub/test/catch2_test_device_segmented_reduce_custom_policy_hub.cu
  • cub/test/catch2_test_device_segmented_reduce_env.cu
  • docs/cub/tuning.rst
  • docs/cub/tuning_infra.rst
✅ Files skipped from review due to trivial changes (4)
  • cub/test/catch2_test_device_segmented_reduce_custom_policy_hub.cu
  • docs/cub/tuning.rst
  • cub/test/catch2_test_device_reduce_dispatcher.cu
  • cub/cub/device/device_reduce.cuh
🚧 Files skipped from review as they are similar to previous changes (20)
  • cub/cub/device/dispatch/kernels/kernel_segmented_reduce.cuh
  • cub/benchmarks/bench/reduce/nondeterministic.cu
  • cub/test/catch2_test_device_segmented_reduce_env.cu
  • cub/benchmarks/bench/transform_reduce/sum.cu
  • cub/benchmarks/bench/reduce/base.cuh
  • cub/cub/device/dispatch/kernels/kernel_reduce_deterministic.cuh
  • cub/cub/device/dispatch/tuning/tuning_segmented_reduce.cuh
  • cub/benchmarks/bench/reduce/deterministic.cu
  • cub/test/catch2_test_device_reduce_env_api.cu
  • cub/test/catch2_test_device_reduce_nondeterministic.cu
  • cub/benchmarks/bench/segmented_reduce/base.cuh
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/cub/device/dispatch/kernels/kernel_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
  • cub/benchmarks/bench/reduce/arg_extrema.cu
  • cub/cub/agent/agent_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce.cuh
  • cub/test/catch2_test_device_reduce_deterministic.cu
  • docs/cub/tuning_infra.rst

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added/extended environment-based tuning support for reduction via policy selectors, including an execution API example.
    • Updated segmented-reduction tuning to use the newer pass-based policy format.
  • Bug Fixes
    • Standardized reduction deterministic and non-deterministic dispatch on the newer ReducePolicy/ReducePassPolicy and pass/algorithm wiring.
  • Documentation
    • Refreshed tuning guide examples to construct ReducePassPolicy/ReducePolicy (including DeviceReduce environment tuning).
  • Deprecations
    • Deprecated legacy reduction dispatch entrypoints in favor of DeviceReduce, and deprecated the legacy AgentReducePolicy type alias.

Walkthrough

Non-ByKey cub::DeviceReduce tuning now uses public ReducePassPolicy and ReducePolicy types end to end. Dispatch, kernels, benchmarks, tests, and docs were updated, and legacy AgentReducePolicy/dispatch entry points were deprecated.

Changes

ReducePolicy API productization

Layer / File(s) Summary
New policy types and deprecated legacy aliases
cub/cub/device/dispatch/tuning/tuning_reduce.cuh, cub/cub/agent/agent_reduce.cuh, cub/cub/device/dispatch/dispatch_reduce.cuh
Adds ReducePassPolicy/ReducePolicy; AgentReducePolicy becomes a deprecated alias to detail::agent_reduce_policy; DispatchReduce/DispatchTransformReduce are deprecated.
Policy hub construction with new pass policies
cub/cub/device/dispatch/tuning/tuning_reduce.cuh, cub/cub/device/dispatch/dispatch_reduce.cuh
Policy hub aliases and selector functions now build and return ReducePolicy from ReducePassPolicy, and the nondeterministic selector updates multi_tile.reduce_algorithm.
Dispatch reduce wiring to multi_tile and single_tile
cub/cub/device/dispatch/dispatch_reduce.cuh, cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
active_policy.reduce references are replaced with .multi_tile/.single_tile across configuration, logging, launch, and assertions.
Kernel policy field updates
cub/cub/device/dispatch/kernels/kernel_reduce.cuh, cub/cub/device/dispatch/kernels/kernel_reduce_deterministic.cuh, cub/cub/device/dispatch/kernels/kernel_segmented_reduce.cuh
Kernel policy aliases now source reduce_algorithm and load_modifier from the new pass policies instead of block_algorithm.
Segmented reduce tuning updated to ReducePassPolicy
cub/cub/device/dispatch/tuning/tuning_segmented_reduce.cuh, cub/benchmarks/bench/segmented_reduce/base.cuh
large_reduce and the segmented benchmark selector switch to ReducePassPolicy and .multi_tile.
Benchmark selectors updated to ReducePassPolicy and ReducePolicy
cub/benchmarks/bench/reduce/*.cu, cub/benchmarks/bench/transform_reduce/sum.cu
Reduce and transform-reduce benchmark selectors now construct ReducePassPolicy and return ReducePolicy.
Test coverage for tuning selectors and env API
cub/test/catch2_test_device_reduce_*.cu, cub/test/catch2_test_device_segmented_reduce_*.cu
Tests switch to the new policy types, add deprecation suppression, add aggregate/equality checks, and add an env API test using cuda::execution::tune.
Documentation examples updated for ReducePassPolicy and ReducePolicy
cub/cub/device/device_reduce.cuh, docs/cub/tuning.rst, docs/cub/tuning_infra.rst
DeviceReduce tuning docs and examples now show ReducePassPolicy/ReducePolicy with multi_tile and single_tile members.

Assessment against linked issues

Objective Addressed Explanation
Public tuning API for non-ByKey cub::DeviceReduce [#7577] ✅
Deprecate internal policy types in favor of the public tuning API [#7577] ✅

Possibly related PRs

  • NVIDIA/cccl#9403: Uses the same DeviceReduce environment-tuning path and public policy-selector shape.

Suggested reviewers: griwes, srinivasyadav18


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

@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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh (1)

199-205: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

critical: reduce_grid_size undercounts exact full-chunk inputs. When num_items % num_items_per_chunk == 0, last_chunk_grid_size is 0, but the loop still launches a full final chunk and writes another chunk_grid_size partials into an allocation sized for one fewer chunk; the final single-tile pass also misses those partials. Account for the final full chunk when has_partial_chunk is false. As per path instructions, cub/**/* reviews should focus on memory access safety.

Source: Path instructions

🧹 Nitpick comments (2)
cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh (1)

103-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Mark the read-only active_policy parameters const or take const ReducePolicy& in both helpers. As per coding guidelines, all variables that are not modified must be declared const.

Also applies to: 172-173

Source: Coding guidelines

cub/cub/device/dispatch/tuning/tuning_reduce.cuh (1)

405-415: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: redundant default-init + reassignment of rp.

Declare and initialize directly, matching the pattern used two branches below (lines 426-427, 438-439).

Simplify rp construction
-      ReducePassPolicy rp{};
       auto [scaled_items, scaled_threads] = scale_mem_bound(sm100_tuning->threads, sm100_tuning->items, accum_size);
-      rp                                  = ReducePassPolicy{
-        scaled_threads, scaled_items, sm100_tuning->items_per_vec_load, BLOCK_REDUCE_WARP_REDUCTIONS, LOAD_LDG};
+      const ReducePassPolicy rp{
+        scaled_threads, scaled_items, sm100_tuning->items_per_vec_load, BLOCK_REDUCE_WARP_REDUCTIONS, LOAD_LDG};
       return {rp, rp};

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: aff48938-e949-4e30-8b08-1dcdbecaf6dc

📥 Commits

Reviewing files that changed from the base of the PR and between 64b6b0e and c448335.

📒 Files selected for processing (24)
  • cub/benchmarks/bench/reduce/arg_extrema.cu
  • cub/benchmarks/bench/reduce/base.cuh
  • cub/benchmarks/bench/reduce/deterministic.cu
  • cub/benchmarks/bench/reduce/nondeterministic.cu
  • cub/benchmarks/bench/segmented_reduce/base.cuh
  • cub/benchmarks/bench/transform_reduce/sum.cu
  • cub/cub/agent/agent_reduce.cuh
  • cub/cub/device/device_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce_deterministic.cuh
  • cub/cub/device/dispatch/kernels/kernel_reduce.cuh
  • cub/cub/device/dispatch/kernels/kernel_reduce_deterministic.cuh
  • cub/cub/device/dispatch/kernels/kernel_segmented_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_segmented_reduce.cuh
  • cub/test/catch2_test_device_reduce_deterministic.cu
  • cub/test/catch2_test_device_reduce_dispatcher.cu
  • cub/test/catch2_test_device_reduce_env.cu
  • cub/test/catch2_test_device_reduce_env_api.cu
  • cub/test/catch2_test_device_reduce_nondeterministic.cu
  • cub/test/catch2_test_device_segmented_reduce_custom_policy_hub.cu
  • cub/test/catch2_test_device_segmented_reduce_env.cu
  • docs/cub/tuning.rst
  • docs/cub/tuning_infra.rst

Comment thread docs/cub/tuning.rst 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
docs/cub/tuning.rst (2)

45-67: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

important: Keep the selector name consistent throughout the example.

CustomReducePolicySelector is introduced here, but the later snippets still instantiate my_reduce_tuning<int> and my_scan_tuning. As written, the page is internally inconsistent and the copy/paste example no longer matches the new API naming. Please update the later usages, or keep compatible aliases if you want the old names to remain valid. As per path instructions, documentation examples should be technically accurate and buildable.

Also applies to: 106-139

Source: Path instructions


50-52: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

suggestion: Clamp or constrain items_per_thread.

64 / sizeof(T) can become 0 for wider T, which yields an invalid tuning value if this template is instantiated beyond the narrow built-in types listed in the comment. Please either constrain the template to the intended element sizes or clamp the expression to at least 1. As per path instructions, documentation examples should stay technically accurate.

Source: Path instructions


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 58ef6c8b-7cab-4d79-9bec-47b73534dc61

📥 Commits

Reviewing files that changed from the base of the PR and between c448335 and 4559250.

📒 Files selected for processing (4)
  • cub/cub/agent/agent_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_reduce.cuh
  • docs/cub/tuning.rst
🚧 Files skipped from review as they are similar to previous changes (3)
  • cub/cub/agent/agent_reduce.cuh
  • cub/cub/device/dispatch/tuning/tuning_reduce.cuh
  • cub/cub/device/dispatch/dispatch_reduce.cuh

@github-actions

This comment has been minimized.

@NaderAlAwar NaderAlAwar 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.

Important: we still need to update device_scope.rst since it uses reduce policy tuning as an example. Line 247 should say multi_tile instead of reduce and line 458 should return cub::ReducePolicy

Comment thread docs/cub/tuning.rst Resolved
Comment thread docs/cub/tuning.rst Resolved
@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber enabled auto-merge (squash) July 3, 2026 07:23
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 46m: Pass: 100%/287 | Total: 13d 09h | Max: 2h 44m | Hits: 19%/986441

See results here.

@bernhardmgruber
bernhardmgruber merged commit 8ee63d9 into NVIDIA:main Jul 3, 2026
304 of 305 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jul 3, 2026
@bernhardmgruber
bernhardmgruber deleted the reduce_public branch July 3, 2026 13:28
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 non-ByKey cub::DeviceReduce tuning API

2 participants