Skip to content

run_to_run deterministic device scan - #9098

Merged
srinivasyadav18 merged 20 commits into
NVIDIA:mainfrom
srinivasyadav18:run_to_run_scan_pr
Jun 3, 2026
Merged

srinivasyadav18 merged 20 commits into
NVIDIA:mainfrom
srinivasyadav18:run_to_run_scan_pr

Conversation

@srinivasyadav18

@srinivasyadav18 srinivasyadav18 commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

closes #7556

This PR makes classic de-coupled lookback algorithm deterministic by waiting on previous base anchor tile's (tile idx multiple of 32) to populate inclusive prefix. This way all non-anchor (non multiple of 32) tiles always have same reduction tree, and also only popuplate only partial prefixes to tile-states. TL;DR: this a serialized 32 batched chain, which works on all the SM's where classic de-coupled lookback algorithm was already working.

Note

Initial experiments in PR 3e45d96 Implements run-to-run deterministic device scan by generating fixed-reduction tree by reduce tile-aggregates in chunks of 32.

The commit also experiments warpspeed on Hopper (SM90 - H100) by using global atomic flag replacing workstealing (SM100), and it performs better than de-coupled for large problem sizes.

Overall benchmarks collected:

scan_f32_228

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@srinivasyadav18
srinivasyadav18 requested review from a team as code owners May 21, 2026 17:40
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 21, 2026
@srinivasyadav18
srinivasyadav18 requested a review from davebayer May 21, 2026 17:40
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 21, 2026

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

This is some impressive work! Because it touches a lot of the extremely performance sensitive pieces of warpspeed scan and lookback, we should split this work into small pieces and review them very carefully (including benchmarks and SASS diffs).

Here are some suggestions:

  • Allowing warpspeed scan to run on Hopper should be it's own PR. That should just include the extension of the kernel by the atomic block index counter and the alternate path for the masked bulk copy store. That's a holistic changeset which can be merged easily with a benchmark on Hopper and a SASS diff for Blackwell.
  • Then the determinism extensions for warpspeed scan. The kernel extensions are less critical since they only affect scan, so we can bear better with the host code changes.
  • Then the determinism extensions to the lookback.

Comment on lines +623 to +626
warpspeed,
lookback_deterministic,
warpspeed_deterministic,
warpspeed_deterministic_atomic

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.

Q: Do we have a reason to believe that the atomic version of the kernel could be faster than cluster launch control on Blackwell?

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.

Remark: Furthermore, I don't think determinism should be part of any tuning information. It's a functional requirement and should be passed through the kernel's template arguments.

Comment on lines +274 to +294
NV_IF_ELSE_TARGET(
NV_PROVIDES_SM_100,
({
if (::cuda::ptx::elect_sync(~0))
{
::cuda::ptx::cp_async_bulk_cp_mask(
::cuda::ptx::space_global,
::cuda::ptx::space_shared,
cpAsyncOobInfo.ptrGmemStartAlignDown,
srcSmem,
/*size*/ 16,
byteMaskStart);
}
}),
({
const int rank = squad.threadRank();
if (rank < 16 && ((byteMaskStart >> rank) & 1u))
{
reinterpret_cast<::cuda::std::byte*>(cpAsyncOobInfo.ptrGmemStartAlignDown)[rank] = srcSmem[rank];
}
}));

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: This seems to repeat a few times, please create a dedicated function for it (can also be a lambda).

