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 / codegen_moe_sim_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include "omega_blackwell_codegen_moe.h" |
| 5 | #include "omega_blackwell_codegen_moe2.h" |
| 6 | #include "bw_warp_sim_k.h" |
| 7 | /* Independent reference, WolframLanguageEvaluator: |
| 8 | * {(1+Mod[56,8]/8)*2^(Quotient[56,8]-7),512*(1+Mod[56,8]/8)*2^(Quotient[56,8]-7)} -> {1,512} |
| 9 | * {2^64,2^56,512*1*1*1,512/128} -> {18446744073709551616,72057594037927936,512,4}. |
| 10 | * All weights encode one, unfolded inputs and scales are one, hence each row is 512. |
| 11 | * Seven output rows and three warps exercise repeated and partial final row groups. |
| 12 | * This simulator models functional IR execution, NOT scoreboard timing or chip qualification. */ |
| 13 | static BlackwellIRProgram prog; |
| 14 | static WsSim sim; |
| 15 | static uint8_t weights[7*512], smem[8192]; |
| 16 | static float input[512],scales[4],output[7]; |
| 17 | static int run(unsigned variant, int mutant, int order, unsigned warp_order) { |
| 18 | OmegaFp8GemvSpec spec={512,8,1,3,2,mutant,1,1,1}; |
| 19 | if((variant==1?omega_blackwell_codegen_fp8_gemv_prog(&spec,&prog):omega_blackwell_codegen_fp8_gemv2_prog(&spec,&prog)))return 0; |
| 20 | memset(weights,56,sizeof weights); |
| 21 | for(unsigned i=0;i<512;i++)input[i]=18446744073709551616.0f; |
| 22 | for(unsigned i=0;i<4;i++)scales[i]=72057594037927936.0f; |
| 23 | for(unsigned i=0;i<7;i++)output[i]=-999.0f; |
| 24 | uint64_t table[2]={(uintptr_t)weights,(uintptr_t)scales}; |
| 25 | memset(&sim,0,sizeof sim);sim.p=&prog;sim.threads=96;sim.order=order;sim.warp_sched=warp_order; |
| 26 | sim.smem=smem;sim.smem_bytes=variant==1?omega_fp8_gemv_shared_bytes(&spec):omega_fp8_gemv2_shared_bytes(&spec); |
| 27 | const uint64_t ptrs[]={(uintptr_t)table,(uintptr_t)input,(uintptr_t)output}; |
| 28 | const unsigned offsets[]={OMEGA_FP8_ARG_TAB,OMEGA_FP8_ARG_X,OMEGA_FP8_ARG_Y}; |
| 29 | for(unsigned i=0;i<3;i++){sim.cbank[offsets[i]/4]=(uint32_t)ptrs[i];sim.cbank[offsets[i]/4+1]=(uint32_t)(ptrs[i]>>32);} |
| 30 | sim.cbank[OMEGA_FP8_ARG_RG/4]=7;sim.cbank[OMEGA_FP8_ARG_STRIDE/4]=3; |
| 31 | sim.nranges=5; |
| 32 | const uintptr_t starts[]={(uintptr_t)table,(uintptr_t)weights,(uintptr_t)scales,(uintptr_t)input,(uintptr_t)output}; |
| 33 | const size_t sizes[]={sizeof table,sizeof weights,sizeof scales,sizeof input,sizeof output}; |
| 34 | for(unsigned i=0;i<5;i++){sim.ranges[i].lo=starts[i];sim.ranges[i].hi=starts[i]+sizes[i];} |
| 35 | if(ws_run(&sim,1,1)){fprintf(stderr,"MOE%u sim: %s\n",variant,sim.msg);return 0;} |
| 36 | for(unsigned i=0;i<7;i++)if((output[i]==512.0f)!=(mutant==0)){fprintf(stderr,"MOE%u mutant %d row %u observed %g expected %s512\n",variant,mutant,i,output[i],mutant?"not ":"");return 0;} |
| 37 | return 1; |
| 38 | } |
| 39 | int main(void){ |
| 40 | const unsigned orders[]={0,1,2654435769u}; |
| 41 | for(unsigned v=1;v<=2;v++)for(int order=0;order<2;order++)for(unsigned w=0;w<3;w++)if(!run(v,0,order,orders[w])||!run(v,1,order,orders[w]))return 1; |
| 42 | puts("CODEGEN MOE WARP SIM PASS (both builders, fragment/warp orders, scale-drop negative controls)");return 0; |
| 43 | } |