Skip to content

Model L: reverse workgroup order on five hybrid Swin kernels - #269

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/rv-hybrid-order
Nov 17, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/rv-hybrid-order

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Model L's hybrid route ran every kernel of its Swin chain with the workgroups in forward order. This change runs five of them in reverse order (WG_REV_ORDER=1, the mechanism the c32 encoder kernels already use), so that each consumer starts on the rows its producer wrote last, which are the likeliest to still be in the caches:

l_project_gather F → swin_block_c64_hyb R → patch_merge_c64_hyb F → swin_block_c96_hyb R → patch_merge_c96_hyb F → bottleneck (unchanged) → expand_c128_hyb R → swin_block_c96_add_hyb F → expand_c96_hyb R → swin_block_c64_add_hyb F → l_dec_project F → l_swin_block_c32_dec_coef12_hyb R

Each workgroup does the same work on the same data, so the output is the same bytes. The change touches only kernel declaration lines and comments:

  • clean/dx12/kernels/hyb_swin.hlsl (2 declarations)
  • clean/dx12/kernels/hyb_gemm.hlsl (2 declarations, plus a comment)
  • clean/dx12/kernels/l_swin.hlsl (1 declaration, plus a comment)

The comments note that WG_REV_ORDER reverses the group index of a 1-D dispatch only (a multi-dimensional launch must flatten it first), and that every kernel using it here is 1-D. wg_platform.hlsli itself is unchanged, because its text is part of Model K's softmax self-check digest. There is no runtime change, and the kernel names stay the same.

Why it is exact: for each of the five kernels, the input and output buffers are distinct (no in-place writes another workgroup could read), there are no atomics or cross-workgroup sums (the coherent cross-workgroup loads in swin_block.hlsl are compiled only into the bottleneck's persistent form), and the group index is read only through WG_SETUP. Every shipped shape stays far below 65,535 workgroups in one launch for these kernels: the largest grid is a block kernel at 4K Performance, at about 4,100 groups.

Measured with the direct-route benchmark (D3D12 timestamps, synthetic model and inputs, 1500 frames per run, 5 interleaved rounds, the same build with and without the change):

  • 1440p Quality: paired median -7.5 us per frame (4 of 5 rounds faster)
  • 1080p Quality: paired median -4.0 us per frame (5 of 5 rounds faster)

The stage split puts the gain in the Swin and decoder-block stages, the hand-offs that were reversed. Record: RV-HYB-RESULT.md.

Tested

  • Final-output hash after 1500 frames on every timing run, at 1440p Quality and 1080p Quality: equal to the unchanged build on all 20 runs.
  • Six different final frames per shape (600 to 605 frames): 12 of 12 identical.
  • Element-wise output comparison, 6 frames with moving motion, D3D12 executor on both sides, unchanged kernels against these kernels: 0 differing values in every frame at 1001x563 → 1501x845, 2293x960 → 3440x1440, 1920x1080 → 3840x2160 and 1707x960 → 2560x1440.
  • Negative control for that comparison: a deliberately wrong workgroup mapping differs in every frame.
  • DXIL identity: 145 of 150 kernels byte-identical to main; exactly the five reversed kernels differ. The comment leaves every kernel's DXIL unchanged (rebuilt and compared).
  • Two mutants, each caught by the hash check at both shapes: a wrong reversal (one workgroup's work done twice, one never) and a one-float32-ulp change at the decoder block's chain end.
  • The build's VGPR check (unchanged counts) and the hybrid ISA rules pass, and every hybrid kernel's rule mutant fails them as required.

Not tested

  • In-game runs.
  • The HIP twins of these kernels (developer builds only; this change is D3D12-only).

…me bytes)

Model L's hybrid route ran every Swin-chain kernel with its workgroups in
forward order. Five of them now run in reverse order (WG_REV_ORDER=1, the
same mechanism the c32 encoder kernels already use), so that along the
chain each consumer starts on the rows its producer wrote last:
l_project_gather F -> swin_block_c64_hyb R -> patch_merge_c64_hyb F ->
swin_block_c96_hyb R -> patch_merge_c96_hyb F -> bottleneck (unchanged) ->
expand_c128_hyb R -> swin_block_c96_add_hyb F -> expand_c96_hyb R ->
swin_block_c64_add_hyb F -> l_dec_project F ->
l_swin_block_c32_dec_coef12_hyb R.

Each workgroup does the same work on the same data: no in-place buffers,
no atomics, the group index only through WG_SETUP. Declarations only; the
other kernels' DXILs are unchanged.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Beside the hybrid L kernels that use it (l_swin.hlsl, hyb_gemm.hlsl): a
multi-dimensional launch must flatten its group index before the
reversal. Comments only; the kernels compile to the same DXIL.
wg_platform.hlsli itself stays unchanged, since its text is part of
Model K's softmax self-check digest.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 force-pushed the model-l/rv-hybrid-order branch from 3ae016b to 54c2951 Compare November 17, 2026 04:51
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 17, 2026 04:59
@phantoslayer21
phantoslayer21 merged commit f2982c8 into main Nov 17, 2026
10 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/rv-hybrid-order branch November 17, 2026 11:48
phantoslayer21 added a commit that referenced this pull request Nov 17, 2026
…s) into release-0.6.1

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant