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 / api_kgen_ew_diff_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Independent retained emitter oracle; never opens a device. The production |
| 3 | * source is included so its static legacy generator remains test-only. */ |
| 4 | #define CUDAPP_MIGRATION_PENDING_C_API_KGEN 1 |
| 5 | #define OMEGA_API_PLAN_ORACLE 1 |
| 6 | #include "../src/omega_gpu_elementwise_api.c" |
| 7 | #include "omega_cubin.h" |
| 8 | |
| 9 | static int cubin_same(const uint8_t *a, size_t na, const uint8_t *b, size_t nb) { |
| 10 | static const OmegaCubinParam params[] = { |
| 11 | {0x380,8,1},{0x388,8,1},{0x390,8,1}, |
| 12 | {0x398,4,0},{0x39c,4,0},{0x3a0,4,0},{0x3a4,4,0},{0x3a8,4,0} |
| 13 | }; |
| 14 | uint8_t *ca=NULL,*cb=NULL; size_t nca=0,ncb=0; char err[128]; |
| 15 | int ra=omega_cubin_pack("api_kgen",a,na,params,8,0x3ac,64,4096,&ca,&nca,err,sizeof err); |
| 16 | int rb=omega_cubin_pack("api_kgen",b,nb,params,8,0x3ac,64,4096,&cb,&ncb,err,sizeof err); |
| 17 | int same=ra==0 && rb==0 && nca==ncb && memcmp(ca,cb,nca)==0; |
| 18 | omega_cubin_free(ca);omega_cubin_free(cb);return same; |
| 19 | } |
| 20 | static int shape_partition(void) { |
| 21 | /* om/components/api_ew_plan.om: zero admission; even/128 divisibility; |
| 22 | * 1024-row and 131072-element clamps; 2048/16384 dimension caps; |
| 23 | * reconvergence lower/upper bound and the mutant 0..3 enum. */ |
| 24 | static const uint64_t ns[]={0,1,2,3,4,127,128,129,1023,1024,1025,131071,131072,131073, |
| 25 | 9223372036854775806ull,9223372036854775807ull,9223372036854775808ull,UINT64_MAX}; |
| 26 | static const uint64_t ds[]={0,1,2,3,127,128,129,2047,2048,2049,16383,16384,16385}; |
| 27 | unsigned admitted=0,refused=0; |
| 28 | for(unsigned mode=0;mode<=6;mode++)for(size_t n=0;n<sizeof ns/sizeof *ns;n++) |
| 29 | for(size_t d=0;d<sizeof ds/sizeof *ds;d++)for(uint64_t lo=0;lo<=4;lo++) { |
| 30 | uint64_t c[16]={ns[n],ds[d],lo,3},om[16]; |
| 31 | memcpy(om,c,sizeof c); |
| 32 | uint64_t cr=ap_c(AP_EW,mode,c); |
| 33 | int orc=ap_plan(AP_EW,mode,om); |
| 34 | if((cr==0)!=(orc==0) || (cr==0 && memcmp(c,om,sizeof c)!=0)) { |
| 35 | fprintf(stderr,"FAIL shape mode=%u n=%llu dim=%llu lo=%llu\n",mode, |
| 36 | (unsigned long long)ns[n],(unsigned long long)ds[d],(unsigned long long)lo); |
| 37 | return 1; |
| 38 | } |
| 39 | if(cr==0)admitted++;else refused++; |
| 40 | } |
| 41 | printf("PASS API EW source-derived boundary partition: admitted=%u refused=%u\n",admitted,refused); |
| 42 | return 0; |
| 43 | } |
| 44 | int main(void) { |
| 45 | BlackwellIRProgram *c=calloc(1,sizeof *c),*om=calloc(1,sizeof *om); |
| 46 | uint8_t *text=malloc(BW_MAX_IR_INSNS*16u); |
| 47 | unsigned accepted=0,refused=0; |
| 48 | if(!c||!om||!text)return 2; |
| 49 | if(shape_partition()!=0)return 1; |
| 50 | /* Shape is deliberately absent: EW IR depends only on op, mutant and |
| 51 | * test_path. n/dim/epsilon/sieve limits reside in launch constant memory. |
| 52 | * Exhaust the complete generator spec, not a sampling of runtime shapes. */ |
| 53 | for(int op=0;op<=OMEGA_GPU_EW_RC_REFUSE_JOIN_ONLY+1;op++) |
| 54 | for(int mut=0;mut<=3;mut++)for(int path=0;path<=1;path++) { |
| 55 | OmegaBlackwellKernel k={0};uint64_t err=0;size_t ntext=0; |
| 56 | memset(c,0,sizeof *c);memset(om,0,sizeof *om); |
| 57 | int cr=build_kernel((OmegaGpuEwOp)op,mut,&k,c,path); |
| 58 | int orc=omega_gpu_om_ir_replay(omega_ew_ir,op,mut,path,0,om,&err); |
| 59 | int ok=orc==0 && om->regalloc.peak_gpr_usage<=EW_GPR_BUDGET; |
| 60 | if((cr==0)!=ok){fprintf(stderr,"FAIL disposition op=%d mut=%d path=%d c=%d om=%d err=%llu peak=%u\n",op,mut,path,cr,orc,(unsigned long long)err,om->regalloc.peak_gpr_usage);return 1;} |
| 61 | if(cr!=0){refused++;continue;} |
| 62 | #ifdef CUDAPP_API_KGEN_RED |
| 63 | om->insns[0].imm^=1u; |
| 64 | #endif |
| 65 | if(c->count!=om->count || memcmp(c->insns,om->insns,c->count*sizeof c->insns[0])!=0){ |
| 66 | for(size_t i=0;i<c->count && i<om->count;i++)if(memcmp(&c->insns[i],&om->insns[i],sizeof c->insns[i])) { |
| 67 | fprintf(stderr,"FAIL IR op=%d mut=%d path=%d at=%zu c_op=%d om_op=%d c_ctl=%x om_ctl=%x c_imm=%x om_imm=%x\n",op,mut,path,i,c->insns[i].op,om->insns[i].op,c->insns[i].control,om->insns[i].control,c->insns[i].imm,om->insns[i].imm);break; |
| 68 | }return 1; |
| 69 | } |
| 70 | if(memcmp(&c->regalloc,&om->regalloc,sizeof c->regalloc)!=0){fprintf(stderr,"FAIL allocation op=%d mut=%d path=%d\n",op,mut,path);return 1;} |
| 71 | if(omega_bw_encode_program(om,text,BW_MAX_IR_INSNS*16u,&ntext)!=0 || ntext!=k.code_size || memcmp(text,k.code,ntext)!=0){fprintf(stderr,"FAIL text op=%d mut=%d path=%d\n",op,mut,path);return 1;} |
| 72 | if(!cubin_same(k.code,k.code_size,text,ntext)){fprintf(stderr,"FAIL cubin op=%d mut=%d path=%d\n",op,mut,path);return 1;} |
| 73 | accepted++;free(k.code); |
| 74 | } |
| 75 | printf("PASS API EW complete spec IR, allocation, text and cubin: accepted=%u refused=%u\n",accepted,refused); |
| 76 | free(text);free(om);free(c);return 0; |
| 77 | } |