omega-gpu-bench
First-party Omega GPU kernel benchmark harness and receipts
Brought by drakestapleton
omega-gpu-bench / tools / receipt.py
| 1 | # tools/receipt.py -- the receipt format, shared by kit/bench.py (writer), tools/validate.py (checker) |
| 2 | # and tools/board.py (leaderboard). INTERIM host glue (Python); Omega successor: the same rules as an |
| 3 | # omc-built checker using omega-mv's SHA-256 unit (see DEPENDENCIES.md). |
| 4 | import hashlib, json, re |
| 5 | |
| 6 | SCHEMA = "omega-gpu-bench/receipt/v1" |
| 7 | REPO = "aien-dev/omega-gpu-bench" |
| 8 | PATH_LABEL = ("NVIDIA libcuda (cuModuleLoadData + cuLaunchKernel): an interop oracle for Omega's " |
| 9 | "machine-code encoder and cubin writer, not CUDA++'s own user-space driver path") |
| 10 | STATEMENT = "I ran this kit as cloned on the machine described here and did not edit this receipt by hand." |
| 11 | # Why kernels/ ships no cubin: the six v7 cubins and their writer were withdrawn. Their hashes stay in |
| 12 | # kernels/WITHDRAWN.sha256 so the imported historical receipts still validate and nothing new can use them. |
| 13 | WITHDRAWN = "removed pending clean-room rewrite (CudaLicenseRisk Q6)" |
| 14 | N, SEED, NT = (1 << 20) + 7, 20261026, 1 << 26 |
| 15 | SIGNOFF = re.compile(r"[^<>\n]*[^<>\s][^<>\n]* <[^<>@\s]+@[^<>\s]+>") |
| 16 | CUBIN = re.compile(r"(vecadd|neg)_sm(\d)(\d)_v7\.cubin") |
| 17 | ROW_KEYS = ("cubin", "cubin_sha256", "kind", "verdict", "checked", "mismatches", "first_bad", |
| 18 | "output_sha256", "kernel_ms", "gbps", "timing_n", "error", "timing_error") |
| 19 | |
| 20 | |
| 21 | def sha256_file(path): |
| 22 | with open(path, "rb") as f: |
| 23 | return hashlib.sha256(f.read()).hexdigest() |
| 24 | |
| 25 | |
| 26 | def parse_sums(text): |
| 27 | sums = {} |
| 28 | for line in text.splitlines(): |
| 29 | if line.strip(): |
| 30 | digest, name = line.split(None, 1) |
| 31 | sums[name.lstrip("*").strip()] = digest |
| 32 | return sums |
| 33 | |
| 34 | |
| 35 | def read_sums(path): |
| 36 | with open(path) as f: |
| 37 | return parse_sums(f.read()) |
| 38 | |
| 39 | |
| 40 | def canonical(body): |
| 41 | body = {k: v for k, v in body.items() if k != "receipt_sha256"} |
| 42 | return json.dumps(body, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode() |
| 43 | |
| 44 | |
| 45 | def seal(body): |
| 46 | body["receipt_sha256"] = hashlib.sha256(canonical(body)).hexdigest() |
| 47 | return body |
| 48 | |
| 49 | |
| 50 | def expected_cubins(cc, sums): |
| 51 | """Kernels a GPU of compute capability cc ("8.9") can load: same major, cubin minor <= GPU minor.""" |
| 52 | m = re.fullmatch(r"(\d+)\.(\d+)", cc or "") |
| 53 | if not m: |
| 54 | return [] |
| 55 | major, minor = int(m.group(1)), int(m.group(2)) |
| 56 | names = [] |
| 57 | for name in sums: |
| 58 | c = CUBIN.fullmatch(name) |
| 59 | if c and int(c.group(2)) == major and int(c.group(3)) <= minor: |
| 60 | names.append(name) |
| 61 | return sorted(names) |
| 62 | |
| 63 | |
| 64 | def result_row(name, digest, kind, ck_out): |
| 65 | row = {k: ck_out.get(k) for k in ROW_KEYS} |
| 66 | row.update(cubin=name, kind=kind, cubin_sha256=ck_out.get("cubin_sha256") or digest) |
| 67 | return row |