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/omega-mv/blob/main/tests/test_omega_unwritten_trap_gb10.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_omega_unwritten_trap_gb10.c` 203 lines ยท 9437 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * C3b: GB10 stress harness for the intermittent "unwritten output" event 19 * (E1 gap table row 10, receipt `6ca4ee4e`, omega `d25d7ad`). 20 * 21 * --chip [--repeats N] [--sizes a,b,c] [--ops SIGMOID,SQRT] 22 * Exit: 0 = clean (no unwritten output), 1 = hits or device error, 2 = refused / NOT_RUN. 23 * 24 * Reuses omega_ds_gb10_run (src/omega_numeric_divsqrt_gb10.c) unchanged: kernels 25 * and dispatch are not touched. That function allocates its own buffers, fills 26 * the device output with 0x55 (:1040 at `32ad8a5` is the memset), waits on the 27 * host marker and then the release semaphore, and copies out. So the poison seen 28 * here is 0x55555555, fixed by that path. To make it unambiguous, every input is 29 * drawn with an exponent below 0xD0 (|x| < 2^82): SIGMOID is in [0,1] or the 30 * canonical NaN, SQRT is below 2^41 or NaN, so neither can ever emit 31 * 0x55555555 (about 1.5e13). The host model is checked on every input first and 32 * the run refuses if any input could produce the poison. 33 * 34 * Device-side completion counter: NOT POSSIBLE without changing the kernels or 35 * the launch path. The kernel frame has no atomic add, the argument block is 36 * fixed (args[0..9] in omega_ds_gb10_run), and the semaphore and marker values 37 * are private to that function (never returned). So the receipt reports only the 38 * host-visible poison scan; the earlier diagnosis (C3-unwritten-output.md 39 * section 4 item 5) says a counter needs a diagnostic-only kernel. 40 * 41 * Output: one OMEGA_UNWRITTEN_HIT line per hit, then 42 * OMEGA_UNWRITTEN_TRAP: / 43 * Never run this directly: chip runs go through the forge queue and are never 44 * killed or timed out (tools/run_unwritten_trap.sh). 45 */ 46 #include "omega_numeric.h" 47 #include "omega_numeric_divsqrt_gb10.h" 48 #include "omega_unwritten_trap.h" 49 50 #include 51 #include 52 #include 53 #include 54 #include 55 56 #define POISON 0x55555555u 57 58 static uint64_t g_rng = 0x9e3779b97f4a7c15ull; 59 static uint64_t rnd(void) { 60 g_rng ^= g_rng << 13; g_rng ^= g_rng >> 7; g_rng ^= g_rng << 17; 61 return g_rng; 62 } 63 64 /* Runs a shell command, joins its output into one line (newlines become " | "). */ 65 static void snap(const char *cmd, char *buf, size_t cap) { 66 buf[0] = '\0'; 67 FILE *f = popen(cmd, "r"); 68 if (!f) { snprintf(buf, cap, "popen failed"); return; } 69 size_t n = 0; 70 int c; 71 while ((c = fgetc(f)) != EOF && n + 4 < cap) { 72 if (c == '\n') { if (n && buf[n - 1] != '|') { buf[n++] = ' '; buf[n++] = '|'; buf[n++] = ' '; } } 73 else if (c == '"') buf[n++] = '\''; 74 else buf[n++] = (char)c; 75 } 76 buf[n] = '\0'; 77 pclose(f); 78 if (n == 0) snprintf(buf, cap, "(none)"); 79 } 80 81 static void utc_now(char *buf, size_t cap) { 82 time_t t = time(NULL); 83 struct tm tm; 84 gmtime_r(&t, &tm); 85 strftime(buf, cap, "%Y-%m-%dT%H:%M:%SZ", &tm); 86 } 87 88 static int parse_sizes(const char *s, size_t *out, int max) { 89 int n = 0; 90 while (*s && n < max) { 91 char *e; 92 unsigned long v = strtoul(s, &e, 10); 93 if (e == s || v == 0 || v > OMEGA_DS_MAX_BATCH) return -1; 94 out[n++] = v; 95 s = *e == ',' ? e + 1 : e; 96 if (*e && *e != ',') return -1; 97 } 98 return n; 99 } 100 101 #ifdef OMEGA_NUMERIC_CPU_ONLY 102 int main(void) { 103 printf("OMEGA_UNWRITTEN_TRAP: NOT_RUN (CPU-only build)\n"); 104 return 2; 105 } 106 #else 107 int main(int argc, char **argv) { 108 setvbuf(stdout, NULL, _IOLBF, 0); 109 int chip = 0; 110 long repeats = 3000; 111 size_t sizes[8] = { 16777153u, 16777151u, 1000003u }; /* 2^24-63, 2^24-65, `1000003`: none a multiple of 64 */ 112 int nsizes = 3; 113 OmegaDsOp ops[2] = { OMEGA_DS_SIGMOID, OMEGA_DS_SQRT }; 114 int nops = 2; 115 for (int i = 1; i < argc; i++) { 116 if (!strcmp(argv[i], "--chip")) chip = 1; 117 else if (!strcmp(argv[i], "--repeats") && i + 1 < argc) repeats = atol(argv[++i]); 118 else if (!strcmp(argv[i], "--sizes") && i + 1 < argc) { 119 nsizes = parse_sizes(argv[++i], sizes, 8); 120 if (nsizes <= 0) { printf("bad --sizes\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } 121 } else if (!strcmp(argv[i], "--ops") && i + 1 < argc) { 122 const char *s = argv[++i]; 123 nops = 0; 124 if (strstr(s, "SIGMOID")) ops[nops++] = OMEGA_DS_SIGMOID; 125 if (strstr(s, "SQRT")) ops[nops++] = OMEGA_DS_SQRT; 126 if (nops == 0) { printf("bad --ops (SIGMOID,SQRT)\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } 127 } else { printf("usage: --chip [--repeats N] [--sizes a,b,c] [--ops SIGMOID,SQRT]\n"); return 2; } 128 } 129 if (!chip || repeats <= 0) { printf("usage: --chip [--repeats N] [--sizes a,b,c] [--ops SIGMOID,SQRT]\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } 130 for (int i = 0; i < nsizes; i++) 131 if (sizes[i] % OMEGA_UNWRITTEN_BLOCK == 0) printf("note: size %zu is a multiple of 64\n", sizes[i]); 132 133 size_t maxn = 0; 134 for (int i = 0; i < nsizes; i++) if (sizes[i] > maxn) maxn = sizes[i]; 135 uint32_t *ain[8] = { 0 }, *o = malloc(maxn * 4); 136 for (int i = 0; i < nsizes; i++) ain[i] = malloc(sizes[i] * 4); 137 int alloc_ok = o != NULL; 138 for (int i = 0; i < nsizes; i++) alloc_ok &= ain[i] != NULL; 139 if (!alloc_ok) { printf("out of memory\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } 140 141 time_t t0 = time(NULL); 142 char start_utc[40]; 143 utc_now(start_utc, sizeof(start_utc)); 144 printf("start=%s repeats_per_op=%ld ops=%d sizes=%d\n", start_utc, repeats, nops, nsizes); 145 146 uint64_t hits = 0, runs = 0, dev_errs = 0; 147 for (int oi = 0; oi < nops; oi++) { 148 OmegaDsOp op = ops[oi]; 149 const char *on = omega_ds_op_name(op); 150 /* inputs per size, fresh per op; the host model must never equal the poison */ 151 for (int si = 0; si < nsizes; si++) 152 for (size_t k = 0; k < sizes[si]; k++) { 153 uint32_t r = (uint32_t)rnd(); 154 ain[si][k] = (r & 0x807fffffu) | (((r >> 23) % 0xD0u) << 23); 155 if (omega_ds_host_exec(op, ain[si][k], 0) == POISON) ain[si][k] = 0x3f800000u; 156 } 157 for (long rep = 0; rep < repeats; rep++) { 158 int si = (int)(rep % nsizes); 159 size_t n = sizes[si]; 160 uint32_t *a = ain[si]; 161 memset(o, 0xAB, n * 4); /* host copy; the device buffer is filled with 0x55 inside the run */ 162 struct timespec s0, s1; 163 clock_gettime(CLOCK_MONOTONIC, &s0); 164 int rc = omega_ds_gb10_run(op, a, NULL, o, n); 165 clock_gettime(CLOCK_MONOTONIC, &s1); 166 runs++; 167 if (rc != OMEGA_NUMERIC_OK) { 168 dev_errs++; 169 printf("OMEGA_UNWRITTEN_DEVERR op=%s run=%ld size=%zu rc=%d\n", on, rep, n, rc); 170 if (dev_errs >= 3) goto done; /* a jammed seat: stop, never loop on it */ 171 continue; 172 } 173 OmegaUnwrittenReport r; 174 omega_unwritten_scan(o, n, POISON, OMEGA_UNWRITTEN_BLOCK, &r); 175 if (r.count) { 176 hits++; 177 char now[40], smi[2048], procs[2048], klog[4096]; 178 char cmd[512]; 179 utc_now(now, sizeof(now)); 180 snap("nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>&1", smi, sizeof(smi)); 181 snap("ps -eo pid,etimes,pcpu,comm,args --sort=-pcpu 2>&1 | grep -E 'qemu|cargo|rustc|nvidia|test_omega|omega' | grep -v grep | head -n 20", procs, sizeof(procs)); 182 snprintf(cmd, sizeof(cmd), 183 "(journalctl -k --since @%lld --no-pager -q 2>&1; dmesg 2>&1) | grep -iE 'xid|nvrm|fault|not permitted|permission|no journal' | tail -n 20", 184 (long long)t0); 185 snap(cmd, klog, sizeof(klog)); 186 printf("OMEGA_UNWRITTEN_HIT op=%s run=%ld size=%zu count=%" PRIu64 " first=%" PRIu64 " last=%" PRIu64 187 " runs=%" PRIu64 " longest_run=%" PRIu64 " full_blocks=%" PRIu64 " partial_blocks=%" PRIu64 188 " whole_blocks=%d tail=%d launch_ms=%ld at=%s nvidia_smi=\"%s\" procs=\"%s\" kernel_log=\"%s\"\n", 189 on, rep, n, r.count, r.first, r.last, r.runs, r.longest_run, r.full_blocks, r.partial_blocks, 190 r.whole_blocks, r.tail, 191 (long)((s1.tv_sec - s0.tv_sec) * 1000 + (s1.tv_nsec - s0.tv_nsec) / `1000000`), now, smi, procs, klog); 192 } 193 if ((rep + 1) % 100 == 0) { printf(" %s %ld/%ld runs, hits so far %" PRIu64 "\n", on, rep + 1, repeats, hits); fflush(stdout); } 194 } 195 } 196 done: 197 printf("device_errors=%" PRIu64 "\n", dev_errs); 198 printf("OMEGA_UNWRITTEN_TRAP: %" PRIu64 "/%" PRIu64 "\n", hits, runs); 199 for (int i = 0; i < nsizes; i++) free(ain[i]); 200 free(o); 201 return (hits || dev_errs) ? 1 : 0; 202 } 203 #endif