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_conv2d_ref.h # 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_conv2d_ref.h` 37 lines · 1914 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #ifndef GPU_CONV2D_REF_H 3 #define GPU_CONV2D_REF_H 4 #include 5 #include 6 #include 7 /* Independent numeric decoding; no emitted IR, seeded plan, or simulator math. */ 8 static double cv_value(const void *p,size_t i,unsigned t) { 9 if(!t) return ((const float*)p)[i]; 10 uint16_t u=((const uint16_t*)p)[i]; 11 if(t==1) {uint32_t x=(uint32_t)u<<16;float f;memcpy(&f,&x,4);return f;} 12 unsigned e=u>>10&31,m=u&1023; double x=e?ldexp(1.0+(double)m/1024,(int)e-15):ldexp((double)m,-24); 13 return u&32768?-x:x; 14 } 15 static size_t cv_index(unsigned layout,size_t n,size_t c,size_t y,size_t x,size_t C,size_t H,size_t W) { 16 return layout?((n*H+y)*W+x)*C+c:((n*C+c)*H+y)*W+x; 17 } 18 static void cv_reference(const OmegaGpuConv2dShape *s,const void *a,const void *b,double *out,double *mag,int wrong) { 19 size_t oh=(s->height+s->pad_top+s->pad_bottom-s->dilation_h*(s->kernel_h-1)-1)/s->stride_h+1; 20 size_t ow=(s->width+s->pad_left+s->pad_right-s->dilation_w*(s->kernel_w-1)-1)/s->stride_w+1; 21 size_t ci=s->in_channels/s->groups,co=s->out_channels/s->groups; 22 for(size_t n=0;nbatch;n++) for(size_t o=0;oout_channels;o++) 23 for(size_t y=0;ykernel_h;ky++) for(size_t kx=0;kxkernel_w;kx++) { 26 int64_t iy=(int64_t)(y*s->stride_h+ky*s->dilation_h)-s->pad_top; 27 int64_t ix=(int64_t)(x*s->stride_w+kx*s->dilation_w)-s->pad_left; 28 if(iy<0||ix<0||iy>=s->height||ix>=s->width) continue; 29 size_t ic=c+(wrong?0:o/co)*ci; 30 double product=cv_value(a,cv_index(s->layout,n,ic,iy,ix,s->in_channels,s->height,s->width),s->dtype)* 31 cv_value(b,((o*ci+c)*s->kernel_h+ky)*s->kernel_w+kx,s->dtype); 32 sum+=product;absum+=fabs(product); 33 } 34 size_t dst=cv_index(s->layout,n,o,y,x,s->out_channels,oh,ow);out[dst]=sum;mag[dst]=absum; 35 } 36 } 37 #endif