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/api_rest_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 / api_rest_check.py` 79 lines · 5838 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Device-free residual migration differential and source-mutant gate. 4 Run inside the device-hiding bwrap invocation recorded in the lane evidence. 5 """ 6 import argparse 7 import json 8 import os 9 from pathlib import Path 10 import re 11 import subprocess 12 import tempfile 13 ROOT=Path(__file__).resolve().parents[1] 14 p=argparse.ArgumentParser();p.add_argument('--out');p.add_argument('--mutants',action='store_true');a=p.parse_args() 15 tmp=None if a.out else tempfile.TemporaryDirectory(prefix='api-rest-') 16 out=Path(a.out if a.out else tmp.name).resolve();out.mkdir(parents=True,exist_ok=True);os.chdir(ROOT) 17 commands=[] 18 def run(cmd,expect=0): 19 cmd=[str(x) for x in cmd];r=subprocess.run(cmd,text=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) 20 commands.append({'command':cmd,'rc':r.returncode,'output':r.stdout});(out/'commands.json').write_text(json.dumps(commands,indent=2)+'\n') 21 if r.stdout:print(r.stdout,end='',flush=True) 22 if expect is not None and r.returncode!=expect:raise SystemExit('FAIL command '+str(cmd)) 23 return r 24 cc=os.environ.get('CC','cc');flags=['-std=gnu11','-O2','-ffp-contract=off','-ffunction-sections','-fdata-sections','-Isrc','-Itests'] 25 units=dict(re.findall(r'^UNITS="\$UNITS (attn_(?:ds|na|mm)_\w+)=([^"\n]+)"$',(ROOT/'om/units.sh').read_text(),re.M)) 26 objects={};providers={} 27 for name in units: 28 matches=sorted((ROOT/'src').glob('cudapp_*_'+name+'.c')) 29 if len(matches)!=1:raise SystemExit('FAIL expected exactly one provider '+name) 30 providers[name]=matches[0] 31 obj=out/(name+'.o');run([cc,*flags,'-c',providers[name],'-o',obj]);objects[name]=obj 32 # parse_semver's existing Omega root is outside this residual slice. 33 obj=out/'artifact_parse.o';run([cc,*flags,'-c','src/cudapp_om_artifact_parse.c','-o',obj]);objects['artifact_parse']=obj 34 obj=out/'attn_buf.o';run([cc,*flags,'-c','src/cudapp_freest_attn_buf.c','-o',obj]);objects['attn_buf']=obj 35 obj=out/'blackwell_matmul.o';run([cc,*flags,'-c','src/omega_blackwell_matmul.c','-o',obj]);objects['blackwell_matmul']=obj 36 obj=out/'bw_scalar.o';run([cc,*flags,'-c','src/cudapp_freest_bw_scalar.c','-o',obj]);objects['bw_scalar']=obj 37 obj=out/'decode_scalar.o';run([cc,*flags,'-c','src/omega_gpu_decode_attn_api.c','-o',obj]) 38 run([os.environ.get('OBJCOPY','objcopy'),'-G','omega_dattn_bf16_rne',obj]);objects['decode_scalar']=obj 39 fixtures=[] 40 for kind,names in [('art',['cubin','layout','version','json']),('mm',['oracle'])]: 41 for prefix in ['om','c']: 42 obj=out/(kind+'-'+prefix+'.o');extra=['-DREST(x)='+prefix+'_ ## x','-DCUDAPP_MIGRATION_PENDING_C_ARTIFACT=1'] 43 if prefix=='c':extra+=['-DCUDAPP_MIGRATION_PENDING_C_NATIVE_ARTIFACT_REST=1','-DCUDAPP_MIGRATION_PENDING_C_MATMUL_ORACLE_GUARD=1'] 44 run([cc,*flags,*extra,'-c','tests/api_rest_'+kind+'_fixture.c','-o',obj]) 45 # Localize unrelated API exports in the fixture, keeping only accessors. 46 keep=[] 47 for name in names:keep+=['-G',prefix+'_'+name] 48 run([os.environ.get('OBJCOPY','objcopy'),*keep,obj]);fixtures.append(obj) 49 main=out/'main.o';run([cc,*flags,'-c','tests/api_attn_rest_diff.c','-o',main]) 50 def link(dest,replacements=None,omit=None,expect=0): 51 objs=dict(objects);objs.update(replacements or {}) 52 if omit:del objs[omit] 53 return run([cc,'-Wl,--gc-sections',main,*fixtures,*objs.values(),'-lm','-o',dest],expect=expect) 54 link(out/'diff');run([out/'diff']) 55 # Strong-reference red control: omitting a migrated implementation must not link. 56 for name in ['attn_ds_round','attn_na_cubin','attn_mm_dot']: 57 r=link(out/'missing',omit=name,expect=None) 58 if not r.returncode:raise SystemExit('FAIL missing-unit linked '+name) 59 print('PASS strong-link red '+name,flush=True) 60 if a.mutants: 61 mutants=[('attn_ds_round','fn av_drnd u uint to uint\nif gx_fin u','fn av_drnd u uint to uint\nif not gx_fin u'),('attn_ds_slot','p = div r 2','p = div r 3'),('attn_ds_vecf','ret av_permf s d r','ret av_permf s d 256'),('attn_na_cubin','ret ar_eq b off txt','ret true'),('attn_na_layout','if ge len b cap','if ge len b 1'),('attn_na_ver','ret gt get h i get n i','ret lt get h i get n i'),('attn_na_json','if or lt c 32 eq c 127','if lt c 32'),('attn_mm_dot','ret bitcast ulong mul x y','ret bitcast ulong add x y'),('attn_mm_err','if gt rel 0.00001','if gt rel 100.0')] 62 env=os.environ.copy();env['OMEGA_SEEDED_OMC']=env['OMEGA_OMC'];rows=[] 63 for num,(name,site,replacement) in enumerate(mutants): 64 source='\n'.join((ROOT/x).read_text() for x in units[name].split(','))+'\n' 65 if source.count(site)!=1:raise SystemExit('FAIL mutant site '+name) 66 om=out/('mutant-'+str(num)+'.om');om.write_text(source.replace(site,replacement)) 67 freestanding=providers[name].name.startswith('cudapp_freest_') 68 cmd=['sh',str(Path(env['OMEGA_BRIDGE'])/('tools/bridge-freest' if freestanding else 'tools/bridge-seeded'))] 69 if not freestanding:cmd+=['--runtime-views'] 70 cmd+=['c',str(om)] 71 r=subprocess.run(cmd,env=env,text=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) 72 commands.append({'command':cmd,'rc':r.returncode,'output':r.stderr}) 73 if r.returncode:raise SystemExit('FAIL mutant generation '+r.stderr) 74 c=om.with_suffix('.c');c.write_text(r.stdout);obj=om.with_suffix('.o');run([cc,*flags,'-c',c,'-o',obj]) 75 exe=out/('mutant-'+str(num));link(exe,{name:obj});r=run([exe],expect=None) 76 if not r.returncode:raise SystemExit('FAIL surviving mutant '+name) 77 rows.append({'unit':name,'site':site,'replacement':replacement,'rc':r.returncode,'verdict':'KILLED'});print('KILLED '+name,flush=True) 78 (out/'mutants.json').write_text(json.dumps(rows,indent=2)+'\n');print('PASS source mutants killed='+str(len(rows)),flush=True) 79 print('API-REST-CHECK PASS',flush=True)