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 / gpu_resident_chip.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_gpu_resident.h" |
| 3 | #include "omega_gpu_cmdlist.h" |
| 4 | #include "gpu_resident_fixture.h" |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | /* No device open without exact --chip argument and an operator-supplied window label. */ |
| 9 | int main(int argc,char **argv) { |
| 10 | if(argc!=2||strcmp(argv[1],"--chip")||!getenv("SPARK_WINDOW")||!*getenv("SPARK_WINDOW")) { |
| 11 | fprintf(stderr,"NOT_RUN: --chip and an authorized SPARK_WINDOW are required\n");return 2; |
| 12 | } |
| 13 | static BlackwellIRProgram p; |
| 14 | OmegaGpuMem code[2]; OmegaGpuMem dm={0},xm={0},sm={0}; |
| 15 | memset(code,0,sizeof code); |
| 16 | uint32_t gpr[2]={0}; |
| 17 | OmegaGpuCmdList *cl=NULL; |
| 18 | int rc=1; |
| 19 | omega_gpu_session_lock(); |
| 20 | if(!omega_gpu_session_open()) goto unlock; |
| 21 | if(omega_gpu_session_alloc(sizeof resident_model,&dm)||omega_gpu_session_alloc(64*sizeof(float),&xm)||omega_gpu_session_alloc(10*sizeof(uint32_t),&sm)) goto unlock; |
| 22 | memcpy(dm.cpu,resident_model,sizeof resident_model); |
| 23 | if(omega_gpu_session_sync_to_gpu(&dm)) goto unlock; |
| 24 | for(unsigned i=0;i<2;i++) { |
| 25 | uint64_t err=0; OmegaBlackwellKernel k; |
| 26 | if(omega_gpu_resident_build(resident_model,i?1:5,64,2,&p,&err)) goto unlock; |
| 27 | size_t bytes=omega_bw_program_code_bytes(&p); |
| 28 | if(omega_gpu_session_alloc_code(bytes,&code[i])||omega_blackwell_kernel_encode_into(&p,code[i].cpu,bytes,&k)||omega_gpu_session_sync_to_gpu(&code[i])) goto unlock; |
| 29 | gpr[i]=omega_bw_gpr_declared(p.regalloc.peak_gpr_usage); |
| 30 | if(gpr[i]<64) gpr[i]=64; |
| 31 | } |
| 32 | omega_gpu_session_unlock(); |
| 33 | if(omega_gpu_cmdlist_create(5,&cl)) goto free_buffers; |
| 34 | omega_gpu_session_lock(); |
| 35 | for(unsigned witness=0;witness<2;witness++) for(unsigned mode=0;mode<2;mode++) { |
| 36 | float expected[64];resident_input(expected,witness);memcpy(xm.cpu,expected,sizeof expected); |
| 37 | resident_reference(resident_model,5,expected);memset(sm.cpu,0,10*sizeof(uint32_t)); |
| 38 | if(omega_gpu_session_sync_to_gpu(&xm)||omega_gpu_session_sync_to_gpu(&sm)) goto unlock; |
| 39 | omega_gpu_cmdlist_reset(cl); |
| 40 | unsigned count=mode?5:1; |
| 41 | for(unsigned l=0;l<count;l++) { |
| 42 | uint64_t ptrs[]={dm.va+l*8*sizeof(uint32_t),xm.va,sm.va+l*2*sizeof(uint32_t)}; |
| 43 | uint32_t args[6];for(unsigned j=0;j<3;j++) {args[2*j]=(uint32_t)ptrs[j];args[2*j+1]=(uint32_t)(ptrs[j]>>32);} |
| 44 | OmegaGpuLaunch L={.code_va=code[mode].va,.gpr_count=gpr[mode],.threads_x=32,.threads_y=1,.grid_x=2,.grid_y=1,.num_elements=64,.args=args,.n_args=6,.timeout_ms=20000}; |
| 45 | if(omega_gpu_cmdlist_add(cl,&L)<0) goto unlock; |
| 46 | } |
| 47 | OmegaGpuCmdListOpts opts={.mode=OMEGA_GPU_CMDLIST_PCAS,.barrier=OMEGA_GPU_CMDLIST_BARRIER_WFI,.timeout_ms=20000}; |
| 48 | OmegaGpuCmdListStats st={0}; |
| 49 | if(omega_gpu_cmdlist_submit(cl,&opts,&st)||omega_gpu_session_sync_to_cpu(&xm)||omega_gpu_session_sync_to_cpu(&sm)) goto unlock; |
| 50 | if(st.launches!=count||st.sems_done!=count||memcmp(xm.cpu,expected,sizeof expected)) goto unlock; |
| 51 | uint32_t *sync=sm.cpu; |
| 52 | for(unsigned l=0;l<count;l++) if(sync[2*l]!=0||sync[2*l+1]!=(mode?1u:5u)) goto unlock; |
| 53 | printf("resident chip witness=%u mode=%s launches=%u submits=%u elapsed_ns=%llu exact_f32=PASS\n",witness,mode?"cmdlist-layers":"resident",st.launches,st.submits,(unsigned long long)st.elapsed_ns); |
| 54 | } |
| 55 | rc=0; |
| 56 | unlock: |
| 57 | if(rc) fprintf(stderr,"resident chip FAIL: %s\n",omega_gpu_session_last_error()); |
| 58 | omega_gpu_session_unlock(); |
| 59 | if(cl) omega_gpu_cmdlist_free(cl); |
| 60 | free_buffers: |
| 61 | omega_gpu_session_lock(); |
| 62 | for(unsigned i=0;i<2;i++) omega_gpu_session_free(&code[i]); |
| 63 | omega_gpu_session_free(&dm);omega_gpu_session_free(&xm);omega_gpu_session_free(&sm); |
| 64 | omega_gpu_session_unlock(); |
| 65 | printf("GPU RESIDENT CHIP %s\n",rc?"FAIL":"PASS");return rc; |
| 66 | } |