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/dagsim/resolve_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 / dagsim / resolve_check.py` 67 lines · 5369 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Source-derived C oracle differential; run inside the bwrap CPU envelope.""" 4 from pathlib import Path 5 import hashlib, os, subprocess, sys 6 root=Path(__file__).resolve().parents[2];os.chdir(root) 7 out=Path('build/dagsim-resolve');out.mkdir(parents=True,exist_ok=True) 8 def run(cmd,**kw): 9 print('+ '+' '.join(map(str,cmd)),flush=True) 10 return subprocess.run(list(map(str,cmd)),check=True,**kw) 11 cc=os.environ.get('CC','cc') 12 flags=['-std=gnu11','-O2','-ffp-contract=off','-D_GNU_SOURCE','-Isrc','-Itools/dagsim'] 13 exports=['ds_status_name','ds_prov_name','ds_day_from_date','ds_find_op','ds_find_res','ds_parse_text','ds_parse_file','ds_resolved_pack','ds_eval_c','ds_eval','ds_eval_interval','ds_counterfactual','ds_diff_models'] 14 for stale in out.glob('*.gcda'):stale.unlink() 15 run([cc,*flags,'-O0','--coverage','-DCUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE=1',*[f'-D{x}=oracle_{x}' for x in exports],'-c','tools/dagsim/dagsim.c','-o',out/'oracle.o']) 16 run([cc,*flags,'--coverage','-c','tools/dagsim/dagsim.c','-o',out/'resolve.o']) 17 sources=['tests/dagsim/resolve_diff.c',out/'oracle.o',out/'resolve.o','src/runtime/rx_costmodel.c','src/sha256.c','src/cudapp_om_dag_eval.c','src/cudapp_om_dag_parse.c','src/cudapp_om_dag_fmt.c','src/cudapp_om_dag_res.c','src/cudapp_om_dag_diff.c'] 18 sources.extend(['src/cudapp_om_core_sha.c',*sorted(Path('src').glob('cudapp_om_cm_*.c'))]) 19 def link(src,dest):run([cc,*flags,*src,'-Wl,--wrap=rx_cm_predict','-Wl,--wrap=malloc','-lm','-lgcov','-o',dest]) 20 link(sources,out/'diff');run([out/'diff']) 21 for name in ['oracle','resolve']: 22 cov=run(['gcov','-b','-c','-t','-o',out/(name+'.gcno'),'tools/dagsim/dagsim.c'],capture_output=True) 23 (out/(name+'.gcov')).write_bytes(cov.stdout);(out/(name+'-coverage.log')).write_bytes(cov.stderr) 24 missing=[cc,*flags,'tools/dagsim/dagsim_cli.c',out/'resolve.o',*sources[3:5],*sources[6:],'-lm','-lgcov','-o',out/'missing-scheduler'] 25 missing.insert(-3, 'src/cudapp_om_dag_jstr.c') 26 neg=subprocess.run([str(x) for x in missing],capture_output=True) 27 symbols=run(['nm',out/'resolve.o'],capture_output=True).stdout 28 (out/'scheduler-boundary.log').write_bytes(('COMMAND '+' '.join(str(x) for x in missing)+'\n').encode()+neg.stdout+neg.stderr+f'\nRC {neg.returncode}\nDEFAULT OBJECT SYMBOLS\n'.encode()+symbols) 29 assert neg.returncode!=0 and b'omega_dag_eval' in neg.stderr,'missing Omega scheduler must fail linkage' 30 assert b' T ds_eval_c' not in symbols and b' U omega_dag_eval' in symbols,'default scheduler must have no C fallback' 31 print('scheduler boundary: PASS (missing Omega scheduler link refused; no C fallback symbol)',flush=True) 32 red=subprocess.run([str(out/'diff')],env=dict(os.environ,DS_RESOLVE_RED='1'),capture_output=True) 33 (out/'red.log').write_bytes(red.stdout+red.stderr) 34 if red.returncode!=1:raise SystemExit(f'resolve red control did not return 1: {red.returncode}') 35 print('resolve red control: caught (rc=1)',flush=True) 36 omc=os.environ.get('OMEGA_OMC',str(Path.home()/'work/cudastack/omega-mv/seed/out/omc')) 37 bridge=Path(os.environ.get('OMEGA_BRIDGE',str(Path.home()/'work/cudastack/omega-bridge'))) 38 if hashlib.sha256(Path(omc).read_bytes()).hexdigest()!='`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`':raise SystemExit('pinned seeded compiler mismatch') 39 res=Path('om/tools/dag_res.om').read_text();diff=Path('om/tools/dag_diff.om').read_text() 40 mutants=[ 41 ('unknown-resource','res','if eq prov 0','if false'), 42 ('stale-boundary','res','if gt dr_i get a 6 expiry','if ge dr_i get a 6 expiry'), 43 ('pessimistic-time','res','v = dr_f m add p 4','v = dr_f m add p 3'), 44 ('prediction-n','res','ret eq get a 27 0','ret false'), 45 ('bandwidth-double','res','bitcast ulong mul dr_f m add add p 2 k 2.0','bitcast ulong mul dr_f m add add p 2 k 3.0'), 46 ('eliminated-proof','diff','ret or not used ne get t add key 80 0','ret true'), 47 ('deferred-consumer','diff','ret not used','ret true'), 48 ('removed-weight','diff','w = add timev launchv','w = timev'), 49 ('changed-membership','res','put m add 7600 i 1','put m add 7600 i 0')] 50 if '--no-mutants' not in sys.argv: 51 for name,unit,old,new in mutants: 52 text=res if unit=='res' else diff 53 if text.count(old)!=1:raise SystemExit(f'mutant {name}: expected unique site, got {text.count(old)}') 54 mr=res.replace(old,new) if unit=='res' else res 55 md=diff.replace(old,new) if unit=='diff' else diff 56 dest=out/('mutant-'+name);dest.mkdir(exist_ok=True) 57 replacements={} 58 for un,source in [('dag_res',mr),('dag_diff',mr+'\n'+md)]: 59 p=dest/(un+'.om');p.write_text(source) 60 emitted=run(['sh',bridge/'tools/bridge-seeded','c',p],env=dict(os.environ,OMEGA_SEEDED_OMC=omc),capture_output=True) 61 c=dest/(un+'.c');c.write_bytes(emitted.stdout);replacements['src/cudapp_om_'+un+'.c']=c 62 link([replacements.get(str(s),s) for s in sources],dest/'diff') 63 r=subprocess.run([str(dest/'diff')],capture_output=True);(dest/'out.log').write_bytes(r.stdout+r.stderr) 64 if r.returncode!=1:raise SystemExit(f'mutant {name}: not killed by assertions (rc={r.returncode})') 65 print(f'resolve mutant {name}: killed (rc=1); {dest}/out.log',flush=True) 66 print(f'resolve mutants: {len(mutants)} killed',flush=True) 67 print('dagsim resolve Omega differential: PASS',flush=True)