interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / ampere / run.py

71 lines · 4095 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Explicit device-only Ampere checks. Never substitutes simulation or updates old receipts."""
4import argparse
5import datetime
6import json
7import os
8from pathlib import Path
9import subprocess
10import sys
11
12ROOT = Path(__file__).resolve().parents[2]
13
14def main():
15 parser = argparse.ArgumentParser(description=__doc__)
16 parser.add_argument("--device", action="store_true", help="authorize submissions on this machine")
17 parser.add_argument("--bdf", required=True, help="exact GA102/GA104 full PCI BDF")
18 parser.add_argument("--output", required=True, type=Path, help="new evidence directory; existing paths refuse")
19 parser.add_argument("--build", type=Path, default=ROOT / "build")
20 parser.add_argument("--full-math", action="store_true", help="all binary32 inputs per unary function; otherwise NOT_RUN")
21 args = parser.parse_args()
22 if not args.device:
23 parser.error("explicit --device required; no driver was opened")
24 args.output.mkdir(parents=True, exist_ok=False)
25 names = ("doctor", "hello", "hello-negative", "math-smoke", "math-negative", "math-exhaustive", "memory-refusal")
26 receipt = {"schema": 1, "created_utc": datetime.datetime.now(datetime.timezone.utc).isoformat(),
27 "bdf": args.bdf, "target": "sm_86", "evidence": "DEVICE",
28 "source_commit": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True).strip(),
29 "checks": {name: {"status": "NOT_RUN"} for name in names}}
30 def save():
31 (args.output / "results.json").write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n")
32 save()
33 env = dict(os.environ, CUDAPP_GPU_BDF=args.bdf)
34 def run(name, command, expected=0, marker=None):
35 check = receipt["checks"][name]
36 check["command"] = [str(x) for x in command]
37 save()
38 try:
39 result = subprocess.run(check["command"], cwd=ROOT, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
40 except OSError as error:
41 check.update(status="FAIL", error=str(error)); save(); return False
42 (args.output / (name + ".log")).write_text(result.stdout)
43 ok = result.returncode == expected and (marker is None or marker in result.stdout)
44 check.update(status="PASS" if ok else "FAIL", exit_code=result.returncode, log=name + ".log")
45 save()
46 print(name + ": " + check["status"], flush=True)
47 return ok
48 if not run("doctor", [sys.executable, ROOT / "tests/ampere/doctor.py", "--bdf", args.bdf], marker='"preflight": "PASS"'):
49 return 1
50 build = args.build.resolve()
51 for binary in ("hello_gpu", "hello_gpu_control", "ampere_math_device", "ampere_memory_refusal"):
52 if not (build / binary).is_file():
53 print("Missing device test binary: " + str(build / binary), file=sys.stderr)
54 return 1
55 sequence = [
56 ("hello", [build / "hello_gpu", "--target=sm_86"], 0, "checked 1048576 of 1048576 elements: 0 wrong, 0 never written"),
57 ("hello-negative", [build / "hello_gpu_control", "--target=sm_86", "--bug=short"], 1, "checked 1048576 of 1048576 elements: 1 wrong, 1 never written"),
58 ("memory-refusal", [build / "ampere_memory_refusal", "--device"], 0, "AMPERE MEMORY REFUSAL PASS"),
59 ("math-smoke", [build / "ampere_math_device", "--device", "--count", "65536"], 0, "SHARD PASS"),
60 ("math-negative", [build / "ampere_math_device", "--device", "--count", "65536", "--inject-output-error"], 1, "AMPERE MATH FAIL op=rcp input=00000000"),
61 ]
62 for name, command, expected, marker in sequence:
63 if not run(name, command, expected, marker):
64 return 1
65 if args.full_math and not run("math-exhaustive", [build / "ampere_math_device", "--device"], marker="AMPERE MATH log2 EXHAUSTIVE PASS"):
66 return 1
67 print("All requested checks passed. Unrequested checks remain NOT_RUN; no qualification registry was changed.")
68 return 0
69
70if __name__ == "__main__":
71 sys.exit(main())