Repository navigation
gemm: fold the GEMM epilogues in F32 and redo a tile exactly only when it leaves range - #700
Conversation
…n it leaves range A GEMM block walks its tile with the F32 epilogue alone (sum32), marking any activation block scale under 2^-64, and each warp votes whether one of its outputs ended non-finite or a scale was marked. Only then does the block walk the tile again with scaled_sum, one n-tile of four accumulators at a time (F64 for NVFP4), and store that walk's outputs. Without either sign no step left the F32 normal range, so the F32 walk's bits are scaled_sum's (grouped.rs module doc, "Range"). scaled_sum at every step and the NVFP4 tile's F64 accumulators kept the grouped and gemm32 entries in local memory on sm_121: at 4096 prompt ids of Qwen3.8 FP4 on GB10, gemm_nvfp4p took 28.3 ms a launch, and 4.5 ms with this change. The PTX spill pins of sm_121, sm_121a and sm_86 on cc 12.1 follow the scans.
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix defect was found in the changed code.
Non-blocking
⚠ Cover the small-scale retry trigger: crates/gpu/src/gemm/grouped.rs:528. The PR reports that deleting this mark leaves nvfp4_native green, so underflow recovery lacks regression coverage. Add tiny, nonuniform activations with small UE4M3 weight scales and an expert scale that restores a normal output. Check against the existing F64 reference and show that deleting the mark fails.
⚠ Complete the performance evidence: crates/gpu/src/gemm/grouped.rs:1590. The fast path adds one block barrier and 32 shared bytes per GEMM block while changing register use. For the occupancy change class, attach register/shared-memory scan columns and the A/B's measured commit pair, model filenames, and exact timing commands with output. The current tables cannot identify or reproduce the measured builds.
Checked
Scope: both cited production lines are added by the diff; both findings remain advisory.
Tests: no test files changed. The PR reports that removing the exact walk fails and removing the small-scale mark passes; these mutations were not reproduced here.
Gates: spill pins and the unsafe ratchet changed with dated reasons; no numerical tolerance changed.
Range: the shared vote is block-uniform; NVFP4 retries retain F64 accumulation through expert scaling.
Escape catalog: no C1–C4 pattern matched the cited paths.
Notes
CUDA gates were not run during validation.
Card check: needs-gpu. This pull request changes crates/gpu/src/gemm/gemm32.rs, crates/gpu/src/gemm/grouped.rs, crates/gpu/src/gemm/kernels.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)
Filed outside this PR: #702
|
The review is done and the contribution check passed, so I'm merging this. |
GB10에서 4K prompt prefill이 약 3배 느려진 문제를, GEMM epilogue를 F32로 먼저 걷고 범위를 벗어난 블록만 정확하게 다시 걷게 해서 고칩니다.
Part of #565. Fixes the High item in #699.
What and why
e4364b6cb("gpu: preserve Q8 rounding in fused NVFP4 activations", part of #687) made every grouped and gemm32 GEMM epilogue step callscaled_sum, which checks each F32 result for leaving the normal range and falls back to F64, and it made the NVFP4 tile accumulators F64. On an sm_121 build the GEMM kernels then spill heavily. A 4,096-id prompt prefill of Qwen3.8 FP4-Local on a DGX Spark ran at 387.6 tok/s on main and runs at 1118.45 tok/s with this change. The commit's PTX pins went only into the sm_121a table, so the sm_121 and sm_86 spill pins did not go red.This change walks each tile with the F32 epilogue alone and marks any activation block scale under 2^-64. Each warp votes with
warp::anywhether one of its outputs ended non-finite or a scale was marked. Only a voted block walks the tile again withscaled_sum, one n-tile of four accumulators at a time (F64 for NVFP4), and stores that walk's outputs. When no vote is cast, no step left the F32 normal range, so the F32 bits are the bitsscaled_sumproduces. The proof is in the "Range" section of thegrouped.rsmodule doc.fold4!,gemm_nts!,range_walks!andexact_vote!ingrouped.rsserve both the grouped and the gemm32 families.scaled_sumnow sharesinner32with the newsum32.nvfp4mma.rs(the native sm_121agemm_nvfp4_mma), the dense BF16 MMA owners, routing and the activation producers.PINlines, so the base code's GEMM rows go red against the sm_121 table (violations=54 FAIL, 12 of them GEMM rows). The unsafe ratchet goes from 2248 to 2250 for the twoVOTESblocks (write and read), each with its own SAFETY line.Release notes: Fixed: Qwen3.8 4,096-id prompt prefill on a DGX Spark runs at 1118.45 tok/s instead of 387.6 tok/s on main, with the same greedy tokens.
Code shape
range_walks!and onefold4!;scaled_sumreusesinner32instead of repeating its two operations.scaled_sumgave before.PINlines.cargo fmtis clean.cargo clippywas not run on this head here.Duplication found or removed (
path:line): none.What I ran
Hardware: a DGX Spark (GB10), sm_121 and sm_121a builds,
bloomery-dev:cuda13.3.1container, models Qwen3.8-Flash-Next FP4-Local revb9ce18a6and NVFP4 revfc694b54.The checks below ran on the kernel source of this change before the final rebase onto main. A later macro squash left the PTX identical (COMPARE_RC sm_121 0), and the commit main gained since touches no GEMM file. I did not rerun the A/B on the rebased head.
Gates (
BLOOMERY_BOX_LOCAL=1,gate_gemm):gate_gemm: split shard ... is missing).--case_synth,g32,g38,dense,fault, q5_0p: CASE_RC 0 for every case, 988 PASS, 0 FAIL.--case nvfp4_native(its Range legs run the plaingemm_nvfp4p): 37 PASS, 0 FAIL.ptx-compareagainst main at sm_121: changed 15 entries, all grouped and gemm32gemm_*; at sm_121a COMPARE_RC 3 for the same reason.Spill bytes a thread at sm_121 (
ptx-scan, spill and JIT local), main against this change:gemm_q4kgemm_nvfp4pgemm_q6kgemm_q5kgemm_q3kgemm_iq3sgoes from 0 / 0 to 24 / 16. Innsysof the 4,096-id prefill,gemm_nvfp4ptakes 8.140 s over 288 launches on main and 1.286 s on this change.FAIL-first:
gemm_q4k spill=1284 pinned=0 ABOVE,gemm_nvfp4p spill=504 pinned=72 ABOVE,gemm_q6k spill=596 pinned=532 ABOVE, andgemm_iq3s spill=0 pinned=24 BELOW.nvfp4_nativeRange legs fail:Range(7.523164e-37, 3.4028235e38)withnative=falseshows wrong=16.Speed, 4,096-id code prompt, C=1, greedy, sm_121 release builds of main and this change, one server load an arm, two requests an arm, clock cap lifted while the requests run:
Prefill is 2.9 times main's in every row. Decode at 128 tokens moves by +0.4%. The 16-token decode in the first row (-3.3%) did not repeat at 128 tokens. Greedy tokens are equal per request in every pair.
What I ran into
This does not block review.
v41_gate_q3kandv41_gate_q3k_synth, because that model is not on the machine. Q3_K shares its epilogue with Q6_K, IQ3_S and IQ4_XS, whose synthetic bit cases passed, and sel_fault_Q3K passed.nvfp4_nativegreen, because a constant-input Range leg cannot produce an F32 subnormal intermediate under a normal output. The exact walk itself is covered: compiling it out fails the Range legs.gate-ptx-spillis red on main already: sm_121 has 42 unpinned non-GEMM entries and 3 vision rows without a pin, and sm_121a has 3 more from other owners. No GEMM row is off its pin on this change.gemm_q4kspills 1284 bytes on main and none here). I did not time it.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.