Files
leleka/scripts/decode-sm120/make_iq_prefix.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 0765a20958 sm120 decode switch GU_SWIGLU: fused expert gate/up + SwiGLU + q8_1 (upstream native_gu_swiglu_kernel) in the verify window (default on for cc 12.0)
Replaces window_moe_gu_<T> + swiglu_entries_kernel + quantize_q8_1_kernel of every routed-expert group launch (VRAM and PCIe tier) by one launch of upstream's
native_gu_swiglu_kernel (16-lane sub-warp rows, gate and up row at once) for the gate/up types 16 17 18 21 22 23 at n_embd 2560, n_ff % 32 == 0; every other
format keeps the three-kernel plan. New sealed asset sm120_gu_swiglu.cu (group sm120-decode) textually includes sm120_iq_prefix.cuh, the pinned
iq_kernels.cu up to the dequant banner (generated and checked by scripts/decode-sm120/make_iq_prefix.py; the whole file would instantiate 24 MB of PTX).
Kernel parameter: upstream's 88-byte NativeExpertLayout (the window's 64 bytes + tail_off, had_block, d_signs = 0).

Switch: policy.gu_swiglu, resolved at window recording from the card (cc 12.0), LELEKA_SM120_PERF=0 and LELEKA_SM120_GU_SWIGLU=0|1.

Model-free probe (tools/decode-sm120/sm120_probe.cpp gu, RTX 5090): the q8_1 blocks the down kernel reads are byte-identical to the old three-kernel path in
30 cases (types 16 17 18 21 22 23, 1-8 rows, 1-40 groups, 1-7 entries a group, random blobs with valid block scales); per layer at 4 rows 20.9 -> 14.2 us (16),
29.8 -> 20.7 us (18), 24.9 -> 19.6 us (21), warm L2. Types 29 and 42 are not probed and not routed to the new kernel. Not yet measured end to end.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 01:20:32 +01:00

24 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Regenerate (or --check) crates/cuda-driver/src/sm120_iq_prefix.cuh: lines 1..END of engine/strata/src/kernels/cuda/iq_kernels.cu.
END is the line before the `dequant (dequantize.cuh)` banner, i.e. everything up to and including native_gu_swiglu_kernel. The whole file instantiates ~60 MB of PTX
through its host launchers (past the 16 MiB asset limit); the prefix holds every trait, row dot and q8_1_store the fused expert kernel needs and no launcher.
The prefix is byte for byte the upstream text (plus a two-line header), so it is checked against the engine tree: --check fails when the pinned file changed.
"""
import sys
SRC = "engine/strata/src/kernels/cuda/iq_kernels.cu"
DST = "crates/cuda-driver/src/sm120_iq_prefix.cuh"
BANNER = "// ---------------------------------------------------------------- dequant (dequantize.cuh)"
HEADER = ("// GENERATED by scripts/decode-sm120/make_iq_prefix.py from " + SRC + " (the pinned upstream, docs/upstream.md): the file up to the dequant banner,\n"
"// unchanged. Do not edit; `make_iq_prefix.py --check` compares it with the engine tree. Opens `namespace strata::kernels { namespace {` and leaves both open.\n")
lines = open(SRC, newline="").read().split("\n")
end = next(i for i, l in enumerate(lines) if l.rstrip("\r") == BANNER)
want = HEADER + "\n".join(lines[:end]) + "\n"
if "--check" in sys.argv:
have = open(DST, newline="").read()
sys.exit(0 if have == want else "sm120_iq_prefix.cuh is stale against " + SRC)
open(DST, "w", newline="").write(want)
print("wrote", DST, end, "upstream lines")