Repository navigation
Model L & M (D3D12): hybrid Swin/bneck/post/project speedups (-0.320 ms Model L at 1440p Q, byte-identical) and m_mode presets - #298
phantoslayer21 wants to merge 9 commits into
Conversation
…ms Model L at 1440p Q, byte-identical) and m_mode presets
…switch (default off) Hybrid decoder blocks with their expand fused in (swin_block.hlsl SW_HYB with SW_ECL; hyb_swin.hlsl): swin_block_c96_add_ex_hyb (dec2, SW_ECL 128) and swin_block_c64_add_ex_hyb (dec1, SW_ECL 96). The expanded input E is computed per window into LDS with the hybrid FP8 point (hyb_q8_of_chain) and read through the coarse mirror (the sw_coarse_src source of the unfused route), so expand_c128_hyb + swin_block_c96_add_hyb and expand_c96_hyb + swin_block_c64_add_hyb become one launch each and the expanded map is never stored. 0 spills, 118 / 158 VGPRs, LDS unchanged, hyb_isa_scan rules 1 and 2 pass, both *_scanmut mutants fail them. Runtime: WG_L_EXFUSE (default on when the manifest has both kernels; 0 = the unfused route) launches them through the M-form fused names and the hyb_map twins. test_hyb_fused_expand_addr.py checks the window / record addressing exhaustively (n = 16 .. 4100, offsets 0 and 2). l_post.hlsl: LP_W64 entries w64_lc12/l_post_recon[_p12][_ldr] (64-lane waves, FP16 code table from f32(k) f32(1/255) exact for all 256 codes, r_prev from the first lane, QuadReadAcrossX). The driver's matrix conversions are wave32-only, so the wave64 form converts in software: RGA gfx1201 7605 -> 12922 instructions. Runtime WG_L_POST_W64=1 (default off, a measurement switch). The lc12 entries are byte-identical DXIL to before. Every kernel that includes a changed source was rebuilt: the 41 pre-existing ones have the same DXIL sha256 as before. kernel_sets.json regenerated, vgpr_limits.json has the two new bounds, test_l_runtime_frame covers the fused route and the toggle.
Model L, 1440p Quality (1706x960 -> 2560x1440), RX 9070 XT on Linux. The PR is faster in both measurements, but its output is not byte-identical on RADV. TimingOur whole-frame host improved by 0.384 ms per frame and was faster in 9/9 interleaved rounds. Your Profiled kernel changes were:
Exactness on RADVEach build is deterministic run to run, but main and the PR differ. Across 31 stage buffers plus the output for three frames, at 64x40 -> 96x60, 77x45 -> 113x67, and 1440p Quality, only 38 of 93 dumped files matched main. The output image differs, as do the hipbench checksums above. The first differing buffer is the c32 encoder block's map, written by Single-kernel and single-source-change diagnostic builds at 64x40 isolated the scope:
A CPU check in IEEE arithmetic gives main's ACO registersOn gfx1201, RADV statistics show Setup: RX 9070 XT (gfx1201), D3D12 kernels through Wine + vkd3d-proton Not tested: Windows, real model weights, RDNA 3, or Model M's new Two questions:
|
…re-exposure division folded, wave64 hardware FP16 conversion L-W2.1. One wave64 kernel of 512 lanes (kernels/l_post_tf.hlsl, tags w64_lc12/l_post_tf_p12 and _pf) replaces l_post_recon_p12 + w64/post_filter_c1_s4 + scale_rgb (the display image is never written): Model L's per-pixel reconstruction (the new shared l_post_core.hlsli, moved from l_post.hlsl unchanged: the wave32 DXILs / ISA of every l_post kernel are identical) inside Model M's post_tf walk (ring of display rows in LDS, analytic Lanczos passes, Dec, store times dec_scale with scale_rgb's bits folded in). With pi != 1 the staged route's division is folded into lev/input_encoder_q20_pf and the _pf post (wg_pidiv.hlsli, as Model M's _pf kernels): no color_divide launch. Wave64 FP16 conversions are the driver channel's single-value hardware conversion (op 0x1C, one v_cvt_f16_f32, as rr_d0r.hlsl): standalone w64_lc12/l_post_recon_p12 12916 -> 8443 instructions. RGA gfx1201: l_post_tf_p12 4289 inst / 84 VGPR / 26752 B LDS / 0 spills; _pf 4916 / 84. Runtime: WG_L_POST_TF (default on when the kernels are in the manifest; 0 = the separate launches), HDR staged route only. Tests: FusedPost in test_l_runtime_frame.py; the other tests run the separate route (WG_L_POST_TF=0).
…bar switch) and test notes
…locks, arithmetic GELU, wave64 projections (WG_L_W3) Every lever is its own set of kernels beside the wave 2 ones (WG_L_W3 mask, default 0x17, 0 = wave 2), selected only when the manifest has them; same arguments, grids and bytes. - SW_DIRECT_W: the C = 32 / 64 hybrid blocks read their weight fragments straight from global memory (no LDS staging, no barriers; the C = 64 fused decoder block keeps only its 8 KB of expand records and 2 barriers). - HYB_GELU_POLY: q8(GELU16(h)) as packed FP16 arithmetic (hyb_gelu_poly8) instead of the 128 KB table's gathers; exact for all 65,536 inputs (test_hyb_gelu_poly.py), both multiplies feeding an add behind the contraction barrier, pinned by FMA counts in isa_checks.json. Applies to C = 32, 64, 96 and the bottleneck. - l_project_gather_w64 / l_dec_project_w64: wave64 design D, weights shared by both token tiles. - l_swin / hyb_swin / hyb_bneck: *_w3, *_gp (ablation), *_w3p (c96 with the MLP-pairs knobs) and their _scanmut mutants. - vgpr_limits.json, kernel_sets.json, build_dx12.py (is_model_l), fused_swin_gen.py anchor, runtime trace and frame tests.
…0 encoder at 96 VGPRs (WG_L_W4) Each lever is its own set of kernels beside the wave 3 ones (WG_L_W4 mask, default 0x3, 0 = wave 3 frame), selected only when the manifest has them; same arguments, grids and bytes. Every wave 2 / 3 kernel's DXIL is unchanged (new defines LP_W4 / ENC_W4). - l_post_tf_p12[_pf]_w4 (bit 0): history_cr's six span loads in one burst (LP_HSEQ 0): RGA 86 VGPRs (84 before), inside the 96 that keep the LDS-capped 2 workgroups per CU. _w4m (bit 2): the motion loads issued ahead of the last gather column (96 VGPRs). Ablations that RGA showed as no-ops are knobs, off: uint2 staging (LP_W4_LDS2), h(uu kA) shared by both rows, half2 sums, unrolled column loop (the driver already merges the dwords and shares the product). - lev/input_encoder_q20[_pf]_w4 (bit 1): 96 VGPRs (104 / 106 before: the 96-register tier): the fourth history position's loads after the first three's values, the uniform loads through readfirstlane, slot 0's stores before slot 1. - vgpr_limits.json / build_dx12.py (vgpr_checked), kernel_sets.json, runtime WG_L_W4, trace signatures and frame tests.
… wins (WG_L_W3 = 0, WG_L_W4 = 0x1) Every lever stays selectable by its mask bit; only the defaults change. Byte-exact in every configuration: 10080 buffers (small, 1705x960 -> 2560x1440, 1706x960 -> 2560x1440; pre-exposure 1, 1.25, 2, 1e38; HDR and LDR; reset and non-reset frames) identical to WG_L_W3=0 WG_L_W4=0 for masks 0x17/0x03, 0x37/0x07 and 0x08/0x00, and 3360 buffers again with the rebuilt default library. Paired ABBA, 8 rounds, 1440p Quality, pre-exposure 1.25, unprofiled frame span (us vs W3=0 W4=0, 4486 us): W3 0x01 c32 direct weights + poly GELU +111 W3 0x08 c32 poly GELU only +96 W3 0x02 c64 direct weights + poly GELU +51 W3 0x04 c96 + bneck6 poly +56 W3 0x24 c96 _w3p + bneck6 +47 W3 0x10 wave64 projections +18 W4 0x01 post (history burst) -8 W4 0x05 post + motion +17 W4 0x02 q20 encoder at 96 VGPRs +6 default 0x17 / 0x03 +244 The per-dispatch GPU profile confirms the routed kernels ran; the poly-GELU and direct-weight forms cost more than the LUT/LDS forms they replace on gfx1201 (c32 blocks 746.7 -> 818.6 and 706.9 -> 801.8 us). Only W4 0x01 is faster (w64_lc12/l_post_tf_p12_pf 896.4 -> 885.8 us); 0x02 is neutral (190.3 -> 190.2 us). Confirmation, 10 rounds, W4 0x1 vs 0: -10.4 us at pre-exposure 1.25, -8.2 us at 1.0 (W4 0x3: -11.0 / -2.7, no better). Scaling at pre-exposure 1.25, 6 rounds, paired vs W3=0 W4=0 (final default; the old 0x17/0x03 default): 1080p Q 2644.5 -> 2642.4 (-1.3; +135.5) 1440p Perf 3007.0 -> 2999.7 (-8.6; +133.8) 1440p Q 4483.6 -> 4477.0 (-4.8; +244.8) 1440p DLAA 9382.1 -> 9374.5 (-7.3; +560.1) 4K Q 10060.2 -> 10052.1 (-8.2; +532.6) Tests follow the new defaults (WG_L_W3 unset = the wave 2 kernels, WG_L_W4 unset = the post only).
…n comments, prune Wave 3/4 dead variants Fixes two RADV/vkd3d-proton/ACO bit-exactness divergences in the hybrid Swin blocks (l_swin_block_c32_enc_lin_hyb and siblings) while keeping VMEM/LUT latency hiding intact: - hyb_block.hlsli (hyb_softmax_pre): restore compiler-proof FP32 hyb_softmax_e8(hyb_round16(s)) instead of FP16 mad(half2) (which splits under vkd3d-proton FMad NoContraction) and FP16 score scaling/clamping, keeping the HybSmaxPre / hyb_softmax_fin split to hide hyb_rcp16 LUT latency behind Wv. - swin_block.hlsl (norm2 b2 add, plain hybrid and SW_Q7_CHUNK): restore FP32 add + AGS RN16 (hyb_add16 / hyb_rn16x8) instead of fptrunc + fadd half. - Clean stale Matrix || Vector overlap comments across swin_block.hlsl, fused_swin.hlsl, and l_ops_project.hlsl (RDNA 4 has 0% WMMA+VALU overlap; the gain is VMEM/LUT latency hiding). - Prune regressive Wave 3 levers (WG_L_W3, _hyb_w3, _hyb_w3p, _hyb_gp, l_ops_project_w64.hlsl, SW_DIRECT_W, HYB_GELU_POLY) and neutral/regressive Wave 4 variants (ENC_W4, LP_W4_MOT, LP_W4_LDS2, LP_W4_H2), making the winning LP_HSEQ=0 burst the default in w64_lc12/l_post_tf_p12[_pf].
Summary
Bit-exact D3D12 hybrid kernel speedups for Model L on RDNA 4 (
gfx1201) plus Model Mm_mode(fast|hybrid|exact) and native D3D12q7csupport, and updatedclean/PERF.mdhardware overlap notes.Key Optimizations (all bit-exact, 0 byte diffs)
l_post.hlsl(-63.5 us,0.9012 -> 0.8377 ms): exact reconstruction/history-encode optimizations.swin_block.hlsl,fused_swin.hlsl,hyb_swin.hlsl,hyb_block.hlsli,wg_hyb.hlsli):swin_block_c64_add_hyb(-61.7 us),swin_block_c64_hyb(-54.0 us),l_swin_block_c32_dec_coef12_hyb(-48.8 us),l_swin_block_c32_enc_lin_hyb(-37.6 us),swin_block_c96_hyb(-8.5 us),swin_block_c96_add_hyb(-4.3 us).vgpr_limits.jsoncaps (256 -> 192VGPRs) forswin_block_c96_hyb,swin_block_c128_hyb,swin_bneck6_hyb, and*_q7c_hyb.hyb_bneck.hlsl: enabledWG_LD_A16=1onswin_bneck6_hyb(192/192VGPRs, 0 spills,hyb_isa_scanpass,scanmutfails as required).l_ops_project.hlsl: paired 2 output tiles (mt += 2u), coalescedwg_ld128/wg_st128+WG_LD_A16=1(l_dec_project-8.3 us,l_project_gather-3.9 us).m_mode/q7c(runtime.cpp,model.cpp,pipeline.py,equiv/model_m.py): addsm_mode=fast|hybrid|exactandSW_Q7_CHUNK(~-154 usfaster Model Mexact, 0 byte diffs across 78 dumps).clean/PERF.md: documents cycle-verifiedgfx1201WMMA vs VALU serialization and genuine SALU/VMEM/LDS/occupancy overlap.Verification (RX 9070 XT
gfx1201, 1440p Quality1706x960 -> 2560x1440)4.7426 msmedian span (4.5465min,4.9566profsum)4.4228 msmedian span (4.2988min,4.6563profsum) — -0.3198 ms span / -0.3003 ms profsum vs v0.6.5hyb_isa_scan.pyPASS (0 fused squares, 0 FP8 bad),*_scanmutFAIL as required,WG_DX12_VGPR_CHECK=1PASS,test_equiv_model_m+test_model_select(21 tests) PASS,tools/ci/check_line_endings.pyPASS.