Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/om/q38-head/check.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / om / q38-head / check.c` 145 lines · 8456 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* External verification instrument. Never linked into the runtime. */ 3 #include "bw_warp_sim_k.h" 4 #include "components/native-frame.h" 5 #include "omega_gpu_session.h" 6 #include 7 #include 8 #include "../standalone-oracles/oracle.h" 9 static uint32_t bits(float f) { uint32_t u; memcpy(&u,&f,4); return u; } 10 static int chip; 11 static OmegaGpuMem code; 12 static void demand(int rc) {if(rc) {fprintf(stderr,"GPU: %s\n",omega_gpu_session_last_error());exit(4);}} 13 static void execute(float **v,uint32_t n,float hn,unsigned order) { 14 if(chip) { 15 OmegaGpuMem mem[4]; uint32_t args[10]; 16 omega_gpu_session_lock(); 17 for(unsigned j=0;j<4;j++) { 18 demand(omega_gpu_session_alloc(so_bytes(n,4,32),&mem[j])); 19 memcpy(mem[j].cpu,v[j],so_bytes(n,4,32));demand(omega_gpu_session_sync_to_gpu(&mem[j])); 20 args[j*2]=(uint32_t)mem[j].va;args[j*2+1]=(uint32_t)(mem[j].va>>32); 21 } 22 args[8]=bits(hn);args[9]=n; 23 OmegaGpuLaunch l={0};l.code_va=code.va;l.gpr_count=64;l.threads_x=256;l.threads_y=1; 24 l.grid_x=(uint32_t)so_call(7,n,0,0,0);l.grid_y=1;l.num_elements=n;l.args=args;l.n_args=10;l.timeout_ms=20000; 25 demand(omega_gpu_session_launch(&l,NULL,NULL)); 26 for(unsigned j=0;j<4;j++) { 27 demand(omega_gpu_session_sync_to_cpu(&mem[j]));memcpy(v[j],mem[j].cpu,so_bytes(n,4,32)); 28 omega_gpu_session_free(&mem[j]); 29 } 30 omega_gpu_session_unlock();return; 31 } 32 static WsSim s; memset(&s,0,sizeof s);s.p=&native_program;s.threads=256;s.order=order; 33 s.nranges=4; 34 for(unsigned j=0;j<4;j++) { 35 uintptr_t p=(uintptr_t)v[j];s.cbank[(896+j*8)/4]=(uint32_t)p;s.cbank[(896+j*8)/4+1]=(uint32_t)(p>>32); 36 s.ranges[j].lo=p;s.ranges[j].hi=so_call(5,p,so_bytes(n,4,0),0,0); 37 } 38 s.cbank[928/4]=bits(hn);s.cbank[932/4]=n; 39 int rc=ws_run(&s,(uint32_t)so_call(7,n,0,0,0),1); 40 if(rc) {fprintf(stderr,"sim n%u order%u: %s\n",n,order,s.msg);exit(2);} 41 } 42 static unsigned run(uint32_t n, float hn, unsigned order) { 43 float *v[4]; 44 for(unsigned j=0;j<4;j++) {v[j]=calloc(so_bytes(n,1,32),4);assert(v[j]);} 45 for(uint32_t i=0;iFLT_MAX, 63 so_all(so_any(lo-slack < -FLT_MAX,(long double)v[2][i]>=lo-slack,0), 64 so_any(hi+slack > FLT_MAX,(long double)v[3][i]<=hi+slack,0),1),0); 65 int ok=so_all((long double)v[2][i]<=lo,(long double)v[3][i]>=hi,tight); 66 if(!ok) { 67 if(!bad) fprintf(stderr,"bad row%u s%g c%g hn%g lo%g hi%g\n",i,v[0][i],v[1][i],hn,v[2][i],v[3][i]); 68 bad=so_bad(bad,ok); 69 } 70 } 71 for(unsigned j=2;j<4;j++)for(uint32_t i=n;i=3&&!strcmp(argv[2],"--chip"); 113 if(argc>=3&&!chip)return 65; 114 if(chip) { 115 unsigned char bytes[16384]; FILE *f=fopen(argv[1],"rb");assert(f); 116 size_t off=48+16*(native_program.regalloc.num_vregs+native_program.regalloc.num_uvregs)+64*native_program.count; 117 assert(!fseek(f,(long)off,SEEK_SET));size_t nb=fread(bytes,1,sizeof bytes,f);assert(!ferror(f));fclose(f); 118 omega_gpu_session_lock();demand(omega_gpu_session_open()?0:-1); 119 demand(omega_gpu_session_alloc_code(nb,&code)); 120 memcpy(code.cpu,bytes,nb);demand(omega_gpu_session_sync_to_gpu(&code));omega_gpu_session_unlock(); 121 } 122 uint32_t counts[]={1,31,32,33,255,256,257,1027}; 123 float norms[]={FLT_TRUE_MIN,0x1p-60f,1,123.25f,0x1p60f,FLT_MAX}; 124 for(unsigned a=0;aop=BW_IR_MOV_IMM;x->imm=bits(INFINITY); 141 x->src1_vreg=x->src2_vreg=x->src3_vreg=-1;changed=1;break; 142 } 143 if(!changed||!run(1027,123.25f,0))return 3; 144 puts("PASS: all-infinite radius mutant caught by bounded slack");return 0; 145 }