Skip to content

[FlyDSL] [gfx1250] mx32 GEMM: software-pipelined K loop; DSv4.1 rows use it - #7668

Open
yhl-amd wants to merge 13 commits into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-mx32-gemm-pipelined-kloop
Open

yhl-amd wants to merge 13 commits into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-mx32-gemm-pipelined-kloop

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #7667; only the commits after #7667's head are new here. Please merge #7667 first; this PR will be rebased onto main after that.

Summary

Software-pipelined K loop for the gfx1250 FlyDSL mx32 GEMM kernel (gemm_a8w8_gfx1250.py, batched and 2-D), the LDS reads of the next k-step and the TDM refill overlap the current k-step's WMMAs. Results are bit-identical to the existing loop. A tuned row opts in with the kernelName suffix _pl; every name without it, including all existing tuned rows and heuristic picks, keeps the single-fence loop it was timed on.

Motivation

Instrumenting the production kernels showed the TDM refill already runs ahead and the tile barrier is not the main serial point. The time goes inside the compute phase: each k-step's ds_loads wait for the WMMA queue to drain (the new fragments reuse registers still read by in-flight WMMAs, and the address VALU sits right before the loads), and the next K-tile's first fragments can only be read after the tile-top barrier. So "LDS read + WMMA" behaves like the sum of the two instead of overlapping.

