Skip to content

Model L on D3D12: the folded decoder block's epilogue on the driver's conversions - #163

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

phantoslayer21 merged 1 commit into
mainfrom
model-l/fold-cvt

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Model L speed on D3D12, fifth change: the folded decoder block's epilogue (l_swin_block_c32_dec_coef12_nc, #159)
uses the driver's FP16 conversion instead of the software forms. It stays byte for byte against main's kernel and
against the pair it replaces; nothing is approximated.

What changes

  • clean/dx12/kernels/swin_block.hlsl (SW_OUT_COEF12 with COEF_CVT_HW) and clean/dx12/hlsl/l_coef_px.hlsli
    (l_coef_vals_hw, l_coef_store12).
    • The 16 values per lane go to FP16 by v_cvt_f16_f32 (wg_to_f16_ags), as do the five RN16 of sigma (one
      conversion) and the three FP16 products (another). Before, these were wg_to_f16, wg_rn16 and the wg_f2h of
      wg_mul_f16. The products keep wg_mul_f16's round-to-odd FP32 value and its +0 rule.
    • wg_platform.hlsli documents the same bits for these conversions. They need wave-uniform control flow, so every
      lane computes the per-pixel values and only the stores stay per lane.
  • l_coef, l_coef_pack12 and l_swin_block_c32_dec_nc (the fallback route and HIP's twins) keep their code.
    • Their DXILs are byte-identical to main's.
    • So is every other kernel built from swin_block.hlsl and the regenerated fused_swin.hlsl: the 14 rebuilt,
      Model M's included.
  • clean/l/runner/l_fold_check.py: the cases cycle through four kinds:
    • the network's range;
    • large inputs (block outputs past the +-20 clamp and tanh's saturation);
    • special FP8 codes in y (NaN outputs);
    • extreme S, T (FP16 products from subnormal to infinite).
  • clean/l/runner/l_d3d12_profile.py: l_linear_32_32_fused (Model L on D3D12: the two input linears in one kernel #160) counted in the encoder step.

Refs #89

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

  • The same inputs run three ways: the folded kernel on D3D12, the pair l_swin_block_c32_dec_nc -> l_coef_pack12
    on D3D12, and the pair on HIP.
  • Raw bytes; per-run sentinels in 64 bytes of slack after every output (HIP 0xA5, the D3D12 pair 0x5A, the fold
    0x3C).
  • 84 of 84 cases identical in all three comparisons (2,710,400 rectangle bytes), and every slack byte kept its own
    sentinel.
    • The coefficient images hold 116,616 NaN, 15,157 infinite, 21,981 subnormal and 109,539 zero FP16 products.
    • The block outputs (y2) hold 1,740,924 values past +-20, 2,109,302 past tanh's saturation (9.01) and 1,340,416 NaN.
    • 494,223 latent codes are at +-1.
  • Negative control (half grid): caught, 16,384 bytes differ.
  • Model M's swin_block_c96_nc control: 8 of 8.

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

  • 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.
  • Against main's build, every recorded array of both models' D3D12 runs (default and all-outputs, 11 frames each) is
    byte-identical (record records/fold-cvt-frame-vs-main.json).

Timing (l_d3d12_profile.py, 1080p Quality, synthetic models). Build A is main's build; build B is main's with
this DXIL. Two sets of 3 interleaved rounds, every run in its own GPU slot; records records/foldcvt-ab.json and
records/foldcvt2-ab.json.

  • l_swin_block_c32_dec_coef12_nc: 0.3500 / 0.3526 -> 0.3111 / 0.3136 ms (medians of the two sets: -39 / -39 us).
    Every round: A 0.348 .. 0.354, B 0.309 .. 0.315 ms.
  • No other kernel moves by more than 0.002 ms.
  • Whole-frame span: A 2.134 / 2.143 / 2.156, 2.128 / 2.150 / 2.143 ms; B 2.119 / 2.117 / 2.130, 2.114 / 2.088 /
    2.209 ms.

Tested

  • The identity check, the frame check and the timing above; public gates.

Not tested

  • In a game (the next game timing run).
  • Real model weights: the arithmetic is unchanged, byte for byte, including the special values above.

… conversions

l_swin_block_c32_dec_coef12_nc's epilogue converted its 16 values per lane to FP16 and
rounded five sigmoids and three products to FP16 with the software forms (wg_to_f16,
wg_rn16, wg_mul_f16's wg_f2h). Now they are the driver's v_cvt_f16_f32 (the same bits;
the products keep wg_mul_f16's round-to-odd FP32 value). The conversions need
wave-uniform control flow, so every lane computes the per-pixel values and only the
stores stay per lane. l_coef / l_coef_pack12 and the unfolded block keep their code and
DXILs (byte-identical to main's), as does every other kernel built from these files.

- clean/l/runner/l_fold_check.py: the cases cycle through large inputs (past the +-20
  clamp and tanh's saturation), special FP8 codes (NaN) and extreme S, T (FP16 products
  from subnormal to infinite).
- clean/l/runner/l_d3d12_profile.py: l_linear_32_32_fused in the encoder step.

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 11:19
@phantoslayer21
phantoslayer21 merged commit 77b4c23 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/fold-cvt branch November 14, 2026 11:22
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