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 / om / attention-mirror / mutants.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | # External source-mutant verification, not a production dependency. |
| 3 | import hashlib,os,subprocess,tempfile |
| 4 | from pathlib import Path |
| 5 | root=Path(__file__).resolve().parents[2] |
| 6 | source=(root/'om/attention-mirror/plan.om').read_text() |
| 7 | mutants={ |
| 8 | 'lose_plane_slack':('add mul maxpos 2048 8256','mul maxpos 2048'), |
| 9 | 'admit_wrong_shape':('ne qheads 24','eq qheads 24'), |
| 10 | 'lose_position_bound':('if gt rows sub maxpos pos','if lt rows sub maxpos pos'), |
| 11 | 'copy_tiny_requests':('lt rows 1024','lt rows 1'), |
| 12 | 'copy_one_plane':('ret mul plane 2','ret plane'), |
| 13 | } |
| 14 | |
| 15 | |
| 16 | ident=(root/'src/cudapp_om_attn_mirror_plan.ident').read_text().strip() |
| 17 | pins=dict(part.split('=',1) for part in ident.split() if '=' in part) |
| 18 | assert hashlib.sha256(Path(os.environ['OMEGA_OMC']).read_bytes()).hexdigest()==pins['omc'] |
| 19 | env=dict(os.environ,OMEGA_SEEDED_OMC=os.environ['OMEGA_OMC']) |
| 20 | bridge=Path(os.environ['OMEGA_BRIDGE'])/'tools/bridge-seeded' |
| 21 | assert hashlib.sha256(bridge.read_bytes()).hexdigest()==pins['frontend'] |
| 22 | assert hashlib.sha256((bridge.parent.parent/'src/toc.om').read_bytes()).hexdigest()==pins['converter'] |
| 23 | with tempfile.TemporaryDirectory(prefix='prefill-shape-mutants-') as t: |
| 24 | t=Path(t) |
| 25 | for name,(old,new) in mutants.items(): |
| 26 | assert source.count(old)==1 |
| 27 | om=t/(name+'.om');om.write_text(source.replace(old,new)) |
| 28 | c=t/(name+'.c');so=t/(name+'.so') |
| 29 | with c.open('w') as f:subprocess.run(['sh',str(bridge),'c',str(om)],env=env,stdout=f,check=True) |
| 30 | subprocess.run([os.environ.get('CC','cc'),'-O2','-shared','-fPIC',str(c),str(root/'src/cudapp_om_attn_mirror_step.c'),'-o',str(so)],check=True) |
| 31 | p=subprocess.run(['python3',str(root/'om/attention-mirror/check.py'),str(so)],capture_output=True,text=True) |
| 32 | assert p.returncode!=0,name+' escaped oracle' |
| 33 | assert 'AssertionError' in p.stderr,(name,p.stderr) |
| 34 | print(name+': caught',flush=True) |
| 35 | |
| 36 | source=(root/'om/attention-mirror/step.om').read_text() |
| 37 | mutants={ |
| 38 | 'advance_failed_copy':('if ne ok 1','if gt ok 1'), |
| 39 | 'skip_copy':('ret 3','ret 4'), |
| 40 | 'reuse_too_small':('if gt need have','if lt need have'), |
| 41 | 'accept_short_allocation':('if lt have need','if gt have need'), |
| 42 | } |
| 43 | with tempfile.TemporaryDirectory(prefix='attention-step-mutants-') as t: |
| 44 | t=Path(t) |
| 45 | for name,(old,new) in mutants.items(): |
| 46 | assert source.count(old)==1 |
| 47 | om=t/(name+'.om');om.write_text(source.replace(old,new)) |
| 48 | c=t/(name+'.c');so=t/(name+'.so') |
| 49 | with c.open('w') as f:subprocess.run(['sh',str(bridge),'c',str(om)],env=env,stdout=f,check=True) |
| 50 | subprocess.run([os.environ.get('CC','cc'),'-O2','-shared','-fPIC',str(c),str(root/'src/cudapp_om_attn_mirror_plan.c'),'-o',str(so)],check=True) |
| 51 | p=subprocess.run(['python3',str(root/'om/attention-mirror/check.py'),str(so)],capture_output=True,text=True) |
| 52 | assert p.returncode!=0 and 'AssertionError' in p.stderr,(name,p.stderr) |
| 53 | print(name+': caught',flush=True) |