Add Optimized MoE Routing Path#901
Open
amd-wsung102 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR is an extension of this merged PR: #582
MoE routing fusion previously only paid off for T ≤ 16, where a single kernel does softmax + top-k gating and counting-sort in LDS. Above that, moe_softmax_sort_flydsl fell back to the unfused two-kernel chain, and the earlier serial multi-tile fusion experiment was actually slower than the fallback (e.g. ~20.4 µs vs ~17.6 µs kernel time at T=64 on DeepSeek-R1) because it serialized 16-token tiles inside one workgroup.
This PR adds a dedicated wide routing path for T = 17–64 on gfx95 that beats the unfused baseline on kernel, CUDA-graph, and eager time. The T ≤ 16 single-kernel path is unchanged, and any unsupported shape/arch still uses the existing fallback.
Performance improvement: 1.16x - 1.2x speedup for graph mode.
Optimizations Applied
Validation
Correctness (gfx950):
Coverage added: tile boundaries T = 17, 31, 32, 33, 48, 63, 64 for both supported shapes, expert masking, renormalization disabled, dispatch-label assertions, and fallback correctness above T = 64.
Latencies are in microseconds; speedup = unfused ÷ fused (higher favors the new path). Representative points from the full T = 17–64 sweep:
Test Result - DeepSeek-R1 — E=256, topk=8, model_dim=7168, bf16
Test Result - GPT-OSS 120B — E=128, topk=4, model_dim=2880, bf16
Test Result - MiniMax M3 428B — E=128, topk=4, model_dim=6144, bf16
Submission Checklist