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/om/attention-mirror/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 / om / attention-mirror / check.py` 44 lines · 2292 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 # Independent external oracle. Not a production dependency. 3 import ctypes,itertools,random,sys 4 lib=ctypes.CDLL(sys.argv[1]);U=ctypes.c_uint64;bad=2**64-1 5 plan=lib.omega_native_attnmirplan;plan.restype=ctypes.c_uint32;plan.argtypes=[ctypes.POINTER(U),ctypes.POINTER(U),U] 6 step=lib.omega_native_attnmirnext;step.restype=ctypes.c_uint32;step.argtypes=[ctypes.POINTER(U)]+[U]*4 7 8 def expected(a): 9 mode,qh,kh,limit,pos,rows,plane=a 10 if not (mode in (0,1,2) and qh==24 and kh==4 and 0=1024) else 0 12 13 cases=[] 14 for limit in (1,30,1023,1024,4096,40960,131072): 15 for rows in (1,30,1023,1024,1025,4096,32768): 16 for pos in (0,max(0,limit-rows),limit): 17 for mode in (0,1,2,3):cases.append((mode,24,4,limit,pos,rows,limit*2048+8256)) 18 base=(2,24,4,40960,0,4096,40960*2048+8256) 19 for i in range(7): 20 for v in (0,1,3,23,25,1023,1024,32768,32769,131072,131073,2**32,2**64-1): 21 a=list(base);a[i]=v;cases.append(tuple(a)) 22 rng=random.Random(710) 23 for _ in range(1000): 24 limit=rng.randrange(1,131073);rows=rng.randrange(1,min(limit,32768)+1);pos=rng.randrange(limit-rows+1) 25 cases.append((rng.randrange(3),24,4,limit,pos,rows,limit*2048+8256)) 26 for a in cases: 27 out=U(99);assert plan(ctypes.byref(out),(U*7)(*a),7)==0;assert out.value==expected(a),('plan',a,out.value,expected(a)) 28 assert plan(None,(U*7)(*base),7)==32 29 assert plan(ctypes.byref(U()),None,7)==32 30 assert plan(ctypes.byref(U()),(U*7)(*base),6)==32 31 32 def next_expected(phase,need,have,ok): 33 if ok!=1 or (need and (need<20608 or need>`536887424` or need%16)):return 0 34 if phase==0:return 1 if need>have else 2 35 if phase==1:return 2 if have>=need else 0 36 if phase==2:return 3 if need else 4 37 if phase==3:return 4 if need else 0 38 if phase==4:return 5 39 return 0 40 n=0 41 for a in itertools.product(range(7),(0,16,20608,20609,`33570944`,`536887424`,`536887440`,2**64-1),(0,16,20608,`33570944`,`536887424`,2**64-1),(0,1,2)): 42 out=U(99);assert step(ctypes.byref(out),*a)==0;assert out.value==next_expected(*a),('step',a,out.value,next_expected(*a));n+=1 43 assert step(None,0,20608,0,1)==32 44 print('PASS independent attention mirror oracle',len(cases),'plans',n,'transitions')