Skip to content

Allow public tuning of non-ByKey cub::DeviceScan - #8853

Merged
bernhardmgruber merged 19 commits into
NVIDIA:mainfrom
bernhardmgruber:scan_tune_prod
Jun 9, 2026
Merged

bernhardmgruber merged 19 commits into
NVIDIA:mainfrom
bernhardmgruber:scan_tune_prod

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

This PR makes all tuning policies required for cub::DeviceScan public and adds tests+documentation.

DispatchScan and AgentScanPolicy will be deprecated in a follow-up PR: #9234

Fixes: #8578

New public entities

Entity Enumerators / Data Members
cub::LookbackDelayAlgorithm no_delay, fixed_delay, exponential_backoff, exponential_backoff_jitter, exponential_backoff_jitter_window, exponential_backon_jitter_window, exponential_backon_jitter, exponential_backon
cub::LookbackDelayPolicy kind (LookbackDelayAlgorithm), delay, l2_write_latency
cub::ScanAlgorithm lookback, warpspeed
cub::ScanLookbackPolicy threads_per_block, items_per_thread, load_algorithm, load_modifier, store_algorithm, scan_algorithm, delay_constructor (LookbackDelayPolicy)
cub::ScanWarpspeedPolicy reduce_and_scan_warps, items_per_thread, lookahead_items_per_thread, lookahead_stages, block_idx_stages
cub::ScanPolicy algorithm (ScanAlgorithm), lookback (ScanLookbackPolicy), warpspeed (ScanWarpspeedPolicy)

@bernhardmgruber
bernhardmgruber requested review from a team as code owners May 6, 2026 20:58
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 6, 2026
@bernhardmgruber
bernhardmgruber marked this pull request as draft May 6, 2026 20:58
@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.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 6, 2026
@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 May 6, 2026 21:38
@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner May 6, 2026 21:38
@bernhardmgruber
bernhardmgruber requested a review from jrhemstad May 6, 2026 21:39
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL May 6, 2026
@github-actions

This comment has been minimized.

@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner May 7, 2026 07:37
@bernhardmgruber bernhardmgruber changed the title Allow public tuning of cub::DeviceScan Allow public tuning of non-ByKey cub::DeviceScan May 7, 2026
@github-actions

This comment has been minimized.

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

Turned to draft to prevent accidental merging. Waiting for #7671 to be resolved.

@bernhardmgruber
bernhardmgruber marked this pull request as draft May 7, 2026 12:13
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Review to In Progress in CCCL May 7, 2026
@bernhardmgruber
bernhardmgruber marked this pull request as ready for review June 2, 2026 11:11
@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner June 2, 2026 11:11
@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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

suggestion:

Walkthrough

suggestion: Exposes public LookbackDelay and Scan policy types and replaces internal delay/scan detail types across tuning tables, dispatch, kernels, NVRTC templates, benchmarks, helpers, docs, and tests.

Changes

Delay and Scan Policy API Productization

