interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / om / q38-head / plan-check.py

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