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/tests/codegen_moe_diff_test.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 / tests / codegen_moe_diff_test.c` 92 lines · 6676 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include 3 #include 4 #include 5 #include "omega_blackwell_codegen_moe.h" 6 #include "omega_blackwell_codegen_moe2.h" 7 #include "omega_cubin.h" 8 #include "cudapp_native.h" 9 #include "omega_gpu_om_ir.h" 10 extern int omega_blackwell_codegen_fp8_gemv_prog_oracle(const OmegaFp8GemvSpec *, BlackwellIRProgram *); 11 extern int omega_blackwell_codegen_fp8_gemv2_prog_oracle(const OmegaFp8GemvSpec *, BlackwellIRProgram *); 12 extern uint32_t omega_fp8_gemv_steps_oracle(const OmegaFp8GemvSpec *); 13 extern uint32_t omega_fp8_gemv_shared_bytes_oracle(const OmegaFp8GemvSpec *); 14 extern uint32_t omega_fp8_gemv2_shared_bytes_oracle(const OmegaFp8GemvSpec *); 15 extern int omega_fp8_gemv2_spec_ok_oracle(const OmegaFp8GemvSpec *); 16 static BlackwellIRProgram a,b; 17 static unsigned cases, refused; 18 static int equal(unsigned version, const OmegaFp8GemvSpec *s) { 19 int ra=version==1?omega_blackwell_codegen_fp8_gemv_prog_oracle(s,&a):omega_blackwell_codegen_fp8_gemv2_prog_oracle(s,&a); 20 int rb=version==1?omega_blackwell_codegen_fp8_gemv_prog(s,&b):omega_blackwell_codegen_fp8_gemv2_prog(s,&b); 21 if(ra!=rb)goto fail; 22 if(ra){refused++;return 1;} 23 if(a.count!=b.count||memcmp(a.insns,b.insns,a.count*sizeof a.insns[0])||memcmp(&a.regalloc,&b.regalloc,sizeof a.regalloc))goto fail; 24 static uint8_t x[BW_MAX_IR_INSNS*16],y[BW_MAX_IR_INSNS*16];size_t nx=0,ny=0; 25 if(omega_bw_encode_program(&a,x,sizeof x,&nx)||omega_bw_encode_program(&b,y,sizeof y,&ny)||nx!=ny||memcmp(x,y,nx))goto fail; 26 uint8_t *cx=NULL,*cy=NULL;size_t lx=0,ly=0;char error[256]; 27 const OmegaCubinParam params[]={{OMEGA_FP8_ARG_TAB,8,1},{OMEGA_FP8_ARG_X,8,1},{OMEGA_FP8_ARG_Y,8,1},{OMEGA_FP8_ARG_RG,4,0},{OMEGA_FP8_ARG_XSTRIDE,4,0},{OMEGA_FP8_ARG_YSTRIDE,4,0},{OMEGA_FP8_ARG_STRIDE,4,0}}; 28 uint32_t shared=version==1?omega_fp8_gemv_shared_bytes(s):omega_fp8_gemv2_shared_bytes(s); 29 int ex=omega_cubin_pack("moe",x,nx,params,7,OMEGA_FP8_ARG_TAB+40,omega_bw_gpr_declared(a.regalloc.peak_gpr_usage),shared,&cx,&lx,error,sizeof error); 30 int ey=omega_cubin_pack("moe",y,ny,params,7,OMEGA_FP8_ARG_TAB+40,omega_bw_gpr_declared(b.regalloc.peak_gpr_usage),shared,&cy,&ly,error,sizeof error); 31 int ceq=!ex&&!ey&&lx==ly&&!memcmp(cx,cy,lx);omega_cubin_free(cx);omega_cubin_free(cy); 32 if(!ceq)goto fail; 33 cases++;return 1; 34 fail: 35 fprintf(stderr,"MOE%u DIFF k=%u lb=%u rows=%u warps=%u depth=%u mutant=%d sched=%u coal=%u wfirst=%u C=%d Omega=%d count=%zu/%zu\n",version,s->k,s->lane_bytes,s->rows,s->warps,s->depth,s->mutant,s->sched,s->coal,s->wfirst,ra,rb,a.count,b.count); 36 for(size_t i=0;ik=value;break;case 1:s->lane_bytes=value;break; 44 case 2:s->rows=value;break;case 3:s->warps=value;break; 45 case 4:s->depth=value;break;case 5:s->mutant=(int32_t)value;break; 46 case 6:s->sched=value;break;case 7:s->coal=value;break;case 8:s->wfirst=value;break; 47 } 48 } 49 static uint32_t corrupt(uint64_t *r,uint64_t k,uint64_t a0,uint64_t q,uint64_t c,void *records,uint64_t nr,void *meta,uint64_t nm){ 50 const uint64_t fields[16]={256,8,1,1}; 51 (void)k;(void)a0;(void)q;(void)c; 52 uint32_t rc=omega_cg_moe(r,fields,16,records,nr,meta,nm); 53 if(!rc&&!*r)((uint64_t*)records)[6]^=1; 54 return rc; 55 } 56 static int negative(void){ 57 OmegaFp8GemvSpec s={256,8,1,1,0,0,0,0,0}; 58 if(omega_blackwell_codegen_fp8_gemv_prog_oracle(&s,&a)||omega_gpu_om_ir_replay(corrupt,0,0,0,0,&b,NULL))return 0; 59 if(a.count==b.count&&!memcmp(a.insns,b.insns,a.count*sizeof a.insns[0]))return 0; 60 puts("CODEGEN MOE RECORD NEGATIVE CONTROL CAUGHT");return 1; 61 } 62 int main(int argc,char **argv) { 63 if(argc==11){OmegaFp8GemvSpec s={0};unsigned v=(unsigned)strtoul(argv[1],0,0);s.k=(uint32_t)strtoul(argv[2],0,0);s.lane_bytes=(uint32_t)strtoul(argv[3],0,0);s.rows=(uint32_t)strtoul(argv[4],0,0);s.warps=(uint32_t)strtoul(argv[5],0,0);s.depth=(uint32_t)strtoul(argv[6],0,0);s.mutant=atoi(argv[7]);s.sched=(uint32_t)strtoul(argv[8],0,0);s.coal=(uint32_t)strtoul(argv[9],0,0);s.wfirst=(uint32_t)strtoul(argv[10],0,0);return equal(v,&s)?0:1;} 64 for(unsigned v=1;v<=2;v++)for(unsigned k=256;k<=32768;k+=256)for(unsigned lb=8;lb<=16;lb*=2)for(unsigned r=1;r<=8;r*=2)for(unsigned w=1;w<=32;w++)for(unsigned d=0;d<=(v==1?16:0);d++)for(int m=0;m<=(v==1?5:3);m++)for(unsigned sc=0;sc<=(v==1?1:0);sc++)for(unsigned co=0;co<=(v==1?1:0);co++)for(unsigned wf=0;wf<=(v==1?1:0);wf++){ 65 OmegaFp8GemvSpec s={k,lb,r,w,d,m,sc,co,wf}; 66 if(v==1){if(omega_fp8_gemv_steps(&s)!=omega_fp8_gemv_steps_oracle(&s)||omega_fp8_gemv_shared_bytes(&s)!=omega_fp8_gemv_shared_bytes_oracle(&s))return 1;if(!omega_fp8_gemv_steps_oracle(&s))continue;} 67 else{if(omega_fp8_gemv2_spec_ok(&s)!=omega_fp8_gemv2_spec_ok_oracle(&s)||omega_fp8_gemv2_shared_bytes(&s)!=omega_fp8_gemv2_shared_bytes_oracle(&s))return 1;if(!omega_fp8_gemv2_spec_ok_oracle(&s))continue;} 68 if(!equal(v,&s))return 1; 69 /* Variant 2 never reads these four scalar axes in the C oracle. Exercise 70 * every bit and all-ones independently for every accepted structural tuple. */ 71 if(v==2)for(unsigned axis=4;axis<=8;axis++){ 72 if(axis==5)continue; 73 for(unsigned bit=0;bit<=32;bit++){ 74 OmegaFp8GemvSpec scalar=s;set_axis(&scalar,axis,bit==32?UINT32_MAX:UINT32_C(1)<