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

60 lines · 3230 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Compile real seeded mutations; compilation failures are NOT mutant kills."""
4import hashlib
5import os
6from pathlib import Path
7import shlex
8import subprocess
9import tempfile
10
11ROOT = Path(__file__).resolve().parents[1]
12SOURCE = ROOT / "om/encoder/bw_enc_sm121.om"
13PIN = "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f"
14MUTANTS = (
15 ("wrong-dadd-opcode", "wda o 29225 0 rb o 3", "wda o 29224 0 rb o 3"),
16 ("swapped-dfma-operands", "wda o 29227 rb o 3 rb o 4", "wda o 29227 rb o 4 rb o 3"),
17 ("dropped-pair-alignment", "if or ne and r 1 0 ge r 254", "if or ne and r 0 0 ge r 254"),
18 ("wrong-dsetp-mode", "get o 6 66084864 ctl o 926720", "get o 6 66060288 ctl o 926720"),
19 ("bound-off-by-one", "if gt op 79", "if gt op 80"),
20 ("wrong-mufu-function", "pick eq op 73 6144 7168", "pick eq op 73 7168 6144"),
21)
22
23
24def main():
25 omc = Path(os.environ["OMEGA_OMC"])
26 bridge = Path(os.environ["OMEGA_BRIDGE"]) / "tools/bridge-seeded"
27 if hashlib.sha256(omc.read_bytes()).hexdigest() != PIN:
28 raise RuntimeError("NOT_RUN: seeded compiler pin differs")
29 # Defense in depth: this gate is a host verifier, never a device consumer. Refuse when a node that
30 # reaches a GPU is visible (NVIDIA, aien-gpu, a VFIO-bound group); /dev/cuse and /dev/vfio/vfio reach none.
31 if (any(Path("/dev").glob("nvidia*")) or any(Path("/dev").glob("aien-gpu*"))
32 or [p for p in Path("/dev/vfio").glob("*") if p.name != "vfio"]):
33 raise RuntimeError("NOT_RUN: run inside the required device-free bwrap namespace")
34 env = dict(os.environ, OMEGA_SEEDED_OMC=str(omc))
35 text = SOURCE.read_text()
36 cc = shlex.split(os.environ.get("CC", "cc"))
37 lib = str(Path(os.environ["OMEGA_TEST_LIB"]).resolve())
38 with tempfile.TemporaryDirectory(prefix="omega-f64-mutants-") as tmp:
39 tmp = Path(tmp)
40 for name, before, after in MUTANTS:
41 if text.count(before) != 1:
42 raise RuntimeError(f"mutation site drift: {name}")
43 source = tmp / (name + ".om")
44 source.write_text(text.replace(before, after))
45 generated = tmp / (name + ".c")
46 with generated.open("w") as out:
47 subprocess.run(["sh", str(bridge), "c", str(source)], cwd=ROOT, env=env, stdout=out, check=True)
48 binary = tmp / name
49 subprocess.run(cc + ["-std=gnu11", "-O2", "-ffp-contract=off", "-Isrc", "-Itests", "-I./m16",
50 "tests/codegen_f64_test.c", str(generated), lib, "-lpthread", "-lm", "-o", str(binary)],
51 cwd=ROOT, check=True)
52 result = subprocess.run([str(binary)], cwd=ROOT, text=True, capture_output=True)
53 if result.returncode != 1 or "codegen-f64: FAIL" not in result.stdout or "f64 check line" not in result.stderr:
54 raise RuntimeError(f"mutant not killed by an assertion: {name}: rc={result.returncode}\n{result.stdout}\n{result.stderr}")
55 print(f"codegen-f64 mutant {name}: KILLED", flush=True)
56 print("codegen-f64 mutants: PASS (6 compiled seeded mutants killed)")
57
58
59if __name__ == "__main__":
60 main()