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 c707c4b4..499d5f69 100644 --- a/clean/dx12/vgpr_limits.json +++ b/clean/dx12/vgpr_limits.json @@ -4,6 +4,7 @@ "l_swin_block_c32_enc_nc": 96, "l_swin_block_c32_dec_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 769a2ab2..61ce253b 100644 --- a/clean/l/runner/l_d3d12_ops_check.py +++ b/clean/l/runner/l_d3d12_ops_check.py @@ -174,6 +174,32 @@ 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 + + # (rw, rh, dw, dh, reset, kind, expo) of the reconstruction: clean/l/runner/l_post_check.py's cases (Model M's ratios, # odd sizes, reset, extreme kernel shapes, the zero-weight known answer "offset_0.1" (spec part 3 Q1: total weight 0 # everywhere) and the FP16 underflow known answer "offset_0.05" (Q3: total weight > 0, every FP16 weight 0)), plus @@ -248,7 +274,8 @@ def post_cases(kernel, rng): 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, - "l_coef_pack12": coef_cases, "lev/input_encoder": enc_cases, "l_post_recon": post_cases} + "l_coef_pack12": coef_cases, "lev/input_encoder": enc_cases, "l_post_recon": post_cases, + "swin_block_c64_add_ex_nc": dec1_ex_cases} CONTROL_KINDS = {"swin_block_c96_nc": control_cases} CO = "l_ops.co"