Skip to content

[HIP] [FlyDSL] conv3d: kW and kH x kW LDS reuse of the im2col input on gfx950 - #6421

Merged
huizzhan merged 11 commits into
ROCm:mainfrom
huizzhan:feature/flydsl-conv3d-kw-reuse
Oct 20, 2026
Merged

huizzhan merged 11 commits into
ROCm:mainfrom
huizzhan:feature/flydsl-conv3d-kw-reuse

Conversation

@huizzhan

@huizzhan huizzhan commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cut L2 traffic of the FlyDSL bf16 implicit-GEMM conv3d on gfx950 without lowering blocks per CU, first by
sharing one LDS strip across the kW taps, then by sharing one LDS patch across all kH x kW taps of a 2D output
block, and retune both VAE tables for it. Against main @ 89a47b84a on an idle MI355X:

  • Hot layers, kernel only, sustained: Wan2.1 down_0_1 @480x832 1.43x, Qwen-Image res_96_L0
    @1328^2 1.34x.
  • All 76 tuned shapes (conv3d_tune.py --run_config), sum of per-shape times:
    • Qwen-Image: 1.32x @1024^2, 1.33x @1328^2;
    • Wan2.1: 1.35x @368x544, 1.37x @480x832;
    • 75/76 shapes >= 0.97x.

0 mismatches everywhere. Branch feature/flydsl-conv3d-kw-reuse: 5dda31588, 576f46dcf, a664ea487,
03e548b11, 96a94eb41, 7270f3c0f, eacb9b1c0, 372e6699b, 972999632.

Motivation

The hot VAE layers (96->96, 3x3(x3), stride 1) are bound by data movement, not by MFMA. On main, down_0_1
moves 11.2 GB through L2 per call:

  • about 2/3 is the im2col input, reloaded by every filter tap (about 18x for 3x3x3);
  • about 1/3 is the weights, reloaded by every M tile.

L2 reads as ~97% busy. Under sustained load the card also sits at its 1000 W cap, with sclk around 1.5 GHz. An
ablation (DMAs redirected to the OOB sentinel, so instructions and LDS writes stay) showed that removing traffic
still pays under sustained load, through power and clock headroom rather than bandwidth:

  • A input traffic: about 2.7 GB, half of it L2 misses. Removing it saves 40%.
  • B weight traffic: about 4.0 GB, all L2 hits. Removing it saves 25%.

The constraint that came out of this: a bigger tile only pays if blocks per CU do not drop. 384x96/6x1 cut
traffic 28% but halved residency and gained nothing.

Changes

1. kW reuse: one LDS strip per (kt, kh, channel block) (5dda31588)

  • Strip: for each (kt, kh, 32-channel block) the block DMAs one strip of tile_m + 2*halo input pixels.
  • Tap reads: the KW taps read the strip back at a row shift of kw*dw, so A traffic drops to about 1/3.
  • Blocks that wrap to the next output row: they use a per-segment offset s(m) = m + halo*(m >= m_w), so
    A fragments are read at per-lane LDS addresses (MmaTiling.read_a_at, rows from partition_A).
  • Pipeline: groups are double buffered, with one barrier per group. Weight packing and the epilogue are
    unchanged.
  • Gate: make_im2col_plan enables it only for:
    • stride-1 W, KW > 1, C/groups % 32 == 0;
    • zeros padding, groups == 1;
    • no split-K, no BIG_IN, Wo >= tile_m;
    • and only if the reuse layout keeps at least as many blocks resident per CU as the default path. Without
      this, 128x192 goes from 2 to 1 block/CU and runs at 0.70-0.90x.
  • Under dyn_hw: only the boolean follows the resolution.

2. Partial last B round (576f46dcf)

  • Before: validate_launch_config required B's vector count to be a multiple of block_threads.
  • Now: B's last DMA round only has to end on a wave boundary (TileConfig.b_tail_threads).
    • The waves past the end still issue the DMA, with the OOB sentinel as offset and a 1 KiB LDS park as
      destination (WeightLoader.stage, LdsStager.dst(park=...)).
    • No branch; 1 KiB extra LDS only when the round is partial.
  • Effect: tiles such as 256x96/4x1 and 384x64/4x1 become legal. They keep two blocks per CU under kW
    reuse (77 KiB / 80 KiB) and reload the weights 25-50% less often.
    • 256x96/4x1 runs 4 waves of 64x96 each, i.e. 8 waves/CU instead of 6.
    • ISA: VGPR 229, no spills.

3. XCD-contiguous block numbering (576f46dcf)

  • Problem: gfx950 deals workgroups round-robin over 8 XCDs, each behind its own L2. Neighbouring M tiles
    share input rows, but land in different L2s that each fetch those rows again.
  • Fix: block_coords renumbers blocks (_xcd_contiguous) so each XCD runs a contiguous range:
    • WGM > 1: renumber the pid, then swizzle as before;
    • single N tile: the renumbered pid is the M tile;
    • several N tiles: decode N-fastest, so an M tile's N tiles run back to back on one XCD and share its A in
      that L2. Under the old round-robin this sharing happened by accident whenever grid_m % 8 == 0;
      decoding M-major lost it and cost those layers 5-14%;
    • M-chunked grids are untouched.
  • Coordinates stay Int32: Int64 pushed 192x128/1x4 from 256 to 260 VGPRs, i.e. one wave per SIMD, and
    cost res_384_L3 39%.

