Repository navigation
[FlyDSL] [Bugfix] Sync both wave groups before the gfx950 A16W16 HTI GEMM reads its first and last stages - #7042
Conversation
The second wave group of the half-tile-interleaved A16W16 kernel runs one barrier ahead, so the barrier after which the first group reads stage 0, and in the tail the stage 1 A half 0, pairs with an earlier barrier of the second group. vmcnt counts only the issuing wave's copies, so the first group could read LDS that the second group's DMA had not written. Make the second group retire those copies before that earlier barrier, as ROCm/FlyDSL#1269 does. No barrier is added. Add test_hgemm_concurrent_copy to op_tests/test_flydsl_hgemm.py. It runs the two-K-tile HTI launch 1000 times next to a 256 MiB copy on a side stream and requires every output to match the idle-GPU output bitwise. On MI355X, 336-362 of the 1000 launches differ on main and none with this change. Signed-off-by: Jin Pan <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Conflict: op_tests/test_flydsl_hgemm.py, where ROCm#7042 added test_hgemm_concurrent_copy at the same spot as this PR's check_input_span / check_large_a / check_strided_out; both kept.
Conflict: op_tests/test_flydsl_hgemm.py keeps both main's HTI concurrent-copy test (ROCm#7042) and this branch's partial-sum exactness test. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
The second wave group of the half-tile-interleaved A16W16 kernel runs one barrier ahead, so the barrier after which the first group reads stage 0, and in the tail the stage 1 A half 0, pairs with an earlier barrier of the second group. vmcnt counts only the issuing wave's copies, so the first group could read LDS that the second group's DMA had not written. Make the second group retire those copies before that earlier barrier, as ROCm/FlyDSL#1269 does. No barrier is added. Add test_hgemm_concurrent_copy to op_tests/test_flydsl_hgemm.py. It runs the two-K-tile HTI launch 1000 times next to a 256 MiB copy on a side stream and requires every output to match the idle-GPU output bitwise. On MI355X, 336-362 of the 1000 launches differ on main and none with this change. Signed-off-by: Jin Pan <[email protected]> Co-authored-by: Yutao Xu <[email protected]>
…#7042) The second wave group of the half-tile-interleaved A16W16 kernel runs one barrier ahead, so the barrier after which the first group reads stage 0, and in the tail the stage 1 A half 0, pairs with an earlier barrier of the second group. vmcnt counts only the issuing wave's copies, so the first group could read LDS that the second group's DMA had not written. Make the second group retire those copies before that earlier barrier, as ROCm/FlyDSL#1269 does. No barrier is added. Add test_hgemm_concurrent_copy to op_tests/test_flydsl_hgemm.py. It runs the two-K-tile HTI launch 1000 times next to a 256 MiB copy on a side stream and requires every output to match the idle-GPU output bitwise. On MI355X, 336-362 of the 1000 launches differ on main and none with this change. Signed-off-by: Jin Pan <[email protected]> Co-authored-by: Yutao Xu <[email protected]>
Summary
Port the fix of ROCm/FlyDSL#1269 to the aiter copy of the gfx950 A16W16 half-tile-interleaved (HTI) GEMM. In
gemm_a16w16_hti_gfx950_kernel, the first wave group can read LDS that the second group writes by LDS DMA before the second group waits for those copies. This PR makes the second group retire those copies before the barrier that releases the read, in the prologue and in the tail. It adds no barrier. It also adds the failing case toop_tests/test_flydsl_hgemm.py.Motivation
The second wave group (
wid // n_waves == 1) runs one barrier ahead. Ans_barriercompletes when every wave arrives at a barrier, whichever one. So the first group'swait_vmcnt_and_barriercompletes together with an earlier barrier of the second group, before the second group runs its owns_waitcnt vmcnt.vmcntcounts only the copies of the issuing wave. The first group can then read stage 0 after the prologue, and the stage 1 A half 0 in the tail (load_a_fragment(0, 1)), while the second group'sbuffer_load ... ldscopies into them are in flight. The barriers and waits of the prologue and the tail in aitermainare the same as in FlyDSL before ROCm/FlyDSL#1269; that PR has the full analysis.The tail read gives wrong results on MI355X when a launch has exactly two K tiles and no split-K: the main loop is skipped, so nothing else orders the second group's copy before the read. Results of the new
test_hgemm_concurrent_copy(8192×8192×128, 256×256×64 HTI, 1000 launches, each next to a 256 MiB copy on a side stream):main457b115main+ only the prologue waitmain+ only the tail waitThe prologue read has not failed on hardware, but no ISA rule orders it, so the prologue wait stays, as in FlyDSL.
No tuned row in
aiter/configshits this case today: none of the 239 gfx950 HTI rows has exactly two K tiles per split-K partition. But the tuning catalog (get_flydsl_a16w16_configs) offers such configs for small-K shapes, and some of them fail without a concurrent copy. For 8192×8192×128 the catalog includes 128×128×64 withm_waves=2, n_waves=4andsplit_k=1. Without a concurrent copy,mainreturns wrong results in 93 of 200 back-to-back launches withgroup_m=4and in 9 of 200 withgroup_m=0; this PR returns none. A wrong launch has about 0.01% wrong elements, which is below the tuner'serrRatioof 0.05, so a tuning run can accept the config. With a concurrent copy, the othern_waves=4tiles of that catalog (128×256×64, 256×128×64 and 256×256×64) also fail onmain(9 to 189 of 500 launches) and not with this PR.Changes
s_barrier, the second group runss_waitcnt vmcnt(0). In split-K launches withks_idx == 0,SplitKProtocol.publishhas already drained every wave, so there this wait finds nothing.wait_vmcnt_and_barrier(0), the second group runss_waitcnt vmcnt(half_ldg_b_iters + half_ldg_a_iters). This retires the stage 1 A half 0 copy; the newer B half 1 and A half 1 copies may stay in flight. The split-K tail starts withwait_vmcnt_and_barrier(0), so there this wait is a no-op.op_tests/test_flydsl_hgemm.py:test_hgemm_concurrent_copyruns the failing case through the model path (flydsl_hgemm(a, w, out=out)) and asserts that no launch differs from the idle-GPU output.checkAllclosechecks the idle-GPU output against torch. The check across launches is bitwise and counts on the GPU: without split-K the kernel is deterministic, and a host sync per launch would change how the GEMM overlaps the copy. (8192, 8192, 128) is in the default-slist, so CI runs the check; it adds a few seconds.Performance
MI355X, one GPU with no other load. Rows: all 4 split-K HTI rows in
aiter/configsand the 6 fastestsplit_k=1HTI rows. One process loads the kernel module ofmainand of this PR and interleaves them: each round runsmain, this PR andmainagain (A/A control), in alternating order. Each variant gets 7 rounds ofrun_perftest(num_iters=200), and the table shows the median kernel time. The script was run twice; the µs columns are from the second run.main(µs)main, run 1, run 2Geometric mean of this PR /
main: 0.994 and 0.996 on the split-K rows, 1.001 and 0.996 on thesplit_k=1rows. This PR /mainis between 0.974 and 1.008; the A/A ratios are between 0.992 and 1.010. The 256×8192×28672 split-K 7 row is 2.6% and 2.2% faster in the two runs; I did not investigate why.Testing
test_hgemm_concurrent_copy, see Motivation.All results above: MI355X,
rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0(the aiter CI image), flydsl 0.4.0 (the aiter pin), aiter 457b115 with and without this PR.Documentation
None needed: no API or documented behavior changes.
Dependencies
Breaking Changes
None.