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
CUDApp / tests / scan_rest_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_gpu_scan.h" |
| 3 | #include "cudapp_native.h" |
| 4 | #include <assert.h> |
| 5 | #include <stdint.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <stdio.h> |
| 8 | #include <string.h> |
| 9 | #include <math.h> |
| 10 | int scan_c_prefix(const float *,size_t,float *); |
| 11 | static uint32_t bits(float f){uint32_t u;memcpy(&u,&f,4);return u;} |
| 12 | static float value(uint32_t u){float f;memcpy(&f,&u,4);return f;} |
| 13 | static void equal(float a,float b){assert((isnan(a)&&isnan(b))||bits(a)==bits(b));} |
| 14 | int main(void){ |
| 15 | const uint32_t cls[]={0,0x80000000u,1,0x80000001u,0x3f800000u,0xbf800000u,0x7f800000u,0xff800000u,0x7fc00001u,0x4b000000u}; |
| 16 | const size_t ns[]={1,31,32,33,63,64,65,1023,1024,1025,2049}; |
| 17 | for(unsigned k=0;k<sizeof ns/sizeof *ns;k++) for(unsigned c=0;c<sizeof cls/sizeof *cls;c++){ |
| 18 | size_t n=ns[k],nt=(n+31)/32; |
| 19 | float *x=malloc(n*4),*a=malloc(n*4),*b=malloc(n*4),*tot=malloc(nt*4); |
| 20 | assert(x&&a&&b&&tot); |
| 21 | for(size_t i=0;i<n;i++)x[i]=value(cls[(i+c)%(sizeof cls/sizeof *cls)]); |
| 22 | assert(!scan_c_prefix(x,n,a));assert(!omega_gpu_prefix_sum_reference(x,n,b)); |
| 23 | for(size_t i=0;i<n;i++)equal(a[i],b[i]); |
| 24 | memcpy(a,x,n*4);memcpy(b,x,n*4); |
| 25 | for(size_t t=0;t<nt;t++)tot[t]=value(cls[(t+c)%(sizeof cls/sizeof *cls)]); |
| 26 | for(size_t i=32;i<n;i++)a[i]=tot[i/32-1]+a[i]; |
| 27 | uint64_t r=9;assert(!omega_ar_carry(&r,tot,nt,b,n)&&!r); |
| 28 | for(size_t i=0;i<n;i++)equal(a[i],b[i]); |
| 29 | if(nt>1){r=0;assert(!omega_ar_carry(&r,tot,0,b,n)&&r==1);} |
| 30 | free(x);free(a);free(b);free(tot); |
| 31 | } |
| 32 | puts("SCAN_REFERENCE_REST differential PASS");return 0; |
| 33 | } |