Skip to content

Model L on D3D12: the projections' conversions by the driver's instructions - #161

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/proj-cvt
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/proj-cvt

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Model L speed on D3D12, fourth change: l_dec_project and l_project_gather do their FP16 rounding and FP8 pack
with the driver's conversion instructions. They used the software forms, which were most of their instructions.
Both stay byte for byte against their HIP kernels; nothing is approximated. The two kernels get the same edit in one
file, so they are one PR, timed separately.

What changes

  • clean/dx12/kernels/l_ops_project.hlsl: the RN16 after every pair of matrix multiplies is now v_cvt_f16_f32 plus
    the exact widening, and the FP8 pack is v_cvt_pk_fp8_f32 after the clamp. Before, these were the software
    wg_rn16 / wg_pack_q8. wg_platform.hlsli documents the same bits; the kernels have no branch, which the driver
    conversions need.
  • clean/l/runner/l_d3d12_ops_check.py: the projection cases run at three weight scales: normal; large (sums past 448
    and past FP16's range: the clamps, infinities); tiny (FP16 subnormal results). Every other case has special FP8
    codes in the input (both NaN codes, +-448, +-0, subnormals).

Refs #89

Byte identity (clean/l/runner/l_d3d12_ops_check.py --kernels l_dec_project,l_project_gather, one GPU slot;
record records/proj-cvt-identity.json in the rr-plugin build folder)

  • D3D12 against HIP, raw bytes, sentinel-filled outputs (HIP 0xA5, D3D12 0x5A).
    • l_dec_project: 36 of 36 cases identical (1,886,976 bytes). Its outputs include 886,656 NaN codes, 241,038 at
      the +-448 clamp and 48,914 subnormals.
    • l_project_gather: 36 of 36 (943,488 bytes); 884,464 at its +-6.28125 clamp. It cannot output a NaN: the clamp
      drops it, as in HIP.
  • Negative control (half grid): caught, 45,509 bytes differ.
  • Model M's swin_block_c96_nc control: 12 of 12.

Frame check (clean/l/runner/l_frame_check.py --compare-d3d12, synthetic models; record
records/proj-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/proj-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
these two DXILs. Two sets of 3 interleaved rounds, every run in its own GPU slot; records records/projcvt-ab.json
and records/projcvt2-ab.json.

  • l_dec_project: 0.1909 / 0.1927 -> 0.0500 / 0.0506 ms (medians of the two sets: -141 / -142 us).
  • l_project_gather: 0.1665 / 0.1679 -> 0.0560 / 0.0564 ms (-111 / -112 us).
  • The other kernels move by at most +-0.012 ms (l_swin_block_c32_enc_nc +2 / +6 us, lev/input_encoder +0 / +11
    us, the post +4 us, color_divide -5 / +5 us).
  • Whole-frame span: A 2.507 / 2.508 / 2.488, 2.486 / 2.489 / 2.493 ms; B 2.266 / 2.266, 2.239 / 2.253 / 2.239 ms.
    • About -240 us per frame. B's first round of the first set (3.078 ms; its two kernels at 0.071 / 0.069 ms) is left
      out.

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.

…ctions

l_dec_project and l_project_gather round to FP16 after every pair of matrix multiplies
and pack to FP8 per tile; both were the software forms (wg_rn16, wg_pack_q8), most of
the kernels' instructions. Now RN16 is v_cvt_f16_f32 plus the exact widening and the
pack v_cvt_pk_fp8_f32 after the clamp (wg_platform.hlsli: the same bits; the kernels
have no branch). Byte for byte against HIP, as before.

- clean/l/runner/l_d3d12_ops_check.py: the projection cases at three weight scales
  (sums past 448 and past FP16's range, FP16 subnormal results) and with special FP8
  codes in the input (NaN, +-448, +-0, subnormals).

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 10:42
@phantoslayer21
phantoslayer21 merged commit 848d77e into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/proj-cvt branch November 14, 2026 10:42
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