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_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_gpu_resident.h" |
| 3 | #include "gpu_resident_grid.h" |
| 4 | #include "gpu_resident_fixture.h" |
| 5 | #include "omega_bw_hazard.h" |
| 6 | /* The static scoreboard checker over the encoded kernel. The warp simulator has no instruction latency, so a |
| 7 | * variable-latency producer (S2R, loads, atomics) read without its wait is invisible to it and is caught only here |
| 8 | * or on the chip (2026-11-12: S2R emitted fixed-latency, GB10 marker timeout). */ |
| 9 | static int hazards(unsigned n, unsigned ctas) { |
| 10 | static BlackwellIRProgram p; static OmegaBwHazardReport rep; |
| 11 | static uint8_t code[65536]; OmegaBlackwellKernel kernel; uint64_t err=0; |
| 12 | if(omega_gpu_resident_build(resident_model,n,64,ctas,&p,&err)) { fprintf(stderr,"resident build refused err=%llu\n",(unsigned long long)err);return 1; } |
| 13 | size_t bytes=omega_bw_program_code_bytes(&p); |
| 14 | if(bytes>sizeof code||omega_blackwell_kernel_encode_into(&p,code,bytes,&kernel)) { fprintf(stderr,"resident encode refused\n");return 1; } |
| 15 | int rc=omega_bw_hazard_check(code,bytes,&rep); |
| 16 | if(rc||rep.count) { |
| 17 | fprintf(stderr,"resident hazards layers=%u ctas=%u: rc=%d findings=%zu\n",n,ctas,rc,rep.count); |
| 18 | for(size_t i=0;i<rep.count&&i<OMEGA_BW_HAZARD_MAX;i++) |
| 19 | fprintf(stderr," IR %u %s R%u release 0x%x (producer/reader IR %u)\n",rep.f[i].pc,omega_bw_hazard_kind(rep.f[i].kind),rep.f[i].reg,rep.f[i].release,rep.f[i].src_pc); |
| 20 | return 1; |
| 21 | } |
| 22 | return 0; |
| 23 | } |
| 24 | static int run(int drop, unsigned order, unsigned quantum, unsigned witness) { |
| 25 | float arena[64], expected[64]; |
| 26 | resident_input(arena,witness); |
| 27 | memcpy(expected,arena,sizeof arena); resident_reference(resident_model,5,expected); |
| 28 | static BlackwellIRProgram p; |
| 29 | uint64_t err=0; |
| 30 | if(omega_gpu_resident_build(resident_model,5,64,2,&p,&err)) { fprintf(stderr,"resident build refused err=%llu\n",(unsigned long long)err);return 1; } |
| 31 | uint8_t code[65536];OmegaBlackwellKernel kernel; |
| 32 | if(omega_blackwell_kernel_encode_into(&p,code,sizeof code,&kernel)) { fprintf(stderr,"resident encode refused\n");return 1; } |
| 33 | if(drop) { |
| 34 | int end=-1,begin=-1; |
| 35 | for(unsigned i=0;i<p.count;i++) { |
| 36 | if(p.insns[i].op==BW_IR_MEMBAR_ALL_SYS && begin<0) begin=(int)i; |
| 37 | if(p.insns[i].op==BW_IR_ATOMG_EXCH_STRONG_SYS) end=(int)i; |
| 38 | } |
| 39 | /* The barrier region includes its spin-loop backward BRA; remove all of it. */ |
| 40 | if(begin<0||end<0) return 1; |
| 41 | int stop=end+1; |
| 42 | while(stop<(int)p.count && p.insns[stop].op!=BW_IR_IADD3) stop++; |
| 43 | for(int i=begin;i<stop;i++) p.insns[i].op=BW_IR_NOP; |
| 44 | } |
| 45 | uint32_t sync[2]={0}; |
| 46 | WsSim s={0}; s.p=&p;s.threads=32;s.order=(int)order;s.quantum=quantum; |
| 47 | uintptr_t args[]={ (uintptr_t)resident_model,(uintptr_t)arena,(uintptr_t)sync }; |
| 48 | for(unsigned i=0;i<3;i++) { s.cbank[(896+8*i)/4]=(uint32_t)args[i];s.cbank[(900+8*i)/4]=(uint32_t)(args[i]>>32); } |
| 49 | s.ranges[0]=(WsRange){(uintptr_t)resident_model,(uintptr_t)resident_model+sizeof resident_model}; |
| 50 | s.ranges[1]=(WsRange){(uintptr_t)arena,(uintptr_t)arena+sizeof arena}; |
| 51 | s.ranges[2]=(WsRange){(uintptr_t)sync,(uintptr_t)sync+sizeof sync};s.nranges=3; |
| 52 | int rc=resident_grid(&s,2,order); |
| 53 | if(!drop && (rc||memcmp(arena,expected,sizeof arena)||sync[1]!=5)) { |
| 54 | fprintf(stderr,"resident rc=%d %s gen=%u order=%u quantum=%u\n",rc,s.msg,sync[1],order,quantum); |
| 55 | for(unsigned i=32;i<46;i++) fprintf(stderr,"%u %g expected %g\n",i,arena[i],expected[i]); |
| 56 | return 1; |
| 57 | } |
| 58 | return drop ? (!rc && !memcmp(arena,expected,sizeof arena)) : 0; |
| 59 | } |
| 60 | int main(int argc,char **argv) { |
| 61 | if(argc!=2||strcmp(argv[1],"--sim")) { fprintf(stderr,"use --sim; chip tier NOT_RUN\n");return 2; } |
| 62 | for(unsigned n=1;n<=5;n+=4) for(unsigned c=1;c<=2;c++) if(hazards(n,c)) return 1; |
| 63 | for(unsigned w=0;w<2;w++) for(unsigned o=0;o<2;o++) for(unsigned q=1;q<=17;q+=8) if(run(0,o,q,w)) return 1; |
| 64 | if(run(1,0,10000,0)) { fprintf(stderr,"dropped barrier survived\n");return 1; } |
| 65 | uint32_t bad[40];memcpy(bad,resident_model,sizeof bad);bad[3]=64; |
| 66 | static BlackwellIRProgram p;uint64_t err=0; |
| 67 | if(!omega_gpu_resident_build(bad,5,64,2,&p,&err)) return 1; |
| 68 | memcpy(bad,resident_model,sizeof bad);bad[0]=99; |
| 69 | if(!omega_gpu_resident_build(bad,5,64,2,&p,&err)) return 1; |
| 70 | const unsigned fields[]={0,1,2,3,4,4,5,5,6,7,13,28}; |
| 71 | const uint32_t values[]={0,64,64,0,0,33,0,33,1,1,2,2}; |
| 72 | for(unsigned i=0;i<sizeof fields/sizeof fields[0];i++) { |
| 73 | memcpy(bad,resident_model,sizeof bad);bad[fields[i]]=values[i]; |
| 74 | if(!omega_gpu_resident_build(bad,5,64,2,&p,&err)) return 1; |
| 75 | } |
| 76 | if(!omega_gpu_resident_build(resident_model,0,64,2,&p,&err) || |
| 77 | !omega_gpu_resident_build(resident_model,5,0,2,&p,&err) || |
| 78 | !omega_gpu_resident_build(resident_model,5,64,0,&p,&err) || |
| 79 | !omega_gpu_resident_build(resident_model,5,64,3,&p,&err)) return 1; |
| 80 | puts("GPU RESIDENT PASS (scheduling hazards, reference, interleaved CTAs, barrier and descriptor controls); chip tier is gpu_resident_chip");return 0; |
| 81 | } |