From aeac0e9e9b4495ac8a24b268dd6d93381a04a061 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:22:11 -0500 Subject: [PATCH 1/2] dx12: hybrid Swin chain with alternating workgroup order (Model L, same bytes) Model L's hybrid route ran every Swin-chain kernel with its workgroups in forward order. Five of them now run in reverse order (WG_REV_ORDER=1, the same mechanism the c32 encoder kernels already use), so that along the chain each consumer starts on the rows its producer wrote last: l_project_gather F -> swin_block_c64_hyb R -> patch_merge_c64_hyb F -> swin_block_c96_hyb R -> patch_merge_c96_hyb F -> bottleneck (unchanged) -> expand_c128_hyb R -> swin_block_c96_add_hyb F -> expand_c96_hyb R -> swin_block_c64_add_hyb F -> l_dec_project F -> l_swin_block_c32_dec_coef12_hyb R. Each workgroup does the same work on the same data: no in-place buffers, no atomics, the group index only through WG_SETUP. Declarations only; the other kernels' DXILs are unchanged. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/dx12/kernels/hyb_gemm.hlsl | 4 ++-- clean/dx12/kernels/hyb_swin.hlsl | 4 ++-- clean/dx12/kernels/l_swin.hlsl | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clean/dx12/kernels/hyb_gemm.hlsl b/clean/dx12/kernels/hyb_gemm.hlsl index ad980dea..1eca3f52 100644 --- a/clean/dx12/kernels/hyb_gemm.hlsl +++ b/clean/dx12/kernels/hyb_gemm.hlsl @@ -15,8 +15,8 @@ // // @wg-kernel patch_merge_c64_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_PM_C=64,SW_PM_CO=96,SW_PM_SPLIT=1 // @wg-kernel patch_merge_c96_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_PM_C=96,SW_PM_CO=128,SW_PM_SPLIT=4 -// @wg-kernel expand_c96_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_EX_CL=96,SW_EX_C=64,SW_EX_SPLIT=0 -// @wg-kernel expand_c128_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_EX_CL=128,SW_EX_C=96,SW_EX_SPLIT=1 +// @wg-kernel expand_c96_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_EX_CL=96,SW_EX_C=64,SW_EX_SPLIT=0,WG_REV_ORDER=1 +// @wg-kernel expand_c128_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_EX_CL=128,SW_EX_C=96,SW_EX_SPLIT=1,WG_REV_ORDER=1 // *_scanmut the ISA rules' mutants (probe=1, outside the manifest; build_dx12.py requires one per model hybrid // kernel): no RN16 before the FP8 pack (HYB_SCAN_MUTANT=1), rule 2 must fail (no norm tree here: rule 1 // has nothing to find) diff --git a/clean/dx12/kernels/hyb_swin.hlsl b/clean/dx12/kernels/hyb_swin.hlsl index ef4df9bc..ec622a6e 100644 --- a/clean/dx12/kernels/hyb_swin.hlsl +++ b/clean/dx12/kernels/hyb_swin.hlsl @@ -11,9 +11,9 @@ // (the table's shared_dec_border) and the skip map with the fine mirror; the member input is RN16(E + S). // HIP twins: the same names in swin_hyb.co (clean/kernels/swin_hyb.hip). // -// @wg-kernel swin_block_c64_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=64,SW_HEADS=2,SW_MLP=256,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c64_hyb +// @wg-kernel swin_block_c64_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=64,SW_HEADS=2,SW_MLP=256,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c64_hyb,WG_REV_ORDER=1 // @wg-kernel swin_block_c64_add_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=64,SW_HEADS=2,SW_MLP=256,SW_ADD=1,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c64_add_hyb -// @wg-kernel swin_block_c96_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=96,SW_HEADS=4,SW_MLP=384,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c96_hyb +// @wg-kernel swin_block_c96_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=96,SW_HEADS=4,SW_MLP=384,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c96_hyb,WG_REV_ORDER=1 // @wg-kernel swin_block_c96_add_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=96,SW_HEADS=4,SW_MLP=384,SW_ADD=1,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c96_add_hyb // @wg-kernel swin_block_c128_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=128,SW_HEADS=4,SW_MLP=512,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HYB=1,SW_ENTRY_OVERRIDE=swin_block_c128_hyb // swin_block_c64_hyb_scanmut / _c128_hyb_scanmut the fused-square scan's mutants (probe=1, outside the manifest; see diff --git a/clean/dx12/kernels/l_swin.hlsl b/clean/dx12/kernels/l_swin.hlsl index 9dacb5b0..418d6a44 100644 --- a/clean/dx12/kernels/l_swin.hlsl +++ b/clean/dx12/kernels/l_swin.hlsl @@ -43,7 +43,7 @@ // form, enc0.Win1, enc0.Win2 as the last arguments) and _dec_hyb with l_coef_pack12 as its // epilogue (SW_OUT_COEF12, COEF_CVT_HW); the same bytes as the launches they replace // @wg-kernel l_swin_block_c32_enc_lin_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u,p,p defines=SW_C=32,SW_HEADS=2,SW_MLP=128,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HPU=8,SW_GELU=0,SW_SRC=3,SW_HYB=1,SW_ENTRY_OVERRIDE=l_swin_block_c32_enc_lin_hyb,WG_REV_ORDER=1 -// @wg-kernel l_swin_block_c32_dec_coef12_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u,p,p,p,p,u,u defines=SW_C=32,SW_HEADS=2,SW_MLP=128,SW_ADD=1,SW_SAFE=1,SW_ECL=0,SW_HPU=8,SW_GELU=0,SW_OUT_F16=1,SW_OUT_COEF12=1,COEF_CVT_HW=1,SW_HYB=1,SW_ENTRY_OVERRIDE=l_swin_block_c32_dec_coef12_hyb +// @wg-kernel l_swin_block_c32_dec_coef12_hyb co=- block=256 wave=32 args=p,p,p,p,u,u,u,u,p,p,p,p,u,u defines=SW_C=32,SW_HEADS=2,SW_MLP=128,SW_ADD=1,SW_SAFE=1,SW_ECL=0,SW_HPU=8,SW_GELU=0,SW_OUT_F16=1,SW_OUT_COEF12=1,COEF_CVT_HW=1,SW_HYB=1,SW_ENTRY_OVERRIDE=l_swin_block_c32_dec_coef12_hyb,WG_REV_ORDER=1 // ..._enc_lin_hyb_dump / _dec_coef12_hyb_dump (+ _mutdump: SW_HYB_MUT_ORDER=4) their stage dumps (probe=1, check only: // l_hyb_stage_check.py --set fused, the oracle per stage); _scanmut: the fused-square scan's // mutants (no contraction barrier, built beside every hybrid build, outside the manifest) From 54c2951f55665b3edc362bd7e320ef54b4d01cac Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:46:50 -0500 Subject: [PATCH 2/2] dx12: note that WG_REV_ORDER reverses a 1-D dispatch only Beside the hybrid L kernels that use it (l_swin.hlsl, hyb_gemm.hlsl): a multi-dimensional launch must flatten its group index before the reversal. Comments only; the kernels compile to the same DXIL. wg_platform.hlsli itself stays unchanged, since its text is part of Model K's softmax self-check digest. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/dx12/kernels/hyb_gemm.hlsl | 2 ++ clean/dx12/kernels/l_swin.hlsl | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean/dx12/kernels/hyb_gemm.hlsl b/clean/dx12/kernels/hyb_gemm.hlsl index 1eca3f52..fb452e42 100644 --- a/clean/dx12/kernels/hyb_gemm.hlsl +++ b/clean/dx12/kernels/hyb_gemm.hlsl @@ -12,6 +12,8 @@ // groups one group at a time, the expand those of one sub-pixel k at a time when SW_EX_SPLIT (expand_c128: the four // sub-pixels' 48 KB do not fit D3D12's 32 KB). // HIP twins: the same names in swin_hyb.co (clean/kernels/swin_hyb.hip: swin.hip's patch_merge / expand with HYB). +// The expands run with their workgroups in reverse order (WG_REV_ORDER, 1-D dispatches; the same bytes), opposite to +// the bottleneck / dec2 block before them, so each starts on the rows its producer wrote last (Model L's hybrid chain). // // @wg-kernel patch_merge_c64_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_PM_C=64,SW_PM_CO=96,SW_PM_SPLIT=1 // @wg-kernel patch_merge_c96_hyb co=- block=256 wave=32 args=p,p,p,u,u defines=SW_PM_C=96,SW_PM_CO=128,SW_PM_SPLIT=4 diff --git a/clean/dx12/kernels/l_swin.hlsl b/clean/dx12/kernels/l_swin.hlsl index 418d6a44..b93d427c 100644 --- a/clean/dx12/kernels/l_swin.hlsl +++ b/clean/dx12/kernels/l_swin.hlsl @@ -14,7 +14,9 @@ // l_swin_block_c32_enc_nc the encoder block: FP16 halo map [H + 4][W + 4][32] in (SW_SRC 1), FP8 out // with its workgroups in reverse order (WG_REV_ORDER, wg_platform.hlsli; the same bytes): it // reads first the rows of x2 the linears wrote last, and its last-written rows of x3 are the -// ones l_project_gather reads first (more cache hits at both hand-offs) +// ones l_project_gather reads first (more cache hits at both hand-offs). WG_REV_ORDER +// reverses the group index of a 1-D dispatch only (a multi-dimensional launch must flatten +// it first); every kernel declared with it here and in hyb_swin.hlsl / hyb_gemm.hlsl is 1-D // l_swin_block_c32_dec_nc the decoder block: FP8 map in with the token-grid mirror (SW_SRC 2), FP16 out (SW_OUT_F16) // l_swin_block_c32_enc_lin_nc D3D12 only: the encoder block with the two input linears as its prologue (SW_SRC 3; // byte for byte the pair l_linear_32_32_fused -> _enc_nc, which stays the fallback route):