Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/components/rowpipe-oracle.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / components / rowpipe-oracle.c` 119 lines · 5707 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* Verification ONLY. Uses the existing `b759afc3` rowpipe C generator, its allocator, 3 * and independently retained C encoder. This is not a production implementation. 4 * Build after all component edits, no GPU: 5 * cc -std=c11 -Wall -Wextra -Werror -DOMEGA_GPU_NO_POSIX -ffunction-sections 6 * -fdata-sections -Wl,--gc-sections -Isrc tests/components/rowpipe-oracle.c 7 * src/omega_blackwell_codegen_moe2.c src/omega_blackwell_codegen.c -o ORACLE 8 * Input: no arguments reads exactly eight LE64 spec words on stdin. Alternatively 9 * ORACLE K LB ROWS WARPS accepts the production spec. Optional final argument 10 * --sb-b / --sb-rd / --branch corrupts independent reference IR for negative cmp. 11 * Native caller and oracle stdout must compare byte for byte, including widths, 12 * allocation, every IR field, and every unpadded encoded instruction. Exit66 13 * is refusal; run mutants1..3 and each reserved field nonzero against native 14 * caller and require66 (caller also verifies all refusal outputs were cleared). 15 * Cover K256 LB8 R1 W1, K768 LB8 R1 W5(partial staging), 16 * K512 LB16 R8 W16, K4096 LB16 R1 W32, and R1/2/4/8 and LB8/16. 17 * K4096 LB8 R1 W16 is a resource-refusal control: generator shape admission 18 * precedes global allocation; native caller returns67 while this combined C 19 * generator/allocator returns66. Neither may emit any output for that control. 20 * Each --sb-b/--sb-rd/--branch output must FAIL cmp against the original caller. 21 * No result from these host checks is device qualification. 22 */ 23 #include "omega_blackwell_codegen_moe2.h" 24 #include 25 #include 26 #include 27 #include 28 29 static int word(uint64_t v) { 30 for (unsigned j = 0; j < 8; ++j) 31 if (putchar((int)((v >> (j * 8)) & 255)) == EOF) return 0; 32 return 1; 33 } 34 static uint64_t regword(int v) { return v < 0 ? UINT64_MAX : (uint64_t)v; } 35 static int number(const char *s, uint64_t *v) { 36 char *end; 37 if (!s[0] || s[0] == '-') return 0; 38 errno = 0; 39 unsigned long long n = strtoull(s, &end, 10); 40 if (errno || *end) return 0; 41 *v = (uint64_t)n; 42 return 1; 43 } 44 static int input(uint64_t spec[8]) { 45 unsigned char b[64]; 46 if (fread(b, 1, sizeof b, stdin) != sizeof b || getchar() != EOF) return 0; 47 for (unsigned j = 0; j < 8; ++j) 48 for (unsigned k = 0; k < 8; ++k) 49 spec[j] |= (uint64_t)b[j * 8 + k] << (k * 8); 50 return !ferror(stdin); 51 } 52 static int mutate(BlackwellIRProgram *p, const char *kind) { 53 if (!kind) return 1; 54 for (size_t j = 0; j < p->count; ++j) { 55 BlackwellIRInsn *i = &p->insns[j]; 56 if (!strcmp(kind, "--sb-b") && ((i->control >> 20) & (1u << 3))) { 57 i->control ^= (1u << 3) << 20; 58 return 1; 59 } 60 if (!strcmp(kind, "--sb-rd") && ((i->control >> 14) & 7) == 3) { 61 i->control = (i->control & ~(7u << 17)) | (7u << 17); 62 return 1; 63 } 64 if (!strcmp(kind, "--branch") && i->op == BW_IR_BRA && i->predicate_p0) { 65 ++i->imm; 66 return 1; 67 } 68 } 69 return 0; 70 } 71 int main(int argc, char **argv) { 72 uint64_t spec[8] = {0}; 73 const char *mutation = NULL; 74 if (argc == 1 || argc == 2) { 75 if (!input(spec)) return 65; 76 if (argc == 2) mutation = argv[1]; 77 } else if (argc == 5 || argc == 6) { 78 for (unsigned j = 0; j < 4; ++j) 79 if (!number(argv[j + 1], &spec[j])) return 65; 80 if (argc == 6) mutation = argv[5]; 81 } else return 65; 82 for (unsigned j = 0; j < 4; ++j) if (spec[j] > UINT32_MAX) return 66; 83 for (unsigned j = 4; j < 8; ++j) if (spec[j]) return 66; 84 OmegaFp8GemvSpec s = {0}; 85 s.k = (uint32_t)spec[0]; s.lane_bytes = (uint32_t)spec[1]; 86 s.rows = (uint32_t)spec[2]; s.warps = (uint32_t)spec[3]; 87 static BlackwellIRProgram p; 88 if (omega_blackwell_codegen_fp8_gemv2_prog(&s, &p) != 0) return 66; 89 if (!mutate(&p, mutation)) return 70; 90 unsigned char code[16384]; 91 size_t padded = 0; 92 if (omega_bw_encode_program(&p, code, sizeof code, &padded) != 0) return 68; 93 size_t used = p.count * 16; 94 if (padded < used) return 68; 95 if (!word(p.count) || !word((uint64_t)p.regalloc.num_vregs) || 96 !word((uint64_t)p.regalloc.num_uvregs) || !word(omega_fp8_gemv2_shared_bytes(&s)) || 97 !word(p.regalloc.peak_gpr_usage) || !word(p.regalloc.peak_ugpr_usage)) return 74; 98 for (int v = 0; v < p.regalloc.num_vregs; ++v) { 99 const OmegaLiveInterval *q = &p.regalloc.intervals[v]; 100 if (!word(q->bundle_size ? q->bundle_size : (q->is_pair ? 2 : (q->is_quad ? 4 : 1))) || 101 !word(regword(p.regalloc.vreg_to_phys[v]))) return 74; 102 } 103 for (int v = 0; v < p.regalloc.num_uvregs; ++v) 104 if (!word(p.regalloc.uintervals[v].is_pair ? 2 : 1) || 105 !word(regword(p.regalloc.uvreg_to_phys[v]))) return 74; 106 for (size_t j = 0; j < p.count; ++j) { 107 const BlackwellIRInsn *i = &p.insns[j]; 108 uint64_t f = (uint64_t)i->is_uniform | ((uint64_t)i->predicate_p0 << 1) | 109 ((uint64_t)i->predicate_not << 2) | ((uint64_t)i->bar_reg << 8) | 110 ((uint64_t)i->dst_subreg << 16) | ((uint64_t)i->src1_subreg << 24) | 111 ((uint64_t)i->src2_subreg << 32) | ((uint64_t)i->src3_subreg << 40); 112 if (!word(i->op) || !word(regword(i->dst_vreg)) || !word(regword(i->src1_vreg)) || 113 !word(regword(i->src2_vreg)) || !word(regword(i->src3_vreg)) || 114 !word(regword(i->ureg)) || !word((uint64_t)i->imm | ((uint64_t)i->control << 32)) || 115 !word(f)) return 74; 116 } 117 if (fwrite(code, 1, used, stdout) != used || fflush(stdout) != 0) return 74; 118 return 0; 119 }