From 5d0897ca07a37729797c318391203a28f991a7b6 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:28:23 -0500 Subject: [PATCH] Model L D3D12: l_swin_block_c32_enc_nc in reverse workgroup order (WG_REV_ORDER; the same bytes) wg_platform.hlsli: a kernel declared with WG_REV_ORDER=1 has workgroup g do the work of workgroup G - 1 - g. The encoder block then reads first the rows of x2 the fused linears wrote last, and the rows of x3 it writes last are the ones l_project_gather reads first: both hand-offs hit the caches more often. Only l_swin_block_c32_enc_nc's DXIL changes; its outputs are byte-identical. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/dx12/hlsl/wg_platform.hlsli | 5 +++++ clean/dx12/kernels/l_swin.hlsl | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clean/dx12/hlsl/wg_platform.hlsli b/clean/dx12/hlsl/wg_platform.hlsli index adcdf2b9..65b6eee5 100644 --- a/clean/dx12/hlsl/wg_platform.hlsli +++ b/clean/dx12/hlsl/wg_platform.hlsli @@ -39,7 +39,12 @@ static uint wg_bid_; // workgroup index in the grid (HIP blockIdx.x) #define WG_KERNEL(name) [numthreads(WG_BLOCK, 1, 1)] [WaveSize(WG_WAVE)] \ void name(uint wg_sv_tid_ : SV_GroupThreadID, uint wg_sv_gid_ : SV_GroupID) +#if WG_REV_ORDER // a kernel declared with WG_REV_ORDER=1: workgroup g does the work of workgroup G - 1 - g (the same + // bytes; the last-written part of its input, likelier still in the caches, first) +#define WG_SETUP() (wg_tid_ = wg_sv_tid_, wg_bid_ = wg_grid_ - 1u - (wg_sv_gid_ + wg_group_base_)) +#else #define WG_SETUP() (wg_tid_ = wg_sv_tid_, wg_bid_ = wg_sv_gid_ + wg_group_base_) +#endif uint wg_lane_id() { return wg_tid_; } // HIP wg_lane_id(): the lane in the workgroup (0 .. WG_BLOCK - 1) uint wg_block_id() { return wg_bid_; } // HIP wg_block_id(): grids above 65535 run as several dispatches diff --git a/clean/dx12/kernels/l_swin.hlsl b/clean/dx12/kernels/l_swin.hlsl index 2242051b..f160c527 100644 --- a/clean/dx12/kernels/l_swin.hlsl +++ b/clean/dx12/kernels/l_swin.hlsl @@ -9,10 +9,13 @@ // HIP's transcendental chain (SW_GELU 0). // l_swin_block_c32_nc FP8 map in, FP8 out, mirror border (#117) // 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) // 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) // // @wg-kernel l_swin_block_c32_nc co=l_swin.co block=256 wave=32 args=p,p,p,p,u,u,u,u 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_ENTRY_OVERRIDE=l_swin_block_c32_nc -// @wg-kernel l_swin_block_c32_enc_nc co=l_swin.co block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=32,SW_HEADS=2,SW_MLP=128,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HPU=8,SW_GELU=3,SW_GELU_PAT=13333,SW_SRC=1,SW_ENTRY_OVERRIDE=l_swin_block_c32_enc_nc +// @wg-kernel l_swin_block_c32_enc_nc co=l_swin.co block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=32,SW_HEADS=2,SW_MLP=128,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HPU=8,SW_GELU=3,SW_GELU_PAT=13333,SW_SRC=1,SW_ENTRY_OVERRIDE=l_swin_block_c32_enc_nc,WG_REV_ORDER=1 // @wg-kernel l_swin_block_c32_dec_nc co=l_swin.co block=256 wave=32 args=p,p,p,p,u,u,u,u defines=SW_C=32,SW_HEADS=2,SW_MLP=128,SW_ADD=0,SW_SAFE=1,SW_ECL=0,SW_HPU=8,SW_GELU=1,SW_SRC=2,SW_OUT_F16=1,SW_ENTRY_OVERRIDE=l_swin_block_c32_dec_nc // l_swin_block_c32_dec_coef12_nc D3D12 only: the decoder block with l_coef_pack12 as its epilogue (SW_OUT_COEF12; // byte for byte the pair _dec_nc -> l_coef_pack12, which stays the fallback route);