Layer / File(s) Summary
Delay policy API: LookbackDelayAlgorithm and LookbackDelayPolicy
cub/cub/detail/delay_constructor.cuh
Exports new LookbackDelayAlgorithm enum and LookbackDelayPolicy struct with operators; renames mapping helper to lookback_delay_policy_from_type and rekeys constructor dispatch and defaults on the new enum.
Scan policy API: ScanAlgorithm and ScanPolicy types
cub/cub/device/dispatch/tuning/tuning_scan.cuh
Adds ScanAlgorithm, ScanLookbackPolicy, ScanWarpspeedPolicy, and ScanPolicy with host operators; updates scan_policy_selector concept and warpspeed helpers to use new types.
DeviceScan documentation
cub/cub/device/device_scan.cuh
Adds Tuning subsection with environment and selector API examples.
Scan dispatch infrastructure
cub/cub/device/dispatch/dispatch_scan.cuh
convert_policy() and policy_selector_from_hub return ScanPolicy; local variables use ScanWarpspeedPolicy/ScanLookbackPolicy.
Scan kernels: DeviceScanInitKernel, DeviceScanKernel
cub/cub/device/dispatch/kernels/kernel_scan.cuh
Use ScanPolicy constants, branch on ScanAlgorithm::warpspeed, and reference policy.lookback_delay.* when instantiating delay constructors.
Warpspeed kernel: num_total_threads, smem_for_stages
cub/cub/device/dispatch/kernels/kernel_scan_warpspeed.cuh
Update parameter and member types from scan_warpspeed_policy to ScanWarpspeedPolicy.
Radix sort scan kernel and tuning
cub/cub/device/dispatch/kernels/kernel_radix_sort.cuh, cub/cub/device/dispatch/tuning/tuning_radix_sort.cuh
Use ScanPolicy identifiers and construct ScanPolicy{ScanAlgorithm::lookback, ScanLookbackPolicy{...}, lookback_delay_policy_from_type<...>}.
Dispatch radix sort
cub/cub/device/dispatch/dispatch_radix_sort.cuh
Generalizes __init_pass_config to template on ScanPolicy.
Scan-by-key tuning: all compute capability branches
cub/cub/device/dispatch/tuning/tuning_scan_by_key.cuh
scan_by_key_policy::delay_constructor → LookbackDelayPolicy; all tuning selectors use lookback_delay_policy_from_type<...>.
Reduce-by-key tuning: SM-specific policy selection
cub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh
reduce_by_key_policy::delay_constructor → LookbackDelayPolicy; all (key_size, accum_size) returns use LookbackDelayAlgorithm::*.
RLE tuning: encode and non-trivial-runs
cub/cub/device/dispatch/tuning/tuning_rle_encode.cuh, tuning_rle_non_trivial_runs.cuh
Policy fields → LookbackDelayPolicy; all SM tuning branches replace old discriminants with LookbackDelayAlgorithm::*.
Unique-by-key tuning: SM100/SM90/SM80 and default
cub/cub/device/dispatch/tuning/tuning_unique_by_key.cuh
unique_by_key_policy::delay_constructor → LookbackDelayPolicy; tuning tables updated to new enum/type.
Select-if tuning: SM80/SM90/SM100 branches
cub/cub/device/dispatch/tuning/tuning_select_if.cuh
select_if_policy::delay_constructor → LookbackDelayPolicy; all selection paths updated.
Three-way partition tuning: SM10.0/SM9.0/SM8.0
cub/cub/device/dispatch/tuning/tuning_three_way_partition.cuh
three_way_partition_policy::delay_constructor → LookbackDelayPolicy across specializations.
Dispatch select/partition/rle helpers
cub/cub/device/dispatch/dispatch_select_if.cuh, dispatch_three_way_partition.cuh, dispatch_rle.cuh
Policy construction updated to use lookback_delay_policy_from_type<...>.
Batch memcpy tuning
cub/cub/device/dispatch/tuning/tuning_batch_memcpy.cuh
small_buffer_policy delay fields → LookbackDelayPolicy.
Scan tuning: warpspeed and lookback selection
cub/cub/device/dispatch/tuning/tuning_scan.cuh
Refactors get_warpspeed_policy(), policy_selector::operator() to return ScanPolicy/ScanWarpspeedPolicy; replaces delay_constructor_policy{...} with LookbackDelayPolicy{LookbackDelayAlgorithm::..., ...}.
Benchmark policy selectors
cub/benchmarks/bench/scan/policy_selector.h, cub/benchmarks/bench/copy/memcpy.cu
Updated to use public cub::ScanPolicy and cub::LookbackDelayPolicy types.
NVRTC kernel sources
c/parallel/src/radix_sort.cu, scan.cu, unique_by_key.cu
JIT source templates import cub::LookbackDelayPolicy and cub::LookbackDelayAlgorithm.
Scan environment API tests
cub/test/catch2_test_device_scan_env.cu, catch2_test_device_scan_env_api.cu
scan_tuning returns cub::ScanPolicy; adds static tests validating ScanPolicy and a tuned DeviceScan::ExclusiveSum test using cuda::execution::tune.
NVBench helper
nvbench_helper/nvbench_helper/look_back_helper.cuh
Type aliases updated to use cub::LookbackDelayAlgorithm and cub::LookbackDelayPolicy.
Thrust test
thrust/testing/scan.cu
Algorithm-selection check updated to use cub::ScanAlgorithm::warpspeed.

Assessment against linked issues

