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

35 lines · 2227 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Recompile five actual graph-bank semantic changes; the independent C oracle must reject each."""
4import os
5from pathlib import Path
6import shlex
7import subprocess
8import tempfile
9ROOT=Path(__file__).resolve().parents[2]
10SOURCE=ROOT/'om/graph/record.om'
11MUTANTS=[
12 ('low-address-bit','put w mul i 2 uint and get v i 4294967295','put w mul i 2 uint and get v i 4294967294'),
13 ('high-address-shift','put w add mul i 2 1 uint shr get v i 32','put w add mul i 2 1 uint shr get v i 31'),
14 ('norm-epsilon-binding','put w 10 uint and get v 5 4294967295\nput w 11','put w 10 uint and get v 6 4294967295\nput w 11'),
15 ('swiglu-scale-binding','put w 4 uint and get v 2 4294967295','put w 4 uint and get v 3 4294967295'),
16 ('gate-length-binding','put w 6 uint and get v 3 4294967295','put w 6 uint and get v 4 4294967295'),
17]
18def run(cmd,**kw):
19 print('+',shlex.join(map(str,cmd)),flush=True)
20 return subprocess.run(list(map(str,cmd)),cwd=ROOT,**kw)
21source=SOURCE.read_text()
22for name,old,new in MUTANTS:
23 if source.count(old)!=1:raise SystemExit(f'{name}: expected exactly one mutation site')
24 with tempfile.TemporaryDirectory(prefix='model-graph-mutant-') as tmp:
25 tmp=Path(tmp);mut=tmp/'record.om';mut.write_text(source.replace(old,new));dest=tmp/'gen'
26 dest.mkdir()
27 env=dict(os.environ,OMEGA_UNITS=f'model_graph_wire={mut},om/graph/entry_wire.om',OMEGA_UNITS_DEST=str(dest))
28 if run(['sh','om/units.sh'],env=env).returncode:raise SystemExit(f'{name}: compilation failed, NOT killed')
29 binary=tmp/'check'
30 if run(shlex.split(os.environ.get('CC','cc'))+['-std=gnu11','-O2','-Wall','-Wextra','-Werror','-Isrc','tests/test_model_graphs_om.c',dest/'cudapp_om_model_graph_wire.c','-o',binary]).returncode:raise SystemExit(f'{name}: host compilation failed, NOT killed')
31 result=run([binary],capture_output=True,text=True)
32 print(result.stdout,end='');print(result.stderr,end='')
33 if result.returncode!=1 or 'FAIL graph wire' not in result.stderr:raise SystemExit(f'{name}: mutant survived or unrelated failure rc={result.returncode}')
34 print(f'MODEL-GRAPHS mutant {name} KILLED',flush=True)
35print('MODEL-GRAPHS mutants PASS killed=5 compiled=5')