Repository navigation
gemm: loop the copied dense MMA stages apart and widen the BF16 raster - #754
Conversation
The dense prompt MMA tile fetched stage s + 2 inside one loop over every stage, with a branch around the fetches for the last two, and read the copied BF16 weight's range check between the stage's wait and its barrier. For a weight copied asynchronously (bf16_mma_gemm and the HC up product) the stages that fetch now run as their own loop and the last two as another, and the check reads the landed words after the stage's products. A byte weight (MXFP8, FP8_B128) holds its pieces in registers across the products and keeps the one loop: the straight loop let ptxas hoist the next pieces' loads and spilled. The tile's raster group is now the weight's: eight column tiles for a BF16 weight, whose slab is half the bytes of the F32 activation tile it meets, and the F32 tiles' four for a byte weight. The dense_mma gate gains a BF16 row of 1,100 columns, a second raster group.
There was a problem hiding this comment.
Verdict: CLEAN: The stage split preserves checked bounds, shared-memory lifetimes and MMA accumulation order.
Non-blocking
⚠ Complete the GPU validation evidence: f32tile.rs:999 changes kernel scheduling, and f32tile.rs:850 changes raster geometry under AGENTS.md.
Attach the omitted gate-ptx-spill results for sm_86 and sm_121. Include the exact build/gate and timed A/B commands with output and model file paths; the supplied summaries leave CONTRIBUTING.md’s evidence list incomplete.
Checked
Duplicates: Two new associated constants and one macro checked; no duplicate owners. Dryer reported zero pairs; GPU gates were searched manually.
Complexity: Crapper flagged no functions. The stage products retain one owner in the macro.
Silent failure: Three range-check result sites followed through line flags to exact replay; exceptional operands still select replay.
Tests: The added (33, 64, 1100) row protects f32tile.rs:850. Limiting the raster to its first group leaves tile 8 unwritten; the band check fails. The PR reports this FAIL-first run.
Gates: No bands, tolerances, pins or cases were relaxed or removed.
Adversarial: Minimum K, buffer reuse, delayed range checks and partial raster groups checked.
Escape catalog: No C1–C4 patterns matched.
Notes
GPU gates were not rerun during validation. The FAIL-first GPU result above is reported in the PR body; validation here was static.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/gemm/f32tile.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. |
Qwen3.8 prefill의 dense 행렬곱 커널에서 BF16 weight의 stage 반복을 따로 돌리고 raster group을 넓혀 큰 shape의 커널 시간을 줄이는 작업입니다.
Part of #565.
What and why
The dense prompt GEMMs of Qwen3.8 on a GB10 run through one MMA tile,
bf16_mma_tile. The NVFP4 checkpoint's dense weights go throughbf16_mma_gemmand FP4-Local's throughmxfp8_mma_gemm, andhc_gated_up_mma_mix_4uses the tile too. This PR changes how the tile runs its stages and lays out its blocks:MmaRowsgains two associated consts.COPIED(defaulttrue) is set for a weight whose fetch is an asynchronous copy, so a thread holds no piece in registers across the products.ByteRows(MXFP8 and FP8_B128) sets it tofalse.GROUPis the number of column tiles in one raster group: 8 by default, andByteRowskeeps its current 4.stage_pass!, holds a stage's products. WithCOPIED, the stages that fetch (0..stages-2) run as one loop with the fetch always on, and the last two stages as a loop with it off, so no branch surrounds the fetch. A byte weight keeps one loop that picks withs + 2 < stages: it holds its next pieces across the products, and hoisting their loads in a branch-free loop would spill.W::landed_fitsmoved from between the stage wait and the barrier to after the first step's products. No warp overwrites that stage buffer before the next stage's barrier, so the check reads the same data (the SAFETY text is updated).W::GROUP: eight column tiles for a BF16 weight (bf16_mma_gemmandHcUpRows), four for a byte weight. A wave of resident blocks reads the weight slabs of its rows and the F32 activations of its columns. A BF16 weight is half an activation's bytes a value, and eight tiles balance the two on GB10's 96 resident blocks.gate_gemm --case dense_mmagains a BF16 row(33, 64, 1100). Its 9 column tiles make a second raster group at group 8. The only earlier BF16 row with two groups was n=513, which at group 8 is one group.hc_gated.rsis not touched.HcUpRowsis a copied BF16 weight, so it takes the new defaults; its kernel time in the profiled run stays within 1.3% of main (275.0 to 271.5 ms on FP4-Local, 271.3 to 274.2 ms on NVFP4).Release notes: Changed: the dense prompt matrix multiply for BF16 weights on GB10 runs its copied stages as separate loops with a wider raster, which cuts its kernel time in the large Qwen3.8 shapes; MXFP8 and FP8_B128 weights keep their loop and group size.
Code shape
stage_pass!, and all three loops use it. The raster group size, a local in the tile before, now has one owner, theGROUPconst.group_sizeis removed.f32tile.rsare unchanged (49unsafe {blocks, 20unsafe fn) andtools/check-unsafe.shis ok.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.cargo fmtandtools/check-comments.share clean. I could not run clippy for the GPU crate: the machine I tried has no CUDA toolkit, sobloomery-gpudoes not build there.Duplication found or removed (
path:line), or "none": the duplicate scan flaggedcrates/gpu/src/gemm/f32tile.rs:487againstcrates/gpu/src/flash_gqa.rs:189. Both are namedGROUP, but one is the query heads per key head and the other is the column tiles of an MMA raster group. I left it.What I ran
Output is unchanged
The kernel bench below compares the FNV digest of every output between main and head. They are equal on every shape.
just gate-gpu-gemm,just gate-gpu-bf16,just gate-gpu-mxfp8andjust gate-gpu-hc-gatednot run as recipes: the node run built each gate binary withcargo oxide buildand ran it throughbash tools/gpu-gate.sh, the last step of each recipe. The measured commit ran them on a DGX Spark:Every
dense_mmarow reportseager_graph_bits=true, so a graph replay gives the eager bits. In the server A/B below, main and head give the same greedy tokens (128 tokens, three prompts) on both checkpoints, and the same two tokens in the profiled request.FAIL-first
I changed the raster so it covers only its first group of column tiles (
n.div_ceil(MMA_COLS).min(W::GROUP)), built that, and ran the same gate.gate_gemm --case dense_mmaexits 1 and the only FAIL lines are the two of thedense_mma bf16 rows=33 K=64 n=1100row, withworst_err_over_band1.1e31 from the unwritten tile 8. Every otherdense_mmarow passes.Speed
Kernel bench on a DGX Spark (GB10, clock cap left on): the production entries
enqueue_bf16_mmaandenqueue_e4m3_mmawith synthetic in-range operands, 4096 columns, 3 warmup and 10 timed launches a shape, main and head alternated three times each, median of three. Shapes are Qwen3.8's dense products and their rank-split shapes. Main here is a commit with the same GPU code as the A/B's base.Weighted by how often each shape launches in a 4,096-token prompt (N = 1), one prompt's BF16 launches take 608.1 ms on main and 529.5 ms on head (-12.9%, -78.6 ms), and its MXFP8 launches 675.4 ms and 663.5 ms (-1.8%), which is inside the run-to-run spread. The small shapes (a K of 640 or less, or 512 rows or fewer) vary by a few percent either way. Driver JIT registers:
bf16_mma_gemm124 to 128,fp8_b128_mma_gemm124 to 122,mxfp8_mma_gemm126 unchanged,hc_gated_up_mma_mix_4128 with 96 local bytes on both sides, the others 0 local bytes.Server A/B on a DGX Spark: Qwen3.8 FP4-Local and NVFP4, C = 1, draft off, three 4096-id code windows with 128 greedy tokens, median of three requests. Each checkpoint started with a discarded warm load; FP4-Local ran head then main, NVFP4 main then head. The clock cap was lifted only around each arm's requests. One extra profiled request an arm collected the kernel times.
Delta (head against main): NVFP4 prefill +2.1% (1285.5 to 1312.7 tok/s) and the BF16 dense kernel -12.9% in the kernel bench (608.1 to 529.5 ms); FP4-Local prefill -3.1% (1306.4 to 1265.3 tok/s) with 29.6 ms less GPU kernel time, from one server run per arm, so a single observation.
On NVFP4, time to first token fell 65 ms (-2.0%), the 423
bf16_mma_gemmlaunches took 77.4 ms less, close to the kernel bench's 78.6 ms estimate, and all GPU kernels together took 70.0 ms less (-2.2%). On FP4-Local, the GPU kernel sum is 29.6 ms lower (mxfp8_mma_gemm17.0 ms, the HC up kernel 3.5 ms), yet prefill reads 3.1% lower. The head arm's decode witness was also 2.1% below main's, and decode does not run these kernels (its one-row path is a SIMT kernel), so I read that arm as a different card state and make no claim from its prefill number. I have no second pair for it.Measured head against the PR head
The measurements ran on commit
e24bb8cceover base2a7005b8a, with the kernel bench's main at0429f1483, two docs and serve commits above that base with no GPU code change. The PR head is285e3e7dcon current main501db04fe. The rebased commit9318baadfwas a pure rebase:range-diffshows1: e24bb8cce = 1: 9318baadf, and the six upstream commits between the bases (docs, serve, tools) touch none of the paths this commit changes. The PR head differs from9318baadfonly in where oneSAFETYcomment sits, moved onto theunsafeline it explains so the lint accepts it; no code changed. I did not rerun the gates or the timings on the PR head.Hardware
DGX Spark (GB10), GPU, driver and CUDA lines from
nvidia-smiof the gate job:Models: Qwen3.8 FP4-Local and NVFP4. Build:
cargo oxide build --arch sm_121a. The gates and the server A/B ran on one DGX Spark and the kernel bench on a second one of the same kind.What I ran into
None of this blocks the PR.
just ptx-comparewere not run. The sm_121a driver JIT lines above show 0 local bytes for the dense entries and 96 forhc_gated_up_mma_mix_4, as before.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.