Skip to content

Model K on D3D12: --model-k, struct arguments, the port check, k_expo_scalars and k_warm - #201

Merged
phantoslayer21 merged 2 commits into
mainfrom
k/d3d12-base
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
k/d3d12-base

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

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

First D3D12 piece of Preset K: the build option, struct arguments, the byte-for-byte check, and the first two ports. k_expo_scalars is byte-identical to its HIP kernel (the pilot of the family check); k_warm is a D3D12-only cache warm-up with no HIP kernel.

What changes

  • build_dx12.py: Model K's kernels (clean/k/dx12/kernels, co=k_*.co) are built only with --model-k, or when --only names them. Without the option the kernel set is Model M's, and with --model-l Model L's, as before. kernel_sets.json has a model_k list; test_kernel_sets.py checks that no K kernel is in the other sets and that --model-k adds only K kernels.
  • Struct arguments (clean/runtime/struct_args.h, new): a HIP kernel that takes a struct with 64-bit pointers by value declares it as s<N>:<fields> (p<n> pointers, b<n> copied bytes, x<n> skipped bytes). The hybrid device (device_dx12.cpp) and the native device (device_d3d12.cpp) turn each pointer into an arena offset. CPU test: clean/tests/test_struct_args.{cpp,py}.
  • fp64=ext: a port that uses binary64 fma or division (the exact input stage will) is marked in the manifest, and both devices drop it when the adapter lacks DoublePrecisionFloatShaderOps.
  • kernel_replay: chain steps take B:<file> (struct by value) and S:<file>:<offset>=@<id>,... (struct with pointers).
  • clean/k/dx12/k_port_check.py (new): the byte-for-byte check, one family at a time (--prepare on the CPU, --run in a GPU slot). Raw bytes; 64 bytes of slack per output with HIP 0xA5 / D3D12 0x5A sentinels; special values among the inputs; a negative control; Model M's scale_rgb as the harness control. README in clean/k/dx12/.
  • Ports: k_expo_scalars (+ _direct, the native executor's texture form) and k_warm.

Tested

  • CPU: test_kernel_sets (7), test_struct_args (1) pass; line endings clean; the runtime library (hybrid and native devices) compiles.
  • Port check, one GPU slot, k_port_check.py --run --family expo,warm --seeds 2:
    • expo: 72 of 72 cases byte-identical to HIP (hdr/LDR, value/texel/none, auto-exposure, first/reset, e1/e2 not 1, a pre-exposure reciprocal of 0, infinity, NaN, FP16 specials: zero, -0, subnormals, 65504, 65520, 1e6, infinity, NaN), every slack byte its own sentinel. Negative control (the port given another exposure than HIP) caught, 8 bytes differ. This kernel has one workgroup, so there is no half-grid control; the different-input control takes its place.
    • warm: 12 of 12 cases as defined (13 pointers and the other bytes through the struct argument; the dummy is written exactly when the key equals a lane's loaded value).
    • Control, Model M scale_rgb: identical.
    • Record: pr4-expo-warm.json of the run (counts and verdicts only).
  • DXILs: 12 Model M and Model L kernels (exposure_pair_diet, scale_rgb, color_divide, input_encoder, expand_c96, patch_merge_c64, l_coef, l_post_recon, l_linear_32_32_fused, l_direct_color, l_project_gather, lev/input_encoder) built from main (f4816cf) and from this branch: all 12 digests identical. No .hlsl or .hlsli of Model M or Model L changed; their compile command is unchanged. Not the full 68-kernel build.
  • public_gates.py: must-pass gates pass; the LOOK counts equal main's except 3 review lines for the HIP SDK path in the new usage text.

Not tested

  • The full Model M plus Model L DXIL set (sample of 12 above).
  • The devices on a game or the existing native device tests (the change to them is the additive s argument and the fp64 flag).
  • Known limit, shared with Model M's ports: D3D12 flushes FP32 denormals to zero, HIP keeps them. k_expo_scalars meets one only with a pre-exposure above about 8.5e37; the check's inputs stay clear of them (README).

… the first ports (k_expo_scalars, k_warm)

Refs #15. build_dx12.py builds clean/k/dx12/kernels only with --model-k (or --only), so Model M's and Model L's kernel sets and DXILs stay as they are; kernel_sets.json has a model_k list. A kernel that takes a struct with pointers by value declares it as s<N>:<fields> (clean/runtime/struct_args.h), supported by the hybrid and the native device; a port that uses binary64 fma or division is marked fp64=ext and dropped on an adapter without them. kernel_replay chains take struct arguments. clean/k/dx12/k_port_check.py compares a family of ports with its HIP kernels byte for byte. k_expo_scalars is ported and checked; k_warm (no HIP kernel) is checked against its definition.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Base automatically changed from k/hip-exposure to main November 14, 2026 22:34
@phantoslayer21
phantoslayer21 merged commit ce5d9b4 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the k/d3d12-base branch November 14, 2026 22:35
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