Comment thread cub/cub/detail/warpspeed/look_ahead.cuh Outdated
@@ -73,10 +72,10 @@ _CCCL_DEVICE_API void
storeTileAggregate(tile_state_t<AccumT>* ptrTileStates, scan_state scanState, AccumT sum, int index)
{
_CCCL_ASSERT(::cuda::is_aligned(ptrTileStates, alignof(tile_state_t<AccumT>)), "");
_CCCL_ASSERT(index >= 0 && index < gridDim.x, "Reading out of bounds tile state");
_CCCL_ASSERT(index >= 0, "Negative tile state index");

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: Why do we need to weaken the check for all architectures? Can't we keep it for the non deterministic version on Blackwell?

Comment thread cub/cub/detail/warpspeed/look_ahead.cuh Outdated
Comment on lines 179 to 187
template <bool RunToRunDeterministic, int numTileStatesPerThread, typename AccumT, typename ScanOpT>
[[nodiscard]] _CCCL_DEVICE_API _CCCL_FORCEINLINE AccumT warpIncrementalLookback(
SpecialRegisters specialRegisters,
tile_state_t<AccumT>* ptrTileStates,
const int idxTilePrev,
const AccumT sumExclusiveCtaPrev,
int& idxTilePrev,
AccumT& sumExclusiveCtaPrev,
const int idxTileNext,
ScanOpT& scan_op)
{

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.

Suggestion: Given the large branch on RunToRunDeterministic below and the different mechanics, I think we should try to just separate the implementation into two warpIncrementalLookback functions. The old one, and the deterministic one. I think this will reduce confusion.

@github-actions

This comment has been minimized.

@copy-pr-bot

copy-pr-bot Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented May 26, 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
📝 Walkthrough

Walkthrough

This PR implements run-to-run deterministic exclusive scan for CUB's DeviceScan by introducing a new StableReductionOrder template parameter that flows through policy selection, dispatch, kernel, and agent layers. The core change replaces the classic sliding-window tile-prefix lookback with an anchor-based deterministic variant when stability is required, preventing warpspeed usage and validating operator constraints.

Changes

Run-to-run Deterministic Exclusive Scan

Layer / File(s) Summary
Policy selection stable reduction order support
cub/cub/device/dispatch/tuning/tuning_scan.cuh
Adds require_stable_reduction_order flag to policy_selector, guards get_warpspeed_policy to return empty when stability required, introduces select_base_policy entry point, and extends policy_selector_from_types with StableReductionOrder template parameter.
Deterministic tile prefix callback with anchor synchronization
cub/cub/agent/single_pass_scan_operators.cuh
Extends TilePrefixCallbackOp with StableReductionOrder parameter; extracts classic lookback into helper; implements deterministic anchor-based lookback using __shfl_sync for anchor detection and TailSegmentedReduce for exclusive-prefix computation; publishes INCLUSIVE status only from anchor tiles (tile_idx & 31 == 0).
Agent scan parameter threading
cub/cub/agent/agent_scan.cuh
AgentScan accepts StableReductionOrder boolean and forwards into TilePrefixCallbackOpT template instantiation.
Device-level determinism validation and routing
cub/cub/device/device_scan.cuh
scan_impl_determinism uses StableReductionOrder boolean for compile-time dispatch instead of runtime determinism object; scan_impl_env separates run-to-run vs gpu-to-gpu constraints, refines operator validation into is_safe_integral_op and is_fp_plus_op, updates static_assert matrix for allowed combinations, and forwards stable_reduction_order flag.
Dispatch infrastructure parameter forwarding
cub/cub/device/dispatch/dispatch_scan.cuh
DeviceScanKernelSource, DispatchScan, detail::scan::dispatch, and dispatch_with_accum all accept StableReductionOrder and thread through default PolicySelector and KernelSource instantiations.
Kernel to agent stable reduction forwarding
cub/cub/device/dispatch/kernels/kernel_scan.cuh
DeviceScanKernel accepts StableReductionOrder parameter and forwards into AgentScan instantiation in non-warpspeed path.
NVRTC kernel name string update
c/parallel/src/scan.cu
Inserts hard-coded false template parameter before init_t in DeviceScanKernel instantiation string for kernel name generation and linking.
Run-to-run determinism test coverage
cub/test/catch2_test_device_scan_deterministic.cu
Adds Catch2 tests validating bit reproducibility across multiple runs under run_to_run determinism; second test validates device output matches host reference; parameterizes across input sizes covering small/edge/tile/lookahead regimes.
Determinism compile-time error validation
cub/test/test_device_exclusive_scan_determinism_fail.cu
Updates expected-error annotations to distinguish run-to-run (safe integral or plus-operator floating-point) from gpu-to-gpu (safe integral only); switches TEST_ERR==2 operator from plus to multiplies to demonstrate unsupported combinations.
Exclusive scan determinism benchmark
cub/benchmarks/bench/scan/exclusive/deterministic.cu
Adds nvbench benchmark for exclusive scan under run_to_run determinism; templates over float/double and int64_t; configures input-size axis from 2^16 to 2^28 elements; records global memory metrics.

Assessment against linked issues

Objective Addressed Explanation
Enable DeviceScan::ExclusiveScan(..., run_to_run) [#7556] ✅
Expand test coverage [#7556] ✅
Add benchmark [#7556] ✅

Suggested reviewers

  • fbusato
  • miscco

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: 2

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

1429-1432: 💤 Low value

suggestion: Inconsistent annotation style. Other methods in policy_selector use _CCCL_HOST_DEVICE_API constexpr, but this method uses _CCCL_API constexpr. While both work (learnings confirm _CCCL_API expands to include _CCCL_HOST_DEVICE), consistency within the struct would be cleaner. Also missing [[nodiscard]] which other similar accessors have.

-  _CCCL_API constexpr bool accum_op_is_non_associative() const
+  [[nodiscard]] _CCCL_HOST_DEVICE_API constexpr bool accum_op_is_non_associative() const
cub/cub/agent/single_pass_scan_operators.cuh (1)

1304-1352: 💤 Low value

suggestion: The deterministic overload assumes the callback is never invoked for tile 0. If it were, the anchor lane would read OOB status (not INCLUSIVE) and loop forever. The non-deterministic version has the same assumption but uses a sliding window that would also break with OOB tiles.

This is likely fine since tile 0 is handled specially in AgentScan, but it may warrant a defensive assertion or doc comment clarifying the precondition that tile_idx > 0.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ec2b1f94-7be5-4141-9c3a-893d809eb128

📥 Commits

Reviewing files that changed from the base of the PR and between 3408197 and f67df1b.

📒 Files selected for processing (8)
  • cub/benchmarks/bench/scan/deterministic/exclusive.cu
  • cub/cub/agent/agent_scan.cuh
  • cub/cub/agent/single_pass_scan_operators.cuh
  • cub/cub/device/device_scan.cuh
  • cub/cub/device/dispatch/dispatch_scan.cuh
  • cub/cub/device/dispatch/kernels/kernel_scan.cuh
  • cub/cub/device/dispatch/tuning/tuning_scan.cuh
  • cub/test/catch2_test_device_scan_deterministic.cu

@srinivasyadav18

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

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

♻️ Duplicate comments (2)
cub/benchmarks/bench/scan/deterministic/exclusive.cu (2)

37-47: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: dispatch_with_accum returns cudaError_t but you ignore it. If sizing fails, tmp_size remains uninitialized and line 49 allocates garbage. Capture each return: cudaError_t err = dispatch_with_accum<...>(...); if (err != cudaSuccess) { state.skip(...); return; } before using tmp_size.


51-76: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: Inside state.exec, dispatch_with_accum can fail but you ignore the return value (lines 54-62, 66-74). Timing invalid results corrupts benchmark data. Capture and check: cudaError_t err = dispatch_with_accum<...>(...); if (err != cudaSuccess) throw std::runtime_error(...); so the catch block on line 78 can skip.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: acdb99b0-7e6f-4b5d-b2d6-5bbdea8b63a2

📥 Commits

Reviewing files that changed from the base of the PR and between f67df1b and 139ff66.

📒 Files selected for processing (2)
  • cub/benchmarks/bench/scan/deterministic/exclusive.cu
  • cub/cub/device/dispatch/tuning/tuning_scan.cuh

@srinivasyadav18

Copy link
Copy Markdown
Contributor Author

/ok to test 8a6ea0f

@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: 0

🧹 Nitpick comments (1)
cub/benchmarks/bench/scan/deterministic/exclusive.cu (1)

59-60: ⚡ Quick win

suggestion: use a determinism-specific benchmark name instead of "base" to avoid ambiguous comparison outputs.

This benchmark enforces run_to_run determinism, so naming it "base" can blur base-vs-new result interpretation in JSON/MD comparisons.

As per coding guidelines, benchmark changes should “preserve useful comparison data” and support base-vs-new comparison workflows.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 85872668-bc01-4a48-bf60-1e21693dba0b

📥 Commits

Reviewing files that changed from the base of the PR and between 139ff66 and 8a6ea0f.

📒 Files selected for processing (2)
  • cub/benchmarks/bench/scan/deterministic/exclusive.cu
  • cub/test/catch2_test_device_scan_deterministic.cu
🚧 Files skipped from review as they are similar to previous changes (1)
  • cub/test/catch2_test_device_scan_deterministic.cu

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: as pointed out last week in a previous comment: I don't think determinism should be part of any tuning information. It's a functional requirement and should be passed through the kernel's template arguments as you already do. There should be no need to add determinism to scan_algorithm or any tuning policy.

@github-actions

This comment has been minimized.

@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/benchmarks/bench/scan/exclusive/exclusive.cu (1)

51-57: 💤 Low value

suggestion: The benchmark only tests floating-point types. Consider adding integer types (e.g., int32_t, int64_t) to verify deterministic scan correctness for integral operators, since per the implementation constraints both integral and FP types with plus are supported in run-to-run mode.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d735569a-e198-4f11-9a60-e900a8b22036

📥 Commits

Reviewing files that changed from the base of the PR and between 8a6ea0f and 02f3ebd.

📒 Files selected for processing (4)
  • cub/benchmarks/bench/scan/exclusive/exclusive.cu
  • cub/cub/agent/single_pass_scan_operators.cuh
  • cub/cub/device/dispatch/dispatch_scan.cuh
  • cub/cub/device/dispatch/kernels/kernel_scan.cuh
🚧 Files skipped from review as they are similar to previous changes (1)
  • cub/cub/device/dispatch/kernels/kernel_scan.cuh

@srinivasyadav18

Copy link
Copy Markdown
Contributor Author

/ok to test 54c3314

@github-actions

This comment has been minimized.

@srinivasyadav18

Copy link
Copy Markdown
Contributor Author

/ok to test 91705db

@github-actions

This comment has been minimized.

Comment thread cub/cub/device/device_scan.cuh Resolved
@srinivasyadav18

Copy link
Copy Markdown
Contributor Author

/ok to test 0743095

@github-actions

This comment has been minimized.

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

A few more nits, otherwise this LGTM

@srinivasyadav18

Copy link
Copy Markdown
Contributor Author

/ok to test 999f76e

@srinivasyadav18
srinivasyadav18 enabled auto-merge (squash) June 3, 2026 22:40
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 36m: Pass: 100%/289 | Total: 11d 22h | Max: 2h 30m | Hits: 17%/1050949

See results here.

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 run-to-run DeviceScan

2 participants