Skip to content

[FlyDSL] [gfx1250] Compute GEMM: fused MXFP8 epilogue; untuned prefill-sized batched mxfp8_32 runs the compute kernel - #7673

Merged
valarLip merged 1 commit into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-bmm-compute-fused-quant-large-m
Nov 19, 2026
Merged

valarLip merged 1 commit into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-bmm-compute-fused-quant-large-m

Conversation

@yhl-amd

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

Copy link
Copy Markdown
Contributor

#7659 (and #7178 before it) is merged, so this PR is now one commit on main (gfx1250 compute GEMM: fused MXFP8 epilogue; untuned prefill-sized bmm runs it).

Summary

  • gemm_a8w8_256x256_gfx1250.py: new fuse_quant_out constexpr. The compute kernel quantizes its C tile to group-32 MXFP8 in the epilogue and writes e4m3 C plus a row-major e8m0 scale, the same contract as the fused epilogue of the generic batched kernel ([FlyDSL] [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #7178).
  • mxfp8_bpreshuffle_gemm_gfx1250.py: the dense mxfp8_32 runner takes y_scale_out and launches the fused variant (compute kernels with split_k 1 and no persistent tiles; anything else raises).
  • batched_gemm_a8w8_gfx1250.py:
  • op_tests/test_flydsl_batched_gemm.py: two prefill-sized M in the gfx1250-strict fused-quant defaults, so both entries go through the compute kernel there. The full-suite defaults already include prefill-sized M.

Motivation

#7659 lets tuned rows name the compute kernel for batched 32x32 GEMMs, and tunes the DSv4.1 Flash O-A (wo_a) prefill row. Two gaps remain for wo_a:

  1. The fused-quant entry (batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant, [FlyDSL] [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #7178) can only run the generic batched kernel: the compute kernel has no quant epilogue, and the runner's compute branch refuses y_scale_out. So prefill wo_a either loses the compute kernel or loses the fused quant.
  2. Prefill M between the decode rows and the tuned prefill row has no row, so it falls back to the generic batched heuristic.

Changes

  • Fused epilogue: values are rounded to the output dtype first (as the bf16 store does), the group amax is one cross-lane max between lanes l and l^16 (a 32-column group is two adjacent 16x16 tiles of one wave), and emit_mx_e8m0_scale / emit_cvt_scalef32_pk8_fp8_f32 produce the codes. So the output matches quantize_fp8 of the bf16 output. The e4m3 tile goes out through LDS as one TDM store; the scale is written row by row. The scale pointer reuses arg_out, which the non-split-K path does not use, so the launch arguments stay the same.
  • It sits in its own const_expr branch next to the persistent C-relocation path. With the default fuse_quant_out=False the kernels compile as before.
  • Routing: pick_bmm_mx32_compute_kernel_name(b, m, n, k) returns the compute name only for M above 1024 and shapes the kernel takes (N a multiple of the cluster's N, K a whole number of K-pairs). cluster_m is 1, so every M-tile count fits. No persistent tiles, so the fused epilogue can use the same config. A tuned row still wins: the runner only asks when no kernel name is given.
  • No new environment variables.

Merge order

Validation

  • gfx1250, this head: python3 op_tests/test_flydsl_batched_gemm.py passes. The explicit compute kernel cases (including [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659's test_compute_operand_guards) pass, and the fused quant epilogue is bit-exact against quantize_fp8 of the bf16 output for every default shape, including the M that take the new compute route ("fused quant epilogue ALL BIT-EXACT").
  • CPU, this head: with kernel launches stubbed, fused calls run on the split_k 1 non-persistent compute kernel and raise on the persistent and split-K ones, and untuned M above 1024 routes to the compute kernel for both entries; op_tests/test_bmm_a8w8_fused_quant_supported.py passes.
  • An earlier version of this change also ran in a gfx1250 DSV4.1-Flash serving stack with all requests completed, and CUDA graph replay matched eager.

PR Self-Review

Reviewed revision

677187d

Behavior and intent

  • Branch: main b5b4bf978 plus one commit; the commit is the same patch as on the previous head (rebased after [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659 merged).
  • Before: the 256x256 compute kernel had no quant epilogue; the batched runner raised ValueError for any fused call on a compute kernel name; untuned prefill-sized M ran the generic batched heuristic tile.
  • After: compute kernels with split_k 1, no persistent tiles and row-major A take y_scale_out and write e4m3 C plus the e8m0 scale, matching quantize_fp8 of the bf16 output; split-K, persistent or preshuffled-A compute kernels still raise the same ValueError. Without a kernel name, M above 1024 on shapes the kernel takes runs the compute kernel for both the bf16 and the fused entry.
  • Decode-sized M, tuned kernel names and the default (non-fused) compute kernels are unchanged. No new environment variable.

Validation and unverified scope

  • gfx1250, this head: python3 op_tests/test_flydsl_batched_gemm.py exits 0. The explicit compute kernel cases and test_compute_operand_guards pass; every fused-quant shape reports 0 scale and 0 fp8 mismatches against quantize_fp8 of the unfused bf16 output, including M 4096 and 16384, which take the new untuned compute route.
  • CPU, this head, kernel launches stubbed: pick_bmm_mx32_compute_kernel_name returns None for decode M and for N/K the kernel cannot take, and the compute name otherwise; a fused call runs on the split_k 1 non-persistent compute kernel and raises ValueError on the persistent and split-K ones; untuned M above 1024 routes to the compute kernel for both entries. python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py: 2 passed.
  • Offline gfx1250 compile at an earlier port: the existing compute variants give ISA identical to [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659; the new fused variants compile with no VGPR spill and no scratch. The kernel diff is unchanged since then (same patch).
  • black 26.10.1 and ruff clean on the changed files.
  • Unverified: the gfx1250-strict defaults (M 1025 and 2048) were not run on a gfx1250-strict device; this run used the gfx1250 full suite, which reaches the same compute route at larger M. No gfx950 impact: the changed paths are gfx1250-only.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

  • Only gfx1250 mxfp8_32 batched and dense compute paths change. The fused epilogue is selected only when y_scale_out is given; the batched runner checks the compute kernel name (split_k 1, no persistent tiles, row-major A) and the dense runner checks it again together with a 1-byte Out with unit column stride, a row stride divisible by 32 and an exactly sized, contiguous, 8-byte-aligned e8m0 scale buffer, so unsupported inputs raise before launch. Auto-routing needs no kernel name, M above 1024, N a multiple of the 1x4 cluster's N, K a multiple of the K tile and at least 512 and a whole number of K pairs; otherwise the previous heuristic runs.

Changed op tests

  • op_tests/test_flydsl_batched_gemm.py: the gfx1250-strict fused-quant default shapes add M = 1025 and 2048 (N and K of DSv4.1 wo_a), so on that arch the bf16 reference and the fused entry both take the new compute route and must stay bit-identical to quantize_fp8. The module docstring says so, and the test_compute_operand_guards docstring now names why its persistent compute case has no epilogue (the test itself is [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659's and unchanged). Not redundant: before this PR the gfx1250-strict defaults stopped at decode-sized M, so the compute fused epilogue was not reached there.

🤖 Generated with Claude Code

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-compute-fused-quant-large-m branch from d33ce97 to 374fb97 Compare November 10, 2026 03:08
@yhl-amd

yhl-amd commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Updated the #7178 merge to its current head (352446c2f); #7659 is unchanged at cd9cb7486. The last commit is unchanged in content. 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. Still a draft until it has run on gfx1250.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-compute-fused-quant-large-m branch from 374fb97 to 4c1fabc Compare November 11, 2026 03:38
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased: #7659's current head (76b2f26) + a merge of #7178's current head (803a3cd, no conflicts) + the same single commit on top, which applied cleanly (its only overlap is op_tests/test_woa_fused_quant.py, where #7178 now returns 0 on other archs; this PR still only adds two prefill-sized M to the default list). Since #7178 now has the sys.path fix, nothing extra is needed for that test under CI. Still a draft until the gfx1250 run.

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; merges cleanly with main and with #7667.

amd-ruitang3
amd-ruitang3 previously approved these changes Nov 17, 2026
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-compute-fused-quant-large-m branch from 4c1fabc to d430716 Compare November 17, 2026 07:50
@yhl-amd

yhl-amd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the current #7659 head 21a8b563d; new head d430716d4 (#7659 plus one commit). The old head 4c1fabcbe is kept as bak/7673-pre1117x on the fork.

@yhl-amd
yhl-amd marked this pull request as ready for review November 17, 2026 09:41
@yhl-amd
yhl-amd requested a review from a team November 17, 2026 09:41
@aiter-bot

aiter-bot commented Nov 17, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 677187d92d3c · 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: main `b5b4bf978` plus one commit; the commit is the same patch as on the previous head (rebased after #7659 merged).
- Before: the 256x256 compute kernel had no quant epilogue; the batched runner raised `ValueError` for any fused call on a compute kernel name; untuned prefill-sized M ran the generic batched heuristic tile.
- After: compute kernels with split_k 1, no persistent tiles and row-major A take `y_scale_out` and write e4m3 C plus the e8m0 scale, matching `quantize_fp8` of the bf16 output; split-K, persistent or preshuffled-A compute kernels still raise the same `ValueError`. Without a kernel name, M above 1024 on shapes the kernel takes runs the compute kernel for both the bf16 and the fused entry.
- Decode-sized M, tuned kernel names and the default (non-fused) compute kernels are unchanged. No new environment variable.

Validation and unverified scope

- gfx1250, this head: `python3 op_tests/test_flydsl_batched_gemm.py` exits 0. The explicit compute kernel cases and `test_compute_operand_guards` pass; every fused-quant shape reports 0 scale and 0 fp8 mismatches against `quantize_fp8` of the unfused bf16 output, including M 4096 and 16384, which take the new untuned compute route.
- CPU, this head, kernel launches stubbed: `pick_bmm_mx32_compute_kernel_name` returns None for decode M and for N/K the kernel cannot take, and the compute name otherwise; a fused call runs on the split_k 1 non-persistent compute kernel and raises `ValueError` on the persistent and split-K ones; untuned M above 1024 routes to the compute kernel for both entries. `python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py`: 2 passed.
- Offline gfx1250 compile at an earlier port: the existing compute variants give ISA identical to #7659; the new fused variants compile with no VGPR spill and no scratch. The kernel diff is unchanged since then (same patch).
- black 26.10.1 and ruff clean on the changed files.
- Unverified: the gfx1250-strict defaults (M 1025 and 2048) were not run on a gfx1250-strict device; this run used the gfx1250 full suite, which reaches the same compute route at larger M. No gfx950 impact: the changed paths are gfx1250-only.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

- Only gfx1250 mxfp8_32 batched and dense compute paths change. The fused epilogue is selected only when `y_scale_out` is given; the batched runner checks the compute kernel name (split_k 1, no persistent tiles, row-major A) and the dense runner checks it again together with a 1-byte Out with unit column stride, a row stride divisible by 32 and an exactly sized, contiguous, 8-byte-aligned e8m0 scale buffer, so unsupported inputs raise before launch. Auto-routing needs no kernel name, M above 1024, N a multiple of the 1x4 cluster's N, K a multiple of the K tile and at least 512 and a whole number of K pairs; otherwise the previous heuristic runs.

Changed op tests

- `op_tests/test_flydsl_batched_gemm.py`: the gfx1250-strict fused-quant default shapes add M = 1025 and 2048 (N and K of DSv4.1 wo_a), so on that arch the bf16 reference and the fused entry both take the new compute route and must stay bit-identical to `quantize_fp8`. The module docstring says so, and the `test_compute_operand_guards` docstring now names why its persistent compute case has no epilogue (the test itself is #7659's and unchanged). Not redundant: before this PR the gfx1250-strict defaults stopped at decode-sized M, so the compute fused epilogue was not reached there.

🤖 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
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

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

… runs it

The 256x256 compute kernel can now quantize its C tile to group-32 MXFP8 in
the epilogue (fuse_quant_out), the way the generic batched kernel already does
for the fused wo_a entry: values are rounded to the output dtype, the group
amax is one cross-lane max between lanes l and l^16, the e4m3 tile goes out
through LDS as one TDM store and the e8m0 scale row by row. The codes match
quantize_fp8 of the bf16 output. Default constexprs keep the existing kernels
unchanged.

The dense mxfp8_32 runner forwards y_scale_out to it (compute kernels with
split_k 1 and no persistent tiles only), and the batched runner passes
y_scale_out through its compute path instead of rejecting it; only compute
kernels without the epilogue (split-K, persistent tiles, preshuffled A) still
raise.

Without a kernel name, a batched mxfp8_32 call with M above the decode range
(1024 rows) now runs the compute kernel (256x256x128, two buffers, 1x4
cluster) when N and K fit it; decode-sized M and calls with a tuned kernel
name keep their current kernels. This covers the prefill wo_a GEMM, bf16 and
fused-quant entries alike, between the decode rows and the tuned prefill row.

op_tests/test_flydsl_batched_gemm.py adds two prefill-sized M to the
gfx1250-strict fused-quant defaults so both entries go through the compute
kernel there; the full-suite defaults already reach it at M 4096 and 16384.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-compute-fused-quant-large-m branch from d430716 to 677187d Compare November 17, 2026 09:56
@yhl-amd

yhl-amd commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main b5b4bf978 now that #7659 is merged; new head 677187d92 is main plus one commit. The old head d430716d4 is kept as bak/7673-pre1117y on the fork.

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