Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
6589da6 to
79b189c
Compare
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved XCD handling can mismatch AOT and runtime specializations and leave MoE tiles unwritten or duplicated, while newly required arguments break existing callers.
5 open issues
Convolution AOT specialization uses the build host's XCD count · New XCD swizzle remaps omit tiles when the grid has a remainder · New Default num_xcds to preserve gather-KV caller compatibility · New Default the new XCD keyword to preserve GEMM caller compatibility · New Default num_xcds to preserve MXFP8 GEMM caller compatibility · New
What changed in this PR
This PR updates FlyDSL dispatch and ahead-of-time compilation to use device or build-target die and compute-unit counts instead of fixed hardware assumptions. It is the FlyDSL portion of the broader backend topology updates.
Changes:
- Pass hardware counts through GEMM, MoE, gather, and convolution paths.
- Distinguish topology-dependent kernel specializations while preserving existing names for eight-die variants.
- Add target-aware AOT count resolution and a dry-run regression test.
| File | Description |
|---|---|
| tests/test_flydsl_dry_run.py | Tests target-derived die counts during AOT replay. |
| aiter/ops/flydsl/mxfp4_gemm2_kernels.py | Supplies die and CU counts to GEMM2 compilation. |
| aiter/ops/flydsl/mxfp4_gemm1_kernels.py | Supplies the die count to GEMM1 compilation. |
| aiter/ops/flydsl/moe_kernels.py | Propagates device die counts through MoE dispatch. |
| aiter/ops/flydsl/kernels/preshuffle_gemm.py | Passes the die count into tile remapping. |
| aiter/ops/flydsl/kernels/mxfp8_gemm_8wave.py | Parameterizes remapping and topology-specific names. |
| aiter/ops/flydsl/kernels/mxfp4_gemm2.py | Parameterizes die remapping and persistent-grid CU limits. |
| aiter/ops/flydsl/kernels/mxfp4_gemm1.py | Parameterizes die remapping and kernel names. |
| aiter/ops/flydsl/kernels/moe_2stage_a16wmix/gemm2.py | Uses configurable die counts and device-derived CU limits. |
| aiter/ops/flydsl/kernels/moe_2stage_a16wmix/gemm1.py | Adds die-count specialization to stage1. |
| aiter/ops/flydsl/kernels/moe_2stage_a16wmix/__init__.py | Queries die counts in both stage wrappers. |
| aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage.py | Forwards die counts to shared MoE builders. |
| aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py | Parameterizes both stages’ remapping and names. |
| aiter/ops/flydsl/kernels/gemm_a8w8_8wave.py | Generalizes the shared die-aware remap. |
| aiter/ops/flydsl/kernels/gemm_a16w16_gfx950.py | Adds die count to GEMM parameters and dispatch. |
| aiter/ops/flydsl/kernels/gather_gemm_8wave.py | Specializes gather remapping by die count. |
| aiter/ops/flydsl/kernels/fhmoe.py | Forwards die counts to shared kernel builders. |
| aiter/ops/flydsl/kernels/conv/conv3d_gfx950_utils.py | Adds die count to convolution grids and coordinates. |
| aiter/ops/flydsl/gemm_kernels.py | Supplies device die count to preshuffled GEMM. |
| aiter/ops/flydsl/gemm_a8w8_mxfp8_8wave.py | Threads die count through MXFP8 compilation. |
| aiter/ops/flydsl/gemm_a8w8_bpreshuffle_8wave.py | Threads die count through eight-wave GEMM compilation. |
| aiter/ops/flydsl/gather_kv_b_proj.py | Uses device die counts for gather compilation and defaults. |
| aiter/ops/flydsl/fhmoe.py | Propagates die counts through FHMoE compilation. |
| aiter/aot/flydsl/mxfp4_moe.py | Includes target topology in AOT jobs and compilation. |
| aiter/aot/flydsl/gemm.py | Passes target-derived die counts to GEMM builders. |
| aiter/aot/flydsl/dry_run.py | Answers die-count queries using the replayed target. |
| aiter/aot/flydsl/common.py | Adds target die-count lookup and the 228-CU architecture mapping. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Both MoE stages mishandle remainder tiles in six-XCD dispatch, leaving some outputs unwritten and processing others twice, with possible double-counted contributions in atomic mode.
5 open issues
XCD swizzle remaps omit tiles when the grid has a remainder Convolution AOT specialization uses the build host's XCD count Default num_xcds to preserve MXFP8 GEMM caller compatibility Default the new XCD keyword to preserve GEMM caller compatibility Default num_xcds to preserve gather-KV caller compatibility
Review effort: Balanced
vpietila-amd
left a comment
There was a problem hiding this comment.
Looks good to me. This is mostly a mechanical change with the default value matching the existing behavior. Hence, the changes from this PR should only cause change of behavior when compiling for devices that have the non-default XCD/CU counts. I've tested these changes in a DeepSeek V4 end-to-end serving, which also covers testing the AOT compilation changes. Both MI350P and MI350X were tested.
- Takes the XCD count from the device through chip_info.get_num_xcds in the FlyDSL GEMM, MoE, conv3d and gather kernels that remapped work over a fixed eight dies, and keys their compiled-kernel caches on it. - Sizes the persistent MXFP4 stage-2 grid from the CU count instead of a fixed 256. - Adds target_num_xcds to the FlyDSL AOT, and answers it for the target in dry_run, so a build compiles each tuned row for its target's die count rather than the build host's. - Covers the dry-run die count per target in the AOT tests.
1e056ab to
4fbb83d
Compare
CI runs op_tests/*.py as sharded scripts, and op_tests/flydsl_tests is not in the plan, so test_flydsl_moe_xcd_swizzle_uneven_grid never ran there. The Focused regression tests step runs `python3 -m pytest -q tests` on pull requests (MI35X shard 0), so the test moves, unchanged, to tests/test_flydsl_moe_xcd_swizzle.py. It imports its data generator, tolerance check, tile_k helper and gfx950 skip from the op test file, which keeps the distinct_experts argument of _generate_a8w4_gui_data. On MI355X (torch 2.13.0+rocm10.0.0, FlyDSL 0.4.2, an empty FlyDSL cache per run): with the three kernel files of the merge-base the test fails (xcd4_uneven_grid_stage1: output has NaN), with this commit's it passes, 0 skipped; the whole tests/ directory in CI's layout runs in 13 s. Signed-off-by: Rony Leppänen <[email protected]> Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The gfx950 skip imported from the op test uses get_gfx(), which follows GPU_ARCHS and takes its last entry, so on an MI355X with GPU_ARCHS='gfx950;gfx942' the regression was skipped. It now checks get_gfx_runtime(), the running GPU, in the test body, as op_tests/test_flydsl_pa_decode.py does. On MI355X with GPU_ARCHS='gfx950;gfx942', get_gfx() returns gfx942 and get_gfx_runtime() gfx950. Under the other settings tried (unset, 'gfx950', 'gfx942;gfx950') both return gfx950. Signed-off-by: Rony Leppänen <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #7774, which ports op_tests/test_flydsl_moe_a16wfp4.py's stage-2 cache-key test to FlyDSL 0.5.0. The version this branch last merged imports _jit_function_cache_key, which FlyDSL 0.5.0 does not have, so that test failed in CI. No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Rony Leppänen <[email protected]>
…sl_xcd_count # Conflicts: # aiter/ops/flydsl/gemm_kernels.py # aiter/ops/flydsl/kernels/gemm_a16w16_gfx950.py
- Maps split-K workgroups so that all splits of a token block share the device's die, pads the grid to whole groups of that many blocks, and sizes the DIST_FINISH residency check by its dies, where each assumed eight. - Reads the die count for the input tensor's device in the wrapper and requires it in grid_size and dist_residency_error, so no caller falls back to eight unnoticed. - Adds the die count to split-K kernel names only when it differs from eight, so eight-die binaries keep their names and single-split kernels, which do not use it, keep one name. - Passes the die count in the Mega-mHC test's scratch-size helper, residency checks and ISA lookup. The splits of a token block exchange partial sums and counters through their die's L2, so the mapping's die count must not be below the device's.
zufayu
left a comment
There was a problem hiding this comment.
AITER SOP code review on current head 2487f08:
Verified blocker: both MoE stages compute workgroups_per_xcd = num_workgroups // num_xcds and remap from that quotient without handling the remainder. For a grid not divisible by the XCD count, this omits some tiles and duplicates others. The dedicated fix in #7567 is still open, so this PR must either absorb that remainder-safe mapping or carry an explicit resolved dependency before merge.
Primary reviewer: @coderfeli (FlyDSL kernel/AOT topology owner); @yadaish can co-review the MoE portion.
Author action: rebase current main, resolve the current conflicts, incorporate/depend on #7567, and rerun topology coverage on the supported XCD counts. Also align the PR description with the intentional no-default compatibility behavior. The failed Aiter Gate remains a separate merge blocker.
…sl_xcd_count # Conflicts: # aiter/ops/flydsl/kernels/gemm_a8w8_8wave.py # aiter/ops/flydsl/kernels/moe_2stage_a16wmix/gemm2.py
…nder' into relbers/gfx950_flydsl_xcd_count
- Takes num_xcds as a required argument of make_launch_grid instead of querying the device inside it, so the host planning stays plain arithmetic that tests/test_conv3d_ci_modes.py can run without imports. - Passes the device's die count from the compile path, and a fixed count in the op test's host-path check, which does not depend on it.
- Uses token 7 and topk 3, a 2 x 21 grid, so the workgroup count is not a multiple of 4 or 8 and the test also fails on a 4-die part if the remap drops the remainder. - Notes that 42 is a multiple of 6, which no gfx950 part has.
- Passes the current die count into the cached compile, so a process that builds several targets cannot reuse a kernel compiled for another die count. - Keeps the public compile_conv3d_implicit(param) signature unchanged.
- Replaces the fixed 8 in the shared-expert XCD round-robin of both stages with num_xcds, as the routed path already does.
|
@zufayu I merged #7567 into this branch, so this PR doesn't have to wait for #7567 to merge first. I also merged latest main and added the runtime XCD count to the kernels that came in from main without it: Mega-mHC split-K, the a16w4 MoE shared expert, and the conv3d compile cache. I reran coverage on MI350P (4 XCDs) and MI355X (8 XCDs) and updated the PR description with the new measurements. The Aiter Gate failure was a NameError from this branch in the conv3d CI-mode test, it is now fixed. |
- Routes the blockscale, mxfp8 8-wave and preshuffle GEMM compiles through main's FlyDSL AOT cache, keeping the device's XCD count as a compile argument. - Adds the XCD count to each of those AOT cache keys, since the cache directory is keyed on arch and CU count but not on the die count. - Passes the XCD count to main's new mxfp8 split-K tail compile as well, which the merged compile wrapper requires.
…et table - Reads get_num_xcds under the input's device in the preshuffle and mxfp8 8-wave wrappers, whose AOT keys and launches use that device, as the blockscale wrapper already does. - Makes num_xcds and out_dtype required in the blockscale _compile_gemm, so a caller cannot silently compile for eight XCDs. - Removes the FlyDSL AOT copy of target_num_xcds and imports the build_targets table in its users, so the FlyDSL prebuild and the HIP build cannot disagree on a SKU's die count. - Updates the AOT cache design doc's blockscale key and its key rules to include the XCD count, which the cache directory's fingerprint does not cover.
…die count - Passes num_xcds to the mxscale preshuffle GEMM's XCD remap and keys its compiled kernels on it; unswizzled configs keep one build for every die count. - Sizes the fused split-K l2_reduce default against the device's XCDs, which assumed eight and so took the path for grids twice its per-XCD budget on a four-XCD part. - Deals the bmm xcd_order tile runs and the skinny a16w16 N slabs over the device's XCDs. - Keeps eight as the split-K tile group in the bmm and mxscale kernels: it is a multiple of every gfx950 XCD count, so a tile's splits still share one XCD's L2 when the count is misread.


Takes the die and CU counts from the device at dispatch, and from the target a job names at AOT build time, instead of assuming eight dies and 256 units. On MI350P this makes FlyDSL Mega-mHC 1.17x faster on geomean at 64 tokens and below (up to 1.31x), and leaves the other FlyDSL kernels' timings unchanged.
First of four, one per backend: this one, Triton (#5505), opus (#5848), HIP (#6877).
Motivation
FlyDSL kernels whose program-id round-robin folds by a die count assumed eight, and the persistent grids assumed 256 units. Both are already wrong on MI308X, which is gfx942 with 80 CUs and four dies and ships 3045 tuned rows. Both are wrong again on MI350P, gfx950 with 128 CUs and four dies.
Technical Details
num_xcds=8as their default so out-of-tree callers keep working, and every in-tree caller passes the queried value. The internal planning helpers that size grids and checks take it as a required argument with no default:grid_sizeanddist_residency_error(Mega-mHC) andmake_launch_grid(conv3d). No in-tree caller can fall back to eight unnoticed.xcd_remap_gridfrom [FlyDSL] [Bugfix] Fix MoE XCD swizzle on grids not divisible by 8 #7567 (eppaneamd), passing the device's die count.xcd_remap_gridgives the firstnum_workgroups % num_xcdsdies one workgroup more, so it is a permutation for any grid size. Until [FlyDSL] [Bugfix] Fix MoE XCD swizzle on grids not divisible by 8 #7567 lands on main, this diff also shows its changes; merging the two in either order is consistent.Testing
AOT job collection matches the base exactly at 781 mxfp4 MoE, 1948 MoE and 3428 GEMM jobs. Kernel names are unchanged at eight dies and carry the suffix at four. Module imports,
ruffandblackclean.tests/test_flydsl_dry_run.pypasses andop_tests/test_flydsl_hgemm.pypasses on MI355X.tests/test_flydsl_moe_xcd_swizzle.pyruns a 2 x 21 grid of 42 workgroups, which is not a multiple of 4 or 8. It fails on MI350P and on MI355X when the remainder-safe remap is reverted, and passes with it.tests/test_conv3d_ci_modes.pypasses.Timed against the merge base on MI355X and on MI350P, run base, head, base on one GPU, each run with its own empty FlyDSL cache; speedup is the mean of the two base runs over head:
test_flydsl_hgemm.pytest_flydsl_moe_a16wfp4.pytest_flydsl_gather_kv_b_proj.pytest_flydsl_moe_a16wfp4.py, shared experttest_flydsl_conv_implicit.py --mode perftest_flydsl_mega_mhc.py, 1 to 64 tokenstest_flydsl_mega_mhc.py, 384 tokens and upThe GEMM, MoE and gather kernels keep their timings on both parts: on MI355X the counts equal the ones they replace, and on MI350P the four-die remap neither gains nor loses on these shapes.
test_flydsl_gather_kv_b_proj.py's Triton column, which this branch does not touch, reads 1.00x on MI350P. The shared-expert and conv3d rows are timed on MI350P only; on MI355X their kernels are unchanged. Of the shared-expert cases only the largest grid, 128 tokens, gains, by 1% to 3%; conv3d is flat over two repeats. FlyDSL a8w4 MoE has no tuned rows for 128 CUs, so MI350P does not run it. The 68 FlyDSL mxfp4 MoE rows tuned for 128 CUs are not timed:test_moe_2stage.pystops on main attest_presorted_moe_hook, before its tuned-row cases.On MI355X the MoE remap is not timed: on grids divisible by the die count every workgroup gets the same tile as before.
Mega-mHC is faster on MI350P up to 64 tokens: one token block now pads to a group of four instead of eight, and from 16 tokens the residency check, now sized for four dies, allows twice the split count.
test_flydsl_mega_mhc.pypasses on both parts; on MI355X its kernels are unchanged, and at 1 to 64 tokens two runs of the same code differ there by up to 5%, as much as base and head do.PR Self-Review
Reviewed revision
f8c4e39
Behavior and intent
FlyDSL kernels take the die and CU counts from the device, and AOT builds from the target, instead of assuming 8 dies and 256 CUs, which is wrong on MI308X and MI350P.
Validation and unverified scope
On MI350P (gfx950, 128 CUs, 4 XCDs, ROCm 7.2.3):
tests/test_flydsl_dry_run.py,tests/test_flydsl_moe_xcd_swizzle.pyandtests/test_conv3d_ci_modes.pypass.op_tests/test_flydsl_moe_a16wfp4.py,test_flydsl_mega_mhc.pyandtest_flydsl_gather_kv_b_proj.pypass.op_tests/test_flydsl_conv_implicit.pyfails 1 of 19 cases because productionconv_inhas no tuned row for (gfx950, 128); this is the same on main.op_tests/test_flydsl_hgemm.pypasses its other checks, then stops at its own "band-stream HGEMM requires gfx950 with 256 CUs" check.nxcd4, so 4-die and 8-die binaries no longer share a cache entry.On MI355X (8 dies) the same tests pass, including
test_flydsl_conv_implicit.pyat 19 of 19. The swizzle test also passes with the die count forced to 4, and fails at 8 dies with the remap change reverted.The FlyDSL hgemm, a16w-mix MoE and gather GEMM tests keep their timings on MI355X and MI350P, and conv3d on MI350P. Mega-mHC is 1.17x faster on geomean on MI350P at 64 tokens and below (see Testing).
Unverified: timing of the FlyDSL mxfp4 MoE rows tuned for 128 CUs, four of which use the MoE remap;
test_moe_2stage.pystops on main before reaching them.Not in scope: band-stream HGEMM explicitly refuses parts other than gfx950 with 256 CUs (
gemm_a16w16_band.py), so it does not run on MI350P.PR-specific question
The main risk is running a binary built for one die count on a part with another. The MoE remap is a permutation for any grid size. The die count is in the kernel name, and the AOT build asks the target rather than the host, which the dry-run test covers. Mega-mHC's split-K finish is only correct when its die count is not below the device's, so the wrapper reads it for the tensor's device.
Changed op tests
op_tests/flydsl_tests/test_flydsl_moe.py: from #7567; its a8w4 data generator gainsdistinct_experts, which the swizzle test uses so that every sorted block holds a routed row. No test is added.op_tests/test_flydsl_conv_implicit.py: passes a die count tomake_launch_gridin its host-path check, which does not depend on it. No test is added.op_tests/test_flydsl_mega_mhc.py: passes the device's die count to the scratch-size helper, the residency checks and the ISA lookup, which otherwise assume eight and disagree with the wrapper on a four-die part. No test is added.