Skip to content

[FlyDSL] [Bugfix] Sync both wave groups before the gfx950 A16W16 HTI GEMM reads its first and last stages - #7042

Merged
coderfeli merged 3 commits into
mainfrom
jhinpan/gfx950-a16w16-hti-wave-sync
Oct 29, 2026
Merged

coderfeli merged 3 commits into
mainfrom
jhinpan/gfx950-a16w16-hti-wave-sync

Conversation

@jhinpan

@jhinpan jhinpan commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

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 to op_tests/test_flydsl_hgemm.py.

Motivation

The second wave group (wid // n_waves == 1) runs one barrier ahead. An s_barrier completes when every wave arrives at a barrier, whichever one. So the first group's wait_vmcnt_and_barrier completes together with an earlier barrier of the second group, before the second group runs its own s_waitcnt vmcnt. vmcnt counts 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's buffer_load ... lds copies into them are in flight. The barriers and waits of the prologue and the tail in aiter main are 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):

Kernel Runs Launches that differ from the idle-GPU output
main 457b115 3 336, 359, 362 of 1000
main + only the prologue wait 2 313, 315 of 1000
main + only the tail wait 3 0 of 1000
This PR 5 0 of 1000

The 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/configs hits 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 with m_waves=2, n_waves=4 and split_k=1. Without a concurrent copy, main returns wrong results in 93 of 200 back-to-back launches with group_m=4 and in 9 of 200 with group_m=0; this PR returns none. A wrong launch has about 0.01% wrong elements, which is below the tuner's errRatio of 0.05, so a tuning run can accept the config. With a concurrent copy, the other n_waves=4 tiles of that catalog (128×256×64, 256×128×64 and 256×256×64) also fail on main (9 to 189 of 500 launches) and not with this PR.

Changes

  • Prologue: after its extra s_barrier, the second group runs s_waitcnt vmcnt(0). In split-K launches with ks_idx == 0, SplitKProtocol.publish has already drained every wave, so there this wait finds nothing.
  • Tail: before the barrier that pairs with the first group's wait_vmcnt_and_barrier(0), the second group runs s_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 with wait_vmcnt_and_barrier(0), so there this wait is a no-op.
  • op_tests/test_flydsl_hgemm.py: test_hgemm_concurrent_copy runs the failing case through the model path (flydsl_hgemm(a, w, out=out)) and asserts that no launch differs from the idle-GPU output. checkAllclose checks 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 -s list, so CI runs the check; it adds a few seconds.
  • The main loop and the non-HTI kernel do not change.

Performance

MI355X, one GPU with no other load. Rows: all 4 split-K HTI rows in aiter/configs and the 6 fastest split_k=1 HTI rows. One process loads the kernel module of main and of this PR and interleaves them: each round runs main, this PR and main again (A/A control), in alternating order. Each variant gets 7 rounds of run_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.

M×N×K Tile Split-K Bias main (µs) This PR (µs) This PR / main, run 1, run 2 A/A, run 1, run 2
196×9216×6144 128×128×64 3 no 41.97 42.20 1.005, 1.005 0.997, 0.998
256×8192×7168 128×128×128 2 no 45.27 45.28 0.993, 1.000 0.994, 1.002
256×8192×28672 128×256×64 7 no 230.44 225.39 0.974, 0.978 0.999, 1.000
999×6144×24576 256×256×64 2 yes 302.96 303.11 1.003, 1.000 1.003, 0.997
2048×5120×640 256×256×64 1 no 19.97 19.92 1.005, 0.998 1.003, 1.000
1296×5120×1280 128×256×64 1 yes 21.13 21.10 0.996, 0.999 1.003, 1.004
2048×3840×1280 256×128×64 1 yes 24.50 24.38 0.996, 0.995 1.005, 0.992
3462×2048×1536 128×128×64 1 no 29.52 29.11 1.002, 0.986 0.993, 0.998
2048×7168×1024 256×256×64 1 no 31.35 31.37 0.997, 1.000 1.003, 1.002
3460×4096×1024 256×256×64 1 no 31.48 31.48 1.008, 1.000 1.010, 0.999

Geometric mean of this PR / main: 0.994 and 0.996 on the split-K rows, 1.001 and 0.996 on the split_k=1 rows. This PR / main is 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

  • Unit tests added/updated: test_hgemm_concurrent_copy, see Motivation.
  • Performance benchmarks run: see Performance.
  • Tested on MI250X / MI300X: the kernel is gfx950 only.

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

  • No new third-party dependencies added

Breaking Changes

None.

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]>
@jhinpan
jhinpan requested a review from a team October 27, 2026 18:03
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7042 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@xytpai
xytpai requested a review from valarLip October 29, 2026 06:03
@coderfeli
coderfeli merged commit 7740098 into main Oct 29, 2026
67 of 75 checks passed
@coderfeli
coderfeli deleted the jhinpan/gfx950-a16w16-hti-wave-sync branch October 29, 2026 07:19
josh-schell-amd added a commit to josh-schell-amd/aiter that referenced this pull request Oct 29, 2026
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.
AndreasKaratzas added a commit to AndreasKaratzas/aiter that referenced this pull request Oct 30, 2026
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]>
solinzby1 pushed a commit that referenced this pull request Nov 2, 2026
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]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants