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

53 lines · 2582 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Reverting the generic replay bound must fail the same boundary regression.
4
5The default build replays through the seeded unit (omega_cg_replay), whose bound
6is the BW_IR_LAST argument; the C replay under CUDAPP_MIGRATION_PENDING_C_CODEGEN_BASE
7is the oracle and carries its own bound. Each is reverted where it is compiled,
8and the unmutated source must pass in both builds first, so a kill is the bound
9and not a broken build.
10"""
11import os
12from pathlib import Path
13import shlex
14import subprocess
15import tempfile
16
17source = Path("src/omega_gpu_om_ir.c").read_text()
18OLD_BOUND = "BW_IR_ATOMG_ADD_F32_STRONG_GPU"
19cases = [
20 # (name, extra cflags, site, reverted site)
21 ("omega-replay", [], " BW_IR_LAST) != OMEGA_OK) return OMEGA_OM_IR_BRIDGE;",
22 " " + OLD_BOUND + ") != OMEGA_OK) return OMEGA_OM_IR_BRIDGE;"),
23 ("c-oracle", ["-DCUDAPP_MIGRATION_PENDING_C_CODEGEN_BASE=1"], "r[0] > (uint64_t)BW_IR_LAST",
24 "r[0] > (uint64_t)" + OLD_BOUND),
25]
26cc = shlex.split(os.environ.get("CC", "cc"))
27lib = os.environ.get("OMEGA_TEST_LIB", "build/libomega_gpu.a")
28
29
30def run(root, name, flags, text):
31 unit = root / (name + ".c")
32 unit.write_text(text)
33 binary = root / name
34 subprocess.run(cc + ["-std=gnu11", "-O2", "-Isrc", "-Itests", "-I./m16"] + flags +
35 ["-o", str(binary), "tests/gpu_om_ir_boundary_test.c", str(unit), lib,
36 "-lpthread", "-lm"], check=True)
37 return subprocess.run([str(binary)], text=True, capture_output=True)
38
39
40with tempfile.TemporaryDirectory(prefix="om-ir-boundary-") as tmp:
41 root = Path(tmp)
42 for name, flags, site, reverted in cases:
43 if source.count(site) != 1:
44 raise SystemExit(f"om-ir-boundary-mutant: FAIL ({name} mutation site not unique)")
45 control = run(root, name + "-control", flags, source)
46 if control.returncode != 0:
47 raise SystemExit(f"om-ir-boundary-mutant: FAIL ({name} unmutated control failed: "
48 f"{control.stderr.strip()})")
49 mutant = run(root, name + "-mutant", flags, source.replace(site, reverted))
50 if mutant.returncode != 1 or "om-ir-boundary: FAIL" not in mutant.stderr:
51 raise SystemExit(f"om-ir-boundary-mutant: FAIL ({name} reverted bound survived)")
52 print(f"om-ir-boundary-mutant: {name} control PASS, reverted-bound mutant killed")
53print("om-ir-boundary-mutant: PASS (Omega replay and C oracle reverted-bound mutants killed)")