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 / prefill-shape / check.py

36 lines · 1768 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2# External admission oracle, not a production dependency.
3import ctypes,sys
4lib=ctypes.CDLL(sys.argv[1]);f=lib.omega_native_qgshape
5f.argtypes=[ctypes.POINTER(ctypes.c_uint64)]+[ctypes.c_uint64]*4;f.restype=ctypes.c_uint32
6cases=[(4,8,1),(2,4,1),(0,0,0),(1,2,0),(2,8,0),(4,4,0),(4,16,1),(8,16,0),(8,8,1),(8,4,0),(8,32,0),(2,0,0),(0,4,0),(2,2,0),(16,32,0),(2**32-1,4,0),(2,2**32-1,0),(2**64-1,4,0),(4,2**64-1,0)]
7cases += [(rt,warps,int((rt,warps) in {(4,8),(4,16),(2,4),(8,8)})) for rt in range(17) for warps in range(33)]
8for rt,warps,want in cases:
9 out=ctypes.c_uint64(999)
10 assert f(ctypes.byref(out),rt,warps,128,0)==0
11 assert out.value==want,(rt,warps,out.value,want)
12assert f(None,2,4,128,0)==32
13print('PASS shape admission and unsafe-shape refusal controls')
14
15# Independent exact-integer enumeration of every emitted store immediate.
16count=0
17for rt in [0,2,4,8,9,2**64-1]:
18 warps=4 if rt==2 else 8
19 for epi in [0,1,2,2**64-1]:
20 widths={0,1,128,5120,6144,16384,17408,34816,2**32-1,2**32,2**64-1}
21 if 1<=rt<=8 and epi in (0,1):
22 top=((1<<23)-1-(36 if epi==0 else 0))//((16*rt-8)*(4 if epi==0 else 1))
23 widths.update([top-1,top,top+1])
24 for n in sorted(widths):
25 valid=1<=n<2**32 and rt in (2,4,8) and epi in (0,1)
26 if valid:
27 stride=n*(4 if epi==0 else 1)
28 emitted=[(16*i+8*h)*stride+(32*j+4*q if epi==0 else 0) for i in range(rt) for h in range(2) for j in range(2) for q in range(2)]
29 want=int(all(0<=x<(1<<23) for x in emitted))
30 else:want=0
31 out=ctypes.c_uint64(999)
32 assert f(ctypes.byref(out),rt,warps,n,epi)==0
33 assert out.value==want,(n,rt,epi,out.value,want)
34 count+=1
35assert f(None,8,8,16384,0)==32
36print('PASS exact emitted-offset boundary oracle',count,'cases')