Repository navigation
Model L D3D12: encoder block in reverse workgroup order (byte-identical, -13/-34 us at 1080p/1440p) - #168
Merged
Conversation
…_REV_ORDER; the same bytes) wg_platform.hlsli: a kernel declared with WG_REV_ORDER=1 has workgroup g do the work of workgroup G - 1 - g. The encoder block then reads first the rows of x2 the fused linears wrote last, and the rows of x3 it writes last are the ones l_project_gather reads first: both hand-offs hit the caches more often. Only l_swin_block_c32_enc_nc's DXIL changes; its outputs are byte-identical. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
force-pushed
the
model-l/pix-order
branch
from
November 14, 2026 13:37
77dd91b to
5d0897c
Compare
phantoslayer21
marked this pull request as ready for review
November 14, 2026 13:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #89
Model L's D3D12 encoder block
l_swin_block_c32_enc_ncnow runs its workgroups in reverse order. The bytes it writes are unchanged and so is the arithmetic: only the order in which the workgroups pick up their work changes.wg_platform.hlsli: a kernel declared withWG_REV_ORDER=1has workgroup g do the work of workgroup G - 1 - g, where G is the launch's whole grid, so split dispatches are covered. Without the define the code is exactly as before.l_swin.hlsl:WG_REV_ORDER=1onl_swin_block_c32_enc_nconly. That kernel is Model L-only; no Model M kernel changes.Cause (measured before the fix)
The 1440p superlinearity in
l_project_gathercomes from cache order at two hand-offs:The fused linears write x2 in forward order. The reversed block reads the last-written x2 rows first, and the x3 rows it writes last are the ones the gather reads first.
Order experiments (records
order-<variant>-<shape>-ab.json, 2 rounds each):The extra 1440p cost of
l_linear_32_32_fusedis not fixable by order. x2 is 107 MB at 1440p, more than the 64 MB last-level cache.Timing
Synthetic models; main (A) against this branch (B), interleaved; 3 rounds; each run in its own GPU slot. Values are medians in ms. Records:
encrev-1080p-quality-ab.jsonandencrev-1440p-quality-ab.json, each with its per-run records.l_swin_block_c32_enc_ncl_project_gatherSo the encoder step is 13 µs faster at 1080p and 34 µs faster at 1440p. All three 1440p rounds of B beat all three of A, in both the encoder step and the frame span.
Tested
build_dx12.py --model-lbuild, all 62 compared against main's build. Onlyl_swin_block_c32_enc_nc.dxildiffers, so every Model M DXIL is unchanged.l_d3d12_check.py --kernels l_swin_block_c32_enc_ncagainst HIP. 28/28 cases byte-identical, specials included.l_swin_block_c32_enc_nc_s0_0, caught (768 bytes differ, 768 sentinel bytes).swin_block_c96_nc: 16/16.encrev-identity.json.l_frame_check.py --run --backend d3d12 / d3d12-stages, then--compare-d3d12, both models, 11 frames, pass. Recordencrev-framecheck-raw-d3d12.json.encrev-frames-vs-main.json.test_kernel_sets.py.public_gates.pypasses; the LOOK lines are at baseline.Not tested