Skip to content

Model L on D3D12: the decoder block with l_coef_pack12 as its epilogue - #159

Merged
phantoslayer21 merged 1 commit into
mainfrom
model-l/dec-coef-fold
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
model-l/dec-coef-fold

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Model L speed on D3D12, second change: the decoder block with l_coef_pack12 as its epilogue. The new D3D12-only
kernel l_swin_block_c32_dec_coef12_nc gives the same bytes in A, C and the latent as the pair
l_swin_block_c32_dec_nc -> l_coef_pack12. The block's FP16 map (y2, 64 bytes per pixel) is neither stored nor
read back. Nothing is approximated, and the pair stays as the fallback route.

What changes

  • clean/dx12/hlsl/l_coef_px.hlsli (new): l_coef's per-pixel functions, moved out of l_ops_coef.hlsl and shared
    with the block. The l_coef / l_coef_pack12 DXILs change from the move; they were checked again on the GPU (below).
  • clean/dx12/kernels/swin_block.hlsl, new SW_OUT_COEF12 mode for the C = 32 decoder block. The lane that holds a
    pixel's channels 0..15 (hh = 0; Model L's 13 values are all among them) runs the shared functions on the FP16
    values the map would hold, for the pixels inside the render rectangle.
  • clean/dx12/kernels/l_swin.hlsl: declares the kernel (co=-); VGPR bound 96, uses 95.
  • fused_swin_gen.py: its argument anchor takes the new lines, so the generated Model M kernels are unchanged (every
    DXIL but the two above is byte-identical to main's). It now writes LF on every OS (it wrote CRLF on Windows).
  • clean/runtime/runtime.cpp: new native D3D12 fusion lc, on by default, used by Model L's pack12 frames.
    • The pair runs (the fallback route) with WG_D3D12_FUSION without lc, or when the build's manifest lacks the
      kernel.
    • The kernel report adds l_dec_fold=on|off. compare.py's copy of the default fusion list is updated.
  • clean/l/runner/l_fold_check.py (new): the identity check below.
  • Tests: the recorder knows the kernel's 14 arguments. The Model L frame and role checks take either decoder form,
    and the D3D12 frame test runs the fold, the pair without lc and the pair without the kernel.

Refs #89

Byte identity (clean/l/runner/l_fold_check.py, one GPU slot; record records/fold-identity.json in the
rr-plugin build folder)

  • The same inputs run three ways: the folded kernel on D3D12, the pair on D3D12 (two kernel_replay passes: the
    block writes y2, then l_coef_pack12 reads it), and the pair on HIP.
  • Raw bytes; 64 bytes of slack after every output, filled with each run's own sentinel (HIP 0xA5, the D3D12 pair
    0x5A, the fold 0x3C).
  • Cases: 7 block grids (H x W from 4 x 8 to 96 x 160), both window offsets, render rectangles of the whole grid, odd sides short
    of it, and about half of it; 2 seeds.
  • 84 of 84 cases identical in all three comparisons (2,710,400 rectangle bytes), and every slack byte kept its own
    sentinel.
  • Negative control (the fold with half its workgroups, on a whole-grid case): caught, 16,136 bytes differ.
  • Model M's swin_block_c96_nc control through the same replay: 8 of 8.
  • l_coef / l_coef_pack12 after the move to the shared include: 12 of 12 each against HIP, negative control caught,
    M control 12 of 12 (clean/l/runner/l_d3d12_ops_check.py; record records/coef-include-identity.json).

Frame check (clean/l/runner/l_frame_check.py --compare-d3d12, synthetic models; record
records/fold-frame-check.json)

  • The default D3D12 run uses the fold (l_dec_fold=on); the all-outputs run (fusions off) uses the pair.
  • Model L: every stage against the reference 11 of 11 frames; the default kernels against the all-outputs run byte
    for byte 11 of 11; its post against Model M's post reference 11 of 11.
  • Model M: D3D12 against HIP 11 of 11. Pass.

Timing (l_d3d12_profile.py, 1080p Quality, synthetic models). Build A is main's build; build B is this change.
Interleaved, 3 rounds each, every run in its own GPU slot; medians; record records/fold-ab.json.

  • The pair: l_swin_block_c32_dec_nc 0.3092 + l_coef_pack12 0.1634 = 0.4726 ms. The fold: 0.3516 ms (-121 us).
  • Decoder step: A 0.661 / 0.663 / 0.663 ms, B 0.540 / 0.543 / 0.543 ms.
  • Whole-frame span: A 2.609 / 2.582 / 2.606 ms, B 2.484 / 2.485 / 2.492 ms.
  • The other kernels are within +-0.004 ms.

Tested

  • The identity check, the frame check and the timing above.
  • clean/l/runtime/tests/test_l_runtime_frame.py (18 tests); public gates.

Not tested

  • In a game (the next game timing run).
  • Real model weights: the arithmetic is the pair's, byte for byte.
  • The synthetic block outputs are not built to reach every branch of the per-pixel functions (the +-20 clamp, tanh's
    saturation). The shared functions' branches are covered by the l_coef_pack12 check, whose map inputs are built
    to reach them.

l_swin_block_c32_dec_coef12_nc (D3D12 only): the decoder block's lane that holds a
pixel's channels 0..15 runs l_coef_pack12's per-pixel functions on the FP16 values the
map would hold, so A, C and the latent come out of the block and y2 is neither stored
nor read back. Byte for byte the pair l_swin_block_c32_dec_nc -> l_coef_pack12.

- hlsl/l_coef_px.hlsli: l_coef's per-pixel functions, shared by l_ops_coef.hlsl and
  the block (swin_block.hlsl SW_OUT_COEF12); fused_swin_gen.py's anchor follows, and it
  writes LF on every OS.
- runtime: native D3D12 fusion "lc" (default on; Model L pack12 frames). Without lc,
  or without the kernel in the manifest, the pair runs (the fallback route).
- clean/l/runner/l_fold_check.py: the folded kernel against the pair on D3D12 and on
  HIP, raw bytes, per-run sentinels in the slack, negative control, Model M control.
- tests: the recorder's signature; the frame and role checks take either decoder form.

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 09:02
@phantoslayer21
phantoslayer21 merged commit 3ab1a6f into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/dec-coef-fold branch November 14, 2026 09:02
phantoslayer21 added a commit that referenced this pull request Nov 14, 2026
…he Model L set

l_linear_32_32_fused (#160) and l_swin_block_c32_dec_coef12_nc (#159) have no
HIP code object, so the co test alone put them in Model M's set. Model M's set
is unchanged (46); Model L's set is 16. kernel_sets.json regenerated; the
profile tool's docstring names --model-l.

Refs #89

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