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

68 lines · 3477 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Mutate Omega sources, regenerate checked bindings, run the C differential oracle.
4Run only inside the prescribed bwrap; inherited /dev must hide GPU devices.
5"""
6import os
7from pathlib import Path
8import subprocess
9import sys
10import tempfile
11
12root = Path(__file__).resolve().parents[1]
13build = (root / sys.argv[1]).resolve()
14files = ['ew_emit.om', 'ew_scalar.om', 'ew_reconv.om', 'ew_prime.om', 'ew_ir.om']
15mutants = [
16 ('descriptor-offset', 'ew_emit.om', 'NR NR NR 856', 'NR NR NR 864'),
17 ('argument-b-offset', 'ew_emit.om', 'r4 1 NR NR NR 904', 'r4 1 NR NR NR 896'),
18 ('cta-register', 'ew_emit.om', 'S2R r4 4 NR NR NR 37', 'S2R r4 4 NR NR NR 33'),
19 ('pair-latency', 'ew_emit.om', 'shl ulong 5 9', 'shl ulong 4 9'),
20 ('ex2-dispatch', 'ew_ir.om', 'ex2 ins meta', 'xchg ins meta'),
21]
22def run(cmd, **kw):
23 return subprocess.run(cmd, cwd=root, text=True, stdout=subprocess.PIPE,
24 stderr=subprocess.STDOUT, **kw)
25
26if Path('/dev/nvidiactl').exists() or Path('/dev/nvidia0').exists():
27 raise SystemExit('FAIL: mutation gate requires bwrap private /dev')
28base = run([str(build / 'ew_diff')])
29if base.returncode != 0:
30 raise SystemExit('FAIL baseline\n' + base.stdout)
31print(base.stdout.strip())
32for name, filename, old, new in mutants:
33 with tempfile.TemporaryDirectory(prefix='ew-mut-', dir=build) as tmp:
34 tmp = Path(tmp)
35 sources = []
36 for f in files:
37 text = (root / 'om/kgen' / f).read_text()
38 if f == filename:
39 if text.count(old) != 1:
40 raise SystemExit(f'FAIL {name}: mutation site count {text.count(old)}')
41 text = text.replace(old, new)
42 dest = tmp / f
43 dest.write_text(text)
44 sources.append(str(dest))
45 generated = tmp / 'generated'
46 generated.mkdir()
47 env = dict(os.environ, OMEGA_UNITS='ew_ir=' + ','.join(sources),
48 OMEGA_UNITS_DEST=str(generated))
49 result = run(['sh', 'om/units.sh'], env=env)
50 if result.returncode:
51 raise SystemExit(f'FAIL {name}: generation is not a killed semantic mutant\n{result.stdout}')
52 obj, exe = tmp / 'mutant.o', tmp / 'diff'
53 result = run([os.environ.get('CC', 'cc'), '-O2', '-Isrc', '-ffunction-sections',
54 '-fdata-sections', '-c', str(generated / 'cudapp_om_ew_ir.c'), '-o', str(obj)])
55 if result.returncode:
56 raise SystemExit(f'FAIL {name}: compile\n{result.stdout}')
57 core = {'ew_diff.o', 'omega_blackwell_codegen.o', 'omega_gpu_om_ir.o', 'omega_cubin.o', 'sha256.o'}
58 objects = [p for p in sorted(build.glob('*.o'))
59 if p.name in core or (p.name.startswith('cudapp_') and p.name != 'cudapp_om_ew_ir.o')]
60 result = run([os.environ.get('CC', 'cc'), '-Wl,--gc-sections', '-o', str(exe),
61 str(obj), *map(str, objects), '-lpthread', '-lm'])
62 if result.returncode:
63 raise SystemExit(f'FAIL {name}: link\n{result.stdout}')
64 result = run([str(exe)])
65 if result.returncode != 1 or not any(line.startswith('FAIL ') for line in result.stdout.splitlines()):
66 raise SystemExit(f'FAIL {name}: survived or crashed rc={result.returncode}\n{result.stdout}')
67 print(f'KILLED {name}: {result.stdout.strip()}')
68print('PASS API EW seeded semantic mutants: 5 killed')