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 / codegen_tc_host_mutants.py
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | """Mutation and strong-link controls for the TC host unit; run in the host sandbox.""" |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import subprocess |
| 7 | import tempfile |
| 8 | ROOT=Path(__file__).resolve().parents[1] |
| 9 | OUT=Path(os.environ.get('OUT_DIR','build')) |
| 10 | BRIDGE=Path(os.environ['OMEGA_BRIDGE']) |
| 11 | ENV=dict(os.environ,OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC']) |
| 12 | source=(ROOT/'om/codegen/tc_host.om').read_text() |
| 13 | numeric=(ROOT/'om/numeric/numeric.om').read_text() |
| 14 | mutants=[('k-floor','lt k 128','lt k 256'),('tc-k-ceiling','gt k 32768','gt k 16384'),('tc2-k-ceiling','gt k 16384','gt k 8192'),('output-bound','ge mul n mul rt 64 8388608','gt mul n mul rt 64 8388608'),('shared','mul get s 1 4096','mul get s 1 2048'),('weight','shl and get s 0 127 4','shl and get s 0 127 3'),('scale','e = add e 64','e = add e 63'),('permutation','shl tch_bf get s 2 16','shl tch_bf get s 1 16')] |
| 15 | def run(args,**kw):return subprocess.run(args,cwd=ROOT,env=ENV,text=True,**kw) |
| 16 | link=['cc','-std=gnu11','-O2','-ffp-contract=off','-Isrc','tests/codegen_tc_host_diff.c',str(OUT/'codegen_tc_oracle.o'),str(OUT/'codegen_tc2_oracle.o')] |
| 17 | with tempfile.TemporaryDirectory(prefix='tc-host-mutants-') as td: |
| 18 | tmp=Path(td) |
| 19 | for name,before,after in mutants: |
| 20 | if source.count(before)!=1:raise SystemExit('ambiguous site '+name) |
| 21 | om=tmp/(name+'.om'); c=tmp/(name+'.c');exe=tmp/name |
| 22 | om.write_text(numeric+'\n'+source.replace(before,after)) |
| 23 | with c.open('w') as f:r=run(['sh',str(BRIDGE/'tools/bridge-seeded'),'c',str(om)],stdout=f) |
| 24 | if r.returncode:raise SystemExit(name+' conversion failure, not a kill') |
| 25 | r=run(link+[str(c),str(OUT/'libomega_gpu.a'),'-lpthread','-lm','-o',str(exe)]) |
| 26 | if r.returncode:raise SystemExit(name+' link failure, not a kill') |
| 27 | r=run([str(exe)],capture_output=True) |
| 28 | if r.returncode!=1 or 'TC-HOST-DIFF FAIL' not in r.stderr:raise SystemExit(name+' survived') |
| 29 | print('TC-HOST MUTANT '+name+' KILLED',flush=True) |
| 30 | # Hide the sole implementation by symbol renaming, not a weak fallback. |
| 31 | missing=tmp/'missing.o' |
| 32 | r=run(['cc','-O2','-Isrc','-Domega_tc_host=removed_omega_tc_host','-c','src/cudapp_om_tc_host.c','-o',str(missing)]) |
| 33 | if r.returncode:raise SystemExit('negative compile failed') |
| 34 | archive=tmp/'missing.a' |
| 35 | objects=[str(p) for p in OUT.glob('*.o') if p.name not in ('cudapp_om_tc_host.o','codegen_tc_oracle.o','codegen_tc2_oracle.o')] |
| 36 | r=run(['ar','rcs',str(archive),*objects,str(missing)]) |
| 37 | if r.returncode:raise SystemExit('negative archive failed') |
| 38 | r=run(link+[str(archive),'-lpthread','-lm','-o',str(tmp/'missing')],capture_output=True) |
| 39 | if r.returncode==0 or 'omega_tc_host' not in r.stderr:raise SystemExit('strong-link negative failed') |
| 40 | print('TC-HOST STRONG-LINK PASS') |
| 41 | print('TC-HOST MUTANTS PASS (8 killed)') |