mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
56 lines
2.4 KiB
Python
56 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate src/nvidia/src/rmapi/providers/class_db_gv100.rs.
|
|
|
|
Source: the "descriptors" line of target/rmapi/original-rmapi-gpu.txt (case gpu-slice3b),
|
|
which tools/check_rmapi_binary.py reads out of the GPU object after the original's own
|
|
attach: the class descriptor list its engine-table constructor built for a GV100 (GPU+0xd90,
|
|
count GPU+0xd98; public gpuConstructEngineTable: generic classes, the chip's engine-less
|
|
classes, then the chip's class-to-engine list). `--check` verifies the checked-in file.
|
|
"""
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RECORD = ROOT / "target/rmapi/original-rmapi-gpu.txt"
|
|
TARGET = ROOT / "src/nvidia/src/rmapi/providers/class_db_gv100.rs"
|
|
|
|
|
|
def main(argv=None) -> None:
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument("--check", action="store_true", help="fail if class_db_gv100.rs differs")
|
|
parser.add_argument("--record", type=Path, default=None, help="path to original-rmapi-gpu.txt")
|
|
args = parser.parse_args(argv)
|
|
|
|
record_path = args.record or RECORD
|
|
if not record_path.is_file():
|
|
raise SystemExit(f"oracle record not found: {record_path}")
|
|
line = next(
|
|
(ln for ln in record_path.read_text(encoding="utf-8").splitlines() if ln.startswith("descriptors ")),
|
|
None,
|
|
)
|
|
if line is None:
|
|
raise SystemExit(f"no 'descriptors ' line found in {record_path}")
|
|
records = [tuple(int(part, 16) for part in field.split(":")) for field in line.split()[1:]]
|
|
lines = [
|
|
"//! Class descriptor list of a GV100: (external class, engine descriptor) in the order of",
|
|
"//! the original's engine-table constructor (GPU+0xd90 after `gpumgrAttachGpu`).",
|
|
"//! Generated by tools/generate_rmapi_class_db.py from the oracle record; do not edit.",
|
|
"",
|
|
"#[rustfmt::skip]",
|
|
f"pub static DESCRIPTORS: [(u32, u32); {len(records)}] = [",
|
|
]
|
|
lines += [f" ({klass:#x}, {engine:#x})," for klass, engine in records]
|
|
lines += ["];", ""]
|
|
text = "\n".join(lines)
|
|
if args.check:
|
|
if not TARGET.is_file() or TARGET.read_text(encoding="utf-8") != text:
|
|
raise SystemExit("class descriptor table differs from the oracle record")
|
|
else:
|
|
TARGET.parent.mkdir(parents=True, exist_ok=True)
|
|
TARGET.write_text(text, encoding="utf-8")
|
|
print(f"{len(records)} class descriptors")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|