4. kH x kW reuse: 2D output blocks (03e548b11)

  • Block shape: a block can own an R x C patch of output pixels in one (n, t) plane instead of TILE_M
    consecutive ones (R * C == TILE_M). R is the new Conv3dImplicitParam.block_rows (compile key); 1 keeps
    consecutive rows.
  • Patch: per (kt, 32-channel block) the block DMAs one LDS patch of (R + (kH-1)dh) x (C + (kW-1)dw)
    input pixels, and all kH*kW taps read it at a constant offset through the per-lane A read.
    • B uses the default path's 4-stage ring (two taps per barrier).
    • The patch is double buffered per group, and its DMA rounds are spread over the batches it may be issued
      in (all at once was ~3% slower).
  • Gate: make_im2col_plan decides: unit H/W stride, kH or kW > 1, C % 16, C/groups % 32, zeros
    padding, groups == 1, no split-K, no BIG_IN/BIG_OUT, and blocks per CU no lower than on the path the layer
    would otherwise take (kW reuse where it applies).
  • Grid: N * Do * ceil(Ho/R) * ceil(Wo/C) M tiles. H and W tails are masked in the epilogue
    (OutputScatter.store row_of / row_ok). dyn_hw is supported (Ho from hw_o / wo). The NCDHW vector
    store is kept only when Wo % 4 == 0.
  • Host: optional tuned-CSV column block_r (missing / empty / Null = 1), carried by the lookup, the
    borrow, AOT and the tuner. The tuner sweeps block_rows = TILE_M / C for C in (32, 64, 128);
    flydsl_conv_implicit takes block_rows= to force it.
  • Effect on down_0_1 (256x96/4x1, R=4 vs kW reuse at the same tile):
    • L2 requests x 64 B: 6.53 -> 5.11 GB;
    • DMA instructions 297 -> 225, barriers 27 -> 41;
    • VGPR 228 -> 196, no spills.
  • op_test: the VAE model shapes run the 2D-block path through the tuned tables (44 rows, 22 of them with an
    H or W tail), and 372e6699b adds cases that force it independently of the tables (see change 7).

5. Defaults, tuner, tables (576f46dcf, a664ea487, 96a94eb41)

  • AITER_CONV3D_KW_REUSE now defaults to 1. The tables are tuned with it on: some of their tiles only fit
    two blocks per CU in the reuse layout. It is part of the compile key, like AITER_CONV3D_DYN_HW, and since
    372e6699b it gates both reuse paths (see change 7).
  • Tuner LDS pruning: the tuner prunes by the LDS the runtime will actually allocate. conv3d_policy takes a
    new lds_bytes_fn(tile) hook, fed from conv3d_im2col.plan_lds_bytes. Without it, 256x96 is pruned at
    the default-path 88 KiB.
  • Both VAE tables retuned with --max_configs 160 and the block_r sweep (96a94eb41):
    • 44/76 rows pick block_r > 1 (Qwen-Image 20/32, Wan2.1 24/44), mostly R = 8 or 12;
    • against the kW-reuse tables of a664ea487: 1.10x (Qwen-Image) and 1.12x (Wan2.1) on the sum of
      --run_config times, no shape below 0.97x (see Results).
    • Why 160: with the smaller reuse LDS, large tiles (384x32, 384x48) pass the LDS filter and the policy's
      fill/area ranking would push small incumbents out of the default 96 cut.
  • New op_test keyword case 2d_tile_256x96: partial B round on the reuse path.

6. Resolution-free closure of the reuse bodies (7270f3c0f)

  • _body_kw_reuse and _body_kh_reuse read geom.cgp, which put the whole ConvGeometry (do / ho /
    wo / npq) into the closure FlyDSL hashes for the launch's manager_key.
  • Under dyn_hw that made every resolution its own artifact, while the AOT dedupe (one job per layer) compiled
    only one of them. With the block_r tables, 4 of the 76 rows (two resolutions of one layer with the same
    config) missed the AOT cache and JIT-compiled on first call.
  • They now use the compile-scope CGP, as _body does. Generated code is unchanged.

7. One rollback switch for both reuse paths; op_test pins the 2D path (372e6699b)

  • Switch: make_im2col_plan checked AITER_CONV3D_KW_REUSE for the kW strip only. With it at 0, all 44
    block_r > 1 rows still took the 2D-block path, and in the final tables only 3 of 76 rows use the kW strip,
    so the switch rolled back almost nothing. The kH x kW gate now requires it too: 0 runs one A tile per tap on
    every row. With 1 (the default) nothing changes.
  • op_test keyword cases, block_rows=8 forced on 256x96/4x1:
    • 2d_block_rows8_nhwc, 3d_block_rows8_ndhwc: NHWC / NDHWC in and out, with H and W tails;
    • 2d_block_rows8_dil_w2: W dilation 2;
    • 2d_block_rows8_gated_s2: stride 2, which the plan must decline (default path).
  • test_block_rows_static: the 2D path with AITER_CONV3D_DYN_HW off for the call (static extents),
    which otherwise only runs when the whole process sets it.

8. Trim the reuse plumbing, no behavior change (972999632)

  • make_im2col_plan checks the layer conditions both reuse paths share once.
  • Im2colPlan.out_block is set only when kH x kW reuse applies, so the grid_out_block() filter is gone and
    callers pass plan.out_block.
  • The tuner caches (block_rows, plan) per tile instead of re-deriving the same plans three times.
  • N_CC is computed once; the forced op_test cases share their keyword dicts.

