interplane.Get Omega
Read in your language

omega-gpu-bench

First-party Omega GPU kernel benchmark harness and receipts

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-bench / tools / import_cloudkernels.py

81 lines · 4870 bytes Raw Blame History
1#!/usr/bin/env python3
2# tools/import_cloudkernels.py -- turn one CloudKernels rental run (aien-dev's own 2026-10-26 runs on
3# rented GPUs, made before this kit existed) into a receipt with origin "cloudkernels-import".
4#
5# import_cloudkernels.py RUN_DIR SPEND_LOG PROVIDER
6#
7# Only rows for kernels this kit ships are imported (vecadd/neg v7); the alu/ctl rows in the same run
8# failed with CUDA_ERROR_ILLEGAL_INSTRUCTION and stay visible in the copied results.jsonl. The copied
9# evidence goes to evidence/cloudkernels/<run>/: results.jsonl, driver-version.txt, nvidia-smi.txt and
10# rental.txt (the run's CREATE/READY/DELETE lines from spend.log without the sandbox id). Those runs did
11# not hash their output buffer or time the kernel, so output_sha256 and timing are null. The cubin hashes
12# are this kit's SHA256SUMS: the run predates hashing in the receipt, and the files it loaded were last
13# written before the run started (vecadd 22:37Z, neg 22:46Z; the runs began 23:13Z or later).
14# The import is recorded in receipts/imports.sha256, which is the validator's allowlist for this origin.
15# INTERIM host glue (Python), one-off; no Omega successor needed once kit runs replace imports.
16import json, os, re, shutil, sys
17
18KIT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19sys.path.insert(0, os.path.join(KIT, "tools"))
20import receipt as R # noqa: E402
21
22run_dir, spend_log, provider = sys.argv[1], sys.argv[2], sys.argv[3]
23run = os.path.basename(run_dir.rstrip("/"))
24res = os.path.join(run_dir, "res")
25sums = R.read_sums(os.path.join(KIT, "kernels", "SHA256SUMS"))
26dest = os.path.join(KIT, "evidence", "cloudkernels", run)
27os.makedirs(dest, exist_ok=True)
28for f in ("results.jsonl", "driver-version.txt", "nvidia-smi.txt"):
29 shutil.copyfile(os.path.join(res, f), os.path.join(dest, f))
30with open(os.path.join(dest, "rental.txt"), "w") as out:
31 for line in open(spend_log):
32 if "\t" + run + "\t" in line and re.search(r"\t(CREATE|READY|DELETE)\t", line):
33 out.write(re.sub(r"\tid=\S+", "", line.strip()) + "\n")
34
35rows, mach = [], None
36for line in open(os.path.join(res, "results.jsonl")):
37 j = json.loads(line)
38 name = os.path.basename(j["cubin"])
39 mach = mach or j
40 if name not in sums:
41 continue
42 j.pop("launch_s", None) # wall clock around one launch, 0.1 ms timer resolution: not a timing
43 j["first_bad"] = [list(t) for t in j.get("first_bad", [])]
44 rows.append(R.result_row(name, sums[name], j["kind"], j))
45rows.sort(key=lambda r: r["cubin"])
46
47nvrm = open(os.path.join(res, "driver-version.txt")).readline().strip()
48drv = re.search(r"\s(\d+\.\d+(?:\.\d+)?)\s", nvrm)
49host = open(os.path.join(res, "host.txt")).read().splitlines()
50os_name = next((l.split("=", 1)[1].strip('"') for l in host if l.startswith("PRETTY_NAME=")), None)
51uname = next((l for l in host if l.startswith("Linux ")), "").split()
52cpu = next((l.split(":", 1)[1].strip() for l in open(os.path.join(res, "cpuinfo.txt"))
53 if l.startswith("model name")), None)
54rec = R.seal({
55 "schema": R.SCHEMA, "origin": "cloudkernels-import", "path": R.PATH_LABEL, "provider": provider,
56 "kit": {"repo": None, "commit": None, "modified": False, "kernels_sha256sums": None},
57 "machine": {"gpu": mach["device"], "cc": mach["cc"], "cuda_driver_api": mach["cuda_driver_api"],
58 "driver_version": drv.group(1) if drv else None, "nvrm": nvrm, "os": os_name,
59 "kernel": uname[2] if len(uname) > 2 else None, "arch": uname[-2] if uname else None,
60 "cpu": cpu},
61 "run": {"utc": host[0].strip(), "driver": "libcuda", "python": None},
62 "submitter": {"signed_off_by": "Aien agents, CloudKernels import <aien@aienos.com>",
63 "statement": "Imported from aien-dev's own CloudKernels run %s; not run with this kit." % run},
64 "results": rows, "not_run": None,
65 "evidence": {
66 "source": "CloudKernels rental run %s (aien-dev, 2026-10-26), harness ck.py, through NVIDIA libcuda" % run,
67 "files": [{"path": "evidence/cloudkernels/%s/%s" % (run, f), "sha256": R.sha256_file(os.path.join(dest, f))}
68 for f in sorted(os.listdir(dest))],
69 "note": "Kit kernels only; alu/ctl rows of the same run are in results.jsonl. No output hash or "
70 "kernel timing was recorded by that harness.",
71 },
72})
73slug = re.sub(r"[^a-z0-9]+", "-", mach["device"].lower()).strip("-")
74fname = os.path.join(KIT, "receipts", "%s-%s-%s.json" % (rec["run"]["utc"].replace("-", "").replace(":", ""),
75 slug, rec["receipt_sha256"][:8]))
76with open(fname, "w") as f:
77 json.dump(rec, f, indent=1, sort_keys=True)
78 f.write("\n")
79with open(os.path.join(KIT, "receipts", "imports.sha256"), "a") as f:
80 f.write("%s %s\n" % (rec["receipt_sha256"], os.path.basename(fname)))
81print(fname)