Skip to content

Frame generation: net1 convolution kernel for HIP and D3D12, bit for bit against the CPU reference - #183

Merged
phantoslayer21 merged 1 commit into
mainfrom
fg/kernels-conv
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
fg/kernels-conv

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Adds the first frame-generation GPU kernel family: net1's FP16 convolution, for HIP and D3D12, byte-identical with each other and bit for bit against the CPU reference net1.conv16 (lane h).

Kernel: fg_conv_f16(x, w, b, y, cin, cout, H, W, k, order, act), in clean/fg/kernels/fg_net1.hip (code object fg_net1.co), with its D3D12 port clean/dx12/kernels/fg_conv.hlsl.

  • One net1 convolution: 3×3 or 1×1, stride 1, zero border, cross-correlation over the natural weights [out][in][k][k].
  • The float16 accumulator starts at the bias. Products are taken in 16-term chunks, each summed exactly and rounded to float16 once, in the layer's chunk order: 0 ascending; 1 channel block, kx, ky; 2 kx, channel block, ky.
  • act: 0 none, 1 leaky ReLU (slope 0x211E).
  • Float16 channel-first tensors, one output element per lane, 256-lane workgroups.
  • Shared arithmetic: clean/fg/kernels/fg_exact16.h holds the integer code both back ends include, using the same method as fp16acc.py (exact 64-bit partial sums, one nearest-even rounding, IEEE inf/NaN, NaN written as 0x7E00). Both back ends therefore run the same operations, and no floating-point rounding happens before the single float16 rounding.

Model M and Model L stay unchanged

  • build_dx12.py gets is_frame_gen: kernels with co=fg_*.co or named fg_* are built only when --only names them, never by a full build, with or without --model-l.
  • kernel_sets.json is unchanged. test_kernel_sets gains a test that frame-generation kernels enter neither set.
  • No shared HLSL header and no existing kernel changed.

Check: clean/fg/runner/fg_d3d12_check.py.

  • --prepare (CPU) builds fg_net1.co, the port (--only) and kernel_replay.
  • --run (inside one GPU slot):
    • compares the raw downloaded bytes of HIP and D3D12. Outputs start with HIP 0xA5 / D3D12 0x5A sentinels, and 64 slack bytes after each output must keep each back end's own sentinel;
    • runs a half-grid negative control, which must be caught;
    • compares the HIP output against the CPU reference value for value (float16 bits; NaN equals NaN).
  • Cases: every net1 layer shape (cin, cout, kernel size, chunk order, activation) on grids from 1×1 to 16×12, plus special values (NaN, ±inf, subnormals, ±65504, −0) in inputs, weights and biases, and sums that overflow.

Refs #96

Tested

  • GPU check on the RX 9070 XT inside one GPU slot (gpu_slot.py --cap-s 170), three seeds: 264 cases and 1,838,160 output values.
    • HIP and D3D12 raw bytes are identical everywhere, and every slack byte kept its back end's sentinel.
    • HIP equals the CPU reference bit for bit, including 5,444 NaN and 1,430 inf outputs.
    • The half-grid negative control was caught.
  • test_kernel_sets (4 tests), the clean/fg unit tests, the line-ending check and the public gates pass, with no hits in the changed files.

Not tested

  • Speed: this is a correctness kernel (scalar integer arithmetic, no matrix unit); no timing was taken.
  • Max-pool and upscale kernels follow in their own PRs.

…bit against the CPU reference

fg_conv_f16 (clean/fg/kernels/fg_net1.hip, code object fg_net1.co) and its
D3D12 port (clean/dx12/kernels/fg_conv.hlsl): one net1 convolution, 3x3 or
1x1, zero border, float16 accumulator from the bias in exact 16-term chunks in
the layer's chunk order, leaky ReLU (slope 0x211E) or none. The arithmetic is
integer code shared by both back ends (clean/fg/kernels/fg_exact16.h, the
method of fp16acc.py).

build_dx12.py builds fg_ kernels only when --only names them, so the Model M
and Model L kernel sets (kernel_sets.json) and their DXILs stay as they are;
test_kernel_sets checks it.

clean/fg/runner/fg_d3d12_check.py: HIP against D3D12 (raw bytes, sentinels
0xA5 / 0x5A, slack, half-grid negative control) and HIP against the CPU
reference, on every net1 layer shape and special values.

Refs #96

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 18:36
@phantoslayer21
phantoslayer21 merged commit 1b37c67 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the fg/kernels-conv branch November 14, 2026 18:39
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