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 / components / numerical.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Verification only: substitute native-produced IR at the existing test's |
| 3 | * generator seam. Reuse its unchanged simulator, data, packing and oracle. */ |
| 4 | #ifdef COMPONENT_STAGED |
| 5 | #define omega_blackwell_codegen_fp8gemm_prog component_native_staged |
| 6 | #define main component_original_staged_main |
| 7 | #include "../gpu_fp8gemm_test.c" |
| 8 | #undef main |
| 9 | #undef omega_blackwell_codegen_fp8gemm_prog |
| 10 | #else |
| 11 | #define omega_blackwell_codegen_fp8_gemv_prog component_native_direct |
| 12 | #define omega_blackwell_codegen_fp8_gemv2_prog component_native_rowpipe |
| 13 | #define main component_original_direct_main |
| 14 | #include "../gpu_fp8_api_test.c" |
| 15 | #undef main |
| 16 | #undef omega_blackwell_codegen_fp8_gemv_prog |
| 17 | #undef omega_blackwell_codegen_fp8_gemv2_prog |
| 18 | #endif |
| 19 | #include "native-frame.h" |
| 20 | static uint32_t shape[5]; |
| 21 | #ifdef COMPONENT_STAGED |
| 22 | int component_native_staged(const OmegaFp8GemmSpec *s,BlackwellIRProgram *p) { |
| 23 | if(s->k!=shape[0]||s->lane_bytes!=shape[1]||s->mt!=shape[2]||s->warps!=shape[3]||s->rowmap!=shape[4]||s->mutant) return -1; |
| 24 | *p=native_program;return 0; |
| 25 | } |
| 26 | #else |
| 27 | static int component_native_gemv(const OmegaFp8GemvSpec *s,BlackwellIRProgram *p) { |
| 28 | if(s->k!=shape[0]||s->lane_bytes!=shape[1]||s->rows!=shape[2]||s->warps!=shape[3]||s->wfirst!=shape[4]||s->mutant||s->coal||s->depth||s->sched) return -1; |
| 29 | *p=native_program;return 0; |
| 30 | } |
| 31 | int component_native_direct(const OmegaFp8GemvSpec *s,BlackwellIRProgram *p) {return component_native_gemv(s,p);} |
| 32 | int component_native_rowpipe(const OmegaFp8GemvSpec *s,BlackwellIRProgram *p) {return component_native_gemv(s,p);} |
| 33 | #endif |
| 34 | int main(int argc,char **argv) { |
| 35 | /* frame K LB rows/MT warps wfirst/rowmap family */ |
| 36 | if(argc!=8) return 65; |
| 37 | for(unsigned j=0;j<5;j++) shape[j]=(uint32_t)strtoul(argv[j+2],NULL,10); |
| 38 | char msg[512];size_t bad=0;int rc; |
| 39 | #ifdef COMPONENT_STAGED |
| 40 | if(!frame_load(argv[1],1)) return 66; |
| 41 | SimPt point={shape[0],40,shape[1],shape[2],shape[3],2,{1,5,9},3}; |
| 42 | int moved=0; |
| 43 | rc=sim_point2(&point,0,41,(int)shape[4],1,0,msg,sizeof msg,&bad,&moved); |
| 44 | if(rc||bad||(shape[4]&&!moved)) {fprintf(stderr,"native staged numerical: rc%d bad%zu: %s\n",rc,bad,msg);return 1;} |
| 45 | printf("native staged both fragment orders, empty segment, tail rows, multi-segment%s: %s\n",shape[4]?", YMAP movement":"",msg); |
| 46 | if(!frame_wrong_result()) return 67; |
| 47 | bad=0;rc=sim_point2(&point,0,41,(int)shape[4],1,0,msg,sizeof msg,&bad,&moved); |
| 48 | if(rc||!bad) {fprintf(stderr,"FFMA->FADD wrong-result mutant not numerically caught: %s\n",msg);return 2;} |
| 49 | printf("wrong-result mutant: %s\n",msg); |
| 50 | native_program.insns[0].op=(BlackwellIROpcode)0x7fffffff; |
| 51 | rc=sim_point2(&point,0,41,(int)shape[4],1,0,msg,sizeof msg,&bad,&moved); |
| 52 | #else |
| 53 | if(!frame_load(argv[1],0)) return 66; |
| 54 | g_sim_variant=atoi(argv[7]); |
| 55 | if(g_sim_variant!=1&&g_sim_variant!=2) return 65; |
| 56 | Weights weights;weights_make(&weights,3,128,shape[0],41); |
| 57 | uint32_t ids[3]={2,0,1},seed=42; |
| 58 | size_t words=(size_t)3*shape[0];float *x=malloc(words*4),*y=malloc(3*128*4); |
| 59 | if(!x||!y) return 68; |
| 60 | for(size_t j=0;j<words;j++) x[j]=frand(&seed,-2.0f,2.0f); |
| 61 | OmegaFp8GemvSpec spec={0};spec.k=shape[0];spec.lane_bytes=shape[1];spec.rows=shape[2];spec.warps=shape[3];spec.wfirst=shape[4]; |
| 62 | rc=sim_gemv(&spec,&weights,3,ids,x,3,y,2,0,msg,sizeof msg); |
| 63 | double worst=rc?1.0:parity(&weights,3,ids,x,3,y,&bad); |
| 64 | if(rc||bad) {fprintf(stderr,"native gemv numerical: rc%d bad%zu worst%.9g: %s\n",rc,bad,worst,msg);return 1;} |
| 65 | printf("native grouped gemv both fragment orders, distinct experts/X rows, double-oracle bad%zu worst%.9g\n",bad,worst); |
| 66 | if(!frame_wrong_result()) return 67; |
| 67 | bad=0;rc=sim_gemv(&spec,&weights,3,ids,x,3,y,2,0,msg,sizeof msg); |
| 68 | if(!rc) (void)parity(&weights,3,ids,x,3,y,&bad); |
| 69 | if(rc||!bad) {fprintf(stderr,"FFMA->FADD wrong-result mutant not numerically caught: %s\n",msg);return 2;} |
| 70 | printf("wrong-result mutant: double-oracle bad%zu\n",bad); |
| 71 | native_program.insns[0].op=(BlackwellIROpcode)0x7fffffff; |
| 72 | rc=sim_gemv(&spec,&weights,3,ids,x,3,y,2,0,msg,sizeof msg); |
| 73 | weights_free(&weights);free(x);free(y); |
| 74 | #endif |
| 75 | if(!rc||!strstr(msg,"opcode not modelled")) {fprintf(stderr,"unknown-op refusal lost: rc%d %s\n",rc,msg);return 3;} |
| 76 | printf("unknown-op mutant refused: %s\n",msg); |
| 77 | return 0; |
| 78 | } |