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/tests/amd-exec/gdnstate_w.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 / tests / amd-exec / gdnstate_w.py` 204 lines · 12114 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Private-output executor acceptance and independent NumPy scalar-order oracle.""" 4 import argparse 5 import hashlib 6 import json 7 from pathlib import Path 8 import runpy 9 import shutil 10 import struct 11 import subprocess 12 import numpy as np 13 14 PIN='`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`' 15 NAME='gdnstate_w' 16 SIZES=(16384,24576,`3145728`,`3145728`,24576,192,192) 17 NAMES=('qk','value','oldstate','newstate','output','decay','beta') 18 CASES=('random-1','random-2','random-3','zero','cancel','subnormal','impulse','exceptional') 19 20 21 def sha(p): 22 with Path(p).open('rb') as f: return hashlib.file_digest(f,'sha256').hexdigest() 23 24 25 def bf16(x): 26 bits=np.asarray(x,dtype=np.float32).view(np.uint32) 27 result=(bits+0x7fff+((bits>>16)&1))&np.uint32(0xffff0000) 28 return np.where((bits&0x7fffffff)>0x7f800000,np.uint32(0x7fc00000),result).astype(np.uint32).view(np.float32) 29 30 31 def fixture(kind): 32 seed=int(kind.split('-')[1]) if kind.startswith('random-') else 7 33 rng=np.random.default_rng(seed) 34 qk=bf16(rng.uniform(-0.125,0.125,(2,16,128)).astype(np.float32)) 35 value=bf16(rng.uniform(-0.25,0.25,(48,128)).astype(np.float32)) 36 old=rng.uniform(-0.25,0.25,(48,128,128)).astype(np.float32) 37 decay=rng.uniform(0.125,0.875,48).astype(np.float32) 38 beta=bf16(rng.uniform(0.125,0.875,48).astype(np.float32)) 39 if kind=='zero': old.fill(0); value.fill(0); qk.fill(0) 40 elif kind=='cancel': 41 old[:]=np.where(np.arange(128)[:,None]%2,0.5,-0.5).astype(np.float32) 42 qk.fill(0.125); value.fill(0); decay.fill(1); beta.fill(1) 43 elif kind=='subnormal': 44 words=np.array([0,0x80000000,1,0x80000001,0x007fffff,0x807fffff,0x00800000,0x80800000],dtype=np.uint32) 45 old[:]=np.resize(words,old.size).reshape(old.shape).view(np.float32) 46 value[:]=np.resize(words,value.size).reshape(value.shape).view(np.float32) 47 qk.fill(0.125); decay.fill(0.5); beta.fill(0.5) 48 elif kind=='impulse': 49 old.fill(0); value.fill(0); qk.fill(0) 50 for head in range(48): 51 old[head,head%128,(head*17)%128]=np.float32((head+1)/64) 52 value[head,(head*7)%128]=np.float32((head+1)/128) 53 for head in range(16): qk[0,head,head*7]=0.5; qk[1,head,head*5]=0.25 54 elif kind=='exceptional': 55 words=np.array([0x7f800000,0xff800000,0x7fc00000,0x7fa12345,0xffa12345,0x7f7fffff,0xff7fffff,0x80000000],dtype=np.uint32) 56 for head in range(48): old[head,head%128,:8]=words.view(np.float32) 57 value[:8,0]=words.view(np.float32); decay[0]=0; beta[1]=0 58 buffers=(qk.tobytes(),value.tobytes(),old.tobytes(),b'\xa5'*SIZES[3],b'\xa5'*SIZES[4],decay.tobytes(),beta.tobytes()) 59 spans=[('kernarg',0,56)]; pointers=[]; cursor=128 60 for name,blob in zip(NAMES,buffers): 61 spans.append((name,cursor,len(blob))); pointers.append(cursor); cursor+=len(blob)+128 62 image=bytearray(b'\xa5')*cursor 63 struct.pack_into('<7Q',image,0,*pointers) 64 for p,b in zip(pointers,buffers): image[p:p+len(b)]=b 65 return image,spans 66 67 68 def oracle(image,spans): 69 ptr={name:p for name,p,n in spans} 70 def arr(name,shape): return np.frombuffer(image,dtype='