Replace the gfx950 blockwise FP8 running-scale accumulator #744
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #744"
general
weight: 0.35
Micky774
[agent reply]
Glossary
Three terms are used throughout and none of them is standard, so they are pinned down here.
| term | meaning |
|---|---|
| running scale | the accumulation form
micro_tkused before this change: one FP32 accumulator carried across all K-blocks holdingT_k / s_k, rescaled every block bys_{k-1} / s_k. || scale-then-accumulate | the form this change puts in its place: each K-block's product is formed in a temporary, multiplied by that block's own scales, and added. The accumulator only ever holds a partial sum in true units. |
| 1D×2D / 1D×1D | which recipe supplies the weight scale. 1D×2D blocks the weights 128×128 (one scalar per wave per K-block); 1D×1D blocks them 1×128 (one value per output column).
Float8BlockScalinguses 1D×2D for fprop and dgrad and 1D×1D for wgrad. |What this changes
micro_tk— the gfx950 FP32-scale blockwise FP8 GEMM, selected whenNVTE_FP8_BLOCK_SCALING_FP32_SCALES=1and K is a multiple of 128 and at least 256 — is replaced with a scale-then-accumulate kernel.The motivation is numerical.
s_{k-1} / s_kis a quotient of two data-dependent quantiser outputs and is unbounded in both directions, which is where theinfreported against this path comes from. Under scale-then-accumulate the accumulator can overflow only if the true result is itself unrepresentable in FP32, so the two empirical floors that were guarding the ratio are no longer load-bearing andkMinScaleInvis removed with them.It is also faster. On MI355X, against the kernel it replaces, measured under the harness described below:
| shape | running scale | this PR | |
|---|---|---|---|
| 4096³ | 939.4 | 1739.4 | 1.85× |
| 6144³ | 849.2 | 1542.1 | 1.82× |
| 8192³ | 1134.7 | 1954.0 | 1.72× |
| 16384³ | 1165.8 | 2088.2 | 1.79× |
TFLOP/s, 1D×1D recipe, FP32 scales. The 1D×2D recipe reaches 1945 / 1788 / 2343 / 2448 on the same shapes.
The speedup does not come from the scale change itself. It comes from two things the scale change made possible:
v_mfma_f32_16x16x128_f8f6f4occupies the matrix pipe for 32 cycles; the fold that consumes tile k-1's result is placed in tile k's shadow so the MFMA issue cadence stays at 32. The MFMA→VALU hazard on this tier is satisfied by elapsed cycles rather than by instruction count, which is why thes_nopcounts in the fold are what they are and are written out rather than left to the scheduler.What this does NOT change
micro_tk_partial_kis untouched — zero lines. It remains the path forK % 128 != 0orK < 256, which this kernel does not accept. It was already scale-then-accumulate and had no ratio, so it never had the overflow this PR is about.micro_tk_pow2is untouched. The default path, when the env var is unset, is unaffected and bit-identical.cdna3/) is untouched. The arch split already runs throughBlockwiseGemmBackend::get_cdna3()/get_cdna4(); every source change here is undercdna4/.amax_epsilon, or to any framework-level file.Files
| file | |
|---|---|
|
cdna4/blockwise_fp8_gemm.cpp|micro_tk's body replaced; signature, name and dispatch unchanged ||
cdna4/blockwise_fp8_gemm_helper.cuh| six running-scale-only helpers deleted;kMinScaleInvandfloor_scale_invdeleted; the transposed-accumulator family andapply_epilogue_tappended under a section banner ||
tests/cpp/operator/test_cublaslt_gemm.cu|BlockwiseGEMMTestSuiteextended — see below |The helper header carries two families of device helpers, separated by a section banner rather than by a file boundary. They differ in the accumulator layout -- whether a lane holds four consecutive M at one N, or the transpose of that -- which changes which index a scale varies along, how many values a lane needs, and whether four elements of C are adjacent or a row apart. That is a property of one kernel, not of a compilation unit:
micro_tkuses the transposed half,micro_tk_pow2andmicro_tk_partial_kthe other.kMinScaleInvRemoved, along with
floor_scale_invand its six call sites. It existed to keep the ratio's denominator away from zero; there is no ratio now. Flooring ascale_invat1e-13in a multiply-then-accumulate path is a distortion with nothing to buy, so it goes rather than staying as a no-op.The two test cases whose comments named it (
// pins kMinScaleInv from below/from above) still pass without it.Epilogue
apply_epilogue_tis the transposed counterpart ofapply_epilogue: same arithmetic, same order, mirrored traversal. The order matters and is preserved — the accumulate term rounds to the output type before adding the prior value, so that the sum matches what an add performed after the store would produce, and moving bias across that rounding would change the result.The traversal flip moves cost between the three terms:
biasis indexed by n alone. Untransposed, a lane's four accumulator entries share one column and one scalar read serves them; transposed they are four consecutive columns. They are adjacent, so they are read as one contiguous run — the load count per tile matchesapply_epilogue's again, and only the bytes differ.gelu_auxandc_inare indexed bymN + n, so the four a lane touches are adjacent rather than a row apart: four strided reads become one contiguous run.gelu_auxis deliberately not gathered into a local. Its index carries the row base, so a gathered copy is live per tile rather than per column and the compiler hoists all eight tiles' worth above the loop. Measured, that costs 588 bytes/lane of scratch and ~800 VGPR spills in theGELU_AUX_BETAinstantiation, against zero without it.Resource usage for every instantiation, from
-Rpass-analysis=kernel-resource-usage:| | VGPR | SGPR | scratch | occupancy | spills |
|---|---|---|---|---|---|
| 1D×2D, all six epilogues | 256 | 67 | 0 | 2 waves/SIMD | 0 |
| 1D×1D, all six epilogues | 256 | 65 | 64–68 | 2 waves/SIMD | 15–16 |
Occupancy is 2 waves/SIMD throughout; no epilogue changes it. The 1D×1D scratch is from the
#pragma unroll 2on the K loop and predates the epilogue.e5m2 operands
cbszandblgpselect the MFMA's per-operand format. Because this kernel feeds the MFMAbbeforea— the operand swap that transposes the accumulator — the two codes swap with them: the template'sCBSZ, which names the caller's A, has to be passed in the builtin's second modifier slot. Passing them straight through would decode the weights with the activations' format, which is silent: same 8 bits, different exponent bias.The generated ISA confirms it. The three instantiations are identical instruction for instruction and register for register, differing only in one modifier:
e5m2 therefore costs nothing.
Tests
BlockwiseGEMMTestSuitewent from 12 cases to 31.Coverage is stated as kernel instantiations actually dispatched, joined from
rocpd_kernel_dispatchagainstrocpd_info_kernel_symbolin arocprofv3 --kernel-tracecapture — not as a count of parameter rows, and not from the symbol table, which lists every instantiation the code object contains whether or not it ran.micro_tk's full cross-product is 3 output types × 2cbsz× 2blgp× 2 recipes × 6 epilogues = 144.| | instantiations reached |
|---|---|
| before | 2 — both
DEFAULT, both e4m3×e4m3, both bf16 out || after | 18 |
Per axis, after:
Every axis is non-zero where it was zero before. The suite had no
bias,gelu_auxoraccumulatefields at all, so the fused epilogue had no C++ coverage; ate.Linear(bias=True)forward pass runs theBIASinstantiation on every step.To support that the reference gained the same three terms in the same order the kernel applies them, and the product is now computed in FP32 and converted after the epilogue rather than before it. The reference is still an independent FP32 loop over dequantised operands, so a kernel that applies the epilogue to the wrong element still fails —
biasis given a profile whose period divides neither the four elements a lane holds nor the 16 or 128 of a tile, because a constant or tile-periodic bias would pass even if the epilogue put it on the wrong column.One thing the new cases establish that is worth recording: the GEMM requires
mto be a multiple of 16 and the kernel indexesbiasbym, so the merged four-element read is always in range and its guarded scalar fallback is unreachable through this entry point.Results
Run on MI355X (gfx950), ROCm 7.15, built with
NVTE_FRAMEWORK=pytorch.| | |
|---|---|
|
BlockwiseGEMMTestSuite, default path | 31 / 31 passed ||
BlockwiseGEMMTestSuite,NVTE_FP8_BLOCK_SCALING_FP32_SCALES=1| 31 / 31 passed ||
test_operator --gtest_filter=Blockwise*| 516 passed, 24 skipped — unchanged from the base commit ||
tests/pytorch/test_float8_blockwise_gemm_exact.py| 938 passed, 641 skipped || the same with
NVTE_FP8_BLOCK_SCALING_FP32_SCALES=1| 938 passed, 641 skipped ||
tests/pytorch/test_float8_blockwise_scaling_exact.py| 258 passed |Every count matches the base commit
03afd8f81measured before the change.JAX was not built, and no JAX test exercises this GEMM.
Benchmark method
The numbers above are medians over 21 timed reps of 10 launches, on an idle GPU, with:
rand()/10produced enough subnormals and zeros to lower switching activity and raise the clock, which reversed one shape's verdict.The reported spread (min/max) was within 1% on every arm; a wide spread is the symptom of a co-tenant and was checked before the medians were believed.