mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Original inferred-C 020155 lifecycle 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 020155 lifecycle C-oracle vectors."
|
|
)
|
|
parser.add_argument("--check", action="store_true")
|
|
args = parser.parse_args(argv)
|
|
|
|
source = ROOT / "tools/gpu_clock_factory_oracle.c"
|
|
if not source.is_file():
|
|
raise SystemExit(f"Missing oracle C source: {source}")
|
|
|
|
with tempfile.TemporaryDirectory(prefix="nv-rs-clock-factory-oracle-") as tmp:
|
|
binary = Path(tmp) / "clock-factory-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 020155 lifecycle.\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": "2existing-pool x3actual-parent x2executed-registry-status x128policy/protected masks; actual021074/109/101reset and literal020198mapping",
|
|
"limits": "Literal original inferred020155/020198/021074/021109/021101 C. Level factory is a fixture, not original020153; node callbacks are recorders. No original machine code or hardware runs.",
|
|
}
|
|
outputs = [
|
|
(ROOT / "src/nvidia/src/gpu/clock_factory_oracle.rs", code),
|
|
(ROOT / "reports/gpu-clock-factory-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-020155 lifecycle oracle:{count_str} cases;{digest}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|