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

33 lines · 1880 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2# External source-mutant verification, not a production dependency.
3import hashlib,os,subprocess,tempfile
4from pathlib import Path
5root=Path(__file__).resolve().parents[2]
6source=(root/'om/prefill-shape/reading.om').read_text()
7mutants={
8 'reading_threshold':('if le rows 64\nret 4','if le rows 63\nret 4'),
9 'reading_group':('if le rows 64\nret 0','if le rows 65\nret 0'),
10 'reading_wait':('if eq index 2\nret 45','if eq index 2\nret 0'),
11 'reading_zero':('if or eq rows 0 gt rows 4294967295','if or eq rows 1 gt rows 4294967295'),
12 'reading_index':('if gt index 3','if gt index 4'),
13
14}
15ident=(root/'src/cudapp_om_prefill_reading.ident').read_text().strip()
16pins=dict(part.split('=',1) for part in ident.split() if '=' in part)
17assert hashlib.sha256(Path(os.environ['OMEGA_OMC']).read_bytes()).hexdigest()==pins['omc']
18env=dict(os.environ,OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC'])
19bridge=Path(os.environ['OMEGA_BRIDGE'])/'tools/bridge-seeded'
20assert hashlib.sha256(bridge.read_bytes()).hexdigest()==pins['frontend']
21assert hashlib.sha256((bridge.parent.parent/'src/toc.om').read_bytes()).hexdigest()==pins['converter']
22with tempfile.TemporaryDirectory(prefix='prefill-shape-mutants-') as t:
23 t=Path(t)
24 for name,(old,new) in mutants.items():
25 assert source.count(old)==1
26 om=t/(name+'.om');om.write_text(source.replace(old,new))
27 c=t/(name+'.c');so=t/(name+'.so')
28 with c.open('w') as f:subprocess.run(['sh',str(bridge),'c',str(om)],env=env,stdout=f,check=True)
29 subprocess.run([os.environ.get('CC','cc'),'-O2','-shared','-fPIC',str(c),'-o',str(so)],check=True)
30 p=subprocess.run(['python3',str(root/'om/prefill-shape/reading-check.py'),str(so)],capture_output=True,text=True)
31 assert p.returncode!=0,name+' escaped oracle'
32 assert 'AssertionError' in p.stderr,(name,p.stderr)
33 print(name+': caught',flush=True)