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 / tests / dagsim / parse_partition.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Source-derived lexical/record/capacity partition for dagsim.c's migration oracle. |
| 3 | No numeric oracle is implemented here: parse_diff compares C to generated Omega. |
| 4 | """ |
| 5 | from pathlib import Path |
| 6 | import sys |
| 7 | out = Path(sys.argv[1]); out.mkdir(parents=True, exist_ok=True) |
| 8 | for stale in out.glob('*.oev'): stale.unlink() |
| 9 | cases = [] |
| 10 | header = 'oev version=1\nmachine id=m soc=s cores=8 mem_bytes=1024 prov=specified\nbuild repo=r sha=' + 'a'*40 + ' physics=p\n' |
| 11 | energy = 'energy instrument=none\n' |
| 12 | res = ('resource id=c kind=compute slots=2 prov=specified\n' |
| 13 | 'resource id=b kind=bandwidth cap=10 lo=8 hi=12 prov=specified\n' |
| 14 | 'resource id=v kind=capacity cap=100 prov=specified\n' |
| 15 | 'resource id=l kind=launch prov=specified\n') |
| 16 | ops = ('op id=a kind=compute engine=c t_ns=2 lo=1 hi=3 prov=specified\n' |
| 17 | 'op id=z kind=copy engine=c bytes=8 bw=b launch_ns=1 launcher=l prov=specified\n') |
| 18 | base = header + res + ops |
| 19 | records = [ |
| 20 | 'oev version=1', 'machine id=m soc=s cores=8 mem_bytes=1024 prov=specified src=x', |
| 21 | 'build repo=r sha='+'a'*40+' physics=p', |
| 22 | 'calibration id=q taken=2026-11-06 valid_days=30 load1=0.5 src=x model=x', |
| 23 | 'resource id=extra kind=compute slots=1 prov=measured src=x', |
| 24 | 'op id=extra kind=compute engine=c t_ns=2 lo=1 hi=3 bytes=8 bw=b launch_ns=1 launcher=l M=1 N=1 core=0 arm=0 prov=measured src=x', |
| 25 | 'dep a z', 'buffer id=extra bytes=10 cap=v first=a last=z', |
| 26 | 'sync id=extra ops=a,z', 'energy instrument=m boundary=box joules=2 prov=measured src=x', |
| 27 | 'removed op=gone reason=reused ref=a proof=receipt', |
| 28 | 'energy instrument=m boundary=box power_w=2 prov=synthetic src=x', |
| 29 | 'resource id=extra kind=bandwidth cap=10 lo=8 hi=12 prov=measured src=x', |
| 30 | 'resource id=extra kind=capacity cap=100 prov=measured src=x'] |
| 31 | def add(label, text): cases.append((label, text)) |
| 32 | add('empty',''); add('valid',base+energy) |
| 33 | for ri, rec in enumerate(records): |
| 34 | prefix = base if ri not in (0,1,2) else '' |
| 35 | suffix = energy if not rec.startswith('energy ') else '' |
| 36 | # singleton records also exercise missing mandatory records at EOF. |
| 37 | add(f'record-{ri}', prefix+rec+'\n'+suffix) |
| 38 | tokens = rec.split() |
| 39 | for ti,t in enumerate(tokens[1:],1): |
| 40 | if '=' not in t: continue |
| 41 | key,_ = t.split('=',1) |
| 42 | for kind, replacement in [('absent',None),('empty',key+'='),('bad',key+'=bogus')]: |
| 43 | ts=tokens.copy() |
| 44 | if replacement is None: del ts[ti] |
| 45 | else: ts[ti]=replacement |
| 46 | add(f'field-{ri}-{key}-{kind}',prefix+' '.join(ts)+'\n'+suffix) |
| 47 | add(f'unknown-key-{ri}',prefix+rec+' extra=1\n'+suffix) |
| 48 | add(f'duplicate-key-{ri}',prefix+rec+' '+tokens[1]+'\n'+suffix) |
| 49 | for kind in ['compute','copy','matvec','barrier','storage','persist','bogus']: |
| 50 | add('op-kind-'+kind,base+f'op id=k kind={kind} engine=c t_ns=1 prov=specified\n'+energy) |
| 51 | add('op-kind-no-time-'+kind,base+f'op id=k kind={kind} engine=c M=2 N=3\n'+energy) |
| 52 | for prov in ['unknown','synthetic','fitted','measured','specified','bogus']: |
| 53 | for src in ['', ' src=x']: |
| 54 | add('prov-'+prov+str(bool(src)),header+f'resource id=c kind=compute slots=1 prov={prov}'+src+'\n'+energy) |
| 55 | for reason in ['eliminated','reused','unchanged_dep','deferred','moved','shared','lookup','bogus']: |
| 56 | add('removed-'+reason,base+f'removed op=gone reason={reason} ref=a proof=x\n'+energy) |
| 57 | for val in ['0','-0','+0','0.0','1','1.25','.5','1.','1e3','1E-3','+2','-2','inf','INF','Infinity','-inf','nan','NaN(x)','1e309','1e-500','-1e-500','1e','1x','0x1p0','0x1.8p+2','0x1p-1074','0x1p1024','2.2250738585072014e-308','4.9406564584124654e-324','1.00000000000000011102230246251565404236316680908203125','9007199254740993','1_0','0x','.', '+']: |
| 58 | add('number-'+str(len(cases)),header+f'resource id=b kind=bandwidth cap={val} prov=specified\n'+energy) |
| 59 | add('buffer-number-'+str(len(cases)),base+f'buffer id=q bytes={val} cap=v\n'+energy) |
| 60 | for val in ['0','1','-1','+2','2147483647','2147483648','4294967295','4294967296','18446744073709551615','18446744073709551616','99999999999999999999999999999999999999999','2x','x','--1']: |
| 61 | add('integer-'+str(len(cases)),header+f'resource id=c kind=compute slots={val} prov=specified\n'+energy) |
| 62 | add('uint-'+str(len(cases)),base+f'op id=q kind=matvec engine=c M={val} N=2\n'+energy) |
| 63 | for date in ['1970-01-01','1969-12-31','2026-11-06','2000-02-29','1900-03-01','2026-0-0','2026-13-32','2026-11-06junk','2026-11','+2026-+11-+6','-1-1-1','2026--1-1','2026-11-x']: |
| 64 | add('date-'+str(len(cases)),header+'calibration id=q taken='+date+' valid_days=1 load1=0 src=x\n'+energy) |
| 65 | for date in ['0-1-1','9223372036854775808-1-1','-9223372036854775809-1-1','2026-9223372036854775808-1','2026-1-9223372036854775808']: |
| 66 | add('date-overflow-'+str(len(cases)),header+'calibration id=q taken='+date+' valid_days=1 load1=0 src=x\n'+energy) |
| 67 | for sep in [' ', '\t', '\r', '\v', '\f', '\n']: |
| 68 | add('whitespace-'+str(len(cases)),header+('resource id=q kind=compute slots=1 prov=specified'.replace(' ',sep))+'\n'+energy) |
| 69 | for tail in ['# ignored', ' # id=bad', '\x00garbage', '\n\n', '\r\n', ' unknown', '=bad', ' x=y=z']: |
| 70 | add('lexical-'+str(len(cases)),base+energy.rstrip('\n')+tail+'\n') |
| 71 | for count in [7,8,9]: add('positions-'+str(count),base+'dep '+' '.join(['a','z']+['unused']*(count-2))+'\n'+energy) |
| 72 | for count in [23,24,25]: add('fields-'+str(count),header+'resource '+' '.join(['id=q','kind=compute','slots=1','prov=specified']+['slots=1']*(count-4))+'\n'+energy) |
| 73 | for length in [30,31,32]: add('keyword-'+str(length),header+'x'*length+'\n'+energy) |
| 74 | for length in [30,31,32]: add('key-'+str(length),header+'machine id=m prov=specified '+'x'*length+'=1\n'+energy) |
| 75 | for length in [38,39,40,41,46,47,48,126,127,128]: |
| 76 | add('value-'+str(length),header+'machine id='+'x'*length+' src='+'y'*length+' prov=specified\n'+energy) |
| 77 | for length in [1022,1023,1024,1025]: add('line-'+str(length),header+'#'+'x'*(length-1)+'\n'+energy) |
| 78 | for count in [31,32,33]: add('resources-'+str(count),header+''.join(f'resource id=r{i} kind=compute slots=1 prov=specified\n' for i in range(count))+energy) |
| 79 | for count in [255,256,257]: |
| 80 | add('ops-'+str(count),header+''.join(f'op id=o{i} kind=barrier\n' for i in range(count))+energy) |
| 81 | add('buffers-'+str(count),base+''.join(f'buffer id=b{i} bytes=0 cap=v\n' for i in range(count))+energy) |
| 82 | add('removed-'+str(count),base+''.join(f'removed op=r{i} reason=lookup\n' for i in range(count))+energy) |
| 83 | for count in [1023,1024,1025]: add('deps-'+str(count),base+'dep a z\n'*count+energy) |
| 84 | for text in ['sync id=q ops=a,,z,','sync id=a ops=a','sync id=q ops=q','dep z a','dep x y','resource id=c kind=compute slots=1 prov=specified','op id=a kind=barrier','energy instrument=none\nenergy instrument=none','removed op=a reason=lookup','calibration id=q taken=2026-11-06 valid_days=1 load1=0 src=x\ncalibration id=r']: |
| 85 | add('refusal-'+str(len(cases)),base+text+'\n'+energy) |
| 86 | for length in [46,47,48,49,126,127,128,129]: |
| 87 | add('physics-src-'+str(length),header+'build sha='+'a'*40+' physics='+'p'*length+'\nmachine id=m prov=measured src='+'s'*length+'\n'+energy) |
| 88 | add('stored-src-'+str(length),header+'resource id=c kind=compute slots=1 prov=measured src='+'s'*length+'\n'+energy) |
| 89 | for space in ['\v','\f']: |
| 90 | add('numeric-space-'+str(len(cases)),header+'machine id=m cores='+space+'1 mem_bytes='+space+'1.25 prov=specified\n'+energy) |
| 91 | add('date-space-'+str(len(cases)),header+'calibration id=q taken='+space+'2026-11-06 valid_days='+space+'2 load1='+space+'0.5 src=x\n'+energy) |
| 92 | for n in [1048575,1048576,1048577]: |
| 93 | text=header+energy |
| 94 | while len(text)+1024<=n: text+='#'+'x'*1022+'\n' |
| 95 | if len(text)<n: text+='#'+'x'*(n-len(text)-1) |
| 96 | add('input-'+str(n),text) |
| 97 | for i,(label,text) in enumerate(cases): (out/f'{i:04d}-{label}.oev').write_bytes(text.encode()) |
| 98 | print(f'parser partition: {len(cases)} cases written to {out}') |