Skip to content

[HIP] [FlyDSL] Conv3d gfx1250 Optimization - #7503

Merged
huizzhan merged 18 commits into
mainfrom
cursor/gfx1250-conv3d-opt-f94a
Nov 9, 2026
Merged

huizzhan merged 18 commits into
mainfrom
cursor/gfx1250-conv3d-opt-f94a

Conversation

@huizzhan

@huizzhan huizzhan commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Speeds up the gfx1250 (MI450X) FlyDSL implicit-GEMM conv3d on the Wan2.1 and Qwen-Image VAEs: kernel pipeline and K-tile changes, kH×kW input reuse, a vectorized epilogue, tuner extensions, and retuned gfx1250 tables. Every shape is 0 mismatches at rtol=atol=2e-2, and no shape is slower than main.

Performance

Kernel time only. Every FlyDSL conv shape of one pass is weighted by its calls (Wan2.1: one 81-frame encode + decode). NDHWC output; main and this PR alternate on the same GPU, median of 2 rounds.

pass MI450X main MI450X this PR speedup vs main MI35X (gfx950 table) speedup vs MI35X MI450X best GEMM ² speedup vs GEMM ²
Wan2.1 368×544 (24 shapes) 173.73 ms 68.45 ms 2.54× 102.89 ms ¹ 1.52× ¹ 98.98 ms 1.53×
Wan2.1 480×832 (24 shapes) 320.27 ms 127.03 ms 2.52× 181.93 ms ¹ 1.44× ¹ — —
Qwen-Image 1024×1024 (16 shapes) 12.89 ms 4.74 ms 2.72× 6.76 ms 1.43× — —
Qwen-Image 1328×1328 (16 shapes) 21.76 ms 7.88 ms 2.76× 11.10 ms 1.41× — —
  • Speedup = other time / this PR's MI450X time (> 1: this PR on MI450X is faster).

  • ² The equivalent bf16 GEMM of every conv shape on MI450X, best backend per shape (section below). It was measured back to back with the conv on another MI450X (heliosr-1b114-d01-3) at commit 14, where the conv took 64.57 ms; the speedup is from that same-GPU pair. The other passes are being measured.

  • MI35X is the call-weighted us of main's gfx950 tuned tables (wan21_vae_bf16_tuned_conv3d.csv, qwenimage_vae_bf16_tuned_conv3d.csv; gfx950, 256 CU). That is tuner timing on an MI35X, not a back-to-back run with the MI450X numbers.

  • ¹ The gfx950 table has no row for the two Wan2.1 time_conv shapes, so the MI35X time covers 22 shapes, and its speedup compares the same 22 shapes (this PR: 67.87 ms at 368×544, 126.21 ms at 480×832).

  • Measured at commit 14 (af4bbc03a) on ctheliosr-1b112-a08-1.

  • Commits 15–16 (head 7acbb8d7c) add to this. In a same-GPU A/B against commit 14 on heliosr-1b114-a07-3, they take a further 0.87 ms off a Wan2.1 368×544 pass and 0.33 ms off a 480×832 pass:

shape commit 14 head speedup
down_9_10_mid 368×544 (160 calls) 40.45 µs 36.36 µs 1.11×
time_conv_192 368×544 14.00 µs 8.75 µs 1.60×
time_conv_384 368×544 15.96 µs 10.46 µs 1.53×
time_conv_192 480×832 24.72 µs 13.02 µs 1.90×
time_conv_384 480×832 16.86 µs 12.03 µs 1.40×
  • Absolute times differ between these MI450X machines (up to ~2×), so compare speedups across machines, not µs.

Against the equivalent bf16 GEMM (Wan2.1 368×544)

How far the conv is from a dense GEMM of the same size. Each conv maps to M = N·Do·Ho·Wo, N = output channels, K = Cin·kT·kH·kW, bf16 with bias. A full csrc/gemm_a16w16/gemm_tuner.py sweep (FlyDSL, OPUS, Triton, torch, hipBLASLt) on the first machine picked the candidates; hipBLASLt won no shape. Each shape's top 8 FlyDSL / OPUS candidates plus Triton and torch were then timed back to back with the conv on heliosr-1b114-d01-3 at commit 14, taking the fastest correct one. On the 8 largest-M shapes no FlyDSL / OPUS candidate was correct, so those are Triton or torch. The GEMM takes its A already in im2col layout, so it is a bound on the arithmetic, not a drop-in replacement.

The conv is faster on 15 of the 24 shapes.

layer calls conv µs GEMM µs conv speedup GEMM backend
down_0_1 80 248.6 483.5 1.94× Triton
down_3_4 60 224.2 318.7 1.42× Triton
down_6_7 60 117.8 151.2 1.28× FlyDSL
down_9_10_mid 160 38.0 33.8 0.89× FlyDSL
wdec_up_384_L1 20 167.9 222.9 1.33× Triton
wdec_up_192_L0 20 150.2 226.1 1.51× Triton
down_3_in 20 138.0 250.7 1.82× Triton
wdec_conv_out 20 99.4 270.4 2.72× Triton
conv_in 20 91.5 79.6 0.87× FlyDSL
down_6_in 20 62.4 82.4 1.32× FlyDSL
resample_96 20 52.1 54.7 1.05× Triton
wdec_up_384_L2 20 30.2 36.4 1.21× Triton
12 smaller shapes 0.56–1.59×
Σ µs × calls (24 shapes) 64.57 ms 98.98 ms 1.53×

