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

33 lines · 1943 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/workspace.om').read_text()
7mutants={
8 'drop_row_capacity':('if gt rows capacity','if lt rows capacity'),
9 'drop_padding':('if gt add rows bm padded','if lt add rows bm padded'),
10 'drop_tile_capacity':('if gt needed tiles','if lt needed tiles'),
11 'lose_guard_tile':('needed = add div add rows sub bm 1 bm 1','needed = div add rows sub bm 1 bm'),
12 'admit_zero_rows':('if or eq rows 0 gt rows 4294967295','if or eq rows 1 gt rows 4294967295'),
13}
14
15ident=(root/'src/cudapp_om_prefill_workspace.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/workspace-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)