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 / q38-head / plan-check.py
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | # External verification of checked portable Omega bindings. |
| 3 | import ctypes as C,struct,sys |
| 4 | L=C.CDLL(sys.argv[1]);F=L.omega_q38_runtime;F.restype=C.c_uint32 |
| 5 | F.argtypes=[C.POINTER(C.c_uint64),C.c_void_p,C.c_uint64,C.c_void_p,C.c_uint64,C.c_void_p,C.c_uint64] |
| 6 | m=(C.c_uint64*16)();b=C.create_string_buffer(struct.pack('<5120f',*([2.7109375]*5120)),20480);q=(C.c_uint64*192)();r=C.c_uint64() |
| 7 | def run(): |
| 8 | return F(C.byref(r),m,16,b,20480,q,192),r.value |
| 9 | m[0]=1;m[1]=248320 |
| 10 | assert run()==(0,1) |
| 11 | info=list(q);hn=struct.unpack('<f',struct.pack('<I',q[0]))[0] |
| 12 | assert hn==195.37811279296875 and q[2]==10384 |
| 13 | assert q[10]==2*1024**3 |
| 14 | m[0]=3 |
| 15 | assert run()==(0,1) and q[10]==2*1024**3 |
| 16 | q[0]=info[0] |
| 17 | p=((248320+2047)//2048)*2048 |
| 18 | assert info[3:10]==[0,20480,20480+248320*4,20480+248320*8,20480+248320*8+p*4,20480+248320*12+p*4,p] |
| 19 | m[0]=2;m[2]=q[0] |
| 20 | for j in range(3,9):m[j]=j*0x1000000 |
| 21 | assert run()==(0,6) |
| 22 | base=m[3];h=m[4];lo=m[5];av=m[6];ai=m[7];tab=m[8] |
| 23 | expected=[ |
| 24 | [1,20,5120,h,0,base,0,0,5120], |
| 25 | [2,0,0,tab,base,base+info[4],0,0,0], |
| 26 | [3,970,248320,base+info[4],base+info[5],base+info[6],base+info[7],info[0],248320], |
| 27 | [4,p//2048,p,base+info[6],0,av,ai,0,0], |
| 28 | [5,1,2048,av,ai,base+info[8],base+info[8]+4,0,0], |
| 29 | [6,0,0,h,base+info[7],lo,base+info[8],0,0]] |
| 30 | for i,row in enumerate(expected):assert list(q)[i*16:(i+1)*16]==row+[0]*7,(i,list(q)[i*16:(i+1)*16],row) |
| 31 | for index,wrong in [(1,0),(1,248321),(2,0),(2,0x7f800000),(2,0x80000000)]+[(j,v) for j in range(3,9) for v in [0,1,1<<48]]: |
| 32 | saved=m[index];m[index]=wrong;before=list(q);assert run()==(0,0);assert list(q)==before;m[index]=saved |
| 33 | E=L.omega_q38_emit;E.restype=C.c_uint32;E.argtypes=[C.POINTER(C.c_uint64),C.c_void_p,C.c_uint64] |
| 34 | code=(C.c_ubyte*16384)();assert E(C.byref(r),code,16384)==0 |
| 35 | frame=open(sys.argv[2],'rb').read() |
| 36 | head=struct.unpack_from('<6Q',frame) |
| 37 | offset=48+16*(head[1]+head[2])+64*head[0] |
| 38 | assert bytes(code[:r.value])==frame[offset:] |
| 39 | print('PASS: layout, six complete descriptors, admission refusals, unchanged output on refusal, emitted kernel byte identity') |