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/gpu_attn_any_test.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 / tests / gpu_attn_any_test.c` 174 lines · 9275 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include "omega_gpu_attn_any_api.h" 3 #include "omega_gpu_session.h" 4 #include "cudapp_native.h" 5 #include "bw_warp_sim_k.h" 6 #include "gpu_attn_any_ref.h" 7 #include 8 static int failures; 9 #define CHECK(x) do { if (!(x)) { fprintf(stderr,"attn-any failure line %d: %s\n",__LINE__,#x); ++failures; } } while (0) 10 static int chip_mode, shell_mode, open_success; 11 static unsigned open_calls, alloc_calls, lock_calls, unlock_calls, free_calls; 12 static max_align_t fake_session; 13 OmegaGpuSession *__real_omega_gpu_session_open(void); 14 void __real_omega_gpu_session_lock(void); 15 void __real_omega_gpu_session_unlock(void); 16 void __real_omega_gpu_session_free(OmegaGpuMem *); 17 int __real_omega_gpu_session_alloc(size_t, OmegaGpuMem *); 18 static _Noreturn void forbidden(const char *name) { 19 fprintf(stderr,"attn-any host guard: forbidden %s\n",name); 20 abort(); 21 } 22 OmegaGpuSession *__wrap_omega_gpu_session_open(void) { 23 if (chip_mode) return __real_omega_gpu_session_open(); 24 if (!shell_mode) forbidden("session_open"); 25 ++open_calls; 26 return open_success ? (OmegaGpuSession *)&fake_session : NULL; 27 } 28 void __wrap_omega_gpu_session_lock(void) { 29 if (chip_mode) { __real_omega_gpu_session_lock(); return; } 30 if (!shell_mode) forbidden("session_lock"); 31 ++lock_calls; 32 } 33 void __wrap_omega_gpu_session_unlock(void) { 34 if (chip_mode) { __real_omega_gpu_session_unlock(); return; } 35 if (!shell_mode) forbidden("session_unlock"); 36 ++unlock_calls; 37 } 38 void __wrap_omega_gpu_session_free(OmegaGpuMem *mem) { 39 if (chip_mode) { __real_omega_gpu_session_free(mem); return; } 40 if (!shell_mode) forbidden("session_free"); 41 ++free_calls; 42 } 43 int __wrap_omega_gpu_session_alloc(size_t bytes, OmegaGpuMem *mem) { 44 if (chip_mode) return __real_omega_gpu_session_alloc(bytes,mem); 45 if (!shell_mode) forbidden("session_alloc"); 46 (void)bytes; (void)mem; ++alloc_calls; 47 return -1; 48 } 49 static void put64(uint32_t *p, uintptr_t x) { p[0]=(uint32_t)x; p[1]=(uint32_t)((uint64_t)x>>32); } 50 static void *input(size_t n, unsigned dtype, unsigned salt) { 51 void *p=malloc(n*(dtype ? 2u:4u)); if (!p) abort(); 52 for (size_t i=0;i>16); } 57 else ((float*)p)[i]=f; 58 } 59 return p; 60 } 61 static int run_shape(OmegaGpuAttnAnyShape s, int chip, int wrong_mask) { 62 size_t nq=(size_t)s.seq_q*s.q_heads*s.head_dim, nk=(size_t)s.seq_kv*s.kv_heads*s.head_dim; 63 void *q=input(nq,s.dtype,1), *k=input(nk,s.dtype,3), *v=input(nk,s.dtype,7); 64 float *o=malloc(nq*sizeof *o); double *ref=malloc(nq*sizeof *ref); 65 BlackwellIRProgram *p=malloc(sizeof *p); uint8_t *code=malloc(OMEGA_BW_CODE_CAP_MAX); 66 if (!o || !ref || !p || !code) abort(); 67 memset(o,0xa5,nq*sizeof *o); 68 OmegaBlackwellKernel kernel; 69 int rc=omega_gpu_attn_any_codegen(&s,p,code,OMEGA_BW_CODE_CAP_MAX,&kernel); 70 if (rc) fprintf(stderr,"attn-any codegen rc=%d dim=%u type=%u\n",rc,s.head_dim,s.dtype); 71 CHECK(rc==OMEGA_GPU_ATTN_ANY_OK); 72 if (!rc && chip) rc=omega_gpu_attn_any(&s,q,k,v,o); 73 if (!rc && !chip) { 74 for (uint32_t h=0;h