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 / attn_host_diff.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include <stdint.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | #include <limits.h> |
| 7 | uint64_t om_plan(uint64_t[32],uint32_t);uint64_t c_plan(uint64_t[32],uint32_t); |
| 8 | size_t om_check(uint32_t,const uint32_t*,const uint32_t*,size_t);size_t c_check(uint32_t,const uint32_t*,const uint32_t*,size_t); |
| 9 | uint64_t om_clock(uint64_t,uint64_t);uint64_t c_clock(uint64_t,uint64_t); |
| 10 | #define REQUIRE(x) do{if(!(x)){fprintf(stderr,"FAIL line %d: %s\n",__LINE__,#x);return 1;}}while(0) |
| 11 | static int policy(void){ |
| 12 | const uint32_t edge[]={0,1,2,3,4,15,16,17,31,32,33,63,64,65,127,128,129,255,256,257,1023,1024,1025,UINT32_MAX-1,UINT32_MAX}; |
| 13 | for(size_t i=0;i<sizeof edge/sizeof*edge;i++){ |
| 14 | uint64_t a[32]={0,0,edge[i]},b[32];memcpy(b,a,sizeof a); |
| 15 | REQUIRE(om_plan(a,0)==c_plan(b,0)&&!memcmp(a,b,sizeof a)); |
| 16 | } |
| 17 | for(size_t i=0;i<sizeof edge/sizeof*edge;i++)for(size_t j=0;j<sizeof edge/sizeof*edge;j++)for(unsigned ids=0;ids<2;ids++){ |
| 18 | uint64_t a[32]={edge[i],edge[j],129,31,edge[j],ids},b[32];memcpy(b,a,sizeof a); |
| 19 | REQUIRE(om_plan(a,1)==c_plan(b,1)&&!memcmp(a,b,sizeof a)); |
| 20 | /* Cursor partitions include the final row boundary without walking billions of rows. */ |
| 21 | uint64_t curs[]={0,edge[i]?edge[i]-1:0,edge[i],(uint64_t)edge[i]+1}; |
| 22 | for(size_t z=0;z<sizeof curs/sizeof*curs;z++){ |
| 23 | a[10]=b[10]=curs[z];REQUIRE(om_plan(a,2)==c_plan(b,2)&&!memcmp(a,b,sizeof a)); |
| 24 | REQUIRE(om_plan(a,3)==c_plan(b,3)&&!memcmp(a,b,sizeof a)); |
| 25 | } |
| 26 | } |
| 27 | /* Source launch policy boundaries per-1/per/per+1 and 32-bit offset wrap. */ |
| 28 | for(size_t j=1;j<sizeof edge/sizeof*edge;j++)for(unsigned z=0;z<3;z++){ |
| 29 | uint64_t a[32]={(uint64_t)edge[j]+z-1,1024,256,edge[j],17,1},b[32];memcpy(b,a,sizeof a); |
| 30 | REQUIRE(om_plan(a,1)==c_plan(b,1)&&!memcmp(a,b,sizeof a)); |
| 31 | REQUIRE(om_plan(a,2)==c_plan(b,2)&&!memcmp(a,b,sizeof a)); |
| 32 | } |
| 33 | return 0; |
| 34 | } |
| 35 | static int scans(void){ |
| 36 | const size_t ns[]={0,1,2,31,32,33,255,256,257,999999,1000000,1000001}; |
| 37 | uint32_t*w=malloc(1000001*sizeof*w),*x=malloc(1000001*sizeof*x);REQUIRE(w&&x); |
| 38 | for(size_t k=0;k<sizeof ns/sizeof*ns;k++){ |
| 39 | size_t n=ns[k];uint32_t sum=0; |
| 40 | for(size_t i=0;i<n;i++){x[i]=(i%3)?UINT32_MAX:17;sum+=x[i];w[i]=sum;} |
| 41 | for(uint32_t op=0;op<3;op++)REQUIRE(om_check(op,w,x,n)==c_check(op,w,x,n)); |
| 42 | REQUIRE(om_check(1,w,x,n)==0); |
| 43 | if(n){w[n-1]^=1;REQUIRE(om_check(1,w,x,n)>0);w[n-1]^=1;} |
| 44 | for(size_t i=0;i<n;i++)w[i]=(uint32_t)i; |
| 45 | REQUIRE(om_check(2,w,w,n)==0); |
| 46 | if(n>1){w[0]=1;w[n-1]=0;REQUIRE(om_check(2,w,w,n)==c_check(2,w,w,n)&&om_check(2,w,w,n)>0);} |
| 47 | for(size_t i=0;i<n;i++)w[i]=0x7fa00bad; |
| 48 | REQUIRE(om_check(0,w,w,n)==n&&om_check(0,w,w,n)==c_check(0,w,w,n)); |
| 49 | if(n){w[n-1]=0x7fa00bac;REQUIRE(om_check(0,w,w,n)==c_check(0,w,w,n));w[n-1]=0x7fa00bae;REQUIRE(om_check(0,w,w,n)==c_check(0,w,w,n));} |
| 50 | } |
| 51 | free(w);free(x);return 0; |
| 52 | } |
| 53 | int main(void){ |
| 54 | REQUIRE(policy()==0);REQUIRE(scans()==0); |
| 55 | const uint64_t ts[]={0,1,999999999,1000000000,1000000001,UINT32_MAX,UINT64_MAX-1,UINT64_MAX}; |
| 56 | for(size_t i=0;i<sizeof ts/sizeof*ts;i++)for(size_t j=0;j<sizeof ts/sizeof*ts;j++)REQUIRE(om_clock(ts[i],ts[j])==c_clock(ts[i],ts[j])); |
| 57 | REQUIRE(om_clock(1,0)!=om_clock(0,0)); |
| 58 | puts("ATTN-HOST-DIFF PASS");return 0; |
| 59 | } |