Skip to content

Model L: D3D12 port of the reconstruction kernel l_post_recon, byte for byte against its HIP kernel - #136

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/l-post-recon-d3d12
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/l-post-recon-d3d12

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

D3D12 port of Model L's reconstruction kernel l_post_recon (l_post.co, HDR, from #128), byte for byte against the HIP kernel.

What

  • clean/dx12/kernels/l_post.hlsl (new): @wg-kernel l_post_recon co=l_post.co block=256 wave=32, the same arguments, buffers, layouts and grid as the HIP kernel. It follows the HIP ISA (llvm-objdump of l_post.co):

    • FP16 gather operations as v_mul_f16 / v_add_f16 / v_fma_f16, with an opaque cut after each FP16 product, because the driver fuses an FP16 multiply with the following add;
    • an opaque cut on each FP16 result before it is widened to FP32 (the exponent and the accumulators). Without the cut, the driver computed the last fma in FP32 (v_fma_mix_f32) and dropped the FP16 rounding. This was the one difference found: about 10 % of the bytes in the random cases;
    • RNE conversions (wg_f2h); one rounding for the kernel shape and the history texel (wg_mul_f16, as HIP's v_fma_mixlo_f16); IEEE divisions (wg_div).
    • Model M's kernels and files are untouched (new file only).
  • clean/l/runner/l_d3d12_ops_check.py: new l_post_recon cases:

    • l_post_check.py's random, reset and extreme kernel-shape cases;
    • the zero-weight known answer (offset_0.1: total weight 0 everywhere, spec part 3 Q1);
    • the FP16-underflow known answer (offset_0.05: total weight > 0, every FP16 weight 0, Q3);
    • R = D (footprint over the LDS cap: the unstaged path);
    • ratio 1.5 with the exposures read from the expo pointer (one exposure 0);
    • "specials": NaN, infinite and 60000 colours; NaN, infinite and negative history texels; motions far outside D.

    The harness change: bytes that no back end writes (the display rows' pitch padding, and 64 slack bytes after each buffer) must keep each back end's own sentinel. The other kernels' comparison is unchanged.

GPU record

l_d3d12_ops_check.py --run --seeds 6 --kernels l_post_recon, one GPU slot, on this branch's port and main's l_post.co.

cases identical bytes compared differing
l_post_recon 60 60 1,982,016 0
control: Model M swin_block_c96_nc 36 36 3,167,424 0
  • What is compared: the raw downloaded bytes of all three outputs (the full history including alpha, the display planes, the reduced codes).
    • 1,710,936 of the l_post_recon bytes are written bytes. The rest is padding and slack, and each back end kept its own sentinel there: 0 bad.
  • Sentinels: HIP 0xA5, D3D12 0x5A.
  • Per seed: 6 random, 1 extreme-C, 1 zero-weight, 1 FP16 underflow, 1 specials (the random ones include reset, R = D, and the expo pointer).
  • Negative control (case l_post_recon_s0_0 again on D3D12 with half its workgroups): caught, 8,498 differing bytes.
  • Model M DXILs unchanged:
    • this PR changes no existing D3D12 source (git diff --stat origin/main: the new l_post.hlsl and the Python harness only), and no file includes l_post.hlsl;
    • built from main (26eb21e) and from this branch with the same output names, SHA-256 identical for 10 of 10 kernels: w64/post_tf_f32_p12_diet_vsit, exposure_auto_diet, input_encoder, lev/input_encoder, swin_block_c96_nc, l_coef, l_coef_pack12, native_fill, color_divide, scale_rgb.
  • The record was run on the branch head before and after merging main (Model L: D3D12 ports of the encoder and decoder blocks, byte for byte against their HIP kernels #132, Model L: D3D12 port of the pack12 coefficient store (l_coef_pack12), byte for byte against its HIP kernel #134). Both runs: 60 / 60, 0 differing, the same negative control. l_post.hip and Model M's post.hip did not change in that merge.

Tested

  • GPU: the record above (HIP vs D3D12 on the same GPU, raw bytes).
  • Model M's DXILs, main vs this branch: 10 kernels built from both trees, identical (see the record).
  • CI: both required checks.
  • Public gates; leak scan 0 hits.

Not tested

  • A build of all of Model M's D3D12 kernels from both trees (only the 10 above; the rest is covered by the scope of the diff).
  • In a game: the D3D12 frame for Model L is param's lane. It reads pack12 coefficients; a pack12 form l_post_recon_p12 follows in its own PR.
  • Against the oracle directly: the HIP kernel's oracle check is Model L reconstruction kernel l_post_recon (HIP, HDR) and its GPU check #128's l_post_check.py. This PR proves D3D12 = HIP.
  • The LDR kernel (follows).

…or byte against its HIP kernel

clean/dx12/kernels/l_post.hlsl ports l_post_recon (l_post.co, HDR) following the HIP ISA: FP16 gather
ops with opaque cuts against the driver's FP16 fusion and FP32 widening, software RNE conversions,
single-rounding history texel, IEEE divisions. l_d3d12_ops_check.py gains the reconstruction cases
(zero-weight and FP16-underflow known answers, extreme kernel shapes, unstaged R = D, exposure pointer,
non-finite inputs) and checks that bytes no back end writes keep each back end's own sentinel.

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…d3d12

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>

# Conflicts:
#	clean/l/runner/l_d3d12_ops_check.py
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