Skip to content

Model L: D3D12 port of the coefficient step (l_coef), byte for byte against its HIP kernel - #126

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

phantoslayer21 merged 2 commits into
mainfrom
model-l/l-coef-d3d12-pr

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Model L (#89): the D3D12 port of Model L's coefficient step, l_coef of l_ops.co (clean/l/kernels/l_ops.hip,
merged in #115), byte for byte against its HIP kernel.

Stacked on #123 (it adds this kernel's cases to the ops harness of #122 / #123); it targets main once those merge.
CI needs no GPU: nothing here runs without one.

  • clean/dx12/kernels/l_ops_coef.hlsl (new): the decoder block's FP16 map -> A, B, C and the new latent, pixels
    inside R only, as HIP (clean/l/FORMATS.md, dec0.coef).
    • Lanes and the two pixels per lane (dx unrolled) as HIP; S and T from the blob at byte 320.
    • Every FP32 step follows HIP's ISA of l_coef where it differs from the source:
      • C0 / C1 are each rounded once to FP16 from the product (v_fma_mixlo_f16 a, b, 0 = wg_mul_f16);
      • tanh's polynomial range keeps fma(p, t^2, +0) with an opaque zero, so the driver cannot turn it into a plain
        product;
      • the softmax codes keep rint((e r) 255) grouped as HIP's (opaque link);
      • the clamp of the two spread inputs to +-20 keeps a NaN, as HIP's compares.
    • The pointers are read through wg_uniform(). Three of the four stores go at the same per-lane offset into
      different buffers, the shape the D3D12 README says the driver may merge. The RGA ISA has all of them (below).
  • clean/l/runner/l_d3d12_ops_check.py: the l_coef cases.
    • Six frames (rw x rh in fw x fh): 24 x 16 in 24 x 16, 67 x 35 in 68 x 36, 7 x 5 in 8 x 6, 100 x 68 in 100 x 68,
      5 x 3 in 6 x 4, 13 x 7 in 20 x 12. That gives odd R sizes, a padded grid wider than R by whole tokens, and partly
      filled waves.
    • The FP16 inputs include values past the +-20 clamp, past tanh's saturation and inside its polynomial range.
    • LDecParams is passed by value (56 bytes).

Refs #89

Tested

Local, Windows, Radeon RX 9000 series card, against the merged #115 (the l_ops.co built from main is bit-identical to
the one these records used):

  • GPU (one GPU slot), l_d3d12_ops_check.py --run --seeds 6 --kernels l_coef:
    • l_coef: 36 of 36 cases identical (6 seeds x 6 frames; 4 outputs per case, 1,160,400 output bytes);
    • the Model M control swin_block_c96_nc: 36 of 36 identical (3,167,424 bytes);
    • 0 differing bytes in every output. The negative control (half grid) was caught: 26,639 bytes differed;
    • compared as raw downloaded bytes. Each output was first filled with its back end's own non-zero sentinel
      (HIP 0xA5, D3D12 0x5A).
  • build_dx12.py --isa (RGA):
    • 6 buffer_store_b32 + 2 buffer_store_b64: 4 stores per pixel x 2 pixels, as HIP's 8 global_store;
    • 26 v_exp_f32 and 22 v_rcp_f32, as HIP;
    • the only branches are the early exits.
  • 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).
  • NaN or infinite inputs (none in the synthetic data). The NaN behaviour of the clamp and of the polynomial range
    follows HIP's ISA but was not run.

…gainst its HIP kernel

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 02:04
Base automatically changed from model-l/l-project-d3d12-pr to main November 14, 2026 02:10
@phantoslayer21
phantoslayer21 merged commit b0602fc into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/l-coef-d3d12-pr branch November 14, 2026 02:16
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