Skip to content

[CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows - #8609

Open
AndreasKaratzas wants to merge 13 commits into
ROCm:mainfrom
AndreasKaratzas:blockscale-slicek-deterministic
Open

AndreasKaratzas wants to merge 13 commits into
ROCm:mainfrom
AndreasKaratzas:blockscale-slicek-deterministic

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #8541; review only the commits on top of it (f7ba659, e695196, and the review-fix commit 4993453).

Summary

#8541 makes the 452 tuned gfx950/cu256 gemm_a8w8_blockscale split-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 >= 2 on 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, like splitK = 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.

Open timing issue (MI350X). In an interleaved main-vs-head run, the five ds_v3 N=128 K=7168 slice-K rows (M=1/2/16/40/80) are 1-20% slower than main, not faster (see "N=128 K=7168 recheck" below). The claim "none of the 201 slice-K rows is slower than main" comes from MI355X and is not confirmed on MI350X for these five rows.

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). Kernel aiter_slicek::kernel<MRep, NRep, NWaves, Unroll, KSplit> on __builtin_amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
    • One workgroup per (16*MRep) x (16*NRep) output tile, NWaves (8 or 16) waves.
    • Wave w takes the 128-wide K blocks w, w+NWaves, ... in a fixed order, applies the x_scale * w_scale block scale per MFMA result, and accumulates in FP32. The tile's x scales are staged in LDS as [K/128][MT].
    • The wave partials are written to LDS, and after __syncthreads each output element is summed in wave order 0..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 by hipMemset2DAsync on the same stream. static_assert(KSplit == 2) blocks more halves.
    • FP16 output: the host launches the same tile with 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 is inf - inf = NaN. The FP16 KSplit = 2 kernel is not instantiated.
    • Host checks (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: new SliceKInstance; 8 variants in slicek_kernels_dict with literal CK kernelIds 19-26, added only when get_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 into gen_legacy_impl; gen_ck_instance picks gen_slicek_impl or gen_legacy_impl (SliceKInstance has no CK tile fields).
  • gemm_a8w8_blockscale_tune.py: the tuner does not try splitK for slice-K kernels.
  • Tuned CSVs (a8w8_blockscale_tuned_gemm.csv 64 rows, qwen3_next_80b_a3b 72, glm53_flash 23, qwen3_14b 12, mistral_large4 12, ds_v3 11, qwen38_27b 7): 201 gfx950/cu256 rows switch to libtype ck, kernelId 19-26, splitK = 0.
  • op_tests/test_gemm_a8w8_blockscale.py: five slice-K cases in test_splitk_deterministic (one per tile family) and a new test_slicek_cancelling_k_halves (see "Changed op tests").
kernelId kernel tile waves unroll KSplit rows
19 a8w8_blockscale_slicek_16x16x128_8w_u2_ks1 16x16 8 2 1 47
20 ..._16x16x128_16w_u2_ks1 16x16 16 2 1 45
21 ..._16x16x128_16w_u4_ks1 16x16 16 4 1 17
22 ..._16x16x128_16w_u4_ks2 16x16 16 4 2 3
23 ..._16x32x128_8w_u2_ks1 16x32 8 2 1 22
24 ..._16x32x128_16w_u2_ks1 16x32 16 2 1 47
25 ..._16x64x128_16w_u2_ks1 16x64 16 2 1 2
26 ..._32x32x128_16w_u2_ks1 32x32 16 2 1 18

Determinism

  • KSplit=1: every wave reads the same K blocks in the same order, the wave partials are summed in a fixed wave order, and each element is rounded once and written by one thread with a plain store. No atomics, no workspace, no cross-workgroup communication: the output is a pure function of the inputs with one rounding, like splitK = 0. Measured on f7ba659: error ratio 1.000 vs splitK = 0 on all 183 KSplit=1 rows of that head, and bitwise equal to CK splitK = 0 in the M=1 op-test case.
  • KSplit=2 (BF16 output): each half's FP32 partial is deterministic (same fixed order), and is rounded to BF16 before the atomic. Each element receives exactly two adds onto a zeroed output: 0 + r(a) = r(a) exactly, then r(r(a) + r(b)), which is the same in either arrival order because IEEE addition is commutative. (A -0 half 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 of splitK = 0 at 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_blockscale with 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 >= 2 on main, including the 16 Qwen3.8-27B rows of #8016), change vs main:

activations geomean rows > +2% rows > +5% worst row rows > 2% faster
#8541 cold -4.4% 15 1 +5.2% (48x256x2048) 240
#8541 warm -4.3% 14 1 +5.4% (48x256x2048) 237
#8541 + this PR cold -11.6% 6 0 +2.9% (16x2624x6144) 341
#8541 + this PR warm -11.4% 4 0 +3.0% (32x2624x6144) 339
previous heads (f7ba659, merged with main) cold -11.2% 7 1 +9.0% (80x5120x8704)
previous heads warm -11.0% 5 1 +9.3% (80x5120x8704)
tuned table rows #8541 #8541 + this PR rows > +2% (either mode)
a8w8_blockscale_tuned_gemm 90 -3.6% -14.3% 4
ds_v3 147 -5.7% -6.7% 2
mistral_large4 37 -3.6% -6.6% 0
qwen38_27b 16 -5.5% -9.6% 0
qwen3_14b 33 -2.7% -6.2% 0
qwen3_next_80b_a3b 88 -3.3% -19.2% 0
glm53_flash 41 -5.7% -14.7% 1

(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):

M x N x K main, us cold warm config
32x576x7168 8.57 +1.6..+2.8% +2.6..+3.6% ck 16x64 splitK 3
32x128x7168 8.36 +2.6..+3.5% +2.7..+3.5% ck 16x64 splitK 3
32x2624x6144 9.23 +1.8..+3.1% +2.5..+3.4% ck 16x64 splitK 3
16x2624x6144 8.08 +1.3..+3.2% +2.2..+2.9% ck 16x64 splitK 3
32x3072x6144 9.46 +2.0..+2.3% +1.8..+2.8% ck 16x64 splitK 3
48x3072x4096 9.38 +2.1..+2.7% +1.6..+2.8% ck 16x64 splitK 3

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_blockscale with each tree's CSVs. Main 1c96e23 and this head in alternate processes (ABBA order, 6 rounds), one script for both trees. run_perftest is the aiter tuner's method (profiler, rotating inputs); graph is 128 calls over 128 input sets in one CUDA graph. Medians:

M main config head config main us (run_perftest) head us (run_perftest) change change (graph)
1 ck 32x64 splitK 3 slicek 16w_u2_ks1 7.27 7.49 +3.0% +1.4%
2 ck 16x64 splitK 3 slicek 16w_u2_ks1 7.08 7.82 +10.5% +17.6%
16 ck 16x64 splitK 3 slicek 16w_u4_ks2 7.78 8.58 +10.3% +19.9%
40 ck 16x64 splitK 3 slicek 16w_u4_ks2 7.95 8.44 +6.1% +13.4%
80 ck 16x64 splitK 3 slicek 16w_u4_ks2 8.37 8.76 +4.6% +15.2%
  • Warm activations (4 rounds): +4.7..+13.9% (run_perftest), +0.9..+37.4% (graph).
  • [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541's ordered split-K on the main kernels, same script (4 rounds, graph): slice-K is +1.4% (M=1) and +7..+16% (M=2..80) slower.
  • FP16 output (head runs the ks2 rows as KSplit=1): 9.2-9.9 us (graph) vs 26-29 us on main, where split-K rows run without split-K for FP16.
  • CSV us: the head values of these rows match run_perftest within 3%. The old main values (5.53-7.74 us) do not reproduce on main today (7.08-8.37 us).
  • Not done yet: recheck on MI355X. If the gap holds, move these five rows back to [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541's config.

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

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

No API, flag or env change. On gfx950 the tuned CSVs select new CK kernelIds 19-26 for 201 rows.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

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):

  • FP16 overflow repro: M=16/40/80, N=128, K=7168, A=1, B=+1/-1 per K half, x_scale=32, w_scale=1 (exact result 0). Before: a8w8_blockscale_slicek_16x16x128_16w_u4_ks2 with FP16 output is all NaN (2048/2048, 5120/5120, 10240/10240), also through aiter.gemm_a8w8_blockscale(..., dtype=fp16). After: 0 NaN, all zero. BF16 and KSplit=1 are zero before and after.
  • FP16 on the ks2 instance: bitwise equal to ..._16w_u4_ks1 on random inputs (M=16/40/80); relative L2 error vs FP32 2.0e-4.
  • Op test: python op_tests/test_gemm_a8w8_blockscale.py exits 0 in 10 of 10 runs in a loop: 5 slice-K cases 0/100 each, test_slicek_cancelling_k_halves 6/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.
  • Kernel IDs: all 201 slice-K CSV rows map to the same kernel name under the literal IDs.
  • Timing: see "N=128 K=7168 recheck".
  • Lint: black 26.10.1, ruff 0.16.0 and clang-format 18.1.8 clean on the changed files.

On f412e77 (#8541's head e949a3e with main 1c96e23 merged), MI355X (gfx950, 256 CUs):

  • Op test: python op_tests/test_gemm_a8w8_blockscale.py exits 0: 9 CK and CK-Tile determinism cases 0/20, the 2 slice-K cases 0/100, test_splitk_concurrent_graphs 0/800. python op_tests/test_gemm_codegen.py: 74 passed, 0 failed.
  • Repeatability: 577 tuned rows at their tuned M and at M-1 (1050 cases), 8 eager calls plus a 4-call graph replayed 4 times, compared bitwise: 0 cases differ, in 4 sweeps with other load on the GPU (main: 742 eager, 753 graph). Relative L2 error vs FP64: median 0.0017, max 0.0025 (main 0.0032 / 0.0042).
  • Timing: all 452 affected rows vs main, cold and warm activations, HIP-graph replay (see Performance): -11.6% / -11.4% geomean, no row above +5%, 7 rows above +2%, none above +3.6%.
  • End to end: Qwen3-Next-80B-A3B-Instruct-FP8 in vLLM on one MI355X, temperature 0, 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.
  • GPU CI: Aiter Test Gate passed on f412e77.
  • Lint: black 26.10.1 and ruff 0.16.0 clean on the changed Python files.

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:

  • 476 rows (436 then-affected + 40 controls) through 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.000x splitK = 0 on every KSplit=1 row, 1.44-1.48x on the KSplit=2 rows. bf16 and fp16 output: 0 mismatches.
  • KSplit=2 adversarial test: 1000 calls on each of 25 shapes, bf16 and fp16, with random matmuls on a second stream and a random _sleep before each call: 0 mismatches. Positive control, main's atomic split-K (ck 6, splitK = 3) at N=128 K=7168: 1000/1000 mismatches.
  • CUDA graphs / streams ([CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541's test plus 5 slice-K shapes) and 240 Hy4-flash-FP8 linear shapes: 0 mismatches.
  • gfx942 safety: GPU_ARCHS=gfx942 codegen (normal and --tune) emits 0 slice-K instances. A GPU_ARCHS="gfx942;gfx950" build succeeds, and all 16 gfx942 slice-K code objects are kernarg prologue + s_endpgm.

Unverified:

  • Everything in the f412e77 list above was not rerun on the review fixes. GPU CI not yet run on them.
  • The five N=128 K=7168 rows are slower than main on MI350X; MI355X recheck pending.
  • gfx942 / MI300X at run time (no hardware; slice-K is not built for it, see above).
  • The KSplit=2 adversarial test, the graph/stream test, the Hy4 shapes and the gfx942 codegen check were not rerun on f412e77 (kernel and variant list unchanged since f7ba659).
  • FP16-output timing beyond the five N=128 K=7168 rows; gfx950 128-CU parts.
  • vLLM end-to-end accuracy (lm_eval). Only repeatability and tokens/s were checked; with AITER fused MoE on, outputs still vary from call to call because of [Issue]: fused_moe stage 2 adds the top-k expert outputs with atomics: output is not repeatable for topk >= 3 (bf16 CK, MXFP4 CK-Tile and FlyDSL atomic kernels, gfx950) #8797.
  • The GPU was shared with other jobs during timing; rows within about 1% of the 2% line move in and out of the slower list between passes.
  • The CSV us values for changed rows come from a graph-replay harness, not the aiter tuner. For the five N=128 K=7168 rows they match run_perftest within 3% on MI350X; the other 196 rows were not rechecked.
  • Tuner coverage: the tuner sees only the 8 shipped variants; a new shape that wants another tile needs the variant list extended.

PR-specific question

  1. Behavior change and why. On gfx950, 201 tuned split-K rows move from [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541's fused split-K path (FP32 workspace + per-tile counter) to new single-pass kernels that split K inside a workgroup and reduce in LDS. [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541 is deterministic but still pays the workspace and counter round trips on decode-sized M. Slice-K takes these 201 rows to -18.8% vs main while keeping determinism.
  2. Validation and unverified scope. See above. On f412e77: op test and codegen test pass, 1050 cases bitwise repeatable (main: 742 not), 452-row timing at -11.6% / -11.4%, vLLM repeatability check, GPU CI passed. On f7ba659: 476-row bitwise sweep, KSplit=2 adversarial test with positive control, graphs/streams, gfx942 codegen. Review fixes on MI350X: FP16 overflow repro before/after, op test 10/10, codegen test. Not covered: gfx942 at run time, most FP16 timing, 128-CU parts, vLLM accuracy, MI355X recheck of the five N=128 K=7168 rows.
  3. Boundaries and invariants. Slice-K kernels exist only when get_gfx() == "gfx950" at codegen, their device body only under __gfx950__, and the host TORCH_CHECKs get_device_gfx() == "gfx950". They are reached only through tuned CSV rows that name them (201 gfx950,256 rows, 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 and static_asserted to 1 or 2.
  4. Changed op tests. 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 (splitK 2 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 of splitK = 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_name for test_splitk_deterministic (the splitK = 0 reference, default: the kernel under test), five slice-K cases (one per tile family), 100 repeats each, with CK 16x64 at splitK = 0 as the reference, and test_slicek_cancelling_k_halves:

  • a8w8_blockscale_slicek_16x16x128_16w_u2_ks1 at M=1 N=2048 K=3072 (KSplit=1, LDS wave reduction). Asserts 0/100 mismatching calls and error < 0.05 vs splitK = 0 (measured: bitwise equal).
  • a8w8_blockscale_slicek_16x16x128_16w_u4_ks2 at 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_ks1 at M=40 N=2048 K=2048 (8 waves, NRep=2), ..._16x64x128_16w_u2_ks1 at M=80 N=3072 K=3072 (NRep=4) and ..._32x32x128_16w_u2_ks1 at M=72 N=2048 K=2048 (MRep=2, partial M tile). Same asserts (measured: 0/100 mismatching calls; 11-26 elements differ from splitK = 0 in the last BF16 bit, max abs 0.016, because the FP32 sum order differs).
  • test_slicek_cancelling_k_halves: ..._16w_u4_ks2 at 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

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.

AndreasKaratzas and others added 2 commits November 24, 2026 15:58
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]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8609 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas and others added 7 commits November 27, 2026 21:16
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]>
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

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

Timing

Same method as in #8541. All 452 gfx950/cu256 rows that use splitK >= 2 on main:

#8541 + this PR activations geomean vs main rows > +2% rows > +5% worst row
previous heads, merged with main cold -11.2% 7 1 +9.0% (80x5120x8704)
previous heads, merged with main warm -11.0% 5 1 +9.3% (80x5120x8704)
these heads cold -11.6% 6 0 +2.9% (16x2624x6144)
these heads warm -11.4% 4 0 +3.0% (32x2624x6144)
  • Counting a row if it is slower in either mode: 8 rows above +2% before, 7 now.
  • The 201 slice-K rows are 18.8% faster than main, and none of them is slower than main in either mode. The 251 rows on [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541's path are 5.4% faster.
  • The 26 rows whose config changed are 8.0% (cold) and 6.8% (warm) faster than before.
  • Sum of per-call times over the 452 rows: main 4982 us, [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541 4761 us, this PR 4539 us (-8.9%).
  • Controls are flat: 65 splitK = 1 rows +0.16% / 0.00% (cold / warm), 53 other tuned rows +0.10% / +0.10%.
  • Eager calls (300 calls in a row, wall time per call, 50-row sample): 17% to 19% faster than main, and no row is slower.
Per tuned table, per M, and the 15 rows that moved

Geomean vs main, cold activations:

tuned table rows #8541 #8541 + this PR
a8w8_blockscale_tuned_gemm 90 -3.6% -14.3%
ds_v3 147 -5.7% -6.7%
mistral_large4 37 -3.6% -6.6%
qwen38_27b 16 -5.5% -9.6%
qwen3_14b 33 -2.7% -6.2%
qwen3_next_80b_a3b 88 -3.3% -19.2%
glm53_flash 41 -5.7% -14.7%

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):

  • 7 Qwen3.8-27B rows: 16x4096x5120 +1.8% -> -26.6%, 16x5120x3072 -1.5% -> -17.5%, 16x8192x5120 -0.1% -> -12.3%, 16x3584x5120 -1.2% -> -11.3%, 32x5120x3072 +2.4% -> -9.0%, 32x4096x5120 +3.9% -> -6.6%, 32x3584x5120 -0.9% -> -6.6%.
  • 72/80/88/96x2048x3072, 40x3072x3072 and 80x3072x3072: 5% to 7% faster than before.
  • 32x4096x6144 -0.4% -> -4.0% and 32x3072x4096 +0.4% -> -1.8%.

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 splitK 0-4 and 124 slice-K variants. A change was kept only if the worse of the two modes improved by at least 0.5% in a six-worker run.

Rows still slower

More than 2% slower than both main workers in both passes. The range covers both passes and both main workers.

M x N x K main, us cold warm config
32x576x7168 8.57 +1.6..+2.8% +2.6..+3.6% ck 16x64 splitK 3
32x128x7168 8.36 +2.6..+3.5% +2.7..+3.5% ck 16x64 splitK 3
32x2624x6144 9.23 +1.8..+3.1% +2.5..+3.4% ck 16x64 splitK 3
16x2624x6144 8.08 +1.3..+3.2% +2.2..+2.9% ck 16x64 splitK 3
32x3072x6144 9.46 +2.0..+2.3% +1.8..+2.8% ck 16x64 splitK 3
48x3072x4096 9.38 +2.1..+2.7% +1.6..+2.8% ck 16x64 splitK 3

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

  • 577 tuned rows at their tuned M and at M-1: 1050 distinct cases. Per case 8 eager calls, then a graph of 4 calls replayed 4 times, all compared bitwise.
  • Main: 742 cases differ between eager calls and 753 under graph replay. This head: 0 and 0, in 4 sweeps that ran while other sweeps, a load process or a vLLM engine used the same GPU.
  • Relative L2 error against FP64: main 0.0032 median and 0.0042 max, this head 0.0017 and 0.0025. The 937 cases that were also swept on the previous head have the same error there.
  • python op_tests/test_gemm_a8w8_blockscale.py exits 0 (9 CK and CK-Tile determinism cases 0 of 20, 2 slice-K cases 0 of 100, test_splitk_concurrent_graphs 0 of 800). python op_tests/test_gemm_codegen.py reports 74 passed, 0 failed. black 26.10.1 and ruff 0.16.0 are clean on the changed Python files.

End to end

Qwen3-Next-80B-A3B-Instruct-FP8 on one MI355X through vLLM, temperature 0, 8 prompts x 64 tokens, VLLM_ROCM_USE_AITER_MOE=0: 5 identical warm calls give 5 different outputs on main and 1 with this head. With default settings the output still changes from call to call, because AITER's fused MoE is not repeatable either (#8797). Tokens/s is unchanged within run-to-run spread. The full table is in #8541.

Not covered

@AndreasKaratzas
AndreasKaratzas marked this pull request as ready for review November 28, 2026 07:08
@AndreasKaratzas
AndreasKaratzas requested a review from a team November 28, 2026 07:08
@github-actions github-actions Bot changed the title [HIP] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows [CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows Nov 28, 2026
@github-actions github-actions Bot added the CK label Nov 28, 2026
@aiter-bot

aiter-bot commented Nov 28, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision d6f782e64c7c · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

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 (f412e7746 plus the FP16 KSplit, kernelId and op-test changes), MI350X (gfx950, 256 CUs, SPX):

- **FP16 overflow repro:** M=16/40/80, N=128, K=7168, A=1, B=+1/-1 per K half, x_scale=32, w_scale=1 (exact result 0). Before: `a8w8_blockscale_slicek_16x16x128_16w_u4_ks2` with FP16 output is all NaN (2048/2048, 5120/5120, 10240/10240), also through `aiter.gemm_a8w8_blockscale(..., dtype=fp16)`. After: 0 NaN, all zero. BF16 and KSplit=1 are zero before and after.
- **FP16 on the ks2 instance:** bitwise equal to `..._16w_u4_ks1` on random inputs (M=16/40/80); relative L2 error vs FP32 2.0e-4.
- **Op test:** `python op_tests/test_gemm_a8w8_blockscale.py` exits 0 in 10 of 10 runs in a loop: 5 slice-K cases 0/100 each, `test_slicek_cancelling_k_halves` 6/6 cases zero, the #8541 cases unchanged. The new cancellation test fails on f412e7746 (FP16: all outputs NaN). `python op_tests/test_gemm_codegen.py`: 74 passed, 0 failed.
- **Kernel IDs:** all 201 slice-K CSV rows map to the same kernel name under the literal IDs.
- **Timing:** see "N=128 K=7168 recheck".
- **Lint:** black 26.10.1, ruff 0.16.0 and clang-format 18.1.8 clean on the changed files.

On f412e7746 (#8541's head e949a3e1d with main 1c96e23eb merged), MI355X (gfx950, 256 CUs):

- **Op test:** `python op_tests/test_gemm_a8w8_blockscale.py` exits 0: 9 CK and CK-Tile determinism cases 0/20, the 2 slice-K cases 0/100, `test_splitk_concurrent_graphs` 0/800. `python op_tests/test_gemm_codegen.py`: 74 passed, 0 failed.
- **Repeatability:** 577 tuned rows at their tuned M and at M-1 (1050 cases), 8 eager calls plus a 4-call graph replayed 4 times, compared bitwise: 0 cases differ, in 4 sweeps with other load on the GPU (main: 742 eager, 753 graph). Relative L2 error vs FP64: median 0.0017, max 0.0025 (main 0.0032 / 0.0042).
- **Timing:** all 452 affected rows vs main, cold and warm activations, HIP-graph replay (see Performance): -11.6% / -11.4% geomean, no row above +5%, 7 rows above +2%, none above +3.6%.
- **End to end:** Qwen3-Next-80B-A3B-Instruct-FP8 in vLLM on one MI355X, temperature 0, `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.
- **GPU CI:** `Aiter Test Gate` passed on f412e7746.
- **Lint:** black 26.10.1 and ruff 0.16.0 clean on the changed Python files.

On earlier heads (7ed1a15d8, f7ba6592f), MI350X. The slice-K kernel source, its 8 variants and their codegen have not changed since f7ba6592f; e69519690 only moves 15 more rows to them:

- 476 rows (436 then-affected + 40 controls) through `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.000x `splitK = 0` on every KSplit=1 row, 1.44-1.48x on the KSplit=2 rows. bf16 and fp16 output: 0 mismatches.
- KSplit=2 adversarial test: 1000 calls on each of 25 shapes, bf16 and fp16, with random matmuls on a second stream and a random `_sleep` before each call: 0 mismatches. Positive control, main's atomic split-K (ck 6, `splitK = 3`) at N=128 K=7168: 1000/1000 mismatches.
- CUDA graphs / streams (#8541's test plus 5 slice-K shapes) and 240 Hy4-flash-FP8 linear shapes: 0 mismatches.
- gfx942 safety: `GPU_ARCHS=gfx942` codegen (normal and `--tune`) emits 0 slice-K instances. A `GPU_ARCHS="gfx942;gfx950"` build succeeds, and all 16 gfx942 slice-K code objects are kernarg prologue + `s_endpgm`.

Unverified:
- Everything in the f412e7746 list above was not rerun on the review fixes. GPU CI not yet run on them.
- The five N=128 K=7168 rows are slower than main on MI350X; MI355X recheck pending.
- gfx942 / MI300X at run time (no hardware; slice-K is not built for it, see above).
- The KSplit=2 adversarial test, the graph/stream test, the Hy4 shapes and the gfx942 codegen check were not rerun on f412e7746 (kernel and variant list unchanged since f7ba6592f).
- FP16-output timing beyond the five N=128 K=7168 rows; gfx95

[truncated in readiness report; see the PR description for the full answer]

PR-specific question

1. **Behavior change and why.** On gfx950, 201 tuned split-K rows move from #8541's fused split-K path (FP32 workspace + per-tile counter) to new single-pass kernels that split K inside a workgroup and reduce in LDS. #8541 is deterministic but still pays the workspace and counter round trips on decode-sized M. Slice-K takes these 201 rows to -18.8% vs main while keeping determinism.
2. **Validation and unverified scope.** See above. On f412e7746: op test and codegen test pass, 1050 cases bitwise repeatable (main: 742 not), 452-row timing at -11.6% / -11.4%, vLLM repeatability check, GPU CI passed. On f7ba6592f: 476-row bitwise sweep, KSplit=2 adversarial test with positive control, graphs/streams, gfx942 codegen. Review fixes on MI350X: FP16 overflow repro before/after, op test 10/10, codegen test. Not covered: gfx942 at run time, most FP16 timing, 128-CU parts, vLLM accuracy, MI355X recheck of the five N=128 K=7168 rows.
3. **Boundaries and invariants.** Slice-K kernels exist only when `get_gfx() == "gfx950"` at codegen, their device body only under `__gfx950__`, and the host `TORCH_CHECK`s `get_device_gfx() == "gfx950"`. They are reached only through tuned CSV rows that name them (201 `gfx950,256` rows, `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 and `static_assert`ed to 1 or 2.
4. **Changed op tests.** `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 (`splitK` 2 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 of `splitK = 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_name` for `test_splitk_deterministic` (the `splitK = 0` reference, default: the kernel under test), five slice-K cases (one per tile family), 100 repeats each, with CK 16x64 at `splitK = 0` as the reference, and `test_slicek_cancelling_k_halves`:
- `a8w8_blockscale_slicek_16x16x128_16w_u2_ks1` at M=1 N=2048 K=3072 (KSplit=1, LDS wave reduction). Asserts 0/100 mismatching calls and error < 0.05 vs `splitK = 0` (measured: bitwise equal).
- `a8w8_blockscale_slicek_16x16x128_16w_u4_ks2` at 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_ks1` at M=40 N=2048 K=2048 (8 waves, NRep=2), `..._16x64x128_16w_u2_ks1` at M=80 N=3072 K=3072 (NRep=4) and `..._32x32x128_16w_u2_ks1` at M=72 N=2048 K=2048 (MRep=2, partial M tile). Same asserts (measured: 0/100 mismatching calls; 11-26 elements differ from `splitK = 0` in the last BF16 bit, max abs 0.016, because the FP32 sum order differs).
- `test_slicek_cancelling_k_halves`: `..._16w_u4_ks2` at 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`.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@demonsan

demonsan commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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 aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROCm/aiter PR #8609 — [CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows

Review (advisory): ⚠️ NEEDS WORK
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

Comment on lines +732 to +737
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [verified] 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); the 8-wave, 16x32 (NRep=2), 16x64 (NRep=4), 32x32 (MRep=2) and u4_ks1 instantiations — 153 of the 201 routed rows — are exercised by no CI-collected test, and the default main-loop shape (N=24576, K=1536) routes to no slice-K row, so a regression in the NRep/MRep>1 addressing (wsp[j] per j, ij/NRep in out_index) or the 8-wave schedule would ship silently. Author must add one case per template shape family (at least the 32x32 MRep=2 kernel and one 8-wave variant) or state why the two collected cases subsume them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [verified] 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 aiter-tuner values, so one column mixes methodologies: the five N=128 K=7168 rows read 33-50% slower than the configs they replace by the column's own numbers (5.67→7.55, 5.53→7.78, 5.64→8.47, 6.21→8.19, 7.74→8.50 us), which the PR attributes to the harness change — and aiter/jit/core.py:655 ranks duplicate shapes across merged config files by lowest us, so the column is load-bearing the day a duplicate appears. Author must re-measure the changed rows with one harness (or annotate the provenance where the CSV is produced) and confirm in one interleaved run that the five N=128 rows are at or below main, as the description claims.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +192 to +194
_next_id = max(candidate_kernels_dict) + 1
for _i, _k in enumerate(slicek_kernels_list):
candidate_kernels_dict[_next_id + _i] = _k

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
AndreasKaratzas and others added 2 commits December 3, 2026 00:39
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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants