#!/usr/bin/env python3 """Original inferred-C base cache prefix oracle with replacement callbacks, no GPU IO.""" from pathlib import Path import argparse,subprocess,json,hashlib r=Path(__file__).resolve().parent.parent;p=argparse.ArgumentParser();p.add_argument('--check',action='store_true');a=p.parse_args() c=r/'tools/gpu_clock_cache_oracle.c';binary=r/'target/clock-cache-oracle';binary.parent.mkdir(exist_ok=True) subprocess.run(['cc','-std=gnu11','-O0','-fno-strict-aliasing',str(c),'-o',str(binary)],check=True) n,h=subprocess.check_output([str(binary)],text=True).strip().split() code=f'// Generated from literal original inferred C base cache prefix.\nconst ORIGINAL_CASES: usize = {n};\nconst ORIGINAL_HASH: u64 = 0x{h};\n' report={'source_sha256':'5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b','oracle_c_sha256':hashlib.sha256(c.read_bytes()).hexdigest(),'cases':int(n),'fnv1a64':h,'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.'} for out,text in [(r/'src/nvidia/src/gpu/clock_cache_oracle.rs',code),(r/'reports/gpu-clock-cache-oracle.json',json.dumps(report,indent=2)+'\n')]: if a.check: if out.read_text()!=text:raise SystemExit('Stale '+str(out)) else:out.write_text(text) print(f'Original clock-base cache prefix oracle:{n} cases;{h}')