Repository navigation
gpu: gdn_delta_prepared keeps its state transposed, so each product's accumulator is the next one's A operand - #957
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: the kernel rewrite checks out against the old math, but this diff leaves chunk_mma and chunk_product with a dead K parameter.
Must fix
1. chunk_mma and chunk_product keep a const generic with one instantiation (kind B, unneeded element)
crates/gpu/src/linear/delta.rs:569, :614. This diff removes the only chunk_product::<16> calls. The one caller left is chunk_product::<HEAD> at :1450. So K, the if K == HEAD { PSTRIDE } else { K / 2 } branch and the "K / 2 otherwise" lines in both docs are dead.
Cost: the next reader must work out that the K / 2 stride is unreachable. The next kernel that adds a K can reuse the dead branch without anyone testing it.
Fix: drop the parameter. The HEAD instantiation stays the same, so ptx-scan stays identical.
/// A warp's 16 × 8 product `A·Bᵀ + c` over [`HEAD`] columns: `a` sixteen packed
/// rows, `b` eight, each `HEAD / 2` pairs at stride [`PSTRIDE`]. `c` and the
/// result are the MMA's accumulator fragment: lane `l` holds rows `l / 4` and
/// `l / 4 + 8`, columns `2·(l % 4)` and the next.
///
/// # Safety
///
/// `a` and `b` address initialized shared words of those shapes, and every
/// lane of the warp executes the call.
#[inline(always)]
#[allow(
clippy::needless_range_loop,
reason = "a range `for` is the loop the unroller recognizes; an iterator loop keeps its array in a local depot"
)]
unsafe fn chunk_mma(a: *const u32, b: *const u32, mut c: [f32; 4]) -> [f32; 4] {
let lane = thread::threadIdx_x() as usize % 32;
let r = lane / 4;
let k = lane % 4;
let mut base = 0;
while base < HEAD / 2 {
let mut af = [0; 4];
for i in 0..4 {
let at = (r + (i % 2) * 8) * PSTRIDE + base + k + (i / 2) * 4;
// SAFETY: rows r and r + 8 of A's sixteen, pair k or k + 4 of
// this step's eight.
af[i] = unsafe { *a.add(at) };
}
let mut bf = [0; 2];
for i in 0..2 {
let at = r * PSTRIDE + base + k + i * 4;
// SAFETY: row r of B's eight, pair k or k + 4 of this step's.
bf[i] = unsafe { *b.add(at) };
}
// SAFETY: every lane runs this step with its documented fragments.
c = unsafe { cuda_device::wmma::mma_m16n8k16_f32_bf16(c, af, bf) };
base += 8;
}
c
}In chunk_product, drop <const K: usize>, call chunk_mma(...) in its three lines, and say "stride PSTRIDE" in the Safety doc. Change the call at :1450 to chunk_product(.
Non-blocking
⚠ Bool at the call (R33): crates/gpu/src/linear/delta.rs:635 frag_a(.., false) and frag_a(.., true) read as nothing at six call sites. chunk_qk_store has the same shape, so this matches the file. Rename the argument at the call, or leave it.
⚠ Spill moved from 0 to 172 B (JIT local 72 B): the pin has its date and reason, and the PR body shows a net gain. Please confirm on a second card that the gain holds. The pin file is for sm_121a only.
Checked
- Duplicates: 5 new items checked (
frag_a,frag_mma,split_mma,prepared_reads,USTRIDE), none duplicated.split_mmarepeatschunk_product's three-term order with the roles swapped; two short copies, not a finding. dryer: 0 pairs. - Complexity: crapper flagged nothing. The kernel body is
#[kernel], so it was read for correctness only. - Kernel read against the old math: A fragment layout in
frag_a, B rows(8·tt+g)·PSTRIDE + 8·kb + qandb + 4, term order, the shared offsets (Q_LOW,KT,KT_LOW,IP,IP_LOW,D,B,END) againstPREPARED_WORDS(all agree), three barriers per chunk with no read-after-overwrite across chunks, prefetch boundstart + CHUNK < allagainstchunks(the launch contract keeps it insidework), andall == 0(the contract giveschunks ≥ 1). All blocked. - Silent failure: 3 sites followed (the prefetch bound,
metazero fortid ≥ 48, zero rows pastcount). The finite checks onyand on the state are unchanged. - Tests:
gate_linearprompt clauses protect the residual terms. Mutant: drop thekpresidual part (part == 1) and the error is ~2e-3, above the 2e-4 band, so the gate turns red. Mutant: prefetch the same chunk, red per the PR body. - Gates:
PROMPT_BAND2e-2 → 2e-4 withPIN(2026-10-29), measured values and a derivation.ptx-shapesspill pin dated.unsafe-ratchetpin dated. - Escape catalog: no shell code in the diff; no pattern matched.
Notes
- The PR body's timing and digest runs name head
1431e88d, base5fc77e82. The PR head isdae1e5d9, basee85f0c8c. Please state whether the kernel is the same code. - There is no
nvidia-smiline, only card, driver and CUDA fields.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_linear.rs, crates/gpu/src/linear/delta.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
dae1e5d to
4a6b88d
Compare
… accumulator is the next one's A operand
4a6b88d to
6e289b9
Compare
There was a problem hiding this comment.
Since the last review: the dead K parameters, unreachable stride branch and obsolete documentation are fixed in crates/gpu/src/linear/delta.rs:568 and its caller.
Verdict: CLEAN: the interdiff specializes the remaining HEAD-only products without changing their indexing or arithmetic.
Non-blocking
⚠ Still open: boolean argument (R33), crates/gpu/src/linear/delta.rs:633. Calls such as frag_a(rt[0], rt[1], false) leave the high/residual choice unnamed. Use a high/residual enum to name that choice. This is the unchanged advisory from the previous review.
Checked
- Duplicates: 0 new items in the interdiff; repository search confirms one remaining
chunk_productcaller. dryer reported 0 pairs; gpu-gates was excluded from its scan. - Complexity: crapper flagged no functions. Specialization removes a constant branch.
- Silent failure: 0 new sites. Both edited definitions match the former HEAD specialization, including all three products.
- Adversarial checks: no compact-stride caller remains; all lanes' A/B offsets, including the last pair and second B half, stay within their tiles. The compile-time assertion fixes HEAD at 128. Product order and inline attributes are unchanged.
- Tests: no test changes in the interdiff. The prior review's residual-drop and repeated-chunk mutation results are unchanged. GPU gates were not rerun here.
- Gates: no pins or bands moved in the interdiff.
- Escape catalog: no patterns matched.
Notes
The PR still lacks a nvidia-smi line. Its timing and gate evidence names base 5fc77e82 and head 1431e88d, rather than this review's commits. Identify the tested source relative to the current head. Attach identical ptx-scan output for the move-class specialization.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_linear.rs, crates/gpu/src/linear/delta.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
…d 16 B JIT local, after #957 kept its state transposed gate-ptx-spill went red on this row alone in the 0.3.11 release batch; #957 re-pinned only the sm_121a table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qwen3.8 FP4-Local의 prefill에서 GDN 재귀 커널이 state를 전치해 레지스터에 두도록 바꿔, 4096 토큰 prefill을 약 3% 줄입니다.
What and why
gdn_delta_prepared, the Gated DeltaNet recurrence of the prompt path, wrote each product's accumulator to shared memory and read it back as the next product's operand. It now keeps the state transposed in registers, so each product's accumulator is the next product's A operand and no state round trip remains. The high and residual products and their order are unchanged; only the operand roles move. The next chunk's rows are prefetched after the state projection, and a chunk costs three barriers.On a DGX Spark, Qwen3.8 FP4-Local prefill is 2.8% to 3.1% faster and TTFT p95 is 2.8% to 3.0% lower, with sample ranges that do not overlap. Decode is within the spread. The kernel output and state are bit for bit the same as the base on the four digest cases below.
Release notes: Changed: Qwen3.8 prompt prefill on DGX Spark is about 3% faster.
Code shape
The review reads these first. A box left unticked needs one line of why.
frag_a,frag_mma,split_mmaandprepared_readsare used only by it.gate_linearkeeps its band for the prompt cases at 2e-4 (it was 2e-2).tools/ref/ptx-shapes/sm_121a-cc12.1.tsvre-pinsgdn_delta_preparedfrom spill 0 and JIT local 0 to 172 B and 72 B with aPIN(2026-10-29):line, because the state now lives in registers;tools/unsafe-ratchet.txtre-pins gpu from 2812 blocks and 378 fns to 2795 and 381 with its reason.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none.What I ran
Timed runs use one DGX Spark,
bloomery-servewith--parallel 1 --ctx-size 16896, andnvidia/Qwen3.8-Flash-Next-FP4-Localat revisionb9ce18a6887e18c089fdea8509a33e63429a3300. A request is a 4096-token prompt with 128 generated tokens, on eight prompt windows of the code corpus (and of the prose corpus for the MTP prose arm). Each side has three recorded rounds after one discarded warm-up round. Base is5fc77e823dafa857e00823ceb06192c428effbbe, head is1431e88d96b86b35020db5825e4166b52273eafa, each built in its own checkout.Each cell is the median of three rounds with its range in parentheses.
Checks on the code of this branch, on a DGX Spark at
arch=sm_121a.just gate-gpu-linearbuilds and runsgate_linear; the prompt cases of the head and the base give the same output and state digests:The 4096-token prompt cases against the oracle, with the band at 2e-4:
Six mutants of the kernel (dropping the state, qk, inverse, causal or solved residual term, and prefetching the same chunk) each make
gate_linearfail, andcompute-sanitizer --tool racecheckon the gate reports 0 hazards.cargo clippy -p bloomery-gpu --all-targetson a DGX Spark (NVIDIA GB10, driver 595.84) reports 0 warnings.Hardware (if the change is for a machine)
nvidia/Qwen3.8-Flash-Next-FP4-LocalAI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.