#!/usr/bin/env python3 """Original inferred-C base cache prefix oracle with replacement callbacks, no GPU IO.""" import argparse import hashlib import json import subprocess import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parent.parent def main(argv=None) -> int: parser = argparse.ArgumentParser( description="Generate or verify clock base-cache prefix C-oracle vectors." ) parser.add_argument("--check", action="store_true") args = parser.parse_args(argv) source = ROOT / "tools/gpu_clock_cache_oracle.c" if not source.is_file(): raise SystemExit(f"Missing oracle C source: {source}") with tempfile.TemporaryDirectory(prefix="nv-rs-clock-cache-oracle-") as tmp: binary = Path(tmp) / "clock-cache-oracle" subprocess.run( ["cc", "-std=gnu11", "-O0", "-fno-strict-aliasing", str(source), "-o", str(binary)], check=True, ) tokens = subprocess.check_output([str(binary)], text=True).strip().split() if len(tokens) != 2: raise SystemExit(f"Unexpected oracle output format: {tokens!r}") count_str, digest = tokens code = ( "// Generated from literal original inferred C base cache prefix.\n" f"const ORIGINAL_CASES: usize = {count_str};\n" f"const ORIGINAL_HASH: u64 = 0x{digest};\n" ) report = { "source_sha256": "5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b", "oracle_c_sha256": hashlib.sha256(source.read_bytes()).hexdigest(), "cases": int(count_str), "fnv1a64": digest, "domain": "66engine masks x34partition masks x2executed query statuses; all130preexistingrecords compared", "limits": "Literal original inferred020153 basecache prefix C. Mask queries and diagnostics are recorders, not actual provider bodies. No original machine code or hardware runs.", } outputs = [ (ROOT / "src/nvidia/src/gpu/clock_cache_oracle.rs", code), (ROOT / "reports/gpu-clock-cache-oracle.json", json.dumps(report, indent=2) + "\n"), ] for out, text in outputs: if args.check: if not out.is_file() or out.read_text() != text: raise SystemExit(f"Stale {out}") else: out.write_text(text) print(f"Original clock-base cache prefix oracle:{count_str} cases;{digest}") return 0 if __name__ == "__main__": raise SystemExit(main())