Conv speedup = GEMM time / conv time (> 1: the conv is faster).

  • After commit 14, commit 16 makes down_9_10_mid 1.11× faster, and the two 368×544 time_conv shapes (where the GEMM was 1.5–1.6× faster) 1.53–1.60× faster.
  • conv_in pads C = 3 to 32 channels, so it does 10.7× the GEMM's MACs.

Optimizations

  1. Pipeline knobs per shape (2bbdfc8e1). The tuner now sweeps num_buffers (LDS ring depth) and main_loop_unroll, as the gfx1250 GEMM tuner sweeps stages / main_loop_unroll. They are carried as optional tuned-CSV columns, and a row without them runs as before.
  2. Wider K tile, and a K-loop race fix (cdee510bc).
    • tile_k (a multiple of 32 that divides C) lets one K step span more channels: one tensor_wait + barrier per tile_k instead of per 32 channels. For example, down_0_1 goes from 81 K steps to 27.
    • s_barrier does not wait for outstanding LDS reads on gfx1250, so a wave could pass the K-loop barrier while a faster wave's TDM refilled the slot it was still reading. A dscnt wait before that barrier fixes the sporadic mismatches seen on one small-tile config.
  3. kH×kW patch input reuse (a7c2fa222). For stride-1 convs, the input is fetched once per (kT, channel) group as one (R + kH − 1) × (C + kW − 1) TDM patch in two LDS stages, and all kH·kW taps read it at constant offsets, cutting A traffic by up to kH·kW×. This is the gfx1250 counterpart of gfx950's kH×kW reuse, as an optional patch tuner/CSV dimension.
  4. Vectorized epilogue (e436796d4, 9753a3351). A lane's 8 accumulator columns are 8 consecutive output channels. With NDHWC output they go out as one 16-byte store instead of 8 16-bit stores, and the bias is read as two dwordx4 loads per column block for every layout. On down_0_1, a wave's epilogue drops from 192 stores + 192 bias loads to 24 + 12.
  5. Tuner (conv3d_tune.py).
    • A two-pass tune: tiles first (-o2 profile), then --tiles_from / --tiles_topk with --pipelines, --tile_ks and --patches on each shape's best tiles.
    • Small-M grid-fill candidates (6bcafb476): when even the largest-first top candidate underfills the CUs, the tile shapes that fill them best are added.
  6. Tables.
    • Every gfx1250 row of wan21_vae_gfx1250_bf16_tuned_conv3d.csv (368×544 and 480×832) and qwenimage_vae_gfx1250_bf16_tuned_conv3d.csv is retuned with the new knobs.
    • The four Wan2.1 encoder time_conv shapes (3×1×1, stride 2×1×1), which were missing from the untuned table and ran the heuristic tile, are added and tuned.
  7. LLVM workaround (122a0946d, re-applied in f9b18e20d). The 2-buffer, tile_k > 32 patch configs spill VGPRs. AMDGPUMarkLastScratchLoad tags spill reloads as last use before the post-RA scheduler, which can then move such a reload above another reload of the same slot. That reads stale scratch, and in one tuning run it caused a memory fault. These configs compile with disable-post-ra, for that compile only; no shipped kernel changes, and the tuner still prunes them because spilling makes them slow. The change touches only conv3d_implicit_gfx1250.py.
  8. CI (ae4a4a920, 233561e72, plus cases in a7c2fa222 / e436796d4). The conv3d CI-mode op test now passes on gfx1250; on main it failed 7 of 21 cases there, none numerically. There are 7 new gfx1250-only cases for tile_k, num_buffers, unroll, the race config, patch and the NDHWC epilogue, each asserting the requested config is the one compiled.
Commits
  1. 2bbdfc8e1 tune num_buffers / main_loop_unroll per shape
  2. cdee510bc tile_k > 32, K-loop LDS race fix
  3. 3af1a0808 retune Wan2.1 368×544 rows
  4. ae4a4a920 conv3d CI-mode op test passes on gfx1250
  5. 233561e72 CI-mode cases for the new K-loop paths
  6. a7c2fa222 kH×kW patch input reuse, patch tuner/CSV dimension, 8 hot 368×544 rows
  7. f3a0f9ac8 tuner: prune 2-buffer wide-K patch variants after the LDS clamp
  8. b49efdfd7 retune Wan2.1 480×832 rows
  9. bc1f3204f patch pass on the remaining Wan2.1 368×544 rows
  10. 97ae390e5 retune Qwen-Image rows
  11. 122a0946d / abac2c505 / f9b18e20d post-RA workaround for spilling patch configs
  12. e436796d4 vectorized NDHWC epilogue
  13. 9753a3351 vector bias read for every layout
  14. af4bbc03a retune 5 rows for the vectorized epilogue
  15. 6bcafb476 tuner: grid-fill candidates for small-M shapes
  16. 7acbb8d7c tune Wan2.1 time_conv rows and the 368×544 mid block

