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 / cmdlist_sim_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Queue epochs may complete in reverse order until an emitted WFI drains them. |
| 3 | * Each dispatch executes real IR in the existing warp simulator. No fake values |
| 4 | * are injected on hazards: missing ordering changes the computed buffer data. */ |
| 5 | #include "cudapp_native.h" |
| 6 | #include "bw_warp_sim.h" |
| 7 | #define fadd em_fadd |
| 8 | #define ffma em_ffma |
| 9 | #include "omega_bw_em.h" |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #define N 32u |
| 14 | #define BUFS 6u |
| 15 | #define LAUNCHES 7u |
| 16 | static uint64_t descriptors[200704],barriers[4096]; |
| 17 | static const unsigned ins[LAUNCHES]={0,2,1,3,4,0,5}; |
| 18 | static const unsigned outs[LAUNCHES]={1,3,4,5,0,0,2}; |
| 19 | static BlackwellIRProgram kernel; |
| 20 | static int build(void) { |
| 21 | omega_bw_ir_init(&kernel);Em em={0};em.p=&kernel;Em *e=&em; |
| 22 | int ud=UV64(e),pi=V64(e),po=V64(e),a=V64(e),tid=V(e),v=V(e),one=V(e); |
| 23 | ldcu64(e,ud,0x358);ldc64(e,pi,0x380);ldc64(e,po,0x388); |
| 24 | s2r(e,tid,BW_SR_TID_X);movi(e,one,0x3f800000u); |
| 25 | imadw(e,a,tid,4u,pi);ldg32(e,v,a,ud,1);fadd(e,v,v,one); |
| 26 | imadw(e,a,tid,4u,po);stg(e,a,0,v,ud);tail(e); |
| 27 | return em.err || omega_bw_regalloc_solve(&kernel); |
| 28 | } |
| 29 | static int dispatch(float data[BUFS][N],unsigned i,int order) { |
| 30 | static WsSim s; memset(&s,0,sizeof s);s.p=&kernel;s.threads=N;s.order=order; |
| 31 | uint64_t pi=(uintptr_t)data[ins[i]],po=(uintptr_t)data[outs[i]]; |
| 32 | s.cbank[0x380/4]=(uint32_t)pi;s.cbank[0x384/4]=(uint32_t)(pi>>32); |
| 33 | s.cbank[0x388/4]=(uint32_t)po;s.cbank[0x38c/4]=(uint32_t)(po>>32); |
| 34 | s.nranges=1;s.ranges[0]=(WsRange){(uintptr_t)data,(uintptr_t)(data+BUFS)}; |
| 35 | if(ws_run(&s,1,1)) { fprintf(stderr,"FAIL warp simulator: %s\n",s.msg);return 1; } |
| 36 | return 0; |
| 37 | } |
| 38 | int main(void) { |
| 39 | if(build()) return 2; |
| 40 | for(unsigned i=0;i<LAUNCHES;i++) { |
| 41 | uint64_t *p=descriptors+i*49;p[0]=2; |
| 42 | p[1]=4096+ins[i]*sizeof(float[N]);p[2]=sizeof(float[N]);p[3]=1; |
| 43 | p[4]=4096+outs[i]*sizeof(float[N]);p[5]=sizeof(float[N]);p[6]=2; |
| 44 | } |
| 45 | uint64_t a[16]={LAUNCHES,LAUNCHES,0,0,16384},o[16],r=1; |
| 46 | if(omega_cmdlist_plan(&r,a,16,descriptors,200704,barriers,4096,o,16)||r) return 2; |
| 47 | for(int order=0;order<2;order++) { |
| 48 | float serial[BUFS][N],queued[BUFS][N]; |
| 49 | for(unsigned b=0;b<BUFS;b++) for(unsigned j=0;j<N;j++) serial[b][j]=(float)(b*N+j); |
| 50 | memcpy(queued,serial,sizeof serial); |
| 51 | for(unsigned i=0;i<LAUNCHES;i++) if(dispatch(serial,i,order)) return 2; |
| 52 | unsigned begin=0; |
| 53 | for(unsigned end=1;end<=LAUNCHES;end++) if(end==LAUNCHES || barriers[end]) { |
| 54 | for(unsigned i=end;i>begin;i--) if(dispatch(queued,i-1,order)) return 2; |
| 55 | begin=end; |
| 56 | } |
| 57 | if(memcmp(serial,queued,sizeof serial)) { fprintf(stderr,"FAIL sim data: queue epochs differ from serialized execution (warp order %d)\n",order);return 1; } |
| 58 | } |
| 59 | printf("PASS sim data: seven dispatches, independent overlap and nonadjacent RAW/WAR/WAW, two warp orders\n"); |
| 60 | return 0; |
| 61 | } |