Skip to content

[CK] [Bugfix] Make a8w8 blockscale split-K deterministic - #8541

Open
AndreasKaratzas wants to merge 7 commits into
ROCm:mainfrom
AndreasKaratzas:blockscale-deterministic-splitk
Open

AndreasKaratzas wants to merge 7 commits into
ROCm:mainfrom
AndreasKaratzas:blockscale-deterministic-splitk

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On gfx950, tuned CK and CK-Tile gemm_a8w8_blockscale rows with splitK >= 2 (KBatch 4 or 8) add their K partials into the BF16/FP16 output with atomics, so the output bits change from call to call. With this PR those rows return the same bits on every call and are as accurate as splitK = 0.

  • CK: the last K batch to finish an output tile reduces the FP32 partials inside the GEMM, in K order, and rounds once. There is no memset and no second kernel.
  • CK-Tile: FP32 partials plus a small reduce kernel (no gfx950 tuned row uses it after the retune). A workspace over 2 GB falls back to the atomic path, as on CK.
  • Retune: 189 of the 452 affected gfx950/cu256 rows change in the tuned CSVs. 167 move to a faster deterministic config. 22 keep their config and only get new timings.
  • gfx950 only. gfx942 and every other arch run main's memset + atomic path unchanged (identical gfx942 ISA for every kernel main builds). gfx942 stays nondeterministic; that is a follow-up.

Benchmark on MI355X, all 452 affected rows: -4.4% geomean vs main (cold activations; -4.3% warm), one row above +5% (+5.4%). Relative error vs FP64: 0.0017 median here, 0.0032 on main.

Motivation

vLLM's AiterFp8BlockScaledMMKernel (w8a8, per-token-group-128 activations, 128x128 weight blocks) calls aiter.gemm_a8w8_blockscale on gfx950. For decode-sized M the tuned rows pick ck/cktile with splitK 2 or 3, so 4 or 8 partials are atomically added into the BF16 output, and the rounding depends on arrival order. This showed up as run-to-run and graph-vs-eager differences when serving Hy4 / Hy4-Flash FP8 in vLLM.

  • On real Hy4-flash-FP8 layers.1.self_attn.linear_gate weights (N=8192, K=3072) the same input differs on 20 of 20 calls, by up to 0.094 abs at M=6. 36 of 50 Hy4-flash (shape, M) cases are nondeterministic.
  • On main adbb6ac, 431 of the 436 affected rows (plus 3 untuned shapes that M-pad onto them) give different bits over 50 calls; 20619 of 21364 repeat calls differ.
  • Size of the differences between calls: 64% of differing elements are 1 ULP apart, 20% are 2 ULP, and 14% are 4 ULP or more, concentrated on near-zero outputs where cancellation makes the local ULP small (max about 384 local ULP).
  • Accuracy also suffers: error vs an FP64 reference is 1.93x that of splitK = 0 at the median, 3.0x at worst, because the BF16 atomic adds round several times.

Why this revision is different from the first one

The first revision of this PR wrote FP32 partials and launched a separate reduce kernel. It was deterministic but cost +7.2% geomean (382 rows above +3%, worst +21.5%). This revision replaces it with a fused last-arriving-workgroup reduction for CK and retunes the affected rows on the new path.

KBatch = 2 (splitK = 1) is left alone: it is already deterministic (see Changes). An earlier version of this description said otherwise; that was wrong.

Changes

  • gemm_a8w8_blockscale_common.cuh, gen_instances.py (CK). Every instance also instantiates the same kernel with FP32 output. For KBatch 4, 8 or 16, kernel_gemm_blockscale_splitk_fused:

    1. stores each K batch's partial to slice blockIdx.z of a [KBatch, M, N] FP32 workspace;
    2. waits for the stores (s_waitcnt vmcnt(0)) and increments a per-tile counter;
    3. the workgroup that sees KBatch - 1 loads the partials, adds them in batch order, rounds once to BF16/FP16, and resets the counter to 0.

    Kernel selection follows the device op (v1/v3 pipeline, tail number, min occupancy). Wave32, other pipelines (no current instance) or a workspace over 2 GB fall back to the atomic path.

  • Coherence without a fence: the sc1 store specialization. Partial stores and the reducer's loads are device-scope (sc1), which keeps them coherent across XCDs. A release/acquire fence (buffer_wbl2 / buffer_inv of the whole L2) made the kernel 30% to 5x slower. CK has no per-call coherence knob on its epilogue store, so the header adds an explicit specialization of ck::amd_buffer_store<float, N, DefaultCoherence> that emits DEVICE_NT0 (sc1). Constraints:

    • It applies only in TUs that include this header, and only under __gfx950__; in those TUs the FP32 partials are the only float global stores.
    • It relies on the gfx942/gfx950 mapping of sc1 (the relaxed agent-scope atomic encoding) plus s_waitcnt vmcnt(0) before the counter increment, not on a C++ release/acquire pair. Without it, M=2000 N=128 gives relerr 0.8.
    • Basis: the code sequence table in LLVM AMDGPUUsage, Memory Model GFX942, which the compiler also applies to gfx950. store atomic monotonic agent is store sc1=1 and load atomic monotonic agent is load sc1=1. atomicrmw release agent is buffer_wbl2 sc1 + s_waitcnt vmcnt(0) + the atomic, and buffer_wbl2 sc1 is there to write back plain stores. In the gfx950 build, all 784 fused kernels have only sc1 stores before the counter atomic and only sc1 loads after it. The table does not state this shortcut as a rule; it follows from the mapping. __ATOMIC_ACQ_REL on the counter is the language-level alternative (it emits buffer_wbl2 sc1 / buffer_inv sc1).
    • A CK change to amd_buffer_store's signature would break the specialization at compile time, not silently.
  • Counter arena (gemm_a8w8_blockscale_splitk_reduce.cuh, new). Per device, 8 MB chunks (65536 counters each, one counter per 128-byte line), at most 32 chunks (256 MB). The reducer resets each counter, so a chunk is zeroed only once.

    • A region of counters belongs to one stream or, under stream capture, to one capture (the id from hipStreamGetCaptureInfo). So concurrent launches and concurrently replayed graphs never share counters.
    • Chunks are allocated and zeroed outside of capture (hipMalloc, hipMemsetAsync, then hipStreamSynchronize of the calling stream), when less than half a chunk is free, or less than a whole chunk once the device has captured. They are never freed, because captured graphs keep pointers into them.
    • A larger region replaces a smaller one for the same owner. The smaller one stays reserved, because launched kernels and captured graphs still point into it.
    • Without a region (no free space under capture, 32 chunks used, or more than 4096 tiles) the call zeroes per-call counters in the stream. This is correct but 1.6 to 3.6 us slower per call.
    • Measured: Qwen3-Next-80B through vLLM (51 batch sizes, piecewise and full graphs) ends with 4 chunks (32 MB) and no fallback.
    • The header also holds the CK-Tile reduce kernel and the workspace allocation (caching allocator, [KBatch, M, N] FP32 per call).
  • gemm_a8w8_blockscale_cktile_common.cuh (CK-Tile, KBatch > 2). FP32 partials plus a separate reduce kernel, because fusing the reduction made the CK-Tile GEMM 2.5-4x slower. With plain B and K % (KBatch * K_Tile) == 0 each batch runs as a K / KBatch GEMM with k_batch = 1 (plain stores); otherwise each batch adds into its own zeroed slice, so every element has one writer. A workspace over 2 GB (KBatch * M * N * 4 > INT32_MAX) falls back to the atomic path, the same bound as the CK fused path.

  • gfx950 gating. use_splitk_fused / use_splitk_partials also require get_device_gfx() == "gfx950" (cached per device, evaluated only after the KBatch test). The check is at run time because a JIT module's host code is shared by every GPU_ARCHS target, so only a runtime check can choose workspace vs memset and which kernel to launch. The fused kernel body and the sc1 specialization are additionally compiled only under __gfx950__; the same exact name is used on both sides, so no arch can pass the dispatch check and launch an empty kernel.

  • Tuned CSVs (a8w8_blockscale_tuned_gemm.csv and 6 model_configs/* files): 189 gfx950/cu256 rows differ from main. 167 change config (libtype, kernelId, splitK, kernelName); 22 keep it and only get new us/tflops/bw values. The first retune changed 175 rows; c3be5b8 moved 18 more rows (4 of them already in the 175) to a faster config. Candidates were CK ids 0-18 x splitK {0,2,3,4}, timed on the new path (CUDA graph, rotating weights), checked bitwise over 20 calls, relerr within 1.02x of splitK = 0. A row changes only if the new config is at least 3% faster than its current one on the new path, or if the current one was more than 2% slower than main and the new one at least 1% faster. The 3 CK-Tile rows move to CK. gfx942 rows are byte-identical to main.

  • op_tests/test_gemm_a8w8_blockscale.py: test_splitk_deterministic (see "Changed op tests").

Why KBatch = 2 is already deterministic. CK's RunMultiDEpilogue converts the FP32 C-shuffle through PassThrough to EDataType before AtomicAdd (global_atomic_pk_add_bf16), and CK-Tile calls cast_tile<ODataType> before the atomic update_tile. The output is zeroed first. So the result is r(0 + r(p0)) = r(p0) then r(r(p0) + r(p1)), which is the same in either order. With three or more partials the intermediate roundings depend on order, which is why KBatch >= 4 needed the fix. Measured: 1000 calls x 5 cases (4 tuned CK splitK = 1 rows and the CK-Tile 32x128 kernel; adversarial cancelling K halves; concurrent GEMM on a side stream): 0/5000 mismatches on main and here, and every element equals bf16(bf16(p0) + bf16(p1)). The same harness with splitK = 2 on main differs on 1000/1000 calls.

Performance (if applicable)

MI355X (gfx950, 256 CUs), BF16 out, aiter.gemm_a8w8_blockscale with each tree's shipped CSVs, against main 1c96e23.

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
this PR cold -4.4% 15 1 +5.2% (48x256x2048) 240
this PR warm -4.3% 14 1 +5.4% (48x256x2048) 237
previous head (3a1324c, merged with main) cold -4.2% 14 2 +8.6% (80x5120x8704)
previous head warm -4.1% 13 2 +9.0% (80x5120x8704)
  • Slower in either mode: 18 rows above +2%, 13 of them again in a second pass with fresh processes; 6 above +3%; 1 above +5%. Previous head: 16, 6 and 2.
  • Sum of per-call times over the 452 rows (cold): 4982 us -> 4761 us (-4.4%).
  • By M: 1-16 (179 rows) -3.7%, 17-64 (99) -2.8%, 65-256 (79) -6.4%, above 256 (95) -5.8%.
  • Controls: 65 tuned splitK = 1 rows +0.14% / -0.08% (cold / warm), 53 other tuned rows +0.05% / +0.05%.
  • Eager calls (300 calls in a row, wall time per call, 50-row sample): 13% to 15% faster than main, no row slower. A call is one launch where main has a memset and a launch.
tuned table rows geomean (cold) rows > +2% (either mode)
a8w8_blockscale_tuned_gemm 90 -3.6% 5
ds_v3 147 -5.7% 5
mistral_large4 37 -3.6% 2
qwen38_27b 16 -5.5% 1
qwen3_14b 33 -2.7% 0
qwen3_next_80b_a3b 88 -3.3% 5
glm53_flash 41 -5.7% 0

Method.

  • One worker process per tree on one GPU: main, the previous head merged with main, this head, the same two for [CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows #8609, and a second main worker as A/A control. The workers take turns in rotating order.
  • Each sample is a HIP-graph replay of at least 240 calls over weights rotated past 400 MB, 11 samples per worker, row and mode. "Cold" rotates the activations as well; "warm" uses one activation buffer.
  • A row's change is the median over the rounds of worker time / main time. A row counts as slower only if it is slower than both main workers.
  • The 91 rows near the line were measured a second time with fresh processes and 15 samples.
  • A/A between the two main workers: median 0.4%, p90 1.7%, max 4.5%. The GPU and the host were shared with other jobs.

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
48x256x2048 4.94 +5.0..+5.3% +5.1..+5.4% ck 16x64 splitK 3
32x4096x6144 11.41 +3.6..+3.8% +2.4..+3.9% ck 16x64 splitK 2
16x128x7168 8.13 +2.9..+5.0% +2.9..+4.8% ck 16x64 splitK 3
16x256x2048 4.63 +2.6..+5.1% +1.0..+3.9% ck 16x64 splitK 3
40x128x7168 8.25 +3.0..+3.2% +2.8..+3.3% ck 16x64 splitK 3
80x128x7168 8.30 +2.9..+3.5% +2.9..+3.4% ck 16x64 splitK 3
32x576x7168 8.57 +2.3..+2.6% +2.7..+2.8% ck 16x64 splitK 3
32x128x7168 8.36 +2.5..+3.4% +2.6..+3.1% ck 16x64 splitK 3
16x1024x2048 4.91 +2.4..+3.6% +1.8..+4.4% ck 16x64 splitK 3
32x2624x6144 9.23 +2.3..+3.4% +2.4..+2.8% ck 16x64 splitK 3
48x6144x4096 13.42 +1.9..+3.2% +2.4..+4.0% ck 64x64 splitK 2
24x4608x2048 7.22 +2.3..+2.5% +2.1..+2.5% ck 16x64 splitK 2
32x3072x6144 9.46 +2.0..+2.3% +1.6..+2.5% ck 16x64 splitK 3

Above +2% in one pass only: 8x256x2048, 8x2624x6144, 16x1024x6144, 16x2624x6144, 32x256x2048, 32x1536x6144, 32x5120x3072. All of these rows run the fused path, and no other repeatable CK config was faster on them. #8609 moves 8 of the 13 to slice-K kernels.

Where the fused path spends its time. 16x1024x6144, CK 16x64x256, splitK = 3, in a build with the steps switched off one at a time: 4.70 us when the kernel stops after the partial stores; +0.08 us for waiting for the stores; +0.57 us for the arrival counter; +1.08 us for loading, adding and storing the 8 partials. Total 6.43 us, against 6.16 us for main's memset and atomic adds. Letting only the first wave reduce was 14% to 26% slower on five such rows.

Build time. Fresh JIT build of module_gemm_a8w8_blockscale (empty build dir, GPU_ARCHS=gfx950, AITER_MAX_JOBS=64, same CK checkout, 43 TUs in both trees), main 1c96e23 vs this head, 3 runs each in the order main, head, head, main, main, head:

wall, s (median) compiler CPU time, s (median) .so size
main 66.8 (65.0..71.9) 1672 (1571..1812) 40 MB
this PR 87.2 (86.7..89.0) 2122 (2113..2198) 105 MB
change +31% +27% +65 MB

The extra cost is the FP32-output instantiations. The host was shared with other jobs (load average 33 to 95 during the runs). gfx942 was not timed.

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. The same calls now return reproducible results on gfx950, and the tuned CSVs pick different kernels for 167 gfx950 rows.

Dependencies

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

Breaking Changes

None in the API. On gfx950, output bits change for splitK >= 2 rows (now rounded once from an FP32 sum) and for the 167 rows that change config. New resources on gfx950: split-K counters in 8 MB per-device chunks (at most 32, 256 MB), allocated outside of capture and never freed, and a per-call [KBatch, M, N] FP32 workspace from the caching allocator (at most 2 GB, else the atomic path).

PR Self-Review

Reviewed revision

953f740b8c0e2844036da15a9d7cd4d0fe3b5b32

Behavior and intent

On gfx950, CK blockscale GEMMs with 4, 8 or 16 K batches (wave64, v1/v3 pipelines) return the same bits for the same inputs: the last K batch of each tile adds the FP32 partials in K order and rounds once. CK-Tile with more than 2 K batches gets the same result through FP32 partials and a reduce kernel. KBatch 1 and 2 are unchanged (KBatch = 2 is already deterministic). Every other arch runs main's code path. The affected gfx950 tuned rows were re-measured on the new path and 167 changed config, so the fix costs nothing overall.

Validation and unverified scope

MI350X (gfx950, 256 CUs), base main adbb6ac, fresh JIT builds (module .so files and build dirs deleted), GPU_ARCHS=gfx950.

  • Op test: python3 op_tests/test_gemm_a8w8_blockscale.py exits 0; all 9 test_splitk_deterministic cases report mismatching calls=0/20, err=0. On main the test fails at the first case (20/20 calls differ).
  • All 476 rows (436 affected + 40 controls) through aiter.gemm_a8w8_blockscale with this branch's CSVs: 50 eager calls bitwise, plus CUDA-graph capture and 10 replays compared with eager: 0 nondeterministic rows, 0 graph-vs-eager mismatches, relerr 1.000x splitK = 0 (FP64 reference) on every row.
  • Direct CK / CK-Tile calls, BF16 and FP16, splitK 2/3/4, 50 calls: 0 mismatches, relerr equal to splitK = 0. CK-Tile with preshuffled B: 0/30 mismatches.
  • CUDA graphs and streams (9 shapes): two graphs on two streams interleaved with eager calls, concurrent eager streams, and a fresh process whose first call is under capture (per-call counters): 0 mismatches.
  • Hy4-flash-FP8 linear shapes (TP1/4/8, M in {1..300}), 50 calls: 0 of 240 cases nondeterministic (main: 36 of 50).
  • KBatch = 2 adversarial test: see Changes (0/5000 here and on main; positive control 1000/1000).
  • gfx942 cross-build: GPU_ARCHS=gfx942 JIT builds of module_gemm_a8w8_blockscale and module_gemm_a8w8_blockscale_cktile succeed. Per-kernel disassembly vs a gfx942 build of main: all 2753 CK and 5121 CK-Tile kernels of main are present with identical ISA. Extra kernels on gfx942: 784 fused kernels (s_endpgm only), 1376 never-launched FP32-output CK instantiations, and the CK-Tile partials/reduce kernels, which the runtime check never launches.
  • Tuned CSVs: every changed row is gfx950/cu256 (189 rows, 167 with a new config); gfx942 rows identical to main.
  • CK-Tile workspace gate: CK-Tile 32x128 kernel, splitK = 2: at 8192x8192x1024 the call allocates the 1 GB workspace; at 16384x8448x1024 (2.06 GB) it allocates none and matches splitK = 0. Passed 10 of 10 runs, together with 10 of 10 runs of the op test.
  • Lint: git clang-format clean on the changed C++ lines; black --check and ruff check clean.
  • Perf: 452-row benchmark, -4.4% geomean vs main (see Performance).
  • Merge with main (3a1324c, main dd6beb9): no conflicts. Main adds model_configs/a8w8_blockscale_tuned_gemm_qwen38_27b.csv ([Config] Add Qwen3.8-27B FP8 a8w8 blockscale GEMM tunings for gfx950 #8016). It has 16 gfx950 CK rows with splitK >= 2. They now run the fused path. c3be5b8 re-timed them on it and moved 5 of them to a faster config.
  • MI300X (gfx942, 304 CUs) after the merge, fresh GPU_ARCHS=gfx942 JIT builds: python op_tests/test_gemm_a8w8_blockscale.py -m 1 2 4 8 16 32 64 128 --ck_preshuffle False exits 0 in 10 of 10 runs (ck and asm err 0 on every shape). The determinism checks are gfx950 only. In 3 of 10 runs, test_splitk_correctness(m=4, n=512, k=16384, splitK=2) warns: 1 of 2048 outputs differs from splitK = 0 by 0.125. This is main's atomic path, which gfx942 keeps.

Unverified:

  • gfx942 / MI300X beyond the op test above. The other evidence is code inspection plus identical gfx942 ISA. gfx942's 320 tuned splitK >= 2 rows stay nondeterministic, as on main; a gfx942 port of the fused path and retune is a follow-up.
  • Exact-name gate: a future gfx95x part falls back to the atomic path until both the runtime check and __gfx950__ guard are extended.
  • gfx950 128-CU parts (no split-K rows), FP16-output timing, CUDA-graph capture of the CK-Tile path (no tuned row uses it; checked eagerly), and vLLM end-to-end serving accuracy.

PR-specific question

  1. Behavior change and why the existing behavior is insufficient. On gfx950, CK KBatch 4/8/16 partials are no longer added atomically into BF16/FP16 in arrival order; they are stored as FP32 and reduced in K order by the last workgroup of each tile. CK-Tile KBatch > 2 gets the same through a reduce kernel. 167 gfx950 rows change config. The atomic path made outputs differ between identical calls and between eager and CUDA-graph replay (431/436 rows; vLLM Hy4 serving affected), with 1.9-3.0x the error of splitK = 0. Clamping splitK <= 1 ([Bug] Make blockscale split-K deterministic #4581) is deterministic but +26.6% geomean with 1.48x error; the first revision's separate reduce kernel was +7.2%.
  2. Validation and unverified scope. MI350X gfx950: op test (exit 0); 476 rows x 50 calls bitwise plus graph-vs-eager, 0 mismatches, relerr 1.000x; direct BF16/FP16 kernel calls; graphs, multi-stream and capture-first; Hy4 repro 0/240; 452-row benchmark -4.4% geomean. gfx942: cross-compiled with ISA identical to main for every main kernel; op test 10/10 on MI300X after the merge with main. Unmeasured: FP16 timing, CK-Tile under graph capture, vLLM end-to-end.
  3. Arch / dtype / shape boundaries.
    • Fused CK path: gfx950 (get_device_gfx() == "gfx950") and KBatch in {4, 8, 16} and wave64 and KBatch * M * N * 4 <= INT32_MAX and a v1/v3 kernel selection; output BF16/FP16 (the only generated EDataTypes); Y.stride(-1) == 1 (TORCH_CHECK).
    • CK-Tile partials path: gfx950 and KBatch > 2 and KBatch * M * N * 4 <= INT32_MAX.
    • Everything else (any other arch, KBatch 1/2/>=32, wave32, other pipelines, huge workspace) runs main's GemmInstance invoker, which still checks IsSupportedArgument.
    • Invariant: the runtime check and the __gfx950__ device guard use the same exact name, so no arch reaches an empty kernel; the KBatch test comes first, so KBatch 1/2 never query the arch. CSV changes are confined to gfx950,256 rows that had splitK >= 2.
    • Other modules: CK bpreshuffle, asm and FlyDSL blockscale paths do not include these headers. module_gemm_a8w8_blockscale_bpreshuffle_cktile includes the CK-Tile header and gets the same gate; all its tuned rows use splitK = 0.
  4. Changed op tests. op_tests/test_gemm_a8w8_blockscale.py adds test_splitk_deterministic; see below.

Changed op tests

op_tests/test_gemm_a8w8_blockscale.py adds test_splitk_deterministic, run on gfx950:

  • Calls named split-K kernels 20 times on decode shapes and asserts bitwise-equal outputs and closeness to splitK = 0: CK v1 16x64x256, 16x128x256, 16x64x128 and CK v3 128x128 (fused path); CK-Tile 4-wave 32x128 and 8-wave 192x256 (partials path); splitK 2/3.
  • Not redundant: test_splitk_correctness checks only closeness with default kernels, where the race does not show up even on main. The new test fails on main (20/20 calls differ). Kernels are named rather than taken from the CSV so the CK-Tile path stays covered now that no tuned gfx950 row selects it.

Related

Duplicate work

This updates PR #8541 itself; no other PR is opened for the same fix.

AI assistance (Claude) wrote this change, the retune and this description, and ran the tests and measurements above on MI350X. A human has not yet reviewed every changed line.

@AndreasKaratzas
AndreasKaratzas requested a review from a team November 24, 2026 05:48
@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 8541 --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.

@github-actions github-actions Bot added the CK label Nov 24, 2026
@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 953f740b8c0e · 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

On gfx950, CK blockscale GEMMs with 4, 8 or 16 K batches (wave64, v1/v3 pipelines) return the same bits for the same inputs: the last K batch of each tile adds the FP32 partials in K order and rounds once. CK-Tile with more than 2 K batches gets the same result through FP32 partials and a reduce kernel. `KBatch` 1 and 2 are unchanged (`KBatch = 2` is already deterministic). Every other arch runs main's code path. The affected gfx950 tuned rows were re-measured on the new path and 167 changed config, so the fix costs nothing overall.

Validation and unverified scope

MI350X (gfx950, 256 CUs), base main adbb6ac8b, fresh JIT builds (module `.so` files and build dirs deleted), `GPU_ARCHS=gfx950`.

- **Op test:** `python3 op_tests/test_gemm_a8w8_blockscale.py` exits 0; all 9 `test_splitk_deterministic` cases report `mismatching calls=0/20, err=0`. On main the test fails at the first case (20/20 calls differ).
- **All 476 rows (436 affected + 40 controls)** through `aiter.gemm_a8w8_blockscale` with this branch's CSVs: 50 eager calls bitwise, plus CUDA-graph capture and 10 replays compared with eager: 0 nondeterministic rows, 0 graph-vs-eager mismatches, relerr 1.000x `splitK = 0` (FP64 reference) on every row.
- **Direct CK / CK-Tile calls,** BF16 and FP16, `splitK` 2/3/4, 50 calls: 0 mismatches, relerr equal to `splitK = 0`. CK-Tile with preshuffled B: 0/30 mismatches.
- **CUDA graphs and streams** (9 shapes): two graphs on two streams interleaved with eager calls, concurrent eager streams, and a fresh process whose first call is under capture (per-call counters): 0 mismatches.
- **Hy4-flash-FP8 linear shapes** (TP1/4/8, M in {1..300}), 50 calls: 0 of 240 cases nondeterministic (main: 36 of 50).
- **`KBatch = 2` adversarial test:** see Changes (0/5000 here and on main; positive control 1000/1000).
- **gfx942 cross-build:** `GPU_ARCHS=gfx942` JIT builds of `module_gemm_a8w8_blockscale` and `module_gemm_a8w8_blockscale_cktile` succeed. Per-kernel disassembly vs a gfx942 build of main: all 2753 CK and 5121 CK-Tile kernels of main are present with identical ISA. Extra kernels on gfx942: 784 fused kernels (`s_endpgm` only), 1376 never-launched FP32-output CK instantiations, and the CK-Tile partials/reduce kernels, which the runtime check never launches.
- **Tuned CSVs:** every changed row is gfx950/cu256 (189 rows, 167 with a new config); gfx942 rows identical to main.
- **CK-Tile workspace gate:** CK-Tile 32x128 kernel, `splitK = 2`: at 8192x8192x1024 the call allocates the 1 GB workspace; at 16384x8448x1024 (2.06 GB) it allocates none and matches `splitK = 0`. Passed 10 of 10 runs, together with 10 of 10 runs of the op test.
- **Lint:** `git clang-format` clean on the changed C++ lines; `black --check` and `ruff check` clean.
- **Perf:** 452-row benchmark, -4.4% geomean vs main (see Performance).
- **Merge with main (3a1324c13, main dd6beb98d):** no conflicts. Main adds `model_configs/a8w8_blockscale_tuned_gemm_qwen38_27b.csv` (#8016). It has 16 gfx950 CK rows with `splitK >= 2`. They now run the fused path. c3be5b813 re-timed them on it and moved 5 of them to a faster config.
- **MI300X (gfx942, 304 CUs) after the merge,** fresh `GPU_ARCHS=gfx942` JIT builds: `python op_tests/test_gemm_a8w8_blockscale.py -m 1 2 4 8 16 32 64 128 --ck_preshuffle False` exits 0 in 10 of 10 runs (ck and asm err 0 on every shape). The determinism checks are gfx950 only. In 3 of 10 runs, `test_splitk_correctness(m=4, n=512, k=16384, splitK=2)` warns: 1 of 2048 outputs differs from `splitK = 0` by 0.125. This is main's atomic path, which gfx942 keeps.

Unverified:
- **gfx942 / MI300X beyond the op test above.** The other evidence is code inspection plus identical gfx942 ISA. gfx942's 320 tuned `splitK >= 2` rows stay nondeterministic, as on main; a gfx942 port of the fused path and retune is a follow-up.
- **Exact-name gate:** a future gfx95x part falls back to the atomic path until both the runtime check and `__gfx950__` guard are extended.
- gfx950 128-CU parts (no split-K rows), FP16-output timing, CUDA-graph capture of the CK-Tile path (no tuned row uses it; checked eagerly), and vLLM end-to-end serving accuracy.

PR-specific question

1. **Behavior change and why the existing behavior is insufficient.** On gfx950, CK `KBatch` 4/8/16 partials are no longer added atomically into BF16/FP16 in arrival order; they are stored as FP32 and reduced in K order by the last workgroup of each tile. CK-Tile `KBatch > 2` gets the same through a reduce kernel. 167 gfx950 rows change config. The atomic path made outputs differ between identical calls and between eager and CUDA-graph replay (431/436 rows; vLLM Hy4 serving affected), with 1.9-3.0x the error of `splitK = 0`. Clamping `splitK <= 1` (#4581) is deterministic but +26.6% geomean with 1.48x error; the first revision's separate reduce kernel was +7.2%.
2. **Validation and unverified scope.** MI350X gfx950: op test (exit 0); 476 rows x 50 calls bitwise plus graph-vs-eager, 0 mismatches, relerr 1.000x; direct BF16/FP16 kernel calls; graphs, multi-stream and capture-first; Hy4 repro 0/240; 452-row benchmark -4.4% geomean. gfx942: cross-compiled with ISA identical to main for every main kernel; op test 10/10 on MI300X after the merge with main. Unmeasured: FP16 timing, CK-Tile under graph capture, vLLM end-to-end.
3. **Arch / dtype / shape boundaries.**
   - Fused CK path: gfx950 (`get_device_gfx() == "gfx950"`) and `KBatch` in {4, 8, 16} and wave64 and `KBatch * M * N * 4 <= INT32_MAX` and a v1/v3 kernel selection; output BF16/FP16 (the only generated `EDataType`s); `Y.stride(-1) == 1` (`TORCH_CHECK`).
   - CK-Tile partials path: gfx950 and `KBatch > 2` and `KBatch * M * N * 4 <= INT32_MAX`.
   - Everything else (any other arch, `KBatch` 1/2/>=32, wave32, other pipelines, huge workspace) runs main's `GemmInstance` invoker, which still checks `IsSupportedArgument`.
   - Invariant: the runtime check and the `__gfx950__` device guard use the same exact name, so no arch reaches an empty kernel; the `KBatch` test comes first, so `KBatch` 1/2 never query the arch. CSV changes are confined to `gfx950,256` rows that had `splitK >= 2`.
   - Other modules: CK bpreshuffle, asm and FlyDSL blockscale paths do not include these headers. `module_gemm_a8w8_blockscale_bpreshuffle_cktile` includes the CK-Tile header and gets the same gate; all its tuned rows use `splitK = 0`.
4. **Changed op tests.** `op_tests/test_gemm_a8w8_blockscale.py` adds `test_splitk_deterministic`; see below.

Changed op tests

`op_tests/test_gemm_a8w8_blockscale.py` adds `test_splitk_deterministic`, run on gfx950:
- Calls named split-K kernels 20 times on decode shapes and asserts bitwise-equal outputs and closeness to `splitK = 0`: CK v1 16x64x256, 16x128x256, 16x64x128 and CK v3 128x128 (fused path); CK-Tile 4-wave 32x128 and 8-wave 192x256 (partials path); `splitK` 2/3.
- Not redundant: `test_splitk_correctness` checks only closeness with default kernels, where the race does not show up even on main. The new test fails on main (20/20 calls differ). Kernels are named rather than taken from the CSV so the CK-Tile path stays covered now that no tuned gfx950 row selects it.

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.

@AndreasKaratzas
AndreasKaratzas marked this pull request as draft November 24, 2026 05:55
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]>
Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas and others added 4 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]>
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]>
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

Four commits pushed on top of 3a1324c: main merged, one bug of this PR fixed, 18 rows retuned. Measured on MI355X (gfx950, 256 CUs, ROCm 10, torch 2.13) against main 1c96e23.

Summary

The bug: captured graphs shared counters

The counter slot was keyed by stream. PyTorch captures every graph on one default capture stream, so every captured graph got the same slot. That is fine while graphs are replayed one after the other. Two graphs replayed at the same time on two streams corrupt each other's arrival counts.

  • Reproducer, now test_splitk_concurrent_graphs in op_tests/test_gemm_a8w8_blockscale.py: 16x34816x5120, splitK = 2, two graphs of 8 calls, each replayed 50 times from its own thread and stream.
    • Previous head: about 780 of 800 replayed outputs differ from eager (4 runs: 779 to 783). In one run 69 outputs had non-finite values. The graphs then stay wrong when replayed one at a time (800 of 800), because the counters never return to zero.
    • This head: 0 of 800 in 6 runs.
  • Fix. A counter region belongs to a stream or, under capture, to the capture (the id from hipStreamGetCaptureInfo, which is unique across capture streams). Regions are cut from 8 MB chunks that are zeroed once and never freed.
  • Chunks are added outside of capture. hipMalloc fails during capture and invalidates it. A chunk is added when less than half a chunk is free, or less than a whole chunk once the device has captured.
  • Fallback. A capture that finds no free space zeroes per-call counters. That is correct, but 1.6 to 3.6 us slower per call (+20% to +38% on 5 to 10 us rows). The whole-chunk rule is there to avoid it: with the half-chunk rule, 5 of 1886 captured calls fell back in a vLLM-like capture schedule run through the op (Qwen3-14B's layer shapes, 51 batch sizes, one eager run and then one graph per model piece for each size). With the whole-chunk rule none did.
  • Cost. None measured: the 434 rows whose config did not change are +0.03% (cold) and -0.06% (warm) against the previous head.
  • Memory. Qwen3-Next-80B through vLLM (51 batch sizes, piecewise and full graphs) ends with 4 chunks (32 MB) and no fallback. The limit is 32 chunks (256 MB) per device.

A framework that replays one graph at a time was never affected. Main's atomic path cannot fail this way.

Timing

aiter.gemm_a8w8_blockscale, BF16 out, each tree with its own tuned CSVs. All 452 gfx950/cu256 rows that use splitK >= 2 on main:

activations geomean vs main rows > +2% rows > +5% worst row
previous head, merged with main cold -4.2% 14 2 +8.6% (80x5120x8704)
previous head, merged with main warm -4.1% 13 2 +9.0% (80x5120x8704)
this head cold -4.4% 15 1 +5.2% (48x256x2048)
this head warm -4.3% 14 1 +5.4% (48x256x2048)
  • Counting a row if it is slower in either mode: 16 rows above +2% on the previous head, 18 on this one. The count at the 2% line does not go down. What improves is the tail and the average.
  • The 18 retuned rows are 5.8% (cold) and 4.6% (warm) faster than before. 80x5120x8704 goes from +9% to -18% vs main.
  • Controls are flat: 65 splitK = 1 rows +0.14% / -0.08% (cold / warm), 53 other tuned rows +0.05% / +0.05%.
  • Eager calls (300 calls in a row, wall time per call, 50-row sample): 13% to 15% faster than main, and no row is slower. A call is one launch where main has a memset and a launch.
Method
  • One worker process per tree on one GPU: main, the previous head merged with main, this head, the same two for [CK] [Perf] Deterministic slice-K a8w8 blockscale kernels for small-M gfx950 rows #8609, and a second main worker as A/A control. The workers take turns in rotating order.
  • Each sample is a HIP-graph replay of at least 240 calls over weights rotated past 400 MB, 11 samples per worker, row and mode.
  • "Cold" rotates the activations as well. "Warm" uses one activation buffer.
  • A row's change is the median over the rounds of worker time / main time. A row counts as slower only if it is slower than both main workers.
  • The 91 rows near the line were measured a second time with fresh processes and 15 samples.
  • A/A between the two main workers: median 0.4%, p90 1.7%, max 4.5%.
  • The retune timed CK ids 0-18 with splitK 0-4 on every row and kept a change only if the worse of the two modes improved by at least 0.5% in a six-worker run. Two-rounding configs (splitK = 1) were not used.
  • Three retuned rows trade one mode for the other. 80x5120x5120: cold +1.6% -> -1.1% vs main, warm -9.2% -> -1.6%. 2534x128x7168: cold about +2% -> 0%, warm -3.3% -> +1%. 240x2048x2048: -11.6% -> -18.7%, -21.9% -> -18.9%.
Rows still slower with this PR alone

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
48x256x2048 4.94 +5.0..+5.3% +5.1..+5.4% ck 16x64 splitK 3
32x4096x6144 11.41 +3.6..+3.8% +2.4..+3.9% ck 16x64 splitK 2
16x128x7168 8.13 +2.9..+5.0% +2.9..+4.8% ck 16x64 splitK 3
16x256x2048 4.63 +2.6..+5.1% +1.0..+3.9% ck 16x64 splitK 3
40x128x7168 8.25 +3.0..+3.2% +2.8..+3.3% ck 16x64 splitK 3
80x128x7168 8.30 +2.9..+3.5% +2.9..+3.4% ck 16x64 splitK 3
32x576x7168 8.57 +2.3..+2.6% +2.7..+2.8% ck 16x64 splitK 3
32x128x7168 8.36 +2.5..+3.4% +2.6..+3.1% ck 16x64 splitK 3
16x1024x2048 4.91 +2.4..+3.6% +1.8..+4.4% ck 16x64 splitK 3
32x2624x6144 9.23 +2.3..+3.4% +2.4..+2.8% ck 16x64 splitK 3
48x6144x4096 13.42 +1.9..+3.2% +2.4..+4.0% ck 64x64 splitK 2
24x4608x2048 7.22 +2.3..+2.5% +2.1..+2.5% ck 16x64 splitK 2
32x3072x6144 9.46 +2.0..+2.3% +1.6..+2.5% ck 16x64 splitK 3

Above +2% in one pass only: 8x256x2048, 8x2624x6144, 16x1024x6144, 16x2624x6144, 32x256x2048, 32x1536x6144, 32x5120x3072.

All of them run the fused path, and no other repeatable CK config was faster on them. The reason is a fixed cost. In a build with the steps switched off one at a time, 16x1024x6144 (CK 16x64x256, splitK = 3) takes 4.70 us when the kernel stops after the partial stores. Waiting for the stores adds 0.08 us, the arrival counter 0.57 us, and loading, adding and storing the 8 partials 1.08 us. That is 6.43 us against 6.16 us for main's memset and atomic adds. Letting only the first wave reduce was 14% to 26% slower on five such rows. #8609 moves 8 of these 13 rows to slice-K kernels.

Repeatability and accuracy

  • 577 tuned rows (the 452 affected ones, 65 splitK = 1 rows, 60 controls) 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 determinism cases 0 of 20, 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 (weight_block_size [128, 128]) on one MI355X through vLLM, in-process engine, temperature 0, 8 prompts x 64 tokens. 192 of its linear layers call aiter.gemm_a8w8_blockscale.

AITER tree calls that return different bits when repeated on the same inputs (eager run) distinct outputs in 5 identical warm calls, VLLM_ROCM_USE_AITER_MOE=0 same, default settings tokens/s, 32 prompts x 128 tokens (median of 7)
main 1c96e23 2304 of 4608 5 5 3252
this PR 0 of 4608 1 5 3204
this PR + #8609 0 of 4608 1 5 3188

Not covered

  • gfx942. Its 320 splitK >= 2 rows stay on the atomic path, and nothing was run on gfx942. To cover it, the fused kernel and the sc1 store specialization have to be compiled for gfx942 as well, the arch check widened, and the 320 rows timed again on MI300X.
  • FP16 output. The determinism tests cover BF16. FP16 runs tuned split-K rows without split-K.
  • Timing noise. The GPU and the host were shared with other jobs. Rows within about 1% of the 2% line move in and out of the list from pass to pass.

@demonsan

demonsan commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 3 review(s); expect to start in about 52 min. 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 #8541 — [CK] [Bugfix] Make a8w8 blockscale split-K deterministic

Review (advisory, not independently refuted): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 disabled the auto-run and no validation report was supplied, so the PR's own evidence (op test exit 0, 476 rows × 50 calls bitwise, 0/800 concurrent-graph replays, gfx942 ISA identical to main) is un-reproduced here
Perf (advisory): NOT RUN — REVIEW_AUTO_VALIDATE=0, so no stages.perf exists; the PR's own base-vs-head benchmark (452 rows, cold −4.4% / warm −4.3% geomean, worst row +5.4%, A/A control) is the only timing evidence
Size: 1379 lines / 12 files — over the review bar
Design (advisory): SPLIT — the natural seams: the deterministic split-K mechanism (the three csrc headers + gen_instances.py), the 189-row gfx950 retune (7 CSVs, data-only), and the op tests
Human: recommend yzhou103 review whether sc1 device-scope stores + s_waitcnt vmcnt(0) + a relaxed agent-scope atomic are a sufficient cross-XCD visibility argument for PR #8541's fused split-K reduction (the OPUS precedent is intra-XCD only), and whether the permanent 8–256 MB per-device counter arena is acceptable

⚠️ [verified] The PR changes the output bits of every gfx950 splitK ≥ 2 row and the default dispatch of 189 rows via aiter/configs/a8w8_blockscale_tuned_gemm.csv and the 6 model_configs CSVs — gemm_a8w8_blockscale is the op behind vLLM's AiterFp8BlockScaledMMKernel on every Hy4/Qwen/GLM FP8 linear layer — and the PR carries no review or sign-off from the path's owner yet. Reviewer must @-mention yzhou103 (top committer of csrc/ck_gemm_a8w8_blockscale, 12 commits) in a PR comment requesting explicit sign-off on the bits and dispatch change before merge, on top of CI.

📝 [verified] Every generated instance now also instantiates an FP32-output twin (gen_instances.py), growing module_gemm_a8w8_blockscale from 40 MB to 105 MB with 1376 never-launched FP32 instantiations and 784 empty fused kernels on gfx942 too, and the PR states build time was "not measured again for this revision" — every fresh JIT build on every arch pays this once. Author must measure and state the build-time delta for this revision.

3 finding(s) posted inline, on the lines they are about:

  • csrc/ck_gemm_a8w8_blockscale/include/gemm_a8w8_blockscale_splitk_reduce.cuh:296-304 — gemm_a8w8_blockscale_splitk_reduce.cuh:296-304 orders the fused reduction on sc1 device-scope stores +…
  • csrc/ck_gemm_a8w8_blockscale/include/gemm_a8w8_blockscale_cktile_common.cuh:445-452 — The CK-Tile partials branch (gemm_a8w8_blockscale_cktile_common.cuh:445-452) takes any k_batch > 2 with no…
  • csrc/ck_gemm_a8w8_blockscale/include/gemm_a8w8_blockscale_splitk_reduce.cuh:82-160 — gemm_a8w8_blockscale_splitk_reduce.cuh:82-160 hipMallocs an 8 MB counter chunk on the first fused call that…

Comment on lines +296 to +304
__builtin_amdgcn_s_waitcnt(0x0f70);
__syncthreads();
if(threadIdx.x == 0)
{
const uint32_t prev =
__hip_atomic_fetch_add(counter, 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT);
last[0] = prev == static_cast<uint32_t>(kbatch - 1);
if(last[0])
__hip_atomic_store(counter, 0u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT);

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] gemm_a8w8_blockscale_splitk_reduce.cuh:296-304 orders the fused reduction on sc1 device-scope stores + s_waitcnt vmcnt(0) + a RELAXED agent-scope atomic instead of a release/acquire pair, and the PR's support is measurement only — the merged OPUS split-K kernels (opus_gemm_pipeline_a8w8_mxscale_flatmm_splitk_gfx950.cuh:2455-2485) ship the same arrival-counter pattern but scoped intra-XCD with workgroup-scope atomics, so the cross-XCD extension has neither precedent nor a cited ISA/memory-model rule; if store completion at device scope is not in fact visible to another XCD's device-scope loads on some stepping or driver, the fused path returns silently nondeterministic bits — the exact defect this PR exists to fix. Author must cite the ISA/memory-model basis (or an AMD confirmation) for the cross-XCD case, or put the OPUS owners' derivation on record.

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, here's the basis. it's the code sequence table in LLVM AMDGPUUsage, "Memory Model GFX942" (https://llvm.org/docs/AMDGPUUsage.html#memory-model-gfx942). gfx950 gets the same sequences from the compiler, I checked both targets.

  • store atomic monotonic agent is global_store sc1=1 and load atomic monotonic agent is load sc1=1. so every partial store and every reducer load uses the agent-scope atomic encoding, which is coherent across the XCD L2s.
  • atomicrmw release agent is buffer_wbl2 sc1 + s_waitcnt vmcnt(0) + the atomic. the buffer_wbl2 only writes back plain stores that can sit dirty in one L2. here there are none: in the gfx950 build all 784 fused kernels have only sc1 stores before the counter atomic, no plain ones.
  • the acquire side adds buffer_inv sc1 after the atomic, which only protects later plain loads. the reducer only does sc1 loads.

to be clear, this follows from the mapping in that table. the doc does not say "sc1 stores + vmcnt(0) are a release" in words, and at the C++ level these are relaxed atomics. if you want the language-level guarantee, the fix is __ATOMIC_ACQ_REL on the counter fetch_add (that emits exactly the buffer_wbl2 sc1 / buffer_inv sc1 pair), but that wbl2/inv fence made the kernel 30% to 5x slower when I tried it. happy to switch if a CK or compiler owner prefers that.

Comment on lines +445 to +452
if(aiter_blockscale::use_splitk_partials(k_batch))
{
// Equal K ranges on plain B: run each batch as its own K=K/k_batch GEMM
// (k_batch=1 in the kernel, so the epilogue stores instead of adding).
// The batch index still comes from blockIdx.z. Otherwise the batches add
// into a zeroed slice, one writer per element.
const bool store_partials = !PreshuffleB && K % (k_batch * GemmInstance::K_Tile_v) == 0;
auto ws = aiter_blockscale::splitk_workspace(Y, k_batch, M, N, /*zeroed=*/!store_partials);

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] The CK-Tile partials branch (gemm_a8w8_blockscale_cktile_common.cuh:445-452) takes any k_batch > 2 with no workspace-size gate, unlike the CK fused path's KBatch×M×N×4 ≤ INT32_MAX check (gemm_a8w8_blockscale_common.cuh:406-408), so a direct cktile call with splitK ≥ 2 on a large shape would allocate KBatch×M×N×4 bytes per call (~4.8 GB at 32768×9216 with 4 batches) where main allocated nothing — an allocation failure on shapes the atomic path served; no tuned row reaches it (0 cktile splitK ≥ 2 rows remain), so only direct callers are exposed. Author must add the same size bound and fall back to the atomic path, or document the shape limit at the op.

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, added the same KBatch * M * N * 4 <= INT32_MAX gate on the CK-Tile partials branch. over it the call falls back to the atomic path, same as the CK side. checked 16384x8448 with splitK 2 (2.06 GB workspace): no workspace gets allocated and the output matches splitK 0.

Comment on lines +82 to +160
inline SplitKCounters splitk_counters(const torch::Tensor& Y, int64_t tiles, hipStream_t stream)
{
constexpr int64_t kMaxTiles = 4096;
constexpr int64_t kChunkTiles = 65536; // 8 MB
constexpr size_t kMaxChunks = 32;
struct Region
{
uint32_t* ptr = nullptr;
int64_t tiles = 0;
};
struct Chunk
{
uint32_t* ptr;
int64_t used;
};
struct Device
{
std::vector<Chunk> chunks;
// Keyed by stream handle and by capture id.
std::map<uint64_t, Region> streams;
std::map<uint64_t, Region> captures;
};
static std::mutex mu;
static std::map<int, Device> devices;

hipStreamCaptureStatus capture = hipStreamCaptureStatusNone;
unsigned long long capture_id = 0;
if(hipStreamGetCaptureInfo(stream, &capture, &capture_id) != hipSuccess)
{
(void)hipGetLastError();
}
else if(tiles <= kMaxTiles)
{
const bool capturing = capture != hipStreamCaptureStatusNone;
std::lock_guard<std::mutex> lock(mu);
Device& dev = devices[Y.get_device()];
const int64_t reserve = dev.captures.empty() ? kChunkTiles / 2 : kChunkTiles;
if(!capturing && dev.chunks.size() < kMaxChunks &&
(dev.chunks.empty() || kChunkTiles - dev.chunks.back().used < reserve))
{
const size_t bytes = kChunkTiles * kSplitKCounterStride * sizeof(uint32_t);
void* p = nullptr;
if(hipMalloc(&p, bytes) == hipSuccess &&
hipMemsetAsync(p, 0, bytes, stream) == hipSuccess &&
hipStreamSynchronize(stream) == hipSuccess)
{
dev.chunks.push_back({static_cast<uint32_t*>(p), 0});
}
else
{
(void)hipGetLastError();
(void)hipFree(p);
}
}
auto& regions = capturing ? dev.captures : dev.streams;
const uint64_t key = capturing ? capture_id : reinterpret_cast<uintptr_t>(stream);
const auto it = regions.find(key);
if(it != regions.end() && it->second.tiles >= tiles)
return {it->second.ptr, {}};
// A larger region replaces a smaller one, which stays reserved: launched
// kernels and captured nodes still point into it.
int64_t size = capturing ? 64 : 256;
while(size < tiles)
size *= 2;
for(Chunk& chunk : dev.chunks)
{
if(chunk.used + size <= kChunkTiles)
{
uint32_t* ptr = chunk.ptr + chunk.used * kSplitKCounterStride;
chunk.used += size;
regions[key] = {ptr, size};
return {ptr, {}};
}
}
}
auto holder = at::zeros({tiles * kSplitKCounterStride}, Y.options().dtype(at::kInt));
return {reinterpret_cast<uint32_t*>(holder.data_ptr<int32_t>()), holder};
}

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] gemm_a8w8_blockscale_splitk_reduce.cuh:82-160 hipMallocs an 8 MB counter chunk on the first fused call that is never freed (up to 32 chunks = 256 MB per device), hipStreamSynchronize's the calling stream whenever a chunk is added, and leaves replaced regions reserved forever — a permanent device-memory cost for any process that touches the op once, disclosed in the PR but signed off by no downstream. Reviewer should ask whether vLLM/SGLang deployments accept the permanent allocation.

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.

yeah, fair. it's 8 MB chunks per device, at most 32 (256 MB). in practice Qwen3-Next-80B through vLLM (51 batch sizes, piecewise and full graphs) ends with 4 chunks (32 MB) and no fallback. the stream sync only runs when a chunk is added, which is never under capture and at most 32 times per device. also fixed the stale arena text in the description.

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

Copy link
Copy Markdown
Contributor Author

@yzhou103 could you take a look and sign off on this one? two things need an owner's eye:

  • output bits and dispatch: on gfx950 every splitK >= 2 row now rounds once from an FP32 sum, and 189 gfx950 tuned rows change (167 move to another config, 22 only get new timings).
  • the cross-XCD argument for the fused reduction (sc1 stores and loads, s_waitcnt vmcnt(0), relaxed agent atomic): [CK] [Bugfix] Make a8w8 blockscale split-K deterministic #8541 (comment)

on the SPLIT advisory: the retune was timed on the new path, so the CSVs should land with it. without them the fused path would run configs that were picked for the atomic path. happy to split out the op tests if you prefer.

@demonsan

demonsan commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 4 review(s); expect to start in about 36 min. The box reviews up to 4 PRs at a time.

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the review pipeline itself (bot logic / prompts), not with this PR.

the worker did not finish within AITER_AGENT_TIMEOUT=2400s; the backend answered normally -- raise it in the runner .env