Accuracy and testing

  • Reference and tolerance match the tuner and the op test: fp32 F.conv3d (with bias), rounded once to bf16, rtol=atol=2e-2. Any mismatched element fails.
  • Tables at commit 14, every shape of all four passes: 10 calls into a NaN-filled output, plus 3 through the production entry flydsl_conv_implicit. 0 mismatches, 0 NaN.
  • The 5 rows commit 16 adds or changes: 6 checked calls each in its A/B, 0 mismatches.
  • Every tuning candidate that ran passed strict_compare.
  • python op_tests/test_flydsl_conv_implicit.py (mode=ci) on gfx1250: 28/28 at the head (14/21 on main; the new cases skip on other archs). tests/test_conv3d_ci_modes.py: 20 passed.
  • AOT of both gfx1250 tables at the head on CPU into an empty cache: 160 replays, 0 failed; --check with FLYDSL_RUNTIME_RUN_ONLY=1 passes.
  • Post-RA workaround: the 152 kernels shipped before commit 16 are byte-identical in .text with and without it. The faulting config runs 10 calls with 0 mismatches and no fault.
  • black / ruff on the changed files.

Not adopted, after measuring: the GEMM's amdgpu-sched-strategy / kernarg-preload codegen knobs; folding kH×kW into the channels for conv_in before the vectorized epilogue; an NCDHW result built as an NDHWC conv plus a permute; persistent tiles; per-wave tiles larger than the tuned ones (lower occupancy).

PR Self-Review

Reviewed revision

7acbb8d7c73f

Behavior and intent

  • On gfx1250, flydsl_conv_implicit / run_conv3d_gfx1250 now run the implicit-GEMM conv3d with:
    • a per-shape K-loop pipeline (num_buffers, main_loop_unroll);
    • K tiles wider than 32 channels (tile_k);
    • optional kH×kW input-patch reuse;
    • a vectorized NDHWC epilogue and bias read;
    • a dscnt wait before the K-loop barrier, which fixes an LDS read/refill race.
  • The gfx1250 tuned tables are retuned with the new columns, 4 missing Wan2.1 time_conv rows are added, and the tuner can sweep the new dimensions and small-M grid-fill tiles.
  • Why main was insufficient: on main, gfx1250 ran a fixed 2-buffer, 32-channel K loop with per-tap input loads and per-element output stores. That is 2.5–2.8× slower than this PR on the Wan2.1 / Qwen-Image VAEs (Performance table). Main also had a latent LDS race, and its CI-mode op test failed 7 of 21 cases on gfx1250.
  • gfx950 behavior is unchanged. It runs the same kernels and tables as main; the only shared-file change is that the tuned-table parser also reads the optional gfx1250 columns, which gfx950 rows do not have.

Validation and unverified scope

Validated on MI450X (gfx1250, 256 CU), FlyDSL 0.4.2, image rocm/fw-bringup-mlperf:gfx1250-atom-20261016. Hosts: heliosr-1b114-a07-3 for the head; ctheliosr-1b112-a08-1 and heliosr-1b114-d01-3 for commit 14 data.

  • python op_tests/test_flydsl_conv_implicit.py (mode=ci): 28/28 at the head (14/21 on main).
  • python -m aiter.aot.flydsl.conv --csv <both gfx1250 tables> into an empty cache: 160/160 replays. Then --check with FLYDSL_RUNTIME_RUN_ONLY=1: all hits.
  • Accuracy, at rtol=atol=2e-2 against fp32 F.conv3d rounded to bf16:
    • every shape of Wan2.1 368×544 / 480×832 and Qwen-Image 1024² / 1328² (80 shapes) at commit 14: 10 NaN-filled calls plus 3 through flydsl_conv_implicit, 0 mismatches;
    • the 5 rows commit 16 adds or changes: 6 calls each, 0 mismatches.
  • Performance: same-GPU A/B against main (Performance section).
  • Upstream CI on MI35X (Standard Tests, 8 shards; OPUS Tests): pass. black / ruff: pass.

Unverified:

  • Upstream CI has no gfx1250 runner, so gfx1250 coverage is the manual runs above, all on pre-production MI450X boards whose clocks differ by up to 2×; none was run on a production MI455X.
  • Shapes outside the two VAE tables run the heuristic tile with the default pipeline (2 buffers, tile_k 32, no patch). The epilogue, bias and race-fix changes apply to them too, but are exercised only by the CI-mode cases, not by a broad shape sweep. groups > 1 and dyn_hw at untuned resolutions are covered only by the existing CI cases.
  • The commit-16 rows were not run through flydsl_conv_implicit.
  • The MI35X numbers come from main's gfx950 tuned tables, not from a back-to-back run. The GEMM comparison covers Wan2.1 368×544 only; Qwen-Image 1024² is being measured.
  • The post-RA workaround applies only to configs that no shipped row uses (patch, 2 buffers, tile_k > 32).

PR-specific question

  • Architecture: flydsl_conv_implicit accepts gfx950 / gfx1250 only (_check_supported_arch). It sends gfx1250 to run_conv3d_gfx1250 (_current_gfx() == "gfx1250"), and compile_conv3d_implicit_gfx1250 asserts the target is gfx1250. gfx950 keeps compile_conv3d_implicit, which this PR does not change.
  • dtype: bf16 input and weight only (assert in _conv3d_impl), with fp32 accumulation and bias.
  • Shapes: the host pads C/groups to a multiple of 32. Each new path has its own gate:
