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 / om / graph / residue-mutants.py

49 lines · 2570 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Compile semantic Omega mutants and require the real differential to turn red.
4Run only inside the documented bwrap environment, including every child.
5"""
6import os
7from pathlib import Path
8import shlex
9import subprocess
10
11root = Path(__file__).resolve().parents[2]
12os.chdir(root)
13out = Path(os.environ.get('OUT_DIR', 'build')).resolve()
14work = out / 'graph-residue-mutants'
15work.mkdir(parents=True, exist_ok=True)
16def run(args, **kw):
17 return subprocess.run(args, check=True, **kw)
18expected = subprocess.check_output([str(out / 'graph-residue')])
19mutants = [
20 ('poison', 'hello_host', 'hello.om', 'uint 4290838510', 'uint 4290838509'),
21 ('input-period', 'hello_host', 'hello.om', 'rem i 7', 'rem i 6'),
22 ('checker-sub', 'hello_host', 'hello.om', 'bitcast uint add x y', 'bitcast uint sub x y'),
23 ('shape-cap', 'model_graph_residue', 'residue.om', 'gt hd 5120', 'gt hd 4096'),
24 ('timeline-room', 'model_graph_residue', 'residue.om', 'sub get c 2 get c 0', 'add sub get c 2 get c 0 1'),
25 ('perm-stride', 'model_graph_table', 'table.om', 'mul rem div j 4 32 16', 'mul rem div j 4 32 8'),
26 ('load-scoreboard', 'hello_plan', 'hello-plan.om', 'wb = 0', 'wb = 1'),
27]
28for name, unit, filename, old, new in mutants:
29 source = (root / 'om/graph' / filename).read_text()
30 if source.count(old) != 1:
31 raise SystemExit(f'FAIL {name}: mutation site count {source.count(old)}')
32 lane = work / name
33 lane.mkdir(exist_ok=True)
34 om = lane / 'mutant.om'
35 om.write_text(source.replace(old, new))
36 env = dict(os.environ, OMEGA_UNITS=f'{unit}={om}', OMEGA_UNITS_DEST=str(lane))
37 with (lane/'generate.log').open('w') as log:
38 run(['sh', 'om/units.sh'], env=env, stdout=log, stderr=log)
39 binary = lane / 'test'
40 with (lane/'compile.log').open('w') as log:
41 run(shlex.split(os.environ.get('CC','cc')) + shlex.split(os.environ['GRAPH_RESIDUE_FLAGS']) +
42 ['tests/test_graph_residue.c', str(lane/f'cudapp_om_{unit}.c'), str(out/'libomega_gpu.a'),
43 '-lpthread','-lm','-o',str(binary)], stdout=log, stderr=log)
44 result = subprocess.run([str(binary)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
45 (lane/'run.log').write_bytes(result.stdout)
46 if result.returncode == 0 and result.stdout == expected:
47 raise SystemExit(f'FAIL mutant {name} survived')
48 print(f'mutant {name} killed rc={result.returncode}', flush=True)
49print(f'PASS graph residue: {len(mutants)} compiled semantic mutants killed')