Skip to content

Model L: D3D12 ports of the input linears, byte for byte against their HIP kernels - #122

Merged
phantoslayer21 merged 5 commits into
mainfrom
model-l/l-linear-d3d12-pr
Nov 14, 2026
Merged

phantoslayer21 merged 5 commits into
mainfrom
model-l/l-linear-d3d12-pr

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Model L (#89): the D3D12 ports of Model L's two input linears, byte for byte against their HIP kernels:
l_linear_32_32_relu and l_linear_32_32_f16 of l_ops.co (clean/l/kernels/l_ops.hip).

Stacked on #117 (it uses kernel_replay and the shared harness rules from there); it targets main once #117
merges. Depends on #115 for the HIP kernels it is checked against (checked at #115's head 0ec574e). CI needs
neither: nothing here runs without a GPU.

  • clean/dx12/kernels/l_ops_linear.hlsl (new): both kernels from one source (LIN_RELU).
    • acc = b + W x: the bias tile vector is the accumulator start, then two FP8 WMMAs (K blocks of 16), then RN16;
    • relu: q8(max(0, acc)), FP8 out; f16: acc as FP16 (round to nearest even);
    • same lanes, blob and map layout as HIP (clean/l/FORMATS.md); every load before the first matrix instruction.
    • No branch around the matrix instructions. A lane past the end of the map (HIP: continue, no store) computes
      pixel npix - 1, since its input is clamped there as in HIP, and stores it to pixel npix - 1. Those are the same bytes
      that pixel's own lane stores. The first version guarded the store with if (pix < npix), as HIP does. The D3D12
      compiler then sank the WMMAs into that branch, where they ran with part of the wave masked off: wrong values in a
      partly filled wave (a 35-pixel map, pixels 32..34). A test padding the same map to a full wave showed HIP right and
      D3D12 wrong. The fixed ISA has 0 branches, 2 stores and 4 WMMAs per kernel (build_dx12.py --isa).
  • clean/l/runner/l_d3d12_ops_check.py (new): any l_ops.co kernel's D3D12 port against its HIP kernel, with the
    rules of Model L: D3D12 port of the C = 32 Swin block, byte for byte against its HIP kernel #117's review:
    • the raw downloaded bytes of both back ends are compared;
    • each output buffer starts filled with its back end's own non-zero sentinel (HIP 0xA5, D3D12 0x5A), so a byte
      left unwritten by either path differs;
    • a negative control (one case on D3D12 with half its workgroups) must be caught;
    • a Model M control: swin_block_c96_nc (swin.co, its D3D12 port already proven on whole frames) runs through
      the same engine in every run, so the harness itself is proven too;
    • HIP's outputs are kept next to D3D12's for a look at any difference.
      The projections and l_coef join it in their own pull requests.
  • clean/l/runner/l_d3d12_check.py: prepare_replay (build the ports and kernel_replay.exe), shared by both
    harnesses.

Refs #89

Tested

Local, Windows, Radeon RX 9000 series card, with #115's HIP kernels:

  • GPU (one GPU slot), l_d3d12_ops_check.py --run --seeds 6 --kernels l_linear_32_32_relu,l_linear_32_32_f16:
    • l_linear_32_32_relu: 30 of 30 cases identical (6 seeds x 5 maps: 16 x 24, 36 x 68, 8 x 8, 68 x 100 and
      5 x 7 pixels, the last a partly filled wave; 1,868,352 output bytes);
    • l_linear_32_32_f16: 30 of 30 identical (3,736,704 bytes);
    • the Model M control swin_block_c96_nc: 36 of 36 identical (3,167,424 bytes);
    • 0 differing bytes in every case; the negative control caught (37,376 bytes);
    • all compared as raw downloaded bytes, each output filled beforehand with its back end's own non-zero sentinel;
    • before the branch fix: 24 of 30 per kernel (the 5 x 7 map differed).
  • build_dx12.py --isa: 2 buffer_store, 4 v_wmma, 0 branches per kernel (the stores the kernel must issue).
  • python tools/ci/check_line_endings.py: 0 problems. Public gates (secrets, personal data, licence, chunks) pass.

Not tested

  • In a whole Model L frame (waits for the L runtime frame).
  • Grids above 65535 workgroups (several dispatches); the maps here are small.

…r HIP kernels

l_ops_linear.hlsl ports l_linear_32_32_relu and l_linear_32_32_f16 of l_ops.co
(clean/l/kernels/l_ops.hip, #115). No branch around the matrix instructions: a lane
past the end of the map stores its clamped pixel's bytes to that pixel (a branch
around the store let the compiler sink the WMMAs into it; wrong values in a partly
filled wave). l_d3d12_ops_check.py compares any l_ops.co kernel's D3D12 port with
its HIP kernel: raw bytes, each back end's output filled with its own sentinel, a
negative control. l_d3d12_check.py gains prepare_replay (the ports and
kernel_replay.exe), shared by both harnesses.

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
The control (swin.co, its D3D12 port already proven on whole frames) runs through
the same engine as the l_ops.co ports (raw bytes, sentinels, negative control) in
every run unless --no-control; cases name their code object.

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 01:40
phantoslayer21 added a commit that referenced this pull request Nov 14, 2026
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21 added a commit that referenced this pull request Nov 14, 2026
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Base automatically changed from model-l/c32-d3d12 to main November 14, 2026 01:53
@phantoslayer21
phantoslayer21 merged commit ba29967 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/l-linear-d3d12-pr branch November 14, 2026 02:03
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