Repository navigation
run_to_run deterministic device scan - #9098
Conversation
bernhardmgruber
left a comment
There was a problem hiding this comment.
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.
| warpspeed, | ||
| lookback_deterministic, | ||
| warpspeed_deterministic, | ||
| warpspeed_deterministic_atomic |
There was a problem hiding this comment.
Q: Do we have a reason to believe that the atomic version of the kernel could be faster than cluster launch control on Blackwell?
There was a problem hiding this comment.
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.
| 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]; | ||
| } | ||
| })); |
There was a problem hiding this comment.
Important: This seems to repeat a few times, please create a dedicated function for it (can also be a lambda).
| @@ -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"); | |||
There was a problem hiding this comment.
Important: Why do we need to weaken the check for all architectures? Can't we keep it for the non deterministic version on Blackwell?
| 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) | ||
| { |
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
9bcb7e0 to
f67df1b
Compare
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR implements run-to-run deterministic exclusive scan for CUB's DeviceScan by introducing a new ChangesRun-to-run Deterministic Exclusive Scan
Assessment against linked issues
Suggested reviewers
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
cub/cub/device/dispatch/tuning/tuning_scan.cuh (1)
1429-1432: 💤 Low valuesuggestion: Inconsistent annotation style. Other methods in
policy_selectoruse_CCCL_HOST_DEVICE_API constexpr, but this method uses_CCCL_API constexpr. While both work (learnings confirm_CCCL_APIexpands 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() constcub/cub/agent/single_pass_scan_operators.cuh (1)
1304-1352: 💤 Low valuesuggestion: 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
📒 Files selected for processing (8)
cub/benchmarks/bench/scan/deterministic/exclusive.cucub/cub/agent/agent_scan.cuhcub/cub/agent/single_pass_scan_operators.cuhcub/cub/device/device_scan.cuhcub/cub/device/dispatch/dispatch_scan.cuhcub/cub/device/dispatch/kernels/kernel_scan.cuhcub/cub/device/dispatch/tuning/tuning_scan.cuhcub/test/catch2_test_device_scan_deterministic.cu
|
pre-commit.ci autofix |
There was a problem hiding this comment.
♻️ Duplicate comments (2)
cub/benchmarks/bench/scan/deterministic/exclusive.cu (2)
37-47:⚠️ Potential issue | 🔴 Critical | ⚡ Quick wincritical:
dispatch_with_accumreturnscudaError_tbut you ignore it. If sizing fails,tmp_sizeremains uninitialized and line 49 allocates garbage. Capture each return:cudaError_t err = dispatch_with_accum<...>(...); if (err != cudaSuccess) { state.skip(...); return; }before usingtmp_size.
51-76:⚠️ Potential issue | 🔴 Critical | ⚡ Quick wincritical: Inside
state.exec,dispatch_with_accumcan 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
📒 Files selected for processing (2)
cub/benchmarks/bench/scan/deterministic/exclusive.cucub/cub/device/dispatch/tuning/tuning_scan.cuh
|
/ok to test 8a6ea0f |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cub/benchmarks/bench/scan/deterministic/exclusive.cu (1)
59-60: ⚡ Quick winsuggestion: use a determinism-specific benchmark name instead of
"base"to avoid ambiguous comparison outputs.This benchmark enforces
run_to_rundeterminism, 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
📒 Files selected for processing (2)
cub/benchmarks/bench/scan/deterministic/exclusive.cucub/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
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cub/benchmarks/bench/scan/exclusive/exclusive.cu (1)
51-57: 💤 Low valuesuggestion: 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
📒 Files selected for processing (4)
cub/benchmarks/bench/scan/exclusive/exclusive.cucub/cub/agent/single_pass_scan_operators.cuhcub/cub/device/dispatch/dispatch_scan.cuhcub/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
|
/ok to test 54c3314 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 91705db |
This comment has been minimized.
This comment has been minimized.
This reverts commit 91705db.
|
/ok to test 0743095 |
This comment has been minimized.
This comment has been minimized.
bernhardmgruber
left a comment
There was a problem hiding this comment.
A few more nits, otherwise this LGTM
|
/ok to test 999f76e |
🥳 CI Workflow Results🟩 Finished in 2h 36m: Pass: 100%/289 | Total: 11d 22h | Max: 2h 30m | Hits: 17%/1050949See results here. |
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:
Checklist