interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / evidence / chip-gates-shared-20261112 / resident-bisect / resident_dbg.c

74 lines · 5006 bytes Raw Blame History
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. */
9static const uint32_t model_v[4][40]={
10 {5,0,0,32,4,1,0,0, 5,32,0,36,4,1,0,0, 5,36,0,40,4,1,0,0, 5,40,0,44,4,1,0,0, 5,44,0,48,4,1,0,0},
11 {1,0,16,32,4,4,0,0, 2,32,20,36,4,1,0,0, 2,36,20,40,4,1,0,0, 2,40,20,44,4,1,0,0, 2,44,20,48,4,1,0,0},
12 {3,0,24,32,4,1,0,0, 1,0,16,36,4,4,0,0, 2,36,20,40,4,1,0,0, 2,40,20,44,4,1,0,0, 2,44,20,48,4,1,0,0},
13 {1,0,16,32,4,4,0,0, 2,32,20,36,4,1,0,0, 3,36,24,40,4,1,0,0, 4,40,0,44,1,4,0,0, 5,44,0,45,1,1,0,0}};
14int main(int argc,char **argv) {
15 const uint32_t *MODEL=getenv("RMODEL")?model_v[atoi(getenv("RMODEL"))&3]:resident_model;
16 if(argc!=2||strcmp(argv[1],"--chip")||!getenv("SPARK_WINDOW")||!*getenv("SPARK_WINDOW")) {
17 fprintf(stderr,"NOT_RUN: --chip and an authorized SPARK_WINDOW are required\n");return 2;
18 }
19 static BlackwellIRProgram p;
20 OmegaGpuMem code[2]; OmegaGpuMem dm={0},xm={0},sm={0};
21 memset(code,0,sizeof code);
22 uint32_t gpr[2]={0};
23 OmegaGpuCmdList *cl=NULL;
24 int rc=1;
25 omega_gpu_session_lock();
26 if(!omega_gpu_session_open()) goto unlock;
27 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;
28 memcpy(dm.cpu,MODEL,sizeof resident_model);
29 if(omega_gpu_session_sync_to_gpu(&dm)) goto unlock;
30 for(unsigned i=0;i<2;i++) {
31 uint64_t err=0; OmegaBlackwellKernel k;
32 if(omega_gpu_resident_build(MODEL,i?1:(getenv("RLAYERS")?atoi(getenv("RLAYERS")):5),64,getenv("RCTAS")?atoi(getenv("RCTAS")):2,&p,&err)) goto unlock;
33 size_t bytes=omega_bw_program_code_bytes(&p);
34 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;
35 gpr[i]=omega_bw_gpr_declared(p.regalloc.peak_gpr_usage);
36 if(gpr[i]<64) gpr[i]=64;
37 }
38 omega_gpu_session_unlock();
39 if(omega_gpu_cmdlist_create(5,&cl)) goto free_buffers;
40 omega_gpu_session_lock();
41 unsigned m0=getenv("RMODE")?(unsigned)atoi(getenv("RMODE")):0; for(unsigned witness=0;witness<2;witness++) for(unsigned mode=m0;mode<m0+1;mode++) {
42 float expected[64];resident_input(expected,witness);memcpy(xm.cpu,expected,sizeof expected);
43 resident_reference(MODEL,mode?5:(getenv("RLAYERS")?atoi(getenv("RLAYERS")):5),expected);memset(sm.cpu,0,10*sizeof(uint32_t));
44 if(omega_gpu_session_sync_to_gpu(&xm)||omega_gpu_session_sync_to_gpu(&sm)) goto unlock;
45 omega_gpu_cmdlist_reset(cl);
46 unsigned count=mode?5:1;
47 for(unsigned l=0;l<count;l++) {
48 uint64_t ptrs[]={dm.va+l*8*sizeof(uint32_t),xm.va,sm.va+l*2*sizeof(uint32_t)};
49 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);}
50 OmegaGpuLaunch L={.code_va=code[mode].va,.gpr_count=gpr[mode],.threads_x=(getenv("RTHREADS")?atoi(getenv("RTHREADS")):32),.threads_y=1,.grid_x=(getenv("RCTAS")?atoi(getenv("RCTAS")):2),.grid_y=1,.num_elements=64,.args=args,.n_args=6,.timeout_ms=20000};
51 if(omega_gpu_cmdlist_add(cl,&L)<0) goto unlock;
52 }
53 OmegaGpuCmdListOpts opts={.mode=OMEGA_GPU_CMDLIST_PCAS,.barrier=OMEGA_GPU_CMDLIST_BARRIER_WFI,.timeout_ms=20000};
54 OmegaGpuCmdListStats st={0};
55 int src=omega_gpu_cmdlist_submit(cl,&opts,&st);
56 { uint32_t *sy=sm.cpu; float *xo=xm.cpu; printf("DBG submit rc=%d witness=%u mode=%u sync:",src,witness,mode); for(int q=0;q<10;q++) printf(" %u",sy[q]); printf("\nDBG x:"); for(int q=0;q<64;q++) printf(" %a",xo[q]); printf("\nDBG want:"); for(int q=0;q<64;q++) printf(" %a",expected[q]); printf("\n"); fflush(stdout); }
57 if(src||omega_gpu_session_sync_to_cpu(&xm)||omega_gpu_session_sync_to_cpu(&sm)) goto unlock;
58 if(st.launches!=count||st.sems_done!=count||memcmp(xm.cpu,expected,sizeof expected)) goto unlock;
59 uint32_t *sync=sm.cpu;
60 for(unsigned l=0;l<count;l++) if(sync[2*l]!=0||sync[2*l+1]!=(mode?1u:5u)) goto unlock;
61 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);
62 }
63 rc=0;
64unlock:
65 if(rc) fprintf(stderr,"resident chip FAIL: %s\n",omega_gpu_session_last_error());
66 omega_gpu_session_unlock();
67 if(cl) omega_gpu_cmdlist_free(cl);
68free_buffers:
69 omega_gpu_session_lock();
70 for(unsigned i=0;i<2;i++) omega_gpu_session_free(&code[i]);
71 omega_gpu_session_free(&dm);omega_gpu_session_free(&xm);omega_gpu_session_free(&sm);
72 omega_gpu_session_unlock();
73 printf("GPU RESIDENT CHIP %s\n",rc?"FAIL":"PASS");return rc;
74}