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_tc_host_diff.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_blackwell_codegen_tc.h" |
| 3 | #include "omega_blackwell_codegen_tc2.h" |
| 4 | #include "cudapp_native.h" |
| 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | #include <limits.h> |
| 9 | int oracle_omega_tcgemm_spec_ok(const OmegaTcGemmSpec *); |
| 10 | uint32_t oracle_omega_tcgemm_shared_bytes(const OmegaTcGemmSpec *); |
| 11 | uint32_t oracle_omega_tcgemm_span(const OmegaTcGemmSpec *); |
| 12 | void oracle_omega_tcgemm_permute_x(const float *,uint32_t,uint16_t *); |
| 13 | uint16_t oracle_omega_tcgemm_w_bf16(uint8_t); |
| 14 | int oracle_omega_tc2_spec_ok(const OmegaTc2Spec *); |
| 15 | uint32_t oracle_omega_tc2_shared_bytes(const OmegaTc2Spec *); |
| 16 | uint32_t oracle_omega_tc2_span(const OmegaTc2Spec *); |
| 17 | static unsigned cases; |
| 18 | static int red; |
| 19 | static int same(uint64_t a,uint64_t b) { cases++; return (a ^ (red && cases==1))==b; } |
| 20 | static int tc(OmegaTcGemmSpec s) { |
| 21 | uint64_t v[16]={s.k,s.rt,s.ct,s.warps,(uint32_t)s.mutant},r; |
| 22 | uint64_t want[3]={oracle_omega_tcgemm_spec_ok(&s),oracle_omega_tcgemm_shared_bytes(&s),oracle_omega_tcgemm_span(&s)}; |
| 23 | uint64_t got[3]={omega_tcgemm_spec_ok(&s),omega_tcgemm_shared_bytes(&s),omega_tcgemm_span(&s)}; |
| 24 | for(unsigned j=0;j<3;j++) if(omega_tc_host(&r,j,v,16)||!same(r,want[j])||got[j]!=want[j]) return 0; |
| 25 | return 1; |
| 26 | } |
| 27 | static int tc2(OmegaTc2Spec s) { |
| 28 | uint64_t v[16]={s.k,s.rt,s.ct,s.warps,(uint32_t)s.mutant,s.n,s.aqn,s.epi,s.direct},r; |
| 29 | uint64_t want[3]={oracle_omega_tc2_spec_ok(&s),oracle_omega_tc2_shared_bytes(&s),oracle_omega_tc2_span(&s)}; |
| 30 | uint64_t got[3]={omega_tc2_spec_ok(&s),omega_tc2_shared_bytes(&s),omega_tc2_span(&s)}; |
| 31 | for(unsigned j=0;j<3;j++) if(omega_tc_host(&r,j+3,v,16)||!same(r,want[j])||got[j]!=want[j]) return 0; |
| 32 | return 1; |
| 33 | } |
| 34 | static int nan16(uint16_t x) { return (x&0x7fff)>0x7f80; } |
| 35 | static int conv(uint32_t u,uint32_t k) { |
| 36 | uint32_t raw[8]={u,u^0x80000000u,u+1,u-1,u,u,u,u}; float x[8]; uint16_t a[8],b[8]; |
| 37 | memcpy(x,raw,sizeof x); memset(a,0xa5,sizeof a);memset(b,0xa5,sizeof b); |
| 38 | omega_tcgemm_permute_x(x,k,a);oracle_omega_tcgemm_permute_x(x,k,b); |
| 39 | for(unsigned j=0;j<8;j++) if(!same(nan16(a[j])?0x7fff:a[j],nan16(b[j])?0x7fff:b[j])) return 0; |
| 40 | return 1; |
| 41 | } |
| 42 | int main(int argc,char **argv) { |
| 43 | (void)argv; red=argc>1; |
| 44 | const uint32_t edge[]={0,1,2,3,4,5,7,8,9,15,16,17,31,32,33,63,64,65,127,128,129,255,256,257,4095,4096,4097,16383,16384,16385,32767,32768,32769,UINT32_MAX}; |
| 45 | if(omega_tcgemm_spec_ok(NULL)||omega_tcgemm_shared_bytes(NULL)||omega_tcgemm_span(NULL)||omega_tc2_spec_ok(NULL)||omega_tc2_shared_bytes(NULL)||omega_tc2_span(NULL)) return 1; |
| 46 | for(uint32_t k=128;k<=32768;k+=128) for(uint32_t rt=1;rt<=8;rt*=2) for(uint32_t ct=1;ct<=4;ct*=2) for(uint32_t w=1;w<=16;w*=2) for(int m=-1;m<=5;m++) { |
| 47 | OmegaTcGemmSpec s={.k=k,.rt=rt,.ct=ct,.warps=w,.mutant=m}; if(!tc(s)) goto fail; |
| 48 | } |
| 49 | for(uint32_t k=128;k<=16384;k+=128) for(uint32_t rt=2;rt<=8;rt*=2) for(uint32_t w=4;w<=16;w*=2) for(uint32_t aq=1;aq<=2;aq++) for(uint32_t ep=0;ep<=1;ep++) for(uint32_t dr=0;dr<=1;dr++) for(int m=0;m<=4;m++) { |
| 50 | OmegaTc2Spec s={.k=k,.rt=rt,.ct=2,.warps=w,.mutant=m,.n=w*16,.aqn=aq,.epi=ep,.direct=dr}; if(!tc2(s)) goto fail; |
| 51 | } |
| 52 | for(unsigned f=0;f<9;f++) for(unsigned i=0;i<sizeof edge/sizeof *edge;i++) { |
| 53 | uint32_t v[9]={128,2,2,4,0,64,1,0,0};v[f]=edge[i]; |
| 54 | OmegaTcGemmSpec s={.k=v[0],.rt=v[1],.ct=v[2],.warps=v[3],.mutant=(int)v[4]};if(!tc(s))goto fail; |
| 55 | OmegaTc2Spec t={.k=v[0],.rt=v[1],.ct=v[2],.warps=v[3],.mutant=(int)v[4],.n=v[5],.aqn=v[6],.epi=v[7],.direct=v[8]};if(!tc2(t))goto fail; |
| 56 | } |
| 57 | /* Every strict output-size boundary, including adjacent and alignment values. */ |
| 58 | for(uint32_t rt=2;rt<=8;rt*=2) for(uint32_t w=4;w<=16;w*=2) { |
| 59 | uint32_t lim=(1u<<23)/(64*rt); const uint32_t ns[]={lim-1,lim,lim+1,(lim/(16*w))*(16*w),(lim/(16*w)-1)*(16*w)}; |
| 60 | for(unsigned j=0;j<sizeof ns/sizeof *ns;j++) { OmegaTc2Spec t={.k=128,.rt=rt,.ct=2,.warps=w,.n=ns[j],.aqn=1};if(!tc2(t))goto fail; } |
| 61 | } |
| 62 | for(unsigned i=0;i<256;i++) { uint64_t v[16]={i},r; if(omega_tc_host(&r,7,v,16)||!same(r,oracle_omega_tcgemm_w_bf16(i))||r!=omega_tcgemm_w_bf16(i))goto fail; } |
| 63 | const uint32_t fp[]={0,0x80000000,1,0x007fffff,0x00800000,0x3f800000,0x5f000000,0x5f7fffff,0x7f7fffff,0x7f800000,0xff800000,0x7f800001,0x7fc12345,0xffc12345}; |
| 64 | for(unsigned i=0;i<sizeof fp/sizeof *fp;i++)for(unsigned k=0;k<=8;k++)if(!conv(fp[i],k))goto fail; |
| 65 | for(uint32_t u=0,i=0;i<65536;i++,u+=65537)if(!conv(u,8))goto fail; |
| 66 | printf("TC-HOST-DIFF PASS cases=%u\n",cases);return 0; |
| 67 | fail: fprintf(stderr,"TC-HOST-DIFF FAIL case=%u\n",cases);return 1; |
| 68 | } |