diff --git a/tools/dsv41-zig/kit/nondiv16-sm121/README.md b/tools/dsv41-zig/kit/nondiv16-sm121/README.md new file mode 100644 index 00000000000..bd05248a0d9 --- /dev/null +++ b/tools/dsv41-zig/kit/nondiv16-sm121/README.md @@ -0,0 +1,67 @@ +# SM121 non-div-16 AOT variants + +Two general AOT records for the DeepSeek-V4.1 kit, for launches whose tile count is not a multiple of 16. They close the `n=600000` / `nt=9375` gap in the current TP2 and TP4 kits. + +## Records + +- `_index_score` `052d6c1ceb0c0134932d80c70ab723b84d5d13784d79962cbb47a4560c82c02d` + - cubin SHA256 `f11eef966275e317522a6ec3b441898acb1a7e102434f1215d5a333707a61edb`, 99,880 bytes + - `HAS_BASE=1`, `KEYS=0`, `OUT=*fp32`; `n.div16=false`, `nt.div16=false` + - 4 warps, 1 CTA, shared 10240, PDL on, no global/profile scratch +- `_score_keys` `9ab1ce45d139729e01bf8351bd87df01bed63459cd2c0d8072656fd178e6e88f` + - cubin SHA256 `e9b6faf7cbb6b37736df75ddac645fdfb49ca52edc5c49ac55dc23e5027bd030`, 38,904 bytes + - `HAS_TMAX=1`, `BN=1024`, `TB=64`; `n.div16=false`, `nt.div16=false` + - 4 warps, 1 CTA, shared 256, PDL on, no global/profile scratch + +All pointer arguments keep the pointer-alignment, dtype and constexpr constraints of the existing records. The argument names, types and constexprs match the current wrappers in `zig/src/families/dsv41/tri_index.zig` (`indexScore` and `scoreKeys`). + +## Why these are needed + +The current TP2 kit has 366 records. Its matching float-score `_index_score` record `34247d211cd2...` and `_score_keys` `HAS_TMAX=1` record `df85d0b39e2d...` both require `n.div16` and `nt.div16`. At `n=600000`, `nt=ceil(n/64)=9375`; 9375 is not divisible by 16, so neither record fits and `aot.Set.find` returns `MissingTritonVariant`. An eager retry does not help: the variant is absent, not merely uncaptured. + +The same two SM121 cubins apply to the TP2 and TP4 GB10 kits; their `aot.json` record sets differ, so append the records rather than replacing a manifest. + +## Provenance + +- Kernel source: `src/tensorfold/families/deepseek_v41/cuda/kernels.py` at Git `8e0966e2b09250abe2f6d9cc51edc20630e6eb1a`, SHA256 `723c3af1c9c1608f7c6439eb4e05d1cadfc7e633727a3b71f10552a67dd4a530`. +- Compiler: Triton 3.7.1+gitf797708c.nv26.7, CUDA 13.3 ptxas, aarch64, SM121. +- Compile launches: `R=3,n=599999` and `R=6,n=600000`; the general records are the two with `n.div16=false` and `nt.div16=false`. +- The records were produced through the existing Recorder, `triton_aot_manifest.py` and `aot_pack.py`; only the two general records are included here. + +The current Zig branch does not carry the Python engine source, so these cubins are the tested artifacts, not a byte-reproducible build from the current branch. A rebuild needs the pinned source above and the pinned compiler. + +## Adding them to a kit + +Merge into a copy of the kit, then repack: + +```python3 +import json, pathlib, shutil +kit = pathlib.Path("kit") # the existing kit +frag = json.loads(pathlib.Path("aot-fragment.json").read_text()) +aot = json.loads((kit / "aot/aot.json").read_text()) +have = {k["hash"]: k for k in aot["kernels"]} +for k in frag["kernels"]: + if k["hash"] in have: + raise SystemExit(f"{k['hash']}: already present") + aot["kernels"].append(k) + shutil.copyfile(pathlib.Path("cubins") / f"{k['hash']}.cubin", + kit / "aot/cubins" / f"{k['hash']}.cubin") +(kit / "aot/aot.json").write_text(json.dumps(aot, indent=1) + "\n") +``` + +Then run `pack_kit.py` on the merged kit to write a fresh `MANIFEST` and `SHA256SUMS`, and `verify_kit.sh` to check them. + +## Test + +```sh +python3 -B tools/dsv41-zig/kit/test_nondiv16.py +``` + +The test checks the two records' hashes, metadata, parameter divisibility flags and cubin bytes. It is a metadata guard, not a GPU test. + +## Not covered + +- Full model/inference qualification; the GPU evidence is synthetic kernel and dispatch testing. +- The initiating CUDA error or CUDA graph capture recovery (TensorFold PR #62). +- The integer-key case in MiaAI-Lab issue #65. +- Arbitrary caps or every base/candidate/key mode. diff --git a/tools/dsv41-zig/kit/nondiv16-sm121/RECEIPT.md b/tools/dsv41-zig/kit/nondiv16-sm121/RECEIPT.md new file mode 100644 index 00000000000..b244c0a17dd --- /dev/null +++ b/tools/dsv41-zig/kit/nondiv16-sm121/RECEIPT.md @@ -0,0 +1,28 @@ +# Receipt + +## Before + +Current TP2 kit (`kit/aot/aot.json`, 366 records) at 2026-11-20. A record-by-record fit check at `n=600000`, `nt=9375`: + +- `_index_score` float-score signature (`HAS_BASE=1`, `KEYS=0`, `OUT=*fp32`): 0 fitting records. The matching record `34247d211cd2...` requires `n.div16` and `nt.div16`; `nt=9375` fails. +- `_score_keys` `HAS_TMAX=1`: 0 fitting records. The matching record `df85d0b39e2d...` requires `n.div16` and `nt.div16`; `nt=9375` fails. + +The real dispatcher returns `MissingTritonVariant`; an eager retry hits the same absent variant. + +## After + +With the two records in this folder appended: + +- `_index_score`: exactly one fitting record, `052d6c1ceb0c...` (`n.div16=false`, `nt.div16=false`). +- `_score_keys`: exactly one fitting record, `9ab1ce45d139...` (`n.div16=false`, `nt.div16=false`). + +## Device evidence + +Candidate kit with these records, actual Zig AOT loader on two GB10 GPUs (2026-11-10): + +- 122 full-output validations and 80 negative-dispatch checks per GPU. +- `n=1, 64, 129, 262144, 599936, 599999, 600000, 600001, 600064, 600065`; `R=3/6`. +- Eager, one capture and two replays with changed base/visibility; normal and `TF_AOT_WEAKEST=1` policies. +- Independent CPU reference matched bit-for-bit; prefix/suffix guards held; unsupported alignment, dtype, constexpr and ABI length were refused before launch. + +Synthetic kernel and dispatch results, not full-inference qualification. The initiating CUDA error 1/901 is a separate concern. diff --git a/tools/dsv41-zig/kit/nondiv16-sm121/aot-fragment.json b/tools/dsv41-zig/kit/nondiv16-sm121/aot-fragment.json new file mode 100644 index 00000000000..0cccedf3f94 --- /dev/null +++ b/tools/dsv41-zig/kit/nondiv16-sm121/aot-fragment.json @@ -0,0 +1,186 @@ +{ + "kernels": [ + { + "fn": "_index_score", + "hash": "052d6c1ceb0c0134932d80c70ab723b84d5d13784d79962cbb47a4560c82c02d", + "name": "_index_score", + "num_warps": 4, + "num_ctas": 1, + "shared": 10240, + "global_scratch": 0, + "global_align": 1, + "profile_scratch": 0, + "pdl": true, + "params": [ + { + "name": "Q", + "type": "*bf16", + "div16": true, + "nospec": false + }, + { + "name": "K", + "type": "*u8", + "div16": true, + "nospec": false + }, + { + "name": "KS", + "type": "*u8", + "div16": true, + "nospec": false + }, + { + "name": "Wt", + "type": "*bf16", + "div16": true, + "nospec": false + }, + { + "name": "VIS", + "type": "*i64", + "div16": true, + "nospec": false + }, + { + "name": "OUT", + "type": "*fp32", + "div16": true, + "nospec": false + }, + { + "name": "n", + "type": "i32", + "div16": false, + "nospec": false + }, + { + "name": "KB", + "type": "*i64", + "div16": true, + "nospec": false + }, + { + "name": "CAND", + "type": "*i64", + "div16": true, + "nospec": false + }, + { + "name": "cs", + "type": "i32", + "div16": true, + "nospec": false + }, + { + "name": "TMAX", + "type": "*fp32", + "div16": true, + "nospec": false + }, + { + "name": "nt", + "type": "i32", + "div16": false, + "nospec": false + } + ], + "consts": { + "IH": { + "int": 32 + }, + "ID": { + "int": 128 + }, + "BN": { + "int": 64 + }, + "PACKED": { + "int": 1 + }, + "HAS_BASE": { + "int": 1 + }, + "PDL": { + "int": 1 + }, + "HAS_CAND": { + "int": 0 + }, + "CB": { + "int": 8 + }, + "KEYS": { + "int": 0 + }, + "HAS_TMAX": { + "int": 0 + }, + "SKIP_DEAD": { + "int": 1 + }, + "DEAD_PAD": { + "int": 0 + } + } + }, + { + "fn": "_score_keys", + "hash": "9ab1ce45d139729e01bf8351bd87df01bed63459cd2c0d8072656fd178e6e88f", + "name": "_score_keys", + "num_warps": 4, + "num_ctas": 1, + "shared": 256, + "global_scratch": 0, + "global_align": 1, + "profile_scratch": 0, + "pdl": true, + "params": [ + { + "name": "S", + "type": "*fp32", + "div16": true, + "nospec": false + }, + { + "name": "OUT", + "type": "*i64", + "div16": true, + "nospec": false + }, + { + "name": "n", + "type": "i32", + "div16": false, + "nospec": false + }, + { + "name": "TMAX", + "type": "*i64", + "div16": true, + "nospec": false + }, + { + "name": "nt", + "type": "i32", + "div16": false, + "nospec": false + } + ], + "consts": { + "BN": { + "int": 1024 + }, + "PDL": { + "int": 1 + }, + "HAS_TMAX": { + "int": 1 + }, + "TB": { + "int": 64 + } + } + } + ] +} diff --git a/tools/dsv41-zig/kit/nondiv16-sm121/cubins/052d6c1ceb0c0134932d80c70ab723b84d5d13784d79962cbb47a4560c82c02d.cubin b/tools/dsv41-zig/kit/nondiv16-sm121/cubins/052d6c1ceb0c0134932d80c70ab723b84d5d13784d79962cbb47a4560c82c02d.cubin new file mode 100644 index 00000000000..49d750c16d1 Binary files /dev/null and b/tools/dsv41-zig/kit/nondiv16-sm121/cubins/052d6c1ceb0c0134932d80c70ab723b84d5d13784d79962cbb47a4560c82c02d.cubin differ diff --git a/tools/dsv41-zig/kit/nondiv16-sm121/cubins/9ab1ce45d139729e01bf8351bd87df01bed63459cd2c0d8072656fd178e6e88f.cubin b/tools/dsv41-zig/kit/nondiv16-sm121/cubins/9ab1ce45d139729e01bf8351bd87df01bed63459cd2c0d8072656fd178e6e88f.cubin new file mode 100644 index 00000000000..1973ffc3912 Binary files /dev/null and b/tools/dsv41-zig/kit/nondiv16-sm121/cubins/9ab1ce45d139729e01bf8351bd87df01bed63459cd2c0d8072656fd178e6e88f.cubin differ diff --git a/tools/dsv41-zig/kit/test_nondiv16.py b/tools/dsv41-zig/kit/test_nondiv16.py new file mode 100644 index 00000000000..e1c38edc1ce --- /dev/null +++ b/tools/dsv41-zig/kit/test_nondiv16.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""Checks the nondiv16-sm121 fragment and its cubins. Usage: python3 -B test_nondiv16.py [--kit DIR]""" + +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +FRAG = HERE / "nondiv16-sm121" / "aot-fragment.json" +CUBINS = FRAG.parent / "cubins" + +EXPECTED = { + "052d6c1ceb0c0134932d80c70ab723b84d5d13784d79962cbb47a4560c82c02d": { + "fn": "_index_score", + "cubin": "f11eef966275e317522a6ec3b441898acb1a7e102434f1215d5a333707a61edb", + "size": 99880, + "shared": 10240, + "consts": { + "IH": 32, "ID": 128, "BN": 64, "PACKED": 1, "HAS_BASE": 1, "PDL": 1, + "HAS_CAND": 0, "CB": 8, "KEYS": 0, "HAS_TMAX": 0, "SKIP_DEAD": 1, "DEAD_PAD": 0, + }, + "params": { + "Q": "*bf16", "K": "*u8", "KS": "*u8", "Wt": "*bf16", "VIS": "*i64", + "OUT": "*fp32", "n": "i32", "KB": "*i64", "CAND": "*i64", "cs": "i32", + "TMAX": "*fp32", "nt": "i32", + }, + }, + "9ab1ce45d139729e01bf8351bd87df01bed63459cd2c0d8072656fd178e6e88f": { + "fn": "_score_keys", + "cubin": "e9b6faf7cbb6b37736df75ddac645fdfb49ca52edc5c49ac55dc23e5027bd030", + "size": 38904, + "shared": 256, + "consts": {"BN": 1024, "PDL": 1, "HAS_TMAX": 1, "TB": 64}, + "params": {"S": "*fp32", "OUT": "*i64", "n": "i32", "TMAX": "*i64", "nt": "i32"}, + }, +} + + +def int_const(v: object) -> int: + assert isinstance(v, dict) and isinstance(v.get("int"), int), v + return v["int"] + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--kit", help="an existing kit to check for hash collisions") + a = ap.parse_args() + + frag = json.loads(FRAG.read_text()) + records = frag["kernels"] + assert len(records) == 2, len(records) + assert {k["hash"] for k in records} == set(EXPECTED) + + for k in records: + want = EXPECTED[k["hash"]] + assert k["fn"] == want["fn"], k + assert k["name"] == want["fn"], k + assert k["num_warps"] == 4 and k["num_ctas"] == 1, k + assert k["shared"] == want["shared"], k + assert k["global_scratch"] == 0 and k["profile_scratch"] == 0, k + assert k["pdl"] is True, k + assert {c: int_const(v) for c, v in k["consts"].items()} == want["consts"], k + assert {p["name"]: p["type"] for p in k["params"]} == want["params"], k + for p in k["params"]: + if p["type"].startswith("*"): + assert p["div16"] is True, (k["fn"], p) + for p in k["params"]: + if p["name"] in ("n", "nt"): + assert p["div16"] is False, (k["fn"], p) + cub = CUBINS / f"{k['hash']}.cubin" + data = cub.read_bytes() + assert len(data) == want["size"], (cub, len(data)) + assert hashlib.sha256(data).hexdigest() == want["cubin"], cub + + if a.kit: + aot = json.loads((Path(a.kit) / "aot/aot.json").read_text()) + have = {k["hash"] for k in aot["kernels"]} + assert not (have & set(EXPECTED)), sorted(have & set(EXPECTED)) + print(f"test_nondiv16: fragment ok; {len(aot['kernels'])} kit records, no collision") + else: + print("test_nondiv16: fragment and two cubins ok") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())