Objective Addressed Explanation
Productize cub::DeviceScan tuning API (non-ByKey variants) [#8578] ✅
Export new public delay and scan policy types [#8578] ✅
Integrate new types into dispatch, kernels, and tuning [#8578] ✅
Add test coverage for public scan policy [#8578] ✅

Possibly related issues

Suggested reviewers

  • shwina
  • pauleonix

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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/tuning/tuning_scan.cuh (1)

130-141: 💤 Low value

suggestion: Missing [[nodiscard]] on equality operators for ScanWarpspeedPolicy, inconsistent with ScanLookbackPolicy (lines 79, 88) and ScanPolicy (lines 162, 167) which have them.

-  _CCCL_HOST_DEVICE_API constexpr friend bool operator==(const ScanWarpspeedPolicy& lhs, const ScanWarpspeedPolicy& rhs)
+  [[nodiscard]] _CCCL_HOST_DEVICE_API constexpr friend bool operator==(const ScanWarpspeedPolicy& lhs, const ScanWarpspeedPolicy& rhs)
   {
     return lhs.num_reduce_and_scan_warps == rhs.num_reduce_and_scan_warps
         && lhs.look_ahead_items_per_thread == rhs.look_ahead_items_per_thread
         && lhs.items_per_thread == rhs.items_per_thread && lhs.lookahead_stages == rhs.lookahead_stages
         && lhs.block_idx_stages == rhs.block_idx_stages;
   }

-  _CCCL_HOST_DEVICE_API constexpr friend bool operator!=(const ScanWarpspeedPolicy& lhs, const ScanWarpspeedPolicy& rhs)
+  [[nodiscard]] _CCCL_HOST_DEVICE_API constexpr friend bool operator!=(const ScanWarpspeedPolicy& lhs, const ScanWarpspeedPolicy& rhs)
   {
     return !(lhs == rhs);
   }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 647d0420-c261-4627-942a-7f98f699739a

📥 Commits

Reviewing files that changed from the base of the PR and between e550b30 and a9a678c.

📒 Files selected for processing (29)
  • c/parallel/src/radix_sort.cu
  • c/parallel/src/scan.cu
  • c/parallel/src/unique_by_key.cu
  • cub/benchmarks/bench/copy/memcpy.cu
  • cub/benchmarks/bench/scan/policy_selector.h
  • cub/cub/detail/delay_constructor.cuh
  • cub/cub/device/device_scan.cuh
  • cub/cub/device/dispatch/dispatch_radix_sort.cuh
  • cub/cub/device/dispatch/dispatch_rle.cuh
  • cub/cub/device/dispatch/dispatch_scan.cuh
  • cub/cub/device/dispatch/dispatch_select_if.cuh
  • cub/cub/device/dispatch/dispatch_three_way_partition.cuh
  • cub/cub/device/dispatch/kernels/kernel_radix_sort.cuh
  • cub/cub/device/dispatch/kernels/kernel_scan.cuh
  • cub/cub/device/dispatch/kernels/kernel_scan_warpspeed.cuh
  • cub/cub/device/dispatch/tuning/tuning_batch_memcpy.cuh
  • cub/cub/device/dispatch/tuning/tuning_radix_sort.cuh
  • cub/cub/device/dispatch/tuning/tuning_reduce_by_key.cuh
  • cub/cub/device/dispatch/tuning/tuning_rle_encode.cuh
  • cub/cub/device/dispatch/tuning/tuning_rle_non_trivial_runs.cuh
  • cub/cub/device/dispatch/tuning/tuning_scan.cuh
  • cub/cub/device/dispatch/tuning/tuning_scan_by_key.cuh
  • cub/cub/device/dispatch/tuning/tuning_select_if.cuh
  • cub/cub/device/dispatch/tuning/tuning_three_way_partition.cuh
  • cub/cub/device/dispatch/tuning/tuning_unique_by_key.cuh
  • cub/test/catch2_test_device_scan_env.cu
  • cub/test/catch2_test_device_scan_env_api.cu
  • nvbench_helper/nvbench_helper/look_back_helper.cuh
  • thrust/testing/scan.cu

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 21m: Pass: 100%/354 | Total: 2d 13h | Max: 40m 45s | Hits: 99%/327737

See results here.

enum class ScanAlgorithm
{
lookback,
warpspeed

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.

Food for thought: I am wondering whether it would be wise to rename this to lookahead

Warpspeed is the library we use to implement the lookahead algorithm.

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.

Oh man, we have had that discussion a few times already and I am sick of renaming :S

@bernhardmgruber
bernhardmgruber merged commit 3a2d278 into NVIDIA:main Jun 9, 2026
374 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jun 9, 2026
@bernhardmgruber
bernhardmgruber deleted the scan_tune_prod branch June 9, 2026 07:24
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::DeviceScan (without *ByKey) tuning API

5 participants