Files: aiter/aot/flydsl/conv.py, conv3d_gfx950_utils.py, conv3d_im2col.py, conv3d_implicit_gfx950.py,
conv3d_policy.py, conv_kernels.py, csrc/flydsl_conv3d/conv3d_tune.py,
op_tests/test_flydsl_conv_implicit.py, and the two model_configs/*_tuned_conv3d.csv (10 files,
+1123 / -153).

Results

Setup

  • gfx950 (MI355X, 256 CU).
  • One GPU confirmed idle (0% use, driver-baseline VRAM).
  • main @ 89a47b84a vs this branch, both on their own production path: own tuned table, own defaults.
  • Runs alternate between the trees, each run in its own process.

Hot layers, kernel only

  • Each tree's tuned tile (branch: block_r from its table).
  • Median of 3 alternating rounds.
  • Sustained = 8 s back to back; both sides at the 1000 W cap.
layer metric main branch speedup
Wan2.1 down_0_1 @480x832 burst 1039.5 us 704.2 us 1.48x
(main 192x96/3x1, branch 256x96/4x1 r4) sustained 1183.6 us 824.9 us 1.43x
production entry, NDHWC 1052.6 us 732.6 us 1.44x
Qwen-Image res_96_L0 @1328^2 burst 469.6 us 348.6 us 1.35x
(main 192x96/3x1, branch 256x96/4x1 r8) sustained 514.6 us 383.1 us 1.34x
production entry, NDHWC 444.9 us 336.5 us 1.32x

Under sustained load the branch runs at a lower sclk (about 1.43-1.49 vs 1.55-1.57 GHz) but does more per
cycle.

What the 2D block adds on top of kW reuse, same tile 256x96/4x1, kernel only, sustained:

layer R kW reuse kH x kW reuse speedup
down_0_1 @480x832 4 907.9 us 824.5 us 1.10x
down_0_1 @368x544 8 466.2 us 419.8 us 1.11x
res_96_L0 @1024^2 4 238.0 us 223.7 us 1.06x
res_96_L0 @1328^2 4 396.9 us 382.4 us 1.04x

PMC on down_0_1 @480x832:

main 192x96/3x1 kW reuse 256x96/4x1 kH x kW reuse 256x96/4x1 r4
L2 requests x 64 B 11.21 GB 6.53 GB 5.11 GB
L2 hit rate 85% 90% 83%

Why the hit rate drops with 2D blocks: a block's LDS patch is larger than its output block by the halo it shares
with its neighbours (10x34 vs 8x32 at R=8, +33%). Under kW reuse that overlap was re-read from L2 as hits; with
2D blocks it is mostly missed, so reads past L2 grow (TCC_EA0_RDREQ, a relative measure: +44% on down_0_1,
+28% on res_96_L0 @1328^2). It does not cost time: a column-strip block order (4 blocks wide) recovered about
half of those misses but left sustained time unchanged on down_0_1 and res_96_L0 (within 0.4%), so the row
order is kept.

All tuned shapes (conv3d_tune.py --run_config)

  • Each side runs its own tuned table: main 89a47b84a vs branch 96a94eb41 (7270f3c0f does not change
    generated code).
  • Times are end-to-end through the production entry, NDHWC in and out (weight repack included), best of 3,
    mean of 3 rotating rounds.
  • Every row of both tuned CSVs is listed, split by model and resolution. Speedups >= 1.1x are in bold; branch
    tiles carry rR when block_r > 1.
model @ resolution shapes sum main -> branch sum speedup geomean min / max
Qwen-Image VAE @1024x1024 16 2391.5 -> 1813.3 us 1.319x 1.235x 1.001x / 1.579x
Qwen-Image VAE @1328x1328 16 3978.5 -> 3002.7 us 1.325x 1.228x 0.921x / 1.830x
Wan2.1 VAE @368x544 22 3560.4 -> 2641.3 us 1.348x 1.204x 0.974x / 1.925x
Wan2.1 VAE @480x832 22 6399.6 -> 4683.4 us 1.366x 1.215x 0.987x / 2.040x
speedup shapes
< 0.97x 1
0.97-1.03x 21
1.03-1.1x 7
1.1-1.2x 7
1.2-1.3x 10
> 1.3x 30

Against the kW-reuse tables of a664ea487 (same run), i.e. what the 2D blocks and the retune add:

model @ resolution shapes sum a664 -> branch sum speedup geomean min / max
Qwen-Image VAE @1024x1024 16 2009.0 -> 1813.3 us 1.108x 1.076x 0.994x / 1.215x
Qwen-Image VAE @1328x1328 16 3275.3 -> 3002.7 us 1.091x 1.063x 0.997x / 1.192x
Wan2.1 VAE @368x544 22 2956.7 -> 2641.3 us 1.119x 1.074x 0.997x / 1.223x
Wan2.1 VAE @480x832 22 5273.9 -> 4683.4 us 1.126x 1.082x 0.987x / 1.226x
  • No shape below 0.97x; 33/76 within 0.97-1.03x, 33/76 at >= 1.1x.

Qwen-Image VAE @1024x1024 (16 shapes)

input (N x C x D x H x W) K filter stride main tile branch tile main us branch us speedup
1x3x1x1024x1024 96 1x3x3 1 64x96/1x2 g1 192x96/4x1 g1 91.6 90.6 1.011x
1x96x1x1024x1024 96 1x3x3 1 192x96/3x1 g1 256x96/4x1 g1 r8 259.0 181.8 1.425x
1x96x1x1025x1025 96 1x3x3 2 128x96/2x1 g1 128x96/2x2 g1 95.5 94.8 1.008x
1x96x1x512x512 192 1x3x3 1 128x192/2x2 g1 256x96/4x1 g1 r8 121.8 94.9 1.283x
1x192x1x512x512 192 1x3x3 1 128x192/2x2 g1 256x96/4x1 g8 r4 199.7 154.5 1.293x
1x192x1x513x513 192 1x3x3 2 128x192/2x2 g1 128x192/2x2 g1 66.7 66.7 1.001x
1x192x1x256x256 384 1x3x3 1 128x192/4x1 g1 256x96/4x1 g8 r8 106.6 84.7 1.258x
1x384x1x256x256 384 1x3x3 1 128x128/2x2 g8 256x96/2x2 g8 r4 187.9 144.5 1.301x
1x384x1x257x257 384 1x3x3 2 128x128/2x2 g1 128x128/2x4 g8 68.3 68.0 1.004x
1x384x1x128x128 384 1x3x3 1 128x128/2x2 g8 256x64/4x1 g1 r4 65.8 58.9 1.117x
1x384x1x128x128 32 1x3x3 1 32x32/1x2 g1 64x32/2x1 g1 30.8 23.7 1.299x
1x16x1x128x128 384 1x3x3 1 128x128/2x4 g1 128x96/4x1 g1 15.9 14.6 1.086x
1x384x1x256x256 192 1x3x3 1 128x192/4x1 g1 256x96/2x2 g1 r8 108.5 78.3 1.385x
1x384x1x512x512 192 1x3x3 1 128x192/2x2 g1 256x96/2x2 g1 r4 417.7 289.0 1.445x
1x192x1x1024x1024 96 1x3x3 1 128x128/2x2 g1 256x96/4x1 g1 r8 411.5 276.9 1.486x
1x96x1x1024x1024 3 1x3x3 1 128x32/2x1 g1 256x32/2x1 g1 r8 144.3 91.4 1.579x
sum 2391.5 1813.3 1.319x

Qwen-Image VAE @1328x1328 (16 shapes)

input (N x C x D x H x W) K filter stride main tile branch tile main us branch us speedup
1x3x1x1328x1328 96 1x3x3 1 192x96/3x2 g1 192x96/4x1 g1 139.1 137.8 1.010x
1x96x1x1328x1328 96 1x3x3 1 192x96/3x1 g1 256x96/4x1 g1 r8 442.1 322.4 1.371x
1x96x1x1329x1329 96 1x3x3 2 192x128/2x2 g1 192x96/2x2 g1 152.6 147.8 1.033x
1x96x1x664x664 192 1x3x3 1 128x192/2x2 g1 384x64/4x1 g8 r12 190.7 147.6 1.292x
1x192x1x664x664 192 1x3x3 1 128x192/2x2 g1 384x64/4x1 g8 r12 341.8 256.7 1.331x
1x192x1x665x665 192 1x3x3 2 128x192/2x2 g1 128x192/2x2 g1 117.1 116.3 1.007x
1x192x1x332x332 384 1x3x3 1 128x128/4x2 g8 384x64/4x1 g8 r12 173.9 143.5 1.212x
1x384x1x332x332 384 1x3x3 1 192x128/2x2 g8 256x128/2x2 g8 r8 321.7 252.3 1.275x
1x384x1x333x333 384 1x3x3 2 192x128/4x1 g1 192x128/2x2 g1 95.2 103.4 0.921x
1x384x1x166x166 384 1x3x3 1 192x128/1x4 g1 256x96/2x2 g1 r8 91.6 77.7 1.179x
1x384x1x166x166 32 1x3x3 1 32x32/1x2 g4 64x32/2x1 g1 32.9 27.9 1.181x
1x16x1x166x166 384 1x3x3 1 128x192/2x2 g4 128x192/2x2 g1 19.0 18.3 1.040x
1x384x1x332x332 192 1x3x3 1 128x192/4x1 g1 256x96/2x2 g8 r8 185.6 136.8 1.356x
1x384x1x664x664 192 1x3x3 1 128x192/2x2 g1 384x64/4x1 g4 r12 713.1 500.5 1.425x
1x192x1x1328x1328 96 1x3x3 1 96x96/2x3 g1 256x96/2x2 g1 r8 699.1 470.0 1.487x
1x96x1x1328x1328 3 1x3x3 1 192x48/3x1 g1 256x32/2x1 g1 r8 263.1 143.7 1.830x
sum 3978.5 3002.7 1.325x

Wan2.1 VAE @368x544 (22 shapes)

input (N x C x D x H x W) K filter stride main tile branch tile main us branch us speedup
1x3x6x370x546 96 3x3x3 1 192x128/4x1 g1 192x96/4x1 g1 114.5 106.9 1.071x
1x96x6x370x546 96 3x3x3 1 192x96/3x1 g1 256x96/4x1 g1 r8 514.1 356.5 1.442x
1x96x1x369x545 96 1x3x3 2 128x96/2x1 g1 128x96/2x2 g1 29.1 28.9 1.005x
4x96x1x369x545 96 1x3x3 2 128x96/2x1 g1 128x96/2x2 g1 84.3 83.6 1.008x
1x96x6x186x274 192 3x3x3 1 128x192/2x2 g1 384x64/4x1 g8 r12 246.3 177.9 1.385x
1x192x6x186x274 192 3x3x3 1 128x192/2x2 g1 384x64/4x1 g8 r12 464.8 345.8 1.344x
1x192x1x185x273 192 1x3x3 2 64x64/2x2 g1 64x64/2x2 g4 28.6 29.1 0.983x
4x192x1x185x273 192 1x3x3 2 128x192/2x2 g1 128x192/2x2 g1 61.7 62.4 0.990x
1x192x4x94x138 384 3x3x3 1 192x128/4x1 g4 256x96/2x2 g8 r8 129.1 106.8 1.209x
1x384x4x94x138 384 3x3x3 1 192x128/4x1 g8 256x96/2x2 g8 r8 243.5 194.4 1.252x
1x384x1x93x137 384 1x3x3 2 32x32/1x2 g1 32x32/1x2 g8 39.9 39.4 1.013x
2x384x1x93x137 384 1x3x3 2 64x64/2x2 g1 64x64/2x2 g8 48.5 48.4 1.002x
1x384x3x48x70 384 3x3x3 1 32x32/1x2 g1 32x32/1x2 g8 92.0 94.5 0.974x
1x384x3x48x70 32 3x3x3 1 32x32/1x2 g1 64x32/2x1 g1 83.0 57.8 1.435x
1x16x3x48x70 384 3x3x3 1 32x32/1x2 g8 32x32/1x2 g1 13.2 13.2 1.002x
1x384x1x92x136 192 1x3x3 1 64x64/2x2 g8 64x64/2x2 g4 42.4 41.9 1.012x
2x384x1x92x136 192 1x3x3 1 192x64/4x1 g8 256x48/4x1 g8 r8 62.3 53.5 1.163x
1x384x1x184x272 192 1x3x3 1 128x192/1x4 g1 256x96/2x2 g4 r8 99.6 75.3 1.323x
4x384x1x184x272 192 1x3x3 1 96x96/3x2 g8 384x64/4x1 g8 r12 353.9 233.0 1.519x
1x192x1x368x544 96 1x3x3 1 96x96/2x3 g1 256x96/2x2 g1 r8 110.4 80.2 1.376x
4x192x1x368x544 96 1x3x3 1 96x96/2x3 g1 256x96/4x1 g1 r8 384.4 248.1 1.549x
1x96x6x370x546 3 3x3x3 1 64x32/1x2 g1 256x32/2x1 g1 r8 314.9 163.5 1.925x
sum 3560.4 2641.3 1.348x

Wan2.1 VAE @480x832 (22 shapes)

input (N x C x D x H x W) K filter stride main tile branch tile main us branch us speedup
1x3x6x482x834 96 3x3x3 1 192x96/3x1 g1 192x96/4x1 g1 182.5 173.9 1.049x
1x96x6x482x834 96 3x3x3 1 192x96/3x1 g1 256x96/4x1 g1 r4 996.2 692.6 1.438x
1x96x1x481x833 96 1x3x3 2 128x96/1x2 g1 128x96/2x2 g1 47.8 45.6 1.048x
4x96x1x481x833 96 1x3x3 2 192x128/2x2 g1 192x96/4x1 g1 145.7 141.9 1.027x
1x96x6x242x418 192 3x3x3 1 128x192/2x2 g1 384x64/4x1 g8 r12 467.3 331.2 1.411x
1x192x6x242x418 192 3x3x3 1 128x192/2x2 g1 384x64/4x1 g4 r12 900.2 656.4 1.371x
1x192x1x241x417 192 1x3x3 2 96x96/2x1 g8 96x96/1x2 g1 39.6 39.1 1.011x
4x192x1x241x417 192 1x3x3 2 128x192/2x2 g1 128x192/2x2 g1 115.2 115.7 0.996x
1x192x4x122x210 384 3x3x3 1 128x128/2x4 g8 256x96/2x2 g1 r8 225.8 192.4 1.174x
1x384x4x122x210 384 3x3x3 1 128x128/4x2 g8 256x96/2x2 g4 r8 458.9 361.8 1.268x
1x384x1x121x209 384 1x3x3 2 64x64/2x2 g1 64x64/2x2 g8 48.6 47.8 1.017x
2x384x1x121x209 384 1x3x3 2 128x128/2x1 g8 96x128/3x1 g4 68.6 64.3 1.067x
1x384x3x62x106 384 3x3x3 1 64x64/2x2 g1 64x64/2x2 g8 114.9 116.4 0.987x
1x384x3x62x106 32 3x3x3 1 32x32/1x2 g4 64x48/4x1 g1 r2 84.8 71.4 1.188x
1x16x3x62x106 384 3x3x3 1 64x64/2x2 g8 64x64/2x2 g1 15.1 15.2 0.991x
1x384x1x120x208 192 1x3x3 1 96x96/2x1 g8 192x64/4x1 g4 r6 59.3 53.7 1.105x
2x384x1x120x208 192 1x3x3 1 128x192/1x4 g1 256x96/2x2 g4 r8 99.0 75.3 1.315x
1x384x1x240x416 192 1x3x3 1 128x192/4x1 g1 256x96/2x2 g8 r8 178.5 131.3 1.360x
4x384x1x240x416 192 1x3x3 1 128x192/2x2 g1 384x64/4x1 g1 r12 645.7 446.4 1.446x
1x192x1x480x832 96 1x3x3 1 96x96/3x2 g1 256x96/4x1 g1 r4 193.2 138.9 1.391x
4x192x1x480x832 96 1x3x3 1 96x96/2x3 g1 256x96/4x1 g1 r8 729.6 486.1 1.501x
1x96x6x482x834 3 3x3x3 1 96x32/1x2 g1 256x32/2x1 g1 r8 583.0 285.8 2.040x
sum 6399.6 4683.4 1.366x

Testing

  • op_tests/test_flydsl_conv_implicit.py (full), at eacb9b1c0 with the final tables: 111 rows, 0 mismatches,
    exit 0. Includes the new 2d_tile_256x96 case.
  • op_tests/tuning_tests/test_config_shape_collision.py: 20 passed.
  • 16 targeted kW-reuse cases vs fp32 F.conv3d (rtol = atol = 2e-2), each run with kW reuse on and off: 0
    mismatches. They cover:
    • row-wrapping blocks, padding, W dilation;
    • M tails with N > 1, 2D;
    • NCDHW / NDHWC output, dyn_hw on / off, Wo = tile_m +- 1;
    • gated-off tiles;
    • partial-B tiles 256x96/4x1 (3D and padded 2D) and 192x128/3x1 with an N tail.
  • 14 targeted 2D-block cases through flydsl_conv_implicit(block_rows=) vs fp32 F.conv3d: 0 mismatches.
    They cover H and W tails (dyn_hw on / off), NCDHW output with Wo % 4 0 and odd, 2D / 3D padding, W
    dilation, an N tail, R = 8 with 32 columns, a 1x1x3 filter, and the gate turning it off (occupancy,
    stride 2, 8-column blocks).
  • AOT: python -m aiter.aot.flydsl.conv into an empty cache (139 jobs, 0 failed), then both tables through
    --run_config with FLYDSL_RUNTIME_RUN_ONLY=1: 76/76 rows OK, no JIT.
  • XCD numbering checked on the flat, multi-N-tile and WGM-swizzle branches via the above plus op_test's g4 /
    g8 rows.
  • ISA spot checks: down_0_1 256x96/4x1 VGPR 228 (kW reuse) / 196 (R=4), 192x128/1x4 back to 256
    VGPRs; no scratch.
  • 372e6699b: host-side only so far. Recomputing make_im2col_plan for all 76 tuned rows gives 44 on the
    2D path with the switch at 1 (unchanged) and 0 with it at 0 (largest footprint 112 KiB); the four new cases
    plan to the paths named in change 7. The new cases still need a gfx950 run (CI MI35X shard 7).
  • 972999632, against 372e6699b, with AITER_CONV3D_KW_REUSE at 1 and 0: identical plan, launch grid,
    scatter plan and LDS bytes for all 76 tuned rows (both output layouts, block_rows 1/4/8/12) and the
    tile-forcing op_test cases; identical tuner candidates for the 76 shapes; identical AOT job lists, and
    host-side compile_conv3d_implicit passes for their 136 conv jobs.
  • black / ruff clean on all changed Python files.

Notes for reviewers

  • Compile key changed: AITER_CONV3D_KW_REUSE defaults to 1 and block_rows is a new compile-key field,
    so build-time AOT artifacts have to be regenerated. A mismatch is not wrong, it just JITs on first call.
  • Turning reuse off: AITER_CONV3D_KW_REUSE=0 turns off both reuse paths, the kW strip and the kH x kW
    blocks. It is a temporary rollback switch while they are validated. The tables assume it on: tiles such as
    256x96 and 384x64 then hold one block per CU (89 / 112 KiB) and are slower than main's picks. The XCD
    numbering and the partial B round are not behind it; neither changes results.
  • Known regression: Qwen-Image enc_down_384 @1328^2 (C384 333x333 s2, K=384), 0.92x (95.5 -> 103.5 us).
    It comes from the multi-N-tile block order of change 3, not from the stride:
    • With 3 N tiles, decoding N-fastest runs an M tile's 3 N tiles back to back on one XCD (shared A), so each
      L2 holds all 3 weight slices (~2.6 MB here) at once.
    • main's round-robin order shares A across N tiles only by accident (grid_m = 144, a multiple of 8) and
      keeps one weight slice per L2 at a time; for this weight-heavy layer that wins by 8% at the same tile.
    • Dropping the XCD numbering for stride-2 layers does not help: across all 18 stride-2 rows it is never
      faster (all within +-0.6%), it is slower on 9 of them, and it makes this row 14% slower (103.5 -> 117.6 us),
      because the N-fastest decode then spreads an M tile over three L2s.
    • Recovering the 8 us needs a per-layer choice of block order; not done here.
  • Tuner default unchanged: the retune used --max_configs 160; the default stays 96. Re-tuning with the
    default would see a different candidate set (see change 5).
  • Tuner timeout: with the block_r sweep the large 3x3x3 layers have 430-490 candidates. In the full Wan2.1
    run three of them (480x832, K >= 5184) passed the default --timeout 1800; retuned on their own with
    --timeout 7200 they took 375 / 1471 / 447 s. Use --timeout 3600 or more for a full retune.
  • Tuner timing: the tuner's run_perftest timing sits between burst and sustained, and under the power cap
    the two can rank tiles differently. The tables were picked on the tuner's measure.

Follow-ups

  • Tuner candidate ranking and cap, so the default 96 does not push small tiles out.

Checked and dropped:

  • An XCD-numbering gate for stride-2 layers: see the known regression above.
  • Staging the NDHWC epilogue through LDS for 16 B stores. A prototype on the 2D-block path cut L2 requests by
    the expected 0.31 GB on down_0_1 (misses unchanged: the half-filled writes were L2 hits) but ran 0.7-1.3%
    slower under sustained load on down_0_1 and res_96_L0.

The implicit-GEMM conv3d reloads the same input pixels from L2 once per
filter tap; on the hot VAE layers L2 was ~97% busy and the kernel time
tracked L2 traffic / L2 rate.

Add an opt-in A path (AITER_CONV3D_KW_REUSE=1): for each (kt, kh,
32-channel block) the block DMAs one strip of tile_m + 2*halo input
pixels into LDS, and the KW taps read it back at a row shift of kw*dw.
Rows that wrap to the next output row get a per-lane segment offset, so
MFMA A fragments are read at per-lane LDS addresses. Groups are double
buffered with one barrier per group; the weight packing and the epilogue
are unchanged.

make_im2col_plan enables it only for stride-1 W, KW > 1, C/groups % 32
== 0, zeros padding, groups == 1, no split-K, no BIG_IN, Wo >= tile_m,
and only when its LDS footprint keeps as many blocks resident per CU as
the default path (128x192 would go 80 KB -> 96 KB, 2 -> 1 block/CU).

gfx950, kernel-only, tuned tile 192x96/3x1:
  down_0_1 @480x832   1179 -> 1021 us (1.155x)
  res_96_L0 @1328^2    511 ->  445 us (1.148x)
  L2 requests x 64B   -30 to -32%; DMA 486 -> 297, barriers 41 -> 27.
op_tests/test_flydsl_conv_implicit.py: 0 mismatches on every shape;
per-pass Wan2.1 encode 1.05-1.06x, decode 1.08x, Qwen-Image 1.04-1.05x.

Co-authored-by: Cursor <[email protected]>
@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: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 6421 --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.

huizzhan and others added 5 commits October 13, 2026 11:14
…with kW reuse on

Three changes that cut L2 traffic without lowering blocks per CU, plus the
retune that lets the tables use them.

- Partial last B DMA round. validate_launch_config only needs B's last round
  to end on a wave boundary; the waves past its end still issue the DMA, with
  the OOB sentinel and a 1 KiB LDS park as destination, so there is no branch.
  This makes e.g. 256x96/4x1 legal: 4 waves of 64x96 each, 77 KiB with kW
  reuse, two blocks (8 waves) per CU, and a quarter less weight traffic than
  192x96.
- XCD-contiguous block numbering. gfx950 deals workgroups round-robin over 8
  XCDs; block_coords renumbers them so each XCD runs a contiguous M range
  (N fastest when the grid has several N tiles, so an M tile's N tiles share
  A in one L2). Coordinates stay Int32: Int64 cost 192x128/1x4 four VGPRs and
  half its waves.
- AITER_CONV3D_KW_REUSE defaults to 1, and the tuner prunes candidates by the
  LDS the runtime will actually allocate (plan_lds_bytes, via a new
  lds_bytes_fn hook in conv3d_policy) instead of the default-path formula.
- Both VAE tables retuned with --max_configs 160 (the newly legal tiles would
  otherwise push smaller incumbents out of the 96 cut): 72 of 76 rows change
  tile, tuner time 1.21x on both tables.

down_0_1 (Wan2.1, 480x832), kernel-only, sustained load, gfx950:
  192x96 kW reuse              1018 us
  + XCD-contiguous              963 us
  256x96/4x1 kW reuse           973 us
  256x96/4x1 + XCD              911 us  (L2 requests 7.57 -> 6.53 GB,
                                         L2-miss reads 1.46 -> 0.49 GB)

op_test per-pass totals vs the previous commit (kW reuse on), same day:
  Wan2.1 encode 1.099-1.104x, decode-only shapes 1.156-1.167x,
  Qwen-Image 1.078-1.093x; Wan resamplers 368x544 0.986x. All 0 mismatches.

Adds op_test keyword case 2d_tile_256x96 (partial B round on the reuse path).

Co-authored-by: Cursor <[email protected]>
…une)

Fresh run of the same retune as the previous commit (branch code, kW reuse on,
--max_configs 160), on an idle gfx950. It reproduces that table: the sum of
tuner times is within 0.2% (Qwen-Image 5258 -> 5269 us, Wan2.1 8194 -> 8182
us). The 24 rows whose tile changed differ by at most 3% from the previous
pick (mostly WGM or wave layout), i.e. near-ties; res_96_L0 @1328^2 moves from
256x96/2x2 to 256x96/4x1 (kernel-only sustained 404 -> 396 us).

Against main 89a47b8, same idle GPU, same day:
  tuner --run_config, all 76 tuned shapes: sum 1.204x (Qwen-Image) / 1.214x
  (Wan2.1), 75/76 >= 0.97x.
  op_test per-pass totals: Wan2.1 encode 1.15-1.18x, decode-only shapes
  1.25-1.26x, Qwen-Image 1.14-1.15x. 0 mismatches.

Co-authored-by: Cursor <[email protected]>
A block can own an R x C patch of output pixels in one (n, t) plane instead
of TILE_M consecutive ones (R * C == TILE_M). Per (kt, 32-channel block) it
DMAs one LDS patch of (R + (kH-1)dh) x (C + (kW-1)dw) input pixels, and all
kH*kW taps read it at a constant offset through the per-lane A read. B uses
the default path's 4-stage ring (two taps per barrier); the patch is double
buffered per group and its DMA rounds are spread over the batches it may be
issued in (all at once was ~3% slower).

- Conv3dImplicitParam.block_rows (compile key). make_im2col_plan decides:
  unit H/W stride, kH or kW > 1, C % 16, C/groups % 32, zeros padding,
  groups 1, no split-K, no BIG_IN/BIG_OUT, and blocks per CU no lower than on
  the path the layer would otherwise take (kW reuse where it applies).
- Grid: N * Do * ceil(Ho/R) * ceil(Wo/C) M tiles; H/W tails are masked in the
  epilogue (OutputScatter.store row_of / row_ok). dyn_hw supported (Ho from
  hw_o / wo). NCDHW vector store kept only when Wo % 4 == 0.
- Host: optional tuned-CSV column block_r (missing/empty/Null = 1), carried by
  the lookup, borrow, AOT and the tuner, which sweeps
  block_rows = TILE_M / C for C in (32, 64, 128); flydsl_conv_implicit
  takes block_rows= to force it.
- op_test keyword case 2d_block_rows4 (H and W tails).

Tables are not retuned in this commit, so production picks are unchanged
until a table carries block_r.

gfx950, 256x96/4x1, kernel only, sustained, vs kW reuse at the same tile:
  down_0_1 @480x832  R=4  907.9 -> 824.5 us (1.10x)
  down_0_1 @368x544  R=8  466.2 -> 419.8 us (1.11x)
  res_96_L0 @1024^2  R=4  238.0 -> 223.7 us (1.06x)
  res_96_L0 @1328^2  R=4  396.9 -> 382.4 us (1.04x)
down_0_1 PMC: L2 requests 6.53 -> 5.11 GB, DMA 297 -> 225, barriers
27 -> 41, VGPR 228 -> 196.

Co-authored-by: Cursor <[email protected]>
Both VAE tables retuned on this branch with kW reuse on and the block_rows
sweep (--max_configs 160). 44 of 76 rows now pick block_r > 1
(Qwen-Image 20/32, Wan2.1 22/44).

The three Wan2.1 3x3x3 rows at 480x832 with K >= 5184 (C192 242x418,
C384 122x210, C384 62x106) timed out under the default --timeout 1800 in the
full run and were retuned on their own with --timeout 7200 (375 / 1471 /
447 s, 0 failures).

gfx950, conv3d_tune.py --run_config, each tree on its own table, mean of 3
rotating rounds, all 76 shapes OK:
  vs a664ea4: Qwen-Image sum 5284.3 -> 4816.0 us (1.097x),
                Wan2.1     sum 8230.6 -> 7324.7 us (1.124x),
                min 0.987x, no shape below 0.97x
  vs 89a47b8: Qwen-Image sum 6370.0 -> 4816.0 us (1.323x),
                Wan2.1     sum 9960.0 -> 7324.7 us (1.360x),
                only enc_down_384 @1328^2 (stride 2) below 0.97x (0.921x,
                same as on a664ea4)

Co-authored-by: Cursor <[email protected]>
_body_kw_reuse and _body_kh_reuse read geom.cgp, which put the whole
ConvGeometry (do/ho/wo/npq) into the closure FlyDSL hashes for the launch's
manager_key. Under dyn_hw that made every resolution its own artifact, while
the AOT dedupe (one job per layer) compiled only one of them: with the
block_r tables, 4 of the 76 rows (two resolutions of one layer with the same
config) missed the AOT cache and JIT-compiled on first call. Use the
compile-scope CGP instead, as _body does.

Fresh-cache AOT (139 jobs) then conv3d_tune.py --run_config under
FLYDSL_RUNTIME_RUN_ONLY=1: 76/76 rows OK (was 72/76). op_test full 112 rows,
0 mismatches.

Co-authored-by: Cursor <[email protected]>
@huizzhan huizzhan changed the title [FlyDSL] conv3d: share one LDS strip across kW taps (kW reuse) [FlyDSL] conv3d: kW and kH x kW LDS reuse of the im2col input on gfx950 Oct 15, 2026
The 2D-block path stays covered by the VAE model shapes (44 tuned rows take
it, 22 of them with an H or W tail) and by the targeted block_rows cases run
for the PR; keep the op_test keyword surface to what it was.

Co-authored-by: Cursor <[email protected]>
@huizzhan
huizzhan marked this pull request as ready for review October 16, 2026 06:43
@huizzhan
huizzhan requested a review from a team October 16, 2026 06:43
@github-actions github-actions Bot changed the title [FlyDSL] conv3d: kW and kH x kW LDS reuse of the im2col input on gfx950 [HIP] [FlyDSL] conv3d: kW and kH x kW LDS reuse of the im2col input on gfx950 Oct 16, 2026
root and others added 3 commits October 19, 2026 08:32
…n it in op_test

AITER_CONV3D_KW_REUSE was the only switch the reuse work added, but
make_im2col_plan checked it for the kW strip only. With it at 0, all 44
tuned rows with block_r > 1 still took the 2D-block path, and in the final
tables only 3 of 76 rows use the kW strip at all, so the switch rolled back
almost nothing. kh_layer_ok now requires param.kw_reuse as well: 0 gives one
A tile per tap on every row (largest default-path footprint 112 KiB, inside
the 160 KiB per CU); 1 (the default) is unchanged. The switch is documented
as a temporary rollback while the reuse paths are validated.

op_test: the 2D-block path was only reached through tuned-table rows (NCDHW,
dyn_hw on). Add KW cases that force block_rows=8 on tile 256x96/4x1:
NHWC and NDHWC with H and W tails, W dilation 2, and a stride-2 shape the
plan must decline; plus test_block_rows_static, which runs the 2D path with
AITER_CONV3D_DYN_HW off for the call.

Co-authored-by: Cursor <[email protected]>
- make_im2col_plan: the layer conditions both reuse paths share (switch,
  scalar K, zeros padding, groups 1, no split-K) are checked once.
- Im2colPlan.out_block is set only when kh_reuse applies, so the
  grid_out_block() filter is gone and callers pass plan.out_block.
- compile_conv3d_implicit: N_CC computed once for both reuse bodies.
- conv3d_tune: block_rows_options caches (block_rows, plan) per tile, so
  lds_bytes_fn and the candidate filter stop re-deriving the same plans.
- op_test: the forced kH x kW cases share _KH8 and the layout dicts.

Checked host-side against the previous commit, with AITER_CONV3D_KW_REUSE
at 1 and 0: plan, launch grid, scatter plan and LDS bytes of all 76 tuned
rows (both output layouts, block_rows 1/4/8/12) and of the tile-forcing
op_test cases; every tuner candidate of the 76 shapes; the AOT job list of
both tables and host-side compile_conv3d_implicit of its 136 conv jobs.

Co-authored-by: Cursor <[email protected]>
@huizzhan
huizzhan merged commit 9e28845 into ROCm:main Oct 20, 2026
huizzhan added a commit that referenced this pull request Oct 20, 2026
Resolve conflicts with #6421 (gfx950 kW / kH x kW LDS reuse), which also
added a block_rows field to the conv3d tuned table:

- Use main's tuned-CSV column block_r (TUNED_BLOCK_ROWS_COLUMN,
  _parse_block_rows) for gfx1250 as well, drop TUNED_OPTIONAL_RESULT_COLUMNS,
  and rename the gfx1250 tuned CSV header from block_rows to block_r. With
  two column names the config merge zero-fills the other arch's column, and
  AOT parse_csv let block_r's default override the gfx1250 value.
- conv3d_tune.py: gfx950 keeps main's per-tile block_rows sweep; gfx1250
  keeps its policy, which already returns block_rows. Both use main's task
  tuple order and write block_r.
- _conv3d_impl takes both block_rows and patch_reuse; keep the new op test
  cases from both sides.

Co-authored-by: Cursor <[email protected]>
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.

2 participants