Repository navigation
gpu: sum the F32 tile two lanes a thread and run the routers' prompt logits on it - #763
Conversation
…logits on it The F32 tile kept one lane sum of the row walk per thread, so each 32-value chunk cost a thread sixteen 4-byte shared loads for 64 multiply-adds. A thread now keeps the lane sums 2p and 2p + 1 of eight rows by eight columns: sixteen threads cover a chunk, one 8-byte load per row and column feeds 128 multiply-adds, and the butterfly runs xor 16, 8, 4, 2 of the lanes as xor 8, 4, 2, 1 of the threads and xor 1 as the add of the pair. Every lane sum and the tree are the row walk's, so each output keeps f32_gemv's bits. A block is eight warps; a row group with no live row is neither staged nor summed. The qwen3moe and gated routers' prompt logits carried their own copy of the tile body. They now call f32_tile_body over their rows and launch through tile_launch, and q8f32's f32_tile_chunk goes with the copy.
On GB10 (ptxas 13.3.73, driver 595.84) gate-ptx-spill reads qwen35moe_router_norm_m at 0 spill bytes and 0 driver-JIT local bytes, under the 32 and 8 its sm_121 and sm_121a rows pin and the 8 its sm_86 row on cc 12.1 pins, so the gate fails BELOW on the base tree as well. The rows now hold what the scans read.
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix defect found in the tile layout, replay, or router launch checks.
Non-blocking
⚠ Measure the final MMA paths: crates/gpu/src/gemm/f32tile.rs:1013. Default replay grows from two passes to eight; HC up uses four. Each pass copies all 32 activation columns. For a full 32×32 replay subtile, the default adds (8-2)*32*4*K/32 = 24*K requested activation-copy bytes per token [derived], before weight reads. The occupancy/geometry class calls for a timed A/B on the contributor's card. Attach final-code dense BF16 and HC MMA comparisons, including exceptional operands.
⚠ Complete the run witness: crates/gpu/src/gemm/f32tile.rs:281. The PR names cards and run results but omits the tested head hash and exact model file. Attach both tested commit hashes, the model file, and command output under CONTRIBUTING's evidence list so the results identify the code and workload they verify.
Optimization headroom
- E. Less work: crates/gpu/src/gemm/f32tile.rs:362. Use the existing column-group coordinates to skip wholly unused groups' computation and copies inside this body. At rows=513, K=2560, n=70, omitting 16 activation lines in the last column block across 17 row blocks saves
16*4*K*17/70requested activation-copy bytes per token, about 39,790 [derived].
Checked
Duplicates: both dryer pairs are distinct CUDA entries that share the existing tile body.
Complexity: f32_tile_at rises 7→14 through paired reduction loops and tail guards. Its kernel bounds and reduction order were checked without proposing a split.
Silent failure: tail clamps supply padding whose outputs are not stored; marked replay preserves healthy cells, and non-finite router logits raise FaultSite::Router. Launch shape failures return named errors.
Tests: none added or changed. Existing wide512 order compares each token's logits and routing outputs; the PR reports its xor-8/xor-4 swap mutant fails.
Gates: PTX and unsafe pins tighten with dated reasons; no tolerance relaxation or gate removal.
Escape catalog: no C1–C4 pattern matched.
Notes
GPU gates were not run during validation. GPU results and the mutant outcome are author-reported. The run witness is incomplete; gpu.json records evidence: false.
Card check: needs-gpu. This pull request changes crates/gpu/src/arch/qwen3moe/router.rs, crates/gpu/src/gemm/f32tile.rs, crates/gpu/src/gemm/kernels32.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의 4K prompt에서 router logits kernel이 thread 하나에 합 두 개를 들게 해서 load당 FMA 수를 늘려 빨라지게 하고, router마다 따로 있던 tile 본문 복사본을 하나로 합치는 작업입니다.
Part of #565.
What and why
In a Qwen3.8 prompt,
qwen35moe_router_logits_512_bf16multiplies the 513 router rows (K 2560) with the activations of each ubatch, 96 launches for a 4,096-id prompt. The kernel and the other F32 tile entries ran one body, and the router crates held their own copies of it. The F32 tile is bound by the register file: each output keeps 32 lane sums, so the tile cannot grow. What can change is how many FMAs run per shared load.This PR changes how the F32 tile body (
f32_tile_bodyincrates/gpu/src/gemm/f32tile.rs) assigns lane sums to threads. The summation order does not change (the row walk's lane sums and the xor 16, 8, 4, 2, 1 butterfly), only which thread holds which lane sum.cp.asyncstages and 48 KiB of static shared memory.qwen3moe_router_logits,qwen35moe_router_logits,qwen35moe_router_logits_512andqwen35moe_router_logits_512_bf16each carried a copy of the tile body (logits_body, an inline copy in the qwen3moe entry,store_rows,store_rows_live). They now callf32_tile_bodyand sharetile_launchfor the grid and the common shape checks.f32_tile_chunk,fma_rowsandTILEinq8f32.rshad no remaining user and are deleted.f32_tile_gemm,mxfp8_tile_gemm,fp8_b128_tile_gemm,bf16_tile_gemm) take the new layout too. Their launch bounds and contract are 256 threads.MmaTile::replay, the exact recomputation of rows and columns that have an out-of-range operand, used by dense MMA and HC MMA) takes its row count from a per-weight constant,MmaRows::REPLAY_ROWS, next to the existingCOPIEDandGROUPconstants. The default is 1;HcUpRowsincrates/gpu/src/hc_gated.rssets 2.replayrunsTILE_ROWS / (ROW_GROUPS * W::REPLAY_ROWS)passes, and an inlineconstassert refuses any other count. Two rows a pass madebf16_mma_gemmspill 264 bytes on an sm_86 build, where main has none, so the dense weights replay one row a pass (126 registers, no spill). One row everywhere madehc_gated_up_mma_mix_4spill more on sm_121 (732 bytes against main's 492), so that weight keeps two (see FAIL-first). The replay is a rare path, so the pass count does not affect speed.qwen35moe_router_norm_mwas already BELOW its pinnedcc 12.1PTX rows on main (spill 0 against a pin of 32, JIT local 0 against 8). This PR touches the same tables, so it lowers that row to the reading too.The change is smaller than what it replaces:
crates/goes from 727 deleted lines against 287 added, and the unsafe ratchet falls from 2282 to 2265 blocks and from 285 to 281 functions.Release notes: Changed: Qwen3.8 prompt router logits run about 31% faster per launch in a kernel profile; end-to-end prefill speed is inside the run-to-run spread.
Code shape
q8f32.rshelpers are gone; every F32 tile entry callsf32_tile_body, andtile_launchis the one place for the launch checks.f32_tile_chunk,fma_rowsandTILEare removed.tile_launchrefuses a bad token count, input length,kor input alignment with a named shape error.PIN(2026-10-24)lines with the reading they follow.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": the router tile-body copies incrates/gpu/src/arch/qwen3moe/router.rsand the helpers incrates/gpu/src/q8f32.rsare removed. The duplicate scan reports no candidate on the head.What I ran
Output is unchanged
Prompt logits are bit-identical to the decode F32 gemv. On an RTX 5090 (
just gate-gpu-qwen35moe-moe --case shape,wide512, rc 0):wide512 ubatch n=70 ... vs host: 70 tokens withlogits_bits=true,ids_exact=trueandweights_bits=true.wide512 order ubatch n=70 vs the fused launch per token: 70/70 bit-identical PASS. Theorder fused m=1, 5, 8lines match the F32 gemv bit for bit, on inputs where 3485 of 4104 logits differ from an f64 rounding.shape kernel=qwen35moe_router_fused_512_bf16 local_depot=false ld_local=0 st_local=0 PASS, and the same for the route kernel.The F32 tile against the decode F32 gemv,
just gate-gpu-gemm --case g32_f32tile: rc 0 on an RTX 5090 and rc 0 on a GB10, withbits_differ_vs_f32_gemv=0andpast_end_untouched=trueon every shape (rows 96, 100, 128 and 512, K 2560, n from 1 to 4095).--case g32_refuseand--case dense_mmaare rc 0 on the RTX 5090.On the final code, on an RTX 5090 (
BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen35moe-moe --case shape,wide512, rc 0): the router kernels readlocal_depot=false,wide512 ubatch n=70 vs the fused launch per token: 70/70 bit-identical PASSandwide512 bf16 ubatch n=70 vs the f32 weight widened: 70/70 bit-identical PASS.On one GB10,
just gate-gpu-hc-gatedis rc 0 on the replay code of this change (bf16_mma_gemmandhc_gated_down_mma_4readlocal_depot=false). On the head that goes up, also on one GB10:just gate-gpu-gemm --case dense_mmarc 0 with 72 PASS and 0 FAIL, including the replay cells for BF16, MXFP8 and FP8_B128 (a 130 by 130 output with an out-of-range operand at row 64 or column 129:others_kept_k=true odd_lines_exact=true PASS);just gate-gpu-bf16rc 0 with 309 PASS;just gate-gpu-mxfp8rc 0 with 343 PASS.The
g32_f32tileandg32_refuseruns above are from an earlier form of this change. The F32 tile body and the routers' path are the same on the final code; only the MMA replay row count differs.FAIL-first
wide512 order ubatch n=70 vs the fused launch per tokenfail with 0/70 bit-identical, the gate print FAIL, and the run exit 1. The check catches a wrong summation order in the new tile.bf16_mma_gemmspills 264 bytes on an sm_86 build (ptx-compareagainst main:spill:0->264). On the same code, one replay row reads spill 0 and 126 registers, four rows reads 164 registers and one block per SM, and aforloop in place of thewhileloops leaves 264 unchanged, so the loop form is not the cause. One row for every weight madehc_gated_up_mma_mix_4worse on sm_121 and sm_121a (spill 732 against main's 492), hence the per-weight count. With the final codebf16_mma_gemmand every other gemm entry match their pins on sm_86, sm_121 and sm_121a.PTX shape
hc_gated_up_mma_mix_4reads lower than its pins, and the tables carry the new readings: sm_86 atcc 12.11352/176 to 484/88 (spill/JIT local), sm_121 and sm_121a atcc 12.1492/176 to 364/88. In the defaulttools/ref/ptx-shapes.tsvthe spill goes from 1352 to 484; that reading comes from an sm_86 ptxas run on a GB10, and thecc 8.6JIT and the stack frame were not measured.just ptx-compare upstream/main gate_gemm(sm_86 build, JITcc 12.1) lists 332 entries on each side, none added or removed, 13 changed, all on this PR's paths: the F32 tile entries and the routers' prompt logits (reqntid512 to 256), and the MMA entries whose replay runs the tile body, each at or below main:bf16_mma_gemmregisters 128 to 126, spill 0 to 0.fp8_b128_mma_gemmregisters 128 to 122.mxfp8_mma_gemmregisters 128 to 124.hc_gated_down_mma_4registers 128 to 124.hc_gated_up_mma_mix_4spill 1352 to 484, JIT local 176 to 88.just ptx-compare upstream/main gate_hc_gatedlists the same 13.just gate-ptx-spillhas one violation on each of sm_86, sm_121 and sm_121a:gqa_flash_fold_mma_256_p12_selabove its pin. It reads the same on main, and this PR does not touch it. Thecheck-ptx-namesrecipe andjust lint(3 warnings, the same count as main) are rc 0 on this code.Speed
Kernel bench (a synthetic input of the real shape: 513 rows, K 2560, 2048 tokens), one GB10 with the clock cap in place, so only same-run comparisons count:
End to end on one DGX Spark: FP4-Local Qwen3.8, 4096-id code windows (offsets 0, 4096, 8192), 128 greedy tokens, one request at a time, draft off. Each checkpoint started with a discarded warm load, a host settle and a read probe preceded each arm, and the greedy tokens of head and main are equal per window. Main was
2a7005b8a. Each arm served withBLOOMERY_DRAFT=off bloomery-serve -m <model> --host 127.0.0.1 --port <port> --parallel 4 --ctx-size 16896.Delta (head against main): FP4-Local prefill -0.4% (1308.4 to 1303.3 tok/s), inside the run-to-run spread; the router logits kernel takes a median of 0.708 ms a launch in place of 1.022 ms (-31%) in a profiler capture of one 4096-id prompt.
The per-window prefill speeds were 1297.2, 1321.7 and 1303.3 tok/s on head against 1298.3, 1314.6 and 1308.4 tok/s on main. I claim no end-to-end prefill gain: the expected saving of 0.8 to 1.0% of the prompt time is inside that spread. Decode on the same arms read 30.20 tok/s on head and 30.56 tok/s on main, a path this change does not touch.
The kernel row is a profiler capture of one extra request on NVFP4 loads (96 launches on each side, 93.4 ms against 69.1 ms in total). The main side of that NVFP4 pair ran in a degraded state: its read probe was the lowest of the sitting and its first request prefilled at 1157.0 tok/s, so I do not use that pair's end-to-end speeds. The kernel launch medians are less sensitive to that state, and the head's median (0.708 ms) is below the main side's fastest launch (0.812 ms).
Timings against the final code
The kernel bench and the end-to-end A/B ran on the first form of this change. The routers' prompt-logits path (
f32_tile_body, the full-row tile) has not changed since. What changed afterwards is the MMA replay row count and the PTX tables, which no router timing reads. I did not rerun the timings, and I did not measure dense BF16 or HC MMA speed.GPU evidence
An RTX 5090 (
nvidia-smiof the gate runs):A DGX Spark (GB10,
nvidia-smiof the timed run):Gate commands and output summaries from those runs:
just gate-gpu-qwen35moe-moe --case shape,wide512rc 0 (final code),just gate-gpu-gemm --case g32_f32tile,g32_refuserc 0,just gate-gpu-bf16rc 0,just gate-gpu-mxfp8rc 0 (earlier form).just gate-gpu-gemm --case dense_mmarc 0 (72 PASS),just gate-gpu-bf16rc 0 (309 PASS) andjust gate-gpu-mxfp8rc 0 (343 PASS) on the head that goes up;just gate-gpu-hc-gatedrc 0 on the replay code of this change;just gate-ptx-spillandjust ptx-compare upstream/main gate_gemmas above, with the build'snvidia-smiabove.Models: Qwen3.8 FP4-Local and NVFP4.
What I ran into
None of this blocks the PR.
just gate-gpu-qwen3moe-routerdid not run: theref_qwen3moereference set is not on the GB10 machine, and the RTX 5090 run is in host mode and cannot read it. The ubatch refusals it checks (no tokens, short input,knot 64, misaligned input) are nowtile_launch's checks; the gated router's equivalent is covered bywide512 bf16 short activation row: fused and ubatch refused. The 128-row kernel's bit evidence isg32_f32tileat 128 rows.bloomery-gpuprints#[unroll] requested but the loop was not unrolledtwice, from countedwhileloops. The PTX is the same with aforloop, so it is cosmetic.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.