Skip to content

[FlyDSL] [gfx1250][MoE] Row-major A1 e8m0 scale store for decode MoE (drop scattered preshuffle) - #6357

Merged
junhaha666 merged 2 commits into
ROCm:mainfrom
karverma-amd:karverma-amd/gfx1250-moe-decode-rowmajor-ascale
Oct 12, 2026
Merged

junhaha666 merged 2 commits into
ROCm:mainfrom
karverma-amd:karverma-amd/gfx1250-moe-decode-rowmajor-ascale

Conversation

@karverma-amd

Copy link
Copy Markdown
Contributor

On the gfx1250 EP MoE decode path (mori FP4 dispatch), the A1 scale-preshuffle
kernel (moe_fused_quant_preshuffle_routeks, the prequantized full-row copy
branch) scattered each grouped row's e8m0 scales into gemm1's 16-row-interleaved
layout at a stride of wmma_rep*16 dwords — i.e. one dword per cache line.

gemm1 already supports reading A-scales row-major (row_major_ascale,
used today by the compact-dispatch path). This PR makes the mori-dispatch decode
path write each grouped row's scales contiguously (row*(K/32) + g) and lets
gemm1 do the 16-row interleave on its LDS→register read instead, removing the
uncoalesced scale scatter.

Gating (no other kernels impacted)

Row-major is enabled only for the decode kernel:
_prequantized and not _compact and not _fuse_ep_route_quant and ep_psum_params is None and tile_m >= 256 and token_num >= 1024.

The prefill tile (tile_m=64, m_warp=1) and tiny decode batches regress —
gemm1's row-major A-scale ds_read is a strided read with a 2-way LDS bank
conflict that costs more than the preshuffle saves once M is large / the GEMM is
compute-bound. Those cases keep the original interleaved store untouched
(verified in the server trace: decode preshuffle becomes ..._r8_..._rm,
prefill stays ..._r4_..., same binary).

  • Env kill-switch: AITER_TDM_ROW_MAJOR_A1_SCALE=0
  • Floor override: AITER_TDM_ROW_MAJOR_A1_MIN_TOKENS (default 1024)
  • No new kernel launches — reuses the existing row_major_ascale gemm1 arg
    and the existing prequant full-row copy kernel (new _rm module-name variant
    so interleaved and row-major builds don't share a JIT binary).

Microbenchmark (4× MI455X / gfx1250, exact production geometry)

bench_mega_moe.py -q a4w4_mxfp4 -tpr 1536 -hd 7168 -id 2048 -e 260 -k 9 --shared_experts 0 --dispatch_backend mori --stage1_fused 0 --dispatch_wire fp4 --combine fused --combine_quant none, 4-layer A/B (AITER_TDM_ROW_MAJOR_A1_SCALE 0 vs 1):

kernel OFF (baseline) ON (patch)
preshuffle (decode) 25.76 µs 9.10 µs
FC1 (K7168 t256) 124.99 µs 125.52 µs
FC2 (K2048 t256) 128.93 µs 127.23 µs
per-layer (device) 445.7 µs 428.8 µs (−3.8%)

Isolated gemm1 output is bit-exact between interleaved and row-major scales
(max abs diff 0).

Prefill tile check (tile_m=64, 4096 tokens): row-major preshuffle 73→17.7 µs
but gemm1 356→420 µs (+18%), net +9 µs/layer → gated off, confirming the
tile_m>=256 gate.

Profile (serving, 1k4k ISL=1024/OSL=4096 conc=6144, MLPerf-aligned flags)

DSR1 EP4 DP-attn, max_num_seqs=1536, steady-state decode (bs≈1473–1536),
dp0 torch-profiler trace, per-call GPU time:

decode kernel baseline µs/call patch µs/call Δ
preshuffle 28.33 8.35 −19.98 (−70%)
FC1 (t256) 127.30 127.61 +0.31 (flat)
FC2 (t256) 115.74 114.59 −1.15 (flat)

≈20 µs/layer × 58 MoE layers ≈ ~1.16 ms saved per decode step. Prefill
t64/r4 preshuffle unchanged (gate off).

Accuracy (MLPerf DSR1 offline accuracy harness, 4388 samples, patch on, 2×)

run exact_match (need ≥ 80.545) tokens/sample (3497.6–4274.9) verdict
1 80.9253 3915.7 PASS
2 80.7885 3910.1 PASS

…ttered preshuffle)

The decode MoE A1 scale-preshuffle (moe_fused_quant_preshuffle_routeks, the
prequantized full-row copy path) scattered each row's e8m0 scales into the
GEMM's 16-row-interleaved layout at a stride of wmma_rep*16 dwords -- one dword
per cache line. gemm1 already supports reading A-scales row-major
(row_major_ascale, used by the compact-dispatch path), so on the mori dispatch
path we now write each grouped row's scales contiguously (row*K/32 + g) and let
gemm1 do the 16-row interleave on its LDS->register read instead.

This removes the uncoalesced scale scatter from the decode preshuffle:
  moe_fused_quant_preshuffle_routeks_fd7168_r8 ...  28.3 us -> 8.35 us/call
with FC1/FC2 unchanged (bit-exact GEMM output, max abs diff 0).

Gated to the decode kernel (tile_m>=256) and token_num>=1024: the prefill tile
(tile_m=64, m_warp=1) and tiny decode batches regress because gemm1's row-major
A-scale ds_read is a strided 2-way-bank-conflict read that costs more than the
preshuffle saves once M is large / the GEMM is compute-bound. Prefill keeps the
original interleaved store untouched. Env kill-switch
AITER_TDM_ROW_MAJOR_A1_SCALE=0; floor override AITER_TDM_ROW_MAJOR_A1_MIN_TOKENS.

No new kernel launches: reuses the existing row_major_ascale gemm1 argument and
the existing prequant full-row copy kernel (new _rm module-name variant so the
interleaved and row-major builds do not share a JIT binary).

Co-authored-by: Cursor <[email protected]>
@karverma-amd
karverma-amd requested a review from a team October 10, 2026 04:29
@github-actions github-actions Bot changed the title [gfx1250][MoE] Row-major A1 e8m0 scale store for decode MoE (drop scattered preshuffle) [FlyDSL] [gfx1250][MoE] Row-major A1 e8m0 scale store for decode MoE (drop scattered preshuffle) Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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: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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6357 --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.

Black wants the env-var membership test on one line, and ruff SIM102
rejects the nested row_major_scale guard. Those two Checks failures
were also failing check-signal and the Aiter Test Gate.

Co-authored-by: Cursor <[email protected]>
@zufayu
zufayu requested a review from yadaish October 12, 2026 01:27
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.

3 participants