Skip to content

Allow public tuning of three-way cub::DevicePartition::If - #9324

Merged
bernhardmgruber merged 5 commits into
NVIDIA:mainfrom
bernhardmgruber:three_way_public
Jun 15, 2026
Merged

bernhardmgruber merged 5 commits into
NVIDIA:mainfrom
bernhardmgruber:three_way_public

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

@copy-pr-bot

copy-pr-bot Bot commented Jun 9, 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 Jun 9, 2026
@bernhardmgruber
bernhardmgruber marked this pull request as ready for review June 12, 2026 22:59
@bernhardmgruber
bernhardmgruber requested review from a team as code owners June 12, 2026 22:59
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 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: f9504ff2-7b79-44b8-8b7c-fba0ae9e66d3

📥 Commits

Reviewing files that changed from the base of the PR and between 2104bd7 and e09cb22.

📒 Files selected for processing (10)
  • cub/benchmarks/bench/partition/three_way.cu
  • cub/cub/agent/agent_three_way_partition.cuh
  • cub/cub/device/device_partition.cuh
  • cub/cub/device/dispatch/dispatch_segmented_sort.cuh
  • cub/cub/device/dispatch/dispatch_three_way_partition.cuh
  • cub/cub/device/dispatch/kernels/kernel_three_way_partition.cuh
  • cub/cub/device/dispatch/tuning/tuning_three_way_partition.cuh
  • cub/test/catch2_test_device_partition_env.cu
  • cub/test/catch2_test_device_partition_env_api.cu
  • cub/test/catch2_test_device_three_way_partition_custom_policy_hub.cu
✅ Files skipped from review due to trivial changes (1)
  • cub/cub/device/device_partition.cuh
🚧 Files skipped from review as they are similar to previous changes (7)
  • cub/test/catch2_test_device_three_way_partition_custom_policy_hub.cu
  • cub/benchmarks/bench/partition/three_way.cu
  • cub/cub/device/dispatch/kernels/kernel_three_way_partition.cuh
  • cub/cub/agent/agent_three_way_partition.cuh
  • cub/test/catch2_test_device_partition_env.cu
  • cub/test/catch2_test_device_partition_env_api.cu
  • cub/cub/device/dispatch/dispatch_three_way_partition.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.

Overview

This PR productizes the three-way cub::DevicePartition::If tuning API by introducing a public cub::ThreeWayPartitionPolicy struct and wiring the three-way partitioning implementation (dispatch, kernels, and tuning selectors) to use it. It deprecates the older agent policy-facing types in favor of the public tuning interface, updates related docs and benchmarks, and adds API + compile-time tests to stabilize the production-ready environment overload for three-way partitioning (addressing issue #9314). A merge-before dependency on #9316 is declared.

Key Changes

New Public API

  • Added cub::ThreeWayPartitionPolicy as the public-facing tuning policy for three-way DevicePartition::If.
  • The policy exposes tuning knobs used by cuda::execution::tune, including:
    • threads_per_block, items_per_thread
    • load/scan algorithm choices
    • lookback_delay configuration (with underlying policy represented via LookbackDelayPolicy)

Deprecations & Internal Type Refactors

  • AgentThreeWayPartitionPolicy is retained only as a deprecated compatibility alias; the implementation policy type is moved to cub::detail::agent_three_way_partition_policy and the public alias is annotated to use the new DevicePartition tuning API.
  • DispatchThreeWayPartitionIf is deprecated (aliased to the underlying implementation) with guidance to use DevicePartition.
  • Internal terminology/field mapping was updated from delay_constructor to lookback_delay, and kernel policy wiring was adjusted accordingly.

Dispatch & Kernel Refactor

  • Updated dispatch policy selection to return/consume cub::ThreeWayPartitionPolicy (instead of the previous internal three-way policy type), with downstream active_policy fields driven by lookback_delay.
  • Refactored detail::three_way_partition::dispatch(...) to inline the full three-way partition dispatch control flow (partition sizing, temp storage allocation/aliasing, streaming context initialization and advancement, tile descriptor setup, and kernel launch/init logic), removing the prior delegation path via a dedicated dispatcher shim.
  • Kernel code updates ensure DeviceThreeWayPartitionKernel uses detail::agent_three_way_partition_policy and reads lookback_delay-based delay constructor configuration.

Documentation, Benchmarks & Tests

  • Expanded cub::DevicePartition Doxygen docs with literalinclude examples showing how to tune the three-way If environment overload via ThreeWayPartitionPolicy (including a policy selector and tuning usage).
  • Updated the three-way partition benchmark to use the public cub::ThreeWayPartitionPolicy as the selector return type.
  • Added/updated tests:
    • Compile-time ThreeWayPartitionPolicy checks (semiregular, aggregate, and aggregate/designated initialization equality/inequality behavior).
    • New env-based API test for cub::DevicePartition::If three-way tuning using cuda::execution::tune and a ThreeWayPartitionPolicySelector that supplies threads/items, algorithm choices, and a fixed lookback_delay.
    • Adjusted legacy/custom policy hub test compilation to ignore deprecated API warnings and noted a TODO around removing an older dispatcher path.

Impact

Downstream users can now tune three-way DevicePartition::If through the stable public cub::ThreeWayPartitionPolicy and cuda::execution::tune, improving production-readiness while deprecating older agent-policy-oriented entry points and internal delay-constructor terminology.

Walkthrough

Introduce public cub::ThreeWayPartitionPolicy with lookback_delay field, move agent policy implementation to detail with deprecated alias, update tuning hub/selectors to map to the public policy, inline dispatch control flow, refactor kernel and benchmark usage, add compile-time and runtime tests, and integrate downstream consumers.

Changes

Three-way partition API productization

Layer / File(s) Summary
Public policy contract and documentation
cub/cub/device/dispatch/tuning/tuning_three_way_partition.cuh, cub/cub/device/device_partition.cuh
Introduce ThreeWayPartitionPolicy struct with lookback_delay field, equality/inequality operators, and ostream printer; extend DevicePartition Doxygen with policy selector and tuning examples for three-way If overload.
Agent policy refactoring and deprecation
cub/cub/agent/agent_three_way_partition.cuh
Move AgentThreeWayPartitionPolicy struct to detail::agent_three_way_partition_policy; reexport original name as deprecated using alias with CCCL_DEPRECATED_BECAUSE("Use the tuning API for DevicePartition").
Tuning hub and selector migration
cub/cub/device/dispatch/tuning/tuning_three_way_partition.cuh
Update DefaultPolicy alias, select_agent_policy/select_agent_policy100 helpers, and policy_selector/policy_selector_from_types operator return types to ThreeWayPartitionPolicy; update three_way_partition_policy_selector concept to constrain on ThreeWayPartitionPolicy; map all selector branches to construct ThreeWayPartitionPolicy with corresponding LookbackDelayPolicy values.
Dispatch refactoring and inlined execution
cub/cub/device/dispatch/dispatch_three_way_partition.cuh
Update policy_selector_from_hub to return ThreeWayPartitionPolicy; rename DispatchThreeWayPartitionIf implementation to dispatch_three_way_partition_if and provide deprecated public alias; inline detail::three_way_partition::dispatch to compute partition/tile sizing, allocate/alias temp storage for streaming state, initialize streaming context, loop over partitions launching init/selection kernels with stream sync and context advancement, and remove delegation through deprecated dispatcher.
Kernel and benchmark propagation
cub/cub/device/dispatch/kernels/kernel_three_way_partition.cuh, cub/benchmarks/bench/partition/three_way.cu
Update kernel AgentThreeWayPartitionPolicyT to use agent_three_way_partition_policy and reference active_policy.lookback_delay.* instead of delay_constructor.*; update benchmark policy selector to return cub::ThreeWayPartitionPolicy.
Test coverage and validation
cub/test/catch2_test_device_partition_env.cu, cub/test/catch2_test_device_partition_env_api.cu, cub/test/catch2_test_device_three_way_partition_custom_policy_hub.cu
Update test policy selector return type to cub::ThreeWayPartitionPolicy; add compile-time type-trait tests for ThreeWayPartitionPolicy (semiregular, aggregate, initialization equivalence, equality); add three-way DevicePartition::If env-based API test with ThreeWayPartitionPolicySelector tuning; suppress deprecated API warnings in custom policy hub test with CCCL_IGNORE_DEPRECATED_API define.
Downstream consumer integration
cub/cub/device/dispatch/dispatch_segmented_sort.cuh
Update DispatchSegmentedSort partition dispatch calls to use cub::detail::three_way_partition::dispatch_three_way_partition_if instead of deprecated cub::DispatchThreeWayPartitionIf.

Assessment against linked issues

Objective Addressed Explanation
Productize three-way partition tuning API by introducing public ThreeWayPartitionPolicy [#9314] ✅
Provide tuning examples and documentation for three-way partition If overload [#9314] ✅
Refactor internal agent policy to detail namespace with deprecation path [#9314] ✅
Update dispatch logic to inline execution and support the new policy type [#9314] ✅

Suggested reviewers

  • shwina
  • NaderAlAwar
  • wmaxey

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

@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

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

463-624: 📐 Maintainability & Code Quality | 💤 Low value

suggestion: Duplicate comment at lines 519 and 522 both say "Construct the tile status interface". The first comment (line 519) appears to describe computing current_num_tiles, not constructing the tile status. Consider changing line 519 to something like "Compute the number of tiles for this partition".


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 188029a2-0155-4a2c-809f-e380deedb63b

📥 Commits

Reviewing files that changed from the base of the PR and between d10f0fb and 0ad9d8e.

📒 Files selected for processing (9)
  • cub/benchmarks/bench/partition/three_way.cu
  • cub/cub/agent/agent_three_way_partition.cuh
  • cub/cub/device/device_partition.cuh
  • cub/cub/device/dispatch/dispatch_three_way_partition.cuh
  • cub/cub/device/dispatch/kernels/kernel_three_way_partition.cuh
  • cub/cub/device/dispatch/tuning/tuning_three_way_partition.cuh
  • cub/test/catch2_test_device_partition_env.cu
  • cub/test/catch2_test_device_partition_env_api.cu
  • cub/test/catch2_test_device_three_way_partition_custom_policy_hub.cu

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber enabled auto-merge (squash) June 15, 2026 08:28
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 13h 17m: Pass: 100%/287 | Total: 11d 03h | Max: 2h 27m | Hits: 19%/969095

See results here.

@bernhardmgruber
bernhardmgruber merged commit c6e14ac into NVIDIA:main Jun 15, 2026
608 of 611 checks passed
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::DevicePartition three-way tuning API

3 participants