Skip to content

docs(warp): point integer reductions at redux.sync, with the measurement - #813

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:docs/warp-reduce-redux-note
Aug 12, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:docs/warp-reduce-redux-note

Conversation

@vyncint

@vyncint vyncint commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Option 3 from #811 — document the gap, change no API.

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 #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-warp u32 sum reductions, 30 timed launches
after 5 warmup, same kernel with only the reduction call swapped:

form µs/launch
butterfly (warp_reduce / hand-written) 159.4
warp::redux_sync_add 33.6
4.74x

Bit-identical: wrapping u32 addition is associative modulo 2³² and
min/max/and/or/xor are exact, so reduction order cannot change the answer.

Where it went

Both places a reader might look:

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

  • Integers only — there is no f32 redux before sm_100, so floats keep
    the butterfly.
  • A full converged 32-lane warp — which is the contract the shuffle
    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_partial for the tail case.
  • It will not assemble below sm_80 — so the call needs gating the way the
    redux_sum example gates it, on compute_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_reduce select
this 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-device clean, so the
    intra-doc link to redux_sync_add resolves;
  • sphinx-build -W --keep-going -b html succeeds;
  • all eight function names, reduce_sum_f32_partial, and the redux_sum
    capability gate checked against the source rather than remembered;
  • cargo fmt --check clean.

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]>
@nihalpasham

Copy link
Copy Markdown
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:

  • all eight redux_sync_* names in the table exist with the documented semantics (add is wrapping, u32/i32 equivalent);
  • warp_reduce's Sum::combine is wrapping_add, so the bit-identical claim is sound;
  • the redux_sum example's sm_80 gate and skip message match the note.

Landing once CI is green. Partially addresses #811; the root cause (target-aware device code) stays open.

@nihalpasham
nihalpasham merged commit afadcd8 into NVIDIA:main Aug 12, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation intrinsics Device intrinsics and libdevice math mappings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants