Repository navigation
Model L (D3D12): l_mode=fast (~3.25 ms at 1440p Q, -26% vs exact) - #305
Draft
phantoslayer21 wants to merge 5 commits into
Draft
phantoslayer21 wants to merge 5 commits into
phantoslayer21 wants to merge 5 commits into
Conversation
…, with the decoder skip); l_mode=hybrid stays the default l_mode=hybrid|fast (runtime option, or env WG_L_MODE; the option wins; unset = hybrid). Fast, native D3D12 only, runs Model L on Model M's WMMA / FP8 _nc kernels with Model M's fusions (pm, xe, mb, xo, rv) and Model L's (ll, le, lc), on Model L's own values (the packers without the hybrid values), the C1/C2 reconstruction and the fused l_post_tf_p12[_pf] as the hybrid route's. The decoder block takes Model L's skip S = the encoder block's map l_x3: l_swin_block_c32_dec_coef12_add_nc / l_swin_block_c32_dec_add_nc (clean/dx12/kernels/l_swin_fast.hlsl: SW_ADD 1, SW_SRC 2, WG_LD_A16 on, 96 / 95 VGPRs, no spills; swin_block.hlsl only relaxes its #error for this one combination, so every other kernel's preprocessed input is unchanged). Hybrid is untouched (same kernels, same launches); warm_up leaves each mode's other kernels out (Device::warm_up_skip). Refusals by name: wrong value, fast off D3D12, fast with WG_L_FORM, a missing kernel, weights that need the clamped block, no bmegahg bottleneck build. Tests: clean/l/runtime/tests/test_l_runtime_fast_mode.py.
…and the encoder block's linears without the hybrid's bit-exactness l_mode=fast launches a "<kernel>_fast" twin in place of a base kernel when the build has one (same arguments; the base kernels, the hybrid twins and everything l_mode=hybrid runs are untouched, a build without a twin runs the base kernel): - w64_lc12/l_post_tf_p12[_pf]_fast (new l_post_tf_fast.hlsl): no driver intrinsic channel and no opaque-zero guards; native FP16 packs with the round-to-nearest bias folded into the multiplier; the gather weight is one v_exp_f16 and the total weight is summed in FP16 from the weights of the nine features; no FP16 code table (1 KB LDS, a barrier, six lookups per texel); Dec as exp2(q k) - 1 for every lane; the filter ring in FP16 pairs (LDS 26752 -> 23040 bytes). Options in pitch_bytes: the weaker history candidate as a bilinear (bit 0), and not read twice when its motion equals the first's (bit 1). - l_project_gather_fast / l_dec_project_fast: the K blocks accumulate in FP32 and round once, in the FP8 pack. - l_swin_block_c32_enc_lin_nc_fast: the linears' results stay FP32 (TT_LINF32). RGA (gfx1201), VALU instructions: post 2096 -> 1703 (pf 2356 -> 1705), project_gather 537 -> 281, dec_project 675 -> 419, enc_lin 997 -> 893; no spills, VGPRs within each kernel's bound. runtime: l_fast_alt maps each base kernel to its twin; warm-up leaves out the twins for l_mode=hybrid and, for l_mode=fast, the hybrid twins, the replaced base kernels and the twins of levers that are off; a developer build reads WG_L_FAST_MASK (an A/B of each lever; no such string in a release build, check_no_dev_diagnostics lists it). Tests: CPU accuracy bounds (clean/l/tests/test_l_fast_numerics.py), the twins' dispatch and the mask (test_l_runtime_fast_mode.py), kernel_sets.json.
…centred 3 x 3 post gather, two windows per wave in the width-32 blocks, quick GELU, c64 twins New fast-mode kernels, each launched in place of a base kernel with the same arguments (runtime kLFastAlts / the "<kernel>_fast" twins; every existing DXIL is byte-identical, swin_block.hlsl is not touched, l_mode=hybrid launches none of them): - w64_lc12/l_post_tf_p12[_pf]_fast3 (l_post_tf_fast.hlsl LP_WIN3, lever 256 with lever 1): the gather over the 3 x 3 render texels centred on each D pixel (every tap within 1.5 render pixels; each row of a pair with its own centred rows, the row n0 + 2 read under a wave-uniform branch) instead of the 4 x 4 window: 18 taps per row pair instead of 32. Staging cap 448 texels (LDS 23040 -> 21504 bytes); a frame whose step footprint does not fit (l_tf3_supported) runs the 4 x 4 twin. - l_swin_block_c32_enc_lin_w2[t]_fast (lever 512) and l_swin_block_c32_dec_coef12_add_w2[t]_fast (lever 1024), new l_swin_c32_fast.hlsl: two windows per wave in 128-lane workgroups (swin_c64w2.hlsl's launch shape: weight fragments, biases, norm vectors and the linears' weights loaded once for both windows, a barrier waits for 4 waves); the softmax without the maximum (the soft cap bounds the exponents to +-11); the decoder's coefficient store one pixel per lane in FP32 (the hh = 1 lanes take the second window's channels by v_permlanex16; no FP16 rounding of y2, tanh as 1 - 2 / (2^(2 t log2 e) + 1)). GELU: quick GELU x / (1 + 2^(-2.53 x)) in "_w2_fast" (lever 4096; no table load; max error 0.016, RMS 0.009 against the model's GELU), the arena table (the model's GELU bytes) in "_w2t_fast". - swin_block_c64_nc_fast / swin_block_c64_add_ex_nc_fast (lever 8, new l_swin_c64_fast.hlsl): the same body at C = 64. RGA (gfx1201), issue slots per window (without s_delay_alu / s_code_end), VGPRs, no spills: decoder block 1568 -> 978 (w2t 1044), 149 / 172 VGPRs; encoder block 1368 (enc_lin_nc_fast) -> 1090 (w2t 1147), 139 / 164 VGPRs; c64 1780 -> 1644, c64_add_ex 2118 -> 1995 (192 VGPRs, the base kernels' tier); the post 2683 -> 2520 static (96 VGPRs, 2 workgroups per CU as before). Quick GELU trades table loads for the exponential unit: w2 320 trans / 49 buffer loads per wave, w2t 64 / 177. runtime: WG_L_FAST_MASK default 127 -> 6015 (every lever but 128 and 2048, the latter reserved for a bottleneck twin); warm-up leaves out the fast kernels the mask does not select (the 3 x 3 post's 4 x 4 twin stays warm); build_dx12.py fast_base names the kernel each fast-mode kernel replaces (is_model_l, the trace's argument kinds). Tests: quick GELU, the softmax without the maximum, the fast coefficient store and the 3 x 3 gather by kernel width (test_l_fast_numerics.py: 3 x 3 vs 4 x 4 52.9 dB on texel noise at sigma 0.5 render pixel, 30.6 dB at sigma 1: lever 256 is the first one to A/B on the GPU), the selection, the warm-up and the footprint fallback (test_l_runtime_fast_mode.py), kernel_sets.json.
…c GELU in the width-32 and width-64 twins, width-96 twins; 3 x 3 post off by default RX 9070 XT (2B-3, 8d0e32f): the 3 x 3 post gather (lever 256) failed the HDR gate (38.7 dB / SSIM 0.955 against 53.2 dB / 0.998 with the 4 x 4 gather); quick GELU x / (1 + 2^(-2.53 x)) was 44 / 56 us slower than the table form in the width-32 blocks and 7 / 18 us slower in the c64 twins (its exponential and reciprocal run on the quarter-rate transcendental unit). Best clean mask there: 1655, 3.266 ms. - GELU (l_swin_c32_fast.hlsl LF_GELU 1): 2 GELU(x) = x + |x| min(P(|x|), 1), P a cubic fitted (weighted minimax) to the model's GELU: |x| by an AND with an opaque mask, three v_fmaak, a v_min, a v_fmac, all of them VOPD-pairable (RGA: the driver pairs most of them), no exponential, no table load. The W2 products accumulate onto twice the residual (the accumulator doubled with b2 after norm2, halved at the output / coefficient store: exact power-of-two scalings, FP8(2 g) = 2 FP8(g) for every normal code), so the halving is no operation per value. Max error 0.0020, RMS 0.0014 against the model's GELU (quick GELU: 0.016 / 0.009), 84.8 % of the FP8 codes unchanged. The hidden values' FP8 range without a clamp is |h| < 224 (the table form's: 448). Kernels: l_swin_block_c32_enc_lin_w2p_fast / l_swin_block_c32_dec_coef12_add_w2p_fast (lever 512 / 1024 with 4096, replacing the quick-GELU "_w2_fast" ones; without 4096 the table twins "_w2t_fast"), swin_block_c64_nc_fast / swin_block_c64_add_ex_nc_fast (lever 8). - Width-96 twins (lever 8192, new l_swin_c96_fast.hlsl): the same body in the base kernels' launch shape (256 lanes, one window per wave), the clamped-cubic GELU (no groupshared table: LDS 26 624 / 28 672 -> 24 576 bytes) and the softmax without the maximum: swin_block_c96_add_ex_nc_fast (dec2, the fused expand) and swin_block_c96_pm_rev_nc_fast (enc2 with enc1's patch merge as its prologue: fused_swin.hlsl's SW_PM code, FZ_PMT 1, its aux / aux2 arguments appended to swin_block.hlsl's argument block by WG_ARGS_END). - No bottleneck twin (lever 2048 stays reserved; the persistent bmegahg kernel is generated and measured sensitive to its compiled form), no post or encoder change (a packed FP16 feature sum in the post gather compiled to the same ISA: the driver scalarizes it). RGA (gfx1201), per wave, loops expanded (base c96: head loop x4 / x2, MLP loop x2), no spills (scratch 0, VGPR / SGPR spills 0); slots without s_delay_alu / s_wait / s_nop: enc0 c32 w2t 164 VGPRs, 2027 slots, 1514 VALU, 41 trans, 192 buffer loads -> w2p 139, 2080, 1696, 41, 64 dec0 c32 w2t 172, 1846, 1391, 65, 177 -> w2p 150, 1880, 1554, 65, 49 enc1 c64 base 191, 3236, 2326, 169, 286 -> fast 192, 3244, 2531, 41, 94 dec1 c64 base 192, 3858, 2774, 169, 324 -> fast 192, 3916, 3026, 41, 132 enc2 c96 base 173 / 26 624 B, 4480, 2865, 39, 216, 451 ds -> fast 186 / 24 576 B, 3264, 2126, 39, 160, 300 ds dec2 c96 base 192 / 28 672 B, 4524, 2973, 39, 231, 417 ds -> fast 181 / 24 576 B, 3404, 2294, 39, 175, 257 ds The width-32 / width-64 twins trade the table loads (and in c64 128 transcendentals) for 1 to 3 % more issue slots; which one is faster is the GPU A/B of lever 4096 (w2p against w2t) and lever 8. The width-96 twins have 25 to 27 % fewer slots. runtime: WG_L_FAST_MASK default 6015 -> 13951 (every lever but 128, 256 and 2048), kLFastAll 16383; l_fast_bit: c96 -> 8192, bneck -> 2048, the other swin_block_* -> 8. build_dx12.py fast_base / runtime_frame_trace: "_w2p_fast". Every other DXIL of the build is byte-identical (135 of 139 entries; changed: the two c64 twins; replaced: the two "_w2_fast"); hyb_isa_scan clean on the 26 hybrid kernels. Tests: PolyGelu (constants, error bounds, shape, the doubled accumulator, FP8 codes) in test_l_fast_numerics.py, the new default and lever 8192 in test_l_runtime_fast_mode.py, kernel_sets.json, vgpr_limits.json.
… block's coefficient store, 8 KB width-32 staging; post options 16384 / 32768 (off) - l_swin_c32_fast.hlsl: the coefficient store reads channels 0..12 only, so the decoder block's W2 runs one output tile (LF_W2_ONE: tile 0 remapped to channels 0..15 by a lane exchange of tile 1's rows; the same products and the same accumulation order per stored channel): 128 -> 112 WMMAs, _w2t_fast 188 -> 165 VGPRs. The width-32 twins stage 2 x 4 KB of MLP weights (SW_HPU=4: 8 KB of LDS instead of 16 KB). - l_post_tf_fast.hlsl: history / A8 loads with their 8-byte alignment stated; option bit 3 (lever 16384) gathers the 4 x 4 window without its four corner taps, option bit 4 (lever 32768) blends two history candidates in the encoded domain and decodes once. Both off by default: 16384 measured 43.2 dB / SSIM 0.982 HDR 1440p Q and 40.5 dB 640 x 360 HDR against the hybrid route (below the gate); 32768 showed no gain. - runtime.cpp: the default selection is 9847 (levers 8 and 4096 off: neutral and +20 us in the A/B); kLFastAll 65535. - Tests and SPEED.md follow the new default. RX 9070 XT, 1440p Q, 6-round ABBA (median of rounds): hybrid 4.3805 / 4.4146 / 4.4160 ms, l_mode=fast (release) 3.2456 / 3.2421 / 3.2419 ms at pi 1.0 / 1.25 / 2.0. l_mode unset and l_mode=hybrid: 0 of 232 buffers differ from 8c07199 (1440p Q HDR / LDR, 640 x 360 HDR), no NaN / Inf. l_mode=fast against hybrid: tone-mapped PSNR >= 49.9 dB steady, SSIM >= 0.9976, no NaN / Inf in the output or the history; the release DLL is bit-identical to the developer build at mask 9847.
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.
Adds the opt-in / default-selectable \l_mode=fast\ path for Model L on native D3D12 (stacked on #298):
f=0\ (-1.14 ms / -26% vs \l_mode=hybrid\ 4.389 ms).