Skip to content

[ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 - #8211

Merged
JohnNikolay84 merged 11 commits into
mainfrom
asm-fmoe-mxfp4fp8-situv2-gfx942
Nov 27, 2026
Merged

JohnNikolay84 merged 11 commits into
mainfrom
asm-fmoe-mxfp4fp8-situv2-gfx942

Conversation

@MiloLurati

@MiloLurati MiloLurati commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a 1-stage ASM MoE kernel for gfx942 (MI300X / MI325X): MXFP8 activations, MXFP4 weights, SiTUv2, bf16 output. With AITER_SITUV2_A8W4=1, Kimi-K3 runs it at M ≥ 1024.

M ≤ 512 is not covered here. #6247 adds the FlyDSL a8w4 kernel for gfx942, which covers M ≤ 512. Its tuned rows for M ≥ 1024 overlap with ours, and the ASM rows are faster there (1.13–1.36×), so they stay.

This PR copies the W1 relayout from #6247 without changes (shuffle_weight_a8w4_gfx942, shuffle_scale_a8w4_gfx942, _mark_a8w4_gfx942). The PR that merges second removes the duplicate.

Changes

  • hsa/gfx942/fmoe/situv2/: two code objects (inter 512 and inter 384) and their manifest.
  • asm_fmoe.cu: fp8 X + fp4x2 W selects the new kernels.
  • aiter/ops/shuffle.py: the W1 relayout from [CK] [FlyDSL] [JIT] gfx942 a8w4 MoE stage1 fp8 kernel #6247. The kernel reads W1 with one 16-byte load per lane instead of four 4-byte loads.
  • fused_moe.py:
    • fused_moe_1stage: quantizes and sorts X to MXFP8 in one call. It refuses W1 without the relayout tag.
    • get_2stage_cfgs: keeps this 1-stage row for preshuffled weights. It drops the row for other activations, bias or stage-2 scatter.
  • kimik3_a8w4_tuned_fmoe.csv: 12 gfx942/304 rows for M = 1024–32768. They are hand-placed (_tag=asm_situv2), like the gfx950 ASM SiTUv2 rows. A retune drops them.
  • op_tests/test_moe_mxfp4fp8_gfx942_asm.py: new test.

Performance

Kimi-K3 (E=896, top-k 16, hidden 3584), median of 5 runs, inter 384 / 512. Baseline: the default a16w4 path.

M MI300X ASM µs vs a16w4 MI325X ASM µs vs a16w4
1024 860 / 1037 1.24 / 1.28× 716 / 895 1.31 / 1.29×
2048 1396 / 1744 1.22 / 1.22× 1142 / 1418 1.31 / 1.30×
4096 2251 / 2817 1.15 / 1.21× 1832 / 2283 1.23 / 1.27×
8192 3917 / 4891 1.25 / 1.23× 3216 / 3978 1.32 / 1.30×
16384 7123 / 8816 1.29 / 1.29× 6068 / 7262 1.32 / 1.32×
32768 13722 / 16960 1.32 / 1.26× 11476 / 13900 1.41 / 1.39×

Testing

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

Documentation

  • No documentation change is needed, with the reason stated below

Adds kernels and tuned rows for an existing opt-in path.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. The default a16w4 path does not change.

PR Self-Review

Reviewed revision

a69e05c

Behavior and intent

With AITER_SITUV2_A8W4=1 on gfx942/304 CUs, Kimi-K3 at M ≥ 1024 runs the new 1-stage ASM kernel. On main the flag has no working gfx942 path, so Kimi-K3 stays on a16w4, which is 1.15–1.41× slower. The default path does not change.

Validation and unverified scope

Tested on MI300X and MI325X with python3 op_tests/test_moe_mxfp4fp8_gfx942_asm.py. MI250X is not tested, because the change is gfx942 only.

PR-specific question

  • Architecture: gfx942 with 304 CUs (the tuned-CSV key).
  • Dtypes: bf16 or fp8 X (MXFP8), MXFP4 W (per_1x32), bf16 out, SiTUv2 with beta 4 / linear_beta 25.
  • Shapes: only the 12 tuned rows (E 896, top-k 16, hidden 3584, inter 384 / 512, M 1024–32768).
  • Guards: get_2stage_cfgs drops the row for other activations, bias or stage-2 scatter, and raises for other betas. fused_moe_1stage raises without the W1 relayout tag or if block_m is not 32. asm_fmoe.cu refuses a model_dim that is not a multiple of 256.
  • Not guarded: without the flag, relaid W1 is read as the a16w4 layout. [CK] [FlyDSL] [JIT] gfx942 a8w4 MoE stage1 fp8 kernel #6247 adds that check.

Changed op tests

  • op_tests/test_moe_mxfp4fp8_gfx942_asm.py (new): dispatch for the 12 rows, accuracy against the torch reference for bf16 and fp8 X, and the W1 layout-tag error. No other test runs this kernel, because test_moe_2stage.py skips tagged rows.

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

@MiloLurati MiloLurati changed the title [MoE] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X [ASM] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X Nov 18, 2026
@MiloLurati MiloLurati self-assigned this Nov 18, 2026
@MiloLurati
MiloLurati force-pushed the asm-fmoe-mxfp4fp8-situv2-gfx942 branch from d98d4d2 to 242b702 Compare November 23, 2026 12:54
@MiloLurati MiloLurati added the ci:mi300x Run MI300X standard and OPUS CI on PRs label Nov 23, 2026
@MiloLurati
MiloLurati marked this pull request as ready for review November 23, 2026 14:09
@MiloLurati
MiloLurati requested a review from a team November 23, 2026 14:09
@github-actions github-actions Bot changed the title [ASM] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X [ASM] [HIP] [CK] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X Nov 23, 2026
@aiter-bot

aiter-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision f19c9fedee28 · 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. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  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 — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

MiloLurati and others added 8 commits November 26, 2026 15:47
Kimi-K3 (E=896, topk=16, SiTUv2, MXFP4 W, AITER_SITUV2_A8W4=1) on gfx942/304 CU:
the new 1-stage asm kernels serve M >= 1024 (32x256 at inter 512, 32x192 at
inter 384). MI300X and MI325X share the tuned rows. M <= 512 has no gfx942
row under the opt-in, as before.

- hsa/gfx942/fmoe/situv2: the two code objects and their manifest
  (model_dim a multiple of 256).
- asm_fmoe.cu: fp8 X + fp4x2 W + bf16 SiTUv2 out selects the new cfg table and
  passes model_dim for its dim_align / dim_min check.
- shuffle.py: shuffle_weight_a8w4_gfx942 / shuffle_scale_a8w4_gfx942, the W1
  relayout the kernel reads (same code as #6247), and the gate_up_interleave
  tag on shuffle_scale that their GUGU check reads.
- fused_moe_1stage: quantise x with fused_dynamic_mxfp8_quant_moe_sort; require
  block_size_M=32 and the a8w4_gfx942_layout W1 / W1-scale tags.
- get_2stage_cfgs: keep this preshuffled-weight 1-stage config instead of
  discarding it; the layout and beta checks still apply. Discard it for
  another activation (act-type fallback), per-expert bias or stage-2 scatter.
- kimik3_a8w4_tuned_fmoe.csv: gfx942 rows for M = 1024..32768 pick the asm
  kernel (hand-placed, _tag=asm_situv2).
- Comments and error texts in fused_moe updated for the asm path.
Rebuild fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x192.co: the down
e8m0 scales are now loaded as aligned dwords instead of 2-byte loads, which
removes a load-issue stall in the down loop. Outputs bit-identical; MI300X
inter 384 2-4% faster at M = 128-2048. The 32x256 object is unchanged.
Rebuild fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x256.co and _32x192.co
with one main-loop copy per path instead of two, which halves the code
size. Outputs bit-identical. MI300X at M >= 1024: 0.6-1.3% faster at
inter 384 and 0.8-2.6% at inter 512.
Rebuild fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x256.co and _32x192.co:
the gate/up e8m0 scale bytes are extracted with one SDWA shift instead of
a bitfield extract and a shift, and the 16-row path skips an unused
activation scale. Outputs bit-identical. MI300X at M >= 1024: 0.2-1.4%
faster.
Rebuild fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x256.co and _32x192.co:
the fp4 weights are decoded one MFMA pair ahead straight into VGPRs, so
the loops no longer stage them in AGPRs. Outputs bit-identical. MI300X:
3-5% faster at M >= 1024, 1-3% faster below.
Rebuild fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x256.co and _32x192.co:
the second half of each pass no longer waits for weight loads it does
not use. Outputs bit-identical. MI300X: inter 384 0.2-1.6% faster,
inter 512 unchanged.
Rebuild fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x256.co and _32x192.co.
MI300X: 0.5-3% faster at M >= 1024, about 2% at inter 384 M <= 4.
Kimi-K3 shapes on gfx942 / 304 CUs, skipped elsewhere. Checks the
dispatch for all 12 tuned rows, the output against the torch reference
for bf16 and pre-quantized fp8 x, and the W1 layout-tag error.
@MiloLurati
MiloLurati force-pushed the asm-fmoe-mxfp4fp8-situv2-gfx942 branch from 242b702 to a2dcfe7 Compare November 26, 2026 15:50
@github-actions github-actions Bot changed the title [ASM] [HIP] [CK] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X [ASM] [HIP] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X Nov 26, 2026
@github-actions github-actions Bot removed the JIT label Nov 26, 2026
@MiloLurati MiloLurati changed the title [ASM] [HIP] gfx942: 1-stage ASM MXFP4 SiTUv2 kernel for M ≥ 1024, enable a8w4 on MI300X [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 Nov 26, 2026
MiloLurati and others added 3 commits November 27, 2026 09:54
W1 relaid by shuffle_*_a8w4_gfx942 has the a16w4 shape and dtype, so
without AITER_SITUV2_A8W4 the a16w4 kernels read it and return wrong
output without an error. Raise a ValueError when tagged W1 reaches a
stage 1 other than the gfx942 asm kernel or a  kernel. The op
test covers this case.
@JohnNikolay84
JohnNikolay84 merged commit 1c96e23 into main Nov 27, 2026
68 checks passed
@JohnNikolay84
JohnNikolay84 deleted the asm-fmoe-mxfp4fp8-situv2-gfx942 branch November 27, 2026 19:44
@qli88 qli88 mentioned this pull request Nov 30, 2026
5 of 10 tasks
vedenev-amd added a commit that referenced this pull request Nov 30, 2026
…rows (#8211) serve those keys again.

The main merge kept both rows for the same 12 keys and the first one, ours, won, so test_moe_mxfp4fp8_gfx942_asm.py failed on MI300X. Measured on MI325X in one process, eager wall clock, A/B/B/A pairs, null control within 0.9%: asm is 20-33% faster on all 12 keys and won every pair. The FlyDSL rows for M = 1..512, where main has no gfx942 row, stay. The untuned CSV drops the same tokens so a re-tune reproduces the tuned CSV, and the op test runs fused_moe only at M served by FlyDSL rows (1..512); the stage-1 kernel checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Dec 1, 2026
…e rows still serve, now that #8211 serves M >= 1024.

The gate docstring, the NotImplementedError and the op test's skip message cited the 0.81-0.89x slowdown at M >= 1024, where the _g942 stage 1 no longer runs. On MI300X a8w4 is also slower than a16w4 at M = 128-512 (0.92-0.99x at inter 384), which is what the texts now give. The "MI325X only" substring the tests match is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Dec 2, 2026
* [FlyDSL] gfx942 a8w4 MoE stage1 fp8 kernel

* Raise on non-gfx942 instead of assert

* Add Triton MXFP8 quant for a8w4 (FNUZ-correct, a8w4 byte order)

* gfx942 a8w4: fused_moe wiring, tuned rows, op test

- moe_kernels: register the _g942 stage-1 names (flydsl_moe1_afp8_wfp4_bf16_*_g942*)
  and route fp8 x fp4 stage 1 on gfx942 to gemm1_a8w4_gfx942 (bf16 sorted
  intermediate, consumed by the unchanged a16w4 stage 2).
- fused_moe: no inter-stage requant for the _g942 stage 1 (a2/a2_scale = None).
- gemm1_a8w4_gfx942: x_layout="moe_sort" reads x / scales as produced by
  fused_dynamic_mxfp8_quant_moe_sort; exponent rule bitwise equal to it.
- kimik3_a8w4_tuned_fmoe.csv: 32 gfx942 (cu 304) rows, inter 384/512,
  M 1..32768 except M=3 (fused_moe pads 3 -> 4); input shapes in
  kimik3_a8w4_gfx942_untuned_fmoe.csv.
- op_tests/test_flydsl_moe_a8w4_gfx942.py: a16w4 vs a8w4 through fused_moe.

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

* op test a8w4 gfx942: scale atol with the MoE output

checkAllclose(rtol=atol=1e-2) reported err ~0.22 for both a16w4 and a8w4:
the MoE output is O(1e3) and the paths and the torch reference round the
bf16 intermediate differently (1-3 bf16 ulps, <= 1.2 % of max|ref| on all
8 shapes). atol = 2e-2 * max|ref| gives err 0 for both paths; cos checks
unchanged.

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

* gfx942 a8w4: quantise x inside stage 1 for M=1,2 (_qi kernels)

At M=1 the separate fused_dynamic_mxfp8_quant_moe_sort launch cost more
than the fp8 stage 1 saved, so a8w4 lost to a16w4 (0.96x). The new
x_layout="bf16" stage-1 variant reads bf16 x and quantises each K tile
to MXFP8 straight into LDS in A8W4_K8_ORDER, bitwise equal to the
separate quant:
- x of tile kt+1 is loaded before compute_tile(kt), quantised after it;
- block amax via maxnum + DPP quad swaps (no NaN-propagating max, no
  LDS swizzle with a full lgkmcnt wait);
- padding rows of the M tile are not quantised (their LDS is zeroed once).

Registry: every _g942 name gets a _qi variant (x_layout="bf16");
fused_moe skips the separate x quant for _qi rows and passes bf16 x.
CSV: gfx942 M=1,2 rows use the _qi stage 1; inter 384 M=1 uses the
a16w4 t16x256x128_atomic stage 2.

MI300X, whole MoE vs a16w4 at M=1: 1.05x (inter 512), 1.11-1.16x
(inter 384), was 0.96x / 1.00x. Non-_qi kernels compile to the same ISA
as before.

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

* gfx942 a8w4: MI325X only; LDS swizzle in _qi kernels; _qi rows for M<=8

- Enable the gfx942 a8w4 stage 1 on MI325X only (PCI device id 0x74A5, read
  from sysfs); elsewhere raise NotImplementedError. On MI300X a8w4 is slower
  than a16w4 at large M and the tuned CSV rows are shared by both cards.
  The op test skips on other gfx942 parts.
- XOR-swizzle the A tile in LDS (as gemm2) only in the _qi kernels, where the
  in-kernel quant hit LDS bank conflicts; other kernels unchanged.
- With that, _qi also wins at M=4, 8: switch those CSV rows to _qi.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* gfx942 a8w4: allow MI325X VF; fix gate comment and error text

- Add 0x74B9 (MI325X VF, SR-IOV guests) to the MI325X allow-list.
- The PciChipId comment: chip_info.py's hardcoded 10019 is wrong on ROCm
  7.2.4 / 7.13 / 7.14 (PciChipId is 10020), hence sysfs.
- Error text: MI300X numbers of this PR (0.81-0.89x at M>=1024).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* gfx942 a8w4: skip _g942 stage 1 in FlyDSL MoE AOT; skip its rows off MI325X in test_moe_2stage

- aot/flydsl/moe.py: the `_g942` stage-1 kernels are built by
  gemm1_a8w4_gfx942 (JIT on first use); the AOT stage-1 compile would build
  the gfx950 mixed-MoE kernel for them and fail (wheel build: 64 failed).
- test_moe_2stage.py: tuned-CSV rows are selected by cu_num only, so on MI300X
  (cu 304) the gfx942 a8w4 rows were picked up and the MI325X-only stage 1
  raises; skip them where a8w4_gfx942_supported() is False
  (test_flydsl_moe_a8w4_gfx942.py covers them on MI325X).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] a8w4 gfx942: drop unused x layouts, @flyc.jit runtime if, fix tests

- Remove x_layout="a8w4", x_scale="row" and the Triton MXFP8 quantiser from
  gemm1_a8w4_gfx942 (no production caller or test reached them). The gfx942 ISA
  is bitwise identical on 5 variants (moe_sort and _qi, k_wave 1/2/4).
- _if_then: a local @flyc.jit dispatch instead of a raw scf.IfOp.
- test_moe_2stage: always skip _g942 rows; the CSV sweep prepares neither the
  a8w4 relayout nor the separated gate/up layout they need, so they aborted
  the run on MI325X. test_flydsl_moe_a8w4_gfx942.py covers them.
- test_flydsl_moe_a8w4_gfx942: set AITER_SITUV2_A8W4 to 1 or 0 explicitly and
  restore the caller's value; add M = 1024 and 4096.

The merge with main (previous commit) resolves the fused_moe_2stages conflict with
#6165 and rejects prequantized_a1 together with the gfx942 a8w4 stage 1.

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

* fixes for item1 and item 2

* item 3

* item 4

* [FlyDSL] a8w4 gfx942: prebuild the _g942 stage-1 kernels in the AOT replay

main's AOT now replays fused_moe for every tuned row, with caller inputs built per quant
family. For fp8 x fp4 it built the gfx950 gate/up-interleaved a16w4 weights, so all 360
replays of the gfx942 rows hit the W1-layout check and failed. A _g942 row now gets
separated gate/up W1 relaid and tagged by shuffle_{weight,scale}_a8w4_gfx942, and
a8w4_gfx942_supported() passes in an AOT replay, which has no device to check and
compiles for the arch GPU_ARCHS names. The replay of kimik3_a8w4_tuned_fmoe.csv for
gfx942 is now 360 ok / 0 failed, so these kernels are prebuilt instead of JIT-compiled
on first use (review item 7).

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

* [FlyDSL] a8w4 gfx942: name things in comments, not PR numbers

Review item 11: comments referred to "the a16w4 port", "the a8w4 port" and
"the #6144 table", which only make sense to someone who followed the
development history. They now name the function or constant they mean
(compile_gemm1_a16w4_port, compile_gemm1_a8w4_gfx942,
_FP4_E2M1_FP8_LUT_LO / _HI). Comments only, no code change.

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

* [FlyDSL] a8w4 gfx942: tune the _g942 stage-1 kernels with the MoE tuner

Review item 5: the tuner rejected per_1x32 on anything but gfx950, so the
shipped gfx942 a8w4 rows could not be regenerated with it. On gfx942 it now
tunes the _g942 stage-1 kernels together with the a16w4 stage 2. The _qi
kernels get the bf16 x and the others the output of the HIP MXFP8 quant; the
separate x-quant launch time is added to the moe_sort kernels and the _qi
rows are marked xbf16, as is already done for per_1x128. The gfx950
inter-stage fp8 cast is not added, because the a16w4 stage 2 reads the bf16
intermediate. Timing and selection are unchanged. On MI325X it picks a _qi
stage 1 at every M <= 8, for both inter dims.

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

* [FlyDSL] a8w4 gfx942: key the kernel cache on a source hash, not a hand-bumped rev

The hand-bumped `rev` tag in the kernel name did not invalidate anything in FlyDSL 0.3.4.1:
the kernel name is not part of FlyDSL's cache key, and the key follows the functions the
kernel body calls but not one reached two calls deep. With the decoder in _fp4x8_to_fp8x8
(called from _gemm1_body_a8w4) changed to give wrong numbers, the cached binary was still
served and the test passed; with an empty cache the same edit fails it (cos diff 0.024).

As pa_decode does in implementation_cache_tag, the factory now hashes the sources the
device code comes from once per process, and the kernel and launcher bodies read the hash,
which puts it into the key. The same helper edit now rebuilds the kernel and fails the test,
an unchanged file still hits the cache, and no tag has to be bumped by hand (review item 9).

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

* [FlyDSL] a8w4 gfx942: cache the stage-1 compile factory again

The source-hash change (63c794a) put _source_tag between the @functools.cache line and
compile_gemm1_a8w4_gfx942, so the hash function got the decorator twice and the factory none.
Every stage-1 call then built a new launcher, which FlyDSL loads from its disk cache and
unloads again when the launcher is dropped. On MI325X this made an eager fused_moe call on the
a8w4 path take 37.6 ms instead of 0.33 ms (M = 1, inter 512), and CUDA-graph capture of it
failed with hipErrorStreamCaptureUnsupported on hipModuleUnload, so the path could not run
under the graphs vLLM uses for decode. The a16w4 path was unaffected.

The factory is cached again (one compiled launcher per config) and _source_tag keeps a single
decorator. The stage-1 kernel test, which runs on every gfx942, now also captures the launch in
a CUDA graph and checks that the replay gives the same output: it fails on 63c794a for both
kernels and passes with this change. The full op test passes on MI325X (exit 0). This was not
pushed when found, so CI has not run it.

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

* [FlyDSL] moe_2stage_a16wmix: share the stage-1 XCD tile map and grid size

The a16w4 stage 1 (gemm1.py) and the gfx942 a8w4 stage 1 each carried their own copy of the
bijective XCD round-robin + M-group swizzle and of the flattened grid size (review item 10).
Both now come from utils.py (xcd_tile_map, gemm1_grid, NUM_XCD); gemm1_a16w4_grid stays as the
public name the package exports. The divisions of the valid-tile bound still happen where the
caller builds the map, as they did inline, so the generated code is unchanged.

Checked by dumping the final ISA of every production config through the AOT replay of the
tuned CSVs that use these kernels (kimik2_i4, kimik3_a16w4, kimik3_a8w4, kimik3_i4,
minimax_m3_a16w4), before and after, with the source-hash suffix of the _g942 kernel names
stripped and nothing else ignored: identical for all 46 a16w4 and 17 _g942 stage-1 kernels on
gfx942 and all 82 a16w4 stage-1 kernels on gfx950 (21 and 31 of the a16w4 ones use the XCD
swizzle); the stage-2 and reduction kernels compiled alongside are identical too. No registered _g942
name uses the XCD swizzle, so that branch of the a8w4 kernel is covered only through the
shared helper. The a8w4 op test passes on MI325X and the AOT replay of
kimik3_a8w4_tuned_fmoe.csv builds 360 gfx942 and 732 gfx950 jobs without failures.

The k_wave reduction and the epilogue stay separate: gemm1.py keeps its accumulators in
memrefs (fx.memref_load_vec / acc.store) while the a8w4 kernel keeps them as SSA values, so
sharing them would mean rewriting one of the kernels rather than moving code.

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

* [FlyDSL] a8w4 gfx942: use the stable FlyDSL APIs where the ISA stays the same

Review item 8 asked the gfx942 a8w4 stage 1 to move off FlyDSL calls outside the stable API.
Each swap was applied on its own and the final ISA of the 17 _g942 stage-1 kernels of
kimik3_a8w4_tuned_fmoe.csv's gfx942 rows (AOT replay, FLYDSL_DUMP_IR) compared with the
previous commit, source-hash suffix stripped and nothing else ignored:

- .shrui(n) -> >> n (both results are masked to bits the arithmetic shift leaves alone):
  17/17 identical.
- gpu.thread_id / gpu.block_id -> fx.thread_idx.x / fx.block_idx.x: 17/17 identical.
- _raw(x) -> x.ir_value() at all 25 sites (the buffer resource is already an ir.Value, so its
  wrapper is dropped; tensor_shim._to_raw is no longer imported): 17/17 identical.
- rocdl.mfma_f32_16x16x32_fp8_fp8 -> fx.make_mma_atom(fx.rocdl.MFMA(16, 16, 32,
  fx.Float8E4M3FNUZ)) + fx.gemm on register fragments: 17/17 identical.

Not taken: the output store through fx.rocdl.make_buffer_tensor + BufferCopy16b changes one
instruction in every kernel. BufferCopy takes a bf16 element index, so a masked row can no
longer get buffer_store's byte offset 0x7FFFFFFF (v_bfrev_b32 -2); it gets 0x7FFFFFFE
(v_mov_b32 with a literal). The store itself and its addressing are unchanged, but the ISA is
not identical, so buffer_ops.create_buffer_resource_from_addr / buffer_store stay.

perm_b32, cvt_pk_fp8_f32 and readfirstlane have no stable FlyDSL wrapper (they are not in
rocdl.__all__ in FlyDSL 0.3.4.1); a one-line comment at their uses says so. With all of this
the final ISA of the 17 kernels is identical to the previous commit's, the a8w4 op test passes
on MI325X, and the AOT replay of kimik3_a8w4_tuned_fmoe.csv builds 360 gfx942 and 732 gfx950
jobs without failures.

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

* Read the gfx942 a8w4 PCI chip id from sysfs via a shared chip_info helper

The a8w4 gfx942 stage-1 dispatch is gated on the PCI device id so it only
enables on MI325X, and reading that id through hipDeviceGetAttribute(PciChipId)
is unreliable because the attribute ordinal is not stable across ROCm releases
(10019 before HIP 7.1, 10020 after, and 10019 returns a bogus 0x200 on ROCm
7.2.4 / 7.13 / 7.14). The sysfs `device` file holds the id directly, so move
that sysfs read into chip_info as a reusable get_pci_chip_id_sysfs() and have
a8w4_gfx942_supported() use it instead of its own inlined copy. The existing
hipDeviceGetAttribute path (_get_pci_chip_id, attribute 10019/10020) is left
untouched so the MI308 device-name gate keeps its current behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* gfx942 a8w4: adopt tuner-picked rows where the whole-MoE A/B wins

Update the tuned rows for the _g942 stage-1 / a16w4 stage-2 kernels to the
in-PR tuner's picks for the 12 shapes where a whole-MoE CUDA-graph A/B
confirms a speedup over the previously shipped rows: M=1,2,8 at inter 512
and 384, and inter-384 M=256,1024,2048,4096,8192,16384 (2.4-8.0% faster).
M=4 and inter-384 M=512 are kept on the existing graph-measured rows, where
the tuner regresses (M=512 +4.8%, M=4 +0.6-0.8%). inter-512 large-M, inter-384
M=16..128 and M=32768 were not re-tuned and keep their current rows. The
swapped rows are numerically equivalent to the ones they replace (cos ~1e-6,
no NaN); only the kernel/tile choice changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* [FlyDSL] a8w4 gfx942: decide the stage-1 arch at runtime with get_gfx_runtime

The gfx942 a8w4 decision was made in four places from two helpers: the stage-1 launcher
(twice) and the compile factory used FlyDSL's get_rocm_arch(), which follows
FLYDSL_GPU_ARCH / ARCH, and the tuner used get_gfx(), which follows GPU_ARCHS. The launcher
and the tuner now use chip_info.get_gfx_runtime(), which reads the live device and answers
the single GPU_ARCHS target in an AOT replay. The launcher's second "gfx942 only" check is
dropped; compile_gemm1_a8w4_gfx942 keeps the one hard check against its compile target
(review item 15).

The op test passes on MI325X (non-_g942 fp8 x fp4 name still refused, 24/24 fused_moe
checks) and the AOT replay of the gfx942 kimik3_a8w4 rows builds 360/360 jobs.

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

* [FlyDSL] a8w4 gfx942: read the MI325X chip id through chip_info._get_pci_chip_id

main (#5182) fixed _get_pci_chip_id to pick the PciChipId attribute from the HIP
runtime version, which was the reason this PR read the PCI id from sysfs instead. That
left chip_info with two chip-id readers that failed differently (the sysfs one raised
OSError and the gate then guessed from the device name). The sysfs reader and the name
fallback are removed; the MI325X ids sit next to MI308_CHIP_IDS, and the a8w4 gate reads
the id through _get_pci_chip_id and fails closed if it cannot (review item 16).

On MI325X with ROCm 7.2 _get_pci_chip_id returns 0x74a5, as the sysfs read did. With the
reader stubbed, the gate is on for 0x74A5 / 0x74B9 and off for 0x74A1 and for a failed
read. The op test passes (24/24 fused_moe checks) and the AOT replay of the gfx942
kimik3_a8w4 rows builds 360/360 jobs.

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

* [FlyDSL] a8w4 gfx942: one predicate for the _g942 stage-1 kernels

Whether a stage-1 kernel is the gfx942 a8w4 one was written out in six places: the
stage-1 dispatch, fused_moe, the AOT replay and the tuner compared in_dtype with the
"a8w4_gfx942" string, the op test did too, and test_moe_2stage.py looked for "_g942" in
the name (review item 17). moe_kernels.py now exports is_a8w4_gfx942_kernel(name or
params) and A8W4_GFX942_IN_DTYPE, and all of them use it, so a rename or a second gfx942
a8w4 family changes one line. The tuner's _is_a8w4_g942 stays: it decides per shape,
from arch and dtypes, which candidate family to sweep, before any kernel name exists.

Checked: true for all 128 _g942 names (by name and by params), false for the other 5965
registered kernels and for None / {} / an unknown name; the op test passes and the AOT
replay of the gfx942 kimik3_a8w4 rows builds 360/360 jobs.

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

* [FlyDSL] a8w4 gfx942: check the stage-1 inputs in one helper, not in fused_moe_2stages

The gfx942 a8w4 input checks (W1 / W1-scale layout tag in both directions, no
caller-prequantized A for a _g942 stage 1, bf16 / fp16 x only for the _qi kernels) were
spread over about 40 lines of fused_moe_2stages, next to the shared a16w4 logic (review
item 18). They are now check_a8w4_gfx942_inputs in moe_kernels.py, beside
is_a8w4_gfx942_kernel, called once before the stage-1 input is prepared. The checks and
their messages are unchanged.

Checked: each of the seven input combinations (good _qi and moe_sort inputs, untagged W1,
tagged W1 with an a16w4 stage 1, untagged a16w4, prequantized A, fp8 x on a _qi row)
passes or raises as before; the op test passes (24/24 fused_moe checks, including the
fp8-x and mixed-layout cases) and the AOT replay of the gfx942 kimik3_a8w4 rows builds
360/360 jobs.

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

* [FlyDSL] a8w4 gfx942: bound the x-scale buffer descriptor

Every buffer descriptor in the gfx942 a8w4 stage 1 was bounded except the one for the
MXFP8 x scales, which set num_records to 0xFFFFFFFF, so hardware bounds checks never
applied to those reads (review item 20). The kernel reads scale rows below cumsum[0] only,
and fused_dynamic_mxfp8_quant_moe_sort allocates pad32(sorted rows) x _ms_npad bytes, so
the descriptor is now bounded at pad32(cumsum[0]) x _ms_npad, the same source the output
descriptor uses. An indexing slip would now read zeros instead of neighbouring memory.

Checked on MI325X: the bound never exceeds the quantiser's allocation (M 1 to 32768,
BM 16 / 32); the 12 CSV _g942 kernels give bitwise-identical output (36/36); the `_qi`
kernels compile to identical ISA (they do not read the scale buffer), the moe_sort ones
gain 12 to 15 scalar setup instructions with the same VGPR count; whole fused_moe a8w4
time is unchanged (new/old 0.999 to 1.001, 6 interleaved runs, M 16 / 128 / 1024 / 2048,
inter 384 / 512). The op test passes and the AOT replay builds 360/360 jobs.

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

* [FlyDSL] a8w4 gfx942: drop the source-hash cache tag, FlyDSL 0.5.0 tracks the helpers

The source-hash tag (_source_tag, read as `_ = _a8w4_src_tag` in the kernel and launcher
bodies and appended to the kernel name) worked around FlyDSL 0.3.4.1's cache key, which
did not follow a helper reached two calls deep. main now pins FlyDSL 0.5.0 (#7600), which
dropped the same pattern from pa_decode (review item 21).

Re-ran the repro at 0.5.0 without the tag: with _fp4x8_to_fp8x8 (called from
_gemm1_body_a8w4) broken, the same cache got a new entry and the kernel-only test failed
as it should (cos diff 0.024, as with an empty cache), and an unchanged file still hit the
cache. So the tag, its reads and its name suffix are removed. The factory keeps its
functools.cache. Final ISA of all 17 _g942 kernels is identical to the previous commit
apart from the name, outputs of the 12 CSV kernels are bitwise identical, the op test
(including its CUDA-graph replay check) passes, and the AOT replay builds 360/360 jobs.

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

* [FlyDSL] a8w4 gfx942: keep the kernel module to the kernel, move the oracle and relayouts out

The torch MXFP8 oracle, the W1 relayouts and their layout tag are host-side tensor
helpers, so they now live next to the other shuffles in aiter/ops/shuffle.py and the
shared exponent rule in fp4_utils, where the tuner imports it as well. The op test
builds its own oracle from that rule, and the kernel entry point is exported from the
moe_2stage_a16wmix package like the a16w4 ones. Outputs of the 12 tuned kernels are
bitwise unchanged and AOT replay compiles all 360 rows.

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

* [FlyDSL] a8w4 gfx942: make the stage-1 op test fail on one wrong block scale

A cos-diff bound of 1e-3 passed outputs with one zeroed column, so test_stage1_kernel
now requires every element within checkAllclose's default tolerances and proves it on
a W1 whose up scale is doubled for one 32-wide block of one column. W1 is scaled by
1/8, which keeps the FP4 codes and keeps every output below SiTUv2's saturation at
100, where about 1 % of the outputs sat before and hid such errors.

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

* [FlyDSL] a8w4 gfx942: say why the output descriptor and store stay on buffer_ops

The reasons were only in the PR thread, so the next FlyDSL pin bump would have to
rediscover why these two calls were not moved to make_buffer_tensor / BufferCopy16b.

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

* FlyDSL a8w4 gfx942: raise on GUGU input in shuffle_weight/scale_a8w4_gfx942

Both relayout functions require GGUU (separated gate/up) layout as input.
A GUGU-preshuffled (gate_up_interleave=True) W1 passes the relayout silently
and receives the a8w4_gfx942_layout tag, but half its bytes are misplaced
relative to the GGUU order the stage-1 kernel reads, giving wrong output
without an error. Add an explicit ValueError check on the gate_up_interleave
attribute so the mislayout is caught at relayout time.

* FlyDSL a8w4 gfx942: assert err == 0 in test_moe_a8w4_gfx942, add self-check

The checkAllclose result was recorded but never asserted, so a localized
output error (e.g. one wrong token) could pass silently. Add assert err == 0
after each checkAllclose call in the candidates loop.

Add a self-check that zeroes one output row and confirms the tolerance catches
it (err > 0), so the check cannot go silent if the tolerance is too loose.
Remove the weaker assert on a8w4 cos < 1e-3 (superseded by err == 0).

* FlyDSL a8w4 gfx942: extend test_stage1_kernel to cover all CSV tile families

The M=1 kernel name in main() was stale since 5d7e4e1: the CSV M=1 rows
now use t16x32x256_g942_kw2_qi, not t16x32x128_g942_kw4_qi. Fix it.

test_stage1_kernel hardcoded tile_m=16 and asserted it, so BM=32 kernels
(t32x*) could not be tested. Remove the tile_m==16 assertion; derive tile_m
from the kernel params instead.

Add five more calls in main() to cover each distinct tile family in
kimik3_a8w4_tuned_fmoe.csv that was not reached on MI300X CI runners:
TILE_K=256 (t16x128x256_g942), bnt0 (t16x128x128_g942_bnt0_kw2),
BM=32 (t32x128x128_g942), and BM=32+TILE_K=256 (t32x128x256_g942_bnt0).

* FlyDSL a8w4 gfx942: apply black formatting to test file

* FlyDSL a8w4 gfx942: fix pre-existing ruff errors in gemm1.py and gemm.py

gemm1.py imported gemm1_grid from .utils but never used it (F401); remove it.
gemm1.py called _udiv and _umod from .utils but did not import them (F821);
add them to the import list.
aiter/aot/flydsl/gemm.py has a shebang but was not executable (EXE001);
set the executable bit.

* FlyDSL a8w4 gfx942: fix pre-existing ruff errors in gemm1.py

gemm1.py imported gemm1_grid from .utils but never used it (F401); remove it.
gemm1.py called _udiv and _umod from .utils but did not import them (F821);
add them to the import list.

* FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)

The file has a #!/usr/bin/env python3 shebang but was not marked executable
(mode 100644). Set the executable bit (100755) to match. Pre-existing lint
error caught by ruff 0.16.0.

* Revert "FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)"

This reverts commit f9f5db0.

* Revert "Revert "FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)""

This reverts commit 2b777e7.

* FlyDSL a8w4 gfx942: fix test_plain_fp8_swiglu_limit_dispatch for #8178

#8178 changed get_2stage_cfgs so that per-token FP8 + clamped SiLU on
gfx942 uses the FlyDSL full_impl path (stage1=None) instead of CK stage1.
The test asserted stage1.func is ck_moe_stage1 without guarding against
the None case, crashing on MI300X CI.

Accept both outcomes: if stage1 is None assert full_impl is set
(FlyDSL took over), otherwise keep the existing CK assertions.

* [FlyDSL] a8w4 gfx942: keep _qi stage 1 rows at M <= 8 so pre-quantised x is accepted above that

The inter-384 M = 256 row used a _qi stage 1, which quantises x itself and refuses MXFP8
x + a1_scale, so a caller passing pre-quantised x at 129-256 tokens got a ValueError
although the contract promises the passthrough from M = 16 on. The row goes back to the
moe_sort kernel it had before the tuner swap. The op test now checks that the CSV uses
_qi only up to M = 8, and accepts a refused pre-quantised x only there.

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

* [FlyDSL] a8w4 gfx942: check every _qi stage 1 of the CSV on full M tiles

The only _qi case in CI was M = 1 with 8 experts, so each M tile held one real row,
where the A swizzle and the per-row x-scale slots are the identity; a mismatch between
the in-kernel quant's write and the read would have passed. test_stage1_kernel now
also runs all five _qi kernels of the CSV with 2 experts / top 2 and 16 tokens, so
every tile row is real. A read without the swizzle, or x-scales written to the
neighbouring row, fails these cases and still passes the M = 1 one.

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

* [FlyDSL] a8w4 gfx942: tag the a16w4 scale preshuffle with its gate/up order

shuffle_scale_a8w4_gfx942 refuses a gate/up-interleaved (GUGU) scale by its
gate_up_interleave tag, but only shuffle_weight set that tag, so a GGUU W1 paired with a
GUGU W1 scale passed both relayouts and gave wrong output without an error.
shuffle_scale now tags its interleave-branch output the way shuffle_weight does, and the
op test checks that both relayouts refuse a GUGU input.

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

* [FlyDSL] a8w4 gfx942: check all twelve CSV stage-1 kernels on every gfx942

Two kernels of the CSV, t16x128x128_g942_kw2 (inter-384 M = 256 and 512) and
t32x128x128_g942_bnt0 (eight large-M rows), were checked only through fused_moe on
MI325X, which CI does not have. test_stage1_kernel now runs them too, and main() asserts
that every stage-1 kernel in the CSV was run, so a row with a new kernel cannot slip
past the MI300X runners.

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

* Revert "FlyDSL a8w4 gfx942: fix test_plain_fp8_swiglu_limit_dispatch for #8178"

This reverts commit 7cb2fdc. test_plain_fp8_swiglu_limit_dispatch is not
part of this PR; it fails on main since #8178 and #8350 fixes it there.
Keeping a partial fix here made the PR fail at a different assertion than
main, which hid that the failure is the same one.

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

* Retrigger CI without the ci:mi300x label.

MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45177648946.

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

* Retrigger CI without the ci:mi300x label.

MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45348931160, attempt 2.

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

* [FlyDSL] a8w4 gfx942: tune the _g942 stage 1 with TUNE_ONLY unset, and fail loudly when the selection leaves it out

With TUNE_ONLY unset the tuner asked the flydslv2 generator first; it has no arch check, so it returned tasks for a gfx942 a8w4 row, TUNE_ONLY became "flydslv2", and the a8w4 branch, which only queues the FlyDSL `_g942` stage 1, then queued nothing and reported no error. The default now skips flydslv2 for these rows, and a TUNE_ONLY or OPUS_ONLY that excludes flydsl raises instead of tuning nothing. A CPU test drives tune() with the generators mocked: 0 queued stage-1 tasks before, all `_g942` ones after.

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

* [FlyDSL] a8w4 gfx942: offer the _qi stage 1 to the tuner only up to 8 tokens

A `_qi` stage 1 quantises x itself and refuses pre-quantised x, so the CSV keeps it to M <= 8, but the tuner offered all 52 `_qi` names at every M and a re-tune could again pick one for M = 256, breaking test_csv_qi_rows and the pre-quantised x path there. The limit now lives in moe_kernels.A8W4_GFX942_QI_MAX_TOKEN, used by the tuner and the op test. A CPU test checks that the tuner offers `_qi` at 8 tokens and none at 9.

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

* [FlyDSL] a8w4 gfx942: refuse a stage-1 tile over the 64 KiB LDS at compile time and keep it out of the tuner

At K = 7168 a BM 32, TILE_K 256, k_wave 4 `_qi` tile needs 73728 B of LDS (double-buffered A plus its f32 scales). Nothing checked it: the compiler only printed "local memory (73728) exceeds limit (65536)", FlyDSL went on, and the launch failed with hipErrorIllegalState, which says nothing about LDS and can leave the GPU context unusable. a8w4_gfx942_stage1_lds_bytes now sizes the tile, compile_gemm1_a8w4_gfx942 raises a ValueError over the limit, and the tuner skips those tiles. K = 3584 (Kimi-K3) has no such tile.

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

* [FlyDSL] a8w4 gfx942: refuse a moe_sort stage 1 with TILE_K other than 128 or 256

load_x_scale_moe_sort builds one E8M0 base from y0 // 8 for the whole tile, which holds only while every block of the tile is in the same 8-block group, i.e. TILE_K 128 or 256. The check only asked for a multiple of 128, so a direct call with 384 or 512 built a kernel that read the wrong scale for half the blocks, up to a 256x error, without any message. The registered names use 128 and 256 only; compile now raises for the others, and a CPU test covers it.

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

* [FlyDSL] a8w4 gfx942: stop a tuner run off MI325X with one up-front error

The tuner recognised a gfx942 a8w4 row by the arch alone, while the runtime path also requires a8w4_gfx942_supported(), so on an MI300X every `_g942` candidate raised NotImplementedError on its own and nothing said the shape is MI325X-only. The a8w4 branch now checks the gate once and raises with that message before queuing anything.

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

* [FlyDSL] a8w4 gfx942: apply swiglu_limit to the silu stage 1, as the a16w4 one does

With act="silu" the epilogue called gate_up_act with no SiTU parameters, so a finite swiglu_limit was ignored, while the a16w4 stage 1 clamps gate and up with clamp_gate_up before the unclamped SiLU and runtime_swiglu_limit documents that a positive SiLU limit is applied. The silu path now builds the parameters and clamps the same way (+inf without a limit). test_stage1_kernel takes act and limit and checks silu with limit 1.0 against torch: equal with the change, 84 % of the elements outside the tolerance without it. The shipped rows are SiTUv2 and unchanged.

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

* [FlyDSL] a8w4 gfx942: gate the op test on the running GPU, not on GPU_ARCHS

get_gfx() follows GPU_ARCHS and takes its last entry, so with GPU_ARCHS="gfx942;gfx950" the test decided it was on gfx950 and skipped everything on a real MI325X, still exiting 0. It now uses get_gfx_runtime(), as the dispatcher does, for the gate and for the gfx column: with that GPU_ARCHS on MI325X the old test ran 0 stage-1 checks, the new one all 14.

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

* [FlyDSL] a8w4 gfx942: make the stage-1 shape checks raise, so python -O keeps them

The eleven shape checks in compile_gemm1_a8w4_gfx942 were asserts, which python -O removes; with D_INTER not a multiple of TILE_N, for example, the kernel would then floor NUM_N_BLOCKS and leave the last columns of the intermediate unwritten, and the `_g942` branch returns before any upstream tile check. They now raise ValueError through one helper, with the same conditions, messages and order. A test compiles a bad shape in a python -O subprocess: it raises now and passed silently before.

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

* Drop the gfx942 a8w4 FlyDSL rows for M >= 1024 so main's asm 1-stage rows (#8211) serve those keys again.

The main merge kept both rows for the same 12 keys and the first one, ours, won, so test_moe_mxfp4fp8_gfx942_asm.py failed on MI300X. Measured on MI325X in one process, eager wall clock, A/B/B/A pairs, null control within 0.9%: asm is 20-33% faster on all 12 keys and won every pair. The FlyDSL rows for M = 1..512, where main has no gfx942 row, stay. The untuned CSV drops the same tokens so a re-tune reproduces the tuned CSV, and the op test runs fused_moe only at M served by FlyDSL rows (1..512); the stage-1 kernel checks are unchanged.

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

* Justify the MI325X-only a8w4 gate with the MI300X numbers at the M the rows still serve, now that #8211 serves M >= 1024.

The gate docstring, the NotImplementedError and the op test's skip message cited the 0.81-0.89x slowdown at M >= 1024, where the _g942 stage 1 no longer runs. On MI300X a8w4 is also slower than a16w4 at M = 128-512 (0.92-0.99x at inter 384), which is what the texts now give. The "MI325X only" substring the tests match is unchanged.

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

* Drop test_a8w4_gfx942_tune_sources.py: no CI job runs it, and review suggested removing tests that only serve local validation.

It held the unit tests of the review-round-3 tuner fixes; they passed at bd616e3 and d9ab86b (10 tests), and the result is posted in the review thread. The op test test_flydsl_moe_a8w4_gfx942.py stays, as the only numeric check of the _g942 stage-1 kernels on the MI300X CI runners.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Vedenev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASM ci:mi300x Run MI300X standard and OPUS CI on PRs HIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants