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_base / mutants.py

46 lines · 2501 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Mutate copies only; regenerate each with the pinned seeded compiler and exercise the real replay path."""
4import os
5import pathlib
6import shlex
7import subprocess
8
9root = pathlib.Path(__file__).resolve().parents[2]
10out = pathlib.Path(os.environ.get('CODEGEN_BASE_OUT', root / 'build/codegen-base-om'))
11objects = shlex.split(os.environ['CODEGEN_BASE_OBJECTS'])
12flags = shlex.split('-std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -ffunction-sections -fdata-sections -Isrc')
13cc = shlex.split(os.environ.get('CC', 'cc'))
14mutants = [
15 ('cg_fields', 'put rec 6 or get raw 6 shl get raw 7 32', 'put rec 6 or get raw 6 shl get raw 7 31'),
16 ('cg_replay', 'if gt get ins b maxop', 'if ge get ins b maxop'),
17 ('cg_life', 'put life add b 1 ulong e', 'put life add b 1 ulong s'),
18 ('cg_invar', 'ret 6', 'ret 0'),
19 ('cg_budget', 'if gt mul decl threads 65536', 'if gt mul decl threads 65535'),
20]
21for unit, old, new in mutants:
22 source = (root / 'om/codegen' / (unit + '.om')).read_text()
23 if source.count(old) != 1:
24 raise SystemExit('FAIL: mutant site is not unique: ' + unit)
25 d = out / ('mutant-' + unit)
26 d.mkdir(exist_ok=True)
27 om = d / (unit + '.om')
28 om.write_text(source.replace(old, new))
29 env = dict(os.environ, OMEGA_UNITS=str(om), OMEGA_UNITS_DEST=str(d))
30 with (d / 'generate.log').open('w') as log:
31 subprocess.run(['sh', 'om/units.sh'], cwd=root, env=env, stdout=log, stderr=subprocess.STDOUT, check=True)
32 obj = d / (unit + '.o')
33 providers = sorted(d.glob('cudapp_*_' + unit + '.c'))
34 assert len(providers) == 1, providers
35 subprocess.run(cc + flags + ['-c', str(providers[0]), '-o', str(obj)], cwd=root, check=True)
36 replace = providers[0].with_suffix('.o').name
37 selected = [str(obj) if pathlib.Path(o).name == replace else o for o in objects]
38 assert sum(pathlib.Path(o).name == replace for o in objects) == 1
39 exe = d / 'differential'
40 subprocess.run(cc + flags + ['tests/codegen_base/differential.c'] + selected + ['--coverage', '-Wl,--gc-sections', '-o', str(exe)], cwd=root, check=True)
41 with (d / 'run.log').open('w') as log:
42 result = subprocess.run([str(exe)], cwd=root, stdout=log, stderr=subprocess.STDOUT)
43 if result.returncode == 0:
44 raise SystemExit('FAIL: mutant survived: ' + unit)
45 print('KILLED', unit, 'rc', result.returncode, flush=True)
46print('CODEGEN BASE MUTANTS PASS: 5 killed')