Repository navigation
docs(warp): point integer reductions at redux.sync, with the measurement - #813
Merged
Merged
Conversation
Option 3 from NVIDIA#811. `warp_reduce` is generic over `T`, so a full warp always costs five shuffles plus five combines; `redux.sync` does an integer reduction in one instruction and cuda-oxide has exposed it since NVIDIA#223/NVIDIA#258. Nothing told a reader that, so the book taught the butterfly and stopped there. Measured on an A10G (sm_86), 1M threads x 64 full-warp u32 sum reductions, 30 timed launches after 5 warmup: 159.4 us per launch for the butterfly against 33.6 us for `redux.sync` -- 4.74x, bit-identical. Wrapping u32 addition is associative modulo 2^32 and min/max/and/or/xor are exact, so reduction order cannot change the answer. Both places a reader might look now say so: * the book's "Warp reduction" section gains a subsection naming all eight functions, the measurement, and the constraints; * `warp_reduce`'s own rustdoc carries a short performance note, since that is what someone about to call it reads. The scope of the number is stated in both: the probe kernel does almost nothing but reduce, so 4.74x sizes the primitive, not an application. A kernel reducing once after a memory-bound pass sees very little. Three constraints are spelled out rather than implied: integers only (there is no f32 redux before sm_100); a full converged 32-lane warp, which is the contract the shuffle reductions already require, with sub-warp tiles and short tails staying on shuffles; and that it will not assemble below sm_80, so the call needs gating the way the `redux_sum` example gates it. Also corrected "five instructions" to "five shuffle steps" in the sentence above, since the butterfly is five shuffles plus five combines and the new subsection counts instructions a few lines later. No API or codegen change: NVIDIA#811 stays open for making `warp_reduce` select this automatically, which needs device code to know its target architecture. This documents what is available today. Verified: `RUSTDOCFLAGS="-D warnings" cargo doc -p cuda-device` clean, so the intra-doc link resolves; `sphinx-build -W --keep-going` succeeds; all eight function names, `reduce_sum_f32_partial`, and the `redux_sum` capability gate checked against the source. Signed-off-by: Vyncint Ng <[email protected]>
Collaborator
|
Gist: implements #811's option 3: document the gap with the measurement rather than change an API that can't see the target arch from device code. Verified here:
Landing once CI is green. Partially addresses #811; the root cause (target-aware device code) stays open. |
nihalpasham
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Option 3 from #811 — document the gap, change no API.
warp_reduceis generic overT, so a full warp always costs five shuffles plusfive combines.
redux.syncdoes an integer reduction in one instruction andcuda-oxide has exposed it since #223/#258 — but nothing told a reader that, so
the book taught the butterfly and stopped there.
The number
A10G (
sm_86), 1M threads × 64 full-warpu32sum reductions, 30 timed launchesafter 5 warmup, same kernel with only the reduction call swapped:
warp_reduce/ hand-written)warp::redux_sync_addBit-identical: wrapping
u32addition is associative modulo 2³² andmin/max/and/or/xor are exact, so reduction order cannot change the answer.
Where it went
Both places a reader might look:
functions, the measurement, and the constraints;
warp_reduce's own rustdoc carries a short performance note, since that iswhat someone about to call it actually reads.
Scope, stated in both
The probe kernel does almost nothing but reduce, so 4.74x sizes the primitive,
not an application. A kernel that reduces once after a memory-bound pass will
see very little. Both texts say so — I would rather a reader calibrate than take
a micro-benchmark as a promise.
Three constraints are spelled out rather than implied:
f32reduxbeforesm_100, so floats keepthe butterfly.
reductions already require (Reduce over the live lanes of a partial warp #672: "every lane must be launched and
converged"), so this asks nothing new. Sub-warp tiles and short tails stay on
shuffles, with a pointer to
reduce_sum_f32_partialfor the tail case.sm_80— so the call needs gating the way theredux_sumexample gates it, oncompute_capability.One small correction alongside
The sentence above the new subsection said the butterfly is "five instructions".
It is five shuffles plus five combines, and the new subsection counts
instructions a few lines later, so I changed it to "five shuffle steps" to keep
the two consistent.
Not closing #811
No API or codegen change here. #811 stays open for making
warp_reduceselectthis form automatically, which needs device code to know its target architecture
— the broader design question. This documents what is available today.
Verification
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p cuda-deviceclean, so theintra-doc link to
redux_sync_addresolves;sphinx-build -W --keep-going -b htmlsucceeds;reduce_sum_f32_partial, and theredux_sumcapability gate checked against the source rather than remembered;
cargo fmt --checkclean.