From 58d6962e3b9e93294e0b0e446816bdf1a5093433 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:10:55 -0500 Subject: [PATCH] Model L: D3D12 port of dec1's block with its fused expand (swin_block_c64_add_ex_nc), byte for byte against its HIP kernel Model M's D3D12 route always runs dec1 fused with the pack12 decoder; Model L's frame launches this kernel for dec1, which had no port. swin_c64ex.hlsl instantiates swin_block.hlsl unchanged (C = 64, ADD, fused expand from 96 channels). Refs #89 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/dx12/kernels/swin_c64ex.hlsl | 12 ++++++++++++ clean/dx12/vgpr_limits.json | 1 + clean/l/runner/l_d3d12_ops_check.py | 29 ++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 clean/dx12/kernels/swin_c64ex.hlsl diff --git a/clean/dx12/kernels/swin_c64ex.hlsl b/clean/dx12/kernels/swin_c64ex.hlsl new file mode 100644 index 00000000..30fd1d84 --- /dev/null +++ b/clean/dx12/kernels/swin_c64ex.hlsl @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +// D3D12 port of swin_block_c64_add_ex_nc (clean/kernels/swin.hip WG_FUSED_KERNEL(swin_block_c64_add_ex, 64, 2, 256, +// true, 0, 96)): dec1's Swin block with its expand fused in, as a kernel of its own (dec1's map written out). Model M's +// D3D12 route runs dec1 fused with the pack12 decoder (d1p12/swin_block_c64_add_dec0*), so this kernel had no port; +// Model L's frame (issue #89) launches it for dec1 (default swin_fuse_stages dec1,dec2: the L decoder reads dec1's map). +// swin_block.hlsl instantiated at C = 64, 2 heads, MLP 256 (its C = 64 path, as swin_block_c64_nc) with the block input +// x + xadd (SW_ADD) and the fused expand from the 96-channel low-resolution map (SW_ECL 96), as +// swin_block_c96_add_ex_nc is at C = 96. 256 lanes, one window per wave; x = dec2's output (96 channels at half size), +// xadd = the skip map, aux unused. +// +// @wg-kernel swin_block_c64_add_ex_nc co=swin.co block=256 wave=32 args=p,p,p,p,u,u,u,u,p defines=SW_C=64,SW_HEADS=2,SW_MLP=256,SW_ADD=1,SW_SAFE=1,SW_ECL=96,SW_ENTRY_OVERRIDE=swin_block_c64_add_ex_nc +#include "swin_block.hlsl" diff --git a/clean/dx12/vgpr_limits.json b/clean/dx12/vgpr_limits.json index d4251e04..1bccffac 100644 --- a/clean/dx12/vgpr_limits.json +++ b/clean/dx12/vgpr_limits.json @@ -2,6 +2,7 @@ "_doc": "build_dx12.py VGPR check: the RGA (gfx1201) USED_VGPRs bound of every Swin / bottleneck kernel (a name with a swin_ part). Each bound is the largest count that keeps the kernel's present occupancy: VGPR file 1536 per SIMD lane, granule 8, a 256-lane wave32 workgroup = 4 waves on each of a CU's 2 SIMDs, so 2 workgroups per CU need <= 192, 3 need <= 128 (a 128-lane workgroup = 2 waves per SIMD: 4 per CU need <= 192). A kernel over its bound fails the build (a merge or an edit lost a workgroup per CU: swin_block_c96_add_xe_* at 215 VGPRs ran 1 per CU, +38 us per frame at 1440p Q). A new Swin / bottleneck kernel needs an entry. WG_DX12_VGPR_CHECK=0 skips the check.", "l_swin_block_c32_nc": 96, "swin_block_c64_nc": 192, + "swin_block_c64_add_ex_nc": 128, "swin_block_c96_nc": 192, "swin_block_c96_add_ex_nc": 192, "swin_block_c96_pm_nc": 192, diff --git a/clean/l/runner/l_d3d12_ops_check.py b/clean/l/runner/l_d3d12_ops_check.py index efa61a91..65c73d8d 100644 --- a/clean/l/runner/l_d3d12_ops_check.py +++ b/clean/l/runner/l_d3d12_ops_check.py @@ -168,9 +168,36 @@ def enc_cases(kernel, rng): return cases +# (H, W) of dec1's map (even: the expand writes 2 x 2 pixels per low-resolution token), each with dec1's two window +# offsets (0, 0) and (2, 0). 4 x 6 and 12 x 20: fewer windows than a workgroup's 8. +DEC1_GRIDS = [(16, 24), (36, 68), (8, 8), (68, 100), (4, 6), (12, 20), (48, 64)] + + +def dec1_ex_cases(kernel, rng): + """swin_block_c64_add_ex_nc (swin.co; Model M's kernel, launched by Model L's frame for dec1): x = the low-resolution + map [H / 2][W / 2][96] FP8, xadd = the skip map [H][W][64] FP8 -> out [H][W][64] FP8; w = dec1's stage blob (block, + then the expand section at the 256-byte aligned block size, clean/runner/packing.py pack_stage); aux null. Only + blobs with the _nc flag (the D3D12 port has only the _nc form).""" + from clean.reference import swin as MS + from clean.runner import packing as P + cases = [] + for (H, W) in DEC1_GRIDS: + for (ox, oy) in ((0, 0), (2, 0)): + blob = P.pack_stage("dec1", MS.random_params("dec1", rng)) + if not np.frombuffer(blob[:4], np.uint32)[0] & 1: + continue + nwin = -(-(W + ox) // 4) * -(-(H + oy) // 4) + cases.append({"kernel": kernel, "co": "swin.co", "grid": -(-nwin // 8), "block": 256, + "args": [("buf", _fp8_map(rng, (H // 2) * (W // 2) * 96)), ("buf", _fp8_map(rng, H * W * 64)), + ("out", H * W * 64), ("buf", blob), ("u32", H), ("u32", W), ("u32", ox), ("u32", oy), + ("null",)]}) + return cases + + KINDS = {"l_linear_32_32_relu": linear_cases, "l_linear_32_32_f16": linear_cases, "l_project_gather": project_cases, "l_dec_project": project_cases, "l_coef": coef_cases, - "lev/input_encoder": enc_cases} + "lev/input_encoder": enc_cases, + "swin_block_c64_add_ex_nc": dec1_ex_cases} CONTROL_KINDS = {"swin_block_c96_nc": control_cases} CO = "l_ops.co"