Files
nvdriver/tools/gpu_generate_clock_objects_oracle.py

66 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Original inferred-C clock object deactivation 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 object deactivation C-oracle vectors."
)
parser.add_argument("--check", action="store_true")
args = parser.parse_args(argv)
source = ROOT / "tools/gpu_clock_objects_oracle.c"
if not source.is_file():
raise SystemExit(f"Missing oracle C source: {source}")
with tempfile.TemporaryDirectory(prefix="nv-rs-clock-objects-oracle-") as tmp:
binary = Path(tmp) / "clock-objects-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 clock object deactivation.\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": "17actual entries x8list counts x2mutation modes x32alias/null/conditional seeds; forward/reverse live list mutations, shared records and reentrant temporary method8",
"assertion_service": "Original020158 is not executed; fixture records assertion invocation. Production diagnostic service remains mandatory.",
"pointer_layout_normalization": "Compare owned record/list identities, not ASLR host pointer bits in overlapping layout fields.",
"limits": "Literal original inferred021082/021087/021096/021084/021089/021090/021095/021080/021094/021085/021088/021079/021081/021083/021086/021091/021092/021093 C only. Leaf callback bodies are recorders, not claimed original external method behavior. No original machine code or hardware runs.",
}
outputs = [
(ROOT / "src/nvidia/src/gpu/clock_objects_oracle.rs", code),
(ROOT / "reports/gpu-clock-objects-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-object deactivation oracle:{count_str} cases;{digest}")
return 0
if __name__ == "__main__":
raise SystemExit(main())