Changes

  • kernels/gemm_a8w8_gfx1250.py, new pipelined constexpr (after fuse_quant_out, default 0):
    • k-step g+1's A / B / scale fragments are read into a second register set before k-step g's WMMAs are issued, across K-tile boundaries too (the next tile's first fragments are read during the last k-step of the current tile and carried through the tile loop).
    • The fence before tile kt+1 is split with the pipeline_fence_signal / pipeline_fence_wait primitives the 256x256 compute kernel already uses: signal after this tile's LDS reads and this wave's TDM of tile kt+1 have landed, issue half of the last k-step's WMMAs, wait, refill the stage with tile kt+num_buffers and read tile kt+1's first fragments, issue the other half.
    • When the layout allows it (no A preshuffle, no A-scale preshuffle, warp_tile_n % 32 == 0), per-stage LDS read bases are formed a tile ahead, so no address VALU sits right before the boundary reads; otherwise they are formed inline.
    • Every accumulator sees its k-steps in the same order with the same operands, hence bit-identical output.
    • check_pipelined_k_loop() is the one place that validates it: only 0 or 1; 1 needs mxfp8_32, no scale preload, no cluster, split_k 1 and tile_k >= 256. The fragment join of load_a / load_b and the serpentine WMMA order are shared with the new loop.
  • Enabling (no environment variable): a trailing _pl on a batched mxfp8_32 kernelName (batched_gemm_a8w8_gfx1250.py) or a generic 2-D mxfp8_32 kernelName (mxfp8_bpreshuffle_gemm_gfx1250.py) is the only switch. A name without it runs the single-fence loop; there is no default pick. Compute-bound and mxfp8_128 names do not accept _pl. Moving other tuned rows to _pl is left to follow-up PRs that re-time them.
  • dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv: after [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659 retuned the same DSv4.1 keys, the pipelined rows were re-timed against main's tiles on one gfx1250 box and kept only where _pl is ahead: N=32768, K=1280 at M 576 and 768 (t192x256x256 nb2 _pl, replacing main's compute-kernel rows in place). The other four keys (N=5120, K=8192 at M 576 / 672 / 768; N=32768, K=1280 at M 672) keep main's rows. The us / tflops / bw / errRatio of the two rows are measured on gfx1250 through the MXFP8 GEMM tuner's harness (see Validation).

PR Self-Review

Reviewed revision

1683901

Behavior and intent

Validation and unverified scope

  • gfx1250, earlier revision (same loop code), with independent scripts (own data, fp64 reference, before / after in separate processes):
    • DSv4.1 decode shapes of the four mx32 GEMMs at M 576 / 672 / 768, two data distributions (one heavy-tailed with +/-448): bit-identical to the previous kernel and tiles.
    • Ragged M tails, ragged K (k_tail with the pipelined loop), and CUDA graph capture / replay with new inputs: bit-identical.
    • The DeepSeek-V4 2-D path (n32k4 weight scale) tuned rows: bit-identical.
    • A sample of DSv4.1 tuned rows across M 1 to 16384, pipelined vs the old loop: all bit-identical, none slower beyond noise.
    • DeepSeek-V4.1-Flash on gfx1250 served end to end with the pipelined loop in the stack; all requests completed.
  • Revision 098f00596 (same K-loop code as this head), offline gfx1250 compile of launch_gemm_a8w8 (flydsl 0.5.0, null pointers, no GPU), final ISA compared:
    • _pl configs (batched 32x32 t128x128x256 nb4, t192x128x256 nb3, t192x256x256 nb2, ragged-K t64x128x256 nb2, 2-D t64x128x256 nb3, fused quant with t128x128x256 and t192x128x256) give ISA identical to the previous head with the loop forced on. No VGPR spill, no scratch.
    • Without _pl, all batched / 2-D / mxfp8_128 / ptpc / fused configs checked give ISA identical to main (bf16) or to [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 (fused); an explicit pipelined=0 is the same kernel as the default. (A name without _pl meant 0 at that revision, as it does at this head; the K-loop kernel code is unchanged since.)
  • 1683901ce (this head): CPU op_tests/test_gemm_host_dispatch_cache.py + test_bmm_a8w8_fused_quant_tuned_row.py 28 passed; the 10 failures are CUDA-only cases that fail the same way on main. black / ruff clean. No idle gfx950 GPU for a rerun. The kernel files of [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 under it give the same gfx1250 ISA as dfc62154e (see [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667). The lines below are at e9476df89; this PR's own commits are unchanged since.
  • e9476df89, CPU (GPU-less container, GPU_ARCHS=gfx950): python -m pytest op_tests/test_gemm_host_dispatch_cache.py 19 passed, 16 skipped; [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's head gives 15 passed, and the same pre-existing case (test_mxscale_config_precheck_matches_padded_walk, needs CUDA) fails on both. black 26.10.1 and ruff clean on the changed files; the CSV keeps its column count.
  • e9476df89, gfx950: python op_tests/test_flydsl_batched_gemm.py (GPU_ARCHS=gfx950) exits 0 and prints the same correctness columns as [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's head dfc62154e run on the same box (45 fused-quant lines, all 0 mismatches). This is a regression check of the shared files only; the pipelined loop is gfx1250-only and its cases do not run on gfx950.
  • This head, gfx1250: pending (the K-loop kernel code is unchanged since 96c03e69a; the rebase onto [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's new head is not yet run on gfx1250). It will be posted before merge.
  • gfx1250 at 138091409: python op_tests/test_flydsl_batched_gemm.py exits 0: the pipelined K loop cases (ragged K t64x128x256 nb2, shipped t192x256x256 nb2, t192x128x256 nb3, t128x128x256 nb4) are bit-exact against the single-fence loop, the fused-quant pinned tiles including the _pl one have 0 mismatches at M = 48 and M = 200, the fused epilogue reports all bit-exact, and main's compute kernelName cases pass. python -m pytest op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py passes on the same box. Row choice: main's row and the _pl row timed back to back on one gfx1250 box for each of the six keys, several rounds in alternating / shuffled order; the two kept keys were ahead in most paired rounds, the other four were behind or within noise. All candidates gave the same output. Log and relative timings in the PR comments.
  • gfx1250 at 0c2745d1a (same K-loop code, on [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's previous head; a name without _pl meant 0 there, as it does now): python op_tests/test_flydsl_batched_gemm.py exits 0 (pipelined K loop all bit-exact for the four PIPELINED_CASES, fused quant epilogue all bit-exact, compute kernelName cases pass) and the three pytest files above pass.
  • CSV values of the two _pl rows: csrc/gemm_a8w8_mxfp8_bpreshuffle/gemm_a8w8_mxfp8_bpreshuffle_tune.py only takes 128x128 shapes on gfx1250, so a thin subclass replaces only its tune() candidate list (main's row and the _pl row for each key) and keeps everything else: generate_data with the 32x32 scale, run_bmm_flydsl (B = 1, the path a kernelId bmm row runs), the mp_tuner task, the default warmup / iterations, the error check and the throughput formula. Eight processes with the candidate order alternated: _pl is ahead of main's row for both keys at either position. The written us is the median for the candidate timed second in its process (the first one in each process is slowed by the GPU ramping up); bw is in the unit of the neighbouring gfx1250 rows; errRatio is the tuner's (main's kernel gives the same value). Main's other gfx1250 rows of this table were not produced by this tuner ([FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659 used kernel traces), so absolute values are not directly comparable across rows; the relative result is in the PR comments.
  • Unverified: serving was not repeated with this row set. CI has no gfx1250 runner for FlyDSL op tests (ci:gfx1250-ffm-triton runs only for branches in ROCm/aiter and only the Triton suite plus two FlyDSL tests), so gfx1250 coverage of the op test is the manual run above.

PR-specific question

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

  • Keys, all in dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv with gfx1250, cu_num 256, w_scale_block 32x32, libtype flydsl: (M, N, K) = (576, 32768, 1280) and (768, 32768, 1280) (DSv4.1 wq_b), reached through the table's padded-M lookup.
  • Unrelated shapes: the CSV diff against main touches only those two rows (replaced in place, no added keys), so the selected kernelName of every other shape is unchanged, and so is its K loop: without _pl a name runs the single-fence loop. test_mx32_shipped_rows_take_the_k_loop_their_name_asks checks this over every kernelName in aiter/configs. mxfp8_128, ptpc, compute-bound, split-K and cluster configs keep exactly the previous kernel.

Changed op tests

  • op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: comes from [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 (CPU test of the fused entry's tuned-row lookup); unchanged here.
  • op_tests/test_gemm_host_dispatch_cache.py (CPU): test_mx32_pl_suffix_round_trip (batched and 2-D mxfp8_32 names parse _pl to 1 and the plain name to 0, nothing else in the config changes; compute-bound and mxfp8_128 names reject _pl), test_mx32_name_without_pl_runs_single_fence_loop (2-D names on which the pipelined loop would apply resolve to 0 without _pl and to 1 with it, also after cluster_m is fitted to M; _nopl and other suffixes do not parse), test_mx32_shipped_rows_take_the_k_loop_their_name_asks (every mxfp8_32 kernelName in the shipped tables runs the pipelined loop exactly when it ends in _pl) and test_pipelined_k_loop_check (tile_k < 256, no mx32, preload, cluster, split_k > 1 and values other than 0 / 1 are rejected). These are the parts that run in CI; no existing test parses _pl or reaches the check.
  • op_tests/test_flydsl_batched_gemm.py (gfx1250): PIPELINED_CASES compare name with name + "_pl" bit for bit on a ragged K (k_tail), on the shipped t192x256x256 nb2 row, and on a three-buffer (t192x128x256 nb3) and a four-buffer (t128x128x256 nb4) tile, where the tail fences wait on fewer outstanding tiles than the steady loop; FUSED_QUANT_TILES runs t128x128 without and with _pl, so the fused epilogue runs after both loops. Not redundant: before this, bit-identity with the old loop rested only on out-of-tree scripts.

🤖 Generated with Claude Code

@yhl-amd
yhl-amd requested a review from a team November 9, 2026 15:09
@github-actions

github-actions Bot commented Nov 9, 2026

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 7668 --add-label <label>

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

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

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

@github-actions github-actions Bot added the FlyDSL label Nov 9, 2026
@aiter-bot

aiter-bot commented Nov 9, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 1683901ce2b7 · 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

- Branch: #7667 (`d4016d527`, on main `3fd42598c`) plus this PR's own commits: the K-loop commit, the review commit that makes `_pl` the only switch, the re-pick of the DSv4.1 rows against #7659's retune with three- and four-buffer `PIPELINED_CASES`, the split-fence comment in code order, the measured `us` / `tflops` / `bw` of the two `_pl` rows, and `e9476df89` (CPU tests that untagged names run the single-fence loop; two kernel comments). The merge of main from the previous head is gone: #7667 is now on current main and this PR's six commits are replayed onto it (`71ec00293..1683901ce`); the only conflicts were test-file docstrings and a test helper next to main's `_fused_quant_k()`. The CSV diff against main is still only the two `_pl` rows. The default pick for names without a suffix and the `_nopl` suffix from the previous head (`1b573ced8`, `292a532f8`) are dropped. The rebase onto #7667's new head kept both #7667's `y_scale_out` and this PR's `pipelined` in the 2-D runner's arguments, and added the `_pl` tile to #7667's longer `FUSED_QUANT_TILES`.
- Before: every mx32 GEMM runs the single-fence K loop, where each k-step's LDS reads wait for the previous WMMAs to drain.
- After: rows whose kernelName ends in `_pl` run the software-pipelined loop; every other row, including heuristic picks, runs the single-fence loop as before. The two tuned DSv4.1 rows listed above carry `_pl`. An unsupported `_pl` config, or a `pipelined` value other than 0 / 1 reaching the kernel, raises.

Validation and unverified scope

- gfx1250, earlier revision (same loop code), with independent scripts (own data, fp64 reference, before / after in separate processes):
  - DSv4.1 decode shapes of the four mx32 GEMMs at M 576 / 672 / 768, two data distributions (one heavy-tailed with +/-448): bit-identical to the previous kernel and tiles.
  - Ragged M tails, ragged K (k_tail with the pipelined loop), and CUDA graph capture / replay with new inputs: bit-identical.
  - The DeepSeek-V4 2-D path (n32k4 weight scale) tuned rows: bit-identical.
  - A sample of DSv4.1 tuned rows across M 1 to 16384, pipelined vs the old loop: all bit-identical, none slower beyond noise.
  - DeepSeek-V4.1-Flash on gfx1250 served end to end with the pipelined loop in the stack; all requests completed.
- Revision `098f00596` (same K-loop code as this head), offline gfx1250 compile of `launch_gemm_a8w8` (flydsl 0.5.0, null pointers, no GPU), final ISA compared:
  - `_pl` configs (batched 32x32 `t128x128x256 nb4`, `t192x128x256 nb3`, `t192x256x256 nb2`, ragged-K `t64x128x256 nb2`, 2-D `t64x128x256 nb3`, fused quant with `t128x128x256` and `t192x128x256`) give ISA identical to the previous head with the loop forced on. No VGPR spill, no scratch.
  - Without `_pl`, all batched / 2-D / mxfp8_128 / ptpc / fused configs checked give ISA identical to main (bf16) or to #7667 (fused); an explicit `pipelined=0` is the same kernel as the default. (A name without `_pl` meant 0 at that revision, as it does at this head; the K-loop kernel code is unchanged since.)
- `1683901ce` (this head): CPU `op_tests/test_gemm_host_dispatch_cache.py` + `test_bmm_a8w8_fused_quant_tuned_row.py` 28 passed; the 10 failures are CUDA-only cases that fail the same way on main. black / ruff clean. No idle gfx950 GPU for a rerun. The kernel files of #7667 under it give the same gfx1250 ISA as `dfc62154e` (see #7667). The lines below are at `e9476df89`; this PR's own commits are unchanged since.
- `e9476df89`, CPU (GPU-less container, `GPU_ARCHS=gfx950`): `python -m pytest op_tests/test_gemm_host_dispatch_cache.py` 19 passed, 16 skipped; #7667's head gives 15 passed, and the same pre-existing case (`test_mxscale_config_precheck_matches_padded_walk`, needs CUDA) fails on both. black 26.10.1 and ruff clean on the changed files; the CSV keeps its column count.
- `e9476df89`, gfx950: `python op_tests/test_flydsl_batched_gemm.py` (GPU_ARCHS=gfx950) exits 0 and prints the same correctness columns as #7667's head `dfc62154e` run on the same box (45 fused-quant lines, all 0 mismatches). This is a regression check of the shared files only; the pipelined loop is gfx1250-only and its cases do not run on gfx950.
- This head, gfx1250: pending (the K-loop kernel code is unchanged since `96c03e69a`; the rebase onto #7667's new head is not yet run on gfx1250). It will be posted before merge.
- gfx1250 at `138091409`: `python op_tests/test_flydsl_batched_gemm.py` exits 0: the pipelined K loop cases (ragged K `t64x128x256 nb2`, shipped `t192x256x256 nb2`, `t192x128x256 nb3`, `t128x128x256 nb4`) are bit-exact against the single-fence loop, the fused-quant pinned tiles including the `_pl` one have 0 mismatches at M = 48 and M = 200, the fused epilogue reports all bit-exact, and main's compute kernelName cases pass. `python -m pytest op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py` passes on the same box. Row choice: main's row and the `_pl` row timed back to back on one gfx1250 box for each of the six keys, several rounds in alternating / shuffled order; the two kept keys were ahead in most paired rounds, the other four were behind or within noise. All candidates gave the same output. Log and relative timings in the PR comments.
- gfx1250 at `0c2745d1a` (same K-loop code, on #7667's previous head; a name without `_pl` meant 0 there, as it does now): `python op_tests/test_flydsl_batched_gemm.py` exits 0 (pipelined K loop all bit-exact for the four `PIPE

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

PR-specific question

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

- Keys, all in `dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv` with `gfx1250, cu_num 256, w_scale_block 32x32, libtype flydsl`: `(M, N, K)` = `(576, 32768, 1280)` and `(768, 32768, 1280)` (DSv4.1 wq_b), reached through the table's padded-M lookup.
- Unrelated shapes: the CSV diff against main touches only those two rows (replaced in place, no added keys), so the selected kernelName of every other shape is unchanged, and so is its K loop: without `_pl` a name runs the single-fence loop. `test_mx32_shipped_rows_take_the_k_loop_their_name_asks` checks this over every kernelName in `aiter/configs`. mxfp8_128, ptpc, compute-bound, split-K and cluster configs keep exactly the previous kernel.

Changed op tests

- `op_tests/test_bmm_a8w8_fused_quant_tuned_row.py`: comes from #7667 (CPU test of the fused entry's tuned-row lookup); unchanged here.
- `op_tests/test_gemm_host_dispatch_cache.py` (CPU): `test_mx32_pl_suffix_round_trip` (batched and 2-D mxfp8_32 names parse `_pl` to 1 and the plain name to 0, nothing else in the config changes; compute-bound and mxfp8_128 names reject `_pl`), `test_mx32_name_without_pl_runs_single_fence_loop` (2-D names on which the pipelined loop would apply resolve to 0 without `_pl` and to 1 with it, also after `cluster_m` is fitted to M; `_nopl` and other suffixes do not parse), `test_mx32_shipped_rows_take_the_k_loop_their_name_asks` (every mxfp8_32 kernelName in the shipped tables runs the pipelined loop exactly when it ends in `_pl`) and `test_pipelined_k_loop_check` (tile_k < 256, no mx32, preload, cluster, split_k > 1 and values other than 0 / 1 are rejected). These are the parts that run in CI; no existing test parses `_pl` or reaches the check.
- `op_tests/test_flydsl_batched_gemm.py` (gfx1250): `PIPELINED_CASES` compare `name` with `name + "_pl"` bit for bit on a ragged K (k_tail), on the shipped `t192x256x256 nb2` row, and on a three-buffer (`t192x128x256 nb3`) and a four-buffer (`t128x128x256 nb4`) tile, where the tail fences wait on fewer outstanding tiles than the steady loop; `FUSED_QUANT_TILES` runs t128x128 without and with `_pl`, so the fused epilogue runs after both loops. Not redundant: before this, bit-identity with the old loop rested only on out-of-tree scripts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

@yhl-amd

yhl-amd commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased with #7667 onto the current head of #7178 (352446c2f). That head already carries the main merge, so the separate merge commit is gone and the branch is now #7178 + the #7667 commits + the pipelined K-loop commit. The table rows are still replaced in place; the rows added on main and in #7178 are kept. bmm_a8w8_mxfp8_fused_quant_supported() now uses base_gfx_arch (from #7178), and op_tests/test_bmm_a8w8_fused_quant_supported.py passes on this branch.

@yhl-amd

yhl-amd commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on the updated #7667 (a17fb17, which fixes the test_woa_fused_quant.py import failure seen in Standard Tests shard 2: log). The K-loop commit itself is unchanged.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-mx32-gemm-pipelined-kloop branch from 52c4a81 to 96d2c64 Compare November 11, 2026 03:38
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the new #7667 (on #7178 @ 803a3cd). The K-loop commit cherry-picked without conflicts and is unchanged. The dsv41 mxscale csv row overlap with #7659 is still expected (whichever lands second gets a row-level rebase).

Checked (no GPU): py_compile / black / ruff on the changed files, modules import from the branch tree, op_tests/test_bmm_a8w8_fused_quant_supported.py passes.

@zufayu
zufayu removed the request for review from coderfeli November 11, 2026 06:55
@zufayu zufayu assigned aoli26 and unassigned coderfeli Nov 11, 2026
@zufayu
zufayu requested a review from coderfeli November 11, 2026 06:55
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-mx32-gemm-pipelined-kloop branch from 96d2c64 to 80eb895 Compare November 11, 2026 14:44
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the new #7667 (on the current #7178 head eba36e7d31). The previous build_aiter_wheels failure was the same Docker Hub 429 Too Many Requests pull failure, not the change.

One fix folded into the K-loop commit: #7655 on main moved the kernel off tdm_ops (import removed, tdm_ops.tensor_wait(n) -> rocdl.s_wait_tensorcnt(n)), so the pipelined prologue's tdm_ops.tensor_wait(num_buffers - 1) would have hit a trace-time NameError. It now uses rocdl.s_wait_tensorcnt(num_buffers - 1), same semantics. py_compile / black / ruff (incl. F821) are clean and the modules import from the branch tree; not re-run on gfx1250 after this rebase.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-mx32-gemm-pipelined-kloop branch from 80eb895 to 8a56033 Compare November 11, 2026 15:54
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the new #7667 (main + two commits), so #7178 is no longer in this branch. The K-loop commit is unchanged and keeps the rocdl.s_wait_tensorcnt(num_buffers - 1) wait. Still stacked on #7667.

@yhl-amd

yhl-amd commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the failing job (MI35X Standard Tests shard 7, https://github.com/ROCm/aiter/actions/runs/43052999770/job/130694496651) has a single failure, op_tests/test_flydsl_hgemm.py: a gfx950 split-K case reports "graph replay mismatch" (one element differs by one bf16 ulp after changed-input graph replay). The same assertion fails on unrelated PRs in the same window (https://github.com/ROCm/aiter/actions/runs/43080903893/job/130836755348, https://github.com/ROCm/aiter/actions/runs/43076930628/job/130774391091). Re-ran the failed jobs.

I also re-checked the rocdl.s_wait_tensorcnt(num_buffers - 1) call in the pipelined K loop (it replaced tdm_ops.tensor_wait after #7655 removed that import): tdm_ops.tensor_wait(n) is just rocdl.s_wait_tensorcnt(n), num_buffers is a Constexpr[int] so the count is an immediate, and the rest of gemm_a8w8_gfx1250.py on main uses the same call. The kernel is only imported from the gfx1250 entry points, so MI35X never traces it; no test on that shard touches it.

aoli26 added a commit that referenced this pull request Nov 13, 2026
…4-1536, 2048/3072

In the model a FlyDSL compute kernel runs 10-25 us slower after another
compute specialization than it does alone, which the tuner cannot see.
Pick kernels that do not have the penalty:

- Q-B (1,32768,1280) M=576/672: compute -> bmm t192x256x256 nb2 _pl
  (needs the software-pipelined K loop from #7668, stacked on #7667)
- O-A batched (8,1024,4096) M=1024..1536 step 64: compute -> bmm
  t256x256x256 nb2 (9 rows replaced; kernelName only; the fused-quant
  entry uses the tuned row only with #7667)
- Shared down (5120,2304) M=2048/3072: new rows, bmm t256x256x256 nb2
- O-B (5120,8192) M=2048/3072: new rows, compute t256x256x128 nb2 cm1_cn1

@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 (4)

  1. Make the pipelined loop one explicit switch instead of a silent default flip. pipelined=-1 (kernels/gemm_a8w8_gfx1250.py:180-185) moves every existing mx32 row with tile_k>=256 that fits the VGPR estimate onto the new loop: 425 rows of dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv, 29 of dsv41_batched_...tuned.csv and 9 dense rows of dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv, not just the 5 rows in the description. Their timings were measured on the old loop, and no kernelName can select the old loop again (no suffix maps to 0), so a regression on one shape can't be rolled back in the CSV. Default to 0, keep _pl as the only switch (add it to the dense name regex too), and mark the rows you validated, starting with the two t192x128x256 rows that currently rely on the auto rule.
  2. Add tests for the new path. op_tests/test_gemm_host_dispatch_cache.py: _pl name round-trip (cfg["pipelined"] 1 / -1) and the tile_k<256 rejection, CPU-only. op_tests/test_flydsl_batched_gemm.py (gfx1250): forced _pl vs old loop bit-identical on one ragged-K shape and one shipped _pl row. Today the bit-identity claim rests only on out-of-tree scripts.
  3. Drop speculative/duplicate code. bmm_mx32_kernel_name(..., pipelined=False) has no caller that passes it (batched_gemm_a8w8_gfx1250.py:164). The runner's tile_k < 256 check (:496) repeats the kernel's pipelined == 1 and not pipe_ok check (kernels/gemm_a8w8_gfx1250.py:161). _join4 copies the shuffle in load_a/load_b (:597, :607), so hoist it and use it in all three. _MMA_ORDER repeats _mma_rows' serpentine order.
  4. Small fixes. Reject pipelined values outside {-1, 0, 1}: 2 currently becomes True without the pipe_ok check. The tail comment "their fences wait for fewer outstanding TDM tiles" isn't true for j=0, which waits num_buffers-2 like the steady loop. Fill in the aiter-bot PR Self-Review sections.

Not blocking: merge #7667 first (this branch carries its two commits). Expect a row-level conflict with #7659 in the dsv41 mxscale CSV. CPU probes found no bugs in the new loop: the early LDS bases give the same addresses as load_a/b/sa/sb (564k cases), and for nb 2-4 the tile-level issue/fence/refill order has no read-before-land or refill-before-read hazard.


Reviewed at 8a56033 (own commit only; base #7667 @ 5aa2e85).

yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 17, 2026
A shared expert with an MXFP8 down projection runs the gate_up GEMM (bf16
[M, 2*I]), silu_and_mul (bf16 [M, I]) and quantize_fp8 (e4m3 [M, I] plus
e8m0 [M, I/32]) as three launches with two round trips through HBM.

launch_gemm_a8w8 gains fuse_act_mul / act_limit (batched mxfp8_32 with a
32x32 B scale, fuse_quant_out, no K tail, 64-column multiples per tile and
per wave):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n rows as
  tile_n/64 blocks of [32 gate rows, the matching 32 up rows] through one
  nested TDM view (and the same for the 32x32 scale rows), so a wave's
  64-column block holds gate and up of the same 32 outputs in the same
  lanes. No weight reorder is needed.
- The epilogue rounds the accumulators to bf16, forms
  bf16(silu(min(g, L)) * clamp(u, -L, L)) like aiter silu_and_mul, and
  quantizes each 32-column group to e4m3 + e8m0 (amax floor 1e-10, ceil
  pow2 of amax/448) like the existing fused-quant epilogue. The e4m3 tile
  goes out with one TDM store, the scales one row per thread.

batched_gemm_a8w8_gfx1250 adds run_gate_up_silu_mxfp8_32_gfx1250(XQ, WQ,
x_scale, w_scale, Out, y_scale_out, swiglu_limit, kernel_name=None) and
gate_up_silu_kernel_for(m, n2, k), which returns the tuned tile for M up to
4096 at shapes the tiles divide, or None (the caller keeps the unfused
path, as for larger M or other archs).

Scales match the unfused chain exactly; an e4m3 code can differ by one
step where the epilogue's exp/rcp and silu_and_mul's land on either side of
an e4m3 rounding midpoint.

Tests: op_tests/test_flydsl_batched_gemm.py runs the fused entry against
GEMM + silu_and_mul + quantize_fp8 for every tile bucket, with clamped,
tiny and zero rows.

Depends on ROCm#7668 (and ROCm#7667); this branch carries their commits until they
merge.

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

yhl-amd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @valarLip. Both items, at 96c03e69a:

1. Merge order. Agreed: #7667 goes in first. This branch still sits on #7667's head 68071323b and adds three commits of its own plus two new ones in this round (0c2745d1a, 96c03e69a, below). Once #7667 is merged, I will rebase this PR onto main so it carries only its own commits, and re-check the dsv41 CSV against main at that point.

2. Split-fence comment order. Fixed in 0c2745d1a (comment only): it now says the wave waits, refills the stage tile kt held with tile kt+num_buffers, then reads the first fragments of tile kt+1 and issues the other half, matching issue(kt % num_buffers, kt + num_buffers) followed by _load_frags(nbuf, 0) at :1177-1178. The description's Changes bullet is corrected the same way.

CSV values of the two kept _pl rows (96c03e69a). In the previous push their us / tflops / bw were main's values scaled by a paired ratio. They are now measured on gfx1250 through the MXFP8 GEMM tuner's harness. csrc/gemm_a8w8_mxfp8_bpreshuffle/gemm_a8w8_mxfp8_bpreshuffle_tune.py refuses 32x32 shapes on gfx1250 (its gfx1250 branch is 128x128 only), so a thin subclass replaced only tune()'s candidate list (main's row and the _pl row per key). Everything else is the tuner's: generate_data with the 32x32 scale, run_bmm_flydsl (B = 1, the path a kernelId bmm row runs), the mp_tuner task, default warmup / iterations, error check and throughput formula. 15 processes in total on one GPU, with the candidate order alternated; the last 8 are a balanced batch (4 per order). Op tests were running on other GPUs of the same box during both batches.

In each process the first candidate timed is slowed by the GPU ramping up, so the comparison is position-matched (gfx1250, at 0c2745d1a, which has the same code as this head):

key (M, N, K) _pl vs main's row, both timed first (median) both timed second (median)
576, 32768, 1280 -2.5% -7.1%
768, 32768, 1280 -3.4% -4.7%

In the balanced batch every _pl time is below every main time at the same position.

The earlier batch of 7 processes gives the same sign at both positions (-3.2% to -4.9%). So _pl still leads under the tuner's own timing, and both rows stay. The written us is the median of the _pl row when timed second; tflops / bw follow the tuner's formula, with bw in the unit of the neighbouring gfx1250 rows, and errRatio is the tuner's value (main's kernel gives the same). Note that main's other gfx1250 rows in this table came from #7659's kernel-trace timing, not from this tuner, so absolute us is not directly comparable from row to row; the kernelNames, which drive dispatch, are unchanged.

gfx1250 run at 0c2745d1a: python op_tests/test_flydsl_batched_gemm.py rc = 0 (pipelined K loop all bit-exact for the four PIPELINED_CASES, fused quant epilogue all bit-exact, compute kernelName cases pass). python -m pytest op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py: 41 passed.

The previous head is kept on the fork as bak/7668-pre1117u. Description and Self-Review are updated to 96c03e69a.

@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 — code done; waiting on #7667 and CI (2)

  1. Merge #7667 first, then rebase this onto main. #7667 (68071323b) is still open with changes requested, and this branch still carries its eight commits. Only 1b0cc342e..96c03e69a belong to this PR. Against current main fe40b01fc, git merge-tree is clean, and main has not touched any of the changed files since 0d894387b.
  2. Tighten two kernel comments (optional, can go in the rebase). In aiter/ops/flydsl/kernels/gemm_a8w8_gfx1250.py:
    • :1027-1029 says the per-stage LDS read bases are formed a whole tile ahead. That is only true when early holds. With a_preshuffle, a_scale_preshuffled or warp_tile_n % 32 != 0, _stage_bases forms them inline. Start the sentence with "When early,".
    • :1195-1198 says tail tile j waits for max(num_buffers - 2 - j, 0) tiles. The last tail tile (j = nb-1, last=True) has no fence, so the max(..., 0) clamp never applies. Say that, or drop the clamp.

I found nothing else. The full review at this head re-checked the DS (_NLD) and tensor wait counts, the split fence for nb 2/3/4, the stage refill vs next-stage reads, the fragment carry across K tiles, ragged K, and the early LDS bases. All of these check out. pipelined=0 leaves the old loop unchanged, pipelined is in both specialization keys, and check_pipelined_k_loop is the single gate. A CPU probe shows that both CSV rows parse to pipelined=1 and pass the check. Their errRatio of 0.0027 is under the tuner's 0.05 threshold, and 19 other gfx1250 rows in the table also have a nonzero errRatio. CI: everything that has reported passes. The py3.12 wheel build is pending and the MI35X standard tests have not reported yet.


Re-reviewed at 96c03e6 (own commits 1b0cc34..96c03e6; base #7667 @ 6807132). Already fixed: the split-fence comment at :1011-1016 now follows the code order (refill, then _load_frags(nbuf, 0), at :1177-1178). The two _pl rows now carry us / tflops / bw measured through the tuner's harness instead of scaled values.

yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 17, 2026
check_pipelined_k_loop rejected a _pl kernelName with tile_k < 256 (one
128-deep k-step per K-tile). The pipelined loop does not need two k-steps:
with one, the last-k-step branch is the only one taken, so the next tile's
first fragments are read and its stage refilled during the second half of
this tile's WMMAs, behind the same split fence. Every accumulator still
sees its k-steps in the same order with the same operands, so the output is
bit-identical to the single-fence loop.

Only a kernelName that ends in _pl selects the loop, so nothing changes for
existing rows. It lets 128-deep tiles that keep two workgroups per CU (for
example t96x256x128 mw1 nw4) overlap their LDS reads with the WMMAs.

Tests: test_gemm_host_dispatch_cache.py drops the tile_k rejection;
test_flydsl_batched_gemm.py compares _pl with the single-fence loop bit for
bit at tile_k = 128 (b = 8 and b = 1 decode shapes, and a ragged K).

Depends on ROCm#7668 (the _pl loop, on ROCm#7667); this branch carries their
commits until they merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 17, 2026
A shared expert with an MXFP8 down projection runs the gate_up GEMM (bf16
[M, 2*I]), silu_and_mul (bf16 [M, I]) and quantize_fp8 (e4m3 [M, I] plus
e8m0 [M, I/32]) as three launches with two round trips through HBM.

launch_gemm_a8w8 gains fuse_act_mul / act_limit (batched mxfp8_32 with a
32x32 B scale, fuse_quant_out, no K tail, 64-column multiples per tile and
per wave):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n rows as
  tile_n/64 blocks of [32 gate rows, the matching 32 up rows] through one
  nested TDM view (and the same for the 32x32 scale rows), so a wave's
  64-column block holds gate and up of the same 32 outputs in the same
  lanes. No weight reorder is needed.
- The epilogue rounds the accumulators to bf16, forms
  bf16(silu(min(g, L)) * clamp(u, -L, L)) like aiter silu_and_mul, and
  quantizes each 32-column group to e4m3 + e8m0 (amax floor 1e-10, ceil
  pow2 of amax/448) like the existing fused-quant epilogue. The e4m3 tile
  goes out with one TDM store, the scales one row per thread.

batched_gemm_a8w8_gfx1250 adds run_gate_up_silu_mxfp8_32_gfx1250(XQ, WQ,
x_scale, w_scale, Out, y_scale_out, swiglu_limit, kernel_name=None) and
gate_up_silu_kernel_for(m, n2, k), which returns the tuned tile for M up to
4096 at shapes the tiles divide, or None (the caller keeps the unfused
path, as for larger M or other archs).

Scales match the unfused chain exactly; an e4m3 code can differ by one
step where the epilogue's exp/rcp and silu_and_mul's land on either side of
an e4m3 rounding midpoint.

Tests: op_tests/test_flydsl_batched_gemm.py runs the fused entry against
GEMM + silu_and_mul + quantize_fp8 for every tile bucket, with clamped,
tiny and zero rows.

Depends on ROCm#7668 (and ROCm#7667); this branch carries their commits until they
merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 17, 2026
A shared expert with an MXFP8 down projection runs the gate_up GEMM (bf16
[M, 2*I]), silu_and_mul (bf16 [M, I]) and quantize_fp8 (e4m3 [M, I] plus
e8m0 [M, I/32]) as three launches with two round trips through HBM.

launch_gemm_a8w8 gains fuse_act_mul / act_limit (batched mxfp8_32 with a
32x32 B scale, fuse_quant_out, no K tail, 64-column multiples per tile and
per wave):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n rows as
  tile_n/64 blocks of [32 gate rows, the matching 32 up rows] through one
  nested TDM view (and the same for the 32x32 scale rows), so a wave's
  64-column block holds gate and up of the same 32 outputs in the same
  lanes. No weight reorder is needed.
- The epilogue rounds the accumulators to bf16, forms
  bf16(silu(min(g, L)) * clamp(u, -L, L)) like aiter silu_and_mul, and
  quantizes each 32-column group to e4m3 + e8m0 (amax floor 1e-10, ceil
  pow2 of amax/448) like the existing fused-quant epilogue. The e4m3 tile
  goes out with one TDM store, the scales one row per thread.

batched_gemm_a8w8_gfx1250 adds run_gate_up_silu_mxfp8_32_gfx1250(XQ, WQ,
x_scale, w_scale, Out, y_scale_out, swiglu_limit, kernel_name=None) and
gate_up_silu_kernel_for(m, n2, k), which returns the tuned tile for M up to
4096 at shapes the tiles divide, or None (the caller keeps the unfused
path, as for larger M or other archs).

Scales match the unfused chain exactly; an e4m3 code can differ by one
step where the epilogue's exp/rcp and silu_and_mul's land on either side of
an e4m3 rounding midpoint.

Tests: op_tests/test_flydsl_batched_gemm.py runs the fused entry against
GEMM + silu_and_mul + quantize_fp8 for every tile bucket, with clamped,
tiny and zero rows.

Depends on ROCm#7668 (and ROCm#7667); this branch carries their commits until they
merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 17, 2026
check_pipelined_k_loop rejected a _pl kernelName with tile_k < 256 (one
128-deep k-step per K-tile). The pipelined loop does not need two k-steps:
with one, the last-k-step branch is the only one taken, so the next tile's
first fragments are read and its stage refilled during the second half of
this tile's WMMAs, behind the same split fence. Every accumulator still
sees its k-steps in the same order with the same operands, so the output is
bit-identical to the single-fence loop.

Only a kernelName that ends in _pl selects the loop, so nothing changes for
existing rows. It lets 128-deep tiles that keep two workgroups per CU (for
example t96x256x128 mw1 nw4) overlap their LDS reads with the WMMAs.

Tests: test_gemm_host_dispatch_cache.py drops the tile_k rejection;
test_flydsl_batched_gemm.py compares _pl with the single-fence loop bit for
bit at tile_k = 128 (b = 8 and b = 1 decode shapes, and a ragged K).

Depends on ROCm#7668 (the _pl loop, on ROCm#7667); this branch carries their
commits until they merge.

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

yhl-amd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 1b573ced8 and 292a532f8 on top of 96c03e69a; #8057 and #8058 are rebased onto them.

Why the automatic pick comes back. With _pl as the only switch, every existing mxfp8_32 generic row without the suffix moved to the single-fence K loop. Those rows, including the DSv4.1 decode rows of the serving tables, were chosen while the automatic rule was in effect, so dropping the rule silently changed the kernel they run (and the first service start after that compiles variants that were never built before). Marking every such row with _pl would mean editing a large number of rows across tables, and every future retune would have to remember the suffix.

What changed, and how it keeps the earlier review points.

  • The kernel's pipelined constexpr stays 0 / 1 and check_pipelined_k_loop() stays the single gate; the kernel does not accept -1.
  • The pick lives on the host, in one place: default_pipelined_k_loop() in mxfp8_bpreshuffle_gemm_gfx1250.py, with the conditions of the earlier rule (mxfp8_32, no preload, no cluster, split_k 1, tile_k >= 256, and the accumulators plus the two in-flight fragment sets within the VGPR budget). The batched parser applies it to a name without a suffix; the 2-D path applies it in _resolved_wmma_config after cluster_m is fitted to M, so a row whose cluster drops to 1 is judged on the config that actually launches.
  • Rolling back one shape in the CSV: a new _nopl suffix pins a row to the single-fence loop, and _pl still pins it to the pipelined loop, so any row can be moved either way without a code change.
  • Both loops give the same output bits, so the pick only affects speed.

Tests.

  • CPU (test_gemm_host_dispatch_cache.py): _pl / _nopl / plain round trip for batched and 2-D names, the rule's conditions (tile_k 128, cluster, split_k > 1, preload, configs on both sides of the VGPR budget), and the 2-D pick after the cluster fit.
  • gfx1250 (test_flydsl_batched_gemm.py): PIPELINED_CASES now compare name + "_nopl" with name + "_pl", since a plain name may already run the pipelined loop; FUSED_QUANT_TILES runs t128x128 with _nopl and with _pl.
  • At 292a532f8 (checked through [FlyDSL] [gfx1250] mx32 GEMM: the _pl K loop also runs at tile_k = 128 (on #7668) #8058's head, which adds only its own commit): python op_tests/test_flydsl_batched_gemm.py exits 0 on gfx1250 (pipelined K loop and fused quant epilogue all bit-exact), and python -m pytest op_tests/test_gemm_host_dispatch_cache.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py passes.
  • A CPU check over the DSv4.1 serving tables: every mxfp8_32 row picks the same K loop as under the earlier automatic rule.

The previous head is kept on the fork as bak/7668-pre1118. Description and Self-Review are updated to 292a532f8.

@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. Drop the default pick again: a kernelName without _pl must run the single-fence loop. 1b573ced8 brings back the silent flip that round 1 asked you to remove. default_pipelined_k_loop() is applied in batched_gemm_a8w8_gfx1250.py:115-128 and mxfp8_bpreshuffle_gemm_gfx1250.py:630-641. It moves 487 untagged rows on main onto the new loop: 442 in dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv, 36 in dsv41_batched_..._tuned.csv and 9 in dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv. These rows were not "tuned with the automatic rule". Main has no pipelined loop, so every one of them was timed on the single-fence loop. On 11-14 you agreed that "every existing row keeps the loop it was timed on" and that only a few rows had been validated at serving shapes. Your own 11-17 re-pick also shows the loop is not a free win. At M576 N5120 K8192, plain t128x128x256 nb4 beat its _pl version, and 30 rows of that tile in the dsv41 table now flip. _pl lost or tied on 4 of 6 keys. The 11-18 "CPU check" only compares against this PR's own earlier rule, not against main. The fix:
    • remove default_pipelined_k_loop, PIPELINED_DEFAULT and _nopl;
    • revert PIPELINED_CASES / FUSED_QUANT_TILES to compare name with name + "_pl";
    • move rows to _pl only after retiming them, with numbers, in their own PR. Rows that #8057 / #8058 need can carry _pl there.
  2. Merge #7667 first, then rebase onto main. #7667 (68071323b) is still open with changes requested. This branch still carries its eight commits, and only 1b0cc342e..292a532f8 belong here.

Optional, still open from last round: in kernels/gemm_a8w8_gfx1250.py, :1028 should start with "When early,". At :1196-1206 the last tail tile has no fence, so the max(..., 0) clamp never applies; drop it or say so.

Nothing else blocks. The kernel code is unchanged since 96c03e69a (only the docstring at :52-53 changed). -1 never reaches the kernel or a cache key. CI: 18 checks pass; the 8 MI35X standard shards and OPUS are still pending.


Re-reviewed at 292a532 (own commits 1b0cc34..292a532 on #7667 @ 6807132; the head moved by two new commits on top of 96c03e6, not a rebase). Already fixed: nothing new since 96c03e6; the earlier rounds' items are still fixed.

@yhl-amd

yhl-amd commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip Thanks for the review. Rebased onto #7667's current head (dfc62154e), and the default pick is gone. New head: e9476df89.

1. Default pick dropped. A kernelName without _pl runs the single-fence loop again, in the batched and the 2-D paths.

  • default_pipelined_k_loop, PIPELINED_DEFAULT and _nopl are removed. I dropped the two commits that added them (1b573ced8, 292a532f8) from the branch instead of reverting them on top. Their code is not in the new head.
  • PIPELINED_CASES and FUSED_QUANT_TILES compare name with name + "_pl" again.
  • New tests in e9476df89 (op_tests/test_gemm_host_dispatch_cache.py, CPU):
    • test_mx32_name_without_pl_runs_single_fence_loop: 2-D names that meet every condition of the pipelined loop (tile_k 256, split_k 1, before and after cluster_m is fitted to M) resolve to pipelined=0 without _pl and to 1 with it. _nopl and other suffixes do not parse.
    • test_mx32_shipped_rows_take_the_k_loop_their_name_asks: every mxfp8_32 kernelName under aiter/configs runs the pipelined loop exactly when it ends in _pl.
  • The only _pl rows are still the two N=32768, K=1280 rows at M576 / M768. Any other row moves to _pl only in its own PR, after it is re-timed. [FlyDSL] [gfx1250] gate_up GEMM with a fused SwiGLU + MXFP8 quant epilogue (on #7668) #8057 / [FlyDSL] [gfx1250] mx32 GEMM: the _pl K loop also runs at tile_k = 128 (on #7668) #8058 will carry the rows they need.

2. Rebase. The branch is #7667 dfc62154e plus this PR's six commits (0a8c5e426..e9476df89). There were two conflicts:

Optional items (both in e9476df89, comments only):

  • kernels/gemm_a8w8_gfx1250.py ~:1028 now starts with "When early," and says that otherwise _stage_bases forms the bases inline.
  • The tail comment now says that the last tail tile (last=True) has no fence, so max(..., 0) only keeps its unused count non-negative. I kept the clamp rather than pass -1 there.

Validation at e9476df89:

@yhl-amd

yhl-amd commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Merged main into the branch to clear a new conflict with #8291 (head 910f36881). #7667's commits are unchanged, and the only conflict was the module docstring of op_tests/test_gemm_host_dispatch_cache.py. I kept main's text and this PR's _pl bullet. CPU host tests pass (same single CUDA-only failure as before), black and ruff are clean. No idle gfx950 GPU was available, so the GPU rerun was skipped; gfx1250 is still pending.

yhl-amd and others added 6 commits November 25, 2026 23:51
…ed entry runs the tuned row

Fused MXFP8 epilogue: when the warp tile holds an even number of 16-column
WMMA tiles (even wmma_n_rep), the group-32 quant reads the accumulators
instead of staging the bf16 C tile in LDS and re-reading it per group. A lane
holds 8 consecutive columns of one row per 16x16 tile, so a 32-column group
is two adjacent tiles across lanes l and l^16 and its amax is one
shuffle_xor(16). Values are rounded to the output dtype first, exactly as the
bf16 path stores them, so the e4m3 codes and e8m0 scales are unchanged; the
e4m3 and scale bytes still go through LDS for the TDM store. An odd
wmma_n_rep keeps the LDS-staged quant. The epilogue has three peer branches
(bf16 store, accumulator quant, LDS-staged quant) with the quant setup and
the group-32 scale step shared by the two quant branches.

batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant looks the shape up in the
same preshuffle table as the bf16 entry and passes a flydsl row's kernelName
to the runner, so both entries run the same tuned tile. No row, an opus row
or a compute-kernel row leaves the tile to the runner; any other name is
passed through, so a name the runner does not accept raises, as for the bf16
entry.

Tests: op_tests/test_flydsl_batched_gemm.py checks the fused quant on tuned
tiles that pin each epilogue branch (two LDS-staged, seven accumulator) at
ragged M against quantize_fp8 of the bf16 GEMM on the same tile;
op_tests/test_bmm_a8w8_fused_quant_tuned_row.py is a CPU test of the
tuned-row lookup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the merge with main's gfx950 fused quant, one _fused_quant_tuned_kernel
serves both arches. The CPU test now also checks a gfx950 flydsl row (passed
through) and a gfx950 opus row or no row (runner's choice).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The batched mxfp8_32 kernel's accumulator quant and the 256x256 compute
kernel's fused epilogue emitted the same per-group step (round to the output
dtype, h0/h1 amax with one shuffle_xor(16), 1e-10 floor, RoundUp e8m0,
scaled fp8 conversion, e4m3 and scale bytes into LDS) and the same scale-row
store. Both now call emit_mxfp8_acc_pair_to_lds and
emit_mxfp8_scale_rows_store in kernels/quant_utils.py, next to
emit_mx_e8m0_scale; emit_mxfp8_group32_scale (floor + RoundUp scale) is also
used by the batched kernel's LDS-staged quant. Each kernel keeps its own e4m3
TDM store. No change in the emitted code is intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FUSED_QUANT_TILES adds t64x32x512 mw4 nw1 (one quant group per tile row) and
t160x128x256 nw2 (more tile rows than threads, so the scale rows take a
second pass), both shipped DSv4.1 rows on the accumulator branch that no test
pinned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The scale-row store loops ceil(tile_m / block) times, so a thread copies
rows tid, tid + block, ...; say that in the helper docstring and at both
kernel call sites instead of "one row per thread". In quant_utils, the
native-scale helper no longer refers to a function that does not exist,
and the module docstring names the dtypes _DTYPE_CFG actually defines.
The gfx950 tuned-row test uses the DSv4 batched preshuffle table's row for
its shape. Comments and test data only; no kernel change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…red group-32 scale

_fused_quant_tuned_kernel imports the gfx1250 compute-kernel name check
only on gfx1250, after the table lookup; gfx950 returns the flydsl row's
name directly, as before the merge with the gfx1250 lookup. The gfx950 bmm
fused epilogue calls emit_mxfp8_group32_scale instead of its own copy of
the same steps (1e-10 floor, RoundUp e8m0, f32 scale). Two docstrings no
longer say the fused epilogue always quantizes the bf16 C tile.

Tests: FUSED_QUANT_TILES also pins the DSv4.1 wo_a tuned tiles the fused
entry runs (t192x128x256, t128x256x256 mw1 nw4, t96x128x256, and the
LDS-staged t32x32x512); the gfx1250 tuned-row fixture uses a CU count
other than the gfx950 one so the lookup must forward the caller's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-mx32-gemm-pipelined-kloop branch from c9ce4ea to b21a4a9 Compare November 25, 2026 16:14
@yhl-amd

yhl-amd commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Re-stacked on the rebased #7667 (f1a3bc230, on main 3fd42598c). The merge of main is gone, and only this PR's six commits remain (head b21a4a943, previous head kept as bak/7668-pre1125a). The conflicts were only in test-file docstrings and a test helper, and the CSV diff against main is still the two _pl rows. CPU host tests pass (the CUDA-only failures match main), and black and ruff are clean. gfx1250 is still pending.

yhl-amd and others added 7 commits November 27, 2026 11:26
Two LDS-staged tiles (t16x64 nw4, t32x32 nw2) and seven accumulator tiles,
as the tuple and the module docstring list them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fragments of k-step g+1 are read from LDS while the WMMAs of k-step g
run, across K-tile boundaries too, so LDS reads, WMMAs and the TDM refill
overlap. The fence before the next K-tile is split into signal/wait (the
primitives the 256x256 compute kernel already uses) around the two halves of
the last k-step's WMMAs, and the per-stage LDS read bases are formed a tile
ahead. Every accumulator sees its k-steps in the same order with the same
operands, so results are bit-identical to the single-fence loop.

New pipelined constexpr, appended after fuse_quant_out: -1 (default)
takes the pipelined loop for mxfp8_32, no scale preload, no cluster,
split_k 1, tile_k >= 256 when the accumulators plus two in-flight fragment
sets fit the register estimate; 1 forces it (batched kernel names may end
in _pl; tile_k < 256 is rejected), 0 keeps the old loop. No new
environment variable.

The DSv4.1 mxscale table rows for N=5120, K=8192 at M 672/768 and for
N=32768, K=1280 at M 576/672/768 are replaced in place with tiles that
use the pipelined loop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pipelined constexpr now defaults to 0 and takes only 0 or 1; the
automatic rule that moved every eligible mx32 tile onto the new loop is
gone, so existing tuned rows keep the loop they were timed on. A trailing
_pl in a batched or 2-D mxfp8_32 kernelName is the only way to select it,
and check_pipelined_k_loop() is the single place that rejects it where the
loop does not apply (it replaces the batched runner's tile_k check).

The DSv4.1 rows validated with the pipelined loop now carry _pl: N=5120,
K=8192 at M 576 / 672 / 768 (the latter two are the t192x128x256 rows that
relied on the automatic rule); the N=32768, K=1280 rows already did.

Also drop the unused pipelined argument of bmm_mx32_kernel_name, share the
fragment join of load_a / load_b and the serpentine WMMA order with the
pipelined loop, and fix the tail fence comment.

Tests: CPU checks of the _pl name round trip (batched and 2-D) and of the
rejections in op_tests/test_gemm_host_dispatch_cache.py; on gfx1250,
op_tests/test_flydsl_batched_gemm.py compares _pl with the single-fence loop
bit for bit on a ragged K and on a shipped _pl row, and runs the fused quant
epilogue on a _pl tile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in's tile; test nb3/nb4

Re-timed the pipelined rows against the retuned tiles now on main for the
six DSv4.1 2-D keys on one gfx1250 box. The pipelined t192x256x256 tile stays
ahead at M 576 and 768 for N=32768, K=1280; the other four keys keep main's
rows. PIPELINED_CASES also compares the pipelined and single-fence loops on a
three-buffer and a four-buffer tile, where the tail fences differ from the
steady loop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the fence wait the wave refills the stage tile kt held and then reads
the first fragments of tile kt+1; the comment had the two steps swapped.
Comment only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The us, tflops and bw of the two kept _pl rows (N=32768, K=1280 at M 576 and
768) were main's values scaled by a paired ratio. Replace them with values
measured on gfx1250 through the MXFP8 GEMM tuner's harness (its data
generation, B=1 batched run path, mp_tuner timing, error check and
throughput formula), bw in the unit of the neighbouring gfx1250 rows. The
kernelName of both rows is unchanged, so dispatch is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_pl` stays the only switch of the software-pipelined K loop: a kernelName
without it runs the single-fence loop it was tuned on, in the batched and
the 2-D paths alike. CPU tests pin that:

- untagged 2-D names on which the pipelined loop would apply (tile_k 256,
  split_k 1, before and after cluster_m is fitted to M) resolve to the
  single-fence loop, and their `_pl` names to the pipelined one; no other
  suffix parses;
- every mxfp8_32 kernelName in the shipped tuned tables runs the pipelined
  loop exactly when it ends in `_pl`.

Kernel comments: the early per-stage LDS bases are formed a tile ahead only
when `early` holds, and the tail's max(..., 0) only touches the last tile's
unused fence count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-mx32-gemm-pipelined-kloop branch from b21a4a9 to 1683901 Compare November 27, 2026 03:31
@yhl-amd

yhl-amd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Re-stacked on #7667 d4016d527 (head 1683901ce, previous head kept as bak/7668-pre1127a). Only this PR's six commits were replayed. The one conflict was the same FUSED_QUANT_TILES header comment, which now uses #7667's nine-tile wording plus one sentence for this PR's _pl entry. No code changed. black and ruff are clean, and gfx1250 is still pending.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants