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 / runtime / cm_sort_unit.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 | #define CUDAPP_MIGRATION_PENDING_C_CM_SORT 1 |
| 7 | #define rx_cm_sort rx_cm_sort_oracle |
| 8 | #include "runtime/rx_cm_sort.h" |
| 9 | #undef rx_cm_sort |
| 10 | #undef RX_CM_SORT_H |
| 11 | #undef CUDAPP_MIGRATION_PENDING_C_CM_SORT |
| 12 | #define CUDAPP_MIGRATION_PENDING_C_CM_SORT 0 |
| 13 | #include "runtime/rx_cm_sort.h" |
| 14 | static uint64_t state=0x5258534f5254ULL; |
| 15 | static uint64_t next(void){state^=state<<13;state^=state>>7;state^=state<<17;return state;} |
| 16 | static void test(size_t n,unsigned mode){ |
| 17 | double *a=calloc(n?n:1,sizeof *a),*b=calloc(n?n:1,sizeof *b); |
| 18 | if(!a||!b)exit(2); |
| 19 | const uint64_t edge[]={0,UINT64_C(0x8000000000000000),UINT64_C(0x7ff0000000000000),UINT64_C(0xfff0000000000000),UINT64_C(0x7ff8000000000000),UINT64_C(0xfff8000000000000),1,UINT64_C(0x8000000000000001)}; |
| 20 | for(size_t i=0;i<n;i++){ |
| 21 | uint64_t u=next(); |
| 22 | if(mode==0)memcpy(a+i,&u,8); |
| 23 | else if(mode==1)a[i]=(double)(i%7); |
| 24 | else if(mode==2)a[i]=(double)(n-i); |
| 25 | else memcpy(a+i,&edge[i%(sizeof edge/sizeof *edge)],8); |
| 26 | } |
| 27 | memcpy(b,a,n*sizeof *a); |
| 28 | if(rx_cm_sort(a,n)||rx_cm_sort_oracle(b,n)||memcmp(a,b,n*sizeof *a)){fprintf(stderr,"CM SORT differential FAIL n=%zu mode=%u\n",n,mode);exit(1);} |
| 29 | free(a);free(b); |
| 30 | } |
| 31 | int main(void){ |
| 32 | const size_t n[]={0,1,2,10,255,256,257,511,512,513,767,768,769,1023,1024,1025,2047,2048,2049,4095,4096,4097}; |
| 33 | for(size_t i=0;i<sizeof n/sizeof *n;i++)for(unsigned mode=0;mode<4;mode++)test(n[i],mode); |
| 34 | for(unsigned i=0;i<100;i++)test((size_t)(next()%8193),i%4); |
| 35 | puts("CM SORT differential PASS");return 0; |
| 36 | } |