Repository navigation
hc_gated: read the fused HC mix in whole sectors and prefetch its streams into L2 - #756
Conversation
The epilogue of `hc_gated_up_mma_mix_4` gave each lane one column of the warp's 32 and walked the hidden indices of a pass one at a time, so every warp-wide load of the normed streams and every store of the mixed values touched 32 cache lines for 4 bytes each. Each lane now takes one hidden index of the pass and every fourth column, so a warp-wide step reads one stream of eight consecutive hidden indices in four columns and stores the same eight values of each: four whole 32-byte sectors. The gates go through the same warp scratch, its columns permuted by the row's hidden index so a step's 32 gate reads land in 32 banks. Each output is mixed in the same order (stream 0 to 3, then the mean), so the mixed values and the fault are unchanged bit for bit.
`hc_gated_up_mma_mix_4` computes a 128 by 128 tile of up-projection gates with the BF16 MMA and only then mixes the four normed streams of the tile's columns with them, so every block waited on its `xn` loads from DRAM after its MMA finished. Each thread now first asks L2 for two of the tile's 512 `xn` lines (one stream of one column, the tile's 32 hidden indices each), and the mix after the MMA finds them there. The prefetch needs the tile's origin before the MMA starts, so the raster `bf16_mma_tile` walks moves into `mma_tile_origin`, which both call. The prefetch is a hint: no value, fault or launch changes.
hc_gated_up_mma_mix_4 reads eight hidden values of four columns a step and keeps those columns' addresses live beside the tile's waiting cells. ptxas 13.3.73 and the GB10 driver JIT (595.84) read 468 spill and 176 local bytes at sm_121 and sm_121a, and 1112 spill bytes with a 176-byte stack frame at sm_86.
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior defect or proven quality defect remains.
Non-blocking
⚠ Time this head: crates/gpu/src/hc_gated.rs:1838. The kernel adds up to 512 prefetch hints per 128×128 tile (256 threads × 2 hints) [derived]. The reported A/B precedes this head's device code; sm_121 spills changed from 468 to 492 bytes. The occupancy / geometry class in AGENTS.md calls for a timed base/head A/B. Supply that run on GB10 for the final device code.
Optimization headroom
- E. Less work: crates/gpu/src/hc_gated.rs:1764. Skip gate computation and scratch stores for columns beyond
m; the read guard already excludes them. At 37 prompt columns and hidden=2560 on GB10, this removes (128−37) × 4 streams × 2560 × 4 = 3,727,360 shared-store bytes per invocation, about 100,739 bytes per prompt token [derived].
Checked
Duplicates: six new named items inspected. Both raster callers use mma_tile_origin, which reuses raster32.
Complexity: the added prefetch loop has a fixed two-iteration bound and a live-column guard.
Silent failure: off-grid tiles return, padded columns are excluded from mix reads, and non-finite mix outputs raise HcMix.
Tests: scratch ownership and 32-bank reads verified arithmetically. Removing the XOR at hc_gated.rs:1712 reduces distinct banks to four. Rust and GPU tests were not run here.
Gates: the three architecture tables carry dated spill PINs and reasons; no accuracy band changed.
Escape catalog: C1–C4 do not match.
Notes
The body includes GB10 identification and HC gate output, but omits the gate run's exact build commit and model file paths. GPU evidence is incomplete.
Card check: needs-gpu. This pull request changes crates/gpu/src/cores.rs, crates/gpu/src/gemm/f32tile.rs, crates/gpu/src/gemm/mod.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 prompt 처리에서 HC의 up과 mix를 합친 커널이 메모리를 읽고 쓰는 방식을 바꾸고 L2 prefetch를 더해, GB10에서 이 커널의 시간을 줄이는 작업입니다.
Part of #565.
What and why
Qwen3.8's prompt pass runs one fused HC up and mix kernel,
hc_gated_up_mma_mix_4, for each HC block: 97 launches for a 4096-id prompt, 273.0 ms of GPU time on a GB10. After its MMA, the mix step had every lane read a different column, so one warp step touched 32 lines ofxnandmixedand used 4 bytes of each. This PR changes that step and starts its reads earlier:mma_mix(crates/gpu/src/hc_gated.rs): laneLmixes hidden indexL % 8of every fourth column fromL / 8(MIX_HIDDEN,MIX_STEP_COLS). A warp step now reads and writes four whole 32-byte sectors ofxnandmixed. The gate scratch goes throughmix_slot, which permutes the columns of each row so those 32 reads land in 32 banks. Each output still mixes its streams in the same order, so values and faults are the same bit for bit.xn(XN_LINES, 512 lines a tile) withcores::l2_prefetch, so the mix finds them there. The prefetch is a hint: it changes no value, fault or launch.mma_tile_originincrates/gpu/src/gemm/f32tile.rsnow owns the tile raster for both callers:bf16_mma_tile(the dense MMA entries) and the HC kernel. The helper takes the weight type, so each caller uses its own weight's group size, and it keeps the let-else shape of the dense body's raster.MMA_ROWSandMMA_COLSbecomepub(crate)for the prefetch.tools/refpin rows move withPIN(2026-10-24)lines.Release notes: Changed: the fused HC up and mix kernel of the Qwen3.8 prompt pass reads whole sectors and prefetches its normed streams into L2, which cuts that kernel's GPU time on GB10.
Code shape
mma_tile_origin(crates/gpu/src/gemm/f32tile.rs:624), called bybf16_mma_tileand by the HC kernel. The mix order, slot map and prefetch each have one owner inhc_gated.rs.Resultchange. The prefetch stays inside one stream of a live column, and the entry's launch check still validates sizes and shapes first.PIN(2026-10-24)and their reason, and their earlier PIN lines are kept. Nounsafeblock was added and no test or gate case was removed.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.cargo fmt --all -- --checkpasses on the GB10 machine, andcargo check --workspace --all-targetspasses on a second machine. I did not run clippy for the GPU crate: the machine I edit on cannot build it. The helper carries one#[allow(clippy::question_mark, ...)]with its reason, because replacing the let-else with?moves the dense entry's PTX.Duplication found or removed (
path:line), or "none": none. The tile raster has one owner,mma_tile_origin(crates/gpu/src/gemm/f32tile.rs:624), and the duplicate scan reports no other candidate.What I ran
Output is unchanged
The new step visits every output in the same order as before, and the gate compares the stages with their rules bit for bit. The gate below ran on this branch's device code on a DGX Spark (GB10, driver 595.84, CUDA 13.3). The raster helper and prefetch it ran against are the ones in this head.
In the server A/B below, every 128-token greedy request gave the same tokens on main and head on both checkpoints. The HC wide arm runs only in the eager prompt pass, and the graph paths are not touched.
The three unit tests
hc_mma_interleaved_rows_and_mix_order,hc_mix_slots_fill_the_scratch_and_every_bankandgemm::f32tile::tests::hc_mma_layoutpassed (tools/gate.sh --oxide -p bloomery-gpu --release --lib -- hc_m,test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 384 filtered out) on an earlier build of this branch. I did not rerun them on this head.Dense entries
The three dense MMA entries that call
bf16_mma_tilecompile to the same PTX, with the same resources, as on upstream main (thejust ptx-comparebelow), so their device code is unchanged and main's dense gate results hold for them.FAIL-first
Two checks failed before the fix and pass after it.
hc_mix_slots_fill_the_scratch_and_every_bankchecks thatmix_slotfills the scratch exactly once and that each lane-wide read of the mix hits 32 distinct banks. Withmix_slotreturningrow * MMA_WARP_COLS + col(no permutation), it fails:A source check that the dense MMA and the HC kernel both reach the raster through
mma_tile_origin::<W>(rows, n)fails on the version where the dense body kept its own copy, and passes on this head. It checks structure only:PTX and spill pins
just ptx-compare generate_ds41 --features gpu,deepseek41of this branch's device code against upstream main (at549df2ec7, before the later upstream commits) on a DGX Spark lists 398 entries on both sides and one changed entry, the fused mix, which is the one this PR changes:The three dense entries have the same PTX md5 and the same resource columns on both sides:
bf16_mma_gemmc06c8803d4e59db84f8d69bdce1243adfp8_b128_mma_gemm9e9ff1d05c116ff93946406c48610512mxfp8_mma_gemm2ee3845c6477fbac1424f3c8469e03e0Upstream main later gained a commit that splits the MMA stage loop and adds a per-weight group size. After rebasing onto it, I reran the compare and the HC gate on the result. A
git range-diffand an empty diff ofcores.rs,hc_gated.rs,gemm/f32tile.rsandgemm/mod.rsshow that the head differs from the checked build only in the pin files, so the device results above carry to this head.The spill pin rows were checked on the GB10 with
ptxas13.3.73 and the driver JIT. The old pins failed the ratchet and the new ones pass it, replayed on the retained scans of the three architectures:The sm_86 build is never launched. I did not measure the cc8.6 driver JIT, so that pin keeps its earlier stack-frame value. The full GPU gate suite was not run, only the HC gate above.
Speed
Qwen3.8 FP4-Local and NVFP4 on one DGX Spark (GB10), C = 1, draft off, three 4096-id code windows of 128 greedy tokens, median of three requests. Each checkpoint began with a discarded warm load, FP4-Local ran head and then main, NVFP4 ran main and then head, and the clock cap was lifted only around each arm's requests. Kernel times come from one profiled request an arm.
Delta (head against main): the fused HC mix kernel -46.9% (273.0 to 145.0 ms) and the whole 4096-id prompt pass -4.5% of GPU time (3131.5 to 2990.3 ms); FP4-Local end-to-end prefill +0.5% (1311.0 to 1317.6 tok/s), inside the spread between requests, from one server run per arm, so a single observation.
The kernel gain is well outside the noise. One mix launch takes 1.49 ms on average instead of 2.81 ms, and the HC wide arm (norm, down, inject, up and mix) shrinks by 128.0 ms of the pass. The head's mix kernel read 145.0, 146.7 and 145.2 ms in three separate profiled runs, while main's read 273.0, 323.1 and 289.5 ms. The other HC kernels and the dense and routed GEMMs move by 9.9 ms or less.
The end-to-end number does not show the saving. FP4-Local prefill is 1317.6 tok/s on head against 1311.0 on main (+0.5%), and the three requests of the head arm alone span 1296.7 to 1343.3 tok/s, so this pair cannot separate them. On NVFP4 the main arm ran while the host kernel was compacting memory (free memory 1.0 to 1.1 GiB), so I do not use the three-request medians of that pair. Between the profiled requests of the same two servers, prefill is 1280.3 tok/s on main and 1372.1 on head (+7.2%), one request each. I ran no second end-to-end pair, so the end-to-end gain is not established beyond this one observation.
Measured build against this head
The A/B and the profiled kernel times ran on an earlier build of this branch over upstream commit
e4204ccbb. That build did not yet share the raster helper withbf16_mma_tile, and upstream has since split the MMA stage loop. This head's fused mix therefore compiles to different PTX than the measured build, with 492 spill bytes at sm_121 instead of 468. I did not rerun the timings on this head, so the speed rows above describe the measured build, and I make no speed claim for this exact head beyond the gate and PTX results above.Hardware
DGX Spark (GB10), GPU, driver and CUDA lines from
nvidia-smiof the check job on this head:Models: Qwen3.8 FP4-Local and NVFP4. The pins were read with
ptxas13.3.73. The workspace compile check ran on a separate machine.What I ran into
None of this blocks the PR.
hc_gated_norm_4wstill takes 225.9 ms of the pass. Those are separate changes.just ptx-compareexits 3 because the fused mix entry changed. That is the intended change, and its pin rows are updated here.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.