Repository navigation
feat: add redux.sync.add warp reduction (sm_80+) - #223
Merged
Merged
Conversation
Single-instruction warp sum via @llvm.nvvm.redux.sync.add: device API, NVVM ReduxSyncAddOp, MIR import dispatch, lowering with [mask,value] -> [value,mask] flip, and convergent marking on export. Signed-off-by: sunteng <[email protected]>
goog00
force-pushed
the
feat/redux-sync-add
branch
from
June 18, 2026 05:40
924674b to
c116378
Compare
Collaborator
|
Thanks for the PR. LGTM 👍🏾 Both test cases return the correct warp sum of 496 across all 8 warps. The operand order flip in Reviewer not: the dialect stores [mask, value] but LLVM's intrinsic takes (src, |
8 tasks done
49 tasks done
5 of 26 tasks
nihalpasham
pushed a commit
that referenced
this pull request
Aug 12, 2026
…ent (#813) Option 3 from #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 #223/#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: #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]>
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
…le grid search (NVIDIA#223) * feat: autotuner core — declared configs, samplers, resumable grid search cutile::tune, the kernel autotuning core: - Config: one candidate as an ordered parameter map with a stable derived id; Triton's vocabulary (configs, prune) on the Autotuner builder. - Sampler trait (Optuna's word) deciding visit order; GridSampler is the default: exhaustive, budget-aware, and resumable from prior trials. - Trial/Outcome: invalid candidates (launch checks, correctness gate, compile errors) are recorded with their message and never abort the search. - Measurement through bench::do_bench (CUDA events, warmup, L2 clearing, medians); the user's setup closure applies a config, runs its correctness gate, and returns the closure to time. - JSONL trial log doubling as resume state for interrupted runs. Six CPU tests (sampler semantics, resume, budget, log roundtrip) and a GPU end-to-end test (gate rejection, winner selection, resume) wired into the GPU suite. Adds serde/serde_json as workspace deps for the trial records. Persisted, provenance-checked artifacts (with l2 cache key verification via NVIDIA#218) land in the follow-up. Signed-off-by: Melih Elibol <[email protected]> * fix: harden the tuner core against adversarial-review findings Two independent review passes converged on the resume/identity surface; all confirmed findings addressed: - Resumed trials for configs no longer in the space are dropped, and best_config skips ids absent from the space instead of returning None when a stale trial holds the global minimum. - Resumed Invalid trials are retried: invalidity may have been transient (poisoned context, OOM), and genuinely invalid candidates fail again cheaply. - The trial log now opens with an identity header (tuner name + space fingerprint); resuming against a foreign or differently-shaped log is refused loudly, as are unreadable/unappendable logs — logging was explicitly requested, so failures are errors, not silent no-ops. A torn final line no longer corrupts the next appended record. - Config ids JSON-encode string values, closing both aliasing forms (Int(1) vs Str(1); separator injection via strings containing , or =). - Winner selection is now contemporaneous: the two best candidates are re-measured head-to-head with do_bench_paired and the paired medians decide — sequential or resumed medians never pick the winner alone. - prune() predicates are stored and applied at run, so .prune() before .configs() composes instead of silently filtering an empty list. - Zero-rep measurements become Invalid instead of panicking in median; non-finite medians never win. New tests pin every behavior above; the GPU end-to-end now counts setup invocations to prove resume semantics rather than inferring them. Signed-off-by: Melih Elibol <[email protected]> * refactor: name the prune predicate type Signed-off-by: Melih Elibol <[email protected]> (cherry picked from commit 2ef87273f4c3195915f9debafadb33328cd4be34) * fix: harden the runoff epilogue; gate tune behind experimental-tune Adversarial-review round two, all in the runoff path: a finalist that fails its runoff setup now forfeits to the other (and the failure is attributed to the finalist that failed, not unconditionally to the leader); a NaN runoff median can no longer win; an exhausted budget skips the runoff instead of overshooting it; runoff trials are logged and carry the real paired-measurement metadata. Config ids now escape keys as well as values, and a whitespace-only trial log is headed instead of being refused on the next open. The module is now gated behind the default-off experimental-tune feature: the API is expected to change, and enabling the feature is the opt-in. Public types take #[non_exhaustive] so fields can grow without breakage, which also makes Config::new the only way to build a Config (id and params can no longer disagree). Signed-off-by: Melih Elibol <[email protected]> * docs: autotune example and performance-guide section A barebones cutile-examples/autotune.rs tunes the block size of an RMS normalization kernel end to end (declared candidates, prune, gate, paired runoff), behind the experimental-tune feature via required-features. The performance guide gains an Autotuning section covering the same flow, the misplaced Measuring Kernels section moves above the page footer, and the tile-shape and compile-hint sections now point at the tuner instead of leaving the search manual. Signed-off-by: Melih Elibol <[email protected]> * refactor: tune::Output and TrialState, following std naming run() now returns tune::Output, module-qualified like std::process::Output, instead of the stuttering TuneOutcome. The per-trial enum becomes TrialState (Optuna's trial.state), held in Trial.state. Result-style names are reserved for Result<...> aliases in Rust, and Ray uses Result for the in-memory return, so neither name is available for the persisted record without ambiguity; the record rename lands in the artifacts PR. Signed-off-by: Melih Elibol <[email protected]> * docs: fix variable name in the autotuning snippet Signed-off-by: Melih Elibol <[email protected]> * refactor: Searcher trait with GridSearch as the default Sampler collides with torch.utils.data.Sampler for exactly our audience, and grid search does not sample anything. Searcher is Ray Tune's term for the same role; GridSearch names the algorithm the default impl actually runs, and the planned TPE opt-in becomes TpeSearch. Signed-off-by: Melih Elibol <[email protected]> --------- Signed-off-by: Melih Elibol <[email protected]>
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.
Single-instruction warp sum via
@llvm.nvvm.redux.sync.add: device API, NVVMReduxSyncAddOp, MIR import dispatch, lowering with[mask,value]→[value,mask]flip, and convergent marking on export.Summary
Adds
warp::redux_sync_add(mask, value)— a single-instruction warp-wide sum reduction (PTXredux.sync.add, sm_80+). Previously a 32-lane warp sum needed 5×shfl+ 5×add; this lowers to one hardware instruction. Covers bothu32andi32(two's-complement add is bit-identical).Changes
redux_sync_adddevice API (mirrors existing*_synccollectives).ReduxSyncAddOp(2 operands[mask, value], 1 result) + register.emit_warp_reduxhelper + dispatch branch.convert_redux→@llvm.nvvm.redux.sync.add, flipping operands to[value, mask](LLVM wants(src, membermask));MirToLlvmConversionimpl.llvm.nvvm.redux.*convergent (warp collective — must not be hoisted into divergent branches).redux_sume2e example (sm_80-gated).Testing
Verified end-to-end on RTX 4080 SUPER (sm_89) — PTX emits
redux.sync.add.s32and each warp computes the correct sum:GPU Compute Capability: sm_89
--- Test 1: redux_sync_add over lane ids ---
Warp sums: [496, 496, 496, 496, 496, 496, 496, 496]
✓ All 8 warp sums correct (each = 496)
--- Test 2: redux_sync_add over input data ---
Warp sums: [496, 496, 496, 496, 496, 496, 496, 496]
✓ All 8 warp sums correct (each = 496)
SUCCESS: redux.sync.add produced correct warp sums
cargo oxide run redux_sumpasses (sm_89)cargo test -p dialect-nvvm -p llvm-exportpasses (op verify + convergent)redux_sum)Checklist
git commit -s)cuda-bindings/modified