@zufayu — please take a look.

Re-comment @aiter-bot review once it is resolved.

zufayu added a commit that referenced this pull request Dec 4, 2026
…runcated watchdog read, size the agent timeouts for the 4-lane pool (#9201)

* [CI] review-bot: read WORK out of a binary fetch log, retry a stalled watchdog read, size the agent timeouts for the 4-lane pool

Three failure modes from the 2026-12-04 outage (6 failed runs, 01:24-03:02):

- run_one.sh extracted WORK= from the tee'd fetch log with a bare grep, so a PR
  with binary artifacts (OPUS .co blobs put NULs in that log) made grep answer
  "binary file matches" instead of the match -- a fetch that SUCCEEDED was
  reported as "fetch produced no WORK dir" on every retry (#8283/#7979/#7983).
  grep -a reads the log as text.

- watchdog.py caught only HTTPError, so a 30s socket timeout crashed the
  watchdog with a bare TimeoutError and failed a run whose review had already
  published a green card (#9178). A stalled GET is now retried (3 attempts,
  5s backoff); a POST is never retried, because a retried comment can land
  twice, and a failed POST degrades to 0, which the caller already warns about.

- AITER_AGENT_TIMEOUT=2400s was sized for one review at a time; the 4-lane
  pool serves four through the same GLM endpoint and workers measured 25-40+
  min under that load, so 2400s timed out live while the backend answered
  normally (#8983/#8541). Defaults now 3300s/agent and 6900s/run (115 min,
  still under the job's timeout-minutes of 120; check_prompts.py asserts it).

watchdog_test.py gains real-socket transport checks (the retry lives below the
_get/_post seam its fakes replace) with a mutation guard; _fetchfail_test.sh
gains the binary-log case. selftest: 156 green / 0 red.

Co-Authored-By: Claude Code <[email protected]>

* watchdog: retry a truncated response body, not just a stalled read

A response that dies mid-body raises http.client.IncompleteRead -- an
HTTPException, not an OSError -- so the OSError-only retry net added for
the 2026-12-04 stall let it escape unretried and unnamed: the same
bare-traceback crash one layer up, and _post's RuntimeError guard could
not degrade it either. Name the family in the catch so a truncated GET is
retried like a stalled one and a truncated POST degrades to 0.

Co-Authored-By: Claude Code <[email protected]>

---------

Co-authored-by: zufayu <[email protected]>
Co-authored-by: Claude Code <[email protected]>
@zufayu

zufayu commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 3 review(s); expect to start in about 39 min. The box reviews up to 4 PRs 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 #8541 — [CK] [Bugfix] Make a8w8 blockscale split-K deterministic

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 and this review box has no usable GPU (/dev/kfd permission denied, all 8 GPUs at 99% use); the target op_tests/test_gemm_a8w8_blockscale.py exists and CI's Aiter Test Gate passed on head 953f740 per the PR's self-review bot — an environment gap, not a PR defect
Perf (advisory): NOT RUN — no GPU access from this review box; the PR's own 452-row base-vs-head benchmark (-4.4% geomean, 18 rows >2% slower, worst +5.4% on 48x256x2048) is the PR's claim, not an independent measurement
Size: 1381 lines / 12 files — over the review bar
Design (advisory): SPLIT — the deterministic mechanism (fused kernel, sc1 store specialization, counter arena, CK-Tile partials path) can land first on the old configs; the 189-row CSV retune and the op-test additions stack on top of it
Human: recommend yzhou103 review the sc1-coherence-without-fence decision in PR #8541 — whether the FP32 partial stores through the specialized amd_buffer_store (sc1) plus s_waitcnt vmcnt(0) before a relaxed agent-scope counter RMW is a safe cross-XCD ordering on gfx950 without a release/acquire pair, and who owns that invariant if CK changes amd_buffer_store's store widths

⚠️ [verified] aiter/configs/a8w8_blockscale_tuned_gemm.csv and the six model_configs tables are the de-facto dispatch table of the widely-consumed aiter.gemm_a8w8_blockscale op — vLLM's AiterFp8BlockScaledMMKernel serves Hy4 through it on gfx950 — and this PR changes the selected kernel for 167 rows, the output bits of every splitK>=2 row, and commits up to 256 MB of never-freed counter memory per GPU; green CI covers only the models and shapes it knows. Author must obtain explicit sign-off from the path owner (yzhou103, top committer of csrc/ck_gemm_a8w8_blockscale) before merge.

4 finding(s) posted inline, on the lines they are about:

  • csrc/ck_gemm_a8w8_blockscale/include/gemm_a8w8_blockscale_common.cuh:173-191 — gemm_a8w8_blockscale_common.cuh:173-191 specializes only amd_buffer_store<float, {1,2,4,8}, DefaultCoherence>…
  • csrc/ck_gemm_a8w8_blockscale/include/gemm_a8w8_blockscale_cktile_common.cuh:453 — All four cktile cases in op_tests/test_gemm_a8w8_blockscale.py use K=3072 with splitK 2/3, which the K %…
  • csrc/ck_gemm_a8w8_blockscale/include/gemm_a8w8_blockscale_splitk_reduce.cuh:309-314 — gemm_a8w8_blockscale_splitk_reduce.cuh:309-314 ends splitk_tile_fixup with a bare else that assumes…
  • csrc/ck_gemm_a8w8_blockscale/gen_instances.py:121 — gen_instances.py:121 instantiates the FP32-output twin for every CK instance unconditionally, so gfx942 and…

Comment on lines +173 to +191
#define AITER_SPLITK_COHERENT_FLOAT_STORE(N) \
template <> \
__device__ void amd_buffer_store<float, N, AmdBufferCoherenceEnum::DefaultCoherence>( \
const typename vector_type_maker<float, N>::type::type src_thread_data, \
float* p_dst_wave, \
const index_t dst_thread_element_offset, \
const bool dst_thread_element_valid, \
const index_t dst_element_space_size) \
{ \
amd_buffer_store<float, N, kSplitKStoreCoherence>(src_thread_data, \
p_dst_wave, \
dst_thread_element_offset, \
dst_thread_element_valid, \
dst_element_space_size); \
}
AITER_SPLITK_COHERENT_FLOAT_STORE(1)
AITER_SPLITK_COHERENT_FLOAT_STORE(2)
AITER_SPLITK_COHERENT_FLOAT_STORE(4)
AITER_SPLITK_COHERENT_FLOAT_STORE(8)

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] gemm_a8w8_blockscale_common.cuh:173-191 specializes only amd_buffer_store<float, {1,2,4,8}, DefaultCoherence> to the sc1 (device-scope) store, and the fused path's correctness rests on that specialization plus s_waitcnt vmcnt(0) before the relaxed counter RMW — an ordering the PR's own text concedes the LLVM AMDGPUUsage table "does not state this shortcut as a rule"; a future CK epilogue that stores 16 floats per thread (today's instances top out at CBLOCK_SPV=8) would bypass the specialization with no signature change and no compile break, and the reducer would then read stale partials — wrong GEMM output, no error. Author must get the sc1 shortcut blessed by a memory-model owner (or move the counter to acq_rel) and make the width coverage un-bypassable — cover every N or static_assert the store width.

// (k_batch=1 in the kernel, so the epilogue stores instead of adding).
// The batch index still comes from blockIdx.z. Otherwise the batches add
// into a zeroed slice, one writer per element.
const bool store_partials = !PreshuffleB && K % (k_batch * GemmInstance::K_Tile_v) == 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] All four cktile cases in op_tests/test_gemm_a8w8_blockscale.py use K=3072 with splitK 2/3, which the K % (k_batch128)==0 test at gemm_a8w8_blockscale_cktile_common.cuh:453 routes to the store_partials branch — the zeroed-slice branch (PreshuffleB, or K not divisible by k_batchK_Tile), where batches atomically add FP32 into a zeroed workspace slice, is exercised by no committed test, and after the retune no tuned gfx950 row selects cktile, so CI never covers it either. Author must add one cktile case with PreshuffleB=True (or a non-divisible K) to test_splitk_deterministic.

Comment on lines +309 to +314
if(kbatch == 4)
splitk_sum_tile<4, TileM, TileN, BlockSize, IsBF16>(ws, out, ldo, M, N, m0, n0);
else if(kbatch == 8)
splitk_sum_tile<8, TileM, TileN, BlockSize, IsBF16>(ws, out, ldo, M, N, m0, n0);
else
splitk_sum_tile<16, TileM, TileN, BlockSize, IsBF16>(ws, out, ldo, M, N, m0, n0);

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] gemm_a8w8_blockscale_splitk_reduce.cuh:309-314 ends splitk_tile_fixup with a bare else that assumes kbatch==16 — extending use_splitk_fused to any other KBatch (e.g. 32, which the 2 GB workspace gate admits at small M,N) would make the last workgroup sum only 16 of 32 slices: wrong output, no error; the CK-Tile reduce kernel handles the same default explicitly at runtime. Author must make it else if(kbatch == 16) with an assert on the unreachable values.

ck::BlockGemmPipelineScheduler::{k.PIPELINE_Sched},
{instance_params}>;
// The same kernel with FP32 output, for the deterministic split-K partials.
using PartialsGemmInstance = DeviceLegacyGemmHelperF8BlockScale<

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] gen_instances.py:121 instantiates the FP32-output twin for every CK instance unconditionally, so gfx942 and every non-gfx950 arch compile 1376 never-launched instantiations — the PR measures +31% JIT build time (66.8s → 87.2s) and .so size 40 MB → 105 MB on archs that keep the nondeterministic path. Author must either guard the PartialsGemmInstance instantiation with gfx950 (the PartialsInstance=void default already supports it) or confirm the build-cost regression on gfx942 is accepted.

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