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 / codegen_tc_sim.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include <stdint.h> |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include "omega_blackwell_codegen_tc.h" |
| 6 | #include "bw_warp_sim_tc.h" |
| 7 | |
| 8 | static BlackwellIRProgram p; |
| 9 | static WsSim sim; |
| 10 | |
| 11 | static void pointer(unsigned at, const void *p) { |
| 12 | uint64_t v=(uintptr_t)p; |
| 13 | sim.cbank[at/4]=(uint32_t)v; |
| 14 | sim.cbank[at/4+1]=(uint32_t)(v>>32); |
| 15 | } |
| 16 | static void range(unsigned at,const void *p,size_t bytes) { |
| 17 | sim.ranges[at].lo=(uintptr_t)p; |
| 18 | sim.ranges[at].hi=(uintptr_t)p+bytes; |
| 19 | sim.nranges=at+1; |
| 20 | } |
| 21 | static int probe(void) { |
| 22 | static uint32_t input[OMEGA_TC_PROBE_IN_BYTES/4]; |
| 23 | static float output[OMEGA_TC_PROBE_OUT_BYTES/4]; |
| 24 | for(unsigned i=0;i<192;i++)input[i]=0x3f803f80u; |
| 25 | for(unsigned i=0;i<128;i++) { |
| 26 | float c=(float)(i%17); |
| 27 | memcpy(&input[192+i],&c,4); |
| 28 | } |
| 29 | for(int mutant=0;mutant<=1;mutant++) { |
| 30 | if(omega_blackwell_codegen_tc_probe_prog(mutant,&p))return 1; |
| 31 | memset(&sim,0,sizeof sim);sim.p=&p;sim.threads=32; |
| 32 | memset(output,0xee,sizeof output); |
| 33 | pointer(0x380,input);pointer(0x388,output); |
| 34 | range(0,input,sizeof input);range(1,output,sizeof output); |
| 35 | if(ws_run(&sim,1,1)){fprintf(stderr,"probe sim: %s\n",sim.msg);return 1;} |
| 36 | for(unsigned i=0;i<128;i++) { |
| 37 | float want=mutant?0.0f:(float)(i%17); |
| 38 | for(unsigned k=0;k<16;k++)want+=1.0f; |
| 39 | if(output[i]!=want){fprintf(stderr,"probe output[%u] differs\n",i);return 1;} |
| 40 | } |
| 41 | } |
| 42 | puts("CODEGEN TC PROBE SIM PASS (accumulate and zero accumulator)");return 0; |
| 43 | } |
| 44 | static int bandwidth(void) { |
| 45 | enum { THREADS=64, ITERS=3, GRID=2, REGION=ITERS*THREADS*128/4 }; |
| 46 | static uint32_t input[GRID*REGION],output[GRID*THREADS]; |
| 47 | for(unsigned i=0;i<GRID*REGION;i++)input[i]=i*2654435761u; |
| 48 | for(unsigned groups=1;groups<=2;groups++) { |
| 49 | if(omega_blackwell_codegen_tc_bw_prog(ITERS,groups,THREADS,&p))return 1; |
| 50 | memset(&sim,0,sizeof sim);sim.p=&p;sim.threads=THREADS; |
| 51 | memset(output,0xee,sizeof output); |
| 52 | pointer(0x380,input);pointer(0x388,output); |
| 53 | range(0,input,sizeof input);range(1,output,sizeof output); |
| 54 | if(ws_run(&sim,GRID,1)){fprintf(stderr,"bandwidth sim: %s\n",sim.msg);return 1;} |
| 55 | for(unsigned c=0;c<GRID;c++)for(unsigned t=0;t<THREADS;t++) { |
| 56 | uint32_t want=0; |
| 57 | const uint32_t *r=input+(groups==1?0:c)*REGION; |
| 58 | for(unsigned it=0;it<ITERS;it++)for(unsigned q=0;q<8;q++)for(unsigned j=0;j<4;j++) |
| 59 | want^=r[(it*THREADS*128+q*THREADS*16+t*16)/4+j]; |
| 60 | if(output[c*THREADS+t]!=want){fprintf(stderr,"bandwidth output differs\n");return 1;} |
| 61 | } |
| 62 | } |
| 63 | puts("CODEGEN TC BANDWIDTH SIM PASS (shared and distinct CTA regions)");return 0; |
| 64 | } |
| 65 | int main(void) { |
| 66 | if(probe() || bandwidth())return 1; |
| 67 | puts("CODEGEN TC SIM PASS");return 0; |
| 68 | } |