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

38 lines · 2414 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2# External verification, never a production dependency. Run in device-empty bwrap.
3import hashlib, os, subprocess, tempfile
4from pathlib import Path
5root=Path(__file__).resolve().parents[2]
6lane=root/'om/standalone-oracles'
7source=(lane/'oracles.om').read_text()
8pins=dict(s.split('=',1) for s in (root/'src/cudapp_om_standalone_oracles.ident').read_text().split() if '=' in s)
9bridge=Path(os.environ['OMEGA_BRIDGE'])/'tools/bridge-seeded'
10assert hashlib.sha256(Path(os.environ['OMEGA_OMC']).read_bytes()).hexdigest()==pins['omc']
11assert hashlib.sha256(bridge.read_bytes()).hexdigest()==pins['frontend']
12assert hashlib.sha256((bridge.parent.parent/'src/toc.om').read_bytes()).hexdigest()==pins['converter']
13assert not list(Path('/dev').glob('nvidia*')), 'run inside the documented device-empty bwrap'
14env=dict(os.environ,OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC'])
15mutants={
16 'vadd_multiplier':('2654435761','2654435760'),
17 'grid_round_down':('ret div add a 255 256','ret div a 256'),
18 'mirror_threshold':('ge b 1024','ge b 1025'),
19 'cache_admit_extra':('if lt a 2','if lt a 3'),
20 'reading_boundary':('if eq op 15\nif le a 64','if eq op 15\nif lt a 64'),
21 'budget_short':('ret 2147483648','ret 2147483647'),
22 'accept_infinity':('if lt and a 2147483647 2139095040','if le and a 2147483647 2139095040'),
23 'rng_multiplier':('1664525','1664526'),
24 'norm_sparse_tail':('if eq a 5119','if eq a 5120'),
25}
26with tempfile.TemporaryDirectory(prefix='standalone-mutants-') as directory:
27 tmp=Path(directory)
28 for name,(old,new) in mutants.items():
29 assert source.count(old)==1,(name,'site not unique')
30 om=tmp/(name+'.om');om.write_text(source.replace(old,new))
31 c=tmp/(name+'.c');exe=tmp/name
32 with c.open('w') as output:
33 subprocess.run(['sh',str(bridge),'c',str(om)],env=env,stdout=output,check=True)
34 subprocess.run([os.environ.get('CC','cc'),'-O2','-ffp-contract=off',str(lane/'scalar-check.c'),str(lane/'oracle-c.c'),str(c),'-o',str(exe)],check=True)
35 result=subprocess.run([str(exe)],capture_output=True,text=True)
36 assert result.returncode==1 and 'scalar mismatch' in result.stderr,(name,'escaped or failed for the wrong reason',result)
37 print('KILLED '+name+': '+result.stderr.strip(),flush=True)
38print('PASS standalone Omega mutants: all nine compiled source mutants killed',flush=True)