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/dispatch-check.c # 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 / dispatch-check.c` 87 lines · 6503 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* Host-only integration instrument: execute the actual adapter with fake device transport. */ 3 #include 4 #include 5 #include 6 #include 7 #include "../../src/omega_gpu_prefill_attn256_api.c" 8 #include "../standalone-oracles/oracle.h" 9 10 static int depth, n, fail, allocs, copies; 11 static unsigned events[16]; 12 static OmegaGpuDecodeAttn256CacheView cv; 13 static OmegaGpuSession fake_session; 14 static unsigned current_m; 15 static void event(unsigned x) { assert(so_all(so_eq(depth,1),so_call(34,n,16,0,0),1)); events[n] = x; n=(int)so_call(5,n,1,0,0); } 16 void __wrap_omega_gpu_session_lock(void) { assert(so_eq(depth,0)); depth=(int)so_call(5,depth,1,0,0); } 17 void __wrap_omega_gpu_session_unlock(void) { depth=(int)so_call(35,depth,1,0,0); assert(so_eq(depth,0)); } 18 OmegaGpuSession *__wrap_omega_gpu_session_open(void) { assert(so_eq(depth,1)); return &fake_session; } 19 int __wrap_omega_gpu_session_on_close(void (*f)(void)) { (void)f; return so_eq(fail,9) ? -1 : 0; } 20 int __wrap_omega_gpu_decode_attn256_cache_view(const OmegaGpuDecodeAttn256Cache *c, uint32_t layer, OmegaGpuDecodeAttn256CacheView *v) { 21 assert(so_all((uintptr_t)c,so_eq(layer,0),1)); *v = cv; return 0; 22 } 23 int __wrap_omega_gpu_session_sync_to_gpu(const OmegaGpuMem *m) { assert(so_all(so_eq(depth,1),(uintptr_t)m->cpu,1)); return 0; } 24 int __wrap_omega_gpu_session_sync_to_cpu(const OmegaGpuMem *m) { assert(so_all(so_eq(depth,1),(uintptr_t)m->cpu,1)); return 0; } 25 void __wrap_omega_gpu_session_free(OmegaGpuMem *m) { assert(so_eq(depth,1)); free(m->cpu); memset(m, 0, sizeof *m); } 26 int __wrap_omega_gpu_pf_alloc_dev_locked(size_t bytes, OmegaGpuMem *m) { 27 event(1); allocs=(int)so_call(5,allocs,1,0,0); 28 assert(so_eq(bytes,so_call(9,cv.k_va,cv.v_va,0,0))); 29 if (so_eq(fail,1)) return -1; 30 memset(m, 0, sizeof *m); m->va = 0x100123450ull; m->size = bytes; return 0; 31 } 32 int __wrap_omega_gpu_pf_copy_va_locked(uint64_t dst, uint64_t src, size_t bytes, uint64_t *ns) { 33 event(3); copies=(int)so_call(5,copies,1,0,0); 34 assert(so_call(33,n,1,0,0) && so_eq(events[n-2],2)); 35 assert(so_all(so_eq(dst,g.mirror.va),so_eq(src,cv.k_va),so_eq(bytes,so_call(9,cv.k_va,cv.v_va,0,0)))); 36 if (ns) *ns = 17; 37 return so_eq(fail,3) ? -1 : 0; 38 } 39 static uint64_t ptr(const uint32_t *a, unsigned i) { return so_call(8,a[i],a[i+1],0,0); } 40 int __wrap_omega_gpu_session_launch(const OmegaGpuLaunch *l, uint64_t *ns, uint32_t *marker) { 41 (void)marker; 42 unsigned action = (unsigned)so_call(41,so_eq(l->n_args,OMEGA_DATTN256_ARGS_WORDS),4,2,0); 43 event(action); 44 if (ns) *ns = action; 45 if (so_eq(action,2)) { assert(so_all(so_eq(ptr(l->args,2),cv.k_va),so_eq(ptr(l->args,4),cv.v_va),1)); } 46 else { 47 assert(so_eq(l->n_args,OMEGA_PATTN256_ARGS_WORDS)); 48 const int copied = so_call(33,n,1,0,0) && so_eq(events[n-2],3); 49 assert(so_eq(ptr(l->args,2),so_call(41,copied,cv.k_va,g.mirror.va,0))); 50 assert(so_eq(ptr(l->args,4),so_call(41,copied,cv.v_va,so_call(5,g.mirror.va,so_call(35,cv.v_va,cv.k_va,0,0),0,0),0))); 51 for (size_t i = 0; i < so_bytes(current_m,cv.out_words,0); i++) ((float *)g.out.cpu)[i] = 1.0f; 52 } 53 return so_eq(fail,action) ? -1 : 0; 54 } 55 static void run(unsigned mode, unsigned m, const unsigned *want, size_t count, int failure) { 56 float *q = calloc(so_bytes(m,cv.qkv_words,0),4), *out = calloc(so_bytes(m,cv.out_words,0),4); 57 assert(q && out); n = 0; fail = failure; current_m = m; uint64_t copy_ns = 99; 58 OmegaGpuPrefillAttn256Info info; 59 int rc = omega_gpu_prefill_attn256_scoped((void *)1,0,0,m,q,1e-6f,1.0f,out,&info,mode,©_ns); 60 assert(so_eq(depth,0)); assert(so_call(36,(uint64_t)(int64_t)rc,(uint64_t)(int64_t)failure,0,0)); assert(so_eq(n,count)); 61 for (size_t i = 0; i < count; i++) assert(so_eq(events[i],want[i])); 62 if (!rc) { assert(so_all(so_eq(so_bits(out[0]),so_bits(1.0f)),so_eq(so_bits(out[so_call(35,so_bytes(m,cv.out_words,0),1,0,0)]),so_bits(1.0f)),1)); assert(so_eq(copy_ns,so_call(10,mode,m,0,0))); } 63 free(q); free(out); 64 } 65 int main(void) { 66 cv.max_pos=8192;cv.q_heads=24;cv.kv_heads=4;cv.q_per_cta=2;cv.qkv_words=8192;cv.out_words=6144; 67 cv.k_va=0x200345670ull;cv.v_va=so_call(5,cv.k_va,so_call(5,so_bytes(cv.max_pos,4*OMEGA_DATTN256_ROW_BYTES,0),OMEGA_DATTN256_PLANE_SLACK,0,0),0,0); 68 uint32_t sh[3]={cv.q_heads,cv.kv_heads,cv.q_per_cta}; 69 for(unsigned k=0;k