Skip to content

[FlyDSL] Launch the planner, GDN, conv3d, FP8 attention and MegaMoE launchers through the AOT cache - #8600

Merged
coderfeli merged 16 commits into
mainfrom
feat/flydsl-aot-remaining-gfx9
Nov 26, 2026
Merged

coderfeli merged 16 commits into
mainfrom
feat/flydsl-aot-remaining-gfx9

Conversation

@coderfeli

@coderfeli coderfeli commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #8565. Routes the remaining gfx942/gfx950 FlyDSL launchers that the AOT replays in aiter/aot/flydsl compile through the export_to_c cache: the paged-attention planner, the GDN kernels, conv3d, the gfx950 FP8 flash attention, the gfx950 intranode MegaMoE and the gfx950 4-wave MXFP8 GEMM that #8582 added. Includes #8680 (closed). gfx1250 is not touched.

Motivation

After #8565 only the GEMM and 2-stage MoE replays went through the cache; the launchers of the other replays traced in every process. A launch only loads entries that a prebuild made, so each of these needed both a binding and a replay that reaches the cache.

Changes

Replay Cache How
pa_decode_plan pa_decode_plan aot_factory + .lazy
chunk_gdn_h chunk_gated_delta_h aot_factory + .lazy; flags coerced with bool()
gdn_fused_prefill gdn_fused_prefill aot_factory + .lazy
conv conv3d_implicit_gfx950 bind_aot, keyed by the fields of its Conv3dImplicitParam; a variable-resolution kernel keys the constants it closes over instead of d/h/w
conv conv3d_transpose_ncdhw_ndhwc bind_aot under (n, c, BIG); s is a launch argument
gemm gemm_a8w8_mxfp8_4wave aot_factory + .lazy (the launcher #8582 added; it was 726 of the gfx950 GEMM replay's compiles)
fmha_fp8 flash_attn_fp8_gfx950 bind_aot under _build_fp8's arguments
mega_moe mega_moe_prepare, mega_moe_stage1_bundle, mega_moe_small_m_stage1, mega_moe_large_m_stage1, mega_moe_stage2, mega_moe_stage2_aligned_pair, mega_moe_mx_quant, mega_moe_combine aot_factory; the bundle's Stage1Config variants are keyed by their field values; the combine is the one after the fused GEMM2

Shared code:

  • tensor_shim._preload_compiled called flyc.compile itself, so a bound launcher never reached the cache (MegaMoE warms up with it). For a bound launcher it now builds the entry in a prebuild and, in a process that serves, loads the entry without launching; with no entry it preloads on the JIT path as before. It takes the launch's specialization_key.
  • tensor_shim._compile_and_keep: the same for a caller that keeps the compiled function and calls it directly (the MegaMoE combine, the conv _dispatch).
  • aot_launch.preload_bound, FlyDSLAotCache.preload.

Where the declarations live. What every cache is built from is now in one table, aiter/aot/flydsl/sources.py: AOT_CACHES (cache name to source files and environment variables), COMMON_SOURCES, COMMON_ENV and ENV_NOT_CODE. A launcher only names its cache (@aot_factory("mixed_moe_gemm1")). The lists were keyword arguments at the 39 sites that create a cache, many inside kernel files, repeated for caches that share one; changing a list changed the file holding it, which is itself a source. A name in the table must not pass sources=/env=, and a cache created under aiter/ops/flydsl must be in the table; a unit test checks that the table and the caches created match.

Variables: AITER_FLYDSL_MOE_EXPERT_SCHEDULING_MODE was an input of every cache because tensor_shim.py read it; it moves to the one gfx1250 kernel that uses it. AITER_FLYDSL_STAGE2_FP8, AITER_MXFP4_INTERMEDIATE, AITER_MXFP4_TUNE_SWIGLU_LIMIT (dispatch helpers of moe_common.py; their choice reaches a kernel as a factory argument) and AITER_K5_OPT_CHECK (a host-side audit) leave the caches' variables and are listed in ENV_NOT_CODE.

Not converted: the fixed-slot MegaMoE stage 1, compile_gemm1, the scale-sort quant, dispatch and the regular combine() (no replay compiles them; aiter.dist uses the last two outside MegaMoE), and the TP, internode and gfx1250 MegaMoE.

Performance (if applicable)

Host time per launch, MI308X. Before is the JIT path, after is a cache hit.

Workload Before After
pa_decode_plan 16.9 us 17.2 us
chunk_gated_delta_h (12 tensors) 22.9 us 25.1 us
gdn_fused_prefill (12 tensors, empty kernel of its argument shape) 14.3 us 17.9 us
flash_attn_fp8_gfx950 (11 tensors, empty kernel of its argument shape) 14.1 us 17.0 us
conv _dispatch, steady state, empty four-tensor kernel about 11 us about 11 us, with or without an entry
MegaMoE lookups (CPU only): stage 2 / stage-1 bundle / prepare / quant 2.7 / 1.7 / 0.32 / 0.11 us 1.6 / 2.5 / 0.36 / 0.18 us

The first four rows were measured at an earlier revision of this branch; their launch path is unchanged since. Kernel code is unchanged (same FlyDSL IR). No GPU timing of MegaMoE was taken.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

MI308X (gfx942), FlyDSL 0.5.3, no MORI, on this branch's head. gfx950 kernels are compile-only here.

  • Compile-only replays (the prebuild), each twice on one cache directory. The second run builds nothing; no launch takes the JIT path:
Replay Arch Entries
aiter.aot.flydsl.pa_decode_plan gfx942 / gfx950 96 / 96
aiter.aot.flydsl.chunk_gdn_h gfx942 198
aiter.aot.flydsl.gdn_fused_prefill gfx950 88
aiter.aot.flydsl.conv gfx950 140 + 9
aiter.aot.flydsl.fmha_fp8 gfx950 92
aiter.aot.flydsl.mega_moe --experts-per-rank 48 --mtpr 8192 gfx950 674
  • tests/test_flydsl_aot_launch.py and tests/test_conv3d_ci_modes.py under 1, verify and 0 (with tests/test_flydsl_aot_cache.py: 55 / 55 / 48 passed, 7 skipped). The launch test prebuilds two configs each of the GDN hidden-state kernel and the planner, then checks that a new process loads them, traces nothing and gives the JIT path's outputs bit for bit; and covers preloading a bound launcher (a prebuild builds, a serving process loads without launching, no entry falls back with one error).
  • On the GPU under 0, verify and 1: op_tests/test_flydsl_pa_decode.py (414 passed in each) and op_tests/test_flydsl_linear_attention_prefill.py (exit 0 in each). They load no prebuilt entry on this machine (the planner replay builds for another CU count; the GDN test's shapes are not tuned rows), so they exercise the JIT path with a miss logged. op_tests/test_gated_delta_rule.py fails one test_chunk_opt_vk_indice[...-hip] case in two of three runs, mode 0 included (the HIP backend).
  • Static checks: 40 caches created, 40 in the table, none missing a source file or a variable.
  • Also on this head (merged with main): aiter.aot.flydsl.gemm for gfx942 (80 entries) and gfx950 (5524, 3 of them the 4-wave MXFP8 GEMM) and aiter.aot.flydsl.moe --row-tokens-only for gfx942 (231) and gfx950 (3007), each twice, second run builds 0.
  • Every flyc.compile of every replay logged on main with this branch merged: none is made outside the cache (gfx950 GEMM 31370, gfx950 MoE 13992, MegaMoE 1176, and the others). Before the 4-wave GEMM was converted, its 726 were the only ones.
  • One traced IR per disk digest: each launch of every replay re-traced (63440 launches, 9850 digests, at an earlier commit of this branch; the gfx950 GEMM replay again on this head, 31614 launches, 5462 digests): no digest has two.
  • On gfx942 under verify, against the entries the replays built: no lookup misses a key that was prebuilt under the same fingerprint; the planner's entries are built for another CU count and miss on this 80-CU machine.
  • The move of the declarations is lossless: with the tree before and after it, every module that creates a cache was imported and the resolved source files, variables and creating file of all 39 caches of that commit compared; they are identical. Removing a cache, a kernel source or a variable from the table, or adding an unknown name, fails the unit test.
  • Every entry of the replays above except GEMM and MoE (1393) embeds, byte for byte, the GPU binary of the FlyDSL artifact of the same traced IR. A simulation of a serving process (MegaMoE built as the replay builds it, COMPILE_ONLY off, flyc.load_module replaced by a recorder) loads all 674 MegaMoE entries with no miss and no trace. Both were run before the last four commits of this head.
  • CI on an earlier head (5da81ff): all 8 Standard Tests shards passed on MI35X under verify, among them test_flydsl_conv_implicit.py, test_flydsl_fmha.py, test_flydsl_linear_attention_prefill.py and test_flydsl_pa_decode.py; the logs show no stale entry and no load failure. No MegaMoE test runs in CI (aiter_test.sh skips them).
  • At earlier revisions, not repeated on this head:
    • MegaMoE: every flyc.compile of the replay logged, 1176 calls, all made by the cache; a probe re-exporting each of those launches found 674 disk digests, none with two objects; the replay under verify found no stale entry; the default build (234 jobs) wrote 7655 entries, 634 MB, in 444 s, and a second run built 0.
    • The other replays: FlyDSL artifacts byte-identical with the cache off and on; the same probe over 35119 launches found no digest with two objects.
  • Three independent reviews of the diff; their findings are fixed or listed below.

Unverified / known:

  • Runtime on gfx950 for conv, fused prefill, FP8 attention and MegaMoE (MegaMoE also needs MORI): results, preload_aot_bundles() in a serving process, the combine's kept function.
  • FlyDSL artifacts of the MegaMoE replay: the same 594 + 80 names with the cache off and on (the names are the traced IR's hash), the 80 combine ones byte for byte. The GPU binary of 34 to 43 of the 594 differs between any two runs, two cache-off runs as much as off and on: LLVM does not make the same bytes of some prepare kernels twice.
  • AITER_MEGA_FIXED_SLOT_MAX_MTPR is an input of the three MegaMoE stage-1 caches. Serving recipes set it, and the prebuild does not: with it set, those caches miss and trace. (The replay with it unset, 511 and 2047 gives the same 674 keys, each from the same traced IR, for --experts-per-rank 48 --mtpr 8192; it stays an input because a miss only costs a trace.)
  • MegaMoE prebuild coverage: the replay builds V4-Pro and K3 at MTPR 8192/16384/32768 and V4.1-Flash at its listed MTPRs. An instance at another MTPR (the size suite of test_mega_moe_v2.py at 16/64/128) or of another network has no entries and traces, with an error per key.
  • mega_moe_stage2_aligned_pair is prebuilt and loads, but no run on gfx950 has launched it.
  • per_1x32_mx_quant is also the internode MegaMoE's quant, so that launches through mega_moe_mx_quant too; a size the intranode replay does not build logs one error and traces.
  • plan_pa_decode also goes through the cache on gfx1250; not validated.
  • The stage-1 bundle lookup costs about 0.8 us more per launch (its variants are turned into tuples).
  • The conv and FP8 wrappers call their builder (not .lazy), so a hit in a fresh process still pays the builder's Python, not the trace.
  • .lazy handles and loaded objects are not evicted.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

docs/flydsl_aot_cache.md (§4.2, §4.4, new §5.5 and §5.6, §6, §7), .claude/skills/flydsl-aot-export/SKILL.md and aiter/ops/flydsl/AGENTS.md.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

  • Every existing AOT entry is rebuilt by the next prebuild: tensor_shim.py, a source of every cache, changed, and so did every file that held a source list.
  • aot_factory / FlyDSLAotCache of a cache that is in aiter/aot/flydsl/sources.py no longer accept sources= / env=; a cache created under aiter/ops/flydsl must be in that table.
  • _preload_compiled of a launcher bound to the cache returns the loaded function (or None in a prebuild) instead of FlyDSL's compiled handle.
  • The MegaMoE combine launchers of the fused path are cached per module instead of per op instance.
  • conv_kernels._dispatch launches through the cache on first use; the conv builders' return objects gain .launcher.

🤖 Generated with Claude Code

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

@coderfeli
coderfeli force-pushed the feat/flydsl-aot-remaining-gfx9 branch 4 times, most recently from 73fd116 to 4025ef7 Compare November 25, 2026 06:34
coderfeli and others added 5 commits November 25, 2026 09:50
…through the AOT cache

The launchers the remaining gfx942/gfx950 AOT replays compile now launch
through the export_to_c cache: pa_decode_plan, chunk_gated_delta_h,
gdn_fused_prefill, conv3d (implicit and transpose) and the gfx950 FP8
flash attention. Each cache declares its sources.

The conv wrapper launches through _run_compiled in place of the
CompiledFunction it kept. A variable-resolution conv keys the constants
it closes over instead of D/H/W, and the transpose keys (n, c, BIG)
instead of its spatial size, so resolutions share an entry.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
_dispatch went through _run_compiled and a compile_hints context on
every launch, about 3.5 us more than the CompiledFunction it used to
keep. It now keeps the function the cache loaded (loaded_kernel) and
calls it directly; mode 0 takes the path it took before the cache.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli
coderfeli force-pushed the feat/flydsl-aot-remaining-gfx9 branch from 4025ef7 to a08e9da Compare November 25, 2026 09:50
@coderfeli
coderfeli marked this pull request as ready for review November 25, 2026 09:50
@coderfeli
coderfeli requested a review from a team November 25, 2026 09:50
@aiter-bot

aiter-bot commented Nov 25, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision fd04fc045b46 · mode shadow

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

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

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

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_pa_decode.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

coderfeli and others added 2 commits November 25, 2026 10:46
The launchers the MegaMoE replay (aiter.aot.flydsl.mega_moe) compiles now
launch through the export_to_c cache: prepare, the stage-1 bundle, the
small- and large-input stage 1, stage 2, the aligned-pair stage 2, the
1x32 MX quant and the combine after the fused GEMM2.

MegaMoE warms its kernels up with tensor_shim._preload_compiled, which
called flyc.compile itself, so a bound launcher never reached the cache:
- _preload_compiled of a bound launcher builds its entry in a prebuild,
  and in a process that serves loads the entry without launching it; with
  no entry it preloads on the JIT path as before.
- _compile_and_keep does the same for a caller that keeps the compiled
  function and calls it directly (the combine).
- The Stage1Config variants of the bundle are keyed by their field values.

The fixed-slot stage 1, compile_gemm1, the scale-sort quant, dispatch and
the regular combine are not compiled by the replay and stay on the JIT
path, as do the TP, internode and gfx1250 MegaMoE.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
coderfeli and others added 3 commits November 25, 2026 11:25
…s branch

The conv dispatch keeps the function its first launch got through
tensor_shim._compile_and_keep, which replaces aot_launch.loaded_kernel:
a key with no entry no longer goes through _run_compiled on every launch.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli coderfeli changed the title [FlyDSL] Launch the planner, GDN, conv3d and FP8 attention launchers through the AOT cache [FlyDSL] Launch the planner, GDN, conv3d, FP8 attention and MegaMoE launchers through the AOT cache Nov 25, 2026
…ists

kernels_common.py, tensor_shim.py and buffer_ops.py are sources of every
cache (aot_cache._COMMON_SOURCES), so a cache lists only its own files.
The set of files hashed is the same; the entries of these four caches are
still new ones, since the file holding the list is itself a source.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli
coderfeli force-pushed the feat/flydsl-aot-remaining-gfx9 branch from db92947 to 13339ec Compare November 26, 2026 03:19
…code

- AITER_FLYDSL_MOE_EXPERT_SCHEDULING_MODE was read in tensor_shim.py, a
  source of every cache, so it was an input of every cache; one gfx1250
  kernel uses it. The switch moves to that kernel's file and leaves
  _COMMON_ENV.
- AITER_FLYDSL_STAGE2_FP8, AITER_MXFP4_INTERMEDIATE and
  AITER_MXFP4_TUNE_SWIGLU_LIMIT are read by dispatch helpers of
  moe_common.py, which the MX MoE kernels import for GateMode only; what
  they choose reaches a kernel as a factory argument. AITER_K5_OPT_CHECK is
  a host-side audit of the GDN wrapper. They leave the caches' env= and are
  listed in _ENV_NOT_CODE, so setting one no longer makes a cache miss.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
coderfeli and others added 4 commits November 26, 2026 04:03
aiter/aot/flydsl/sources.py holds, by cache name, the source files and
environment variables of every cache, with the common sources, the common
variables and the variables that cannot change code. A launcher only names
its cache: aot_factory("name") / FlyDSLAotCache("name").

The lists were keyword arguments at the 39 sites that create a cache,
many inside kernel files, the same list repeated for caches that share
one; changing a list changed the file holding it, which is itself a
source. sources= and env= remain for a cache outside the table (tests);
a name that is in the table must not pass them.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…table holds tuples

- Creating a cache from a file under aiter/ops/flydsl under a name that
  aiter/aot/flydsl/sources.py does not hold raises: a misspelled or
  unregistered name would quietly depend on its own file and the common
  sources only.
- The lists of the table are tuples, so that the ones several caches share
  cannot be changed for all of them through one.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ut, not a cache input

AITER_MEGA_FIXED_SLOT_MAX_MTPR was declared by the three MegaMoE stage-1
caches, so setting it (serving recipes do) made every one of their entries
miss. The planner in mega_moe_config.py reads it to choose a route and
tiles, which reach a kernel as factory arguments. It moves to ENV_NOT_CODE.
The replay built with it unset, 511 and 2047 gives the same 674 keys, each
from the same traced IR.

Also: a test for preloading under a specialization key, and the doc line
on the conv dispatch.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A miss only traces; an entry served for the wrong planner setting would not
be noticed. The three stage-1 caches declare AITER_MEGA_FIXED_SLOT_MAX_MTPR
again, so a process that sets it misses their entries unless the prebuild
had it set. Drops the specialization-key preload test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli
coderfeli merged commit 9c9fb96 into main Nov 26, 2026
65 of 66 checks passed
@coderfeli
coderfeli deleted the feat/flydsl-aot-remaining-gfx9 branch November 26, 2026 14:25
AndreasKaratzas added a commit to AndreasKaratzas/aiter that referenced this pull request Nov 26, 2026
Conflicts:
- gemm_a16w16_gfx950.py: take main's AOT-cache launch (ROCm#8565, ROCm#8600):
  bind_aot, _PARAM_ITEMS and _run_compiled with the sorted param items
  and the device as the specialization key. Keep this branch's fp32
  workspace argument, its one-counter get_split_k_buffers(stream,
  device) and its get_cu_num/buf_base_i64 imports. The param items now
  include this branch's split_k_resident and m_tail, so the AOT key
  covers the per-launch reduction choice.
- llama70B, minimax_m3_eagle tables: key-based 3-way merge. Take main's
  change where this branch did not touch a row. For minimax_m3_eagle
  128x50016x6144, which both sides changed, keep main's row (ROCm#8598,
  FlyDSL t128x256x64x3 ks1 w4x4x1, 119.9 us vs this branch's torch row
  at 135.0 us). It has no split-K and no slice-K, so this PR's
  reduction does not apply and it is exact. This follows the earlier
  merges, which kept main's row where main's non-split-K pick is faster.

Signed-off-by: Andreas Karatzas <[email protected]>
Co-authored-by: Claude <[email protected]>
GwilliamHu added a commit that referenced this pull request Nov 27, 2026
op_tests/multigpu_tests/test_mega_moe_v2.py has been in skip_tests since
MegaMoE landed (#4439), so no automated flow runs MegaMoE: changes to its
kernels or launch path merge without a single GPU run. #8600, which moved
every MegaMoE launcher onto the FlyDSL AOT cache, is an example: it was
only validated by hand afterwards.

Run the routes suite (staged, small-input and large-input routes as
production builds them; accuracy against the fp32 reference and the
staged route, per-layer rebinding, epoch wrap, CUDA graph replay) for
DeepSeek-V4-Pro and DeepSeek-V4.1-Flash EP8 on 8 ranks. Like
test_mega_moe_tp.py it skips unless the job has 8 gfx950 GPUs, and it
also skips without mori. Under the job's AITER_FLYDSL_AOT_CACHE=verify it
re-traces each MegaMoE launcher the wheel's AOT prebuild covers and
compares it with the cached object.

Measured on 8x MI355X: 182 s for both networks, with an empty FlyDSL
cache and with the AOT cache in verify mode alike. The suite's timing
section is informational only; pass/fail comes from the accuracy gates
with fixed seeds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GwilliamHu added a commit that referenced this pull request Nov 27, 2026
op_tests/multigpu_tests/test_mega_moe_v2.py has been in skip_tests since
MegaMoE landed (#4439), so no automated flow runs MegaMoE: changes to its
kernels or launch path merge without a single GPU run. #8600, which moved
every MegaMoE launcher onto the FlyDSL AOT cache, is an example: it was
only validated by hand afterwards.

Run the routes suite (staged, small-input and large-input routes as
production builds them; accuracy against the fp32 reference and the
staged route, per-layer rebinding, epoch wrap, CUDA graph replay) for
DeepSeek-V4-Pro and DeepSeek-V4.1-Flash EP8 on 8 ranks. Like
test_mega_moe_tp.py it skips unless the job has 8 gfx950 GPUs, and it
also skips without mori. Under the job's AITER_FLYDSL_AOT_CACHE=verify it
re-traces each MegaMoE launcher the wheel's AOT prebuild covers and
compares it with the cached object.

Measured on 8x MI355X: 182 s for both networks, with an empty FlyDSL
cache and with the AOT cache in verify mode alike. The suite's timing
section is informational only; pass/fail comes from the accuracy gates
with fixed seeds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit that referenced this pull request Nov 27, 2026
…e and #8600

#7788 (the base of this branch) was squash-merged into main as 49ec5a3, and
main has since moved the MegaMoE small-input launcher onto the FlyDSL AOT cache
(#8600) and its buffer helpers onto ptr_buf_tensor / buf_copy_*. The branch
still carried #7788's pre-squash history, so a plain merge conflicted in 15
files. Resolution: every file outside this PR's own 24 commits takes main's
version; the 13 files those commits touch were 3-way merged with base 69b0135
(this PR's starting point) instead of the old merge base, so only this PR's
delta is replayed onto main.

Hand-resolved, mega_moe_small_m.py:
- source_done / arg_running / work_head stores: main's ptr_buf_tensor /
  buf_copy_store forms, with this PR's disp_order, M2 "tl" and "xt" branches.
- LDS plan table: main's plan_incl / plan_count (Int32) plus this PR's
  sh_partial and lean_tab; plan_multi_tile reads them through plan_ptr like
  plan_lookup does.
- shared_in pre-phase and lean table read the dispatch table through main's
  disp_t (main removed _buffer_load / _make_buffer_from_addr).
- run_mega_moe_stage1 is gone on main: _launcher(config, **variant) caches one
  launcher per (config, shared_add / shared_in / shared_in_opt variant), and
  _launch runs it through _run_compiled / _preload_compiled with this PR's
  shared_in tensors and dispatch table.
- gemm1.build_fused_gemm1: main's a_async_lds rename plus this PR's
  mfma_m_active.

aiter/aot/flydsl/sources.py: the small-input cache declares the two new kernel
files it imports (mega_moe/shared_expert.py, silu_mul_quant_epilogue.py) and
the variables its sources now read; the stage1 bundle and large-input caches
declare the three mega_moe_config.py variables (AITER_MEGA_FUSED_BUCKET_MAP,
AITER_MEGA_FUSED_DRAFT_LAYOUT, AITER_MEGA_SMALL_M_OVERRIDE). Without this the
AOT cache (on by default) refuses to build these kernels.

tests/test_mega_moe_gfx950_route_plan.py: EP4 / EP8 / EP2 digests recomputed
on the merged tables. Every knob of every (MTPR, tokens) entry equals this
PR's value where the PR changed it (69b0135 -> 8e2813c) and main's value
otherwise; no knob was changed by both sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
coderfeli pushed a commit that referenced this pull request Nov 29, 2026
…nce optimizations, capacity 32768, rank-shared AOT (#8623)

* tune(mega_moe): 256-wide small-input GEMM1/GEMM2 tiles for EP8 V4.1-Flash at 16 and 32 tokens

Half the GEMM1 tiles and GEMM2 blocks, each streaming a longer weight slab.
Measured on 8x MI355X (EP8 V4.1-Flash a8w4, MTPR 1024, one CUDA graph per
distinct input, max over ranks): -2..-8% per call at 16-32 rows a rank
under uniform, zipf and hot routing. Bitwise identical outputs (asmval, 142
points). The EP8 fused-config digest follows.

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

* perf(mega_moe): send a dedup row before its expert-counter atomic

A deduplicated token row goes to its destination's token-row region, whose
place does not depend on the expert offset the counter atomic returns, so the
row push is issued first and overlaps the atomic's remote round trip.
Bitwise identical outputs (asmval, 142 points: decode MTPR 128 and prefill
MTPR 16384, uniform / zipf / hot / invalid-slot routing, uneven and idle
ranks). Measured with the next three commits: 1-8% per call at 16-512 rows a
rank (EP8 V4.1-Flash a8w4, MTPR 1024; e.g. 512 rows 355.9 -> 344.4 us
uniform, 618.0 -> 587.9 zipf, 1487.4 -> 1417.6 hot).

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

* perf(mega_moe): quantize each token row once in the small-input dispatch

With dedup_rows a producer wave takes a token instead of a route: it loads
and quantizes the row once and pushes it to each distinct destination rank
of its top-k (one lane a route; v_readlane keeps the remote pointers
scalar), and the top-k counter atomics go out from one instruction. Before,
each route's wave quantized the row again. Bitwise identical outputs
(asmval, 142 points); part of the 1-8% measured with the neighbouring
dispatch and entry changes.

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

* perf(mega_moe): interleave an expert's slots over its small-input m-tiles

m-tile t of an expert with nt m-tiles takes its slots t, t + nt, ..., so the
rows of a GEMM2 tile come from many source ranks and its returns spread over
their links instead of one. A row's GEMM math and the combine's fixed top-k
order are unchanged, and the slot order within an expert was already decided
by racing atomics: bitwise identical outputs (asmval, 142 points); part of
the 1-8% measured with the neighbouring dispatch and entry changes.

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

* perf(mega_moe): small-input entry without the ticket atomic and epoch gate

Protocol change: a launch no longer takes an entry ticket (one atomic per
CTA) or waits at an epoch gate. Roles go by block id (owner, producers,
consumers), and every CTA reads the entry state past L2: the previous
launch's epoch (DispatchSlot.LAUNCH_EPOCH), parity and expected source
value, and advances them itself. The last WG of a launch (the combine's last
ticket, when every CTA is past its reads) zeroes the work and producer
counters and stores this launch's epoch, parity and expected value for the
next one; stream order puts those stores before the next launch's loads.
Cross-rank buffers written before the plan stay parity double-buffered, so
no handshake is needed. The names follow (launch_epoch, cta).

The op test's epoch-wrap case now presets the runtime's launch-epoch word
(the entry ticket counter it preset is gone); the next launches still cross
the 32-bit wrap. Bitwise identical outputs (asmval, 142 points); part of the
1-8% measured with the dispatch changes before it.

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

* feat(mega_moe): EP8 small-input GEMM1 pairs an expert's 32-row m-tiles into 64-row units

On a rank that reads W1 through the cache (a hot expert or many routed rows), each GEMM1 unit of an expert
with more than one m-tile runs a pair of its interleaved m-tiles (2j, 2j + 1) as one 64-row tile, so its W1
slab is read once per 64 rows instead of once per 32. The local plan keeps a per-expert unit-group table
next to its m-tile table; a unit's plan comes from one ballot lookup over it (shared with the m-tile lookup).
The XCD slices of the GEMM1 unit space stay equal in m-tile units (a pair's units weigh two m-tiles'), so an
XCD holding a paired hot expert does not take more rows than the others; a rank that does not pair skips
those lookups. GEMM2 keeps its m-tile units and slices.

V4.1-Flash EP8 configs: pair_tiles at 64 and 128 tokens. Measured on 8x MI355X (a8w4, MTPR 1024, 3 ABBA
rounds against the parent): hot -11.7% at 64 rows a rank and -17.3% at 128, zipf -1.0% / -4.2%, uniform and
the other sizes within +-0.2%. Bitwise identical outputs (asmval, 142 points; MFMA order per accumulator
unchanged).

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

* feat(mega_moe): EP8 V4.1-Flash large-input route at every capacity

V41_FLASH_EP8_LARGE_M_MTPRS lists every large-input capacity (1024..16384).
The fault that kept capacities 1024-4096 on the staged route came from
another process's kernels sharing the GPUs, not from the kernel: on exclusive
GPUs the large-input route at 1024, 2048 and 4096 passes the asmval large
points three times each without a fault. An EP8 instance below 8192 now
serves prefill through the fused route (768 rows a rank at capacity 1024:
354 us vs 518 us staged, uniform). The config docstring and the AOT README
follow.

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

* feat(mega_moe): serve A4W4 decode calls through the fused small-input route

An A4W4 MegaMoEV2(routed=True) on a FUSED_LAYOUTS layout (EP8 DeepSeek-V4-Pro,
EP8 / EP4 / EP2 DeepSeek-V4.1-Flash) now builds the small-input runtimes and
sends calls of up to 512 rows a rank through the fused dispatch + GEMM1 +
GEMM2 + combine kernel; above that A4W4 takes the staged route. The
large-input route stays A8W4 (LARGE_M_QUANTS).

- The producers quantize each bf16 row to MXFP4 (E2M1 + E8M0 per 32 values),
  bit-identical to per_1x32_mx_quant(quant_mode="fp4") of the staged route,
  with the MXFP8 lane mapping (16 values a lane, a scale group per lane pair):
  a lane stores 8 payload bytes per 1024-value chunk, so rows of 5120 / 7168
  values tile exactly. The dedup_rows producers (one quantization a token)
  take the same path.
- GEMM1 reads FP4 A (128-byte K-steps), also through the dedup_rows srcmap.
- The GEMM1 output stays FP8, so GEMM2 and the combine are unchanged; the
  shared GEMM1-output arena is sized per route dtype.
- Kernel names gain _afp4 for A4W4 only; the A8W4 kernels are unchanged.
- The V4.1-Flash AOT profiles ship A4W4 as well.

The A4W4 small-input kernels use the A8W4 small-input tunes unchanged.

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

* test(mega_moe): run the routes suite with --quant a4w4

The routes suite builds the instance with --quant (A4W4: small-input and
staged routes, gated at relL2 0.25 against the fp32 reference and the staged
route).

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

* refactor(mega_moe): share the MX quant helpers with the fused small-input producers

Review follow-ups on the A4W4 small-input route:
- The E8M0 scale comes from quant_utils.emit_mx_e8m0_scale (RoundUp) in
  per_1x32_mx_quant and in the fused producers' _quantize_row_mx; quant.py
  gains pack_mx_fp4_words, which both use for the FP4 words.
- The payload store derives a lane's word count from the quantized row; the dead
  fz_n_i32 argument of emit_direct_fixed_slot_payload and TILE_K_BYTES go.
- SmallMRuntime / LargeMRuntime gate on FUSED_QUANTS / LARGE_M_QUANTS; the
  small-input payload capacity takes the A dtype (MegaMoEV2 drops _quant).
- The route-plan test covers MTPR 128 and 8192, pins the payload-arena size, the
  staged A4W4 row bytes and the FP8 GEMM1 output, and reuses the shape dicts.
- README: fused small-input route a8w4 or a4w4, large-input a8w4 only; the
  V4.1-Flash defaults build both quants.

ISA: the small-input kernels (a8w4 and a4w4) are byte-identical to the parent's
(offline gfx950 build of every token bucket).

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

* refactor(mega_moe): let the fused GEMM1 short and fold tiles read FP4 A

Prepares the A4W4 large-input route, whose GEMM1 runs the short, mid and
fold tiles (dedup_rows srcmap, async A copies) on packed FP4 rows:

- ATileLoader: an async A copy may end on a partial round (an FP4 fold tile
  of 128 + 32 rows is 1280 16-byte chunks, 2.5 rounds of 512 threads); the
  round runs on its leading waves, and load_row_map points the idle threads'
  rows past the tile at its last row, so the row-arrival wait never spins on
  another tile's rows. Every existing tile copies whole rounds and keeps
  its code.
- build_fused_gemm1: the short / fold tile loaders and MFMAs take the A
  dtype and its row bytes; the row_map path no longer requires 256-byte
  K-steps.

No kernel changes: the A8W4 tiles pass the same values.

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

* feat(mega_moe): serve A4W4 prefill calls through the fused large-input route

An A4W4 MegaMoEV2(routed=True) on a FUSED_LAYOUTS layout now also builds the
large-input persistent kernel at the capacities large_m_mtprs_for() gives the
layout (1024..16384 for EP8 DeepSeek-V4-Pro and EP8 DeepSeek-V4.1-Flash, 8192
and 16384 for EP4 / EP2 DeepSeek-V4.1-Flash), so a call of 513 rows a rank up
to the capacity is fused like A8W4 instead of taking the staged route.
LARGE_M_QUANTS goes: both fused routes take FUSED_QUANTS.

- The input quant kernel writes MXFP4 rows (model_dim / 2 bytes, the same
  E8M0 scales); the dispatch moves them in 64-lane column blocks of 1024
  values, a dwordx2 a lane (dwordx4 for FP8), in the presend and batched
  payload copies; the route-major copy takes any dwordx4-aligned row.
- GEMM1 reads FP4 A (128-byte K-steps) in every tile shape: main, short,
  mid and fold, also through the dedup_rows srcmap (x_bytes from the FP4
  row size).
- The GEMM1 output stays FP8, so GEMM2 and the combine are unchanged; the
  shared GEMM1-output arena is sized for the large-input route's FP8 rows.
- LargeMRuntime sizes its payload, quant buffers, input checks and AOT
  preload by the A dtype; _dispatch_dtype moves to mega_moe_stage1 for both
  fused runtimes.
- Kernel names gain _afp4 for A4W4 only; the A8W4 kernels are unchanged.

The A4W4 large-input kernels use the A8W4 large-input tunes unchanged. The
route-plan test follows: A4W4 routed instances of the four fused layouts take
the large-input route at MTPR 8192 and 16384 (FP4 payload rows, uint8 quant
buffer, FP8 GEMM1 output held by the shared arena), the large-input buffers
fit 32-bit offsets for both quants, and the A4W4 large-input kernel runs the
A8W4 config and Stage2 spec with row copies and GEMM1 tiles of whole column
blocks and waves.

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

* test(mega_moe): cover the A4W4 large-input route

- AOT: the V4.1-Flash EP4 / EP2 / EP8 A4W4 jobs include the large-input
  MTPRs (8192, 16384).
- Multi-GPU: the A4W4 large-input route is compared with the staged route
  to --rtol (FP8 vs FP4 GEMM1 output), in the main comparison, layer-slot
  stress and skewed route switch; the SiLU gate checks the instance's quant.
  The fused-vs-staged gates of the size suite's main comparison and the
  routes suite also fail on any row off by more than half its norm (a
  corrupted row the tensor's relative L2 would hide).

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

* feat(mega_moe): per-quant fused configs for A4W4 tuning

select_fused_config takes the quant: A4W4 starts from a layout's A8W4
config and goes through _tune_a4w4_small / _tune_a4w4_large (identity for
now), so the A4W4 small- and large-input routes can take tunes of their own.
The runtimes select their configs with their quant, and the payload-sharing
classmethods (indexed_payload, payload_capacity, ends_all_ranks) take the
activation dtype, since a tune may change the protocol knobs they read.
No kernel changes.

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

* feat(mega_moe): per-bucket large-input configs and a small-input split-tail knob for A4W4 tuning

Large-input route: a call launches the config of its EP-wide max_tokens
(MegaMoEV2.forward / forward_prequant pass it through; None keeps the
capacity's config), so _tune_a4w4_large takes the token bucket and can
change the launch geometry per row count, as the staged path does. The
knobs that size the runtime's buffers or set what the routes share
(large_m_runtime_knobs: P2P quant, dedup rows, bucket pairs, combine token
wait, row alignment, scale staging) must agree across the buckets of a
capacity; LargeMRuntime checks it, sizes the scale staging buffer for the
largest bucket config and preloads every distinct bucket config. A8W4
still runs one config per capacity.

Small-input route, FusedStage1Knobs.g1_split_tail (off by default): with
tile_n 256, up to N units of an XCD slice's partial last GEMM1 round run as
two tile_n / 2 halves, as many as that round leaves CTAs idle; GEMM2
readiness counts half units. It enters the small-input kernel name only when
set (not with pair_tiles). The kernel's GEMM1 builds share one argument list.
The small-input kernels are byte-identical to the parent's (offline gfx950
build); on 8x MI355X per-bucket large configs (V4-Pro EP8) and g1_split_tail
(V4-Pro EP8 small-input kernel) run correctly (--check-time-acc).

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

* feat(mega_moe): A4W4 tune for EP8 DeepSeek-V4-Pro fused routes

A4W4 on EP8 V4-Pro now takes its own small- and large-input tunes instead of
the A8W4 ones (A8W4 configs and every other layout are unchanged).

Large input (routes suite, MTPR 16384, speedup = staged / fused):
  rows      513   1024  2048  4096  8192  16384
  before   0.871 0.935 0.995 0.953 1.013 0.982
  after    1.307 1.365 1.384 1.283 1.246 1.182
The EP4 V4.1-Flash knob set without the parts V4-Pro's dims cannot take
(fold_tail / mid_tail_rows, GEMM2 fold_tail / nt_single / ascale_lds /
early_p_mid), cached W1, payload_min_blocks 4, and early_p 2 from the
8192-row bucket.

Small input (MTPR 512):
  tokens     1     16    64    128   256   512
  before   1.538 1.584 1.614 1.628 1.295 1.083
  after    1.749 1.621 1.637 1.646 1.304 1.124
The EP8 V4.1-Flash small tune (with its 256-wide GEMM1/GEMM2 n-tiles at 16
tokens) without the parts measured on V4.1-Flash only (its 256-wide GEMM2
tiles at 32 tokens and its GEMM1 m-tile pairs), cached W1 at 1 token, and
256-wide GEMM1 n-tiles with g1_split_tail 64 at 256/512.

The A4W4 large-input test now checks the A4W4 config and compares the payload
geometry with A8W4 only while the runtime-sizing knobs agree (the V4-Pro A4W4
tune dedups dispatch rows).

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

* feat(mega_moe): A4W4 tune for EP8 DeepSeek-V4.1-Flash fused routes

A4W4 on the EP8 V4.1-Flash layout takes its own small- and large-input
tunes (_tune_v41_flash_ep8_a4w4_small / _large) on top of the A8W4 ones,
selected from the A4W4 hooks; A8W4 configs are unchanged.

Small input: bucket 1 cached W1; bucket 16 256-wide GEMM1/GEMM2 tiles with
g1_split_tail 64; buckets 256/512 256-wide GEMM1 tiles; the A8W4 tune's
GEMM1 m-tile pairs at 64 / 128 tokens and 256-wide GEMM2 tiles at 32 carry
over. Large input: buckets >= 2048 payload_min_blocks 4; 512/1024 keep the
A8W4 tune.

Measured on gfx950, 8 ranks, routes suite, MTPR 16384 (staged/routed,
uniform; measured before this series carried the A8W4 small-input
changes): small 1.31-2.37x -> 1.37-2.49x, large 1.22-1.66x ->
1.25-1.68x; zipf 1.0 and all-to-rank-0 routing do not regress.

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

* tune(mega_moe): A4W4 EP4 V4.1-Flash fused small/large configs

Small: tile_n 256 + g1_split_tail 64 at 64/256 tokens, stream_w + early_p 6
at 512. Large: cached W1, 64 producer CTAs and early_p 2 from 4096 tokens.
Measured on gfx950 (4 ranks, routes suite, MTPR 16384); A8W4 unchanged.

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

* tune(mega_moe): A4W4 EP2 DeepSeek-V4.1-Flash fused small- and large-input configs

Small-input: cached W1 at 1 token, 256-wide GEMM1 tiles at 64 tokens.
Large-input: presend over 16 local experts. A8W4 configs unchanged.

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

* test(mega_moe): A4W4 fused-config digests and quant-parametrized protocol checks

- A4W4 fused-config digests for EP8 DeepSeek-V4-Pro and EP8 / EP4 / EP2
  DeepSeek-V4.1-Flash: every small-input bucket at MTPR 256 and 512 and every
  large-input capacity of the layout at each of its token buckets.
- The *_small_m_buckets_share_one_protocol tests run for a8w4 and a4w4.
- EP8 V4.1-Flash pairs an expert's 32-row m-tiles at 64 and 128 tokens for
  either quant (the A4W4 tune keeps the A8W4 one there), on the interleaved
  local plan the pairing needs.
- The A4W4 large-input config geometry is checked at every capacity a layout's
  large-input route serves (1024..16384 on EP8).

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

* feat(mega_moe): V4.1-Flash EP4 / EP2 large-input route at every capacity

Every fused layout now builds the large-input kernel at every capacity in
LARGE_M_MTPRS (1024..16384), as EP8 V4.1-Flash already did since 6420f64;
large_m_mtprs_for() and the per-layout V41_FLASH_EP*_LARGE_M_MTPRS lists go.
EP4 and EP2 reuse their existing large-input tunes unchanged: the tunes do not
depend on the capacity (A4W4 varies by token bucket only), so a capacity below
8192 launches, at each bucket, the config the 16384 capacity launches there.

The EP4 fault once seen at 1024-4096 is believed to be the same co-residency
misdiagnosis as EP8's (another process's kernels sharing the GPUs); GPU
revalidation of EP4 / EP2 at 1024, 2048 and 4096 is pending.

Offline: the AOT replay builds EP4 and EP2 at MTPR 1024 / 2048 / 4096 for a8w4
and a4w4 (36 jobs ok, --check 36 ok). Rank-0 large-input kernel spills vs the
16384 kernels: a8w4 keeps sgpr 47 / vgpr 50 / scratch 188 everywhere; a4w4
keeps sgpr 47 / vgpr 31 / scratch 112 at EP4 2048 / 4096, but EP4 1024 and EP2
1024 / 2048 / 4096 spill one more vgpr (vgpr 32, scratch 116 vs 31 / 112).
The shipped AOT MTPR list is unchanged; its comment and the README follow.

Tests: the capacity tests run every layout over LARGE_M_MTPRS, a new test pins
that each capacity's configs equal 16384's, the A4W4 digests stay over the
capacities they pinned, and the offline routed instance adds MTPR 1024 / 4096.

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

* feat(mega_moe): send every call the small-input route cannot take to the large-input route

MegaMoEBundlePlan.route_for drops the max_tokens >= LARGE_M_MIN_TOKENS bound
of the large-input route: on an instance that builds it, a call the
small-input route does not take (forward_prequant, a part without 256 CUs, a
max_tokens above the reduced small_m_mtprs) runs fused instead of staged. With
the large-input route at every capacity of every fused layout, a routed
instance at a power-of-two MTPR up to 16384 now stages no call that passes
max_tokens.

Such a call of fewer than LARGE_M_MIN_TOKENS rows launches the
LARGE_M_MIN_TOKENS config, which large_m_buckets() already builds, so no new
kernel is compiled; every large-input tune keeps that config up to 1024 rows
(a test pins it), so it is also the config of the call's own bucket. Calls of
513 rows or more take the same route and config as before.

Tests: an exhaustive sweep (4 fused layouts x a8w4 / a4w4 x MTPR 1..16384 x
every max_tokens) asserts no routed call stages and every large-input call
launches a built bucket, and that without the small-input route the
large-input route takes every call from MTPR 1024; the route-exclusion and
routed-instance tests cover prequant and reduced small capacities.

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

* fix(mega_moe): keep the large-input 8-bit combine offset off the gfx950 packed high-dword read

The combine tail of a route_i8 large-input kernel subtracts 128 x the scale
sum from each unit's four accumulators. Written as a vector product, the
compiler packed two units' offsets into one register pair and subtracted the
second one with v_pk_add_f32 op_sel:[0,1]: the low half reads src1's high
dword, the pattern that reads 0 in lanes 48-63 on gfx950 while another wave of
the SIMD runs MFMA (#7818). Each unit's offset is now one scalar
product subtracted value by value, so it sits in the low dword of its own
register and the packed subtract broadcasts it with op_sel_hi only.

Same operations in the same order: bitwise identical results. Offline gfx950
ISA of the V4.1-Flash EP8 (1024, 16384), EP4 and EP2 (16384) large-input
kernels, A8W4 and A4W4: 4 -> 0 op_sel:[x,1] packed-f32 instructions each,
same VGPR/SGPR counts, 3-5 fewer instructions. Found in BinDing's
0055824 (AITER_MEGA_LARGE_V3=qf), which used inline v_sub_f32 instead.

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

* perf(mega_moe): spread a few-token launch's dedup sends over each producer's waves

With dedup_rows one producer wave takes a token: it quantizes the row once and sends it to every destination
of its top-k. At 1-4 tokens a rank that leaves the other waves of each producer CTA idle and puts all of a
token's remote rows behind one wave. A launch of at most _SPREAD_MAX_TOKENS (4) tokens a rank now has every
wave of the token's producer CTA quantize it and send, count and publish the routes of its own top-k slots
(slot j: wave j % num_waves). The writes each destination sees, and the protocol (one producer CTA a token,
the same done counts), are unchanged; the choice is rank-local.

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

* perf(mega_moe): fused small-input GEMM2 stores BF16 P2P rows with every lane of the workgroup

The fused small-input kernel's GEMM2 epilogue scattered one weighted BF16 row per wave store with
BN // 8 lanes active (32 of 64 at BN 256), each row behind a readfirstlane chain for its route,
weight and peer base. On BF16 launches (fp8_rows == 0) every lane now stores 16 bytes of one row,
64 // (BN // 8) rows per store (as amd-kernels PR #12's fused EP8 return path), through a global
store at its own peer address; the route/weight/peer/value LDS reads of all passes are issued
before the first store. FP8 launches (with their BF16 head rows) keep the per-wave rows.

Each element is still f32(acc) * f32(weight) rounded once to BF16 at the same destination byte,
so the P2P rows and the combine output are bitwise unchanged. Lean / tok_done epilogues are
untouched (wide_bf16 is off for them).

V4.1-Flash EP8 decode (MTPR 512, ABBA, 1-512 rows x uniform/zipf/hot): 0 points slower;
8 rows uniform/zipf 1.7-2.2% faster and 192/256 rows uniform 1.1-2.4% faster, both quants.

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

* tune(mega_moe): EP8 V4.1-Flash 8-column GEMM1 epilogue from 16 small-input tokens

Both quants, from the 16-token bucket: the per-tile output resource with the 8-column GEMM1 quantize/store pass
(epi_evec 8) and its no-serial-wait form (epi_lean 1; the IEEE SiLU stays, so outputs are bitwise-identical).
ATT of the hot rank at 128 zipf tokens: the 2-column pass costs 49k cycles a wave, 16k of them on its 2-byte
stores. Applied in _tune_v41_flash_ep8_small_both after the A8W4 / A4W4 tunes of the V4.1-Flash EP8 layout only.
Offline gfx950 ISA: 236-248 VGPRs; the a8w4 pair-tile body (64 / 128 tokens) spills 4 SGPRs.

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

* perf(mega_moe): small-input 64-row GEMM2 issues its B loads ahead of the barrier and the A copy

The fused small-input kernel's BM64 / BN256 GEMM2 tiles (256 and 512 tokens) take gemm2_compute_v2's
early_b_load with a_dma_uniform: each K-step's W2 and scale loads go before the barrier and an unconditional
A copy, so the first MFMA waits for them with vmcnt(4) (the copy stays in flight). Before, the A copy was issued
first and the MFMAs waited vmcnt(2) behind it. ATT at 192 uniform tokens: that wait (gemm2.py:92) is
41.1k / 40.5k cycles a wave (9.7% / 9.4%, A8W4 / A4W4). Both quants (GEMM2 reads FP8 A for either).
Offline gfx950 ISA: no new spills; the 32-row tiles (and EP2) compile byte-identical.

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

* refactor(mega_moe): clamp-SwiGLU of the GEMM1 epilogue as a module function

SiluQuantEpilogue's silu(gate) * up with the swiglu_limit clamps becomes gemm_util.silu_mul_f32, so a GEMM1
body with its own epilogue computes the same values. Same operations in the same order: every offline gfx950
small-input kernel (EP8 / EP4 / EP2 V4.1-Flash, EP8 V4-Pro, A8W4 / A4W4, 1-512 tokens) compiles byte-identical.

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

* perf(mega_moe): ring GEMM cores for the fused small-input kernel (ring_core knob, off)

The small-input GEMM1 / GEMM2 K-loops wait on loads they just issued: at 192 uniform tokens ATT shows 66.2k
(GEMM1) and 45.1k (GEMM2) cycles a wave of vmcnt waits against 10.8k / 5.6k in amd-kernels PR #12, whose
loops are issue-bound instead. The new gemm_ring module ports that PR's GEMM core as one unit:

- the K loop is unrolled at trace time (no back-edge register copies), the FP4 weights are the scaled MFMA's
  operand A, and step k + pf's weight loads are spread over step k's MFMAs in the order they are emitted;
- the activation rows reach LDS by async DMA (BufferLoadAsyncLDS128b, asyncmark groups) through an nbuf-stage
  ring of 128-K steps in MFMA fragment order, nbuf - 2 >= pf steps ahead, so a weight wait never drains it;
- GEMM1 runs clamp-SwiGLU and the 1x32 MXFP8 quant in registers (no C-shuffle) and stores its output in the
  fragment order GEMM2's ring copies, with one scale dword per row and K step;
- GEMM2 reads its first pf weight steps and its rows' route ids before the m-tile's ready wait (the first read
  of the ready word goes ahead of them), and drops the CU's L1 at the unit claim, before any of its loads.

FusedStage1Knobs.ring_core = (pf1, nbuf1, pf2, nbuf2) turns it on (kernel name _rc...). It needs 64-row
interleaved m-tiles, 64 GEMM1 columns a wave (tile_n 256) and 256-wide GEMM2 tiles; each wave owns 64 rows x 32
intermediate / 64 hidden columns. Dispatch, plan, unit claims, ready epochs and combine are unchanged; GEMM2
takes its m-tile's expert and rows from the CTA's own plan. The GEMM2 scatter epilogue gains acc_t (transposed
accumulators, 16-byte LDS writes, rows BN + 4 floats apart). Both quants share the code: only GEMM1's activation
differs (FP4 rows: one slot a row tile and step).

No config sets ring_core yet: every offline gfx950 small-input kernel compiles byte-identical.

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

* tune(mega_moe): EP8 V4.1-Flash small-input ring GEMM cores from 64 tokens

Both quants, buckets 64-512 (_tune_v41_flash_ep8_small_both): ring_core (2, 4, 2, 6) on 64-row m-tiles,
256-wide GEMM1 units and 256-wide GEMM2 tiles; 64 and 128 tokens leave their 32-row m-tile pairs (amd-kernels
PR #12 runs its 64-row tier from 49 tokens). GEMM2 weights go 2 steps ahead: with 4 weight loads a step and wave
that is more bytes in flight per CU than the PR's 3 steps of 2 (3 steps spill 12 VGPRs).

Offline gfx950 ISA (FlyDSL 0.5.3), A8W4 / A4W4: 252-256 VGPRs (128 arch + AGPRs), no scratch, LDS 67728 B
(2 CTAs a CU: 135 KiB of 160), 1856 MFMAs (2 x 640 GEMM1 + 2 x 288 GEMM2, unrolled), steady K-loop waits
vmcnt(7-16) where the 64-row bodies they replace wait vmcnt(0-2). Every other layout and bucket compiles
byte-identical. Config digests updated for EP8 V4.1-Flash.

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

* perf(mega_moe): half-height ring GEMM bodies for m-tiles of at most 32 rows

With interleaved m-tiles an m-tile of at most half the 64 rows is its expert's only one. Its GEMM1 unit and GEMM2
tiles run 32-row ring bodies (streamed weights) instead of the 64-row ones: half the MFMAs, activation DMA slots and
epilogue rows. The GEMM2 epilogue takes zero accumulators for the masked upper rows.

EP8 V4.1-Flash on MI350X against the parent of the ring commits (ABBA x2, MTPR 512): 142/142 asmval points bitwise
for both quants; 1-32 tokens within noise; 64-512 tokens zipf / hot -2~-17%. Uniform routing loses at 64-128 tokens
(A4W4 +1.7~2.4%, A8W4 +0.6~1.3%) and wins from 192. Bucket rule: a bucket keeps the ring core when its zipf / hot
gain exceeds its uniform loss (serving routing is skewed, the hot expert takes ~49% of the tokens); that holds for
every bucket of both quants (worst: A4W4 64 tokens, uniform +2.4% against zipf -12.5% / hot -4.0%), so both quants
share the 64-512 ring buckets.

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

* perf(mega_moe): large-input GEMM2 claims ahead and reads m-block classes from LDS

The large-input kernel's GEMM2 loop paid two serial thread-0 chains per
(m, n) unit between its barriers: the claim RMW and, with g2_skip_pad, a
chain of dependent srcmap / tile-row / expert loads that classifies the
claimed m-block (skip, fold its tail, single m-block).

- Every CTA classifies all m-blocks once at GEMM2 entry, one m-block per
  thread, into one LDS byte each in the A-scale bytes GEMM2 leaves unused;
  a claim then reads its m-block's byte. The class reads only plan-final
  rows, so it equals the per-claim result.
- A unit's publish takes the CTA's next claim before its drain, so the
  claim RMW returns while the peer stores retire; the loop head uses it
  (or claims itself after a skipped unit).

Each unit is still claimed once and run by its claimer with unchanged
per-row math, scatter and close protocol, so outputs stay bitwise equal.

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

* refactor(mega_moe): drop the large-input on/off API; max_tokens is the route switch

Remove MegaMoEV2.set_large_m_enabled(), the large_m_enabled constructor argument and the _large_m_choice state.
forward(max_tokens=...) already picks the route of every call (MegaMoEBundlePlan.route_for): on a routed instance
a call with max_tokens takes a fused route on every fused layout, and a call without it keeps main's staged route
(fixed-slot or compact), as it did while set_large_m_enabled() had not been called. routed=True builds the
large-input route wherever the layout and capacity support it; routed=False keeps the staged instance of main.
A second switch could only send a call with max_tokens to the staged route; MegaMoEBundlePlan.route_for drops its
large_m exclusion with it.

The only external user was the unmerged SGLang PR sgl-project/sglang#47065, written against an older interface.
The multi-GPU tests take their staged reference from a call without max_tokens, and the size suite and the
benchmark pin their plan through routed / small_m_mtprs.

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

* fix(mega_moe): small-input co-residency check covers the whole LDS and the pair tiles

The small-input fused kernel needs its whole grid resident (2 CTAs a CU): the combine
reducers spin until every CTA took its ticket. The LDS check counted only the pool, not
the A scales, the work word and the plan tables, and pair_tiles at 64-row m-tiles
(128-row pairs) needs 87440 bytes of LDS and 264 registers (one CTA a CU, a hang).
Check the whole SharedStorage at compile time and reject pair_tiles off 32-row m-tiles
in the config. The check equals the compiled LDS size of every offline gfx950 small-input kernel
(V4.1-Flash EP8 / EP4 / EP2, V4-Pro EP8, both quants, 1-512 tokens, 30608-81040 bytes) except the ring-core
kernels, which it bounds 16 bytes high (67744 vs 67728: their A-scale words are unused). No kernel changes
(the 72 kernels compile byte-identical).

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

* perf(mega_moe): ring GEMM cores for every small-input layout and bucket

Every small-input config (EP8 V4-Pro and EP8 / EP4 / EP2 V4.1-Flash, A8W4 and
A4W4, token buckets 1..512) runs the gemm_ring GEMM1 / GEMM2 cores on 64-row
interleaved m-tiles of the local plan, 256-wide GEMM1 units and 256-wide GEMM2
tiles; an m-tile of at most 32 rows (most of them at the small buckets) runs
the half-height bodies. V4-Pro A8W4 takes the dedup rows and local plan the
ring reads; at V4-Pro's dims the GEMM2 weights go one step ahead (two spill).

To fit every layout without scratch: the kernel allocates no AGPRs (with them
the registers split 128 / 128 and the K loops spill VGPRs or copy operands
between the halves), the pointers and epoch the consumer loops hold across
the GEMMs are SGPRs and GEMM2's other dispatch-table pointers and the combine
peer base are loaded past GEMM1 (held through it as VGPRs, they spill the K
loops), grids of one CTA a CU hint one wave a SIMD (the EP4 4-token kernel
spilled), and the 16-token grids of two CTAs a CU no longer hint one.

Offline gfx950 ISA (FlyDSL 0.5.3), all 144 small kernels (4 layouts x 2 quants
x 9 buckets x MTPR 256 / 512): no scratch, at most 256 VGPRs, at most 68.7 KiB
LDS a CTA (two CTAs a CU fit).

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

* refactor(mega_moe): the small-input kernel keeps only the ring GEMM cores

Every small-input config runs the ring cores (previous commit), so the old
GEMM bodies of compile_mega_moe_stage1 go: the streamed / cached / paired /
split-tail GEMM1 builds, the gemm2_compute_v2 tile runner, their LDS (A-scale
tile, C-shuffle) and resources, the m-tile pair plan and the split-tail work
encoding. What the ring requires becomes the kernel itself: dedup token rows
(the per-route payload dispatch goes) and the CTA-local interleaved plan.

Knobs that no config reads any more go with them: FusedStage1Knobs plan_local,
g2_uniform, g1_lookahead, g1_a_ahead, g1_split_tail, pair_tiles and ring_core
(the ring depths are the kernel's: GEMM2 weights one step ahead at V4-Pro's
model dim), and the small kernel's tile_k, pipe_weights, mfma_amajor,
swizzle_a, async_a_copy, use_tile_resource, epi_evec, epi_lean and
ascale_packed (large-input only now). The small-input tunes keep what still
changes a kernel; the protocol tuple is direct_done, tok_counters,
bf16_head_tokens. The launch drops the unused sorted-id / expert-id / token
count / input-scale arguments, and the fixed slots are 64 rows (the m-tile).

Offline gfx950 ISA, all 144 small kernels vs the previous commit: the same
MFMA and memory instructions (kernel-argument loads and register allocation
differ), no scratch, LDS <= 68.7 KiB a CTA. Math order unchanged.

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

* refactor(mega_moe): drop the shared GEMM helpers' small-input-only paths

With the small-input kernel on the ring cores, the staged Stage1 and the
large-input kernel are the only users of build_fused_gemm1 and its helpers,
and both run do_tile. do_tile_la, the paired-tile runner and _PairEpilogue
go, with build_fused_gemm1's rows_rsrc / lookahead / plan_lookup / a_ahead /
pair_tiles; the A loaders' paired / tx modes, their row_stride and valid-rows
clamps, the epilogue's valid-rows / store-policy overrides, the B-scale load
cache policy and gemm2's valid_rows. _LA_CM moves to gemm_ring, its last user.

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

* perf(mega_moe): 32-row ring m-tiles for the small-input buckets up to 128 tokens an EP group

Up to 128 tokens an EP group (EP8 16, EP4 32, EP2 64 tokens a rank) the
small-input kernel plans 32-row m-tiles and runs only the 32-row ring bodies
(the 64-row kernels carry both heights). The kernel is half the size, and the
experts that hold every token of a skewed launch get twice the GEMM1 / GEMM2
units while those still fit one round of the grid. Per-row math order is
unchanged. The plan CTA's m-tile metadata, sized by 64-row m-tiles, holds the
32-row m-tiles of these buckets too (asserted).

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

* refactor(mega_moe): drop the ring cores' fixed knobs and stale small-input notes

What: make_ring_gemm1 takes no sw_cm / q_cm (every caller passed the same
sc0|nt policy, now gemm_ring's _G1_CM) and _lane_ids no unused wave count;
the small-input finalize drops interleave / keep_running (its only caller
passes True for both) and the non-interleaved metadata branch;
SiluQuantEpilogue's fused vec8 store reads its own cache policy instead of
a pass-through argument; comments that named the removed la2 bodies or
64-row-only tiles are corrected.

Why: dead parameters and branches left by the ring-core switch.

Effect: no code generation change: the small-input final ISA of 42 kernels
(EP8 / EP4 / EP2 V4.1-Flash and EP8 V4-Pro, a8w4 and a4w4, 1..512 tokens)
is byte-identical to the previous commit's (FlyDSL 0.5.3, gfx950).

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

* refactor(mega_moe): small-input plan CTA publishes only the plan flag

What: the small-input finalize keeps the source wait, the expert counts and
the plan-flag store, and drops the per-m-tile metadata it wrote (sorted
expert ids, tile row bases, tile rows, num_valid / overflow words), the
plan_wt knob that only set those stores' cache policy and the release
before the flag, and the dispatch-table slots and workspace that only the
removed bodies read (SORTED_EXPERT, TILE_ROW_BASE, NUM_VALID, TILE_ROWS,
G2_EIDS, G2_TRB, G2_MAX_M_BLOCKS, XCD_ACQ). The remaining slots keep their
indices. Fused-config digests move only by the removed plan_wt field (the
old tables without it hash to the new digests).

Why: every CTA builds the plan in its own LDS since the ring cores
replaced the old GEMM bodies; nothing reads the plan CTA's metadata.

Effect: the 42 small-input kernels checked (EP8 / EP4 / EP2 V4.1-Flash and
EP8 V4-Pro, a8w4 and a4w4, 1..512 tokens) keep their VGPR / SGPR / LDS
and have no scratch; the plan CTA's code is about 600 ISA lines shorter.

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

* [CI] Run the MegaMoE V2 routes suite in the multi-GPU job

op_tests/multigpu_tests/test_mega_moe_v2.py has been in skip_tests since
MegaMoE landed (#4439), so no automated flow runs MegaMoE: changes to its
kernels or launch path merge without a single GPU run. #8600, which moved
every MegaMoE launcher onto the FlyDSL AOT cache, is an example: it was
only validated by hand afterwards.

Run the routes suite (staged, small-input and large-input routes as
production builds them; accuracy against the fp32 reference and the
staged route, per-layer rebinding, epoch wrap, CUDA graph replay) for
DeepSeek-V4-Pro and DeepSeek-V4.1-Flash EP8 on 8 ranks. Like
test_mega_moe_tp.py it skips unless the job has 8 gfx950 GPUs, and it
also skips without mori. Under the job's AITER_FLYDSL_AOT_CACHE=verify it
re-traces each MegaMoE launcher the wheel's AOT prebuild covers and
compares it with the cached object.

Measured on 8x MI355X: 182 s for both networks, with an empty FlyDSL
cache and with the AOT cache in verify mode alike. The suite's timing
section is informational only; pass/fail comes from the accuracy gates
with fixed seeds.

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

* ci: run the MegaMoE V2 routes suite for V4.1-Flash EP8 A4W4 too

The multi-GPU case added in the previous commit runs the routes suite for
DeepSeek-V4-Pro and V4.1-Flash EP8 with the default A8W4; this PR adds the
fused A4W4 routes, so the case also runs --network v41_flash --quant a4w4
(about 1.5 min on 8x MI355X).

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

* feat(mega_moe): large-input route at MTPR 32768 on every fused layout

Add 32768 to LARGE_M_MTPRS, so a 32768-capacity instance (ATOM's prefill
max_num_batched_tokens) builds the large-input route and every call that
passes max_tokens takes a fused route (small-input up to 512 rows a rank,
large-input above) instead of staging 513..32768 rows.

At 32768 every layout's large-input config sends a token row to a
destination once (dedup_rows, indexed payload). The V4.1-Flash tunes and
the V4-Pro A4W4 tune already do; V4-Pro A8W4 (all fused knobs off,
route-major payload: a 15.29 GiB/GPU symmetric heap) takes the V4-Pro
A4W4 large-input tune at 32768 only, renamed _tune_v4_pro_large
(8.04 GiB/GPU). Its 1024..16384 configs are unchanged. 65536 stays out
of reach: the tagged count words hold 16-bit counts.

The AOT default V4.1-Flash MTPRs gain 32768 (+28 jobs per quant set);
V4-Pro's 32768 jobs build the large-input kernel through LARGE_M_MTPRS.
Tests: the never-staged exhaustive check covers pow2 capacities up to
32768, the 32-bit offset test also bounds the GEMM1 out-scale view and
the GEMM1 output (per-tile resources past 2^31), every 32768 config is
checked to use dedup_rows, and the A4W4 digests stay pinned to the
pre-existing capacities.

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

* MegaMoE gfx950: map global expert IDs to W1/W2 indices without the rank

The GEMM1 tile scheduler and GEMM2 subtracted a compile-time rank * experts
offset from the global expert IDs the dispatch plan writes. A rank's IDs
modulo its expert count are the same indices, so the GEMMs no longer need
the rank: expert_offset becomes experts_per_rank. The aligned-pair Stage2
passes its pair's local experts directly.

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

* MegaMoE gfx950: pass the rank to the staged kernels at launch

The staged Stage1 bundle, prepare, Stage2 and aligned-pair Stage2 kernels
took the rank as a compile-time constant, so the AOT cache built every
kernel once per rank. They now take it as an i32 kernel argument: the
compile functions and their AOT keys drop rank, and the run/preload
helpers pass it at launch. Rank-dependent index math becomes a few scalar
ops; the source < rank prefix sums become select chains over the running
sums. Outputs are unchanged.

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

* FlyDSL intranode combine: take the rank as a kernel argument

make_combine_kernel baked the rank into its P2P slot offsets, its
cross-device barrier word and the invalid-slot peer, so MegaMoE's fused
combine (mega_moe_combine) was compiled once per rank. The kernel now
takes an i32 rank argument, which the op passes on every launch; the
generic dispatch/combine path shares the same kernel.

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

* MegaMoE gfx950: pass the rank to the small-input kernel at launch

The small-input persistent kernel takes the rank as an i32 kernel
argument instead of a compile-time constant, so one AOT entry serves
every rank. The fused combine publishes its flag at a byte offset
(rank * 8) read from the runtime's dispatch table where it is used,
rather than keeping the rank live across the GEMMs.

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

* MegaMoE gfx950: pass the rank to the large-input kernel at launch

The large-input persistent kernel takes the rank as an i32 kernel
argument. large_m_kernel_specs drops ("rank", rank) from the fused Stage2
spec, so the kernel name hash (S2_KEY) and the AOT key no longer depend on
the rank; the skew boost of the payload geometry tests the destination
against the rank at run time, and the plan writes its counts through the
base of its own row in each destination's count matrix.

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

* AOT MegaMoE: build one job per profile instead of one per rank

Every MegaMoE kernel now takes the rank at launch and no AOT key holds
it, so rank 0's replay builds the kernels of every rank. default_jobs
yields one job per (MTPR, experts per rank, quant): the default build
drops from 276 jobs and 8898 AOT entries to 42 jobs and 1333 entries.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
charlieguo1106 added a commit that referenced this pull request Nov 30, 2026
- fused_moe.py takes main's version: main moved the sort helpers to
  aiter/moev2/segments/sort.py, which now allocates the persist-es expert
  table (AITER_MXFP4_G2_ES=1) and passes it to the Opus sort.
- moe_sorting_opus.h: from 2048 tokens main sorts with the chunk kernels
  (#8316), which did not write the expert table. The chunk Place kernel now
  writes it from one more workgroup, after the groups' ones. The counting
  sort is shared with the multi-phase P23 kernel
  (impl::moe_sorting_write_expert_info).
- mxmoe_dispatcher.py: main launches the GEMM2 through the AOT cache
  (#8600), so the launcher has no _cf after a launch. The persist-es grid
  takes its blocks per CU from a compile-only flyc.compile, before the
  first launch.

Sort outputs and expert table (GLM-5.2 routing, 512 to 16384 tokens) match
the previous commit. Persist-es route rows byte-identical to the previous
persist-es; fused_moe outputs with and without AITER_MXFP4_G2_ES
byte-identical (2k, 4k). GLM-5.2 GEMM2, MI355X, one GPU, cold, us, mean of
3 rounds, against the previous commit:

                          2k     4k
  fp4 route rows   prev 101.3  134.6
                   new  100.5  134.3
johannes-graner added a commit that referenced this pull request Nov 30, 2026
The merge of main (#8600 AOT binding) left _build_fp8's out_dtype out of
the bind_aot key, so bf16 and f16 launchers shared one cached kernel and the
f16 call ran the bf16 epilogue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants