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/codegen_dec_diff.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 / codegen_dec_diff.c` 64 lines · 4145 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* Differential: retained C DEC builder (oracle) against the Omega unit cg_dec through the checked replay. 3 * Domain: every kind (plus out-of-enum values) crossed with boundary sets taken from each refusal predicate 4 * (v-1/v/v+1) and 0/UINT32_MAX on every u32 field. Accepted programs compare IR records, the register 5 * allocation and the encoded bytes; refusals must agree; each accepted case runs a flipped-record control. */ 6 #include "omega_blackwell_codegen_dec.h" 7 #include "omega_gpu_om_ir.h" 8 #include "cudapp_native.h" 9 #include 10 #include 11 #include 12 int omega_codegen_dec_oracle(const OmegaDecSpec *, BlackwellIRProgram *); 13 static BlackwellIRProgram c, o; 14 static unsigned char cb[BW_MAX_IR_INSNS * 16], ob[BW_MAX_IR_INSNS * 16]; 15 static int same(int verbose) { 16 if (c.count != o.count) { if (verbose) printf("count mismatch c=%zu om=%zu\n", c.count, o.count); return 0; } 17 for (size_t i = 0; i < c.count; ++i) if (memcmp(&c.insns[i], &o.insns[i], sizeof c.insns[i])) { 18 const unsigned char *a = (const unsigned char *)&c.insns[i], *b = (const unsigned char *)&o.insns[i]; 19 for (size_t j = 0; j < sizeof c.insns[i]; ++j) if (a[j] != b[j]) { 20 if (verbose) printf("IR mismatch record=%zu op=%d byte=%zu c=%u om=%u\n", i, (int)c.insns[i].op, j, a[j], b[j]); 21 break; 22 } 23 return 0; 24 } 25 if (memcmp(&c.regalloc, &o.regalloc, sizeof c.regalloc)) { if (verbose) puts("allocation mismatch"); return 0; } 26 OmegaBlackwellKernel ck, ok; 27 if (omega_blackwell_kernel_encode_into(&c, cb, sizeof cb, &ck) || 28 omega_blackwell_kernel_encode_into(&o, ob, sizeof ob, &ok)) { if (verbose) puts("encode failed"); return 0; } 29 return ck.code_size == ok.code_size && memcmp(cb, ob, ck.code_size) == 0; 30 } 31 int main(void) { 32 static const int kinds[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, INT_MAX}; 33 static const uint32_t modes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, UINT32_MAX}; 34 static const uint32_t widths[] = {0, 1, 255, 256, 257, 767, 768, 769, 1023, 1024, 1025, 2048, 3072, 4096, 35 5120, 6144, 7168, 8192, 8193, 9216, UINT32_MAX}; 36 static const uint32_t groups[] = {0, 1, 7, 8, 9, 10, 15, 16, 17, UINT32_MAX}; 37 static const uint32_t strides[] = {0, 1, 15, 16, 17, 128, 255, 256, 257, 512, UINT32_MAX}; 38 static const int mutants[] = {INT_MIN, -1, 0, 1, 2, 3, 4, INT_MAX}; 39 #define N(a) (sizeof a / sizeof a[0]) 40 unsigned long cases = 0, accepted = 0, changed = 0; 41 for (unsigned k = 0; k < N(kinds); ++k) for (unsigned md = 0; md < N(modes); ++md) 42 for (unsigned w = 0; w < N(widths); ++w) for (unsigned g = 0; g < N(groups); ++g) 43 for (unsigned st = 0; st < N(strides); ++st) for (unsigned mu = 0; mu < N(mutants); ++mu) { 44 OmegaDecSpec s; 45 memset(&s, 0, sizeof s); 46 s.kind = (OmegaDecKind)kinds[k]; s.mode = modes[md]; s.width = widths[w]; s.groups = groups[g]; 47 s.stride = strides[st]; s.mutant = mutants[mu]; 48 int cr = omega_codegen_dec_oracle(&s, &c), rc = omega_blackwell_codegen_dec_prog(&s, &o); 49 ++cases; 50 if ((cr == 0) != (rc == 0) || (!cr && !same(1))) { 51 printf("FAIL kind=%d mode=%u width=%u groups=%u stride=%u mutant=%d c=%d om=%d records=%zu/%zu\n", 52 kinds[k], s.mode, s.width, s.groups, s.stride, s.mutant, cr, rc, c.count, o.count); 53 return 1; 54 } 55 if (!cr) { ++accepted; o.insns[0].imm ^= 1; if (same(0)) return 2; ++changed; } 56 } 57 if (omega_blackwell_codegen_dec_prog(NULL, &o) != -1) return 3; 58 OmegaDecSpec ds; memset(&ds, 0, sizeof ds); ds.kind = OMEGA_DEC_GATE; 59 if (omega_blackwell_codegen_dec_prog(&ds, NULL) != -1) return 3; 60 printf("PASS dec differential cases=%lu accepted=%lu record-negative-controls=%lu IR+allocation+encoded-bytes\n", 61 cases, accepted, changed); 62 /* frozen: the accepted partition of the product above; a builder that widens or narrows admission changes it */ 63 return changed == accepted && accepted == 1220470ul ? 0 : 6; 64 }