path taken when otherwise
tile_k > 32 a multiple of 32 that divides C/groups; split-K stays at 32 (tile_k_unsupported_gfx1250) falls back to 32
num_buffers clamped to the K tiles of the split and to the LDS budget (_clamp_num_buffers), and to kH·kW with patch —
patch kH·kW > 1, unit H/W stride, split-K 1, num_buffers ≤ kH·kW (patch_unsupported_gfx1250) per-tap path
vectorized epilogue NDHWC output, no split-K, no BIG_OUT, K % 8 = 0 and K/groups % 8 = 0 per-element stores
vector bias no split-K and K/groups % 8 = 0 per-element bias
disable-post-ra patch, 2 buffers and tile_k > 32 only —
  • Invariant: the host resolves every tuned or requested knob through these gates before it builds the kernel param. compile_conv3d_implicit_gfx1250 then asserts them again: cgp % 32 == 0, 2 <= num_buffers <= 8, enough K tiles for the pipeline, patch_unsupported_gfx1250(...) is None, and tile_k a multiple of 32. An unsupported combination therefore fails at compile time instead of producing wrong output. Tuned rows match exactly on (gfx, cu_num, full shape), so a row never applies to another shape.

Changed op tests

op_tests/test_flydsl_conv_implicit.py:

  • Host-path checks (_compile_hook, _assert_host_path_gfx1250, and the gfx1250 AITER_CONV3D_DYN_HW patch).
    • On main, the six host-path spies patched gfx950's compile_conv3d_implicit. On gfx1250 they therefore never saw a compile and failed (6 of the 7 gfx1250 CI failures, none numerical).
    • They now hook the compile entry the device actually uses, and assert that the gfx1250 host honors an explicit tile, block_rows, split-K and static extents. No other test checks that explicit configs reach the gfx1250 kernel.
  • _PIPELINE_CASES (7 gfx1250-only cases, skipped elsewhere): num_buffers 3/4 with unroll, tile_k 64/96, the config that exposed the LDS race, patch with several (kT, channel) groups in 3D and 2D, and the NDHWC vectorized epilogue with a channel tail and with patch.
    • Each case checks accuracy over its calls and asserts that the compiled param equals the requested one.
    • These knobs come only from tuned-table columns, not from the public entry's arguments, so the existing cases cannot reach these paths.

The gfx1250 conv3d kernel already takes num_buffers and main_loop_unroll
(the A16W16 GEMM pipeline knobs) but the tuner never swept them and the
tuned CSV could not carry them, so every row ran 2 buffers, no unroll.

- tuned CSV: optional num_buffers / main_loop_unroll columns; the runtime
  lookup reads them and run_conv3d_gfx1250 uses them unless the caller
  passes its own (empty or absent -> 2 buffers, no unroll)
- conv3d_tune.py: --pipelines sweeps num_buffers:unroll pairs per tile
  (recording the clamped value that runs); --tiles_from/--tiles_topk
  restricts each shape to its fastest tiles from an earlier -o2 profile,
  for a two-pass tile-then-pipeline tune
- README: two-pass gfx1250 tune and the new columns
@huizzhan
huizzhan requested a review from a team November 5, 2026 08:46
@github-actions

github-actions Bot commented Nov 5, 2026

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 7503 --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.

@github-actions github-actions Bot changed the title [FlyDSL] conv3d gfx1250: tune num_buffers / main_loop_unroll per shape [HIP] [FlyDSL] conv3d gfx1250: tune num_buffers / main_loop_unroll per shape Nov 5, 2026
@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 7acbb8d7c73f · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

- On gfx1250, `flydsl_conv_implicit` / `run_conv3d_gfx1250` now run the implicit-GEMM conv3d with:
  - a per-shape K-loop pipeline (`num_buffers`, `main_loop_unroll`);
  - K tiles wider than 32 channels (`tile_k`);
  - optional kH×kW input-patch reuse;
  - a vectorized NDHWC epilogue and bias read;
  - a `dscnt` wait before the K-loop barrier, which fixes an LDS read/refill race.
- The gfx1250 tuned tables are retuned with the new columns, 4 missing Wan2.1 `time_conv` rows are added, and the tuner can sweep the new dimensions and small-M grid-fill tiles.
- Why main was insufficient: on main, gfx1250 ran a fixed 2-buffer, 32-channel K loop with per-tap input loads and per-element output stores. That is 2.5–2.8× slower than this PR on the Wan2.1 / Qwen-Image VAEs (Performance table). Main also had a latent LDS race, and its CI-mode op test failed 7 of 21 cases on gfx1250.
- gfx950 behavior is unchanged. It runs the same kernels and tables as main; the only shared-file change is that the tuned-table parser also reads the optional gfx1250 columns, which gfx950 rows do not have.

Validation and unverified scope

Validated on MI450X (gfx1250, 256 CU), FlyDSL 0.4.2, image `rocm/fw-bringup-mlperf:gfx1250-atom-20261016`. Hosts: `heliosr-1b114-a07-3` for the head; `ctheliosr-1b112-a08-1` and `heliosr-1b114-d01-3` for commit 14 data.

- `python op_tests/test_flydsl_conv_implicit.py` (mode=ci): 28/28 at the head (14/21 on main).
- `python -m aiter.aot.flydsl.conv --csv <both gfx1250 tables>` into an empty cache: 160/160 replays. Then `--check` with `FLYDSL_RUNTIME_RUN_ONLY=1`: all hits.
- Accuracy, at `rtol=atol=2e-2` against fp32 `F.conv3d` rounded to bf16:
  - every shape of Wan2.1 368×544 / 480×832 and Qwen-Image 1024² / 1328² (80 shapes) at commit 14: 10 NaN-filled calls plus 3 through `flydsl_conv_implicit`, 0 mismatches;
  - the 5 rows commit 16 adds or changes: 6 calls each, 0 mismatches.
