Skip to content

[ASM] Add gfx950 Kimi K3 fused MXFP4 prefill producer for 8K+ tokens - #8020

Merged
JohnNikolay84 merged 2 commits into
mainfrom
kimi-k3-asm-prefill
Nov 16, 2026
Merged

JohnNikolay84 merged 2 commits into
mainfrom
kimi-k3-asm-prefill

Conversation

@vstakhov-amd

Copy link
Copy Markdown
Contributor

Summary

This PR adds a fused assembly producer for Kimi K3 MXFP4 MoE prefill on gfx950. The Kimi a4w4 config selects it for the 16384 and 32768 token rows, which serve 8193 to 131071 tokens. With captured Kimi routing, full fused_moe latency is 8–11% lower than with the tuned FlyDSL path. With random routing it is 6–8% lower from 12K tokens up.

The PR changes no Python, C++, FlyDSL or Triton code. It has three changes:

  • one code object: hsa/gfx950/fmoe/situv2/fmoe_bf16_pertokenMXfp4_g1u1_situv2_prefill_1tg_4w_256mx1_128nx1_ps_fp32gate_route.co
  • one manifest row in fmoe_bf16_pertokenMXfp4_g1u1_situv2.csv (flat=3, subGU_m=256, subGU_n=384, one workgroup per CU)
  • two changed rows in kimik3_a4w4_tuned_fmoe.csv (tokens 16384 and 32768). The 8192 row and all smaller rows stay on FlyDSL.

How it works

The producer uses the existing post-reduction ASM mode (flat=3, added in #5988 for Qwen Q256):

  1. Opus sort with 256-row tiles and the existing MXFP4 activation quantization and scale sort.
  2. One persistent assembly producer (256 workgroups) does the following for each routed row:
    • gate/up GEMM
    • SiTUv2 (beta 4, linear beta 25)
    • MXFP4 hidden quantization
    • down GEMM
    • route weighting
  3. The producer writes one BF16 contribution per (token, topk) slot.
  4. The existing FlyDSL reduction sums the contributions in FP32.

The launch uses the standard fmoe_g1u1 launcher and its 448-byte argument layout. The kernel reads no argument slot beyond the ones the launcher fills, and it needs no workspace.

For 8193 to 32768 tokens the producer plans its own work order. Each XCD takes a contiguous range of the sorted tiles, so the tiles of one expert run on one XCD and share its weights in L2. Inside the range, the 32 workgroups of the XCD take 32 neighbouring tiles per round. The tile with the most valid rows goes to the workgroup with the least work so far. All workgroups compute the same plan from the sorted route IDs, so the plan needs no shared state.

Shape: model 3584, intermediate 384, 896 experts, top-k 16, MXFP4 activations and weights, BF16 output.

Performance

MI355X (gfx950, 256 CUs), one GPU leased through gpuq for each run. Both arms call the public fused_moe with a caller-provided output. Each arm is one CUDA graph of 20 calls. The arms are replayed in alternating order, 50 samples per arm, and the table shows medians per call. Latency includes sorting, activation quantization, scale sort, the producer and the reduction. The baseline is main's tuned FlyDSL row. Weights and activations are synthetic. "Captured" rows use Kimi K3 routing captured from vLLM (layers 1 and 2).

Tokens Routing FlyDSL, µs ASM, µs Change Change, second GPU
8193 random 992.0 1003.8 +1.2% +0.9%
10240 random 1146.3 1114.1 −2.8% −2.5%
12288 random 1349.3 1250.8 −7.3% −7.2%
16384 random 1720.6 1703.6 −1.0% −1.4%
16384 captured L1 1728.3 1572.3 −9.0% −8.3%
16384 captured L2 1729.2 1556.7 −10.0% −9.5%
16385 random 1820.8 1676.6 −7.9% −8.1%
20480 random 2018.9 1866.1 −7.6% −7.1%
24576 random 2435.7 2233.9 −8.3% −8.7%
32768 random 3169.8 2916.6 −8.0% −7.6%
32768 captured L1 3142.6 2807.3 −10.7% −10.6%
32768 captured L2 3163.4 2868.6 −9.3% −9.0%
49152 random 4555.2 4220.9 −7.3% −6.2%
65536 random 6004.1 5638.4 −6.1% −5.5%
98304 random 8893.8 8360.3 −6.0% −6.1%

The µs columns are from PCI 0000:85:00.0; the last column is the same test on 0000:f5:00.0. A third run, with this branch merged into main at 3d3d56db3e, agrees with both within 1 percentage point on every row.

At the low end of the 16384 row (8193 tokens, random routing) the producer is 1% slower than FlyDSL. At 8192 tokens and below the config does not change.

Correctness

  • Reference: an independent FP32 reference (MXFP4 activations and hidden, SiTUv2, BF16 route products, FP32 sum) matches the ASM output bit for bit on all sampled tokens. Checked at 8193, 10240, 12288, 16384, 16385, 20480, 24576, 32768, 32769, 49152, 65536 and 98304 tokens; 16384 and 32768 also with captured L1 and L2 routing.
  • FlyDSL: the normalized RMS difference from FlyDSL is 0.02–0.11% up to 16384 tokens and 0.32–0.34% above. Above 16384 tokens FlyDSL has the same difference from the reference.
  • Coverage: the checks ran with the contribution buffer filled with NaN before the launch. A route row that the producer did not write would show in the output.
  • Determinism and graph replay: outputs are deterministic. A CUDA-graph replay with new routes and activations matches eager execution bit for bit.

Environment: Torch 2.13 (ROCm 7.2), FlyDSL 0.5.0, Triton 3.8.

Install a PyISA fused producer for Kimi K3 MoE prefill (model 3584, inter 384,
896 experts, top-k 16, SiTUv2, MXFP4 activations and weights). It uses the
existing post-reduction mode (flat=3): standard fmoe launcher, Opus sort with
256-row tiles, token-major BF16 partials and the FlyDSL reduction.

Select it in the Kimi a4w4 config for the 16384 and 32768 token rows, which
serve 8193 to 131071 tokens. The 8192 row stays on FlyDSL.
@vstakhov-amd
vstakhov-amd requested a review from a team November 16, 2026 09:02
@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 8020 --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.

@github-actions github-actions Bot changed the title Add gfx950 Kimi K3 fused MXFP4 prefill producer for 8K+ tokens [ASM] Add gfx950 Kimi K3 fused MXFP4 prefill producer for 8K+ tokens Nov 16, 2026
@github-actions github-actions Bot added the ASM label Nov 16, 2026
@aiter-bot

aiter-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 59e7f83702f3 · 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 — 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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants