Skip to content

[FlyDSL] [Perf] gfx950: persistent 4-wave MXFP8 GEMM kernel, tuner backend and MiniMax-M3.1 o_proj_full rows - #8582

Merged
zufayu merged 6 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mxfp8-4wave-kernel
Nov 26, 2026
Merged

zufayu merged 6 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mxfp8-4wave-kernel

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

At a glance

  • Change: a persistent 4-wave MXFP8 GEMM kernel for gfx950 (mxfp8_gemm_4wave.py), its dispatch (flydsl_mxfp8_4w_* kernel names) and tuner backend, and 15 MiniMax-M3.1 TP4 o_proj_full rows (N6144 K8192, M 1536..65536) in the MXFP8 bpreshuffle table.
  • Why it is faster: each workgroup is 4 waves covering a 256x256 tile, so a wave reads half the LDS bytes per MFMA of the 8-wave 2x4 layout; the loads run two K-steps ahead, workgroups walk the tiles persistently with the next tile's first loads overlapping the current tile's last steps, and the bf16 output goes through a per-wave LDS transpose so every store writes whole rows.
  • How much (MI355X gfx950, N6144 K8192, graph of 8 cold weight copies, median us per call): kernel only vs the best public 8-wave kernel: -11% (M=2048) to -22% (M=3072, 6144), -14% at M=8192..32768; through the public op vs the previous table rows: M=2048 101.3 -> 87.3 us, 3072 175.1 -> 133.1, 4096 194.1 -> 158.5, 8192 358.7 -> 271.7, 16384 763.0 -> 536.8, 32768 1443.2 -> 1074.7 (A-scale shuffle included). Between the table's rows (M = 1088..3840) the new path is 0-48% faster and never slower.
  • End to end: not measured in this PR.
  • Stack order: the branch also carries the commit of [Config] [Perf] MiniMax-M3.1 TP4 o_proj_full (N6144 K8192) MXFP8: 8-wave picks at M >= 8192 on gfx950 #8578 (o_proj_full 8-wave rows), which it is stacked on for the table baseline; review the top commits, the diff shrinks as [Config] [Perf] MiniMax-M3.1 TP4 o_proj_full (N6144 K8192) MXFP8: 8-wave picks at M >= 8192 on gfx950 #8578 lands. No ATOM change needed.

Summary

One PR for the gfx950 persistent 4-wave MXFP8 GEMM: the kernel (previously #8582) and its dispatch, tuner backend and MiniMax-M3.1 o_proj_full rows (previously #8584). They were two stacked PRs on the same kernel; the branch now holds both (+1963/-12, kernel first, then dispatch). Still stacked on #8578 (o_proj_full 8-wave rows) for the table baseline.

Part 1: the kernel (was #8582)

Summary

Adds the persistent 4-wave MXFP8 GEMM kernel for gfx950 as aiter/ops/flydsl/kernels/mxfp8_gemm_4wave.py (compile_mxfp8_gemm_4w), ported from amd-kernels' gemm/mxfp8_common/mxfp8_gemm_4wave.py (itself built on FlyDSL's fp4_gemm_4wave). Kernel + its test only; no dispatch, no config rows: the dispatcher and tuned rows are the follow-up PR (stacked on this and on #8578). Nothing imports amd-kernels; the only changes to the source are the buffer helpers (aiter's own kernels/buffer_ops.py, same API), the 12-line MFMA issue order inlined, and an explicit K >= 512 assert (the K loop needs four 128-K steps; K = 256 silently computed garbage).

Why

o_proj_full (N6144 x K8192) of the MiniMax-M3.1 TP4 sequence-parallel prefill, and the other large-M MXFP8 GEMMs, run 13-27% slower on the public 8-wave / bmm kernels than on amd-kernels' 4-wave kernel (ticket measurements: M 2048 +13%, 3072 +27%, 4096 +18%, 6144 +22%, 8192 +17%). A wide sweep of every public candidate (126 kernels x 4 row counts) found nothing better: the gap is the kernel, not its tile / stage / swizzle choice.

Design (kernel)

  • One workgroup = 4 waves = a 256x256 tile, each wave a 2x2 of 64x64 quadrants of v_mfma_scale_f32_16x16x128_f8f6f4 (a wave reads half the LDS bytes per MFMA of the 8-wave 2x4 layout). Eight 16 KB LDS buffers (cur / next x two 128-row halves x A / W) filled by buffer_load ... lds two K-steps ahead; scales (the shuffle_scale_a16w4 layout) gathered into LDS one 256-K block ahead and picked with op_sel / op_sel_hi.
  • Persistent: min(tiles, grid_max) workgroups walk the tiles; the next tile's first loads go out in the last two steps of the current one, the stores of a finished quadrant interleave with the next MFMAs, and the bf16 output goes through a per-wave LDS transpose so every store writes whole rows. tiles=(4, 4) / (2, 4) / (2, 2) select the 256x256 / 256x128 / 128x128 sub-tile of the remainder round; tile_off / n_work pick a range of work items; grid_max large = a plain grid.
  • Operands: row-major fp8 A, shuffle_weight(.., (16, 16)) W, both scales shuffled with shuffle_scale_a16w4(.., 1, False) over rows padded to 32; M any (rows past M read zero through the buffer bounds, their stores are dropped), N % 256 == 0, K % 256 == 0 and >= 512, bf16 out. All buffer resources are bounded by num_records_bytes of the real extents (max_size=False).

Results (MI355X, gfx950, ROCm 7.2.4, FlyDSL 0.5.3; graph of 8 cold weight copies, median us/call, kernel only on pre-shuffled scales)

N6144 x K8192 (the o_proj_full shape):

M best public 8-wave this kernel amd-kernels this vs 8-wave
2048 92.6 82.8 80.0 -11%
3072 158.6 123.1 123.4 -22%
4096 181.2 153.2 149.3 -15%
6144 272.2 211.7 219.1 -22%
8192 315.9 268.9 268.6 -15%
16384 613.9 530.4 529.8 -14%
24576 928.2 795.3 1022.7 -14%
32768 1231.7 1060.0 1362.6 -14%

At M <= 16384 it is within +4% of the amd-kernels kernel (it is that kernel); above 16384 amd-kernels' table picks another row and this one is 22% faster. The other shapes measured (6144x2048, 6144x3072, 6144x6144, 2560x6144, M 1024-32768) are in the ticket; they are within +8% of amd-kernels for M >= 2048.

Correctness

op_tests/test_mxfp8_gemm_4wave.py (20 tests, all pass): output bit-identical to the public 8-wave kernel (same MFMA, same K order per accumulator) for (M, N, K) = (256, 256, 1024), (300, 512, 1024) (M not a multiple of the tile), (2048 / 3072, 6144, 8192), (4100, 6144, 8192) (ragged last row of tiles), (5000, 2560, 6144) x tiles (4, 4), (2, 4), (2, 2); persistent grid == plain grid; relative L2 error vs an fp32 dequantized reference < 5e-3 (the 8-wave kernel's own error: 1.7e-3). Also bit-identical to the amd-kernels kernel on all its shapes in the dispatcher PR's sweep.

Notes for review

  • 1288 lines in one kernel file: a verbatim port of a single kernel that does not split; tests are 126 more. The follow-up (dispatch + rows) is separate and small.
  • The ported kernel uses fx.arith.select / bitcast / trunc_f, which are not in fx.arith.__all__ (rule D10b); they are inherited from the verified source and kept to keep the validated instruction stream, no typed form substituted. Happy to move them to the typed forms in a follow-up with its own validation.
  • No AOT entry (aot_factory) is added here; the launcher JIT-compiles on first use (a few seconds) and caches in the FlyDSL cache. The dispatcher PR is where an AOT registration belongs.
  • gfx950 only (MFMA scale + buffer_load lds m0 asm); the test skips elsewhere.
  • Technique credit: amd-kernels mxfp8_gemm_4wave.py (and FlyDSL fp4_gemm_4wave, HipKittens 4-wave layout).

Review

Run by hand through the repo's review-pr triage (rules A1 A4 B4 B6 B8 C1 C2 C4 C5 D1 D8 D10 D10b D12 D13 D14 G1 P1-P3 P5 P6): twins / siblings / flydsl-bounds / aot-pairing / ci-coverage / symbols checks clean; B8: every buffer resource is max_size=False with exact byte extents; D10: the launcher goes through tensor_shim._run_compiled only (no second launch); D12: not applicable here (nothing registered with AOT, no dispatcher); D13/D14 belong to the dispatcher PR (device, dtype, stride, 32-bit extent checks live there); P6: measured against the amd-kernels kernel and the public 8-wave candidates back to back on one GPU (table above). Open note: D10b above.

Part 2: dispatch, tuner and rows (was #8584)

Summary

Stacked on #8582 (the persistent 4-wave MXFP8 kernel) and #8578 (o_proj_full 8-wave rows): the first commits of this branch are those PRs, review the top commit only; the diff shrinks as they land.

Makes the 4-wave kernel reachable through gemm_a8w8_blockscale(..., isBpreshuffled=True) / gemm_a8w8_mxfp8_bpreshuffle and puts it in the MiniMax-M3.1 TP4 o_proj_full (N6144 x K8192) rows, so the aiter-only path matches amd-kernels' ak_gemm for the sequence-parallel prefill.

  • aiter/ops/flydsl/gemm_a8w8_mxfp8_4wave.py (new): backend with the 8-wave module's shape: kernelName flydsl_mxfp8_4w_256x256x128_F8_F8_B16_xcd{0|1}[_nt] (make / parse), flydsl_mxfp8_4wave_gemm (raw row-major e8m0 scales in), launch_mxfp8_4wave_shuffled (for a producer that emits the kernel's scale layout), run_gemm_a8w8_mxfp8_4wave (the kernelName entry).
  • Scales: the kernel wants both scales in shuffle_scale_a16w4 order. A's is shuffled per call by one small Triton kernel (the torch 7-D permute copy costs 5-13 us at M 1024-16384, this 2.5-10 us, bit-identical, rows padded to 32 with 127 in the same pass); W's once per weight-scale tensor (cache keyed by device / pointer / shape / strides / _version, the entry holds the tensor so its storage cannot be freed and reused under the key, 512 entries). A caller that already has shuffled A scales (a quantizer emitting them) calls launch_mxfp8_4wave_shuffled and skips the 3-6 us; amd-kernels' numbers below do that.
  • Launch plan (same as amd-kernels' _fourwave_plan, generalized to get_cu_num()): one persistent round of 256x256 tiles; a remainder of R <= cus/2 parent tiles runs as one round of 128x128 (R <= cus/4) or 128x256 sub-tiles.
  • mxscale_preshuffle_kernels.run_gemm_a8w8_mxfp8_gfx950: routes the flydsl_mxfp8_4w_ prefix; a non-bf16 Out or a non-1x32 w_scale falls back to the mxpsh heuristic tile, as the 8-wave prefix does.
  • Tuner: a 4wave pipeline (4 candidates: xcd remap x non-temporal stores) in the 1x32 pipeline list, ids from 2_000_000; fits = N % 256 == 0, K % 256 == 0, K >= 512, 32-bit extents.
  • minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv: N6144 K8192 rows at M = 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536 -> 4-wave (the rows at 2048, 4096 and at M >= 8192 replace bmm / 8-wave rows; M <= 1024 rows unchanged). us is the measured public-path time.

Results (MI355X, gfx950; public path gemm_a8w8_blockscale(isBpreshuffled=True), graph of 8 cold weight copies, median us/call, A scale shuffle included)

M before (#8578 table) this PR amd-kernels
1536 94.1 77.8 69.2
2048 101.3 87.3 86.7
2304 176.7 93.1 92.1
3072 175.1 133.1 123.7
4096 194.1 158.5 152.6
4608 230.9 166.2 172.7
6144 350.1 221.7 220.1
8192 358.7 271.7 270.4
12288 589.6 415.7 411.9
16384 763.0 536.8 532.7
24576 1084.2 805.0 1023.5
32768 1443.2 1074.7 1358.2
49152 2174.6 1599.8 2023.6
65536 2908.6 2143.9 2702.9

Between the table's rows (M = 1088 ... 3840, 4608) the new path is 0-48% faster than before (e.g. 2304: 176.7 -> 93.1, 2816: 180.7 -> 125.8) and never slower; against amd-kernels it is within +0-9% for M 2048-16384 (the gap is the per-call A-scale shuffle, 3-6 us) and 21-26% faster above 16384 (amd-kernels' own table picks a slower row there). Output is bit-identical to amd-kernels' at every M >= 1280 above (pub_eq_ak); M = 1024 is a different kernel on both sides (unchanged rows, not bit-identical to ak's split kernel, as before).

Correctness

op_tests/test_mxfp8_gemm_4wave_dispatch.py (28 tests, all pass) plus #8582's 20: kernelName round trip, the launch plan (no remainder / 128x128 / 128x256 remainder, with and without XCD dealing), the Triton scale shuffle == shuffle_scale_a16w4 over padded rows (M 1 ... 8192, K 512 / 8192), run_gemm_a8w8_mxfp8_gfx950 with the 4-wave name bit-identical to the 8-wave kernel at (300, 512, 1024), (3072 / 4096 / 4100, 6144, 8192) (the three remainder-round plans) and (5120, 2560, 6144), both store modes, and the W-scale cache following an in-place scale update (version bump). The tuner's pipelines list the 4-wave candidates for (4096, 6144, 8192) and refuse N = 6000 / K = 256.

Notes for review

  • No AOT registration (aot_factory) for the 4-wave launcher yet: first use JIT-compiles it (a few seconds, cached in the FlyDSL cache). Follow-up.
  • A caller must have called the op once with a given w_scale tensor before CUDA-graph capture (the first call shuffles it; later calls hit the cache). ATOM's warm-up already runs each linear before capture; a producer that holds pre-shuffled scales can use launch_mxfp8_4wave_shuffled and has no cache.
  • Rows only for the o_proj_full shape: 6144x2048 / 6144x3072 / 6144x6144 / 2560x6144 also gain 5-12% at M >= 6144 in the same sweep, but their margin over the current rows is within the run-to-run noise at M < 6144, so they are left to the tuner (gemm_a8w8_mxfp8_bpreshuffle_tune.py now enumerates the 4-wave kernels).
  • The DBO plain-grid switch of amd-kernels (_PLAIN_GRID_MAX while two microbatches share the GPU) is not ported: grid_max is a parameter of the kernel, the policy belongs to the engine.

Review

Run by hand through the repo's review-pr triage (rules A1 A3 A4 B1 B3 B4 B6 B7 C4 C5 D1 D3 D8 D10 D12 D13 D14 E2 P1-P3 P5 P6): siblings / guards / aot-pairing / symbols / ci-coverage / flydsl-bounds checks clean. B4 (new dispatch value): the prefix is handled in run_gemm_a8w8_mxfp8_gfx950 with a documented fallback for non-bf16 out / non-1x32 scales, and the backend raises on a shape it cannot run instead of falling through; D13: the compiled-handle cache keys K, xcd, nt, tiles and grid size, and every launch passes the device as the specialization key; D14: operands are checked for device, contiguity, shape, dtype width and 32-bit extents before the raw-pointer launch, under torch.cuda.device; D3: no hipblaslt rows; D12: AOT not added (stated above); P6: base vs head measured back to back (tables above). Findings fixed before opening: a bf16-only / 1x32-only fallback for the 4-wave prefix (first version raised for an fp16 out), device check, rows restricted to the verified shape.

Technique credit: amd-kernels gemm/mxfp8_common/gemm.py (_fourwave_plan, scale preparation).

Supersedes #8582's standalone form and #8584 (closed in favour of this PR).

Review-fix update (head e1375f44e)

Changes after the review (commits 1e092621a and e1375f44e):

  • AOT: the Triton scale shuffle is skipped under compile_only (the Triton kernel moved to kernels/mxfp8_scale_shuffle_triton.py, imported inside _shuffled_scale only); new tests/test_flydsl_aot_replay.py::test_4wave_mxfp8_csv_rows_reach_flydsl_through_public_replay replays all 15 flydsl_mxfp8_4w_ rows in a GPU-hidden process.
  • The W-scale cache: a miss during graph capture is not published, an eager miss syncs the stream before publishing, no eviction (at 512 entries a new scale is shuffled per call).
  • M == 0 returns Out; KERNEL_ID_BASE_4WAVE is 6_000_000; the 4-wave branch also requires fits_shape; the kernel leftovers (MN, _SCALE_LDS_BYTES, _swap_bufs) are removed.
  • Tests: K=512 / 768 variants, xcd0, NaN-filled outputs, grid_max 8 / 90 / 256 vs the plain grid, checkAllclose against the fp32 reference, a public-op test with an injected row, a malformed-operand test, a bench (--bench), runtime-arch gating of the tests and of --bench.
  • ruff 0.16.0 clean (I001, RUF046, B023 with a file-level reason).

Re-verified on gfx950 (overlay of the PR tree on an older aiter image): op_tests/test_mxfp8_gemm_4wave.py 51 passed, op_tests/test_mxfp8_gemm_4wave_dispatch.py 52 passed, tests/test_flydsl_aot_{replay,launch,cache}.py 30 passed / 4 skipped; --bench 4-wave 86.7 / 135.0 / 164.0 us vs 8-wave 119.5 / 226.6 / 237.6 us at M 2048 / 3072 / 4096 (outputs equal). e1375f44e only changes the --bench gate in main(); the test files were not re-run after it.

Reproduce: python3 op_tests/test_mxfp8_gemm_4wave.py, python3 op_tests/test_mxfp8_gemm_4wave_dispatch.py, python3 op_tests/test_mxfp8_gemm_4wave.py --bench.

PR Self-Review

Reviewed revision

e1375f44e

Behavior and intent

Adds a 4-wave persistent MXFP8 GEMM that is 11-22% faster than the public 8-wave kernels at the MiniMax-M3.1 TP4 o_proj_full shape, makes it reachable through gemm_a8w8_blockscale(..., isBpreshuffled=True) and the tuner, and routes 15 o_proj_full rows to it. The public 8-wave / bmm kernels were 13-27% slower than amd-kernels' 4-wave kernel for these M (a 126-kernel x 4-row-count sweep found nothing better among them).

Validation and unverified scope

Commands and results are in the Results and review-fix sections (gfx950 MI355X): outputs bit-identical to the public 8-wave kernel and to amd-kernels' kernel at every M >= 1280 above, 103 gfx950 tests, the 15-row AOT replay. Not verified: end-to-end effect; the DBO plain-grid policy of amd-kernels is not ported; the rows for 6144x2048 / 6144x3072 / 6144x6144 / 2560x6144 are left to the tuner; a caller must have called the op once per w_scale before CUDA-graph capture (documented).

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

The 15 rows N=6144 K=8192 at M = 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536 in minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv (kernel names flydsl_mxfp8_4w_256x256x128_F8_F8_B16_xcd{0|1}[_nt]). The lookup key includes N and K, so other (N, K) are unaffected, and the rows at M <= 1024 are unchanged. The replay test resolves each of the 15 rows to the 4-wave runner, the dispatch tests check the kernel name, plan and public op, and the table above shows the path is never slower between rows.

Changed op tests

  • op_tests/test_mxfp8_gemm_4wave.py: kernel-level: output bit-identical to the public 8-wave kernel for ragged M and K = 512 / 768 / 1024 / 8192 across the 3 tiles and both xcd modes, persistent grid vs plain grid, checkAllclose against an fp32 dequantized reference, the malformed-operand rejection and --bench. It needs its own file because the existing bpreshuffle test drives the 8-wave kernel through the tuned CSV, where the 4-wave kernel is not reachable without a row.
  • op_tests/test_mxfp8_gemm_4wave_dispatch.py: dispatch-level: kernel-name round trip, launch plan, Triton scale shuffle vs shuffle_scale_a16w4, run_gemm_a8w8_mxfp8_gfx950 with a 4-wave name, the W-scale cache (capture, eviction, in-place update) and the public op with an injected row.

🤖 Generated with Claude Code

@ganyi1996ppo
ganyi1996ppo requested review from a team and a balanced review from Copilot November 24, 2026 14:23
…ave picks at M >= 8192 on gfx950

Replace the 7 FlyDSL bmm rows of the 6144x8192 1x32 shape at M = 8192 ... 65536
in model_configs/minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv
with FlyDSL 8-wave MXFP8 (256x256x128) picks. Config only, no code change;
output is bit-identical to the previous kernels.

Co-Authored-By: Claude <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

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

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8582 --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.

@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision e1375f44e11b · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)

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

…shuffle and MiniMax-M3.1 o_proj_full rows

The dispatcher half of the persistent 4-wave MXFP8 kernel: a gemm_a8w8_mxfp8_4wave backend
(kernelName flydsl_mxfp8_4w_..., raw scales in, shuffled in the backend), the tuner pipeline,
and N6144 x K8192 rows from M 1536 to 65536.

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

Copilot AI 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.

🟡 Changes recommended

The tests lack a reproducible performance benchmark, use build rather than runtime GPU architecture for gating, and fail to adequately validate persistent multi-tile execution and elementwise FP32 correctness.

4 open issues
What changed in this PR

Adds a persistent four-wave MXFP8 GEMM kernel for gfx950, targeting large-M prefill workloads. This provides the kernel foundation for follow-up dispatch and tuning work; existing dispatch paths and configuration rows are unchanged.

Changes:

  • Introduces a 256×256-tile kernel with configurable sub-tiles, overlapping data loads and computation, and bf16 output.
  • Adds correctness comparisons against the existing eight-wave kernel and an FP32 reference, including ragged-M shapes and different grid limits.
File Description
op_tests/​test_mxfp8_gemm_4wave.py Adds operand preparation and numerical tests for tile variants, ragged rows, and grid configurations.
aiter/​ops/​flydsl/​kernels/​mxfp8_gemm_4wave.py Implements the persistent four-wave kernel and JIT launcher, including shuffled-scale loading and output stores.

Review effort: Balanced

Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved
Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved
Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved
Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved
Copilot AI balanced review requested due to automatic review settings November 25, 2026 06:03
@ganyi1996ppo ganyi1996ppo changed the title [FlyDSL] [Perf] gfx950: persistent 4-wave MXFP8 GEMM kernel (256x256 tile, ported from amd-kernels) [FlyDSL] [Perf] gfx950: persistent 4-wave MXFP8 GEMM kernel, tuner backend and MiniMax-M3.1 o_proj_full rows Nov 25, 2026

Copilot AI 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.

🟡 Changes recommended

Critical issues remain: compile-only AOT replay fails on a Triton launch, the producer-facing entry lacks validation and can write out of bounds, and scale caching can reuse stale or incompletely initialized data.

10 open issues

Review effort: Balanced

@xytpai xytpai 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.

Read-through of 77cedd3: the diff plus the dispatch, tuner and AOT code around it. I have not run anything on gfx950.

The kernel half looks sound to me. I checked that _xcd_swizzle is a bijection over the parent grid, that launch_plan's main and remainder launches cover every parent tile exactly once (the round-up-to-8 overshoot lands beyond M and is dropped by the buffer bounds), the LDS total (131072 + 8192 + 16384 = 155648 B, under 160 KiB), and the masks in the Triton scale shuffle. The replaced CSV rows are all faster than the rows they replace. My concerns are in the dispatch half and in test coverage.

Before the CSV rows land

  1. AOT replay of the 15 new rows. Same finding as the existing thread on _shuffled_scale; this is what I traced. aiter/aot/flydsl/gemm.py replays every flydsl row of this table through gemm_a8w8_blockscale_bpreshuffle on FakeTensors. A 4-wave row reaches the Triton launch in _shuffled_scale, where the dry run's Triton driver stand-in raises. replay_job does not treat that as "another backend", because the traceback has a frame under aiter/ops/flydsl/ (_in_flydsl is true), so each row is a [FAIL] and aiter/aot/flydsl/common.py raises AssertionError("[aiter] FlyDSL AOT failures: ..."). CI did not show it here because the wheel-build jobs were skipped. I would hold the rows until a 4-wave row replays cleanly, with a test for it.
  2. CI is red on this revision. Ruff fails (I001 at kernels/mxfp8_gemm_4wave.py:34, RUF046 at :247, B023 at :1078 and :1225-1228, UP037 at gemm_a8w8_mxfp8_4wave.py:123; the annotation list is truncated), Standard Tests (1 GPU) were skipped and Aiter Test Gate failed, so none of the 48 new tests has a CI result yet.

Inline

  • The W-scale cache is not safe across a CUDA graph capture.
  • Kernel paths that no test compiles: K % 512 == 256, K == 512, and xcd0.
  • KERNEL_ID_BASE_4WAVE equals KERNEL_ID_BASE_FSK.
  • A few smaller ones.

Minor

  • flydsl_gemm_mxscale_preshuffle_common.py now imports gemm_a8w8_mxfp8_4wave at module level, that module imports triton at module level, and mxscale_preshuffle_kernels.py imports the common module at its top. Every mxscale GEMM import now pulls in Triton. Importing triton inside _shuffled_scale would keep it local.
  • aiter/ops/flydsl/AGENTS.md asks new kernels to stay off the legacy buffer_ops and to comment each raw op with the stable API that is missing. The description covers the raw arith ops (D10b) but not buffer_ops. Keeping the validated instruction stream is a fair reason; a tracking issue for the follow-up would help.
  • The branch still carries #8578's commit, and all 7 rows it changes are overwritten here by 4-wave rows. Either drop the commit or close #8578.
  • The PR Self-Review sections the bot asks for are still missing from the description.

Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved

@xytpai xytpai 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.

Second pass, checking this PR against the repo's .claude/skills (aiter-op-test, flydsl-kernel-code-cleanup, review-pr). Only points that are not already raised in this PR:

  • Tests (aiter-op-test). The skill asks to extend the existing op_tests/test_<op>.py rather than add a parallel suite. This op already has op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py, and the PR adds two new pytest-only files. Inline: the outputs are torch.empty with no sentinel.
  • Raw LDS pointers (flydsl-kernel-code-cleanup, section 3b). Inline.
  • Size (review-pr). 1963 added lines against the 1000-line review bar, where the skill recommends a stacked split. The natural seam is the two PRs this was merged from: the kernel with its test, and the dispatch, tuner and rows (#8584).
  • Downstream CI (review-pr). The rows change the default kernel for MiniMax-M3 MXFP8 prefill and no ci:* label is set, so no downstream job ran. The closest downstream case I can find is the MiniMax-M3-MXFP8 one in atom-di-ci-smoke-workflow.yaml (run_minimax_m3_fp8_2p1d_tp8); the rule's fallback is ci:all.
  • Named constants (review-pr). The kernel addresses LDS and tiles with raw 16 / 64 / 128 / 1024 / 2048 literals next to a few named ones (PARENT_M, BLOCK_K, _LDS_BUF_BYTES). Naming the MFMA tile and LDS row sizes would make the offset math checkable.

The collision guard side is fine: I merged the five a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm files at this head and found no duplicate key.

Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved
…eam-safe W-scale cache, shared operand validation, review fixes

- _shuffled_scale returns the placeholder under COMPILE_ONLY (AOT replay of the 4-wave rows no longer reaches a Triton launch); Triton is imported lazily from kernels/mxfp8_scale_shuffle_triton.py
- W-scale cache: a miss inside a CUDA graph capture is not published, entries finish (stream sync) before publication, no LRU eviction (stop caching at the cap)
- launch_mxfp8_4wave_shuffled validates operands (shared with the raw-scale wrapper) and scale lengths; M == 0 returns before fits_shape
- run_gemm_a8w8_mxfp8_gfx950: a 4-wave row whose M fails fits_shape runs the heuristic tile instead of raising
- KERNEL_ID_BASE_4WAVE 6_000_000 (was equal to KERNEL_ID_BASE_FSK); kernel: drop MN, _swap_bufs, _SCALE_LDS_BYTES, fix docstrings, xcd tag in the kernel name; ruff (I001, RUF046, B023, UP037)
- tests: K=512 / K%512==256, xcd0, grid cap 8, NaN sentinels, runtime arch gate, elementwise fp32 check, public-op case with an injected row, capture / empty-batch / validation cases, 4-wave vs 8-wave benchmark, AOT replay of the 4-wave CSV rows

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:22

Copilot AI 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.

🟡 Changes recommended

The 4-wave paths lack architecture guards in both direct calls and benchmark execution, and selecting them rejects valid caller-owned strided outputs supported by the public API.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Reject unsupported GPU architectures in 4-wave operand validation

aiter/​ops/​flydsl/​gemm_a8w8_mxfp8_4wave.py:203

The shared operand validator accepts tensors from any CUDA architecture, so a direct call to either 4-wave entry on gfx942 with M=256, N=256, K=1024 reaches a gfx950-only kernel instead of being rejected by the wrapper. That kernel uses scaled MFMA instructions and allocates 8×16384 + 2×4096 + 4×2×16×32×4 = 155648 bytes of LDS, beyond gfx942's capacity. Please add a gfx950 allow-list here using get_gfx_runtime(), before scale preparation or compilation, as the 8-wave backend does in its validation.

Medium severity Support strided output tensors in the 4-wave backend

aiter/​ops/​flydsl/​mxscale_preshuffle_kernels.py:617

Selecting a new 4-wave row rejects valid caller-owned strided outputs: at M=8192, N=6144, K=8192, out = backing[:, :6144] with row stride 6400 passes the public API's checks but fails the backend's contiguity check. The 8-wave backend supports this layout (gemm_a8w8_mxfp8_8wave.py:199–207). Compute into a contiguous temporary for non-contiguous outputs and copy back into Out; add a public-op regression test checking both values and returned-object identity.

9 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_mxfp8_gemm_4wave.py Resolved
The pytest skip marker does not apply when main() calls bench_4wave directly; --bench on another arch entered
the gfx950-only kernel instead of skipping.

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 02:57
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Re the two review summaries (items 1.1 / 1.2 and the minor items): the AOT replay of the 15 rows, the ruff findings, and Triton being imported by every mxscale import are fixed in 1e09262 (the Triton shuffle is skipped under compile-only, a replay test covers all 15 flydsl_mxfp8_4w_ rows, ruff 0.16.0 is clean, the Triton kernel moved to kernels/mxfp8_scale_shuffle_triton.py and is imported inside _shuffled_scale only). The inline items are answered in their threads. The remaining points of the summaries (test layout, PR split, the raw LDS pointer, the named constants, the buffer_ops note) are design / scope calls that I am looking into before answering.

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed to evaluate public-API correctness risks from rejected strided outputs and stale cached scales after in-place inference-tensor updates.

1 open issue
1 resolved since last review

Review effort: Balanced

@xytpai xytpai 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.

Re-checked at e1375f4. I read both new commits.

Fixed, with tests

These threads can be resolved:

  • AOT replay. The Triton shuffle is skipped under compile-only, and test_4wave_mxfp8_csv_rows_reach_flydsl_through_public_replay replays the 15 rows with the GPUs hidden. Triton is now imported only inside _shuffled_scale.
  • W-scale cache. A miss during a capture is not published, eager entries use persistent_alloc and are published after a stream sync, and nothing is evicted.
  • Dispatch. KERNEL_ID_BASE_4WAVE is 6_000_000, M == 0 returns Out, and a row whose shape fails fits_shape falls back to the heuristic tile.
  • Tests. K = 512 and K = 768, xcd0, NaN-filled outputs, and the injected-row public-op case.
  • Kernel leftovers (MN, the (4, 2) docs, the dead helpers, the xcd tag in the name) and the Ruff findings.
  • Raw LDS pointer. It keeps its form with a comment saying why. That is enough for me.

Before I approve

CI on this head. build_aiter_wheels is still running as I write, and the standard tests start after it. The wheel build is the step that proves the replay fix. I will approve once both are green.

Follow-ups, not blocking

  • The _min raw select you are looking into.
  • From my second pass: the test layout, the PR split, the named constants and the downstream-CI label.
  • #8578's commit is still in this branch while #8578 is open.

@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Status of the bot review summaries (Copilot reviews 6041072845, 6052697405, 6067343168, 6067995829), head e1375f4:

  • Inline items on arch gating, plain-grid test, allclose check, perf test, AOT replay, shape validation, cache publication, benchmark gating: fixed in 1e09262 / e1375f4, see the thread replies.
  • 4691095018 (in-place update of a W scale under inference mode not seen by the cache): acknowledged, tracked, decision pending (documented contract vs bypass for inference tensors).
  • 6067343168 "previously missed" items, not addressed yet: gfx950 allow-list in the shared operand validator before scale preparation, and strided caller-owned outputs in the 4-wave backend. Acknowledged, tracked; no fix pushed.

aiter-bot Self-Review, queue and CI Guide comments: the PR Self-Review section in the description covers the current head and the bot refreshes its comment on its own; nothing further to answer there.

@xytpai xytpai 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.

LGTM at e1375f4.

CI is green on this head, and it covers what I was waiting for:

  • Wheel build. With the 4-wave rows in the table, the GEMM replay reports 23948 ok and 0 failed.
  • Standard tests. All eight MI35X shards pass. op_tests/test_mxfp8_gemm_4wave.py ran 51 tests and op_tests/test_mxfp8_gemm_4wave_dispatch.py ran 52, with none skipped.

This rests on reading the code and on this CI run. I did not run anything on gfx950 myself.

The follow-ups from my last comment still stand and do not block. One has changed: #8578 was closed, so its seven 8-wave rows now land through this PR.

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