- Performance: same-GPU A/B against main (Performance section).
- Upstream CI on MI35X (Standard Tests, 8 shards; OPUS Tests): pass. `black` / `ruff`: pass.

Unverified:

- Upstream CI has no gfx1250 runner, so gfx1250 coverage is the manual runs above, all on pre-production MI450X boards whose clocks differ by up to 2×; none was run on a production MI455X.
- Shapes outside the two VAE tables run the heuristic tile with the default pipeline (2 buffers, `tile_k` 32, no patch). The epilogue, bias and race-fix changes apply to them too, but are exercised only by the CI-mode cases, not by a broad shape sweep. `groups > 1` and `dyn_hw` at untuned resolutions are covered only by the existing CI cases.
- The commit-16 rows were not run through `flydsl_conv_implicit`.
- The MI35X numbers come from main's gfx950 tuned tables, not from a back-to-back run. The GEMM comparison covers Wan2.1 368×544 only; Qwen-Image 1024² is being measured.
- The post-RA workaround applies only to configs that no shipped row uses (patch, 2 buffers, `tile_k` > 32).

PR-specific question

- **Architecture:** `flydsl_conv_implicit` accepts gfx950 / gfx1250 only (`_check_supported_arch`). It sends gfx1250 to `run_conv3d_gfx1250` (`_current_gfx() == "gfx1250"`), and `compile_conv3d_implicit_gfx1250` asserts the target is gfx1250. gfx950 keeps `compile_conv3d_implicit`, which this PR does not change.
- **dtype:** bf16 input and weight only (assert in `_conv3d_impl`), with fp32 accumulation and bias.
- **Shapes:** the host pads C/groups to a multiple of 32. Each new path has its own gate:

| path | taken when | otherwise |
|---|---|---|
| `tile_k` > 32 | a multiple of 32 that divides C/groups; split-K stays at 32 (`tile_k_unsupported_gfx1250`) | falls back to 32 |
| `num_buffers` | clamped to the K tiles of the split and to the LDS budget (`_clamp_num_buffers`), and to kH·kW with patch | — |
| patch | kH·kW > 1, unit H/W stride, split-K 1, `num_buffers` ≤ kH·kW (`patch_unsupported_gfx1250`) | per-tap path |
| vectorized epilogue | NDHWC output, no split-K, no BIG_OUT, K % 8 = 0 and K/groups % 8 = 0 | per-element stores |
| vector bias | no split-K and K/groups % 8 = 0 | per-element bias |
| `disable-post-ra` | patch, 2 buffers and `tile_k` > 32 only | — |

- **Invariant:** the host resolves every tuned or requested knob through these gates before it builds the kernel param. `compile_conv3d_implicit_gfx1250` then asserts them again: `cgp % 32 == 0`, `2 <= num_buffers <= 8`, enough K tiles for the pipeline, `patch_unsupported_gfx1250(...) is None`, and `tile_k` a multiple of 32. An unsupported combination therefore fails at compile time instead of producing wrong output. Tuned rows match exactly on (gfx, cu_num, full shape), so a row never applies to another shape.

Changed op tests

`op_tests/test_flydsl_conv_implicit.py`:

- **Host-path checks** (`_compile_hook`, `_assert_host_path_gfx1250`, and the gfx1250 `AITER_CONV3D_DYN_HW` patch).
  - On main, the six host-path spies patched gfx950's `compile_conv3d_implicit`. On gfx1250 they therefore never saw a compile and failed (6 of the 7 gfx1250 CI failures, none numerical).
  - They now hook the compile entry the device actually uses, and assert that the gfx1250 host honors an explicit tile, `block_rows`, split-K and static extents. No other test checks that explicit configs reach the gfx1250 kernel.
- **`_PIPELINE_CASES`** (7 gfx1250-only cases, skipped elsewhere): `num_buffers` 3/4 with unroll, `tile_k` 64/96, the config that exposed the LDS race, patch with several (kT, channel) groups in 3D and 2D, and the NDHWC vectorized epilogue with a channel tail and with patch.
  - Each case checks accuracy over its calls and asserts that the compiled param equals the requested one.
  - These knobs come only from tuned-table columns, not from the public entry's arguments, so the existing cases cannot reach these paths.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@huizzhan huizzhan changed the title [HIP] [FlyDSL] conv3d gfx1250: tune num_buffers / main_loop_unroll per shape [HIP] [FlyDSL] conv3d gfx1250 optimization Nov 5, 2026
@huizzhan huizzhan changed the title [HIP] [FlyDSL] conv3d gfx1250 optimization [HIP] [FlyDSL] Conv3d gfx1250 Optimization Nov 5, 2026
…-loop barrier

tile_k: a K tile can now span tile_k channels (a multiple of 32 dividing
C/groups padded to 32), so the K loop takes one tensor_wait + barrier per
tile_k instead of per 32 channels. In LDS the tile stays a run of padded
32-channel chunks (pad interval 32), and TDM sees the global channel axis
split the same way, as (tile_k/32, 32). WMMA K step ks reads chunk ks.
tile_k=32 keeps the previous layouts unchanged. The tuned CSV gains an
optional tile_k column (default 32), conv3d_tune.py a --tile_ks sweep.
Split-K stays at tile_k=32.

Race fix: s_barrier does not wait for outstanding LDS reads on gfx1250,
so a wave could pass the K-loop barrier with its fragment reads of the
slot the next trip's TDM refills still in flight, and a faster wave's
refill could land under them. Wait on dscnt before that barrier. It
showed as sporadic mismatches (44-127 of 2.4M elements, varying run to
run) on a small-tile tile_k=96 config; 50 runs clean after the fix, and
the shipped tile_k=32 configs time the same (0.993-1.009x).
… and tile_k

The 22 tuned 368x544 rows of wan21_vae_gfx1250_bf16_tuned_conv3d.csv,
retuned in two passes on gfx1250 (tiles at the default pipeline, then each
shape's 4 fastest tiles with --pipelines 2:0,2:1,3:0,3:1,4:0,4:1
--tile_ks 32,64,96,128), now carry num_buffers / main_loop_unroll /
tile_k. The 480x832 rows are unchanged and leave the new columns empty
(2 buffers, no unroll, tile_k 32).

Same GPU, alternating with main: one 81-frame 368x544 encode + decode,
all 24 FlyDSL conv shapes, 343.9 -> 224.6 ms (0.653x); down_0_1
1493.7 -> 1034.9 us. Every changed row 10 calls NaN-filled and the
production entry 3 calls per shape, no mismatched element.
On gfx1250, python op_tests/test_flydsl_conv_implicit.py (mode=ci) failed
7 of 21 cases on main, none of them numerically:

- Six host-path checks spied on conv_kernels.compile_conv3d_implicit,
  the gfx950 compile entry, which the gfx1250 backend never calls, so
  they reported 'no implicit compile parameter was observed'. The spies
  now hook the compile entry of the device's own backend. On gfx1250 they
  assert what that backend has: the explicit tile / block_rows / split-K
  reach the compiled param, and the static case really runs static
  extents. The static case now also turns off the gfx1250 host's own
  AITER_CONV3D_DYN_HW copy, and the tuned-lookup spy checks the gfx1250
  compile param as well. The gfx950 assertions are unchanged.
- 2d_splitk2 passes tile=(32, 32, 1, 2) without block_rows; the gfx1250
  host defaulted to block_rows=8, i.e. 4 columns, which is not a legal
  R x C block. An explicit tile now falls back to a legal block_rows the
  same way a tuned row already did.

gfx1250 (MI450X): mode=ci 21/21 passed. tests/test_conv3d_ci_modes.py
20 passed, including a new check of the gfx1250 assertion.
…and tile_k

Tuned gfx1250 rows now set num_buffers / main_loop_unroll / tile_k, which
the CI-mode subset never reached: its tuned conv_in row runs tile_k 32 and
the compact cases run the heuristic tile. Add three gfx1250-only cases on
compact 3x3x3 shapes, each 2 warmups + 10 checked calls, which call the
gfx1250 host directly (the public entry does not take these knobs) and
assert the requested config is the compiled one:

- tile_k 96, num_buffers 3 (the down_0_1 config)
- tile_k 96, num_buffers 3 + unroll, 32x32 tile, K=3 (the config that
  exposed the K-loop LDS race)
- tile_k 64, num_buffers 4 + unroll, C=K=192

Skipped elsewhere, so gfx950 CI is unchanged. gfx1250 (MI450X) mode=ci:
24/24 passed; 33 s with an empty FlyDSL cache, 2.5 s warm. Perf mode
summarizes the same cases in their own table. docs/conv3d-ci.md notes
the gfx1250 additions.
…x544 hot rows

Stride-1 kH x kW > 1 convs can now fetch the im2col input once per (kT,
channel) group as one (R + kH - 1) x (C + kW - 1) TDM patch that all kH * kW
taps read at constant LDS offsets; the weights keep the per-tap ring. The
next group's patch is issued a whole group ahead, after that step's B tile,
so in-order TDM completion still orders it before the B it is waited with.
The per-tap loop and the patch loop share one prelude; the default path's
ISA is unchanged on the nine hot configs.

The tuner sweeps it with --patches (optional `patch` CSV column; empty means
off). Two buffers with tile_k > 32 is pruned: it spills VGPRs on most patch
tiles, and a kernel with scratch faults on gfx1250.

Eight of the nine Wan2.1 368x544 hot rows switch to the patch path; the
480x832 rows and the Qwen-Image table are unchanged. Same MI450X, back to
back: the nine hot layers go from 207.0 to 179.1 ms per 368x544 pass (0.865),
down_0_1 1033.8 -> 881.2 us; 0 mismatches at rtol=atol=2e-2. CI mode adds two
patch cases (26/26 on gfx1250).
…LDS clamp

The prune of 2-buffer patch variants with tile_k > 32 looked at the
requested num_buffers, so a 3 or 4 the LDS clamp brought down to 2 still
ran; check the clamped value instead. Also correct the reason: those are
the only patch variants that spilled VGPRs on the Wan2.1 hot layers (42 of
500), and one of them hit a memory access fault on gfx1250. Other spilled
ones ran correctly, so spilling alone is not shown to fault.

The shipped rows are unaffected: none of the eight patch winners is such a
variant, and all eight stay in the candidate set (401 on the hot rows).
aoli26
aoli26 previously approved these changes Nov 6, 2026

@aoli26 aoli26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…, tile_k and patch

The 22 Wan2.1 480x832 rows still carried main's configs. Retuned on gfx1250
the way the 368x544 rows were: each shape's 4 fastest pass-1 tiles over
--pipelines 2:0,2:1,3:0,3:1,4:0,4:1 --tile_ks 32,64,96,128, and its 8
fastest over --pipelines 2:0,3:0,4:0 --tile_ks 32,64,96 --patches 1; the
patch winner is taken where it beats the per-tap winner by more than 2%
(14 of 22 rows). Every candidate that ran passed strict_compare.

Same MI450X, alternating with main, kernel time only, all 24 FlyDSL conv
shapes of one 81-frame 480x832 encode + decode: 618.1 -> 366.2 ms (0.592);
0 mismatches at rtol=atol=2e-2 (10 calls per shape into a NaN-filled
output, and 3 through flydsl_conv_implicit). The 368x544 rows and the
Qwen-Image table are unchanged.
Commit 6 ran the patch pass on the 9 hot 368x544 rows only. The other 13
rows: 6 have stride 2 and take no patch; the 7 stride-1 ones were swept
with --pipelines 2:0,3:0,4:0 --tile_ks 32,64,96 --patches 1 on their 8
fastest pass-1 tiles (356 candidates, all passing strict_compare). 6 of 7
beat their row by more than 2% and switch to the patch path.

Same MI450X, alternating with main, all 24 FlyDSL conv shapes of one
81-frame 368x544 encode + decode: 344.0 -> 195.9 ms (0.570; 224.6 ms before
the patch rows). 0 mismatches at rtol=atol=2e-2.
…e, tile_k and patch

The 32 rows still carried main's configs and no pipeline columns. Tuned as
the Wan2.1 rows: each shape's 4 fastest pass-1 tiles over --pipelines
2:0,2:1,3:0,3:1,4:0,4:1 --tile_ks 32,64,96,128 (2024 candidates), and its 8
fastest over --pipelines 2:0,3:0,4:0 --tile_ks 32,64,96 --patches 1 (1138
candidates); the patch winner is taken where it beats the per-tap winner
by more than 2% (21 of 32 rows). Every candidate that ran passed
strict_compare.

Same MI450X, alternating with main, kernel time only: 1024x1024 25.70 ->
17.73 ms (0.690), 1328x1328 41.87 -> 29.41 ms (0.702); no shape slower.
0 mismatches at rtol=atol=2e-2 (10 calls per shape into a NaN-filled
output, and 3 through flydsl_conv_implicit).
…ch configs

The 2-buffer patch configs with tile_k > 32 spill VGPRs, and one of them
(t128x192 w2x2 r4, tile_k 96, on Wan2.1 down_6_7) read wrong bias offsets
and faulted. Root cause is in LLVM: AMDGPUMarkLastScratchLoad tags spill
reloads th:TH_LOAD_LU before the post-RA scheduler runs, and the scheduler
moved an LU reload above another reload of the same slot, which then read
stale scratch. Those configs now compile with disable-post-ra.

On that config the register allocation is unchanged (1024 VGPRs, 32
spilled) and the LU-then-reload sites go from 4 to 0; on the GPU it is 0
mismatches in 10 calls with no fault. The 152 kernels of the two shipped
gfx1250 tables are byte-identical in .text, and none of them spills. The
tuner keeps skipping these variants (they are slow); its comment and the
README now give the reason. CI mode 26/26 on gfx1250.
Revert 122a094's kernel change: the fault it works around is an LLVM
issue, and it only reaches configs that no shipped row uses and that the
tuner already skips. The kernel is back to 97ae390, whose 152 shipped
kernels were validated as is. The tuner comment and README keep the root
cause (LLVM's post-RA scheduler moving a last-use spill reload above
another reload of the same slot) as the reason those variants stay pruned.
…ng patch configs

Re-applies 122a094's kernel change, which touches only this conv3d
kernel: the 2-buffer patch configs with tile_k > 32 compile with
disable-post-ra, set for that compile only (FlyDSL restores LLVM options
after each compile). The kernel file is identical to 122a094, which was
validated: 152 shipped kernels byte-identical in .text, the faulting config
0 mismatches in 10 calls with no fault, CI mode 26/26. The tuner comment and
README now state both the root cause and the workaround.
…ore per 8 channels)

A lane's 8 accumulator columns are 8 consecutive output channels. With NDHWC
output they are contiguous, and with K and the per-group K multiples of 8
they are 16-byte aligned and wholly inside or outside a channel tail. The
epilogue stored them as 8 separate 16-bit buffer stores and read the bias as
8 dword loads per (wm, wn); it now does one 128-bit store per 8 channels
(routed to the OOB sentinel when masked) and reads each wn's bias once as
two dwordx4 loads. NCDHW output, BIG_OUT, split-K and K % 8 != 0 keep the
per-element path. On down_0_1's tile the epilogue goes from 192 stores and
192 bias loads per wave to 24 and 12.

Same MI450X, back to back with the previous head, same tuned tables, every
FlyDSL conv shape: Wan2.1 368x544 196.1 -> 122.3 ms (0.624), 480x832 365.9
-> 226.9 ms (0.620), Qwen-Image 1024x1024 17.69 -> 9.14 ms (0.517),
1328x1328 29.37 -> 13.81 ms (0.470). 0 mismatches at rtol=atol=2e-2. The
152 kernels of both tables compile with no spills. CI mode adds two NDHWC
cases (a channel tail, and the patch path): 28/28.
…n block for every layout

