Repository navigation
[CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows - #8609
AndreasKaratzas wants to merge 13 commits into
Conversation
With splitK >= 2 (KBatch = 1 << splitK >= 4) the CK and CK-Tile blockscale GEMMs add their K partials into the BF16/FP16 output with atomics, so the result depends on arrival order: on gfx950, 426 of the 436 tuned ck/cktile rows with splitK >= 2 give different bits from call to call. CK (KBatch 4, 8, 16): the last K batch to finish an output tile reduces it inside the GEMM. - Each instance also instantiates the same kernel with FP32 output. Every K batch stores its partial to its slice of a [KBatch, M, N] workspace with device-scope (sc1) stores, waits for them, and increments a per-tile counter. - The workgroup that sees count == KBatch - 1 loads the KBatch partials with device-scope loads, adds them in batch order, rounds once to BF16/FP16, and resets the counter to zero. - Device-scope loads and stores are coherent across XCDs, so no release/acquire fence (buffer_wbl2 / buffer_inv of the whole L2) is needed. - The counters live in a per-device arena (one slot per stream, zeroed once, one counter per cache line), so there is no memset and no second kernel per call. Calls that cannot use a slot (first call under stream capture, more than 16 streams or 4096 tiles) zero per-call counters in the stream. - Wave32 and pipelines other than v1/v3 keep the atomic path (no current instance). CK-Tile (KBatch > 2) writes FP32 partials to the workspace and a small kernel adds them in batch order: fusing the reduction made the CK-Tile GEMM several times slower. Both paths are gfx950 only. The dispatch checks the device arch at run time, because the host code is shared by every GPU_ARCHS target; the fused kernel body and the sc1 store specialization are also compiled for gfx950 only. On other archs (gfx942) split-K runs main's memset + atomic path, and the gfx942 ISA of every kernel main builds is unchanged. KBatch = 2 (splitK 1) keeps the atomic path, which is already deterministic: each FP32 partial is rounded to BF16/FP16 in the epilogue and atomically added into the zeroed output, so the result is round(p0 + p1) in either arrival order. The affected gfx950 tuned rows were re-measured with the new path (CK kernel ids 0-18, splitK 0/2/3/4, CUDA graph, rotating weights, 20-call bitwise check). 175 of them change to a faster config. The 3 CK-Tile rows move to CK. No other arch's rows change. The output is as accurate as splitK = 0. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Adds hand-written gfx950 a8w8 blockscale GEMM kernels for small M. They are exposed as CK candidates of gemm_a8w8_blockscale and are selected for 186 of the 436 tuned gfx950/cu256 rows that used split-K. The PR this one stacks on makes those rows deterministic with an ordered split-K reduction. These kernels are deterministic without any reduction pass: - Each workgroup owns one (16 * MRep) x (16 * NRep) output tile. Its NWaves waves take the 128-wide K blocks w, w + NWaves, ... and accumulate in FP32 in a fixed order. The wave partials are added in LDS in wave order and the tile is stored once. There are no atomics and no workspace, and the result has one rounding, like splitK=0. - KSplit=2 runs two workgroups per tile over the two K halves. Each half is rounded to the output type and added with a packed bf16/fp16 atomic into an output zeroed by hipMemset2DAsync. The result is r(r(a) + r(b)) in either arrival order because the add is commutative and 0 + r(x) is exact. Three rows use it (N=128 K=7168, M=16/40/80), where no single-rounding kernel stays within +3% of main. The kernels are added to the CK candidate list only on gfx950 (existing kernel IDs are unchanged). The device code is compiled only for __gfx950__. The host checks get_device_gfx() == "gfx950", and the tuned rows are gfx950 only. The tuner does not try splitK for them. Only the 8 variants used by the tuned CSVs are listed, which keeps the build small. gen_instances.py now builds the CK instance parameters only for KernelInstance (gen_legacy_impl), because SliceKInstance has no CK tile fields. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Picks up ROCm#8790, which refreshes the MoE dispatch golden that failed tests/test_moe_dispatch_snapshot.py on the previous head. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
The counter slot was keyed by stream, and PyTorch captures every graph on one default capture stream, so all graphs shared a slot. Replaying two of them at once on different streams left tiles unreduced (garbage output) and the counters corrupt for the rest of the process. A region now belongs to a stream or, under capture, to the capture. The regions come from 8 MB chunks that are added outside of capture as they fill up, so a capture adds no node to its graph. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
Re-timed all 452 gfx950/cu256 rows that use split-K on main (the 16 Qwen3.8-27B rows main added after the first retune included) against every repeatable CK config, and moved 18 rows to a faster one. The worst row, 80x5120x8704, goes from +9% to -18% vs main. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
…istic Brings in main, the per-capture split-K counters and the base PR's retune. Tuned tables with conflicting rows keep this branch's side; the next commit re-applies the selection to every affected row. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
…ernels Same re-timing as the base PR's retune, with the listed slice-K kernels as candidates: 15 more rows move to a slice-K kernel (7 of them are Qwen3.8-27B rows main added after the first selection). No new kernel variant, and KSplit=2 stays on the 3 rows that already had it. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
A capture cannot add a chunk, and the graphs captured for one batch size can need more than the half chunk that was kept free. The rest fell back to per-call zeroed counters, 1.6 to 3.6 us slower per call. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
…istic Brings in the base PR's follow-up to the split-K counter chunks. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
|
This branch is brought up to #8541's new head (which has main 1c96e23 merged), and 15 more rows move to slice-K kernels. Measured on MI355X (gfx950, 256 CUs, ROCm 10, torch 2.13) against main 1c96e23. Summary
TimingSame method as in #8541. All 452 gfx950/cu256 rows that use
Per tuned table, per M, and the 15 rows that movedGeomean vs main, cold activations:
By M: 1-16 (179 rows) -16.4%, 17-64 (99) -9.3%, 65-256 (79) -9.8%, above 256 (95) -6.0%. The 15 rows that moved from #8541's fused path to a listed slice-K kernel, change vs main before -> after (cold):
The other 11 changed rows are CK changes that come with #8541's retune, for example 80x5120x8704 +9.2% -> -18.6%. The candidates were CK ids 0-18 with Rows still slowerMore than 2% slower than both main workers in both passes. The range covers both passes and both main workers.
Above +2% in one pass only: 16x1024x6144, 16x3072x6144, 48x6144x4096. All of them run #8541's fused path, whose arrival counter and reduce cost a fixed 1.7 us or so, a little more than main's memset and atomic adds (breakdown in #8541). The slice-K kernels were slower still on these shapes in the candidate sweep. In that sweep 32x128x7168 and 32x576x7168 were at or below main with a KSplit=2 slice-K kernel, which rounds twice. They stay on single rounding here: KSplit=2 is kept to the 3 rows that already had it (N=128, K=7168 at M=16, 40 and 80), and no row moved to a two-rounding config. Repeatability and accuracy
End to endQwen3-Next-80B-A3B-Instruct-FP8 on one MI355X through vLLM, temperature 0, 8 prompts x 64 tokens, Not covered
|
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
@aiter-bot review |
|
aiter-bot — queued behind 20 review(s); expect to start in about 5.8 h. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8609 — [CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows
Review (advisory):
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled) and this box is gfx942-only (8× MI308X), so the gfx950-gated slice-K cases of the target op_tests/test_gemm_a8w8_blockscale.py cannot run here; what could run without a gfx950 was run by hand: gen_instances.py on GPU_ARCHS=gfx942 emits 0 slice-K instances and on gfx950 emits all 8, and op_tests/test_gemm_codegen.py passes 58/0
Perf (advisory): NOT RUN — no gfx950 on this box (8× gfx942/MI308X); the slice-K kernels are gfx950-only, so the target cannot time them here; the PR's own MI355X numbers (vs main 1c96e23, method disclosed) are the only timing evidence and were not re-derived
Size: 2068 lines / 15 files — over the review bar
Design (advisory): SPLIT — the seams: #8541's fused deterministic split-K (already a separate stacked PR), the slice-K kernel + 8 variants + codegen/tuner wiring, and the 201-row CSV retune + op-test cases
Human: recommend LuweiZhou2025 review whether the one-workgroup wave-sliced K reduction with fixed-order LDS reduction (and the two-rounding KSplit=2 packed atomic for the 3 N=128 K=7168 rows) is the right determinism/latency trade for the 201 gfx950 rows in PR #8609, versus keeping them on #8541's fused split-K path
3 finding(s) posted inline, on the lines they are about:
op_tests/test_gemm_a8w8_blockscale.py:732-737— collects only 2 of the 8 shipped slice-K variants (16x16x128_16w_u2_ks1, 16x16x128_16w_u4_ks2)aiter/configs/model_configs/a8w8_blockscale_tuned_gemm_ds_v3.csv:39— (and lines 69, 166, 252, 331) now carries us values from a graph-replay harness while the unchanged rows keep…csrc/ck_gemm_a8w8_blockscale/gemm_a8w8_blockscale_instance.py:192-194— assigns kernelIds 19-26 with max(candidate_kernels_dict)+1 while the 7 CSVs hardcode 19-26
| for m, n, k, kernel_name in [ | ||
| (1, 2048, 3072, "a8w8_blockscale_slicek_16x16x128_16w_u2_ks1"), | ||
| (80, 128, 7168, "a8w8_blockscale_slicek_16x16x128_16w_u4_ks2"), | ||
| ]: | ||
| test_splitk_deterministic( | ||
| m, n, k, 0, "ck", kernel_name, repeats=100, ref_kernel_name=_ck16x64 |
There was a problem hiding this comment.
There was a problem hiding this comment.
agreed. added three cases: 16x32 8-wave (M=40, N=2048, K=2048), 16x64 NRep=4 (M=80, N=3072, K=3072) and 32x32 MRep=2 (M=72, N=2048, K=2048, partial M tile). all 0/100 mismatching calls. vs the CK splitK=0 reference only a few elements differ, in the last bf16 bit (different fp32 sum order).
| gfx942,304,32768,4096,512,ck,0,0,267.7638,a8w8_blockscale_1x128x128_256x128x128x128_16x16_32x32_2x2_8x32x1_8x32x1_1x32x1x8_8_1x1_intrawave_v3,513.28,1073.0,0.0 | ||
| gfx942,304,32768,7168,2048,ck,0,0,1205.4161,a8w8_blockscale_1x128x128_256x128x128x128_16x16_32x32_2x2_8x32x1_8x32x1_1x32x1x8_8_1x1_intrawave_v3,798.12,457.56,0.0 | ||
| gfx950,256,1,128,7168,ck,11,3,5.6664,a8w8_blockscale_1x128x128_256x32x64x128_16x16_16x16_2x1_8x32x1_8x32x1_1x32x1x8_8_2x1_intrawave_v1,0.32,163.23,0.0 | ||
| gfx950,256,1,128,7168,ck,20,0,7.5513,a8w8_blockscale_slicek_16x16x128_16w_u2_ks1,0.24,122.49,0.0 |
There was a problem hiding this comment.
There was a problem hiding this comment.
fair point, and the claim does not hold for these five. i timed them interleaved, main vs this head, one script for both trees (aiter run_perftest, the tuner's method, plus a cuda-graph replay), BF16, 6 rounds on an MI350X:
| M | main us | head us | change (run_perftest / graph) |
|---|---|---|---|
| 1 | 7.27 | 7.49 | +3.0% / +1.4% |
| 2 | 7.08 | 7.82 | +10.5% / +17.6% |
| 16 | 7.78 | 8.58 | +10.3% / +19.9% |
| 40 | 7.95 | 8.44 | +6.1% / +13.4% |
| 80 | 8.37 | 8.76 | +4.6% / +15.2% |
so slice-K is slower than main here, and for M=2..80 also slower than #8541's split-K on the old kernel. the head us values in the csv match run_perftest within 3%; the old main values (5.5-7.7) do not reproduce on main today. i'll recheck on MI355X, where these rows were picked. if the gap holds, these five go back to #8541's config with tuner us values.
| _next_id = max(candidate_kernels_dict) + 1 | ||
| for _i, _k in enumerate(slicek_kernels_list): | ||
| candidate_kernels_dict[_next_id + _i] = _k |
There was a problem hiding this comment.
📝 [verified] csrc/ck_gemm_a8w8_blockscale/gemm_a8w8_blockscale_instance.py:192-194 assigns kernelIds 19-26 with max(candidate_kernels_dict)+1 while the 7 CSVs hardcode 19-26; a later PR that appends a 19th legacy KernelInstance silently shifts every slice-K id, and because the runtime dispatch is name-keyed nothing fails — the CSV kernelId column and the tune-mode table just drift. Author must pin the ids as literals (or add a test asserting the id↔name mapping) so the drift cannot happen silently.
There was a problem hiding this comment.
done, the slice-K ids are now literals 19-26 in slicek_kernels_dict, with an assert that they do not overlap the CK ids.
| else | ||
| { | ||
| using f16x2_t = _Float16 __attribute__((ext_vector_type(2))); | ||
| f16x2_t v{static_cast<_Float16>(a), static_cast<_Float16>(b)}; |
There was a problem hiding this comment.
Please keep the cross-split reduction in FP32 for FP16 output, or route FP16 away from KSplit=2. I compiled the unmodified slicek header from f412e7746 on gfx950 and tested M=16/40/80, N=128, K=7168 with A=1, B=+1 for the first half of K and -1 for the second half, x_scale=32 and w_scale=1. The exact result is zero, but the FP16 KSplit=2 kernel returns all NaNs: the partials (+114688 and -114688) overflow before the atomic adds. KSplit=1 and BF16 controls return zero. The tuned ks2 rows use splitK=0, so the existing FP16 splitK guard does not protect these callers. Please add this cancellation regression.
This was a native kernel diagnostic, not a full op/model test.
There was a problem hiding this comment.
good catch, thanks. reproduced it here: fp16 ks2 gives all NaN at M=16/40/80, bf16 and ks1 are fine. i routed fp16 away from the two-half path, so with fp16 output the ks2 instance now runs as one workgroup per tile (KSplit=1, one rounding) and the fp16 atomic is gone. your cancellation case is in the op test now, it fails on f412e77 and passes with the fix.
The CK-Tile partials branch allocated KBatch*M*N*4 bytes with no limit. Use the INT32_MAX bound of the CK fused path and fall back to the atomic path above it. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
With FP16 output the KSplit=2 kernel rounded each K-half partial to FP16 before the atomic add, so large cancelling partials overflowed to NaN. FP16 output now runs the same tile with KSplit=1 and one rounding. Add the cancelling case and one case per untested slice-K family to the op test, and make the slice-K kernel ids literals. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
…-deterministic Signed-off-by: Andreas Karatzas <[email protected]>
Summary
#8541 makes the 452 tuned gfx950/cu256
gemm_a8w8_blockscalesplit-K rows deterministic with an ordered FP32 reduction. This PR adds hand-written gfx950 kernels for small M that are deterministic without any reduction pass (no workspace, no counters), and routes the 201 rows where they are faster to them.On MI355X, all 452 affected rows (gfx950/cu256 rows with
splitK >= 2on main) vs main: -11.6% geomean with cold activations and -11.4% with warm ones (#8541 alone: -4.4% / -4.3%), no row above +5% (see Performance). The 201 slice-K rows are -18.8% vs main, and none of them is slower than main. Every row is bitwise reproducible; the 198 KSplit=1 slice-K rows round once, likesplitK = 0, and the three KSplit=2 rows (N=128 K=7168, M=16/40/80) are at 1.47-1.48x with BF16 output (main's atomic split-K: 2.4-2.6x). With FP16 output the KSplit=2 kernel runs as KSplit=1 (one rounding), because an FP16 K half can overflow when the sum does not.This is a separate PR because it adds a hand-written HIP kernel (aiter CI: one kernel backend per PR) and it depends on #8541's CSVs and dispatch.
Motivation
After #8541 the small-M split-K rows are deterministic and on average faster than main, but they still pay for a
[KBatch, M, N]FP32 workspace round trip and a per-tile counter, and a few N=128 / N=256 rows stay at +3..7% vs main. For decode-sized M the K loop dominates and a single workgroup per output tile can split K across its own waves and reduce in LDS, which is both cheaper and trivially deterministic.Changes
include/gemm_a8w8_blockscale_slicek.cuh(new, gfx950 only). Kernelaiter_slicek::kernel<MRep, NRep, NWaves, Unroll, KSplit>on__builtin_amdgcn_mfma_scale_f32_16x16x128_f8f6f4:(16*MRep) x (16*NRep)output tile,NWaves(8 or 16) waves.wtakes the 128-wide K blocksw, w+NWaves, ...in a fixed order, applies thex_scale * w_scaleblock scale per MFMA result, and accumulates in FP32. The tile's x scales are staged in LDS as[K/128][MT].__syncthreadseach output element is summed in wave order0..NWaves-1, converted once (ck::type_convert<EDataType>) and written with a plain store.KSplit = 2(BF16 output only): two workgroups per tile (grid z), one per K half, each rounding its half to BF16 and adding it with one packed atomic (global_atomic_pk_add_bf16) into an output zeroed byhipMemset2DAsyncon the same stream.static_assert(KSplit == 2)blocks more halves.KSplit = 1, so each element is summed in FP32 and rounded once. A K half rounded to FP16 can overflow (65504) even when the sum is small; then the output isinf - inf = NaN. The FP16KSplit = 2kernel is not instantiated.TORCH_CHECK):splitK = 0(these kernels split K internally),K % 128 == 0,N % (16*NRep) == 0, contiguous 16-byte-aligned rows, scale shapes cover the GEMM,get_device_gfx() == "gfx950", and LDS (max(16*MRep*K/128, NWaves*MRep*NRep*256)floats) within 64 KB.gemm_a8w8_blockscale_instance.py: newSliceKInstance; 8 variants inslicek_kernels_dictwith literal CK kernelIds 19-26, added only whenget_gfx() == "gfx950"(existing IDs unchanged). An assert stops an overlap with the CK IDs. Only variants used by the tuned CSVs ship (8 of the 39 explored).gen_instances.py: CK tile parameter generation moves intogen_legacy_impl;gen_ck_instancepicksgen_slicek_implorgen_legacy_impl(SliceKInstancehas no CK tile fields).gemm_a8w8_blockscale_tune.py: the tuner does not trysplitKfor slice-K kernels.a8w8_blockscale_tuned_gemm.csv64 rows,qwen3_next_80b_a3b72,glm53_flash23,qwen3_14b12,mistral_large412,ds_v311,qwen38_27b7): 201 gfx950/cu256 rows switch to libtypeck, kernelId 19-26,splitK = 0.op_tests/test_gemm_a8w8_blockscale.py: five slice-K cases intest_splitk_deterministic(one per tile family) and a newtest_slicek_cancelling_k_halves(see "Changed op tests").a8w8_blockscale_slicek_16x16x128_8w_u2_ks1..._16x16x128_16w_u2_ks1..._16x16x128_16w_u4_ks1..._16x16x128_16w_u4_ks2..._16x32x128_8w_u2_ks1..._16x32x128_16w_u2_ks1..._16x64x128_16w_u2_ks1..._32x32x128_16w_u2_ks1Determinism
splitK = 0. Measured on f7ba659: error ratio 1.000 vssplitK = 0on all 183 KSplit=1 rows of that head, and bitwise equal to CKsplitK = 0in the M=1 op-test case.0 + r(a) = r(a)exactly, thenr(r(a) + r(b)), which is the same in either arrival order because IEEE addition is commutative. (A-0half yields+0, which does not change the final sum.) It is not the order-dependent FP32-into-BF16 or 3+-partial case. The cost is double rounding: 1.47-1.48x the error ofsplitK = 0at BF16 on the three shipped rows (main's atomic split-K on the same shapes: 2.4-2.6x).Which rows, and why
Selection data: main, #8541 and all 39 explored slice-K variants timed interleaved on the same GPU (CUDA-graph replay, rotating weights), two full passes plus rechecks of borderline rows, averaged.
Result: 201 rows, M 1-588 (138 with M <= 16, 41 with M 17-64, 22 above), mostly K 2048-6144 (K=2048: 66, 3072: 49, 4096: 34, 6144: 24). 15 of them moved to slice-K in a later retune against #8541's current head (e695196, same 8 variants). The other 251 of the 452 affected rows keep #8541's config.
Performance (if applicable)
MI355X (gfx950, 256 CUs), BF16 out,
aiter.gemm_a8w8_blockscalewith each tree's shipped CSVs, against main 1c96e23. Method as in #8541: one worker per tree plus a second main worker on one GPU, HIP-graph replay over rotated weights, activations rotated ("cold") or on one buffer ("warm"), a row counts as slower only if it is slower than both main workers, rows near the line measured twice.All 452 affected gfx950 rows (every gfx950/cu256 row with
splitK >= 2on main, including the 16 Qwen3.8-27B rows of #8016), change vs main:splitK = 1rows +0.16% / 0.00% (cold / warm), 53 other tuned rows +0.10% / +0.10%.(geomean vs main, cold activations.)
Rows still slower (more than 2% slower than both main workers in both passes; the range covers both passes and both main workers):
Above +2% in one pass only: 16x1024x6144, 16x3072x6144, 48x6144x4096. All of these rows run #8541's fused path, whose arrival counter and reduce cost a fixed 1.7 us or so, a little more than main's memset and atomic adds (breakdown in #8541). In the candidate sweep 32x128x7168 and 32x576x7168 were at or below main with a KSplit=2 kernel (two roundings); they keep single rounding.
N=128 K=7168 recheck (MI350X, after review). The ds_v3 rows M=1/2/16/40/80 that moved to slice-K, BF16 out,
aiter.gemm_a8w8_blockscalewith each tree's CSVs. Main 1c96e23 and this head in alternate processes (ABBA order, 6 rounds), one script for both trees.run_perftestis the aiter tuner's method (profiler, rotating inputs); graph is 128 calls over 128 input sets in one CUDA graph. Medians:run_perftest), +0.9..+37.4% (graph).us: the head values of these rows matchrun_perftestwithin 3%. The old main values (5.53-7.74 us) do not reproduce on main today (7.08-8.37 us).JIT build time. Not measured again for this revision. The slice-K variant list is unchanged (8 variants, all still used by tuned rows).
Testing
Documentation
No API, flag or env change. On gfx950 the tuned CSVs select new CK kernelIds 19-26 for 201 rows.
Dependencies
Depends on #8541 (base branch).
Breaking Changes
None in the API. On gfx950 the 201 rows run different kernels; output bits change but stay deterministic, and the 198 KSplit=1 rows round once, like
splitK = 0. CK kernelIds 19-26 now exist on gfx950 only; a CSV row naming them on another arch would fail at codegen/dispatch, and no such row exists.PR Self-Review
Reviewed revision
d6f782e
Behavior and intent
Adds deterministic gfx950 small-M blockscale kernels as CK candidates and selects them for 201 tuned gfx950/cu256 rows that #8541 runs on its fused split-K path. KSplit=1 kernels reduce K across waves in LDS in fixed order and round once; the one KSplit=2 kernel (3 rows) rounds each half and adds two values with a commutative atomic onto zero. FP16 output never uses the KSplit=2 atomic; it runs the same tile with KSplit=1. All other rows, archs and the default (untuned) dispatch are unchanged from #8541.
Validation and unverified scope
On the review fixes (f412e77 plus the FP16 KSplit, kernelId and op-test changes), MI350X (gfx950, 256 CUs, SPX):
a8w8_blockscale_slicek_16x16x128_16w_u4_ks2with FP16 output is all NaN (2048/2048, 5120/5120, 10240/10240), also throughaiter.gemm_a8w8_blockscale(..., dtype=fp16). After: 0 NaN, all zero. BF16 and KSplit=1 are zero before and after...._16w_u4_ks1on random inputs (M=16/40/80); relative L2 error vs FP32 2.0e-4.python op_tests/test_gemm_a8w8_blockscale.pyexits 0 in 10 of 10 runs in a loop: 5 slice-K cases 0/100 each,test_slicek_cancelling_k_halves6/6 cases zero, the [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541 cases unchanged. The new cancellation test fails on f412e77 (FP16: all outputs NaN).python op_tests/test_gemm_codegen.py: 74 passed, 0 failed.On f412e77 (#8541's head e949a3e with main 1c96e23 merged), MI355X (gfx950, 256 CUs):
python op_tests/test_gemm_a8w8_blockscale.pyexits 0: 9 CK and CK-Tile determinism cases 0/20, the 2 slice-K cases 0/100,test_splitk_concurrent_graphs0/800.python op_tests/test_gemm_codegen.py: 74 passed, 0 failed.VLLM_ROCM_USE_AITER_MOE=0: 5 identical calls give 5 different outputs on main and 1 with this head. Tokens/s unchanged within run-to-run spread.Aiter Test Gatepassed on f412e77.On earlier heads (7ed1a15d8, f7ba659), MI350X. The slice-K kernel source, its 8 variants and their codegen have not changed since f7ba659; e695196 only moves 15 more rows to them:
aiter.gemm_a8w8_blockscale: 50 eager calls bitwise plus CUDA-graph capture and 10 replays: 0 nondeterministic rows, 0 graph-vs-eager mismatches; error 1.000xsplitK = 0on every KSplit=1 row, 1.44-1.48x on the KSplit=2 rows. bf16 and fp16 output: 0 mismatches._sleepbefore each call: 0 mismatches. Positive control, main's atomic split-K (ck 6,splitK = 3) at N=128 K=7168: 1000/1000 mismatches.GPU_ARCHS=gfx942codegen (normal and--tune) emits 0 slice-K instances. AGPU_ARCHS="gfx942;gfx950"build succeeds, and all 16 gfx942 slice-K code objects are kernarg prologue +s_endpgm.Unverified:
usvalues for changed rows come from a graph-replay harness, not the aiter tuner. For the five N=128 K=7168 rows they matchrun_perftestwithin 3% on MI350X; the other 196 rows were not rechecked.PR-specific question
get_gfx() == "gfx950"at codegen, their device body only under__gfx950__, and the hostTORCH_CHECKsget_device_gfx() == "gfx950". They are reached only through tuned CSV rows that name them (201gfx950,256rows,splitK = 0); the default heuristic does not pick them. Shape/dtype: FP8 A/W, FP32 scales, BF16/FP16 out (KSplit=2 only for BF16),K % 128 == 0,N % (16*NRep) == 0, contiguous 16-byte-aligned rows, LDS <= 64 KB (bounds K),splitK = 0(TORCH_CHECK); anything else fails loudly rather than running a wrong path. KSplit is fixed per instance andstatic_asserted to 1 or 2.op_tests/test_gemm_a8w8_blockscale.py: see below.Changed op tests
op_tests/test_gemm_a8w8_blockscale.py. Against main, this file also carries #8541's changes, which run only on gfx950:test_splitk_deterministic: 9 tuned CK and CK-Tile split-K kernels (splitK2 and 3, including a v3 pipeline and an 8-wave CK-Tile kernel), 20 repeats each. It asserts that every call returns the first call's bits and that the output is within tolerance ofsplitK = 0.test_splitk_concurrent_graphs: two graphs captured on the default capture stream and replayed at the same time from two threads must match eager. It fails if two graphs share split-K counters.This PR adds on top of them an optional
ref_kernel_namefortest_splitk_deterministic(thesplitK = 0reference, default: the kernel under test), five slice-K cases (one per tile family), 100 repeats each, with CK 16x64 atsplitK = 0as the reference, andtest_slicek_cancelling_k_halves:a8w8_blockscale_slicek_16x16x128_16w_u2_ks1at M=1 N=2048 K=3072 (KSplit=1, LDS wave reduction). Asserts 0/100 mismatching calls and error < 0.05 vssplitK = 0(measured: bitwise equal).a8w8_blockscale_slicek_16x16x128_16w_u4_ks2at M=80 N=128 K=7168 (KSplit=2, the shipped two-half atomic kernel). Asserts 0/100 mismatching calls and error < 0.05 (measured: 0.007).a8w8_blockscale_slicek_16x32x128_8w_u2_ks1at M=40 N=2048 K=2048 (8 waves, NRep=2),..._16x64x128_16w_u2_ks1at M=80 N=3072 K=3072 (NRep=4) and..._32x32x128_16w_u2_ks1at M=72 N=2048 K=2048 (MRep=2, partial M tile). Same asserts (measured: 0/100 mismatching calls; 11-26 elements differ fromsplitK = 0in the last BF16 bit, max abs 0.016, because the FP32 sum order differs).test_slicek_cancelling_k_halves:..._16w_u4_ks2at M=16/40/80 N=128 K=7168 with K halves of +114688 and -114688, FP16 and BF16 output. Asserts that every output is zero. It fails before the FP16 fix (all NaN).Not redundant: no other op test calls a slice-K kernel, so nothing else covers the LDS wave reduction, the two-half atomic path, the 8-wave schedule, the NRep/MRep > 1 addressing, or the FP16 overflow. The reference parameter is needed because slice-K kernels take no
splitK.Related
splitKto <= 1 (deterministic, but slower).Duplicate work
No other open PR adds deterministic small-M blockscale kernels; this extends #8541 and is split out only because of the one-backend-per-PR rule.
AI assistance (Claude) wrote this change, the selection, the CSV updates and this description, and ran the tests and measurements above on MI350X. The review fixes (FP16 KSplit, literal kernel IDs, new op tests) and the MI350X recheck were also AI-assisted. A human has not yet reviewed every changed line.