Skip to content

[FlyDSL] [Perf] Let the consumer finish a gfx1250 PTPC split-K GEMM - #7449

Merged
lirui927 merged 7 commits into
ROCm:mainfrom
lirui927:fuse/f2-splitk-consumer
Dec 2, 2026
Merged

lirui927 merged 7 commits into
ROCm:mainfrom
lirui927:fuse/f2-splitk-consumer

Conversation

@lirui927

@lirui927 lirui927 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Based on main, GEMM only, with no dependency on other PRs. The consumer side is separate: #8011 lets fused_qknorm_idxrqknorm take the partials (qkv_partials). ROCm/ATOM#2988 uses both.

What this PR does

At decode sizes (M ≤ 64 per rank), the tuned gfx1250 PTPC FP8 GEMM (gemm_a8w8_bpreshuffle, FlyDSL backend) splits K. A separate gemm_a8w8_splitk_reduce launch then sums the fp32 partials into bf16. That reduce moves very little data, so its cost is mostly the launch plus one store/reload round trip. This PR lets the kernel that reads the GEMM output do the reduction itself.

  • gemm_a8w8_bpreshuffle_splitk_deferred(...) runs the same tuned kernel but skips the reduce. It applies when the tuned row is the gfx1250 FlyDSL kernel with split 2/4/8, the operands are fp8 with bf16 output, K is unpadded and M ≤ max_m (default 64). Every other call goes through gemm_a8w8_bpreshuffle and its input checks and returns its output.
    • The returned bf16 tensor shares one allocation with the fp32 partials.
    • gemm_a8w8_bpreshuffle_splitk_partials(y) hands the partials to a consumer. The consumer sums them as the reduce kernel does (fp32, split order, one round to nearest even) and writes the reduced rows back, so it sees, and leaves behind, exactly what the two-kernel path produces.
    • gemm_a8w8_bpreshuffle_splitk_reduce(y) finishes y in place with the standalone reduce kernel, for a consumer that cannot take partials.
    • Any other view of a deferred output (a reshape, a column slice, a later row slice, a transpose) raises in gemm_a8w8_bpreshuffle_splitk_partials instead of reading as finished. When the 64-entry hand-off table is full, the oldest unclaimed output is finished with the standalone reduce (on the current stream; during graph capture this raises instead).
    • The deferred path and gemm_a8w8_bpreshuffle pick the kernel from the same tuned-row lookup (_bpreshuffle_config).
  • run_preshuffle_gemm_a8_gfx1250(..., partials=) (and run_gemm_a8w8_bpreshuffle_gfx1250) accepts a caller-provided partials buffer and leaves it unreduced; reduce_splitk_partials_gfx1250 launches the reduce on its own. Without that argument they behave as before.

Why the partials are implicit

gemm_a8w8_bpreshuffle_splitk_deferred returns one tensor and keeps the partials behind it (same allocation, found again by its address) instead of taking or returning a workspace. The reason is how ROCm/ATOM#2988 calls it:

  • ATOM traces the model once with torch.compile (its default, --level 3) and runs that graph for every batch size. LinearBase.forward runs the GEMM in it as an opaque torch_compile_guard op.
  • Whether a call defers, and with which split, is decided inside that op when it runs, from the tuned row for this M. One layer sees several outcomes: gate/up 6144 × 6144 is tuned to split 8 at M 1, 2, 4, 16 and 48, and to split 4 at M 8, 32 and 64.
  • Such a graph passes on tensors whose shapes follow from the input shapes. [M, N] does. A [split_k, M, N] tensor that may not exist would have a data-dependent shape, which no op in aiter or ATOM has today.

