Skip to content

Model K on D3D12: the wide network stages, byte-identical to HIP - #206

Merged
phantoslayer21 merged 4 commits into
mainfrom
k/d3d12-wide
Nov 14, 2026
Merged

phantoslayer21 merged 4 commits into
mainfrom
k/d3d12-wide

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #15. Stacked on #204 (and through it #201, #198, #194): the diff is against that branch.

Preset K's wide network stages on D3D12, byte-identical to their HIP kernels on the exact FP32 path (no FP16-accumulating or FP8 forms).

What changes

  • clean/k/dx12/kernels/k_block_wide.hlsl and hlsl/k_wide.hlsli: the wide block (k_block_wide.hip, template k_block_wide<C, HEADS, softmax, IN, CIN, CNEXT, NG>) for the seven kernels the runtime launches: k_stagew2_e3, k_stagew4_e4, k_stagew2_e4, k_stagew4_m, k_stagew4_d4, k_stagew2_d4, k_stagew2_d3. One workgroup of 128 NG lanes per window; KBlkParams by value (s184:p19.b32). Every matrix product is the driver's 16x16x16 FP16 multiply with FP32 accumulation, summed in HIP's order; the elementwise FP16 steps, the softmax (round-to-odd product, one rounding) and the normalization follow HIP operation by operation. The header lists the places where the D3D12 code is arranged differently without a change of result (weight stream ring, interleaved independent accumulators, a different LDS layout for NG = 4 to fit D3D12's 32 KB).
  • kernel_sets.json: seven more kernels in model_k.
  • k_port_check.py: the stage family (Model K on D3D12: the narrow network stages, byte-identical to HIP #204) now also runs the wide kernels.

Tested

k_port_check.py --run --family wide --seeds 2, one GPU slot, random stage weights and inputs, six grids per kernel (8 x 8 to 33 x 17, ragged edges, fewer windows than a workgroup), window offsets from {0, 2, 4, 6}:

  • 84 of 84 cases identical to HIP over the defined bytes, 12 per kernel for all seven kernels; every output buffer's 64 slack bytes kept their run's sentinel (HIP 0xA5, D3D12 0x5A).
  • Special values: 28 cases with infinity, +-65504, zero, -0, subnormals in the inputs, raw bytes identical in all 28; 28 more with NaN as well: raw bytes identical in 16, and in 12 cases 201 elements are NaN on both devices with a different sign (IEEE 754 does not define a NaN's sign; every other byte is identical). Both counts are in the record.
  • Negative control (half grid) caught, 40960 bytes differ. Control, Model M scale_rgb: identical.
  • The narrow family (Model K on D3D12: the narrow network stages, byte-identical to HIP #204) re-run after the check's refactor: 120 of 120.
  • Record: pr7-wide.json (counts and verdicts only).
  • CPU: test_kernel_sets passes; line endings clean.
  • DXILs: no Model M or Model L source changed in this PR.
  • public_gates.py: must-pass gates pass; the LOOK counts equal main's.

Not tested

  • The full Model M plus Model L DXIL set.
  • Whole network frames on D3D12 (the runtime does not select these ports yet).
  • Real model weights; the 4K case where e4 / d4 change from NG = 4 to NG = 2 is covered by both kernels being checked, not by a frame.

Accepted exceptions (review decision, 2026-11-14)

  • NaN sign: with NaN in the inputs, the decoder stages produce NaN at exactly the same elements on D3D12 and HIP, but the NaN sign can differ. Every non-NaN byte is identical. A NaN sign carries no value (NaN propagates), so this is accepted as a documented exception to raw-byte identity; the port check keeps counting these elements separately.
  • FP32 denormals: D3D12 flushes FP32 denormals where HIP keeps them, the same accepted behaviour as the Model M ports. The check inputs avoid denormals.

…ntical to HIP

Refs #15. Ports of k_stagew2_e3, k_stagew4_e4, k_stagew2_e4, k_stagew4_m, k_stagew4_d4, k_stagew2_d4 and k_stagew2_d3 (the exact FP32 path; one workgroup of 128 NG lanes per window; weight stream, driver-channel matrix products, same operation orders as HIP). The port check's stage family covers them.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 22:08
Base automatically changed from k/d3d12-narrow to main November 14, 2026 22:35
@phantoslayer21
phantoslayer21 merged commit 2cc0983 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the k/d3d12-wide branch November 14, 2026 22:49
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