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 / standalone-oracles / family-check.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | """Verification only. All CUDA/session transports are CPU stubs or WsSim. |
| 3 | Run inside the documented device-empty bwrap, never against a real driver. |
| 4 | --base optionally compares the original source at that exact Git revision; |
| 5 | otherwise the explicit default-OFF C migration oracle supplies the baseline. |
| 6 | """ |
| 7 | import argparse, os, resource, struct, subprocess, tempfile |
| 8 | from pathlib import Path |
| 9 | |
| 10 | root=Path(__file__).resolve().parents[2] |
| 11 | lane=root/'om/standalone-oracles' |
| 12 | p=argparse.ArgumentParser() |
| 13 | p.add_argument('library',type=Path) |
| 14 | p.add_argument('--frame',type=Path,required=True) |
| 15 | p.add_argument('--base') |
| 16 | args=p.parse_args() |
| 17 | assert not list(Path('/dev').glob('nvidia*')), 'run inside the documented device-empty bwrap' |
| 18 | resource.setrlimit(resource.RLIMIT_CORE,(0,0)) |
| 19 | cc=os.environ.get('CC','cc') |
| 20 | flags=['-O2','-std=gnu11','-Wall','-Wextra','-Werror','-Wno-unused-function','-ffp-contract=off','-I'+str(root/'src'),'-I'+str(root/'tests'),'-I'+os.environ.get('CUDA_INC','/usr/local/cuda/include')] |
| 21 | lib=str(args.library.resolve()) |
| 22 | frame=str(args.frame.resolve()) |
| 23 | attn=['omega_gpu_session_lock','omega_gpu_session_unlock','omega_gpu_session_open','omega_gpu_session_on_close','omega_gpu_decode_attn256_cache_view','omega_gpu_session_sync_to_gpu','omega_gpu_session_sync_to_cpu','omega_gpu_session_free','omega_gpu_pf_alloc_dev_locked','omega_gpu_pf_copy_va_locked','omega_gpu_session_launch'] |
| 24 | norm=['omega_blackwell_codegen_dec_prog','omega_gpu_session_lock','omega_gpu_session_unlock','omega_gpu_session_open','omega_gpu_session_alloc_code','omega_gpu_session_alloc','omega_gpu_session_sync_to_gpu','omega_gpu_session_sync_to_cpu','omega_gpu_session_free','omega_gpu_session_launch'] |
| 25 | checks=[ |
| 26 | ('vadd','compat/cuda/fixture/vadd_drv.c',[],['host-cuda.c'],None), |
| 27 | ('probe','tools/interop/cubin_probe.c',[],['host-cuda.c'],None), |
| 28 | ('dispatch','om/attention-mirror/dispatch-check.c',attn,[],3), |
| 29 | ('cache','om/prefill-shape/cache-check.c',['omega_gpu_session_alloc_code'],[],14), |
| 30 | ('scoped','om/prefill-shape/scoped-check.c',['omega_gpu_pf_open_locked','omega_gpu_pf_kernel_locked'],[],3), |
| 31 | ('budget','om/q38-head/budget-check.c',[],[],3), |
| 32 | ('bounds','om/q38-head/check.c',[],[],4), |
| 33 | ('norm','om/q38-head/norm-check.c',norm,['host-norm.c'],None), |
| 34 | ] |
| 35 | |
| 36 | def invoke(cmd,env=None): |
| 37 | return subprocess.run(cmd,env=env,text=True,capture_output=True) |
| 38 | |
| 39 | with tempfile.TemporaryDirectory(prefix='standalone-family-') as directory: |
| 40 | tmp=Path(directory) |
| 41 | (tmp/'src').symlink_to(root/'src',target_is_directory=True) |
| 42 | (tmp/'weights.f32').write_bytes(struct.pack('=f',1.0)*5120) |
| 43 | (tmp/'module.txt').write_text('Host-only CPU transport input, never executable GPU code.\n') |
| 44 | missing=invoke([cc,*flags,str(lane/'scalar-check.c'),str(lane/'oracle-c.c'),'-o',str(tmp/'missing-unit')]) |
| 45 | assert missing.returncode!=0 and 'omega_so_oracles' in missing.stderr,('strong-link negative control',missing.stderr) |
| 46 | print('PASS missing Omega unit: link refused with undefined omega_so_oracles',flush=True) |
| 47 | baseline='original@'+args.base if args.base else 'C-snapshot' |
| 48 | print('BASELINE '+baseline,flush=True) |
| 49 | for name,path,wraps,extras,redop in checks: |
| 50 | original=tmp/path |
| 51 | original.parent.mkdir(parents=True,exist_ok=True) |
| 52 | if args.base: |
| 53 | old=subprocess.run(['git','show',args.base+':'+path],cwd=root,capture_output=True,check=True) |
| 54 | original.write_bytes(old.stdout) |
| 55 | else: |
| 56 | original=root/path |
| 57 | runargs={'vadd':[str(root/'compat/cuda/fixture/vadd_u32.ptx')], |
| 58 | 'probe':[str(tmp/'module.txt'),'host_gemm','17','7','19'], |
| 59 | 'norm':['--chip',str(tmp/'weights.f32'),'100'], |
| 60 | 'bounds':[frame]}.get(name,[]) |
| 61 | env=dict(os.environ,SPARK_WINDOW='HOST-STUB-NOT-A-GPU-WINDOW',SO_HOST_M='17',SO_HOST_K='7',SO_HOST_N='19') |
| 62 | env.pop('SO_HOST_RED',None) |
| 63 | env.pop('SO_RED_OP',None) |
| 64 | outputs=[] |
| 65 | for variant in ('before','after','c-oracle'): |
| 66 | exe=tmp/(name+'-'+variant) |
| 67 | source=original if variant=='before' else root/path |
| 68 | defines=[] if args.base and variant=='before' else (['-DCUDAPP_MIGRATION_PENDING_C_STANDALONE_ORACLES=1'] if variant!='after' else []) |
| 69 | wrapopts=['-Wl,--wrap='+f for f in wraps] |
| 70 | sources=[str(source)]+[str(lane/e) for e in extras] |
| 71 | if variant=='after': |
| 72 | sources+=[str(lane/'red.c')] |
| 73 | wrapopts+=['-Wl,--wrap=omega_so_oracles'] |
| 74 | command=[cc,*flags,*defines,*sources,lib,*wrapopts,'-lpthread','-lm','-o',str(exe)] |
| 75 | subprocess.run(command,check=True) |
| 76 | result=invoke([str(exe),*runargs],env) |
| 77 | assert result.returncode==0,(name,variant,result.returncode,result.stdout,result.stderr) |
| 78 | outputs.append((result.stdout,result.stderr)) |
| 79 | print(name+' '+variant+' rc=0\n'+result.stdout+result.stderr,flush=True) |
| 80 | if variant=='after': |
| 81 | poisoned=dict(env,**({'SO_HOST_RED':'1'} if redop is None else {'SO_RED_OP':str(redop)})) |
| 82 | red=invoke([str(exe),*runargs],poisoned) |
| 83 | assert red.returncode!=0,(name,'red control escaped',red.stdout,red.stderr) |
| 84 | print(name+' RED rc='+str(red.returncode)+' (corrupted '+('transport result' if redop is None else 'Omega verdict op '+str(redop))+')',flush=True) |
| 85 | assert outputs[0]==outputs[1]==outputs[2],(name,'before/after/C-oracle output drift',outputs) |
| 86 | print('PASS '+name+' '+baseline+'/default/C-oracle outputs byte-identical; red rejected',flush=True) |
| 87 | print('PASS standalone family: eight host checks, identical before/after verdicts, eight red controls',flush=True) |