Skip to content

[FlyDSL] [Perf] gfx1250 MoE: router writes MXFP4 token rows, GEMM1 gathers them (no decode A1 route/quant launch) - #8461

Draft
XiaobingSuper wants to merge 16 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-moe-router-quant-rows
Draft

XiaobingSuper wants to merge 16 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-moe-router-quant-rows

Conversation

@XiaobingSuper

@XiaobingSuper XiaobingSuper commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

For the decode TP grouped MoE on gfx1250, the router launch also quantizes its input, so the grouped MoE no longer needs its A1 route/quant launch.

  • Router writes the rows. The router is the fused router GEMM + top-k of [FlyDSL] [Perf] gfx1250 MoE router GEMM + biased sigmoid top-k in one launch #8431 (flydsl_moe_router_topk). Passed quant_rows=(payload, E8M0), it also writes every token row as MXFP4: exactly the bytes the A1 quant writes for each of that token's routed rows. quant_rows8 adds the MXFP8 copy that a folded shared expert ([FlyDSL] [Perf] gfx1250 MoE: fold a shared MXFP8 expert into the routed MXFP4 GEMMs #8430) reads.

  • GEMM1 gathers them. The grouped MoE skips the A1 route/quant launch. GEMM1 does that launch's work in a new tp_gather build of the TDM task, launched by launch_gemm_a8w4_tdm_tpg:

    • each workgroup re-derives the TP route in LDS from all T x 4 ids, the way [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's route-in-quant does: per-expert counts, tile-aligned exclusive starts, rows within an expert in route order;
    • it finds its own tile's routes with one ballot pass, and gathers their rows with buffer loads into the LDS layout the A TDM load produces (padding rows zero), one k-tile ahead in registers;
    • workgroup 0 writes psum (into the tile-map argument), masked_m and the dropped routes' topids_to_rows; each tile's first N tile writes its routes' rows.
  • API.

    • router_quant_rows_buffers(tokens, model_dim, device, topk) allocates the rows, or returns None where a grouped call would not take them.
    • moe_router_quant_rows(topk_ids, rows) hands them to the grouped MoE run inside the block. It is eager and thread-local, for an opaque custom op.
    • AITER_MOE_ROUTER_QUANT_ROWS=0 turns it off.
  • Where it applies. Only where the A1 launch would be [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's TP route-in-quant, and only for a call routed by that same topk_ids tensor:

    • by default, the token-multidest kernel's batches (T >= 64); topk 4; MXFP4 experts; one K wave; no A-scale prologue; no row-major scales;
    • with a shared fold, only if the router also wrote the MXFP8 copy at the fold's row capacity.

    Every other call keeps today's launches.

  • Second commit, AITER_MOE_ROUTER_QUANT_ROWS_MIN_TOKENS=N (unset by default). Decode batches from N tokens also take the rows. Below 64 tokens, GEMM1's gather then replaces the small-T route-indexed A1 launch, whose rows are the same MXFP4 bytes. MiniMax-M3.1 runs it at 8.

Why

At decode, a MiniMax-M3.1 MoE layer's front is router + A1 route/quant + GEMM1. The A1 launch reads the hidden rows once more and writes them to expert order. It costs a launch and a kernel switch on the critical path (about 0.8 us idle per switch inside a CUDA graph on MI455X). The router already reads every row, so it can write the quantized rows at little cost: about 0.3-0.9 us more per router launch, measured below.

Correctness

  • Kernel level (MI455X). The MoE output is byte-identical with and without the router rows, eager and in a CUDA graph: 154/154 cases without the shared fold. The cases cover 14 token counts from 64 to 512 and ten routing kinds: random, duplicated rows, every token on the same experts, saturated, zero rows, partly and fully invalid rows, duplicate ids, dropped ids and hot experts. With the fold, 153/154: the one mismatch was the fold GEMM2 race that [FlyDSL] [Perf] gfx1250 MoE: fold a shared MXFP8 expert into the routed MXFP4 GEMMs #8430's latest commit fixes, not this change. The env doc of the MiniMax-M3.1 integration reports the min-tokens path bit-exact at T = 8..64, eager and CUDA graph.
  • Model. MiniMax-M3.1 TP4 on 4x MI455X, with the ATOM wiring (perf(minimax-m3): the fused router writes the MoE input as MXFP4 rows for GEMM1 (opt-in) ATOM#3714, ATOM_MINIMAX_M3_MOE_ROUTER_QUANT) in our integration stack: our serving gate passes with real speculative acceptance, and GSM8K (1319, 5-shot) scores 0.9545.

Performance

Kernel level. One MiniMax-M3.1 TP4 routed-MoE decode layer (hidden 6144, E128 top-4, MXFP4), MI455X, CUDA graph, us. Two runs (a / b) of the same A/B, base vs router rows:

T router (base / + rows) layer, no fold: a layer, no fold: b MoE glue: b
64 3.95 / 4.52 56.93 -> 56.14 56.74 -> 55.32 11.23 -> 9.81
128 3.96 / 4.54 62.89 -> 60.28 61.78 -> 58.92 10.64 -> 7.78
192 4.05 / 4.72 66.43 -> 66.68 65.74 -> 63.27 13.33 -> 10.86
256 4.16 / 4.80 74.73 -> 73.59 71.63 -> 69.51 13.25 -> 11.13

With the shared fold on, the same layers measured 0.5-3.9 us slower in both runs. The fold is off in our production configuration.

End-to-end. At concurrency 4 (agentic multi-turn trace replay, 900 s per run, same node), a group of small-batch decode changes took P90 interactivity from 737.5 to 775.4 tok/s/user. The group includes AITER_MOE_ROUTER_QUANT_ROWS_MIN_TOKENS=8, the sampler (ROCm/ATOM#3704), the draft model's fused all-reduce (ROCm/ATOM#3707) and the engine idle yield (ROCm/ATOM#3703). This change's own share is not separated out.

Dependencies

Stacked on #7543 (lirui927), #8431 and #8430; please review only the top 2 commits.

The merges below them combine the three PR branches unchanged:

Changes in the port onto main:

  • launch_gemm_a8w4_tdm_tpg passes layout["kernel_attrs"] as launch_gemm_a8w4_tdm does after main's TDM-task refactor.
  • Null operands go through flyc.from_c_void_p, since main's ptr_arg takes no None.
  • The switches are read with os.environ.get. Our stack's env_once helper is not brought in, matching [FlyDSL] [Perf] gfx1250 MoE: fold a shared MXFP8 expert into the routed MXFP4 GEMMs #8430, which dropped it the same way. Its original commit is not available upstream, and it is only a caching shortcut.

Validation status

  • Validated on our 1120 integration stack (image base aiter 576d3f0) on 4x MI455X. That stack carried an earlier revision of the TP route-in-quant than [FlyDSL] perf(flydsl): fold the gfx1250 TP MoE route into the activation quant #7543's current head.
  • Re-checked after the port (no GPUs):
    • FlyDSL compile-only for gfx1250 (FlyDSL 0.5.0, in a GPU-less container): the router with quant rows (split-K 8 and 4, MXFP4 and MXFP4 + MXFP8); the tp_gather GEMM1 (16x256, 16x384 and 32x384 tiles; 1, 2 and 8 token slots; with and without the row-route map); the shared-fold GEMM1 with and without tp_gather; the shared-fold GEMM2. Also the merged A1 quant builders: token-multidest plain, with the MXFP8 copy (unsplit and K-split 8) and with the TP route (K-split 8), plus the route-indexed build plain, with the copy and with the TP route; the TP route + copy pair is rejected at build time as intended. All compiled; each group took seconds.
    • py_compile, black, and ruff (E4/E7/E9/F) are clean on the changed lines.
  • Not re-run on GPUs after the port.

🤖 Generated with Claude Code

lirui927 and others added 12 commits November 16, 2026 10:21
Add tp_route_params to flydsl_moe_fused_quant_preshuffle. With it, the
quant launch does the work of moe_route_psum_fused itself: every quant
workgroup loads all expert ids, counts them in LDS (all routes, and the
routes before its own), scans the tile-aligned counts, and gives its own
routes their rows. It writes topids_to_rows, and block 0 writes masked_m
and psum, so gemm1, gemm2 and the gather-reduce read what they read before.
No workgroup waits on another, and nothing is left in global memory between
calls.

Both quant kernels the route batches use take it: the route-indexed kernel,
and the K-split build of the token-multidest kernel (from 64 tokens), which
gets a tp_route_slots build flag; its two kernel entry points share one
quant context. The id loads and the
lane's hidden-row loads are issued before the first barrier, so the route
work hides under them. Each thread loads 8 id slots, enough for the 2048
routes the fused TP route serves, and skips the slots a smaller call does
not use, so one build serves every batch.

Rows within an expert follow route order, the same in every block. The
single-workgroup route assigns them with LDS atomics, so its order varies
from call to call; each route's quantized row, masked_m and psum are bitwise
those of the split path, and the MoE output too, because no GEMM row or
gather-reduce result depends on where a row sits.

The wrapper refuses buffers the kernel cannot write in place (non-int32 or
strided topids_to_rows, masked_m or psum, too few grouped rows) and the
modes the fused route does not cover (prequantized, A-preshuffle, remap,
EP psum, row-major scales, num_valid_routes, more than 256 experts). The
quant kernels without the route compile to the same ISA as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Small TP batches (token_num * topk <= 2048) build their routes with
moe_route_psum_fused, one workgroup that counts, scans and remaps every
route, and then quantize the bf16 hidden rows into expert order in a second
launch. On MiniMax-M3 TP4 decode (E = 129, top-5 with the shared expert on
every token) that route launch runs once per MoE layer.

The grouped MoE now hands those batches to the quant launch with
tp_route_params, so a MoE call runs 4 kernels instead of 5. It is taken
for the fused TP route batches with bf16 input, E <= 256, no a1_scale, no
A-preshuffle and not the compact-scale quant pair; every other batch keeps
its launches. AITER_TDM_FUSE_TP_ROUTE_QUANT=0 restores the separate route
launch, like AITER_TDM_FUSE_PSUM_QUANT does for the EP psum.

The compact-scale decision is now made once per call and shared by this
gate and the quant dispatch.

test_grouped_skips_pad_rows_routed_to_minus_one checked that a 128-token
TP batch with pad rows routed to -1 reaches the token-multidest quant; that
batch now takes the route-in-quant build. The test now runs it both ways,
with the route in its own launch and in the quant, and checks the same
zero pad rows and unchanged real rows on each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
op_tests/test_moe_tp_route_quant_fused.py compares the fused route + quant
with fused_route_psum_remap followed by the quant, at 1 to 409 tokens with
M3 routing (E = 129, top-4 plus a shared expert), padded TP rows and
dropped or out-of-range ids:

- masked_m, psum and topids_to_rows equal a CPU reference;
- payload and scales equal the split path's once each route's row is moved,
  with sentinel-filled outputs so an unwritten row fails;
- a HIP graph replayed with new routes rewrites every route output;
- buffers the kernel cannot write in place are refused;
- the public fused_moe output (a4w4 and a8w4) is bitwise equal with the
  switch on and off, and only the switch-off call launches the route.

python3 op_tests/test_moe_tp_route_quant_fused.py runs the same checks over
a token sweep and prints the split and fused route + quant times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n the same pass

A shared expert run beside the routed MXFP4 MoE (MiniMax-M3.1) quantizes the
same bf16 rows to MXFP8 in its own launch. The routed A1 quant already reads
each row and reduces every 32-block's amax, so it can write that copy too:
fused_moe / flydsl_moe_fused_quant_preshuffle take `mxfp8_copy_out=(payload,
scale)`, row-major (M, K) E4M3 + (M, K/32) E8M0, the bytes of
per_1x32_mx_quant_hip(quant_dtype=fp8, scale_type=fp8_e8m0) (amax floored at
kAmaxFloor, RoundUp exponent against 448, v_cvt_scalef32_pk8_fp8_bf16).

The three quant builds the M3.1 grouped MoE dispatches take a `mxfp8_copy`
build flag (`_mx8cp` builds with two more pointers): token-multidest (plain
and K-split), the compact-scale quant, and the route-indexed quant (each
source row's first route writes it, mapped or not). Any other A1 path, or a
non-grouped MoE / FHMoE, fills the copy with the HIP quant instead. Without
the flag every build is unchanged: the kernel bodies moved into a @flyc.jit
body inlined into either signature.

fused_moe's plugin contract moves to version 3 (two more outputs a v2
provider would leave unwritten, so v2 is not superseded);
tests/plugin_contracts.json records it.

op_tests/test_moe_quant_shared_mxfp8.py: routed outputs bitwise unchanged and
the copy bitwise the split quant (and a torch model of the rule) for every
variant at 8..32768 tokens, the public fused_moe path, and timing of the fused
launch against routed quant + split quant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shared-expert add

Add an optional output epilogue to the grouped MoE gather-reduce:
out = bf16(bf16(bf16(sum_k w * rows) * scale) + addend), each step rounded
like the separate torch ops it replaces (the multiply is skipped at scale
1.0), so the bytes are unchanged.

moe_output_epilogue(addend, scale, before=None) is a context manager that
hands the pending epilogue to the next _grouped_a8w4_tdm_moe call in the
block; `before` runs right before the gather-reduce launch (e.g. a wait for
the stream that produced addend) and `consumed` tells the caller whether a
gather-reduce took it. EP calls and other MoE paths leave it unconsumed and
the caller applies the scale and add itself. Python-side state: for eager
callers, not torch.compile tracing.

MiniMax-M3.1 TP4 shape (hidden 6144, E128 top-4, bf16), 4x MI455X, us:
  T                       64    128   192   256
  gather-reduce+mul+add  5.41  5.61  6.09  6.50
  fused gather-reduce    1.84  1.91  2.19  2.21
Output bitwise identical to the separate ops (eager and Inductor).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed MXFP4 GEMM launches

moe_shared_expert_fold(weights, scale) runs a dense shared expert inside the
next grouped MoE call (_grouped_a8w4_tdm_moe), as one more expert every
token routes to with weight 1:

- GEMM1: launch_gemm_a8w4_tdm_shared_fold puts the shared gate/up tiles in
  the routed GEMM1 launch (leading workgroups, FP8 x FP8 on the MXFP8 copy of
  the input the A1 quant writes, SwiGLU and MXFP8 quant in the same
  epilogue), the routed tiles unchanged behind them;
- GEMM2: the shared down tiles in the routed GEMM2 launch (BF16 rows);
- the shared rows are added after the routed scale in the gather-reduce
  (moe_output_epilogue).

The MXFP4 TDM GEMM gains b_fp8 (row-major FP8 B, staged like the FP8
activation), inline_task, dense_rows and c_stage_apart knobs for the dense
tiles; the routed tiles compile as before. prepare_shared_fold_weights()
lays the weights out once (gate/up interleaved, n32k4 scales) into storage
it owns, so a caller may shuffle its own parameters in place afterwards. The
fold is taken only for unclustered decode tiles without EP, compact or
prequantized A1; elsewhere `consumed` stays False and the caller runs the
shared expert itself.

MiniMax-M3.1 TP4 MoE layer (E128 top-4 MXFP4 routed + MXFP8 shared,
hidden 6144), 4x MI455X, us per layer:
  T                         64    128   192   256
  routed + shared (2 streams) 69.1  78.4  81.7  82.6
  fold                       65.6  72.7  78.0  81.0
Shared-expert rel-L2 vs fp32: 2.0e-3 (separate MLP: 1.7e-2, which rounds the
gate/up and SwiGLU outputs to BF16 before its quant). Not bitwise the
separate MLP for that reason; MoE output rel-L2 vs the current path 1.4e-5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… launch

Add flydsl_moe_router_topk: the decode MoE front pair
tgemm.mm(x, w_router) (the gfx1250 FlyDSL A16W16 split-K GEMM, bf16
logits) + topk_gating(..., score_func="sigmoid") in one FlyDSL launch with
the same bytes:

- logits: each 16-row token tile is one workgroup cluster of
  split_k x expert groups; the WMMA chains, operands and split order are
  those of the tuned FlyDSL GEMM, and the partials are reduced after the
  cluster barrier (no flags or polling);
- top-k: topk_gating_kernel_opt's sigmoid, bias, sorting network, lowest-lane
  tie break and renormalization, one wave per row.

router_split_k(m, n, k, dtype, otype) reads the tuned A16W16 config and
returns the split_k to use, or None when the shape is not served by the
gfx1250 FlyDSL FT/HT GEMM (the caller keeps the pair then). The kernel can
also write per-8-row-group expert counts (group_counts, optional).

MiniMax-M3.1 TP4 router (E128, K 6144, top-4), 4x MI455X, CUDA graph,
us per call:
  T              64    128   192   256   320   512
  GEMM + gating 6.17  6.39  7.09  7.17  7.90  7.46
  fused         3.93  4.02  4.14  4.25  6.77  6.06
op_tests/test_flydsl_moe_front.py: topk_weights / topk_ids bitwise equal to
tgemm.mm + topk_gating for T = 1..512 with random, tied, saturated and
padded (num_valid_rows) inputs (283/283 cases on the validation stack), and
the group counts against a histogram of the ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stores, not a TDM store

On gfx1250 a TDM store (tensor_store_from_lds) can read LDS bytes that
predate ds_stores the workgroup issued before `s_wait_dscnt 0` and
`s_barrier`. In the shared-fold GEMM2 (routed 16x128 with the 64x64 /
32x64 dense tiles), the C pieces of each wave's last ds_store, in the
first rows of its 8-row TDM box, sometimes came out as the input stage's
older A/B bytes. That happened in 0.2-10% of launches at T 48-80 under
hot-expert routing on MI455X. A ds_load after the same barrier always sees
the new data.

New build option c_lds_store (bf16/f16 C without EP scatter): after the
barrier that follows the C restage, the waves read the tile back from LDS
in whole-row 16-byte chunks and write it with buffer_store_b128. Rows past
mn_oob are dropped, as the TDM store's row extent drops them.
launch_gemm_a8w4_tdm_shared_fold turns it on for GEMM2. The kernel name
gains `_cldsst`.

MI455X, T 48-256, hot-expert routing: 0 bad launches in 84,000 (the TDM
store: up to 10%), bitwise the clean output, +0.0-0.6 us per GEMM2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…old)

Both PR branches unchanged; the merge had no conflicts.
…#8430 + ROCm#8431

ROCm#7543's branch unchanged. Its TP route-in-quant and ROCm#8430's MXFP8 copy
(f84ed58) both extend the token-multidest and route-indexed quant
builders; the resolution keeps both features:
- build_moe_token_multidest_quant_module: ROCm#7543's _quant_ctx helper and
  TP-route kernel, with ROCm#8430's shared body and two kernel signatures (with
  and without the copy pointers) for the non-route kernel.
- build_moe_fused_quant_preshuffle_route_ksplit_module: both parameters
  and both mode checks.
- The TP-route builds write no MXFP8 copy (both builders reject the pair).
  flydsl_moe_fused_quant_preshuffle then sends the copy out on its own
  launch (mxfp8_row_copy) when a TP-route call also asks for one, as it
  already does for the other modes that take no copy. Same bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…thers them

For the decode TP grouped MoE, the router launch (flydsl_moe_router_topk,
ROCm#8431) can also quantize its input rows. With
quant_rows=(payload, E8M0) it writes every token row as MXFP4: the bytes
the A1 quant writes for each routed row. quant_rows8 adds the MXFP8 copy
that a folded shared expert (ROCm#8430) reads. The grouped MoE then skips the
A1 route/quant launch, and GEMM1 (launch_gemm_a8w4_tdm_tpg, the tp_gather
build of the TDM task) does its work:
- each workgroup re-derives the TP route in LDS from all T x 4 ids, as the
  route-in-quant of ROCm#7543 does: per-expert counts, tile-aligned exclusive
  starts, rows within an expert in route order;
- it finds its tile's routes with one ballot pass and gathers their rows
  with buffer loads into the LDS layout the A TDM load produces (padding
  rows zero), one k-tile ahead in registers;
- workgroup 0 writes psum (into the tile-map argument), masked_m and the
  dropped routes' topids_to_rows; each tile's first N tile writes its
  routes' rows.
GEMM1's bytes are those of the A1-fed launch, so the MoE output is
unchanged.

API:
- router_quant_rows_buffers(tokens, model_dim, device, topk) allocates the
  rows, or returns None where a grouped call would not take them;
- moe_router_quant_rows(topk_ids, rows) hands them to the grouped MoE run
  inside the block (eager, thread-local);
- AITER_MOE_ROUTER_QUANT_ROWS=0 turns it off.

Taken only where the A1 launch would be the TP route-in-quant
token-multidest kernel (T >= 64, topk 4, MXFP4, one K wave, no A-scale
prologue or row-major scales), for a call routed by that same topk_ids
tensor. With a shared fold it also needs the router's MXFP8 copy at the
fold's row capacity. Everything else keeps today's launches.

Ported onto main's TDM task refactor: the tp_gather launcher passes
layout["kernel_attrs"] like launch_gemm_a8w4_tdm, null operands go through
flyc.from_c_void_p (main's ptr_arg takes no None), and switches are read
with os.environ.get as in ROCm#8430 (no env_once).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tch (AITER_MOE_ROUTER_QUANT_ROWS_MIN_TOKENS)

Unset (the default), the router's MXFP4 rows go only where the A1 launch
would be the TP route-in-quant token-multidest kernel (T >= 64), as
before. AITER_MOE_ROUTER_QUANT_ROWS_MIN_TOKENS=N lets decode batches from
N tokens take them too. Below 64 tokens GEMM1's gather then
replaces the small-T route-indexed A1 launch
(moe_fused_quant_preshuffle_routeks), whose rows are the same MXFP4 bytes.

MiniMax-M3.1 TP4 on 4x MI455X runs it at 8: T = 8-63 decode steps lose the
route+quant launch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 8461 --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.

XiaobingSuper and others added 3 commits November 23, 2026 02:28
…m LDS instead of TDM-storing it

On gfx1250, a TDM store's (tensor_store_from_lds) read of LDS is not
ordered behind the other waves' ds_stores, even after `s_wait_dscnt 0` and a
workgroup barrier. A 16-byte piece of a wave's TDM box can then leave as the
bytes LDS held before the C tile: the input stage's FP4 / FP8 operands. ROCm#8430
fixed this for the shared-fold GEMM2. The same store pattern runs in the plain
routed MoE GEMMs:
- GEMM2's bf16 tile, where stale operand bytes read as bf16 are 1e25-1e38;
- a stage-1 GEMM's quantized FP4 / FP8 tile (with its E8M0 scales), which
  GEMM2 then dequantizes.

Both now leave LDS through a ds_load read-back behind the existing barrier,
then buffer stores:
- launch_gemm_a8w4_tdm takes `c_lds_store`. For GEMM2 it is the bf16
  read-back ROCm#8430 added for the fold (`c_lds_store`). For a quantized stage-1
  GEMM it is a new `cq_lds_store` epilogue that writes the payload rows the
  same way (kernel name `_cqldsst`), kept on the TDM store where its 16-byte
  chunking does not divide the block.
- flydsl_grouped_gemm_a8w4_masked turns it on by default
  (`_c_lds_store`). EP scatter keeps its own store, and
  AITER_TDM_C_LDS_STORE=0 restores the TDM store.

The race fires when another queue's kernels share the CUs, e.g. MiniMax-M3's
shared MLP running beside the routed MoE on the other stream of a captured
graph. On MiniMax-M3.1 TP4 (4x MI455X), together with the same change in the
MXFP8 GEMM, all-zero logit rows (decoded as token 0) went from 8 of 40 greedy
passes to 0 of 40, 0 of 12 high-concurrency passes and 0 over full GSM8K.
The decode step is unchanged within noise; GSM8K 0.9545 / 0.9538.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-rows branch

The bugfix branch (C tile leaves LDS by a ds_load read-back + buffer stores)
sits on ROCm#8430; this branch sits on ROCm#8430 + ROCm#8431 + ROCm#7543. Conflicts were
context only, both sides kept: build_gemm_a8w4_tdm_task takes both the
tp_gather parameters and cq_lds_store, and the kernel name carries both the
`_cldsst` / `_cqldsst` and `_tpg` suffixes; grouped_gemm_mxfp4 keeps both
the tp_gather helpers and `_c_lds_store`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from LDS too

launch_gemm_a8w4_tdm_tpg (the k1b GEMM1 that gathers the router's MXFP4
rows) takes `cq_lds_store`, and flydsl_grouped_gemm_a8w4_masked passes it
the same `_c_lds_store` decision as the plain launcher's stage-1 GEMM. Its
quantized FP4 tile then leaves LDS through the ds_load read-back + buffer
stores instead of the TDM store, whose LDS read is not ordered behind the
other waves' ds_stores on gfx1250 (see the C-store read-back fix this branch
merges). AITER_TDM_C_LDS_STORE=0 restores the TDM store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XiaobingSuper

XiaobingSuper commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Reverted (see the next comment, 6f6cd37): the read-back described below is no longer on this branch.

Update: two commits on top of this branch (fast-forward):

Why. This is the fix for the stray token-0 bug, also applied to the MXFP8 GEMM in #8273. Our validated stack carried it in this launcher too. Re-checked: FlyDSL compile-only for gfx1250 (GPU-less container): the tp_gather GEMM1 at 16x256 / 16x384 / 32x384 with cq_lds_store 0 and 1, plus the plain GEMM1 / GEMM2 launcher, 32 of 32 compile; py_compile, black and ruff clean. Not re-run on GPUs.

…e2e9)

Scope decision for the stray token-0 fix: only the read-back in
gemm_a8w8_gfx1250 ships (ROCm#8273); the grouped MoE PR (ROCm#8466) is
closed. This reverts both commits that brought it here:
- f3c9c30, the `cq_lds_store` wiring for launch_gemm_a8w4_tdm_tpg;
- the merge 77be2e9 of the grouped GEMM1 / GEMM2 read-back
  (`_c_lds_store`, `cq_lds_store`).

The grouped MoE read-back cost about 4% of prefill time (uncached prefill
TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283), and no failure was ever observed
in these kernels. They keep the TDM store, a latent risk recorded in
ROCm#8273's hardware / compiler note. This branch's tree is again that of
9baf599.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XiaobingSuper

Copy link
Copy Markdown
Contributor Author

Update: pushed 6f6cd37, which reverts the TDM C-store read-back added earlier today: the cq_lds_store wiring for launch_gemm_a8w4_tdm_tpg (f3c9c30) and the merge of the grouped-MoE read-back (77be2e9). Scope decision: only the gemm_a8w8_gfx1250 read-back ships (in #8273, where all failures were located). The grouped MoE read-back cost about 4% of prefill time (uncached prefill TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283), with no observed failure in these kernels, and is recorded as a latent risk in #8273's hardware / compiler note. The branch tree is again that of 9baf599 (no force-push).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants