Skip to content

Model L D3D12: encoder block with the input linears as its prologue (byte-identical; enc0 -88/-141/-70 us) - #190

Merged
phantoslayer21 merged 1 commit into
mainfrom
model-l/enc-lin
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
model-l/enc-lin

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Refs #89

Model L's D3D12 encoder block now runs the two input linears as its prologue. The new kernel l_swin_block_c32_enc_lin_nc reads the FP8 q halo map and computes x2 in registers, so x2 (64 bytes per halo pixel) is never stored or read back and the linears launch goes. Its output is byte-identical to the sequence it replaces, l_linear_32_32_fused → l_swin_block_c32_enc_nc.

What changes

  • swin_block.hlsl: gather mode SW_SRC 3. Each window member is a pixel of the q halo map at the same position mode 1 reads from x2. The member's lane runs l_linear_32_32_fused's arithmetic on it, which is the same lane mapping (token t, channel half h). Every lane runs it, so control flow stays wave-uniform. The block then starts from those FP16 values exactly as mode 1 does. The pointer arguments linW1 and linW2 are added under SW_SRC == 3.
  • hlsl/l_lin_px.hlsli (new): the linears' helpers lin_blob, lin_acc and lin_pair. l_ops_linear.hlsl includes it in place of its own copies; the fused linears kernel keeps its inline sequence, and its DXIL is unchanged.
  • l_swin.hlsl: declares l_swin_block_c32_enc_lin_nc, D3D12 only, with the encoder block's defines plus SW_SRC=3 and WG_REV_ORDER=1.
    • Arguments: the block's (x = q), then enc0.Win1 and enc0.Win2.
    • 95 VGPRs against a bound of 96 (4 workgroups per CU), 0 spills, 16 KB LDS.
  • Runtime fusion le, on by default, after ll in the default list (pm,xe,mb,rv,xo,xd,lc,ll,le; compare.py mirrors it).
    • The input encoder writes q to l_narrow, then the fused block and the gather run.
    • Without le, or without the kernel in the build, the linears (fused under ll) and the plain block run.
  • Tests and docs:
    • runtime_frame_trace.cpp records the new kernel's argument kinds.
    • test_l_runtime_frame.py covers its arguments, roles and map chain, plus fallback subtests for each fusion setting and each kernel missing from the manifest.
    • Also updated: kernel_sets.json, vgpr_limits.json, FORMATS.md, and the regenerated fused_swin.hlsl (its argument anchor too).

Timing

Synthetic models; main (6622148) against the same build with this branch's runtime and kernel, interleaved, 5 rounds, each run in its own GPU slot. Values are medians in ms. Records: enclin-timing.json and its per-run records enclin-{m6622,elrt}-<shape>-r1..5.json.

shape enc0 main enc0 this PR difference frame span main frame span this PR difference
1080p Quality 0.5447 0.4571 −87.6 µs 2.3717 2.2708 −100.9 µs
1440p Quality 0.9885 0.8479 −140.6 µs 3.9984 3.8649 −133.5 µs
1440p Performance (1280x720 → 2560x1440) 0.5355 0.4653 −70.1 µs 2.8749 2.7911 −83.8 µs

Per kernel at 1080p Quality: the block goes from 0.260 to 0.296 ms, the linears (0.096 ms) are gone, and l_project_gather goes from 0.058 to 0.042 ms (x3 now stays in cache).

Tested

  • Kernel check: l_enclin_check.py --seeds 2 (new). Record enclin-identity.json.
    • 28/28 encoder block cases: grids with fewer windows than a workgroup's 8, both window offsets, three weight scales, special FP8 codes in q in every other case.
    • Byte-identical across the fused kernel, the D3D12 sequence and the HIP sequence (relu → f16 → block): raw bytes, per-run sentinels, 64 slack bytes kept.
    • Negative control (half grid): caught, 30976 bytes differ.
    • Model M control swin_block_c96_nc: 8/8.
  • Frame check: main's raw frame check, l_frame_check.py --run --backend d3d12 / d3d12-stages then --compare-d3d12, pass, with all negative controls caught. Record enclin-framecheck-raw-d3d12.json.
  • Frames against main: every recorded D3D12 array, both models, both configurations, 11 frames, compared byte for byte: 0 differing. Record enclin-frames-vs-main.json.
  • DXILs: full build_dx12.py --model-l build against main's (6622148). All 68 existing DXILs are unchanged, Model M's included; the only addition is the new kernel, and that DXIL is the one tested and timed.
  • Unit tests: test_l_runtime_frame.py (21 tests), test_kernel_sets.py, fused_swin_gen.py --check.
  • Gates: public_gates.py passes. The LOOK lines carry no hit in this branch's files.

Not tested

  • HIP: unchanged; this is a D3D12-only kernel and fusion.
  • Real models and real game frames.

…ologue (fusion le; the same bytes)

l_swin_block_c32_enc_lin_nc (swin_block.hlsl SW_SRC 3, declared in l_swin.hlsl): the encoder block reads the FP8 q
halo map and runs l_linear_32_32_fused's arithmetic on each member's pixel in registers (hlsl/l_lin_px.hlsli, shared
with that kernel), so x2 (64 bytes a halo pixel) is neither stored nor read back and one launch goes. 95 VGPRs (bound
96: 4 workgroups per CU). Runtime fusion le (on by default, over ll); without it, or without the kernel in the build,
the linears and the block run. l_enclin_check.py: the kernel against the sequence on D3D12 and on HIP, raw bytes,
sentinels, negative control, Model M control. Every existing DXIL unchanged.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 19:28
@phantoslayer21
phantoslayer21 merged commit 14358fd into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/enc-lin branch November 14, 2026 19:29
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