Repository navigation
[HIP] Speed up gfx950 384-expert sqrtsoftplus topk gating - #8258
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🔵 Needs a closer look
The changed default gfx950 wave64 dispatch for the 384-expert sqrtsoftplus path requires hardware validation because no head-matched GPU correctness results or base/head latency comparisons were supplied.
No open issues 🎉
What changed in this PR
This PR targets faster HIP top-k expert gating on gfx950 for 384-expert workloads using sqrtsoftplus scoring.
Changes:
- Adds a gfx950-specific single-wave dispatch for top-k values up to 8, with and without renormalization.
- Extends the existing single-wave kernel to wave64 using architecture-appropriate ballot handling.
- Preserves wave64 padded-row early exits and the existing expert tie order.
| File | Description |
|---|---|
csrc/include/topk_gating_kernels.cuh |
Adds the gfx950 dispatch and adapts the single-wave kernel for wave64 execution. |
Review effort: Balanced
|
@valar-cop review |
valar-cop
left a comment
There was a problem hiding this comment.
a few small things..
gfx950 base-vs-head latency for topk 1, 2, 4 and 7?
ci green.
Summary
Speed up HIP
topk_gatingon gfx950 for sqrtsoftplus routing with 384 experts and top-k 1–8 by reusing the existing vwave kernel with a wave64 layout. The public API and dispatch inputs are unchanged; the new path is selected automatically.Motivation
The existing gfx950 register kernel uses runtime cursors to select entries from per-lane sorted lists. Reusing the vwave implementation lets the kernel shift these lists after each selection while retaining the existing expert layout, tie order, and normalization order. This improves the measured MI355X workload without depending on the Triton implementation in #7846.
Changes
WARP_SIZE. On gfx950, one wave handles one row, with six experts per lane andWPT=1.ctzllon GFX9 so winning lanes 32–63 remain visible.Only
csrc/include/topk_gating_kernels.cuhchanges. No environment variables, tuning configurations, or dependencies are added. The measurements cover the combined change; individual optimizations were not isolated with ablation experiments.Performance (if applicable)
Hardware/software: one MI355X (gfx950), PyTorch
2.10.0+rocm7.2.4.git3d3aa833, HIP7.2.53211, Triton3.7.0. All three candidates were measured on the same GPU, without clock locking.Workload: BF16 logits
[rows, 384], FP32 correction bias and output weights, INT32 expert IDs, sqrtsoftplus,renorm=True, routed scaling factor1.5, no shared experts, preallocated outputs, and warm-cache inputs. Results are medians of five rounds with alternating candidate order. Compilation and allocation are excluded; IDs and FP32 weight bits were checked before timing.Comparison revisions: original HIP at main
db3b870ea154f4e5d68b4a38a1759cee1a8bcdcd; this HIP change at5be669a848b7bc0aa83e76af8201959e7508e938; Triton from #7846 ata935e8354250fd4f6a560ea7ede6638a0805a24e. For the three-way comparison, the same HIP patch was applied to the #7846 tree to access its Triton dispatch, with original and optimized HIP modules loaded separately. The relevant original HIP sources match the main baseline. This PR itself is based on main and has no dependency on #7846.Eager GPU kernel time:
run_perftest(testGraph=False)These are profiler-derived GPU kernel times (
device_time_sum), not host wall-clock times. All latencies below are in microseconds.For these shapes, latency is approximately 25–27% lower than original HIP and 13–19% lower than Triton.
Graph GPU kernel time:
run_perftest(testGraph=True)This also reports profiler-derived GPU kernel time. At 128–512 rows, this PR and Triton are approximately tied under this measurement method.
The Triton path in the compared revision is enabled only through 2048 rows; larger shapes are not reported as Triton measurements. The HIP performance sweep covered 1–16384 rows.
Graph replay without profiler: GPU events, amortized per call
Each graph contains 256 calls and is replayed 20 times per round after warmup. GPU-event elapsed time is divided by the number of calls. This includes gaps between graph nodes and excludes capture and Python dispatch. It is a separate metric from the profiler kernel times above.
Under this method, latency is approximately 33–35% lower than original HIP and 16–23% lower than Triton. A separate same-graph profiler-on/off experiment showed that profiling perturbs these short kernels, so the two graph measurements are reported separately. No model or end-to-end throughput claim is made.
Supplemental top-k 1–8 sweep (review follow-up)
To cover the full dispatch range, both main baseline
db3b870ea154f4e5d68b4a38a1759cee1a8bcdcdand PR head5be669a848b7bc0aa83e76af8201959e7508e938were rebuilt into separate JIT directories in the same container, then measured on another single MI355X/gfx950. This is a separate base/head run; its measurements are not combined with the earlier three-way comparison.The workload and three timing methods match those defined above: BF16
[rows,384]logits, FP32 bias/weights, INT32 IDs, sqrtsoftplus, renormalization enabled, scaling factor 1.5, no shared experts, preallocated outputs, warm cache, and five alternating-order rounds. The sweep covers rows 1/64/128/256/512/2048/4096/16384 crossed with every top-k from 1 through 8. Software: the same PyTorch2.10.0+rocm7.2.4.git3d3aa833and HIP7.2.53211, with FlyDSL0.5.0; this container has Triton3.8.0, but this supplement measures only the HIP candidates. GPU clocks were not locked.All 64 configurations passed exact expert-ID and FP32-weight-bit comparison against baseline and an independent FP32 reference check. GPU traces confirm that top-k 1–8 selects the new vwave kernel and top-k 9 retains the original kernel.
Across all 64 shapes, the unprofiled graph-event latency reduction is 17.3%–40.8%. Eager profiler medians range from effectively flat (0.5% lower) to 33.1% lower. Profiled graph results do not show a uniform win: 17 of 64 medians are higher, by at most 2.34% (128 rows, top-k 5: 4.294 → 4.395 µs); the largest reduction is 30.6%. Small-row profiled graph results remain close to a tie. The table below includes the specifically requested top-k 1/2/4/7 values rather than inferring their performance from 6/8.
All times are µs, shown as baseline → PR head.
Complete 64-configuration base/head table and container provenance
Container:
rocm/atom-dev@sha256:f3c2fcd6f2213401d275207dd6a7815ef00a9e6ff7bc610dd5e7e266cd55705e. Both HIP builds use the same compiler and CK revisionf93c029e09f67c983696eecac8e0e0350f3dbb54. The unprofiled graph contains 256 calls and is replayed 20 times per round, as in the earlier measurements.Testing
The existing canonical test was run after rebuilding the final main-based worktree:
Result: exit 0,
All topk_gating benchmarks passed!. The default dtype sweep covers FP16/BF16/FP32, with 443 decorated benchmark invocations plus unaligned-input checks. Top-k 9 exercises the existing fallback.Additional validation:
op_tests/triton_tests/moe/moe_routing/test_topk_gating_sqrtsoftplus_384.pyin the [Triton/Gluon] [gfx950] topk_gating: light Triton kernel for 384-expert sqrtsoftplus routing at decode widths #7846 comparison tree with this HIP patch. These cover exact HIP/Triton agreement, dynamic valid-row counts, and first graph capture. This is supplementary evidence from that comparison tree; the test file is not part of this PR or the final main-based tree.git diff --checkpassed.Documentation
No user-facing API or configuration changes. Inline kernel comments describe the wave-size invariant and dispatch scope; performance and validation are documented here.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
5be669a848b7bc0aa83e76af8201959e7508e938Behavior and intent
The gfx950 384-expert sqrtsoftplus path automatically uses the wave64 vwave kernel for top-k 1–8. The intent is to reduce routing latency while preserving the existing output contract, including tie order, normalization, padding, and shared experts. The implementation and measured benefit are described above.
Validation and unverified scope
On MI355X/gfx950, ran
python3 op_tests/test_moe_topk_gating.py --section softplus,nan,ties,eplb,shared,pad-rows,unaligned --num-experts 384 --num-tokens 1,128,2048 --topk 1,6,8,9after rebuilding revision5be669a848b7bc0aa83e76af8201959e7508e938. It passed with exit 0 andAll topk_gating benchmarks passed!(443 decorated invocations plus unaligned checks). Another 432 baseline comparisons passed with identical expert IDs and FP32 weight bits.The review follow-up rebuilt baseline and head in the same container and passed a further 64-case performance/correctness sweep: rows 1/64/128/256/512/2048/4096/16384, every top-k 1–8, and five alternating-order rounds. All 64 cases match the baseline bit for bit and pass the independent FP32 reference. GPU traces verify the top-k 1–8 optimized dispatch and top-k 9 fallback. The Performance section provides all measurements, including the small profiled-graph slowdowns, and separates the earlier three-way run from the supplemental HIP-only run.
Unverified / deferred: downstream model/end-to-end validation is deferred for this PR; no model accuracy or throughput result is claimed. MI250X/MI300X and gfx1250 hardware tests were not run. gfx1250 evidence is limited to offline compilation and ISA comparison. The #7846 tests and earlier three-way timings were run in that comparison tree with this HIP patch, while canonical tests, the 432-case baseline checks, and the supplemental HIP sweep used the final main-based head. These local results do not assert that all PR CI jobs are green.
The default
ci:atommatrix selects DeepSeek-R1-0528 and gpt-oss-120b. A targeted downstream follow-up must verify that the model actually selects the 384-expert sqrtsoftplus HIP branch; a generic downstream green result alone is not claimed as coverage of this dispatch. No model CI run was triggered for this follow-up.PR-specific question
Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
The new dispatch requires runtime architecture gfx950, score function sqrtsoftplus, exactly 384 routed experts, and supported top-k 1–8. There is no row-count cutoff. Existing validation and dtype dispatch continue to accept FP16/BF16/FP32 logits and the existing correction-bias combinations (FP32, or BF16 with BF16/FP32 logits, or no bias).
The launcher selects
WPT=1with oneWARP_SIZEblock per row. On gfx950 this means 64 lanes, six experts per lane, and top-k bounded by the kernel's eight selections. Scalar loads introduce no extra vector-alignment requirement; existing accepted strides, renormalization modes, shared experts, and dynamic valid-row counts retain their contracts. The architecture/score/expert/top-k gates keep other configurations on their previous paths, and the existing host validation remains in force before launch.Changed op tests
None. No
op_tests/files are changed. Existingtest_moe_topk_gating.pysections cover sqrtsoftplus, non-finite values, ties, expert remapping, shared experts, padded rows, and unaligned inputs. The external #7846 test results are identified separately above and are not presented as tests added by this PR.