Skip to content

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

Merged
phantoslayer21 merged 2 commits into
mainfrom
fg/kernels-upscale
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
fg/kernels-upscale

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Adds the third frame-generation GPU kernel family: net1's bilinear upscale, for HIP and D3D12, byte-identical with each other and bit for bit against the CPU reference net1.upscale_to (lane h). It stacks on #187 (max-pool); after #187 merges, its base becomes main.

Kernel: fg_upscale_f16(x, y, C, hi, wi, ho, wo, rx, ry) in clean/fg/kernels/fg_net1.hip (code object fg_net1.co), with its D3D12 port clean/dx12/kernels/fg_upscale.hlsl.

  • Bilinear, align corners, from [C][hi][wi] to [C][ho][wo] float16 (net1's level sizes: the coarse level is the fine one halved with floor).
  • Ratios: rx, ry are (n_in − 1)/(n_out − 1) as correctly rounded single-precision bits from the caller (0 for an extent of 1), as the CPU reference computes them. No division runs on the GPU.
  • Positions: per axis, in single precision, one operation at a time (the HIP file disables contraction): s = r·o, i0 = trunc(s), i1 = trunc(s + 1) (both n_in − 1 at the edge), w1 = h(s − i0), w0 = h((i0 − s) + 1).
  • Blend: top = h(h(wx0·P00) + h(wx1·P01)), bottom the same on row y1, out = h(h(wy0·top) + h(wy1·bottom)).
    • A product of two float16 values is exact in single precision.
    • Rounding a sum of two float16 values first to single precision and then to float16 equals one rounding of the exact sum (24 ≥ 2·11 + 2). So both back ends match the CPU's exact-then-round values.
  • NaN results are written as 0x7E00. Like every fg_ kernel, this one is built only with --only, so Model M's and Model L's kernel sets and DXILs are unchanged.

Check (clean/fg/runner/fg_d3d12_check.py): upscale cases covering net1's level pairs (for example 17×33 → 35×67, 1×2 → 2×4), other sizes (3×4 → 7×9, 5×2 → 11×4), output extents of 1, equal sizes, and special values (NaN, ±inf, subnormals, ±65504, −0) in the input.

Refs #96

Tested

  • GPU check on the RX 9070 XT inside one GPU slot (gpu_slot.py --cap-s 170), three seeds, all three kernel families in one run: 348 cases (63 upscale) and 2,211,618 output values.
    • HIP and D3D12 raw bytes are identical, and every slack byte kept its back end's sentinel (0xA5 / 0x5A).
    • HIP equals the CPU reference bit for bit, including 25,005 NaN and 6,707 inf outputs.
    • All three per-kernel negative controls were caught (upscale 2,127 differing bytes, pool 9,760, conv 1,214).
  • test_kernel_sets, the clean/fg unit tests, the line-ending check and the public gates pass, with no hits in the changed files.

Not tested

  • Speed (correctness kernels); no timing was taken.
  • A whole-network GPU run: chaining the kernels into net1's 32 steps is the next piece.

…against the CPU reference

fg_upscale_f16 (fg_net1.co) and its D3D12 port clean/dx12/kernels/fg_upscale.hlsl:
bilinear, align corners, as net1.upscale_to. The ratios come from the caller
as correctly rounded single-precision bits (no division on the GPU);
positions in single precision one operation at a time (HIP without
contraction), every product and sum rounded to float16. Built only with
--only, as every fg_ kernel.

fg_d3d12_check.py: upscale cases (net1's level pairs, other sizes, an output
extent of 1, equal sizes, special values).

Refs #96

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:12
Base automatically changed from fg/kernels-pool to main November 14, 2026 19:12
@phantoslayer21
phantoslayer21 merged commit 0315427 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the fg/kernels-upscale branch November 14, 2026 19:13
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