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_dnn_activations_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_dnn_activations_test.c` 138 lines · 7237 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include "omega_gpu_dnn_activations_api.h" 3 #include "omega_gpu_session.h" 4 #include "cudapp_native.h" 5 #include "bw_warp_sim_k.h" 6 #include "gpu_dnn_activations_ref.h" 7 #include 8 #include 9 static int failures,opens,locks,unlocks,frees,allocs,open_success,chip_mode,shell_mode; 10 static OmegaGpuSession fake_session; 11 OmegaGpuSession *__real_omega_gpu_session_open(void); 12 void __real_omega_gpu_session_lock(void); 13 void __real_omega_gpu_session_unlock(void); 14 void __real_omega_gpu_session_free(OmegaGpuMem *); 15 int __real_omega_gpu_session_alloc(size_t,OmegaGpuMem *); 16 OmegaGpuSession *__wrap_omega_gpu_session_open(void) { 17 if(chip_mode) return __real_omega_gpu_session_open(); 18 if(!shell_mode) {fputs("DNN-HOST-GUARD session_open\n",stderr);abort();} 19 ++opens;return open_success ? &fake_session : NULL; 20 } 21 void __wrap_omega_gpu_session_lock(void) { 22 if(chip_mode) {__real_omega_gpu_session_lock();return;} 23 if(!shell_mode) {fputs("DNN-HOST-GUARD session_lock\n",stderr);abort();} 24 ++locks; 25 } 26 void __wrap_omega_gpu_session_unlock(void) { 27 if(chip_mode) {__real_omega_gpu_session_unlock();return;} 28 if(!shell_mode) {fputs("DNN-HOST-GUARD session_unlock\n",stderr);abort();} 29 ++unlocks; 30 } 31 void __wrap_omega_gpu_session_free(OmegaGpuMem *m) { 32 if(chip_mode) {__real_omega_gpu_session_free(m);return;} 33 if(!shell_mode) {fputs("DNN-HOST-GUARD session_free\n",stderr);abort();} 34 ++frees; 35 } 36 int __wrap_omega_gpu_session_alloc(size_t bytes,OmegaGpuMem *m) { 37 if(chip_mode) return __real_omega_gpu_session_alloc(bytes,m); 38 if(!shell_mode) {fputs("DNN-HOST-GUARD session_alloc\n",stderr);abort();} 39 ++allocs;return -1; 40 } 41 #define CHECK(v) do { if (!(v)) { fprintf(stderr,"dnn-activations line %d: %s\n",__LINE__,#v);++failures; } } while(0) 42 static void put64(uint32_t *p,uintptr_t v) { p[0]=(uint32_t)v;p[1]=(uint32_t)((uint64_t)v>>32); } 43 static unsigned input_offset; 44 static void *inputs(size_t n,unsigned dtype) { 45 static const float values[]={0.0f,-0.0f,0.`000001f`,-0.`000001f`,0.125f,-0.125f,0.5f,-0.5f,1,-1,2,-2,3,-3,5,-5,8,-8,10,-10,20,-20,80,-80,100,-100,65504,-65504}; 46 void *p=malloc(n*(dtype?2:4));if (!p) abort(); 47 for(size_t i=0;i>16); } 53 else { _Float16 h=(_Float16)x;memcpy((uint16_t*)p+i,&h,2); } 54 } 55 return p; 56 } 57 static int run_case(uint64_t n,unsigned op,unsigned dtype,int wrong) { 58 OmegaGpuDnnActivationsShape shape={n,op,dtype}; 59 void *in=inputs(n,dtype);float *out=malloc((n+1)*4);BlackwellIRProgram *p=malloc(sizeof *p); 60 uint8_t *code=malloc(OMEGA_BW_CODE_CAP_MAX);OmegaBlackwellKernel k; 61 if (!out||!p||!code) abort(); 62 for(size_t i=0;i<=n;++i) out[i]=12345.0f; 63 int rc=omega_gpu_dnn_activations_codegen(&shape,p,code,OMEGA_BW_CODE_CAP_MAX,&k); 64 CHECK(rc==0); 65 if (!rc && chip_mode) { rc=omega_gpu_dnn_activations(&shape,in,out);CHECK(rc==0); } 66 if (!rc && !chip_mode) { 67 WsSim sim={0};sim.p=p;sim.threads=32;sim.order=op&1;sim.warp_sched=dtype&1; 68 uint32_t *cb=&sim.cbank[0x380/4];put64(cb,(uintptr_t)in);put64(cb+2,(uintptr_t)out);cb[4]=(uint32_t)n; 69 sim.ranges[0]=(WsRange){(uintptr_t)in,(uintptr_t)in+n*(dtype?2:4)}; 70 sim.ranges[1]=(WsRange){(uintptr_t)out,(uintptr_t)out+n*4};sim.nranges=2; 71 rc=ws_run(&sim,(uint32_t)((n+31)/32),1); 72 if(rc) fprintf(stderr,"activation simulator: %s\n",sim.msg); 73 CHECK(rc==0); 74 } 75 int equal=!rc; 76 for(size_t i=0;i