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
CUDApp / tests / gpu_resident_mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Compile seeded source mutants; each must build, then fail the independent oracle.""" |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import subprocess |
| 7 | import sys |
| 8 | import tempfile |
| 9 | ROOT=Path(__file__).resolve().parents[1] |
| 10 | MUTANTS={ |
| 11 | 'drop-grid-barrier': ('gridbar ins m\n', 'note mutant drops grid barrier\n'), |
| 12 | 'wrong-matvec': ('ef ins m FMUL r4 19 19 20 NONE 0', 'ef ins m FADD r4 19 19 20 NONE 0'), |
| 13 | 'descriptor-output-bound': ('if or not spanok a na size not spanok out rows size', 'if not spanok a na size'), |
| 14 | 'contracted-matvec': ('ef ins m FMUL r4 19 19 20 NONE 0', 'ef ins m 33 r4 19 19 20 18 0\nmov ins m 18 0'), |
| 15 | 'stale-generation': ('atomic ins m 27 27 3 26', 'atomic ins m 27 27 3 22'), |
| 16 | 'wrong-queue-stride': ('ef ins m IMADW r4 4 9 NONE 0 32', 'ef ins m IMADW r4 4 9 NONE 0 16'), |
| 17 | 'fixed-latency-thread-id': ('emit ins m okk S2R KVAR 0 NONE r4 8 NONE NONE NONE 33', 'ef ins m S2R r4 8 NONE NONE NONE 33'), |
| 18 | } |
| 19 | def main(): |
| 20 | bridge=os.environ.get('OMEGA_BRIDGE') |
| 21 | omc=os.environ.get('OMEGA_OMC') |
| 22 | if not bridge or not omc: |
| 23 | print('NOT_RUN: OMEGA_BRIDGE and OMEGA_OMC are required');return 2 |
| 24 | env=dict(os.environ,OMEGA_SEEDED_OMC=omc) |
| 25 | source=(ROOT/'om/resident/resident.om').read_text() |
| 26 | check=(ROOT/'om/resident/check.om').read_text() |
| 27 | archive=Path(sys.argv[1]).resolve() |
| 28 | with tempfile.TemporaryDirectory(prefix='resident-mutants-') as tmp: |
| 29 | t=Path(tmp) |
| 30 | for name,(old,new) in MUTANTS.items(): |
| 31 | if source.count(old)!=1: raise RuntimeError(f'{name}: expected one mutation site') |
| 32 | mutant=source.replace(old,new) |
| 33 | outputs=[] |
| 34 | for suffix,text in [('emit',mutant),('check',mutant+'\n'+check)]: |
| 35 | om=t/f'{name}-{suffix}.om';c=om.with_suffix('.c');om.write_text(text) |
| 36 | with c.open('w') as out: |
| 37 | subprocess.run(['sh',str(Path(bridge)/'tools/bridge-seeded'),'c',str(om)],stdout=out,env=env,check=True) |
| 38 | outputs.append(str(c)) |
| 39 | exe=t/name |
| 40 | subprocess.run([os.environ.get('CC','cc'),'-std=gnu11','-O2','-D_GNU_SOURCE','-ffp-contract=off','-I'+str(ROOT/'src'),'-I'+str(ROOT/'tests'),str(ROOT/'tests/gpu_resident_test.c'),str(ROOT/'src/omega_bw_hazard.c'),str(ROOT/'src/omega_gpu_resident.c'),*outputs,str(archive),'-lpthread','-lm','-o',str(exe)],check=True) |
| 41 | got=subprocess.run([str(exe),'--sim'],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True) |
| 42 | if got.returncode==0: raise RuntimeError(name+': SURVIVED') |
| 43 | print(f'{name}: KILLED rc={got.returncode}',flush=True) |
| 44 | print('GPU RESIDENT SOURCE MUTANTS PASS');return 0 |
| 45 | if __name__=='__main__': sys.exit(main()) |