Repository navigation
Frame generation (D3D12): tiled/fused pre-net2, batched FP16 conversion, and tap-pipelined net1/net2 WMMAs (-53.1% Preset C 2x, -49.5% Preset A 2x) - #299
Open
phantoslayer21 wants to merge 15 commits into
Conversation
…on, and tap-pipelined net1/net2 WMMAs (-53.1% Preset C 2x, -49.5% Preset A 2x, 116/116 exact)
…'s packed rows directly, dropping the fg_exec_pack pass (Preset A 2x -45 us, 6x -219 us; Preset C 2x -45 us, 6x -223 us; exact) The Full path's fg_out_pull / fg_out_push_fine and the light path's fg_lite_blend each get a _pack variant that stores the 8 / 10-bit UNORM slot code (clean/dx12/hlsl/fg_pack.hlsli, the same code fg_exec_pack computes) instead of the float16 image, so the generated frame is neither written at 8 B per pixel, read back, nor given its own dispatch and barrier. The executor picks them when nothing writes the output image after them (no menu output, prefill or copy), outputs are not kept for readback and the slot is an RGBA8 / BGRA8 / RGB10A2 image of the output size; every other case keeps the old kernels. Two Full-path slot-format cases join the input-SRV test (RGBA8 preset A, RGB10A2 preset B, odd widths).
…tself, dropping the merge dispatch (Preset A 2x -10 us; exact) fg_full_blend_merge stores the ten-channel net2 input element (the two block means, the hole flag and the float16 of t) next to the three mean images it already writes, with the bits fg_net2_merge_pixels builds from them, so the executor skips that dispatch and its barrier in both net2 paths. The Full blend op now carries t. Used only when the kernel is present and outputs are not kept for readback.
…rectComposition entry points load at run time fg_full_blend / fg_full_blend_merge: the driver's packed float16 conversion does not quiet a NaN the way fg_f2h does, so a lane holding a NaN now converts through fg_pack_h2 (a rare, branch-guarded path); the Full-path input-SRV cases (131-wide frames) match the 86105a8 kernels bit for bit again. Preset A 2x costs about +20 us against the unfixed kernel. Presenter: DCompositionGetFrameId / GetStatistics / GetTargetStatistics / CreateSurfaceHandle (bound by ordinal through dcomp.lib, which fails to load the module on Windows Server 2022), CreateDevice3 and CreatePresentationFactory are resolved with GetProcAddress on first use; a missing export is an ordinary failure. dcomp.lib is no longer linked.
…multi-frame batching, hoisted per-index work, split shared queue work (all exact, each with an off switch) Phase 0: WRONGGPU_FG_KPROF=1 / FgD3d12ExecutorDesc::kernel_profile times every launch (kernel, workgroups, ordinal), including net1's raw dispatches; TakeTimings also reports the wall-clock span and the busy time of every queue on one clock. test_fg_d3d12_e2e --bench takes --gen 1..5 (2x..6x, really recorded), --kprof and --batch / --hoist / --dualq 0|1 for paired runs. Phase 1: the per-index images live in scratch banks (one per generated index). RecordGeneratedBatch records layer k of every index back to back, so the barriers sit only between dependent layers (WG_FG_BATCH=0 off; the session batches consecutive generated indices when the executor asks for it). The per-index MA / MB fills and intermediate-time scatters of every index run on a second compute queue beside net1 (WG_FG_HOIST=0 off). The downsample runs beside the motion / p2c chain on the game queue (WG_FG_DUALQ=0 off). The kernels and their arguments are unchanged; only where and when independent work is recorded differs.
… mask, tiled hole rule, both intermediate-time passes with LDS-binned minima, net2 L25 heads staged in one pass), all exact and switchable (WG_FG_FUSE=0) fg_lite_p2c_fine_mask runs the hole mask on the value the fine pass finishes (net1 grid = scatter grid), dropping one launch and one read of F. fg_lite_p2c_inpaint_tiled computes the 5 x 5 hole rule on 32 x 8 tiles from ballot row masks (1.7 loads per pixel instead of 5). fg_lite_interm_both runs both passes in one launch and bins each tile's scatters in a 32 x 32 window of signed 64-bit LDS cells before one global minimum per cell (min is associative and commutative, the result is the same bits). fg_net2_mconv_h3b1u_s3 stages L25's three heads in one pass. The kernels they replace are unchanged (their DXIL is byte-identical to the previous build). CPU proofs of the exactness arguments in clean/fg/tests/test_fg_turbo_v2.py; test_fg_d3d12_e2e --gpu --only turbo compares every lever on against every lever off byte for byte; fg_lite_d3d12_check.py --turbo checks the new kernels against the CPU reference.
…ther lever switches
…sidual pairs, upwarp in L14's staging, blend weights in the blends, pyramid tail, RGB X0 / X1), all exact and switchable (WG_FG_FUSE2=0) Eighteen kernels beside the ones they replace (whose DXIL is byte-identical to the previous build); each lever is used only when its kernels are in the kernel folder and its bit is wanted (FgD3d12ExecutorDesc::fuse2: 0 off, 1 all, or a mask). - fg_mconv2_mid_cells: net1_01 builds its cells in LDS from the images fg_lite_net1_input packs (and writes Qc / Om itself): no input launch, no cell tensor round trip. - fg_net2_mpair_res_c64 / _c32: net2's residual pairs (L4+L5 .. L10+L11, L16+L17 .. L22+L23) in one launch on 14 x 6 interiors; the first layer runs on the region with its border and stays in LDS; both layers are the single-layer kernels' code. - fg_net2_mconv_m1b2_uw / _m1b2s_uw: L14 evaluates the upwarp for its staged tile (shared with fg_net2_upwarp through fg_net2_upwarp.hlsli) and writes U4 / U1 / U3 itself: no y tensor, no upwarp launch. - fg_lite_blend_w / _pack_w, fg_full_blend_w / _merge_w: the blend builds the W texels its tile's taps touch in LDS (fg_weight_texel, a copy of fg_lite_weights' body): no weights launch. - fg_out_tail (the coarsest pushes in one workgroup, as many levels as fit 28 KB) and fg_out_push_fine_l1 / _pack_l1 (level 1 pushed on the spot at the holes' taps). - fg_full_blend_*_x3 / fg_out_pull_x3: X0 / X1 stored as 3 x float16 (nothing reads their alpha). RGA (gfx1201): 0 spills, 0 scratch, at most 152 VGPRs. CPU proofs of the exactness arguments in clean/fg/tests/test_fg_turbo_v2.py; test_fg_d3d12_e2e --gpu --only turbo compares every lever on against every lever off and Wave 1B alone against Wave 1, byte for byte; --bench takes --fuse2 0|1|MASK.
…er per queue, so no buffer has writes from two queues in flight; the turbo test no longer re-claims COMMON for textures it already moved The debug layer's "Simultaneous-access or Buffer Resource is still referenced by write | transition_barrier GPU operations in-flight on another Command Queue" is raised for any two queues that use one buffer at the same time, UAV dispatches included (a two-queue program with the same shape raises it with and without transition barriers; one buffer resource per queue over the same heap memory raises nothing). The dual-queue and hoist levers do run the game queue's downsample and the second compute queue's fills / scatters beside the producer queue's work on disjoint ranges of the arena, so: - the arena is one heap with a placed buffer per queue that works in it at once (producer: arena, game queue: arena_game, second compute queue: arena_aux); the kernels see the same offsets through each, every recording uses its queue's alias (Rec::ares, Impl::ArenaFor) and starts with an aliasing barrier; fences still order every hand-over; - the driver-channel UAV of the descriptor tables is one buffer per queue's recordings as well. Test: TestTurboExact uploaded game frame 1 twice, the second time claiming the textures were in COMMON (state before = COMMON) when the first upload had left them in their input states: that was the "Before state ... does not match" error, not the executor.
… in paired timing (net1 cells + pyramid tail); the others stay opt-in Paired ABBA at 2560x1440 on an RX 9070 XT (6 rounds, 200 frames): all six Wave 1B levers together cost +13 .. +306 us per game frame over Wave 1 (preset A 2x..6x, preset C 2x..6x); the weights-in-the-blend lever (A13) is the worst (+60 .. +245 us), then net2 pairs (A7) and the upwarp in L14 (A9) on preset A, and RGB X0 / X1 (A12) is neutral. Net1 cells (A6) and the pyramid tail (A14) win alone and together. - fuse2 = 1 (the default, WG_FG_FUSE2 unset) now means mask 17 (A6 + A14); 63 runs every lever; any other value is still a mask; 0 is off. - test_fg_d3d12_e2e: --only turbo runs the Wave 1B legs against every lever on (63) by default; --turbo-fuse2 MASK picks another mask (--turbo-fuse2 1 runs the executor's default levers). Both are byte-exact with the D3D12 debug layer at 0 errors.
…itchable (fuse2 bits 64-1024, WG_FG_NET2_BATCH) A15 (64): fg_lite_fill16_p2, the fill without integer divisions. A lane's eight units are the same four words for every lane (first is a multiple of 8, the period 1, 2 or 4 divides 8), so the 16-byte word is built once and the tail unit is i & (period - 1). RGA: 9 v_mul_hi_u32 -> 0, 329 -> 82 instructions, 22 -> 5 VGPRs. Same grid and arguments. A16 (128): the _b kernels (fg_lite_blend / _pack, fg_lite_weights, fg_full_blend / _merge, fg_out_pull / _pack) read a bilinear tap row with one 16-byte (float16 x 4) or 8-byte (float16 x 2) load, since x1 is x0 + 1 or x0 itself at the frame border. The same four texel values reach the same fma chain. RGA: loads 34 -> 20 (light blend), 30 -> 18 (full blend), 12 -> 8 (weights), 19 -> 15 (pull); VGPRs up by 0 to 10 (at most 64, the 16-wave cap is unchanged); no scratch. A17 (256, 512): fg_lite_blend_t / _pack_t run 32 x 8 pixel tiles (tiles_x * ceil(ho / 8) workgroups) with an 8-byte pair store in the packed output and no per-pixel division; fg_out_pull_q skips the four divisions of a pyramid level on tiles without a hole, where the weight is 4^m and the division is the exact power-of-two scale. RGA: per-pixel division 1 -> 0. A18 (1024, WG_FG_NET2_BATCH=0 off): the _z twins of net2's fg_net2_mconv kernels (WG_Z_GRID, FG_ZB) take the launch of every index of a batch as one (groups, 1, N) dispatch; slice z adds z * bank stride to the pointers that differ between the frames. FgPlanZBatch decides it from the recorded arguments (CPU-tested); any other launch stays separate. The originals and their checkers are unchanged. WG_FG_FUSE2=17 is the Wave 1B default; the new default is 2001 (17 + 64 + 128 + 256 + 512 + 1024) and 2047 is every lever. The e2e turbo test now runs every lever against every lever off. Every unmodified DXIL is byte-identical to the previous set. CPU proofs: clean/fg/tests/test_fg_turbo_v2_wave2.py.
…l16 without divisions + A17 output pull power-of-two skip) Paired ABBA at 2560x1440 on an RX 9070 XT (gpu_span_per_frame, 10 rounds, interleaved, median of per-round diffs vs mask 17): mask 593 is -13 us (Preset A 2x), -1 us (C 2x), -52 us (A 6x) and -52 us (C 6x). A16 bilinear row loads (128) cost +4 to +56 us and A17 light blend tiles (256) cost +14 to +28 us on Preset C, so they leave the default; A18 net2 z-batching (1024) is neutral to worse (mask 1617: A 6x -34 us, C 2x +24 us), so it stays opt-in too. Mask 2001 (the previous default) was +14 to +20 us against 17, mask 2047 +44 to +353 us. Every lever stays switchable (WG_FG_FUSE2=MASK, --fuse2 MASK). Exact: --gpu --only turbo --debug-layer with masks 2047, 2001, 17 and 1 (the new default, 593) over Presets A / B / C and N = 1 .. 5 (2x .. 6x): 0 byte differences against every lever off, 0 Debug Layer errors; the full --gpu --debug-layer suite passes (1368 checks, 0 failed). WrongGPU-FG.asi has no dcomp.dll import.
…ftmax self-check digest for the WG_Z_GRID line in wg_platform.hlsli test_fg_turbo_v2_wave2.py was committed with CR LF (tools/ci/check_line_endings.py). Wave 2's WG_Z_GRID block in wg_platform.hlsli (the default 0 leaves WG_KERNEL as before) is in the include closure of Model K's softmax self-check kernels, so k_smx_selfcheck.h's kSourceDigest no longer matched (clean/k/dx12/smx_selfcheck_digest.py); only the digest line is updated (the reference hashes come from the HIP kernels, which this change does not touch). test_k_smx_selfcheck_digest, test_dev_diagnostics_off, test_build_models and the FG turbo v2 tests pass locally.
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.
Summary
Bit-exact D3D12 kernel and executor optimizations for Frame Generation (Presets A & C, 2x-6x) stacked on
fg/070-rc-integration(86105a8).Key Optimizations (all bit-exact, 116/116 E2E checks pass)
fg_full_blend.hlsl,fg_out_pull.hlsl,fg_lite_r3.hlsl,fg_lite_p2c.hlsl,fg_lite_g.hlsl,fg_net2_merge_pixels.hlsl,fg_fp16.hlsli,fg_d3d12_executor.cpp): tiled/fused passes, batchedwg_to_f16_agsconversions, and native FP16 paths where bit-exact.fg_mconv.hlslfg_accumulate_halo): software-pipelinestap+1VMEM weight and LDS halo loads ahead oftap's WMMAs onfg_mconv2_mid,fg_mconv2_narrow,fg_mconv1_late(-1.6%onnet1, 69-87 VGPRs, 0 spills).fg_net2_mconv.hlslfg_conv_tile): unrolled 9-tap prefetch pipelining gated toFG_STAGE && (FG_MT * FG_NB <= 2)(h3b1u, h3b2u, m2b1, m1b2, m1b2u, m1b1u, m1b2s), cuttingnet2by -5.0% (1.0178 -> 0.9669 ms, 71-120 VGPRs, 0 spills).Verification (RX 9070 XT
gfx1201,2560x1440, paired 3x ABBA vsfg/070-rc-integration86105a8)86105a8)test_fg_d3d12_e2e.exe --dxil ...:cpu: 116 checks, 0 failed;fg_d3d12_e2e: 116 checks, 0 failed.proxy-rel, ReleaseWrongGPU-FG.asi): 35/35 tests passed.tools/ci/check_line_endings.py: 1596 files checked, 0 problems.