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 / mathlibs_host_om.py

90 lines · 4960 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Verification oracle only. Run through the documented device-masked wrapper."""
4import glob
5import os
6from pathlib import Path
7import shutil
8import subprocess
9import sys
10import tempfile
11
12ROOT = Path(__file__).resolve().parents[1]
13OUT = ROOT / "build/mathlibs-host-om"
14OUT.mkdir(parents=True, exist_ok=True)
15# Refuse when a node that reaches a GPU is visible: NVIDIA, aien-gpu, or a VFIO-bound group. The
16# /dev/vfio/vfio control node of a hosted runner reaches no device.
17if (glob.glob("/dev/nvidia*") or glob.glob("/dev/aien-gpu*")
18 or [p for p in Path("/dev/vfio").glob("*") if p.name != "vfio"]):
19 sys.exit("REFUSED: run under bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10")
20
21
22def run(name, command, expect=0, env=None):
23 result = subprocess.run(command, cwd=ROOT, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
24 text = result.stdout.decode(errors="replace")
25 (OUT / (name + ".log")).write_text("$ " + " ".join(map(str, command)) + "\n" + text + "\nrc=" + str(result.returncode) + "\n")
26 print(name + ": rc=" + str(result.returncode) + " " + (text.strip().splitlines()[-1] if text.strip() else "(no output)"), flush=True)
27 if expect is not None and result.returncode != expect:
28 sys.exit("FAIL " + name + "; see " + str(OUT / (name + ".log")))
29 return result.returncode, text
30
31
32CC = os.environ.get("CC", "cc")
33CFLAGS = ["-std=gnu11", "-Wall", "-Wextra", "-Werror", "-D_GNU_SOURCE", "-Isrc", "-Im16", "-Invrm", "-ffp-contract=off"]
34TEST = "tests/mathlibs_host_om_test.c"
35LIB = "build/libomega_gpu.a"
36run("build", ["make", "-j3", "build/gpu_mathlibs_test"])
37base = OUT / "differential"
38for path in OUT.glob("*.gcda"):
39 path.unlink()
40run("compile", [CC, *CFLAGS, "-O0", "--coverage", "-o", str(base), TEST, LIB, "-lpthread", "-lm"])
41run("differential", [str(base)])
42rc, _ = run("red", [str(base), "--red"], expect=None)
43if rc != 1:
44 sys.exit("FAIL red control did not reject the changed expected address")
45run("coverage", ["gcov", "-b", "-c", "-f", "-o", str(OUT / "differential-mathlibs_host_om_test.gcno"), TEST])
46# gcov emits source-relative names in cwd; retain its text without adding build artifacts to git.
47for path in ROOT.glob("*.gcov"):
48 shutil.move(str(path), OUT / path.name)
49
50with tempfile.TemporaryDirectory(prefix="mathlibs-host-om-") as tmpname:
51 tmp = Path(tmpname)
52 archive = tmp / "without-host.a"
53 shutil.copyfile(ROOT / LIB, archive)
54 members = ["host", "walk", "step", "many", "index", "fft"]
55 run("strip-host", ["ar", "d", str(archive), *["cudapp_om_mathlibs_" + n + ".o" for n in members]])
56 rc, text = run("missing-unit", [CC, *CFLAGS, "-O2", "-o", str(tmp / "missing"), TEST, str(archive), "-lpthread", "-lm"], expect=None)
57 if not rc or "undefined reference" not in text or "omega_native_mh" not in text:
58 sys.exit("FAIL missing Omega unit did not fail at link")
59
60 original = (ROOT / "om/mathlibs/host.om").read_text()
61 mutants = [
62 ("rng-stream-limit", "gt ns 131072", "gt ns 131073"),
63 ("seed-increment", "mul add i 1 11400714819323198485", "mul add i 2 11400714819323198485"),
64 ("poison64", "eq a 18427282365706066861", "eq a 18427282365706066860"),
65 ("chunk-bound", "grid = mh_min sub ctas first 1024", "grid = mh_min sub ctas first 1023"),
66 ("zero-stride", "if eq get s 243 0", "if eq get s 243 1"),
67 ("real-half", "put s 22 add div get s 21 2 1", "put s 22 add div get s 21 2 0"),
68 ("axis-rotation", "v = get s add 41 get s 20", "v = get s 41"),
69 ("overlap-bit", "bit = shl ulong 1 and idx 7", "bit = shl ulong 1 and idx 6"),
70 ]
71 rows = ["mutant\tcompile_rc\trun_rc\tverdict"]
72 for name, before, after in mutants:
73 if original.count(before) != 1:
74 sys.exit("FAIL mutant site is not unique: " + name)
75 source = tmp / "host.om"
76 source.write_text(original.replace(before, after))
77 dest = tmp / name
78 dest.mkdir()
79 env = os.environ.copy()
80 env["OMEGA_UNITS_DEST"] = str(dest)
81 env["OMEGA_UNITS"] = " ".join("mathlibs_" + n + "=" + str(source) + ",om/mathlibs/host_" + ("scalar" if n == "host" else n) + ".om" for n in members)
82 run(name + "-generate", ["sh", "om/units.sh"], env=env)
83 binary = tmp / (name + "-test")
84 run(name + "-compile", [CC, *CFLAGS, "-O2", "-o", str(binary), TEST, *[str(dest / ("cudapp_om_mathlibs_" + n + ".c")) for n in members], LIB, "-lpthread", "-lm"])
85 rc, text = run(name, [str(binary)], expect=None)
86 if not rc or "MATHLIBS-HOST-OM PASS" in text:
87 sys.exit("FAIL survived .om mutant " + name)
88 rows.append(name + "\t0\t" + str(rc) + "\tKILLED")
89 (OUT / "mutants.tsv").write_text("\n".join(rows) + "\n")
90print("MATHLIBS-HOST-OM GATE PASS: differential, red, strong-link negative, gcov, 8 killed .om mutants")