Repository navigation
Frame generation: net1 fused tier B (11 launches), D3D12 within 1.5x of HIP, exact path selectable - #205
Merged
Conversation
…of HIP, exact path selectable
- fg_mpair_{b,d4..d0} (HIP + fg_mpair.hlsl): the bottleneck and each decoder level as two chained 1 x 1
convolutions in registers, the decoders' upscale and skip add computed per input fragment
- fg_fast16.h: leaky ReLU with fg_leaky16's bits from one product and one rounding (checked on all 65,536 inputs
on HIP, D3D12 and the CPU), the skip add; fg_mconv's epilogue uses it
- D3D12: float16 rounding of whole fragments by the driver conversion instead of the software wg_f2h; lanes past
the grid end compute a clamped pixel (a validity array corrupted other lanes' matrix rows); both in the README's
driver exceptions
- runner/fg_net1_mma.py: paths fused / tierb / exact; gates HIP == D3D12 (sentinels, slack, half-grid negative
control per kernel incl. a 768 x 768 case), fused == tierb, the leaky check; report with absolute and relative
differences; timing; records/net1-fused-2026-11-14.json
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #96 (frame generation). The second piece of net1's tier-B fast path: the bottleneck and decoders fused, the D3D12 gap to HIP explained and mostly closed, and the exact path selectable as the fallback.
What changes
fg_mpair_{b,d4,d3,d2,d1,d0}(clean/fg/kernels/fg_net1_mma.hip,clean/dx12/kernels/fg_mpair.hlsl): two chained 1 x 1 convolutions, kept in registers. A result fragment (lane = pixel, 8 consecutive channels) has exactly the layout of the next convolution's input fragment, so neither LDS nor memory sits between them.fused) instead of 27: five encoder convolutions with the pool fused, the bottleneck pair, five decoder pairs.fg_leaky_fast16(clean/fg/kernels/fg_fast16.h, check kernelfg_leaky_fast_f16): the leaky ReLU as one single-precision product with the slope, one float16 rounding and the max. It givesfg_leaky16's bits for every input; the earlier integer version was the bulk of the convolution epilogue's code.fg_mconvuses it too.wg_to_f16_ags, the bits of HIP's(_Float16)), instead of the softwarewg_f2h.clean/fg/runner/fg_net1_mma.py --paths fused,tierb,exact: the exact path (Frame generation: net1's 32 steps on the GPU (HIP and D3D12), bit for bit against the CPU reference #191's bit-exact kernels) stays selectable in the same runner, as the validation mode and a cheap fallback (tier C) if the frame gate needs it.clean/dx12/README.md"Driver exceptions": the two findings below, for future ports.clean/fg/records/net1-fused-2026-11-14.json: gate results, report (counts only), timing, and the D3D12 profile per launch.Why D3D12 was ~2.8x slower than HIP, and what changed
Measured with
WG_D3D12_PROFILEGPU timestamps per dispatch against HIP device events per launch (1080p-sized input), plus the RGA ISA:(half)cast rounds toward zero, sowg_f2his about 20 instructions per value. Tier B rounds every accumulator value after every chunk, which made that the hot loop's main cost; HIP does it with onev_cvt_f16_f32. The driver conversion of a whole fragment replaces it, and the decoders' upscale / add roundings are batched the same way.fg_leaky_fast16, which halved that kernel's code.Fused path, D3D12 GPU time summed over its launches: 10.40 ms before the driver conversion, 3.99 ms after; HIP 2.72 ms (1.47x). net1_01 (the largest layer) is 1.18 ms on D3D12 against 0.74 ms on HIP.
A port bug found and fixed on the way: lanes past the end of the grid corrupted other lanes' matrix results on D3D12. The kernel used a per-lane validity array with
select()for the pixel and a guarded store. With part of the last 16-pixel group past the end (odd level sizes), valid lanes got NaN in exactly the output rows whose weight-fragment row sat in an invalid lane, while HIP was right. Every lane now computes a clamped pixel and only the store tests the range. The 70 x 90 case caught it; it is in the README's driver exceptions.Gates (the port standard)
Report against the exact CPU reference (record above; not a gate)
Converted real weights, fixed 64 x 64 input (execute-only: converter pass, 42/42 stage digests, converted file deleted, no output digest in public):
Per output value (fused), max |diff| / max |ref|: 2.2e-3, 2.2e-3, 2.4e-3, 3.9e-3. The step counts come from small and near-zero values. The absolute error stays at about 10⁻³ of each buffer's range through the network; see the drift analysis that preceded #199's merge.
Timing (information only; synthetic weights, mean of 10 runs after a warm-up; HIP device events, D3D12 wall time per synchronised run including host submission and the wait)
The longest single launch was 1.26 ms. For comparison, #199 measured tierb at 4.46 / 7.10 ms (HIP) and 12.47 / 20.46 ms (D3D12).
Tested
python -m unittest discover -s clean/fg/tests -t .: 85 OK, including new tests: the 11-launch plan (buffers, launch arguments, every kernel has a half grid at 768 x 768) and the fast leaky formula on all 65,536 inputs.clean/dx12/tests/test_kernel_sets.py: 4 OK.public_gates.py: must-pass gates pass; the LOOK lines are at main's baseline.Not tested