Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/attn_host_check.py # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / attn_host_check.py` 60 lines · 4436 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Run only inside the device-hiding sandbox documented in the evidence.""" 4 import argparse,json,os,subprocess,tempfile 5 from pathlib import Path 6 ROOT=Path(__file__).resolve().parents[1] 7 p=argparse.ArgumentParser();p.add_argument('--out');p.add_argument('--mutants',action='store_true');a=p.parse_args() 8 tmp=None if a.out else tempfile.TemporaryDirectory(prefix='attn-host-') 9 out=Path(a.out or tmp.name).resolve();out.mkdir(parents=True,exist_ok=True);os.chdir(ROOT) 10 commands=[] 11 def run(cmd,expect=0): 12 cmd=[str(x) for x in cmd];r=subprocess.run(cmd,text=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) 13 commands.append({'command':cmd,'rc':r.returncode,'output':r.stdout});(out/'commands.json').write_text(json.dumps(commands,indent=2)+'\n') 14 if r.stdout:print(r.stdout,end='',flush=True) 15 if expect is not None and r.returncode!=expect:raise SystemExit('FAIL command '+str(cmd)) 16 return r 17 cc=os.environ.get('CC','cc');flags=['-std=gnu11','-O2','-ffp-contract=off','-Isrc'] 18 units={'attn_host':'om/api/attn_host.om','attn_scanchk':'om/scan/scan_check.om','attn_clock':'om/api/clock_ns.om'} 19 # om/units.sh generates each unit either seeded (cudapp_om_) or freestanding (cudapp_freest_). 20 providers={} 21 for name in units: 22 found=[p for p in ('src/cudapp_om_'+name+'.c','src/cudapp_freest_'+name+'.c') if (ROOT/p).is_file()] 23 if len(found)!=1:raise SystemExit('FAIL expected exactly one checked provider for '+name+': '+str(found)) 24 providers[name]=found[0] 25 objects={} 26 for name in units: 27 obj=out/(name+'.o');run([cc,*flags,'-c',providers[name],'-o',obj]);objects[name]=obj 28 fixtures=[] 29 for prefix in ['om','c']: 30 obj=out/(prefix+'.o');extra=['-DHOST(x)='+prefix+'_ ## x'] 31 if prefix=='c':extra+=['-DCUDAPP_MIGRATION_PENDING_C_'+name+'=1' for name in ['ATTENTION_HOST_POLICY','SCAN_CHECK_REST','CLOCK_SCALARS']] 32 run([cc,*flags,*extra,'-c','tests/attn_host_fixture.c','-o',obj]);fixtures.append(obj) 33 main=out/'main.o';run([cc,*flags,'-c','tests/attn_host_diff.c','-o',main]) 34 def link(dest,replacements=None,omit=None,expect=0): 35 objs=dict(objects);objs.update(replacements or {}) 36 if omit:del objs[omit] 37 return run([cc,main,*fixtures,*objs.values(),'-o',dest],expect) 38 link(out/'diff');run([out/'diff']) 39 for name in units: 40 r=link(out/'missing',omit=name,expect=None) 41 if not r.returncode:raise SystemExit('FAIL missing-unit linked '+name) 42 print('PASS strong-link red '+name,flush=True) 43 if a.mutants: 44 mutants=[('attn_host','31 `4294967264`','30 `4294967264`'),('attn_host','put q 9 ulong mul v 16','put q 9 ulong mul v 8'),('attn_host','put q 9 add add mul get q 3 4 get q 1 idw','put q 9 add add mul get q 3 3 get q 1 idw'),('attn_host','if gt nr get q 3','if lt nr get q 3'),('attn_host','put q 21 ulong mul uint get q 12 4','put q 21 ulong mul uint get q 12 8'),('attn_scanchk','if eq get w i `2141195181`','if eq get w i `2141195180`'),('attn_scanchk','v = sub v get w sub i 1','v = add v get w sub i 1'),('attn_scanchk','if lt get w i get w sub i 1','if gt get w i get w sub i 1'),('attn_clock','mul s `1000000000`','mul s `1000000`')] 45 env=os.environ.copy();env['OMEGA_SEEDED_OMC']=env['OMEGA_OMC'];rows=[] 46 for num,(name,site,replacement) in enumerate(mutants): 47 source=(ROOT/units[name]).read_text() 48 if source.count(site)!=1:raise SystemExit('FAIL mutant site '+name) 49 om=out/('mutant-'+str(num)+'.om');om.write_text(source.replace(site,replacement)) 50 freest=providers[name].startswith('src/cudapp_freest_') 51 cmd=['sh',str(Path(env['OMEGA_BRIDGE'])/('tools/bridge-freest' if freest else 'tools/bridge-seeded')),*([] if freest else ['--runtime-views']),'c',str(om)] 52 r=subprocess.run(cmd,env=env,text=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 53 commands.append({'command':cmd,'rc':r.returncode,'output':r.stderr}) 54 if r.returncode:raise SystemExit('FAIL mutant generation '+r.stderr) 55 c=om.with_suffix('.c');c.write_text(r.stdout);obj=om.with_suffix('.o');run([cc,*flags,'-c',c,'-o',obj]) 56 exe=out/('mutant-'+str(num));link(exe,{name:obj});r=run([exe],expect=None) 57 if not r.returncode:raise SystemExit('FAIL surviving mutant '+name) 58 rows.append({'unit':name,'site':site,'replacement':replacement,'rc':r.returncode,'verdict':'KILLED'});print('KILLED '+name,flush=True) 59 (out/'mutants.json').write_text(json.dumps(rows,indent=2)+'\n');print('PASS source mutants killed='+str(len(rows)),flush=True) 60 print('ATTN-HOST-CHECK PASS',flush=True)