The bias read only needs a lane's 8 columns aligned and wholly inside or
outside a channel tail (per-group K a multiple of 8), not NDHWC output, so
the NCDHW path now loads each wn's bias once as two dwordx4 loads too
instead of 8 dword loads per (wm, wn).

Same MI450X, back to back, Wan2.1 368x544 with NCDHW output (the production
entry's default layout): 130.7 -> 125.2 ms (0.958); conv_in 359 -> 226 us.
NCDHW is now within 2% of NDHWC (122.6 ms). 0 mismatches; both tables'
152 kernels compile with no spills; CI mode 28/28.
The tables were tuned while the epilogue was per-element; with commits 12-13
the store cost moved, so the hot rows were swept again (Wan2.1: a fresh tile
pass, then the top tiles over pipeline / tile_k and patch; Qwen-Image: the
top tiles of the earlier tile pass). Only rows that beat the current one by
more than 3% in both rounds of a same-GPU A/B are taken: Wan2.1 480x832
conv_in and wdec_up_192_L0, Qwen-Image 1024x1024 res_96_L0, 1328x1328
res_192_L1 and dec_up_192_L0 (0.69-0.93x each). Every other row is unchanged.

Same MI450X, back to back with the previous tables: Wan2.1 480x832 0.979x,
Qwen-Image 1024x1024 0.960x, 1328x1328 0.971x, Wan2.1 368x544 unchanged.
0 mismatches at rtol=atol=2e-2 (10 calls per shape into a NaN-filled output,
and 3 through flydsl_conv_implicit); AOT of both tables builds and checks,
no kernel spills.
…hapes

The gfx1250 candidate list is ordered largest tile first and cut at
max_configs, so on a small GEMM M every survivor launches fewer blocks than
there are CUs. When even the top candidate underfills the device, the policy
now also appends every wave/block_rows variant of the six tile shapes with
the best grid fill (blocks / whole waves of CUs, rounded to one decimal,
ties broken by the area-first order). Larger shapes get the same list as
before, so their tuned rows are unaffected.

On the Wan2.1 368x544 encoder mid block (M = 3128, N = 384, K = 10368) this
is what lets the tuner reach 128x48 w4x1 r8, which is not in the old list.
…4 mid block

The Wan2.1 encoder's temporal downsample convs (kernel 3x1x1, stride 2x1x1,
20 calls each per encode) were missing from the untuned table, so gfx1250 ran
them on the heuristic tile. Add the four shapes (192 and 384 channels at
368x544 and 480x832) and tune them. Retune the 368x544 mid block row with the
grid-fill candidates, its pass 1 ranked at 4 buffers / tile_k 96 since the
default 2 buffers / tile_k 32 does not order these deep-K tiles usefully.
The 480x832 mid block retune lost to the shipped row, which stays.

MI450X (heliosr-1b114-a07-3), same GPU back to back, 2 rounds, rtol=atol=2e-2
0 mismatches; trees differ only in the two tables:
  368x544 down_9_10_mid  40.45 -> 36.36 us (-10.1%), 160 calls
  368x544 time_conv_192  14.00 ->  8.75 us (-37.5%)
  368x544 time_conv_384  15.96 -> 10.46 us (-34.5%)
  480x832 time_conv_192  24.72 -> 13.02 us (-47.3%)
  480x832 time_conv_384  16.86 -> 12.03 us (-28.7%)
CI mode 28/28.
@huizzhan
huizzhan requested review from aoli26 and jayzlee147 November 9, 2026 07:59

@jayzlee147 jayzlee147 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@huizzhan
huizzhan merged commit 97d2389 into main Nov 9, 2026
@huizzhan
huizzhan deleted the cursor/gfx1250-conv3d-opt-f94a branch November 9, 2026 09:58
ruanjm pushed a commit that referenced this pull request Nov 10, 2026
conv3d gfx1250: K-loop pipeline, wide K tiles, kH×kW patch reuse, vectorized epilogue, retuned tables

2.52-2.76x over main on the Wan2.1 / Qwen-Image VAEs on MI450X (gfx1250);
gfx950 unchanged.

- Kernel: per-shape num_buffers / unroll, tile_k > 32, kH×kW input-patch
  reuse, vectorized NDHWC epilogue and bias, LDS read/refill race fix,
  disable-post-ra workaround for spilling patch configs.
- Tuner / tables: new pipeline / tile_k / patch dimensions and small-M
  candidates; all gfx1250 Wan2.1 and Qwen-Image rows retuned, Wan2.1
  time_conv rows added.
- Tests: gfx1250 CI-mode op test 28/28 (was 14/21) with 7 new cases;
  0 mismatches at rtol=atol=2e-2 on all VAE shapes.
huizzhan added a commit to huizzhan/aiter that referenced this pull request Nov 16, 2026
Resolve the conflicts in csrc/flydsl_conv3d/conv3d_tune.py and README.md with
ROCm#6662 / ROCm#7503, which brought the gfx1250 tuner with the same fp32 reference,
strict_compare, run_kwargs and --run_config kernel_us this branch added. Take
main's version and keep this branch's gfx950 part on top of it: a splitK=1
gfx950 candidate is timed as the kernel alone on prepared operands into a
NaN-filled buffer (generate_data_kernel / run_flydsl_conv3d_kernel), split-K
still through the entry point; conv3d_ref keeps the NCDHW-contiguous fp32
input; the docstrings and README say us is kernel-only on both archs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants