Skip to content

[HIP] [Perf] MoE routing top-k: readlane/DPP instead of ds_bpermute - #7338

Merged
TennyWang1223 merged 3 commits into
ROCm:mainfrom
phambinhfin:phambinh/topk-reg-lane-bcast
Nov 30, 2026
Merged

TennyWang1223 merged 3 commits into
ROCm:mainfrom
phambinhfin:phambinh/topk-reg-lane-bcast

Conversation

@phambinhfin

@phambinhfin phambinhfin commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replaces ds_bpermute round trips with readlane, DPP, ds_swizzle and ballot/mbcnt in the two decode-size MoE routing kernels on wave64: the register top-k behind biased_grouped_topk / single-group grouped_topk (GLM-5.2) and topk_gating softmax (Qwen3-MoE). Outputs are bit-identical to main. At M = 1–128 on MI325X, GLM-5.2 routing is 1.11–1.19× faster and Qwen3 routing 1.22–1.24× faster.

Motivation

At decode sizes each row is one wave, so the cost is the launch plus the wave's dependent cross-lane chain. On gfx942 every __shfl / __shfl_xor is a ds_bpermute, the slowest step in that chain.

Changes

Data movement only. Dispatch, launch configuration, API, tie rules and arithmetic order are unchanged.

  • topk_reg_kernel (≤ 8 scores a lane, E ≤ 512): the pivot is broadcast with readlane; candidate slots come from one ballot + mbcnt instead of two warp_cumsum scans; the rank and the renorm sum are unrolled over constant lanes when n_cand ≤ 8 / 16 and topk ≤ 8. Wider instantiations keep the original code.
  • topk_gating_kernel_prefill: when a row is the whole wave, the argmax broadcasts and the softmax max use readlane and the fused DPP max; the softmax sum keeps the __shfl_xor pairing order, exchanging through DPP and ds_swizzle on gfx9.
  • op_tests/test_moeTopkSoftmax.py: new stable_cases for the added boundaries; the legacy reference is padded until it takes the LDS kernel.

Performance (if applicable)

Main f70ac7f90 vs this PR 0d5bd9b4a, both JIT-built in vllm/vllm-openai-rocm:nightly-edad8b03c5285a1c12e7e4f83c1af709b319a01b (PyTorch 2.13, ROCm 10.0) on one idle GPU. CUDA graph of 64 calls, per-call median of 5 alternating rounds; round-to-round spread ≤ 0.011 µs on the rows below.

Hardware Workload/configuration Before After Change
MI325X (gfx942) biased_grouped_topk, GLM-5.2 E=256 top-8 fp32, strided [M,9] out, M=1 2.870 µs 2.417 µs 1.19×
MI325X (gfx942) same, M=8 3.081 µs 2.699 µs 1.14×
MI325X (gfx942) same, M=128 3.137 µs 2.815 µs 1.11×
MI325X (gfx942) topk_gating softmax, Qwen3 E=128 top-8 bf16, renorm, M=1 3.261 µs 2.639 µs 1.24×
MI325X (gfx942) same, M=8 3.450 µs 2.820 µs 1.22×
MI325X (gfx942) same, M=128 3.539 µs 2.907 µs 1.22×
Speedup (main / this PR) on the other shapes that share the changed code
Shape M=1 M=8 M=64 M=1024 M=4096 M=16384
biased E256 k8 fp32 1.18 1.14 1.11 1.13 1.15 1.05
biased E128 k8 bf16 1.18 1.12 1.10 1.12 1.16 1.06
biased E384 k8 bf16 1.12 1.12 1.12 1.13 1.15 1.06
biased E512 k8 fp32 1.10 1.14 1.11 1.12 1.13 1.22
biased E128 k32 fp32 1.07 1.10 1.10 1.06 1.06 1.06
grouped softmax E256 k8 bf16 1.16 1.12 1.12 1.10 1.11 1.03
biased E896 k16 bf16 (unchanged code) 1.00 1.02 1.00 1.00 1.00 1.00
biased E2048 k32 bf16 (unchanged code) 1.00 1.00 1.00 1.00 1.00 1.00
topk_gating softmax E128 k8 bf16 1.23 1.22 1.22 1.01 1.01 1.01
topk_gating softmax E256 k8 bf16 1.20 1.19 1.19 1.03 1.02 1.02
topk_gating softmax E512 k10 bf16 1.12 1.19 1.19 1.11 1.00 1.00
topk_gating sigmoid E128 k8 bf16 1.00 1.00 1.00 1.00 0.99 0.99

Spreads above 0.1 µs: E128 k32 at M ≤ 64 (≤ 0.51), E512 k10 at M=1 (0.44), grouped softmax at M=64 (0.42), E896 at M=8 (0.57), and E256 / E384 / E2048 at M=16384 (≤ 0.32). The sigmoid row has no source change; its opt_n kernel compiles one instruction longer because subwarpArgmax's two __shfl no longer share an address.

Bandwidth and roofline: latency-bound at M ≤ 128. A GLM-5.2 row reads 1 KB and writes 64 B, so HBM traffic is negligible.

Per-wave rocprofv3 counters at M=1, main → this PR:

  • GLM: VALU 315 → 264, SALU 107 → 77, LDS 20 → 15, branch 30 → 21, wave cycles 1778 → 1613.
  • Qwen: VALU 350 → 325, SALU 77 → 116, LDS 36 → 2, wave cycles 1782 → 1642.

Resources: topk_reg_kernel instantiations with ≤ 8 scores a lane use ≤ 52 VGPRs and 0 scratch (GLM: 41 VGPRs, 46 SGPRs). topk_gating_kernel_prefill<bf16,128,TPW=1>: 19 VGPRs, 0 scratch.

Testing

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

Documentation

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

No API, dispatch or output change.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

0d5bd9b4a

Behavior and intent

Same outputs, bit for bit, from fewer and cheaper cross-lane operations in topk_reg_kernel and topk_gating_kernel_prefill. The existing code is correct, but at decode sizes most of the wave's time goes to ds_bpermute round trips in the scans, rank, renorm and butterflies.

Validation and unverified scope

  • Bitwise A/B, main f70ac7f90 vs 0d5bd9b4a: 960 configurations through biased_grouped_topk, grouped_topk and topk_gating (E = 64–896, top-k 4–32, M = 1–16384, random, ties, NaN and ±inf, renorm on and off), weights compared as bit patterns: 0 differences.
  • On 0d5bd9b4a, rebuilt from scratch: python3 op_tests/test_moeTopkSoftmax.py passed with 0 failed! lines and all 32 stable_cases rows at err 0. op_tests/test_moe_topk_gating.py, op_tests/test_topk_softmax.py and pytest tests/test_moe_dispatch_snapshot.py passed.
  • The unseeded 256-expert, 8-group test_grouped_topk cases print intermittent failed! lines on main too; they run the LDS kernel, which this PR does not change.
  • Not run: gfx950 and gfx1250 on hardware (gfx950 comes from CI), and no end-to-end result is claimed.

PR-specific question

  • The register top-k is reached only when LAUNCHER_TOPK_REG passes: wave64 (reg_lanes == 64), no group filter, num_experts % 4 == 0, 4 <= topk <= 32. The new slots, rank tiers and renorm unroll are compile-time gated to EXPERTS_PER_LANE <= 8; the 14/16/32-a-lane instantiations keep the original code.
  • The fast-path test (pivot > -inf, topk <= n_cand <= 64) sees the same n_cand. Rank tiers check n_cand <= 8 / 16 and the renorm unroll checks topk <= 8, each falling back to the original loop.
  • topk_gating: the readlane paths compile only when a row is the whole wave, and the DPP / ds_swizzle exchanges only under __GFX9__; other targets keep __shfl_xor.
  • Invariant: emit orders by a unique (score, tie rank) key; lanes past n_cand hold key 0 and lanes past topk hold weight +0.0f, so slot order and the unrolled loops cannot change the output.

Changed op tests

op_tests/test_moeTopkSoftmax.py adds stable_cases for boundaries no existing case reached: thirty_two_way_tie (n_cand = 32, back to the warp_rank_desc loop), top-16 with n_cand = 16, E=512 (the EXPERTS_PER_LANE == 8 gate), top-4 (dead lanes in the rank and renorm), E=192 (odd experts per lane) and E=200 (masked last round). The padded legacy reference previously stayed on the register path for E = 128/192/200; it now pads until it takes the LDS kernel, so each case compares two different kernels.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 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 7338 --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.

@aiter-bot

aiter-bot commented Nov 2, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 0d5bd9b4adf8 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Same outputs, bit for bit, from fewer and cheaper cross-lane operations in `topk_reg_kernel` and `topk_gating_kernel_prefill`. The existing code is correct, but at decode sizes most of the wave's time goes to `ds_bpermute` round trips in the scans, rank, renorm and butterflies.

Validation and unverified scope

- Bitwise A/B, main `f70ac7f90` vs `0d5bd9b4a`: 960 configurations through `biased_grouped_topk`, `grouped_topk` and `topk_gating` (E = 64–896, top-k 4–32, M = 1–16384, random, ties, NaN and ±inf, renorm on and off), weights compared as bit patterns: 0 differences.
- On `0d5bd9b4a`, rebuilt from scratch: `python3 op_tests/test_moeTopkSoftmax.py` passed with 0 `failed!` lines and all 32 `stable_cases` rows at `err` 0. `op_tests/test_moe_topk_gating.py`, `op_tests/test_topk_softmax.py` and `pytest tests/test_moe_dispatch_snapshot.py` passed.
- The unseeded 256-expert, 8-group `test_grouped_topk` cases print intermittent `failed!` lines on main too; they run the LDS kernel, which this PR does not change.
- Not run: gfx950 and gfx1250 on hardware (gfx950 comes from CI), and no end-to-end result is claimed.

PR-specific question

- The register top-k is reached only when `LAUNCHER_TOPK_REG` passes: wave64 (`reg_lanes == 64`), no group filter, `num_experts % 4 == 0`, `4 <= topk <= 32`. The new slots, rank tiers and renorm unroll are compile-time gated to `EXPERTS_PER_LANE <= 8`; the 14/16/32-a-lane instantiations keep the original code.
- The fast-path test (`pivot > -inf`, `topk <= n_cand <= 64`) sees the same `n_cand`. Rank tiers check `n_cand <= 8 / 16` and the renorm unroll checks `topk <= 8`, each falling back to the original loop.
- `topk_gating`: the `readlane` paths compile only when a row is the whole wave, and the DPP / `ds_swizzle` exchanges only under `__GFX9__`; other targets keep `__shfl_xor`.
- Invariant: emit orders by a unique (score, tie rank) key; lanes past `n_cand` hold key 0 and lanes past `topk` hold weight `+0.0f`, so slot order and the unrolled loops cannot change the output.

Changed op tests

`op_tests/test_moeTopkSoftmax.py` adds `stable_cases` for boundaries no existing case reached: `thirty_two_way_tie` (`n_cand = 32`, back to the `warp_rank_desc` loop), top-16 with `n_cand = 16`, E=512 (the `EXPERTS_PER_LANE == 8` gate), top-4 (dead lanes in the rank and renorm), E=192 (odd experts per lane) and E=200 (masked last round). The padded legacy reference previously stayed on the register path for E = 128/192/200; it now pads until it takes the LDS kernel, so each case compares two different kernels.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

@phambinhfin phambinhfin changed the title [Perf] MoE routing top-k: readlane/DPP instead of ds_bpermute, bit-identical [Perf] MoE routing top-k: readlane/DPP instead of ds_bpermute Nov 2, 2026
@phambinhfin
phambinhfin force-pushed the phambinh/topk-reg-lane-bcast branch from ce45343 to c582e7f Compare November 5, 2026 14:49

@samremes samremes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark vs Existing Kernels & Review Summary

We verified bit-identity and op_tests (test_moeTopkSoftmax.py, test_moe_topk_gating.py) on MI325X (gfx942, 304 CUs) and MI355X (gfx950, 256 CUs), and benchmarked this PR against both main (c1096fa40a) and the other MoE routing kernels already available in AITER / vLLM (CUDA Graph replay: 64 calls/graph, 8 replays, 25 samples across 5 alternating rounds, median per-call µs).

1. Comparison with Existing Kernels on MI325X (gfx942)

A. Softmax Routing — Qwen3-MoE (E=128, k=8, bf16, renorm=True) & Neighboring Shapes

Shape M Base topk_gating PR #7338 topk_gating PR Speedup grouped_topk (is_softmax=True) topk_softmax (HIP) topk_softmax_asm (existing .co)
E=128 k=8 bf16 1 3.210 2.755 1.17× 2.989 5.949 2.118 (1.30× vs PR)
E=128 k=8 bf16 4 3.412 2.881 1.18× 3.030 5.967 2.071 (1.39× vs PR)
E=128 k=8 bf16 16 3.441 2.897 1.19× 3.214 5.994 2.171 (1.33× vs PR)
E=128 k=8 bf16 64 3.470 2.966 1.17× 3.302 7.384 2.263 (1.31× vs PR)
E=128 k=8 bf16 128 3.503 2.975 1.18× 3.304 7.339 2.281 (1.30× vs PR)
E=128 k=8 bf16 1024 6.277 6.161 1.02× 3.973 7.641 2.390 (2.58× vs PR)
E=128 k=8 bf16 4096 6.448 6.303 1.02× 6.485 7.712 3.236 (1.95× vs PR)
E=256 k=8 bf16 1 / 64 / 1024 3.705 / 3.924 / 6.493 3.154 / 3.344 / 6.302 1.17× / 1.17× / 1.03× 3.299 / 3.718 / 3.977 6.223 / 7.793 / 7.946 2.338 / 2.543 / 2.655
E=512 k=10 bf16 1 / 64 / 1024 5.308 / 5.501 / 6.514 4.502 / 4.677 / 5.879 1.18× / 1.18× / 1.11× 4.316 / 4.561 / 5.231 9.679 / 10.012 / 10.208 N/A
E=128 k=8 shared=1 1 / 64 / 1024 3.568 / 3.832 / 6.661 3.118 / 3.338 / 6.509 1.14× / 1.15× / 1.02× N/A 6.753 / 8.481 / 8.849 N/A
  • AITER already ships precompiled ASM kernels (topk_softmax_asm in hsa/{gfx942,gfx950}/topksoftmax/topksoftmax.csv, covering (E, k) ∈ {(128, 4/6/8), (256, 6/8), (384, 8), (640, 8)} for bf16 and fp32), which are 1.30–1.39× faster than PR #7338 at M=1..128 (2.05–2.28 µs) and 2.58× faster at M=1024 (and 1.97–2.26 µs vs 2.58–2.76 µs on gfx950), but topk_gating / topk_softmax do not currently route to topk_softmax_asm.

B. Ungrouped Biased Sigmoid — GLM-5.2 (E=256, k=8, fp32, strided [M, 9][:, :8], renorm=True, scale=2.5)

M Base biased_grouped_topk_hip PR #7338 biased_grouped_topk_hip PR Speedup topk_gating(sigmoid) vLLM Triton _sigmoid_bias_flat
1 2.916 2.731 1.07× 3.917 2.463 (contig: 2.395)
4 3.017 2.847 1.06× 3.954 2.472
16 3.071 2.943 1.04× 4.008 2.520
64 3.133 2.988 1.05× 4.062 2.556
128 3.169 3.034 1.04× 4.099 2.602
1024 3.450 3.315 1.04× 4.337 —
4096 6.654 6.028 1.10× 8.297 —
  • Within AITER's C++/HIP ops, biased_grouped_topk_hip (topk_reg_kernel) is the fastest path (1.3–2.2× ahead of topk_gating(..., score_func="sigmoid") across E=128..512), and this PR consistently improves it on both gfx942 and gfx950.
  • For vLLM decode (M <= 128, E <= 512, k <= 8), vLLM's 0-LDS register Triton kernel (_sigmoid_bias_flat_topk_kernel, currently gated to _MAX_TOKENS = 1) runs at 2.42–2.60 µs on gfx942 (2.14–2.47 µs on gfx950), 1.12–1.17× faster than PR #7338.
  • One neighboring shape to check on gfx942 (ROCm 10.1): E=128, k=32, fp32 improved at M=1..1024 (4.19 → 3.95 µs at M=1) but measured slower at M=4096 (7.84 → 9.43 µs).

2. Recommendation

  1. Follow-up dispatch opportunities (outside this PR): For maximum Qwen3-MoE and GLM-5.2 decode performance, separate follow-ups should (a) route eligible unbiased contiguous softmax calls (num_shared_experts == 0, num_valid_rows == None, routed_scaling_factor == 1.0) to topk_softmax_asm, and (b) raise _MAX_TOKENS on vLLM's _sigmoid_bias_flat_topk_kernel for M <= 128.
  2. This PR itself is clean, bit-identical, and worth merging for the general topk_reg_kernel and topk_gating_kernel_prefill paths — which remain active whenever num_valid_rows (CUDA-graph / DP padding), num_shared_experts > 0 (3.57 → 3.12 µs), correction_bias on softmax, M > 128 / topk > 8, or bit-identical legacy tie ordering are needed.
  3. Small inline improvements on the current diff: All cross-lane encodings (row_ror:8 for XOR 8, ds_swizzle 0x401f for XOR 16, warp_rank_desc_upto key == 0 dead-lane invariant, and wave32 subwarpArgmaxLane) checked out cleanly. Left a few focused inline comments where small tweaks to the touched lines drop remaining ds_bpermute/ds_swizzle ops, extra DPP moves, or compiler-generated branch/EXEC blocks while preserving 0-ULP bit-identity.
  4. Nit (aiter-bot): Please bump Reviewed revision in the PR description from ce453431700c to 71283d53aa8c (or the next head SHA).

Comment thread csrc/include/topk_gating_kernels.cuh Resolved
Comment thread csrc/include/topk_gating_kernels.cuh Resolved
Comment thread op_tests/test_moeTopkSoftmax.py Resolved
@phambinhfin
phambinhfin marked this pull request as ready for review November 23, 2026 16:43
@phambinhfin
phambinhfin requested a review from a team November 23, 2026 16:43
@github-actions github-actions Bot changed the title [Perf] MoE routing top-k: readlane/DPP instead of ds_bpermute [HIP] [Perf] MoE routing top-k: readlane/DPP instead of ds_bpermute Nov 23, 2026
@github-actions github-actions Bot added the HIP label Nov 23, 2026
@zufayu
zufayu requested a review from yifehuan November 24, 2026 01:17
…entical

Covers the register top-k behind biased_grouped_topk and the topk_gating softmax decode path.

Signed-off-by: Pham Binh <[email protected]>
The existing thirty_two_way_tie case only reached the non-unrolled
warp_rank_desc fallback with the unrolled (topk<=8) renorm. Two
combinations this PR's rank/renorm unrolling introduces were still
untested: topk>8 together with the n_cand<=16 unrolled rank tier, and
EXPERTS_PER_LANE==8 (E=512), the edge of the BALLOT_SLOTS<=8 compile
gate.
@phambinhfin
phambinhfin force-pushed the phambinh/topk-reg-lane-bcast branch 2 times, most recently from c8ca617 to 22f02c9 Compare November 27, 2026 07:13
…ble tests

- lane_xor<4>: start from mov_dpp with bound_ctrl, dropping a v_mov and s_nop.
- Full-wave softmax max: fused DPP max plus readlane, halving the LDS ops.
- lane_serial_sum: drop the per-lane guard; unused lanes already hold +0.0f.
- Ballot slots: compute mbcnt outside the ternary, avoiding EXEC save/restore.
- Stable tests: topk=4, E=192 and E=200; pad the legacy reference to the LDS path.

Outputs are bit-identical to the previous commit.
@phambinhfin

phambinhfin commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

@samremes all five inline suggestions are in 0d5bd9b; local_max only for the full-wave row (see the thread). Outputs are bit-identical to main f70ac7f90 on 960 cases (biased, grouped and topk_gating; E=64–896; M=1–16384; ties, NaN and ±Inf).

Per call, CUDA graph, median of 5 alternating rounds, MI325X, ROCm 10.0 image:

Shape main µs PR before fixes µs 0d5bd9b µs
GLM-5.2 E256 k8 fp32, M=1 2.870 2.587 2.417
GLM-5.2 E256 k8 fp32, M=128 3.137 2.987 2.815
Qwen3 softmax E128 k8 bf16, M=1 3.261 2.703 2.639
Qwen3 softmax E128 k8 bf16, M=128 3.539 2.967 2.907
E128 k32 fp32, M=1 4.157 3.927 3.962
E128 k32 fp32, M=4096 10.217 9.674 9.598

I can't reproduce the E128 k32 M=4096 slowdown; which image did you use? At M=16384, E128 k8 bf16, E384 k8 bf16 and grouped softmax E256 are 3–4% slower than before the fixes, still 1.03–1.06× over main; I haven't looked into it yet. Agreed that topk_softmax_asm routing and vLLM _MAX_TOKENS belong in follow-ups.

@samremes samremes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 0d5bd9b4a. All five suggestions are in and correct (lane_xor<4> mov_dpp + bound_ctrl, local_max readlane limited to the full-wave row, lane_serial_sum<8>, the mbcnt hoist, and the new stable_cases). Thanks for the quick turnaround.

Validation: head 0d5bd9b4a vs main f70ac7f90, both JIT-built from scratch on each arch.

MI325X (gfx942) MI355X (gfx950)
Bit-identical outputs (biased_grouped_topk_hip, grouped_topk, topk_gating; E=64–2048, k=4–32, M=1–8192; random, 16/32-way ties, all-equal, NaN, ±inf, masked) 26,148 / 26,148 configs 26,148 / 26,148 configs
test_moeTopkSoftmax.py, test_moe_topk_gating.py pass; 32/32 reg_stable rows err 0, incl. the new topk=4, E=192, E=200 rows same
PR vs main, 23 shapes (CUDA graph, 6 alternating rounds) 1.004–1.216× faster 1.02–1.21× faster
biased_grouped_topk_hip E128 k32 fp32, M=4096 10.177 → 9.543 µs 6.436 → 6.205 µs
Control: topk_gating sigmoid E128 k32 fp32, M=4096 (code path unchanged) 16.436 vs 16.443 µs 9.956 vs 9.958 µs

Image / E128 k32 M=4096: round 1 used rocm/pytorch:rocm10.1.0_ubuntu24.04_py3.12_pytorch_release_2.14.0, and so did this round. I can't reproduce the slowdown either: your 10.217 → 9.598 µs matches our 10.177 → 9.543 µs. Looking back at the round-1 data, the PR arm was fine; it is within 1.2% of today's numbers. The base arm (main c1096fa40a) was 23% faster than today's main at this shape, and 28% faster on the unchanged topk_gating sigmoid control. So the "regression" came from an anomalous baseline, not this PR. Sorry for the noise.

M=16384: we didn't measure against the pre-fix commit. Against main, the PR is 1.03–1.07× faster on gfx942 and 1.13–1.18× faster on gfx950 for E128 k8 bf16, E384 k8 bf16 and grouped softmax E256, so this is not blocking.

Non-blocking:

  • The padded legacy reference in test_moeTopkSoftmax.py hard-codes (2, 3, 4, 6, 8, 14, 16, 32), which mirrors AITER_TOPK_REG_LAUNCH_EPLS. If the C++ list grows, the reference silently lands on the register path and the stable cases compare the kernel with itself. A comment pointing at the macro would be enough.
  • Agreed on the unseeded multi-group test_grouped_topk cases: we saw the same intermittent topk_ids ... failed! lines on MI325X on main too. I'm opening a separate PR to seed that test.
  • CI: MI35X Standard Tests shards 0, 4 and 5 failed with "The self-hosted runner lost communication with the server", not a test failure. GitHub won't re-run jobs while shard 6 is still running, so I'll re-run the failed jobs as soon as the run finishes.

@TennyWang1223
TennyWang1223 merged commit 68f7f67 into ROCm:main Nov 30, 2026
98 of 102 checks passed
lirui927 pushed a commit that referenced this pull request Nov 30, 2026
…pk-mw

Conflicts with #7338 (readlane/DPP top-k) in two files:

- csrc/kernels/topk_softmax_kernels_group.cu: both sides' helpers stay
  (warp_rank_desc_slots; warp_rank_desc_upto, lane_serial_sum).
  emit_legacy_ordered_topk is main's template <bool UNROLLED> with this
  branch's slot split: the one-slot arm (wave64) takes main's unrolled
  rank tiers, the two-slot arm (wave32) is unchanged, and the renorm
  tail is main's. main's ballot compaction and readlane pivot merge
  without conflict and now also run at wave32 for EPL 4, 6 and 8.
- op_tests/test_moeTopkSoftmax.py: thirty_two_way_tie keeps pattern id
  7, forty_way_tie takes 8 (the id only seeds the rows). main's padding
  loop gives 260 for the two ref260 cases, so ref_experts goes and the
  cases move into stable_cases.

Device code of module_moe_asm: gfx942 and gfx950 match main for every
kernel main has; on gfx1250 only topk_reg_kernel EPL 4, 6 and 8 change
against aa3a0de. Not run on a GPU.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

5 participants