#!/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")