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

45 lines · 2580 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Compile five altered Omega planners; require behavioral (not build) failures."""
4import os
5from pathlib import Path
6import shlex
7import subprocess
8import sys
9
10root = Path(__file__).resolve().parents[1]
11work = root / os.environ.get('OUT_DIR', 'build') / 'om-cmdlist' / 'mutants'
12work.mkdir(parents=True, exist_ok=True)
13source = (root / 'om/cmdlist/plan.om').read_text()
14mutants = [
15 ('drop-required-barrier', 'h = clhazards p i get o 3', 'h = ulong 0', 'sim'),
16 ('capacity-off-by-one', 'if gt get a 0 get a 1', 'if ge get a 0 get a 1', 'planner'),
17 ('wrong-RAW-class', 'h = or h 1', 'h = or h 2', 'planner'),
18 ('adjacent-only', 'mul add start j 49', 'mul sub i 1 49', 'planner'),
19 ('under-count-pushbuffer', 'put o 0 35', 'put o 0 34', 'planner'),
20]
21cc = shlex.split(os.environ.get('CC', 'cc'))
22for name, old, new, check in mutants:
23 if source.count(old) != 1:
24 sys.exit('FAIL mutant site is not unique: ' + name)
25 directory = work / name
26 directory.mkdir(exist_ok=True)
27 om = directory / 'plan.om'
28 om.write_text(source.replace(old, new))
29 env = dict(os.environ, OMEGA_UNITS='cmdlist_plan=' + str(om), OMEGA_UNITS_DEST=str(directory))
30 with (directory / 'build.log').open('w') as log:
31 subprocess.run(['sh', 'om/units.sh'], cwd=root, env=env, stdout=log, stderr=log, check=True)
32 test = root / ('tests/cmdlist_sim_test.c' if check == 'sim' else 'tests/cmdlist_plan_test.c')
33 command = cc + ['-std=gnu11', '-O2', '-ffp-contract=off', '-Isrc', '-Itests', str(test), str(directory/'cudapp_om_cmdlist_plan.c')]
34 if check == 'sim':
35 command += [str(root/os.environ.get('OUT_DIR','build')/'libomega_gpu.a'), '-lpthread', '-lm']
36 else:
37 command += ['src/cudapp_om_cmdlist_record.c', 'src/cudapp_om_cmdlist_layout.c', 'src/omega_blackwell_qmd.c', 'src/cudapp_om_bw_qmd.c']
38 command += ['-o', str(directory/'check')]
39 subprocess.run(command, cwd=root, stdout=log, stderr=log, check=True)
40 run = subprocess.run([str(directory/'check')], cwd=root, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
41 (directory/'run.log').write_text(run.stdout)
42 if run.returncode != 1 or (check == 'sim' and 'FAIL sim data:' not in run.stdout):
43 sys.exit('FAIL mutant survived or failed outside the data check: ' + name + '\n' + run.stdout)
44 print('PASS red mutant: ' + name + ' rc=1 ' + run.stdout.splitlines()[-1])
45print('PASS five compiled Omega mutants rejected by behavior')