So the per-call facts (deferred or not, split count, where the partials are) travel beside the graph, keyed by the output's address, and ATOM's graph keeps carrying one tensor. An explicit form would have to carry more through that graph: partials with a data-dependent size, or a fixed-capacity workspace plus the split count. It is not part of this PR. The consumers already take the partials as an argument (qkv_partials in #8011), and a caller that picks the kernel itself has the explicit low-level form, run_gemm_a8w8_bpreshuffle_gfx1250(..., partials=).

What the caller has to know, as the docstring now states it. Nothing detects the first three:

  • y read before it is claimed is uninitialised memory.
  • A copy of an unclaimed y (clone(), float()) reads as finished. (A view other than the whole output or a leading row slice raises at the claim.)
  • A consumer outside the graph that captured the GEMM claims once; after every later replay it reads the values that claim left in y. perf(minimax-m3): reduce split-K QKV and gate/up partials in their consumers ATOM#2988 does not defer while a token graph records.
  • y's storage is the whole allocation, about (2 + 4·split_k)/2 times y (5x, 9x, 17x at split 2, 4, 8), for as long as y lives, claimed or not. Up to 64 unclaimed outputs stay listed, storage included.

Benefit

One MI455X, MiniMax-M3 TP4 decode GEMMs. 16 GEMMs with independent inputs are captured in one HIP graph; the number is the average per GEMM over replays, median of 5 rounds (a benchmark script outside this PR).

GEMM (N × K) M split GEMM + reduce (µs) deferred GEMM (µs) left to the consumer (µs)
sparse QKV (2560 × 6144) 1 4 5.36 3.73 1.63
sparse QKV (2560 × 6144) 16 4 5.83 3.85 1.98
sparse QKV (2560 × 6144) 64 8 6.53 4.14 2.39
dense QKV (2304 × 6144) 1 8 5.59 3.67 1.92
dense QKV (2304 × 6144) 16 8 5.78 3.62 2.17
dense QKV (2304 × 6144) 64 8 6.64 4.32 2.32
gate/up (6144 × 6144) 1 8 6.32 4.58 1.74
gate/up (6144 × 6144) 16 8 7.11 4.85 2.26
gate/up (6144 × 6144) 64 4 7.94 5.38 2.56

The deferred GEMM followed by gemm_a8w8_bpreshuffle_splitk_reduce takes as long as gemm_a8w8_bpreshuffle (within ±0.4 µs run to run), so the new path costs nothing by itself.

What a layer saves is the last column minus what the consumer spends on summing the partials. For fused_qknorm_idxrqknorm with #8011 that is 0.5 µs at 4 splits and 1.4–2.2 µs at 8 splits, so the MiniMax-M3 sparse attention layer saves about 1.5 µs at M 16, 0.7 µs at M 32 and 0.2 µs at M 64.

Why not a fused in-kernel split-K epilogue (_fsk)

I built a PTPC _fsk variant for the comparison (not in this PR): the split-K workgroups of a tile form one (1, 1, split_k) cluster and reduce in-kernel. Where the shared emit_fused_splitk_epilogue cannot take the tile (t16x64 and similar rows, where a split owns fewer rows than its row loop needs), a flat-indexed copy of it reduces instead, so every M3 decode row fits. It is bitwise equal to GEMM + reduce in all 155 checked cases (11 configs incl. split 2, 4 and 8, 3 shapes, M 1–64 with tails) and for each best config below. Per layer, on one MI455X: 16 layers with independent weights per HIP graph, µs per layer, median of 9 interleaved rounds (max-min spread ≤ 0.4 µs for (a) and (b), ≤ 0.95 µs for (c); one outlier round in (b) at sparse M 32). (b) is the fastest _fsk config per shape and M from a sweep over tile, tile_k, buffers, warps and split 2/4/8 (256 configs that fit in LDS). Consumers as in ROCm/ATOM#2988: sparse QKV → fused_qknorm_idxrqknorm insert mode (#8011), dense QKV → ATOM's triton_fused_norm_rope_cache, gate/up → ATOM's swiglu_oai_split; the KV caches are bf16. The script is outside this PR.

layer M tuned (c) best _fsk (b) (c) GEMM+reduce+consumer (a) deferred (b) _fsk a vs b
sparse QKV 2560x6144 1 t16x64x512 sk4 t16x64x512 mw1nw4 nb3 sk4 7.58 6.88 7.21 +0.33
sparse QKV 2560x6144 2 t16x64x512 sk4 t16x64x256 mw1nw2 nb3 sk8 7.83 6.67 7.24 +0.57
sparse QKV 2560x6144 4 t16x64x256 sk4 t16x64x256 mw1nw2 nb3 sk8 8.11 6.70 7.28 +0.58
sparse QKV 2560x6144 8 t16x64x512 sk4 t16x64x256 mw1nw2 nb3 sk8 8.11 6.95 7.27 +0.32
sparse QKV 2560x6144 16 t16x64x512 sk4 t16x64x256 mw1nw2 nb3 sk8 8.24 6.97 7.54 +0.57
sparse QKV 2560x6144 32 t64x128x256 sk8 t32x128x256 mw1nw2 nb3 sk8 8.93 8.05 8.33 +0.28
sparse QKV 2560x6144 48 t64x128x256 sk8 t16x128x512 mw1nw4 nb3 sk4 8.98 8.55 8.71 +0.17
sparse QKV 2560x6144 64 t64x128x256 sk8 t32x128x512 mw1nw4 nb3 sk4 9.44 8.74 8.73 -0.01
dense QKV 2304x6144 1 t32x128x256 sk8 t16x64x128 mw1nw4 nb4 sk8 7.53 7.21 6.90 -0.31
dense QKV 2304x6144 2 t16x64x512 sk4 t16x64x512 mw1nw4 nb3 sk4 7.79 6.82 6.94 +0.13
dense QKV 2304x6144 4 t16x64x512 sk4 t16x64x512 mw1nw2 nb3 sk4 7.87 7.11 6.94 -0.17
dense QKV 2304x6144 8 t16x64x512 sk4 t16x64x512 mw1nw2 nb3 sk4 8.30 7.20 7.31 +0.11
dense QKV 2304x6144 16 t16x128x256 sk8 t16x64x512 mw1nw4 nb3 sk4 8.61 7.33 7.54 +0.21
dense QKV 2304x6144 32 t32x64x256 sk8 t32x128x256 mw1nw4 nb3 sk8 8.76 7.74 8.22 +0.48
dense QKV 2304x6144 48 t64x128x256 sk8 t16x128x512 mw1nw4 nb3 sk4 9.40 8.06 8.97 +0.91
dense QKV 2304x6144 64 t128x128x256 sk8 t64x128x512 mw1nw4 nb3 sk4 10.09 8.70 9.42 +0.71
gate/up 6144x6144 1 t16x192x256 sk8 t16x64x256 mw1nw2 nb4 sk4 7.86 6.35 7.06 +0.72
gate/up 6144x6144 2 t16x64x256 sk8 t16x64x256 mw1nw2 nb4 sk4 8.12 6.51 7.13 +0.62
gate/up 6144x6144 4 t16x192x256 sk8 t16x64x256 mw1nw2 nb4 sk4 8.81 6.83 7.26 +0.43
gate/up 6144x6144 8 t16x128x512 sk4 t16x128x512 mw1nw4 nb3 sk4 8.05 6.45 7.61 +1.16
gate/up 6144x6144 16 t16x64x128 sk8 t16x128x512 mw1nw4 nb3 sk4 8.60 7.28 7.78 +0.49
gate/up 6144x6144 32 t32x128x256 sk4 t32x128x512 mw1nw4 nb3 sk4 9.30 7.26 8.27 +1.01
gate/up 6144x6144 48 t64x192x128 sk8 t64x128x256 mw1nw4 nb4 sk4 10.15 8.83 8.96 +0.12
gate/up 6144x6144 64 t64x128x512 sk4 t64x128x256 mw1nw4 nb4 sk4 9.71 8.21 9.09 +0.87

The deferred design is faster on 21 of 24 rows, by 0.1–1.2 µs per layer (median 0.5). _fsk wins only on dense QKV at M 1 and 4 (0.3 and 0.2 µs), and ties at sparse QKV M 64. Its in-kernel exchange (peer rows through L2 behind a cluster barrier, every split waiting for the slowest) costs more than the consumer spends summing the partials. So this PR keeps the deferred API.

Testing

GPU runs on one MI455X. The library files of the head (87a18c5) are those of 92397e7, the merge of main 4960107, where op_tests/test_gemm_a8w8_splitk_deferred.py passed on MI455X. 87a18c5 changes only that test's timed deferred candidate, which now claims the partials inside the timed call; the test has not been rerun on a GPU since. The test_gemm_a8w8.py --no-legacy sweep is from b6892c5, before the merge.

  • op_tests/test_gemm_a8w8_splitk_deferred.py (an aiter op test run as python3 <file>: one @benchmark sweep with a summary table of us / TFLOPS / TB/s / err per candidate): 21 GEMM cases, sparse QKV, dense QKV and gate/up at M 1–64, split 4 and 8. The deferred GEMM + reduce is bitwise equal to gemm_a8w8_bpreshuffle in every case, and every candidate is within 1% + 0.1 per element of an fp32 torch reference. It also checks the hand-off: the partials are handed out once, and gemm_a8w8_bpreshuffle_splitk_reduce claims them itself and returns a finished tensor as it is. It fails if no case actually splits K.
  • check_handoff_table in the same file runs on every arch, also under python3 <file>, so CI executes it: both FlyDSL launchers are stubbed and it checks claim-once, the leading-row-slice claim, that five other views raise, that eviction reduces the oldest output, and that off gfx1250 the deferred GEMM returns gemm_a8w8_bpreshuffle's output. Passes on MI455X, and on a GPU-less host with the arch set to gfx950 (AITER_AOT_REPLAY=1 GPU_ARCHS=gfx950; other cases skipped).
  • op_tests/test_gemm_a8w8.py --no-legacy runs every FlyDSL shape of the gfx1250 tuned bpreshuffle CSV through gemm_a8w8_bpreshuffle, whose split-K reduce now goes through the shared launcher. All 451 shapes pass. 177 are within atol/rtol 1e-2 of the fp32 reference; 274 have up to 2.4% of elements outside it from bf16 rounding (largest absolute difference 0.094). None fails the catastrophic check.
  • black and ruff pass.

Not covered

  • CI runs on MI300X/MI35X, where only the host-side hand-off test runs; the GPU cases are gfx1250 only.
  • No end-to-end accuracy A/B in this PR (perf(minimax-m3): reduce split-K QKV and gate/up partials in their consumers ATOM#2988 reports one).
  • The misuses listed under "Why the partials are implicit" are documented, not detected.
  • There is no public wrapper with a caller-owned workspace. Only the low-level partials= form is explicit.
  • The GPU sweep has not been rerun at the head: since the MI455X run at 92397e7 only the test's timed deferred candidate changed, so its us / TFLOPS / TB/s columns are not re-measured. test_gemm_a8w8.py --no-legacy was last run at b6892c5, before the merge of main.

PR Self-Review

Reviewed revision

87a18c5

Behavior and intent

  • Adds gemm_a8w8_bpreshuffle_splitk_deferred(...): for the gfx1250 FlyDSL PTPC FP8 GEMM with split 2/4/8, fp8 operands, bf16 output, unpadded K and M <= max_m (default 64), it skips the gemm_a8w8_splitk_reduce launch and leaves the fp32 partials for the consumer (gemm_a8w8_bpreshuffle_splitk_partials(y)), or finishes in place with gemm_a8w8_bpreshuffle_splitk_reduce(y). Every other call returns gemm_a8w8_bpreshuffle's output.
  • A claim through a wrong view fails loudly: any view of a deferred output other than the whole output or a leading row slice raises. Eviction from the 64-entry table finishes the evicted output with the standalone reduce (and raises during graph capture).
  • The deferred path shares the tuned-row lookup with _gemm_a8w8_bpreshuffle_into (_bpreshuffle_config).
  • run_preshuffle_gemm_a8_gfx1250 / run_gemm_a8w8_bpreshuffle_gfx1250 accept a caller partials= buffer; without it they behave as before.
  • The public wrapper keeps the partials behind the returned tensor (found by its address) instead of in a caller-owned workspace: perf(minimax-m3): reduce split-K QKV and gate/up partials in their consumers ATOM#2988 runs the GEMM as an opaque op in a graph traced once for every M, and whether a call defers, and with which split, is known only when that op runs, so a [split_k, M, N] tensor would have a data-dependent shape there. The docstring states this, the three misuses nothing detects (output read before its claim, copy of an unclaimed output, consumer outside the producer's graph) and the memory behind the output.
  • Why: at decode sizes the separate reduce is mostly launch cost plus a store/reload round trip; the per-GEMM table in the description shows 1.6-2.6 us left to the consumer vs GEMM + reduce on main's path. A fused in-kernel split-K epilogue (_fsk) was measured per layer on the M3 shapes and loses on 21 of 24 rows (table in the description), so the deferred API stays.

Validation and unverified scope

  • This revision (87a18c5) changes only op_tests/test_gemm_a8w8_splitk_deferred.py: the timed deferred candidate claims the partials inside the timed call (claimed(...), a host pop with no launch), so no output stays listed and none is evicted. Host trace with both FlyDSL launchers stubbed, 104 calls a shape over three shapes: the old candidate launched the standalone reduce in 40 of 104 calls on the first shape and 103 of 104 on the later ones, with 64 outputs left listed; the new one in 0 of 104, with none listed. check_handoff_table passes on the same host; black --check and ruff check pass on the file.
  • MI455X, one idle GPU, at 92397e7 (the parent; same library files), image rocm/fw-bringup:gfx1250-minimax-m3-20261112: python3 op_tests/test_gemm_a8w8_splitk_deferred.py exits 0; 21 shapes (sparse QKV, dense QKV, gate/up; M 1-64; split 4 or 8), three candidates each bitwise equal to gemm_a8w8_bpreshuffle and err 0 against the fp32 reference; the claim check and the hand-off check pass, through main's AOT cache launchers.
  • 92397e7 merges main 4960107. One conflict, in aiter/ops/flydsl/bpreshuffle_gemm_gfx1250.py: main's [FlyDSL] [gfx1250] Launch the GEMM and grouped-MoE kernels through the AOT cache #8678 launches the GEMM and the split-K reduce through the AOT cache launchers, so _launch_splitk_reduce takes splitk_reduce_launcher.lazy(split_k, out_dtype, "f32"), the call main's own reduce makes.
  • GPU-less host (AITER_AOT_REPLAY=1 GPU_ARCHS=gfx950 python3 op_tests/test_gemm_a8w8_splitk_deferred.py, aiter's native enum module stubbed): the hand-off check passes, then the sweep is skipped for the arch, exit 0; CI runs it this way on every arch.
  • MI455X at b6892c5 (before the merge of main): python3 op_tests/test_gemm_a8w8.py --no-legacy over all 451 FlyDSL shapes of the gfx1250 tuned CSV (reduce via the shared launcher): none fails; 177 within 1e-2, 274 with up to 2.4% of elements off by bf16 rounding (max 0.094).
  • MI455X at b6892c5, perf(minimax-m3): reduce split-K QKV and gate/up partials in their consumers ATOM#2988 at 8be91b11: python3 -m pytest -q tests/model_ops/test_splitk_consumer_reduce.py tests/model_ops/test_splitk_consumer_claims.py: 21 passed.
  • Unverified: the GPU sweep at this revision (the deferred candidate's timing columns are not re-measured); test_gemm_a8w8.py --no-legacy and the ATOM tests after the merge of main; CI GPU cases (MI300X/MI35X, where the GPU cases skip); a caller-owned workspace in ATOM's compiled graph (not built; only a CPU toy of the op boundary was run).
  • Known limits: an output read before its claim, a copy of an unclaimed output, and a consumer outside the producer's graph are documented, not detected; an unclaimed output is finished only once 64 are listed.

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

  • test_gemm_a8w8_splitk_deferred.py is new and calls APIs added here (gemm_a8w8_bpreshuffle_splitk_deferred, gemm_a8w8_bpreshuffle_splitk_partials, gemm_a8w8_bpreshuffle_splitk_reduce), so it cannot run before this PR.
  • It also fails if no case actually splits K, so a tuned-CSV change that disables split-K cannot make it pass vacuously.
  • test_gemm_a8w8.py checks the finished GEMM against an fp32 reference with tolerance; it never exposes unreduced partials or the claim/hand-off contract, and it does not check bitwise equality between the deferred and two-kernel paths.

Changed op tests

  • op_tests/test_gemm_a8w8_splitk_deferred.py (new)
    • Covers: deferred GEMM + reduce bitwise equal to gemm_a8w8_bpreshuffle on MiniMax-M3 decode shapes at split 4/8; partials handed out once; gemm_a8w8_bpreshuffle_splitk_reduce claims them itself and passes a finished tensor through unchanged; on every arch, the host-side hand-off table (rejected views raise, eviction reduces) and the off-gfx1250 fallback.
    • Before this PR: fails at import/call, since the deferred API does not exist.
    • Not redundant: no existing test covers the partials hand-off or bitwise parity of the deferred path; test_gemm_a8w8.py only checks finished outputs within tolerance.

@lirui927
lirui927 force-pushed the xiaobingsuper/m3-mi455-perf-stack branch from 2c8902d to 3499407 Compare November 10, 2026 07:46
@lirui927
lirui927 force-pushed the fuse/f2-splitk-consumer branch 2 times, most recently from 9ecd054 to 546a3e8 Compare November 12, 2026 05:08
@lirui927
lirui927 changed the base branch from xiaobingsuper/m3-mi455-perf-stack to main November 12, 2026 05:08
@lirui927
lirui927 force-pushed the fuse/f2-splitk-consumer branch from 49f0052 to 9f82222 Compare November 16, 2026 08:07
@lirui927
lirui927 marked this pull request as ready for review November 16, 2026 08:25
@lirui927
lirui927 requested a review from a team November 16, 2026 08:25
@github-actions github-actions Bot changed the title [Perf] Let the consumer finish a gfx1250 PTPC split-K GEMM [FlyDSL] [Perf] Let the consumer finish a gfx1250 PTPC split-K GEMM Nov 16, 2026
@aiter-bot

aiter-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 87a18c5f09ab · 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 `gemm_a8w8_bpreshuffle_splitk_deferred(...)`: for the gfx1250 FlyDSL PTPC FP8 GEMM with split 2/4/8, fp8 operands, bf16 output, unpadded K and M <= `max_m` (default 64), it skips the `gemm_a8w8_splitk_reduce` launch and leaves the fp32 partials for the consumer (`gemm_a8w8_bpreshuffle_splitk_partials(y)`), or finishes in place with `gemm_a8w8_bpreshuffle_splitk_reduce(y)`. Every other call returns `gemm_a8w8_bpreshuffle`'s output.
- A claim through a wrong view fails loudly: any view of a deferred output other than the whole output or a leading row slice raises. Eviction from the 64-entry table finishes the evicted output with the standalone reduce (and raises during graph capture).
- The deferred path shares the tuned-row lookup with `_gemm_a8w8_bpreshuffle_into` (`_bpreshuffle_config`).
- `run_preshuffle_gemm_a8_gfx1250` / `run_gemm_a8w8_bpreshuffle_gfx1250` accept a caller `partials=` buffer; without it they behave as before.
- The public wrapper keeps the partials behind the returned tensor (found by its address) instead of in a caller-owned workspace: ROCm/ATOM#2988 runs the GEMM as an opaque op in a graph traced once for every M, and whether a call defers, and with which split, is known only when that op runs, so a `[split_k, M, N]` tensor would have a data-dependent shape there. The docstring states this, the three misuses nothing detects (output read before its claim, copy of an unclaimed output, consumer outside the producer's graph) and the memory behind the output.
- Why: at decode sizes the separate reduce is mostly launch cost plus a store/reload round trip; the per-GEMM table in the description shows 1.6-2.6 us left to the consumer vs GEMM + reduce on main's path. A fused in-kernel split-K epilogue (`_fsk`) was measured per layer on the M3 shapes and loses on 21 of 24 rows (table in the description), so the deferred API stays.

Validation and unverified scope

- This revision (87a18c5f) changes only `op_tests/test_gemm_a8w8_splitk_deferred.py`: the timed `deferred` candidate claims the partials inside the timed call (`claimed(...)`, a host pop with no launch), so no output stays listed and none is evicted. Host trace with both FlyDSL launchers stubbed, 104 calls a shape over three shapes: the old candidate launched the standalone reduce in 40 of 104 calls on the first shape and 103 of 104 on the later ones, with 64 outputs left listed; the new one in 0 of 104, with none listed. `check_handoff_table` passes on the same host; `black --check` and `ruff check` pass on the file.
- MI455X, one idle GPU, at 92397e70 (the parent; same library files), image `rocm/fw-bringup:gfx1250-minimax-m3-20261112`: `python3 op_tests/test_gemm_a8w8_splitk_deferred.py` exits 0; 21 shapes (sparse QKV, dense QKV, gate/up; M 1-64; split 4 or 8), three candidates each bitwise equal to `gemm_a8w8_bpreshuffle` and err 0 against the fp32 reference; the claim check and the hand-off check pass, through main's AOT cache launchers.
- 92397e70 merges main 4960107e. One conflict, in `aiter/ops/flydsl/bpreshuffle_gemm_gfx1250.py`: main's #8678 launches the GEMM and the split-K reduce through the AOT cache launchers, so `_launch_splitk_reduce` takes `splitk_reduce_launcher.lazy(split_k, out_dtype, "f32")`, the call main's own reduce makes.
- GPU-less host (`AITER_AOT_REPLAY=1 GPU_ARCHS=gfx950 python3 op_tests/test_gemm_a8w8_splitk_deferred.py`, aiter's native enum module stubbed): the hand-off check passes, then the sweep is skipped for the arch, exit 0; CI runs it this way on every arch.
- MI455X at b6892c58 (before the merge of main): `python3 op_tests/test_gemm_a8w8.py --no-legacy` over all 451 FlyDSL shapes of the gfx1250 tuned CSV (reduce via the shared launcher): none fails; 177 within 1e-2, 274 with up to 2.4% of elements off by bf16 rounding (max 0.094).
- MI455X at b6892c58, ROCm/ATOM#2988 at 8be91b11: `python3 -m pytest -q tests/model_ops/test_splitk_consumer_reduce.py tests/model_ops/test_splitk_consumer_claims.py`: 21 passed.
- Unverified: the GPU sweep at this revision (the `deferred` candidate's timing columns are not re-measured); `test_gemm_a8w8.py --no-legacy` and the ATOM tests after the merge of main; CI GPU cases (MI300X/MI35X, where the GPU cases skip); a caller-owned workspace in ATOM's compiled graph (not built; only a CPU toy of the op boundary was run).
- Known limits: an output read before its claim, a copy of an unclaimed output, and a consumer outside the producer's graph are documented, not detected; an unclaimed output is finished only once 64 are listed.

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
- `test_gemm_a8w8_splitk_deferred.py` is new and calls APIs added here (`gemm_a8w8_bpreshuffle_splitk_deferred`, `gemm_a8w8_bpreshuffle_splitk_partials`, `gemm_a8w8_bpreshuffle_splitk_reduce`), so it cannot run before this PR.
- It also fails if no case actually splits K, so a tuned-CSV change that disables split-K cannot make it pass vacuously.
- `test_gemm_a8w8.py` checks the finished GEMM against an fp32 reference with tolerance; it never exposes unreduced partials or the claim/hand-off contract, and it does not check bitwise equality between the deferred and two-kernel paths.

Changed op tests

- `op_tests/test_gemm_a8w8_splitk_deferred.py` (new)
  - Covers: deferred GEMM + reduce bitwise equal to `gemm_a8w8_bpreshuffle` on MiniMax-M3 decode shapes at split 4/8; partials handed out once; `gemm_a8w8_bpreshuffle_splitk_reduce` claims them itself and passes a finished tensor through unchanged; on every arch, the host-side hand-off table (rejected views raise, eviction reduces) and the off-gfx1250 fallback.
  - Before this PR: fails at import/call, since the deferred API does not exist.
  - Not redundant: no existing test covers the partials hand-off or bitwise parity of the deferred path; `test_gemm_a8w8.py` only checks finished outputs within tolerance.

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.

lirui927 pushed a commit that referenced this pull request Nov 16, 2026
…ials as input (#8011)

Squash of #8011 at ea2cca7, by @lirui927.

#8011 brings the split-K partials consumer of 87a9321 (an earlier
#7449) to the optimized kernel, so the kernel and wrapper are
taken whole from #8011; the header and pybind already match.
@lirui927
lirui927 requested review from coderfeli and zufayu November 16, 2026 14:51
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 17, 2026
…heir consumers

With ROCm/aiter#7449, aiter.gemm_a8w8_bpreshuffle_splitk_deferred leaves the
fp32 partials unreduced when the tuned gfx1250 PTPC GEMM splits K and M is at
most max_m; the consumer claims them (aiter.splitk_partials) and reduces them
as it reads the output.

- LinearBase.splitk_consumer_max_m (0 = off) routes the per-token FP8
  bpreshuffle GEMM through it. Not while a token graph records: its replay
  would run the consumer, an eager region, without the partials.
- MiniMax-M3 sets it on gfx1250 to ATOM_SPLITK_CONSUMER_REDUCE_MAX_M
  (default 64, 0 = off) for the QKV projections whose attention impl claims
  the partials in rope_cache (not under Ulysses SP, whose head exchange reads
  qkv first) and for the dense MLP's gate/up.
- PagedAttentionImpl.rope_cache hands them to triton_fused_norm_rope_cache;
  SparseMHAPagedAttentionImpl.rope_cache to aiter.fused_qknorm_idxrqknorm
  (qkv_partials, ROCm/aiter#8011) when that op takes them: the index branch
  runs, no fp4 cache, and an aiter with the argument. Every other path
  finishes qkv with the standalone reduce first. A dummy run releases them.
- swiglu_oai_split_reducing, an opaque op, claims a gate/up's partials at run
  time and reduces them in the activation kernel.

An aiter without #7449 never defers; one with #7449 but without #8011 defers
and reduces in the sparse layers with the standalone kernel, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zufayu

zufayu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Review routing reminder: @aoli26 is the primary reviewer for the FlyDSL GEMM scope on this PR, with @coderfeli as backup. Please route the next technical review/action to the component owner; CI status remains a separate merge gate.

lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 17, 2026
…er decide

Drop the aiter probes: the try-import of the deferred GEMM API and the
inspect.signature check for fused_qknorm_idxrqknorm's qkv_partials. ATOM
needs aiter with ROCm/aiter#7449 and #8011 (docs/environment_variables.md).

Stop restating aiter's rules: the sparse rope_cache passes qkv's partials to
fused_qknorm_idxrqknorm in every mode (the op reduces them itself where it
cannot fuse them), and the gfx1250 gate goes: the deferred GEMM decides per
call, arch included, whether it defers. Only ATOM's own Triton kernel path
still reduces first.

claims_splitk_partials is opt-in per class: PagedAttentionImpl and
SparseMHAPagedAttentionImpl set it, a subclass does not inherit it. The
model checks ATOM's own attention layer and impl by type instead of getattr
defaults. The env doc names both deferred GEMMs (QKV and the dense MLP
gate/up into SwiGLU-OAI).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zufayu
zufayu requested a review from aoli26 November 17, 2026 07:49

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (3)

  1. Make a missed claim fail loudly instead of returning the "already reduced" None. aiter/ops/gemm_op_a8w8.py splitk_partials (~L1053-1067) returns None both for "y holds its values" and for a still-deferred y it does not recognise: a reshaped view (y.view(m, h, d)), a column slice, a non-leading row slice, or an entry pushed out of the 64-entry table (~L1041). The consumer then reads unwritten bf16, and reduce_splitk_partials(y) returns y unwritten too. A CPU run of the PR's own code reproduces all four cases. Fix: when the address/storage matches a live entry but the view check fails, raise. On eviction, launch the standalone reduce for the evicted entry (or raise); do not drop it silently.
  2. Share the kernel selection with _gemm_a8w8_bpreshuffle_into instead of re-deriving it in _splitk_deferrable. _splitk_deferrable (~L979) re-implements the config lookup, the libtype check and the arch gate, and the deferred path also skips gemm_a8w8_bpreshuffle's input asserts (e.g. WQ.dtype == fp8). Main has already changed that dispatch since this branch's base (INT8 bpreshuffle), so the two copies can drift and break the "bitwise equal" promise. Fix: factor one (config, kernelName) resolver and call it from both paths.
  3. Add a CPU test of the hand-off table that CI actually runs. op_tests/test_gemm_a8w8_splitk_deferred.py skips everywhere except gfx1250, so CI (MI300X/MI35X) never executes any of the new logic. The table is pure host code. Fix: stub the two launchers and cover claim-once, the leading-row-slice claim, the rejected views (they should raise after item 1) and eviction.

Minor (non-blocking):

  • _SPLITK_DEFERRED.pop(Y.data_ptr(), None) in the non-deferred branch is dead code. A live entry holds its allocation, so a fresh Y can never land on that address.
  • The eviction while can be an if.
  • The comment "its address cannot be handed out again until the consumer claims it" ignores eviction.
  • The test docstring says "Every check is bitwise", but the err column is an allclose check against the fp32 reference.

Reviewed at 9f82222. CI: 30 pass, 33 skipped, 0 failing (the new test skips on CI archs).

@aoli26

aoli26 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

gemm_a8w8_256x256_gfx1250.py already has a cluster-based fused split-K epilogue (_fsk) that reduces in-kernel, so the output is final with no extra launch and no caller hand-off. Have you tried extending that to the PTPC kernel? For decode shapes (M ≤ 64, split 2/4/8) the cluster constraints look satisfiable, and it would avoid the deferred path's caveats (unclaimed outputs reading uninitialized data, 64-entry eviction, extra memory pinned, eager-only).
If you hit a blocker, could you note it in the PR? A comparison against a fused PTPC variant on the MiniMax-M3 shapes would also help justify the added complexity.

@lirui927
lirui927 force-pushed the fuse/f2-splitk-consumer branch from 9f82222 to 6bd1332 Compare November 18, 2026 03:27
@lirui927

Copy link
Copy Markdown
Contributor Author

@valarLip thanks, all three are addressed in 6bd1332 (rebased on current main):

  1. Missed claim fails loudly. The hand-off table is now keyed by the allocation, so splitk_partials finds any view of a deferred output. The whole output or a leading row slice claims as before. A reshape, a column slice, a later row slice or a transpose now raises ValueError (and reduce_splitk_partials raises with it) instead of returning None. When the table is full, the oldest unclaimed output is finished with the standalone reduce before it is dropped, so it never stays unwritten. The minor items are done too: the dead pop in the non-deferred branch is gone, the eviction while is an if, the table comment covers eviction, and the test docstring separates the bitwise checks from the allclose err column.
  2. Shared kernel selection. _bpreshuffle_config(XQ, WQ) is now the only tuned-row lookup; _gemm_a8w8_bpreshuffle_into and _splitk_deferrable both call it. On top of that row, the deferred path only checks that it is a gfx1250 FlyDSL row with split 2/4/8. It defers only fp8 XQ/WQ with bf16 output and an unpadded K. Every other call, including any input gemm_a8w8_bpreshuffle would reject, goes through gemm_a8w8_bpreshuffle and its asserts. The arch half of the gate is now a public query, gemm_a8w8_bpreshuffle_splitk_deferred_supports_arch(), so perf(minimax-m3): reduce split-K QKV and gate/up partials in their consumers ATOM#2988 asks aiter whether to wire the deferred path instead of copying the gfx1250 check.
  3. CPU test that CI runs. test_handoff_table in op_tests/test_gemm_a8w8_splitk_deferred.py stubs run_gemm_a8w8_bpreshuffle_gfx1250 and reduce_splitk_partials_gfx1250. It covers claim-once, the leading-row-slice claim, five rejected views (each must raise), eviction (the evicted output is reduced; the 64 newer ones can still be claimed) and the supports_arch query. It has no arch skip, and main() runs it before the gfx1250 early exit, so CI runs it under both python3 <file> and pytest. It passes on CPU and fails if either fix is reverted.

GPU rerun at 6bd1332 on one MI455X:

  • test_gemm_a8w8_splitk_deferred.py: all 21 GEMM cases (sparse QKV, dense QKV and gate/up, M 1–64, split 4 and 8) bitwise equal to gemm_a8w8_bpreshuffle; pytest 5 passed.
  • test_gemm_a8w8.py --no-legacy: all 451 FlyDSL shapes pass, as before.

@lirui927

Copy link
Copy Markdown
Contributor Author

@aoli26 good question. I had not tried _fsk on the PTPC kernel. Here is what I found in the code; nothing below is measured yet.

What fits.

  • The PTPC kernel (gemm_a8w8_gfx1250.py) applies the per-token/per-channel scales in registers before the fp32 tile is staged in LDS, so the reduction is a plain fp32 sum and the scales are not a blocker.
  • Its split-K grid is already (gx, gy, split_k), so a (cluster_m, cluster_n, split_k) cluster (≤ 16 workgroups) works as in the 256x256 kernel.
  • The C staging area (tile_m * tile_n * 4 B, 4 KB at 16x64) has room for the rotated local stripe.
  • emit_fused_splitk_epilogue sums in fp32 in split order, like gemm_a8w8_splitk_reduce, so bitwise parity with the two-kernel path is plausible. It needs a GPU run to confirm.

The blocker for the decode configs. The shared epilogue splits a tile by rows: each split reduces tile_m / split_k rows and needs at least block / (tile_n / 4) of them. The a4w4 launcher states this as tile_m // split_k >= m_warp * n_warp * 128 // tile_n. Most M3 decode rows at M ≤ 32 in a8w8_bpreshuffle_tuned_gemm_minimax_m3.csv fail it:

GEMM (N × K) M tuned tile, split rows per split needed
sparse QKV (2560 × 6144) 1, 2, 4, 8, 16 t16x64, sk4 4 8
dense QKV (2304 × 6144) 2, 4, 8 t16x64, sk4 4 8
dense QKV 16 t16x128, sk8 2 4
dense QKV 32 t32x64, sk8 4 8
gate/up (6144 × 6144) 2, 16 t16x64, sk8 2 8

These are the rows where the deferred path gains the most. Every other M3 decode row passes: the t32x128 and larger tiles, t16x128 sk4 (gate/up M 8), and the tile_n 192 rows (gate/up M 1, 4 and 48). No current _fsk user runs tile_n 192, so those would need checking. I see two ways past the blocker:

  • generalise the epilogue to split the flat tile (at tile_n < 128 the LDS tile has no padding) instead of rows. This touches code shared with the MX and a4w4 kernels, whose ISA would have to stay identical;
  • tune over _fsk-eligible configs only (e.g. t16x128 sk4, or 2-wave t16x64 sk4), which halves the workgroup count at these M.

What the fused epilogue would buy. It removes the second launch, which is the deferred design's whole gain, and it also removes the deferred caveats you list (unclaimed outputs, eviction, pinned memory, eager-only hand-off). It further avoids the cost the deferred path pays in the consumer, which reads split_k fp32 rows instead of one bf16 row: fused_qknorm_idxrqknorm with #8011 spends 0.5 µs on that at split 4 and 1.4–2.2 µs at split 8. And it would help every split-K GEMM whose consumer cannot take partials: in aiter only fused_qknorm_idxrqknorm (#8011) can, and gate/up relies on a Triton SwiGLU in ATOM to do it. What it costs instead is the in-kernel exchange: peer rows go through L2 behind a cluster barrier, and all splits of a tile wait for the slowest one. If that exchange costs less than what the consumer pays, _fsk is the better design.

Measurement. One MI455X, the same HIP-graph harness as the PR table (16 independent GEMMs per graph, average per GEMM, median of 5 rounds), on the M3 TP4 decode shapes 2560×6144, 2304×6144 and 6144×6144 at M 1, 2, 4, 8, 16, 32, 48, 64:

  • (a) main: GEMM + reduce;
  • (b) a PTPC _fsk variant, best over the eligible configs (plus the generalised epilogue if it loses only on the t16x64 rows), also checked bitwise against (a);
  • (c) this PR: deferred GEMM plus the consumer's extra time (fused_qknorm_idxrqknorm with qkv_partials minus the same kernel on bf16).

Compared per layer: GEMM→qknorm for QKV, GEMM→SwiGLU for gate/up. I will post the numbers here. If (b) ≤ (c) on the decode rows, I will replace the deferred API with a PTPC _fsk variant. Until then the PR stays as it is (6bd1332).

@lirui927
lirui927 requested a review from valarLip November 18, 2026 03:27

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (2)

  1. Post the _fsk comparison @aoli26 asked for, and settle the design before this public API lands. You plan to replace the deferred API with a PTPC _fsk variant if (b) ≤ (c) on the decode rows (comment of 2026-11-18). Until those numbers are in, merging would ship four top-level names (aiter.splitk_partials, aiter.reduce_splitk_partials, gemm_a8w8_bpreshuffle_splitk_deferred[_supports_arch]) plus a global hand-off table that may be deleted shortly after, and ROCm/ATOM#2988 would be built on them. Fix: post (a)/(b)/(c) per layer on the M3 shapes here. Keep this design only if the fused epilogue loses or cannot fit the t16x64 rows, and say so in the PR body.
  2. Fix the two docstrings that contradict the code. aiter/ops/gemm_op_a8w8.py gemm_a8w8_bpreshuffle_splitk_deferred: "Eager only" followed by "a graph must capture producer and consumer together". Graph capture of both together is the intended ATOM use, so drop "Eager only" and state that constraint instead. _splitk_deferrable: says "split_k > 1", but the code defers only split_k in (2, 4, 8).

Minor (non-blocking):

  • splitk_partials / reduce_splitk_partials land at top level through import * with names that read as generic, but they only apply to deferred bpreshuffle outputs. Consider a gemm_a8w8_bpreshuffle_ prefix.
  • The eviction reduce runs on the current stream, not the stream of the evicted GEMM. That is only a hazard for an unclaimed output produced on a side stream.
  • bpreshuffle_gemm_gfx1250.py reduce_splitk_partials_gfx1250: tuple(...) around the torch.Size comparison is redundant.

Re-reviewed at 6bd1332. Already fixed: a missed claim now raises for views and eviction reduces (1), the shared _bpreshuffle_config resolver (2), and the CPU test_handoff_table that main() runs on every arch (3). All four minors are done too. CI: 16 pass, 25 skipped, 1 wheel build pending; the op-test run has not happened yet at this head.

lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 23, 2026
…heir consumers

With ROCm/aiter#7449, aiter.gemm_a8w8_bpreshuffle_splitk_deferred leaves the
fp32 partials unreduced when the tuned gfx1250 PTPC GEMM splits K and M is at
most max_m; the consumer claims them (aiter.splitk_partials) and reduces them
as it reads the output.

- LinearBase.splitk_consumer_max_m (0 = off) routes the per-token FP8
  bpreshuffle GEMM through it. Not while a token graph records: its replay
  would run the consumer, an eager region, without the partials.
- MiniMax-M3 sets it on gfx1250 to ATOM_SPLITK_CONSUMER_REDUCE_MAX_M
  (default 64, 0 = off) for the QKV projections whose attention impl claims
  the partials in rope_cache (not under Ulysses SP, whose head exchange reads
  qkv first) and for the dense MLP's gate/up.
- PagedAttentionImpl.rope_cache hands them to triton_fused_norm_rope_cache;
  SparseMHAPagedAttentionImpl.rope_cache to aiter.fused_qknorm_idxrqknorm
  (qkv_partials, ROCm/aiter#8011) when that op takes them: the index branch
  runs, no fp4 cache, and an aiter with the argument. Every other path
  finishes qkv with the standalone reduce first. A dummy run releases them.
- swiglu_oai_split_reducing, an opaque op, claims a gate/up's partials at run
  time and reduces them in the activation kernel.

An aiter without #7449 never defers; one with #7449 but without #8011 defers
and reduces in the sparse layers with the standalone kernel, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lirui927 pushed a commit to lirui927/ATOM that referenced this pull request Nov 23, 2026
…er decide

Drop the aiter probes: the try-import of the deferred GEMM API and the
inspect.signature check for fused_qknorm_idxrqknorm's qkv_partials. ATOM
needs aiter with ROCm/aiter#7449 and #8011 (docs/environment_variables.md).

Stop restating aiter's rules: the sparse rope_cache passes qkv's partials to
fused_qknorm_idxrqknorm in every mode (the op reduces them itself where it
cannot fuse them), and the gfx1250 gate goes: the deferred GEMM decides per
call, arch included, whether it defers. Only ATOM's own Triton kernel path
still reduces first.

claims_splitk_partials is opt-in per class: PagedAttentionImpl and
SparseMHAPagedAttentionImpl set it, a subclass does not inherit it. The
model checks ATOM's own attention layer and impl by type instead of getattr
defaults. The env doc names both deferred GEMMs (QKV and the dense MLP
gate/up into SwiGLU-OAI).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lirui927
lirui927 force-pushed the fuse/f2-splitk-consumer branch from 6bd1332 to b6892c5 Compare November 23, 2026 09:14
@lirui927
lirui927 requested a review from valarLip November 25, 2026 07:10
aoli26
aoli26 previously approved these changes Nov 25, 2026

@aoli26 aoli26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the detailed reply and the docstring/body updates. LGTM now.

lirui927 and others added 4 commits November 25, 2026 11:17
At decode sizes the tuned gfx1250 PTPC GEMM splits K (MiniMax-M3 TP4 sparse
QKV, M16 x N2560 x K6144: 40 output tiles on 256 CUs, split 4), and a second
kernel sums the fp32 partials into bf16. That reduce reads 0.7 MB and costs a
fixed ~1.3 us per launch in a HIP graph from 46 KB to 2.9 MB (1.7 us of the
GEMM + reduce pair at M16), 57 times per M3 decode step.

gemm_a8w8_bpreshuffle_splitk_deferred runs the same tuned kernel but, when it
splits K (split 2/4/8, M <= max_m, gfx1250), leaves the partials unreduced in
the allocation of the bf16 output it returns. A consumer claims them with
splitk_partials() and sums them as gemm_a8w8_splitk_reduce does (fp32, split
order, one round to nearest even), writing the reduced row back, so it sees
and leaves behind exactly what the two-kernel path produces.
reduce_splitk_partials() finishes the output with the standalone kernel for a
consumer that cannot. Every other call returns gemm_a8w8_bpreshuffle's output.

run_preshuffle_gemm_a8_gfx1250 and run_gemm_a8w8_bpreshuffle_gfx1250 take a
caller's partials buffer (partials=) and then skip the reduce, which
reduce_splitk_partials_gfx1250 launches on its own. Without partials= they
behave as before.

op_tests/test_gemm_a8w8_splitk_deferred.py checks the deferred GEMM + reduce
bitwise against gemm_a8w8_bpreshuffle at the M3 TP4 decode shapes, M 1..64
(sparse QKV, dense QKV, dense gate/up), and the hand-off rules.

Signed-off-by: lirui927 <[email protected]>
Co-authored-by: Cursor <[email protected]>
…ookup

splitk_partials now looks a tensor up by its allocation, so any view of a
deferred output is found: the whole output or a leading row slice claims the
partials as before, and any other view (a reshape, a column slice, a later row
slice) raises instead of reading as an output that already holds its values.
When the 64-entry table is full, the oldest unclaimed output is finished with
the standalone reduce instead of being dropped unwritten.

_bpreshuffle_config is the tuned-row lookup _gemm_a8w8_bpreshuffle_into
dispatches on; the deferred path uses it instead of its own copy, and only takes
fp8 operands with a bf16 output, so every other call goes through
gemm_a8w8_bpreshuffle and its input checks. Drop the dead table pop in the
non-deferred branch.

op_tests/test_gemm_a8w8_splitk_deferred.py gains a host-only test of the
hand-off table with both FlyDSL launchers stubbed (claim once, leading row
slice, rejected views, eviction), which runs on every arch, also as
`python3 <file>`; the GPU tests stay gfx1250 only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
splitk_partials and reduce_splitk_partials apply to deferred
gemm_a8w8_bpreshuffle outputs only, so they are now
gemm_a8w8_bpreshuffle_splitk_partials and
gemm_a8w8_bpreshuffle_splitk_reduce, next to
gemm_a8w8_bpreshuffle_splitk_deferred.

gemm_a8w8_bpreshuffle_splitk_deferred no longer says "Eager only": it
states the graph-capture constraint instead (capture the producer and its
consumer, or the reduce, in the same graph). _splitk_deferrable says
split_k in (2, 4, 8), as the code checks. The table comment says that an
eviction reduce runs on the stream current at the eviction. The
reduce_splitk_partials_gfx1250 shape check compares torch.Size directly.
An eviction during graph capture raises instead of recording a reduce into
an allocation the table then drops. gemm_a8w8_bpreshuffle_splitk_partials
notes that a copy of a deferred output is not recognised.

test_handoff_table also checks that off gfx1250 the deferred GEMM returns
gemm_a8w8_bpreshuffle's output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t know

gemm_a8w8_bpreshuffle_splitk_deferred's docstring now states:

- why the partials sit behind the returned tensor instead of in a second
  one: whether a call defers, and with which split_k, is known only when it
  runs (the tuned row for this M). A caller that traces its model once for
  every M and runs the GEMM as an opaque op of that graph (torch.compile, as
  ATOM's LinearBase does) can pass on the output, whose shape follows from
  the input shapes; a [split_k, M, N] tensor that may not exist would need a
  data-dependent shape there. The explicit form stays ``partials=`` of
  run_gemm_a8w8_bpreshuffle_gfx1250;
- the misuses nothing detects: an output read before it is claimed
  (uninitialised memory), a copy of an unclaimed output (clone, cast), which
  reads as finished, and a consumer outside the producer's graph, which
  claims once and after every later replay reads the values that claim left;
- the memory: the output's storage is the whole allocation, about
  (2 + 4 * split_k) / 2 times its own size (9x at split 4), for as long as
  the output lives, claimed or not, and up to 64 unclaimed outputs stay
  listed with theirs.

Docstrings only (gemm_a8w8_bpreshuffle_splitk_partials' is re-wrapped, same
words); no code change.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@lirui927
lirui927 force-pushed the fuse/f2-splitk-consumer branch from 97f5332 to ed0119b Compare November 25, 2026 11:19
One @benchmark function, test_gemm_a8w8_splitk_deferred(m, n, k), with a candidate loop that records us, TFLOPS, TB/s and err for each candidate and asserts both the bitwise match with gemm_a8w8_bpreshuffle and the fp32 torch reference (run_torch); one -s/--mnk sweep and one summary table. The claim and hand-off checks are plain functions that main() calls, so the file needs no pytest: CI runs it as python3 <file>, where the hand-off check runs on every arch.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
coderfeli
coderfeli previously approved these changes Nov 27, 2026
@lirui927

Copy link
Copy Markdown
Contributor Author

@valarLip could you take another look? Your review of 2026-11-24 left one item open, the reply to aoli26 on the API form, with approval once aoli26 was satisfied.

  • The reply and the docstring/description changes went in on 2026-11-25 (97f5332): why the partials stay implicit, and the three cases you listed (a read before the claim, a copy of y, the storage y keeps until it is claimed).
  • aoli26 approved after that; coderfeli approved the current head.
  • Since then the branch was rebased onto main (no change to the PR's lines), and 8799f95 reshapes only the test file to the op-test layout; it passes on MI455X (21 shapes, bitwise equal to gemm_a8w8_bpreshuffle).

…umer

main (ROCm#8678) launches the GEMM and the split-K reduce through the AOT cache launchers; _launch_splitk_reduce takes splitk_reduce_launcher the same way.

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

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (2)

Thanks for the merge and the op-test reshape. Prior asks: all fixed at this head. That covers:

  • the loud missed claim and the eviction reduce (gemm_op_a8w8.py:1316-1331, :1293-1301);
  • the shared _bpreshuffle_config (:1103, :1217);
  • the CI-run host test, which ran and passed at this head on MI35X shard 4;
  • the _fsk comparison and the docstrings;
  • the reply to @aoli26, with the misuse cases and the memory cost now in the docstring (:1253-1278).

The merge resolution in _launch_splitk_reduce uses main's splitk_reduce_launcher.lazy, and the deferred GEMM still goes through the same run_gemm_a8w8_bpreshuffle_gfx1250 as main's AOT path.

Two small things:

  1. The "deferred" timing in the op test includes standalone reduces (op_tests/test_gemm_a8w8_splitk_deferred.py:85-99).
    • The timed deferred lambda leaves every output unclaimed. Once 64 outputs are listed, each call evicts the oldest one and launches gemm_a8w8_bpreshuffle_splitk_reduce.
    • The table also carries 63 entries from one shape to the next. A host-only trace of the head code with stubbed launchers shows standalone reduces in 40 of 104 timed calls for the first shape and in 103 of 104 for every later shape.
    • So the "deferred" us/TFLOPS/TB/s columns show roughly the GEMM + reduce cost, and the comment "The GEMM alone, as the model launches it" is wrong.
    • Fix: claim inside the timed call so nothing stays listed, e.g. y = deferred_gemm(...); return y, splitk_partials(y), then finish with splitk_reduce(*out). The claim is a host-side pop with no launch.
    • Earlier rounds, mine included, missed this: the lambda was already there at b6892c5. I am raising it now because this head rewrote its comment.
  2. Bring the PR description up to date with the head (it is the squash text).
    • Testing still says "The head, ed0119b, is 97f5332 rebased onto main e6d2d31"; the head is 92397e7.
    • "Not covered" says the GPU tests were not rerun after the rebase, while the Self-Review says MI455X at this head exits 0 on the 21 shapes.
    • The "pytest 5 passed" line describes the old pytest layout, which this head no longer has.

Root cause vs patch

Root problem: at decode M, split-K pays a separate reduce launch plus an fp32 round trip. The clean fix is a consumer that takes the partials explicitly (#8011). The fused in-kernel epilogue was measured and loses on 21 of 24 rows. The address-keyed global table is the patch-like part. It exists only because ATOM's opaque torch.compile op returns one tensor, and a [split_k, M, N] output would need a data-dependent shape. It is documented, the component owner accepted it, and the explicit partials= form exists at the low level, so I see no cheap cleaner fix. Verdict: right direction with patch-like parts; not blocking.

Both items are small. I will approve once they are in.


Reviewed at 92397e7 (round 4, pass A; request_changes, so no pass B; true delta = old b6892c5 replayed onto merge base 4960107 -> head). Already fixed: missed-claim raise and eviction reduce, shared config, CI host test, _fsk comparison, docstrings, misuse-case docstring.

@lirui927
lirui927 requested a review from valarLip December 1, 2026 06:41
The timed "deferred" candidate left every output unclaimed, so once 64 were
listed each call evicted the oldest and launched the standalone reduce: its
us / TFLOPS / TB/s columns showed GEMM + reduce. The candidate now claims the
partials as the consumer does (a host pop, no launch), so nothing stays
listed; the output is still finished and checked outside the timing.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@lirui927

lirui927 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Both items of the 2026-12-01 review are in at 87a18c5 (test file only; the library files are those of 92397e7).

1. The timed deferred candidate no longer includes standalone reduces.

  • It now claims inside the timed call, as you suggested: claimed(deferred_gemm(...)) returns (y, splitk_partials(y)), and the output is finished with splitk_reduce(*out) outside the timing. The comment says what is timed and why the claim is inside.
  • I reproduced your trace first. Host only, both FlyDSL launchers stubbed, 104 calls a shape over three shapes: the old candidate launched the standalone reduce in 40 of 104 calls on the first shape and in 103 of 104 on the later ones, with 64 outputs left listed. The new one launches it in 0 of 104, with nothing listed afterwards.
  • check_handoff_table, black and ruff pass.
  • Not rerun on a GPU yet: the four MI455X here are busy. So the deferred us / TFLOPS / TB/s columns are not re-measured at this head; the bitwise and fp32-reference asserts are unchanged. I will rerun the sweep when a card is free and add the result here.

2. The description matches the head.

  • Testing and the Self-Review name 87a18c5 and 92397e7; the ed0119b / 97f5332 / e6d2d31 lines are gone.
  • "Not covered" now says what is actually not rerun: the GPU sweep at this head, and test_gemm_a8w8.py --no-legacy and the ATOM tests since the merge of main.
  • The "pytest 5 passed" line is removed (the test has no pytest layout any more).

@lirui927
lirui927 marked this pull request as draft December 2, 2026 06:20
@lirui927
lirui927 removed the request for review from valarLip December 2, 2026 06:38
@lirui927
lirui927 marked this pull request as ready for review December 2, 2026 06:43

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ LGTM

Thanks. Both items from round 4 are fixed at this head. The only change since 92397e7 is the op test (op_tests/test_gemm_a8w8_splitk_deferred.py, +12/-4); the library files are the ones reviewed last round.

Prior asks (round 4):

  1. The "deferred" timing included standalone reduces: fixed.
    • claimed() (:64-66) claims inside the timed call (:95), and :107 finishes the output outside the timing.
    • A host-only trace of the head code with both FlyDSL launchers stubbed (104 calls per candidate, as run_perftest makes them) shows 0 standalone reduces in the timed "deferred" calls on every shape (it was 40/104, then 103/104), and nothing left listed between shapes.
    • Every output form is finished correctly: split 4/8 gives (y, partials) and one reduce; a split-1 row, gfx950, or M above max_m gives (y, None), and splitk_reduce(y, None) returns y unchanged. run_perftest passes a tuple return through untouched.
    • The new comments at :91-94 and :106 are true.
  2. PR description: fixed. Testing and Self-Review name 87a18c5 / 92397e7, the stale ed0119b / e6d2d31 and "pytest 5 passed" lines are gone, and "Not covered" now agrees with the Self-Review (no GPU sweep at this head).

Rounds 1-3 stay fixed (library unchanged). @aoli26's two questions were answered and they posted "LGTM now".

CI: the first PR run (46823068865) at this head was cancelled, so its GPU jobs show "fail" at 0 s; the rerun is still in progress. Please merge once it is green.

Root cause vs patch

Root problem: at decode M, split-K pays a separate reduce launch plus an fp32 round trip. The clean fix is a consumer that takes the partials explicitly, which this PR provides. The address-keyed hand-off table is the patch-like part, needed only because ATOM's opaque torch.compile op returns one tensor. It is documented and accepted by the component owner, and the explicit partials= form exists at the low level. Verdict: right direction with patch-like parts; not blocking.


Reviewed at 87a18c5 (round 5, passes A+B, both approve; true delta = 92397e7 -> 87a18c5, same merge base 4960107). Already fixed: missed-claim raise and eviction reduce, shared config, CI host test, _fsk comparison, docstrings, misuse-case docstring, deferred timing claim, PR description.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved at 87a18c5 (passes A+B).

@lirui927
lirui927 merged commit a7752f1 into ROCm:main Dec 2, 2026
95 of 103 checks passed
aoli26 added a commit that referenced this pull request Dec 3, 2026
Conflict resolved (from #7449, PTPC split-K left to the consumer):
- bpreshuffle_gemm_gfx1250: keep both of run_preshuffle_gemm_a8_gfx1250's
  fused_splitk and partials arguments. A caller's partials buffer is the
  unfused (split_k, M, N) layout, so a launch with partials runs unfused
  (the same fallback as an unsupported fused geometry) and skips the reduce;
  the fused epilogue and the reduce launch keep their own guards.

Merged cleanly but needed a change:
- gemm_op_a8w8._splitk_deferrable: a fused split-K row (_fsk) reduces in the
  kernel, its output is final, so it is not deferred and goes through
  gemm_a8w8_bpreshuffle.
aoli26 added a commit that referenced this pull request Dec 3, 2026
…plit-K hand-off (#7449)

- test_gemm_a8w8: a fused PTPC kernel name launched with partials= writes the
  unfused (split_k, M, N) partials, launches no reduce and leaves Out alone;
  reduce_splitk_partials_gfx1250 then gives the fused output's bytes.
- test_gemm_a8w8_splitk_deferred: a fused split-K row is not deferred (host
  table check, and on gfx1250 the deferred call is the plain GEMM: no reduce
  launch, no partials, same bytes).
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…15808c7, head 2026-11-19T10:14:52Z)

Applied as the diff ce334d0..15808c7 (26 files) onto the rebased 1116 tree; PR state: open, author aoli26, base main.

Squash-applied: #8246's branch merges main (ce334d0, this tree's base) and carries rebased copies of aoli26's
#7827 (head 9d38b5c, every added line present here) and #7868 (head 570805d; 3 of its added lines
are superseded by #8246's later edits), so this one diff applies the #7827 -> #7868 -> #8246 stack as #8246 has it.

(cherry picked from commit f58bb7e)

Rebase onto main 12-03: kept at the 15808c7 snapshot (the PR head is now c4f8a6d, see the rebase report). Main's #8678 (AOT launchers) and #7449 (deferred split-K partials) conflict with it in the two wrappers: bpreshuffle_gemm_gfx1250.py takes both fused_splitk and main's partials (a launch with partials runs unfused, main's _launch_splitk_reduce / reduce_splitk_partials_gfx1250 kept, skipped when fused); mxfp8_bpreshuffle_gemm_gfx1250.py keeps fused_splitk_ok (generic kernel included) and launches gemm_a8w8_launcher.lazy() with this PR's argument layout (arg_out, runtime cluster_m, fused_splitk). Same as the PR author's own merge of main, without the later lean_stripe_fits guard. aiter/aot/flydsl/sources.py: the gemm_a8w8_gfx1250 cache now also hashes kernels/splitk_fused_epilogue_gfx1250.py, which the kernel imports (as on the PR head).

Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce), as on the PR head.
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
#8978)

* K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8)

#8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head
ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had
changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It
carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute
guard, which #8778 replaces); no other main change rides in.

Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X
(wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of
main, which brings #8737); those can follow when #8778 lands.

Co-authored-by: zejunchen-zejun <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update K3 FP8 kernels to c997 and add exact-M tuning

Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding.

---------

Co-authored-by: aoli26 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zhang <[email protected]>
(cherry picked from commit 1cc9d02)

Rebase onto main 12-03: the 19 files keep this commit's content; only main's later changes are added: the AOT launcher factories of #8678 (mxfp8 / batched wrappers launch gemm_a8w8_launcher.lazy(), _gemm_a8w8_compute_bound_launcher.lazy(), splitk_reduce_launcher.lazy(); _lazy_import keeps _data_ptr), #7449's deferred split-K entry points and #8636's ragged-K fallback. gemm_a8w8_gfx1250.py: this commit's rank0 split-K epilogue and flush_addr (it already carries #8737's flush). gemm_op_a8w8.py: main's #8566 guard in get_mxscale_bpreshuffle_config (no padded row below a compute kernel's M tile) is removed, as on the #8778 head, because the c997 compute kernel serves underfilled tiles; test_gemm_host_dispatch_cache.py takes #8778's test_mxscale_compute_row_serves_underfilled_m_tile in place of main's two guard tests. kimik3 mxscale tuned CSV: this commit's rows (626 changed or added) replayed by key; the result equals this commit's table.

Rebase onto main 12-03: main #7449 moved the bpreshuffle row lookup into _bpreshuffle_config(XQ, WQ); this commit's Kimi-K3 exact-row lookup there needs x_scale, w_scale and Y, so _bpreshuffle_config takes them (the deferred split-K path passes a meta tensor of the output's shape and dtype, so it picks the same row as gemm_a8w8_bpreshuffle).

Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce).
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.

6 participants