Files
nvdriver/tools/arch_gate.py
kubuntugamer ad3bbdf670 tools: gate first-open runs on their own PMC_BOOT_42
The RTX 5050 runbook decodes 000a00 by hand and asserts architecture 0x1b with
implementation other than 0xb. Move that decode next to the inventory and let a
run assert it: tools/arch_gate.py applies chip_arch::BootId's arithmetic to the
logged word, and run_hardware_first_open.py records the result and fails the
run when --expect-arch or --forbid-impl is given and does not hold.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-12-01 03:50:12 -06:00

69 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Decode PMC_BOOT_42 from a first-open inventory and gate on the result.
`src/nvidia/src/gpu/chip_arch.rs` reproduces `_nv030823rm`'s decode of
(PMC_BOOT_0, PMC_BOOT_42); this is the same arithmetic on the inventory word
`000a00` that `hardware_inventory=1` logs, so a run can assert the card it
tested instead of reading the report by hand.
tools/arch_gate.py reports/hardware-first-open-<label>.json \
--expect-arch 0x1b --forbid-impl 0xb
Exit 0 when the word is present and the expectations hold, 1 otherwise.
"""
import argparse
import json
from pathlib import Path
# 6-bit PMC_BOOT_42 architecture -> family, as ArchFamily::from_boot42_arch.
FAMILIES = {0x11: "Maxwell1", 0x12: "Maxwell2", 0x13: "Pascal", 0x14: "Volta",
0x16: "Turing", 0x17: "Ampere", 0x18: "Hopper", 0x19: "Ada",
0x1a: "Blackwell1", 0x1b: "Blackwell2", 0x1c: "Rubin"}
def decode(boot42):
"""The decoded `000a00` word, with the fields chip_arch::BootId reads."""
arch = (boot42 >> 24) & 0x3f
return {"word_000a00": f"{boot42:08x}", "arch": arch, "arch_hex": f"{arch:02x}",
"family": FAMILIES.get(arch), "implementation": (boot42 >> 20) & 0xf,
"chip": (boot42 >> 20) & 0x3ff,
"major_rev": (boot42 >> 16) & 0xf, "minor_rev": (boot42 >> 12) & 0xf,
"minor_ext_rev": (boot42 >> 8) & 0xf}
def from_inventory(inventory, expect_arch=None, forbid_impl=None):
"""Decode the inventory's `000a00` and apply the caller's expectations."""
word = inventory.get("000a00")
if word is None:
return {"passed": False, "reason": "the inventory has no 000a00 (PMC_BOOT_42)"}
result = decode(int(word, 16))
reasons = []
if expect_arch is not None and result["arch"] != expect_arch:
reasons.append(f"arch {result['arch_hex']} is not the expected {expect_arch:02x}")
if forbid_impl is not None and result["implementation"] == forbid_impl:
reasons.append(f"implementation {result['implementation']:x} is the forbidden "
f"{forbid_impl:x}")
result["passed"] = not reasons
if reasons:
result["reason"] = "; ".join(reasons)
return result
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("report", type=Path, help="a hardware-first-open-*.json report")
parser.add_argument("--expect-arch", type=lambda text: int(text, 0), metavar="N",
help="require this 6-bit PMC_BOOT_42 architecture (0x1b = Blackwell2)")
parser.add_argument("--forbid-impl", type=lambda text: int(text, 0), metavar="N",
help="fail if the implementation is N (0xb = GB20y/Tegra)")
arguments = parser.parse_args()
report = json.loads(arguments.report.read_text())
result = from_inventory(report.get("inventory") or {},
arguments.expect_arch, arguments.forbid_impl)
print(json.dumps(result, indent=2))
raise SystemExit(0 if result["passed"] else 1)
if __name__ == "__main__":
main()