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 / staged-oracle.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Verification only. The existing independent C generator/allocator/encoder |
| 3 | * supplies every successful expected bit; this file has no GEMM algorithm. |
| 4 | * Protocol and suggested cases are in staged-caller.om. No GPU is opened. */ |
| 5 | #include "omega_blackwell_codegen_gemm.h" |
| 6 | #include <stdio.h> |
| 7 | #include <stdint.h> |
| 8 | #include <string.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <errno.h> |
| 11 | |
| 12 | static void word(uint64_t v) { |
| 13 | for (unsigned j=0;j<8;j++) putchar((int)((v>>(j*8))&255)); |
| 14 | } |
| 15 | static uint64_t reg(int v) { return v<0 ? UINT64_MAX : (uint64_t)v; } |
| 16 | static int power2(uint64_t v) { return v && !(v&(v-1)); } |
| 17 | /* The native bounded contract is checked independently, before narrowing. */ |
| 18 | static int supported(const uint64_t s[16]) { |
| 19 | if (!s[0] || s[0]>16384 || (s[1]!=8 && s[1]!=16)) return 0; |
| 20 | if (s[2]!=1 && s[2]!=2 && s[2]!=4 && s[2]!=8) return 0; |
| 21 | if (!power2(s[3]) || s[3]>32 || (s[2]*s[1])%s[3]) return 0; |
| 22 | if (s[2]*s[1]/s[3]>8 || s[2]*128*s[1]>16384) return 0; |
| 23 | if (s[0]%(32*s[1])) return 0; |
| 24 | const uint64_t ks=s[0]/(32*s[1]); |
| 25 | if ((ks&1) && ks>3) return 0; |
| 26 | if (s[4]>1 || (s[4] && s[2]>4)) return 0; |
| 27 | for (unsigned j=5;j<16;j++) if (s[j]) return 0; |
| 28 | return 1; |
| 29 | } |
| 30 | int main(int argc, char **argv) { |
| 31 | uint64_t s[16]={0}; |
| 32 | if (argc==1) { |
| 33 | unsigned char raw[128]; |
| 34 | if (fread(raw,1,sizeof raw,stdin)!=sizeof raw) return 65; |
| 35 | for (unsigned k=0;k<16;k++) |
| 36 | for (unsigned j=0;j<8;j++) s[k]|=(uint64_t)raw[k*8+j]<<(j*8); |
| 37 | } else if (argc==6) { |
| 38 | for (unsigned k=0;k<5;k++) { |
| 39 | char *tail=NULL; |
| 40 | if (argv[k+1][0]<'0' || argv[k+1][0]>'9') return 65; |
| 41 | errno=0; |
| 42 | s[k]=strtoull(argv[k+1],&tail,10); |
| 43 | if (errno || !tail || *tail) return 65; |
| 44 | } |
| 45 | } else return 65; |
| 46 | if (!supported(s)) { word(1); return ferror(stdout)?74:0; } |
| 47 | OmegaFp8GemmSpec spec={0}; |
| 48 | spec.k=(uint32_t)s[0]; spec.lane_bytes=(uint32_t)s[1]; |
| 49 | spec.mt=(uint32_t)s[2]; spec.warps=(uint32_t)s[3]; |
| 50 | spec.rowmap=(uint32_t)s[4]; |
| 51 | BlackwellIRProgram p; |
| 52 | memset(&p,0,sizeof p); |
| 53 | if (omega_blackwell_codegen_fp8gemm_prog(&spec,&p)!=0) return 66; |
| 54 | uint8_t code[16384]; size_t nbytes=0; |
| 55 | if (omega_bw_encode_program(&p,code,sizeof code,&nbytes)!=0) return 68; |
| 56 | word(0); word(p.count); word(p.regalloc.num_vregs); |
| 57 | word(p.regalloc.num_uvregs); word(omega_fp8gemm_shared_bytes(&spec)); |
| 58 | word(p.regalloc.peak_gpr_usage); word(p.regalloc.peak_ugpr_usage); |
| 59 | for (int v=0;v<p.regalloc.num_vregs;v++) { |
| 60 | const OmegaLiveInterval *q=&p.regalloc.intervals[v]; |
| 61 | word(q->bundle_size?q->bundle_size:(q->is_pair?2:(q->is_quad?4:1))); |
| 62 | word(reg(p.regalloc.vreg_to_phys[v])); |
| 63 | } |
| 64 | for (int v=0;v<p.regalloc.num_uvregs;v++) { |
| 65 | word(p.regalloc.uintervals[v].is_pair?2:1); |
| 66 | word(reg(p.regalloc.uvreg_to_phys[v])); |
| 67 | } |
| 68 | for (size_t k=0;k<p.count;k++) { |
| 69 | const BlackwellIRInsn *i=&p.insns[k]; |
| 70 | word(i->op); word(reg(i->dst_vreg)); word(reg(i->src1_vreg)); |
| 71 | word(reg(i->src2_vreg)); word(reg(i->src3_vreg)); word(reg(i->ureg)); |
| 72 | word((uint64_t)i->imm|((uint64_t)i->control<<32)); |
| 73 | word((uint64_t)i->is_uniform|((uint64_t)i->predicate_p0<<1)| |
| 74 | ((uint64_t)i->predicate_not<<2)|((uint64_t)i->bar_reg<<8)| |
| 75 | ((uint64_t)i->dst_subreg<<16)|((uint64_t)i->src1_subreg<<24)| |
| 76 | ((uint64_t)i->src2_subreg<<32)|((uint64_t)i->src3_subreg<<40)); |
| 77 | } |
| 78 | if (fwrite(code,1,nbytes,stdout)!=nbytes || ferror(stdout)) return 74; |
| 79 | return 0; |
| 80 | } |