Skip to content

Frame generation: net1's 32 steps on the GPU (HIP and D3D12), bit for bit against the CPU reference - #191

Merged
phantoslayer21 merged 2 commits into
mainfrom
fg/net1-gpu
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
fg/net1-gpu

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Issue #96 (frame generation), lane groundwork: net1's 32 steps run on the GPU on both back ends and match the CPU reference bit for bit.

What changes

  • fg_add_f16, net1's skip add (y = h(a + b)), in clean/fg/kernels/fg_net1.hip, plus its D3D12 port clean/dx12/kernels/fg_add.hlsl. Per-kernel cases are added to fg_d3d12_check.py: random pairs, and every pair of thirteen special values.
  • clean/dx12/tests/kernel_replay.cpp gets additive chain blocks: device buffers that persist between launches, step lines (@id pointers or 32-bit values), save, and an optional time <runs>. Existing case blocks parse and run as before.
  • clean/fg/runner/fg_net1_gpu.py builds net1 from NET1_WIRING: one launch per step, every buffer resident, and no host round trip between steps. It runs on HIP in-process and on D3D12 as one chain per case. Then:
    • every step output (not only the final one) is compared as raw bytes between the back ends: HIP sentinel 0xA5, D3D12 sentinel 0x5A, and 64 slack bytes that no step may write;
    • every HIP step output is compared with the CPU reference's buffer (float16 bits; NaN equals NaN);
    • one negative control per kernel: the first launch of that kernel runs on half its grid and must be caught;
    • the network output is digested on HIP, D3D12 and CPU. HIP and D3D12 must match byte for byte; the CPU digest is compared with every NaN set to 0x7E00, because the reference's NaN payload is not specified.
  • Cases:
    • synthetic weights at 64 x 64 input pixels;
    • 70 x 90 pixels (odd level sizes, floor halving);
    • special values in the input, biases and weights (NaN, ±inf, subnormals, ±65504, −0, overflowing sums);
    • finite special values only;
    • with --model, the weights of a converter output file of the preset-FG map, on net1_digest.py's fixed input. Execute-only: the files the tool writes for the replay are deleted after the run, and it prints only counts and digests.
  • --timing (information only) runs a 512 x 512 probe that times every launch. Only if every single launch, scaled up, stays under 250 ms does it time net1 at 1920 x 1080 and 2560 x 1440 input pixels on both back ends.
  • FG kernels are still built only through build_dx12.py --only. The Model M / Model L kernel sets and kernel_sets.json are unchanged.

Tested

  • python -m unittest discover -s clean/fg/tests -t .: 77 OK, including 4 new plan tests (every step output's shape against the reference buffers, launch arguments, natural weight order, chain lines). clean/dx12/tests/test_kernel_sets.py: 4 OK.

  • GPU (one GPU slot each, under its cap):

    • per-kernel check fg_d3d12_check.py --run: 244 cases and 1,502,364 values. HIP matches D3D12 in raw bytes and matches the CPU reference; all four negative controls were caught (add: 973 bytes).
    • whole network fg_net1_gpu.py --run, synthetic weights: 4 cases, 128 step outputs and 1,290,608 values, all bit for bit, with 16 of 16 negative controls caught.
    • whole network with the real converted weights (execute-only, converter verdict pass, 42/42 stage digests): 32 of 32 step outputs bit for bit. The output digest is identical on HIP, D3D12 and CPU, and equals the CPU digest recorded privately for the earlier net1 wiring PR. The converted file was deleted, and only digests were kept (privately).
  • Timing line, information only and no claims (synthetic weights, buffers resident, mean of 5 runs after a warm-up; HIP: device events, D3D12: wall time per synchronised run):

    • net1 at 1080p-sized input: HIP 122 ms, D3D12 169 ms;
    • net1 at 1440p-sized input: HIP 215 ms, D3D12 300 ms.

    The longest single launch measured 102 ms. Both back ends' outputs were identical at both sizes. These kernels are exactness references, one scalar output per lane, and not tuned.

  • public_gates.py: must-pass gates pass. The leak and number LOOK lines are at main's baseline, with none in the changed files.

Not tested

  • Model M / Model L runs: their kernels, sets and DXILs are untouched, and nothing in their path changed.
  • net2, the input packing (what the 10 values are made of), and any runtime integration: still open on the spec side.
  • The slope literal (Q-FG1) and the upscale ratio (Q-FG2) are kept as they are until the spec side answers.

… bit for bit against the CPU reference

- fg_add_f16 (HIP) and its D3D12 port fg_add.hlsl: the skip add, y = h(a + b); per-kernel cases in fg_d3d12_check.py
- kernel_replay: additive "chain" blocks (buffers that persist between launches, steps, saves, optional timing);
  "case" blocks unchanged
- runner/fg_net1_gpu.py: the whole network from NET1_WIRING on both back ends; every step output compared raw
  (sentinels, slack) and against the CPU reference; a half-grid negative control per kernel; synthetic weights,
  odd sizes, special values; --model for a converter output file (execute-only); --timing as information only
- FG kernels still built only through --only; Model M / Model L kernel sets unchanged

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 19:43
@phantoslayer21
phantoslayer21 merged commit 1f2a3ac into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the fg/net1-gpu branch November 14, 2026 19:44
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