Repository navigation
[FlyDSL] [gfx1250] Fall back to compiler allocation when a prefill tile exceeds the VGPR partition - #8540
Conversation
…le exceeds the VGPR partition 256x256x256 grouped MoE tiles pin each k128 prefetch slot to 128 VGPRs (v256-v511) and the accumulators to 512 (from v512) whenever FlyDSL exposes sched_vgpr. Wave grids that need more, such as a4w4 1x4 (160 per slot) or a8w4 2x2 (192), hit `assert slot_width <= 128` in make_rmem_slot. Tuned rows from ROCm#7726 select them, so 36 gfx1250 FlyDSL MoE AOT replay jobs fail and run_aot() aborts. Enable the explicit partition only when the tile fits, using the same arithmetic as the assertion; otherwise keep compiler allocation, as every non-prefill tile does. Tiles that fit build exactly as before. Add an a4w4 1x4 regression test. a8w4 on these tiles is tracked in ROCm#8539. Co-Authored-By: Claude <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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 |
zhiding512
left a comment
There was a problem hiding this comment.
Verified on gfx1250 (flydsl 0.5.0, base 162173e89c vs head e27f1e429c).
The fallback condition matches the placement asserts exactly. slot_vgprs is wmma_m_rep * ACT_NDW + wmma_n_rep * WMMA_VECTOR_DWORDS: A and B are placed back to back from 256 + slot_idx * 128, with no padding. n_acc * (WMMA_N // 2) <= 512 is the accumulator assert. Run over the tuned gfx1250 grouped CSVs, the condition selects exactly the 36 failing replay jobs:
gptoss_gfx1250row 12: a4w4 1x4, 12 jobsminimax_m3_gfx1250row 29: a8w4 2x2 GEMM2, 12 jobstuned_grouped_fmoe.csvrows 20, 67 and 68: a8w4 1x4 and 2x2, 4 jobs each
On hardware:
- New test: at base it fails with the empty
assert slot_width <= 128. At head it passes (logits_diff 3.8e-06). The overrides also apply to GEMM2, so both kernels take the fallback: they are..._w1x4_...with no_regpart. This test is skipped on CI (MI35X), so the green CI does not cover it. - Fallback kernels: 866 and 874 VGPRs, no spills, no scratch. Without
waves_per_eu=1the compiler still fits them. - Fitting tiles are unchanged: the a4w4 2x2 kernels keep
_regpart, and their ISA is byte-identical between base and head.
The a8w4 problem is in the harness, not the kernel. On gfx1250, resolve_activation_dtype() returns fp4x2 unless AITER_FORCE_A8W4=1 is set (fused_moe.py:1189). run_moe() does not set it; only the CLI's set_data_format() does. So run_moe("a8w4", ...) runs the a4w4 kernel (mxfp4_tdm_fp4_*) and compares it against the a8w4 reference. That gives logits_diff 0.109 / rel_l2 0.506, the #8539 numbers, for every tile, including the default 64-row tile.
With AITER_FORCE_A8W4=1, the real a8w4 kernels (mxfp4_tdm_fp8_*) pass at the same shape (logits_diff 4.6e-06) with the default tile and with 256x256x256 at both 2x2 and 1x4. So the 24 a8w4 jobs this PR unblocks run correctly. The existing test_grouped_a8w4_situv2_matches_torch_ref has the same gap: 0.064 without the variable, 8.6e-06 with it. That is probably one of the 6 failures that were already there. Could you update the a8w4 notes in the description and in #8539? Making run_moe() call set_data_format() would fix the harness (separate PR).
Suggestion: also require at most 4 waves. The partition always puts the accumulators at v512 and above, and it only works with one wave per SIMD. 2x4, 4x2 and 4x4 pass both checks but cannot run. For 4x2, the build produces 768-VGPR _regpart kernels for a 256-thread workgroup, and dispatch fails with hipErrorLaunchOutOfResources. This happens for both a4w4 and a8w4; the a8w4 kernel also spills 60–69 VGPRs. That is the 4x2 row of #8539, which was actually an a4w4 kernel, and probably the cause of the 4x4 hang as well (not run here). With compiler allocation, a4w4 4x2 runs and passes: 476 VGPRs, 4 spilled.
No tuned row uses these grids today, but an AITER_TDM_M_WARP/N_WARP sweep can reach them, and at 4x4 that hangs the GPU. Adding and m_warp * n_warp * k_waves <= 4 to fits_vgpr_partition would send them to compiler allocation too.
Nit: (8 if a_is_fp4 else 16) duplicates ACT_NDW. Defining ACT_NDW before this check and reusing it would keep the condition and the asserts from drifting apart.
Summary
Builds 256x256x256 grouped MoE TDM tiles whose wave grid does not fit the explicit VGPR partition with compiler allocation, instead of asserting. This fixes the 36 gfx1250 FlyDSL MoE AOT replay failures first reported in #8133.
Motivation
When FlyDSL exposes
sched_vgpr, every 256x256x256 tile pins each k128 prefetch slot to 128 VGPRs (v256-v511) and the accumulators to 512 (from v512). Some wave grids need more per slot: a4w4 1x4 needs 168 + 216 = 160, and a8w4 2x2 needs 816 + 88 = 192. Tuned rows from #7726 select them, somake_rmem_slotfailsassert slot_width <= 128. The replay prints an emptyAssertionErrorfor 36 gfx1250 jobs, andrun_aot()aborts. #8133 attributed these failures to themoe_sort_quant.cuhDPP build error; #8164 fixed that error, but these 36 jobs still fail at162173e89c.Changes
mxfp4_preshuffle_gfx1250_tdm.py:USE_EXPLICIT_VGPR_PARTITIONalso requires the slot (wmma_m_rep * ACT_NDW + wmma_n_rep * WMMA_N/2 <= 128) and the accumulators (n_acc * WMMA_N/2 <= 512) to fit. These are the same bounds the placement code asserts. Tiles that fit build exactly as before, including the_regpartkernel name andwaves_per_eu=1.test_flydsl_grouped_gemm.py:test_grouped_a4w4_prefill_tile_beyond_vgpr_partitionforces a 256x256x256 tile with a 1x4 wave grid and checks a4w4 MoE against the PyTorch reference.Testing
On gfx1250 hardware at
162173e89c:run_aot)AssertionError: slot_width <= 128test_flydsl_grouped_gemm.pyDocumentation
The comment at the changed condition explains the fallback.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
e27f1e4
Behavior and intent
256x256x256 tiles that cannot fit the fixed VGPR placement now build with compiler allocation instead of failing an assertion. Tiles that fit are unchanged, so tuned rows that work today keep their kernel and name.
Validation and unverified scope
Validated on gfx1250 at 162173e.
python3 -c "from aiter.aot.flydsl.common import run_aot; run_aot('/tmp/flydsl-cache')": MoE replay 2690 ok/36 failed before, 2726 ok/0 failed after.pytest op_tests/flydsl_tests/test_flydsl_grouped_gemm.py: the new a4w4 test fails before (AssertionError) and passes after; the other tests give 53 passed and 6 failed, identically before and after. Unverified: performance of the fallback tiles (they did not build before), and a8w4 numerics on 256x256x256 tiles. a8w4 2x2 builds with this change but gives wrong output on our hardware, and a8w4 grids that fit the partition (unchanged by this PR) also fail. That is tracked in #8539 for the kernel owners.PR-specific question
The kernel source changes only the condition that selects the explicit VGPR partition; the placement code is unchanged. Compiled kernels that keep the partition are byte-identical in name and attributes. The only other change is one new op test.
Changed op tests
op_tests/flydsl_tests/test_flydsl_grouped_gemm.py: addstest_grouped_a4w4_prefill_tile_beyond_vgpr_partition. It covers a 256x256x256 tile whose 1x4 wave grid exceeds the 128-VGPR slot. Before this change that tile fails to build; no existing test selects it.🤖 Generated with Claude Code