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
GitHub aien-dev/omega-mv#197 (code only)
Apply it
git checkout -b patch-974f0d30ce03f2b5 32ad8a51cea78182ef64dc05a2065005cf92678d curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/974f0d30ce03f2b5.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
197
54be9ff66d0a16b63cc8e70edc27586f1b2f2fee
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":197,"url":"https://github.com/aien-dev/omega-mv/pull/197","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:44Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/Makefile b/Makefile index ac5036b68..f993dd402 100644 --- a/Makefile +++ b/Makefile @@ -1628,3 +1628,14 @@ build/test_omega_numeric_transc_gb10_cpu: $(TRANSC_GB10_SRCS) $(DIVSQRT_HDRS) sr gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -Isrc -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(TRANSC_GB10_SRCS) test-numeric-transc-gb10-host: build/test_omega_numeric_transc_gb10_cpu ./build/test_omega_numeric_transc_gb10_cpu + +# C3: host-only detector for the intermittent unwritten-output event, with its +# own unit test on synthetic buffers. The GB10 harness is +# tests/test_omega_unwritten_trap_gb10.c (chip: forge queue only, see +# tools/run_unwritten_trap.sh). +.PHONY: test-unwritten-trap-host +build/test_omega_unwritten_trap: tests/test_omega_unwritten_trap.c src/omega_unwritten_trap.c src/omega_unwritten_trap.h + @mkdir -p build + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -o $@ tests/test_omega_unwritten_trap.c src/omega_unwritten_trap.c +test-unwritten-trap-host: build/test_omega_unwritten_trap + ./build/test_omega_unwritten_trap diff --git a/src/omega_unwritten_trap.c b/src/omega_unwritten_trap.c new file mode 100644 index 000000000..3424dd552 --- /dev/null +++ b/src/omega_unwritten_trap.c @@ -0,0 +1,30 @@ +#include "omega_unwritten_trap.h" +#include <string.h> + +void omega_unwritten_scan(const uint32_t *out, size_t n, uint32_t poison, uint32_t block, + OmegaUnwrittenReport *r) { + memset(r, 0, sizeof(*r)); + if (!out || block == 0) return; + uint64_t run = 0; + for (size_t b = 0; b < n; b += block) { + size_t end = b + block < n ? b + block : n; + uint64_t hits = 0; + for (size_t i = b; i < end; i++) { + if (out[i] == poison) { + if (r->count == 0) r->first = i; + r->last = i; + r->count++; + hits++; + if (run == 0) r->runs++; + run++; + if (run > r->longest_run) r->longest_run = run; + } else { + run = 0; + } + } + if (hits == end - b) r->full_blocks++; + else if (hits) r->partial_blocks++; + } + r->whole_blocks = r->count > 0 && r->partial_blocks == 0; + r->tail = r->count > 0 && r->last == n - 1 && r->count == (uint64_t)n - r->first; +} diff --git a/src/omega_unwritten_trap.h b/src/omega_unwritten_trap.h new file mode 100644 index 000000000..0b75fc089 --- /dev/null +++ b/src/omega_unwritten_trap.h @@ -0,0 +1,34 @@ +/* + * C3 unwritten-output trap: host-only detector (no GPU, no libm). + * + * The caller pre-fills an output buffer with a poison word that the op under + * test cannot emit, runs the work, and calls omega_unwritten_scan. A word that + * still equals the poison was never stored (or its store was not visible). + * Whole-block means every aligned group of `block` words that contains a hit is + * entirely poison (the last group may be short), which is the signature of whole + * missing 64-thread CTAs rather than scattered lost stores. + */ +#ifndef OMEGA_UNWRITTEN_TRAP_H +#define OMEGA_UNWRITTEN_TRAP_H + +#include <stddef.h> +#include <stdint.h> + +#define OMEGA_UNWRITTEN_BLOCK 64u + +typedef struct { + uint64_t count; /* words equal to the poison */ + uint64_t first, last; /* index of first and last hit (valid if count>0) */ + uint64_t runs; /* maximal contiguous runs of hits */ + uint64_t longest_run; /* length of the longest run */ + uint64_t full_blocks; /* aligned blocks that are entirely poison */ + uint64_t partial_blocks; /* aligned blocks with some but not all poison */ + int whole_blocks; /* count>0 and partial_blocks==0 */ + int tail; /* count>0 and hits are exactly [first, n) */ +} OmegaUnwrittenReport; + +/* Scans out[0..n). block must be > 0 (use OMEGA_UNWRITTEN_BLOCK for CTAs). */ +void omega_unwritten_scan(const uint32_t *out, size_t n, uint32_t poison, uint32_t block, + OmegaUnwrittenReport *r); + +#endif diff --git a/tests/test_omega_unwritten_trap.c b/tests/test_omega_unwritten_trap.c new file mode 100644 index 000000000..168eba522 --- /dev/null +++ b/tests/test_omega_unwritten_trap.c @@ -0,0 +1,77 @@ +/* Host unit test of the C3 unwritten-output detector, on synthetic buffers. */ +#include "omega_unwritten_trap.h" +#include <stdio.h> +#include <stdlib.h> + +#define POISON 0x55555555u +static int pass, fail; +static void check(int ok, const char *id) { if (ok) pass++; else fail++; printf("[%s] %s\n", ok ? "PASS" : "FAIL", id); } + +static uint32_t *mk(size_t n) { + uint32_t *b = malloc(n * 4); + if (!b) exit(2); + for (size_t i = 0; i < n; i++) b[i] = (uint32_t)(0x3f800000u + i); /* never the poison */ + return b; +} +static void fillp(uint32_t *b, size_t lo, size_t hi) { for (size_t i = lo; i < hi; i++) b[i] = POISON; } + +int main(void) { + OmegaUnwrittenReport r; + const size_t N = 1000003; /* not a multiple of 64; last block has 3 words */ + uint32_t *b = mk(N); + + omega_unwritten_scan(b, N, POISON, 64, &r); + check(r.count == 0 && r.runs == 0 && !r.whole_blocks && !r.tail && r.full_blocks == 0 && r.partial_blocks == 0, "NO_POISON"); + + omega_unwritten_scan(b, 0, POISON, 64, &r); + check(r.count == 0, "EMPTY_BUFFER"); + + /* tail: last 100 words */ + fillp(b, N - 100, N); + omega_unwritten_scan(b, N, POISON, 64, &r); + check(r.count == 100 && r.first == N - 100 && r.last == N - 1 && r.runs == 1 && r.tail, "TAIL_COUNT_INDEX_RUN"); + check(!r.whole_blocks && r.partial_blocks == 1 && r.full_blocks == 2, "TAIL_STARTS_MID_BLOCK_IS_NOT_WHOLE"); + free(b); b = mk(N); + + /* tail that is exactly the short last block: whole */ + fillp(b, N - 3, N); + omega_unwritten_scan(b, N, POISON, 64, &r); + check(r.count == 3 && r.tail && r.whole_blocks && r.full_blocks == 1, "SHORT_LAST_BLOCK_IS_WHOLE"); + free(b); + + /* whole-block window in the middle: 1536 blocks = 98304 words (the C3 event shape) */ + size_t M = 64 * 262144 - 37; /* 16777179: grid-sized, not a multiple of 64 */ + size_t lo = 64 * 3000, hi = lo + 98304; + b = mk(M); + fillp(b, lo, hi); + omega_unwritten_scan(b, M, POISON, 64, &r); + check(r.count == 98304 && r.first == lo && r.last == hi - 1, "WINDOW_COUNT_FIRST_LAST"); + check(r.whole_blocks && r.full_blocks == 1536 && r.partial_blocks == 0 && r.runs == 1 && r.longest_run == 98304 && !r.tail, "WINDOW_IS_1536_WHOLE_BLOCKS"); + + /* two separate whole-block windows */ + fillp(b, 64 * 10, 64 * 12); + omega_unwritten_scan(b, M, POISON, 64, &r); + check(r.runs == 2 && r.full_blocks == 1538 && r.whole_blocks && r.first == 640, "TWO_WINDOWS"); + free(b); b = mk(N); + + /* shifted window (starts 1 word into a block): not whole blocks */ + fillp(b, 64 * 100 + 1, 64 * 102 + 1); + omega_unwritten_scan(b, N, POISON, 64, &r); + check(r.count == 128 && !r.whole_blocks && r.partial_blocks == 2 && r.full_blocks == 1, "SHIFTED_WINDOW_NOT_WHOLE"); + free(b); b = mk(N); + + /* scattered hits */ + size_t idx[] = { 5, 70, 71, 9000, 500000, N - 1 }; + for (size_t i = 0; i < sizeof(idx) / sizeof(idx[0]); i++) b[idx[i]] = POISON; + omega_unwritten_scan(b, N, POISON, 64, &r); + check(r.count == 6 && r.first == 5 && r.last == N - 1 && r.runs == 5 && r.longest_run == 2, "SCATTERED_COUNT_INDEX_RUNS"); + check(!r.whole_blocks && !r.tail && r.partial_blocks == 5 && r.full_blocks == 0, "SCATTERED_NOT_WHOLE_NOT_TAIL"); + + /* a different poison value is ignored */ + omega_unwritten_scan(b, N, 0xdeadbeefu, 64, &r); + check(r.count == 0, "OTHER_POISON_NOT_COUNTED"); + free(b); + + printf("SUMMARY passed=%d failed=%d\n", pass, fail); + return fail ? 1 : 0; +} diff --git a/tests/test_omega_unwritten_trap_gb10.c b/tests/test_omega_unwritten_trap_gb10.c new file mode 100644 index 000000000..381a59d18 --- /dev/null +++ b/tests/test_omega_unwritten_trap_gb10.c @@ -0,0 +1,187 @@ +/* + * C3b: GB10 stress harness for the intermittent "unwritten output" event + * (E1 gap table row 10, receipt 6ca4ee4e, omega d25d7ad). + * + * --chip [--repeats N] [--sizes a,b,c] [--ops SIGMOID,SQRT] + * Exit: 0 = clean (no unwritten output), 1 = hits or device error, 2 = refused / NOT_RUN. + * + * Reuses omega_ds_gb10_run (src/omega_numeric_divsqrt_gb10.c) unchanged: kernels + * and dispatch are not touched. That function allocates its own buffers, fills + * the device output with 0x55 (:1040 at 32ad8a5 is the memset), waits on the + * host marker and then the release semaphore, and copies out. So the poison seen + * here is 0x55555555, fixed by that path. To make it unambiguous, every input is + * drawn with an exponent below 0xD0 (|x| < 2^82): SIGMOID is in [0,1] or the + * canonical NaN, SQRT is below 2^41 or NaN, so neither can ever emit + * 0x55555555 (about 1.5e13). The host model is checked on every input first and + * the run refuses if any input could produce the poison. + * + * Device-side completion counter: NOT POSSIBLE without changing the kernels or + * the launch path. The kernel frame has no atomic add, the argument block is + * fixed (args[0..9] in omega_ds_gb10_run), and the semaphore and marker values + * are private to that function (never returned). So the receipt reports only the + * host-visible poison scan; the earlier diagnosis (C3-unwritten-output.md + * section 4 item 5) says a counter needs a diagnostic-only kernel. + * + * Output: one OMEGA_UNWRITTEN_HIT line per hit, then + * OMEGA_UNWRITTEN_TRAP: <hits>/<runs> + * Never run this directly: chip runs go through the forge queue and are never + * killed or timed out (tools/run_unwritten_trap.sh). + */ +#include "omega_numeric.h" +#include "omega_numeric_divsqrt_gb10.h" +#include "omega_unwritten_trap.h" + +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#define POISON 0x55555555u + +static uint64_t g_rng = 0x9e3779b97f4a7c15ull; +static uint64_t rnd(void) { + g_rng ^= g_rng << 13; g_rng ^= g_rng >> 7; g_rng ^= g_rng << 17; + return g_rng; +} + +/* Runs a shell command, joins its output into one line (newlines become " | "). */ +static void snap(const char *cmd, char *buf, size_t cap) { + buf[0] = '\0'; + FILE *f = popen(cmd, "r"); + if (!f) { snprintf(buf, cap, "popen failed"); return; } + size_t n = 0; + int c; + while ((c = fgetc(f)) != EOF && n + 4 < cap) { + if (c == '\n') { if (n && buf[n - 1] != '|') { buf[n++] = ' '; buf[n++] = '|'; buf[n++] = ' '; } } + else if (c == '"') buf[n++] = '\''; + else buf[n++] = (char)c; + } + buf[n] = '\0'; + pclose(f); + if (n == 0) snprintf(buf, cap, "(none)"); +} + +static void utc_now(char *buf, size_t cap) { + time_t t = time(NULL); + struct tm tm; + gmtime_r(&t, &tm); + strftime(buf, cap, "%Y-%m-%dT%H:%M:%SZ", &tm); +} + +static int parse_sizes(const char *s, size_t *out, int max) { + int n = 0; + while (*s && n < max) { + char *e; + unsigned long v = strtoul(s, &e, 10); + if (e == s || v == 0 || v > OMEGA_DS_MAX_BATCH) return -1; + out[n++] = v; + s = *e == ',' ? e + 1 : e; + if (*e && *e != ',') return -1; + } + return n; +} + +#ifdef OMEGA_NUMERIC_CPU_ONLY +int main(void) { + printf("OMEGA_UNWRITTEN_TRAP: NOT_RUN (CPU-only build)\n"); + return 2; +} +#else +int main(int argc, char **argv) { + setvbuf(stdout, NULL, _IOLBF, 0); + int chip = 0; + long repeats = 3000; + size_t sizes[8] = { 16777153u, 16777151u, 1000003u }; /* 2^24-63, 2^24-65, 1000003: none a multiple of 64 */ + int nsizes = 3; + OmegaDsOp ops[2] = { OMEGA_DS_SIGMOID, OMEGA_DS_SQRT }; + int nops = 2; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--chip")) chip = 1; + else if (!strcmp(argv[i], "--repeats") && i + 1 < argc) repeats = atol(argv[++i]); + else if (!strcmp(argv[i], "--sizes") && i + 1 < argc) { + nsizes = parse_sizes(argv[++i], sizes, 8); + if (nsizes <= 0) { printf("bad --sizes\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } + } else if (!strcmp(argv[i], "--ops") && i + 1 < argc) { + const char *s = argv[++i]; + nops = 0; + if (strstr(s, "SIGMOID")) ops[nops++] = OMEGA_DS_SIGMOID; + if (strstr(s, "SQRT")) ops[nops++] = OMEGA_DS_SQRT; + if (nops == 0) { printf("bad --ops (SIGMOID,SQRT)\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } + } else { printf("usage: --chip [--repeats N] [--sizes a,b,c] [--ops SIGMOID,SQRT]\n"); return 2; } + } + if (!chip || repeats <= 0) { printf("usage: --chip [--repeats N] [--sizes a,b,c] [--ops SIGMOID,SQRT]\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } + for (int i = 0; i < nsizes; i++) + if (sizes[i] % OMEGA_UNWRITTEN_BLOCK == 0) printf("note: size %zu is a multiple of 64\n", sizes[i]); + + size_t maxn = 0; + for (int i = 0; i < nsizes; i++) if (sizes[i] > maxn) maxn = sizes[i]; + uint32_t *ain[8] = { 0 }, *o = malloc(maxn * 4); + for (int i = 0; i < nsizes; i++) ain[i] = malloc(sizes[i] * 4); + int alloc_ok = o != NULL; + for (int i = 0; i < nsizes; i++) alloc_ok &= ain[i] != NULL; + if (!alloc_ok) { printf("out of memory\nOMEGA_UNWRITTEN_TRAP: NOT_RUN\n"); return 2; } + + time_t t0 = time(NULL); + char start_utc[40]; + utc_now(start_utc, sizeof(start_utc)); + printf("start=%s repeats_per_op=%ld ops=%d sizes=%d\n", start_utc, repeats, nops, nsizes); + + uint64_t hits = 0, runs = 0, dev_errs = 0; + for (int oi = 0; oi < nops; oi++) { + OmegaDsOp op = ops[oi]; + const char *on = omega_ds_op_name(op); + /* inputs per size, fresh per op; the host model must never equal the poison */ + for (int si = 0; si < nsizes; si++) + for (size_t k = 0; k < sizes[si]; k++) { + uint32_t r = (uint32_t)rnd(); + ain[si][k] = (r & 0x807fffffu) | (((r >> 23) % 0xD0u) << 23); + if (omega_ds_host_exec(op, ain[si][k], 0) == POISON) ain[si][k] = 0x3f800000u; + } + for (long rep = 0; rep < repeats; rep++) { + int si = (int)(rep % nsizes); + size_t n = sizes[si]; + uint32_t *a = ain[si]; + memset(o, 0xAB, n * 4); /* host copy; the device buffer is filled with 0x55 inside the run */ + struct timespec s0, s1; + clock_gettime(CLOCK_MONOTONIC, &s0); + int rc = omega_ds_gb10_run(op, a, NULL, o, n); + clock_gettime(CLOCK_MONOTONIC, &s1); + runs++; + if (rc != OMEGA_NUMERIC_OK) { + dev_errs++; + printf("OMEGA_UNWRITTEN_DEVERR op=%s run=%ld size=%zu rc=%d\n", on, rep, n, rc); + if (dev_errs >= 3) goto done; /* a jammed seat: stop, never loop on it */ + continue; + } + OmegaUnwrittenReport r; + omega_unwritten_scan(o, n, POISON, OMEGA_UNWRITTEN_BLOCK, &r); + if (r.count) { + hits++; + char now[40], smi[2048], procs[2048], klog[4096]; + char cmd[512]; + utc_now(now, sizeof(now)); + snap("nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>&1", smi, sizeof(smi)); + 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)); + snprintf(cmd, sizeof(cmd), + "(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", + (long long)t0); + snap(cmd, klog, sizeof(klog)); + printf("OMEGA_UNWRITTEN_HIT op=%s run=%ld size=%zu count=%" PRIu64 " first=%" PRIu64 " last=%" PRIu64 + " runs=%" PRIu64 " longest_run=%" PRIu64 " full_blocks=%" PRIu64 " partial_blocks=%" PRIu64 + " whole_blocks=%d tail=%d launch_ms=%ld at=%s nvidia_smi=\"%s\" procs=\"%s\" kernel_log=\"%s\"\n", + on, rep, n, r.count, r.first, r.last, r.runs, r.longest_run, r.full_blocks, r.partial_blocks, + r.whole_blocks, r.tail, + (long)((s1.tv_sec - s0.tv_sec) * 1000 + (s1.tv_nsec - s0.tv_nsec) / 1000000), now, smi, procs, klog); + } + if ((rep + 1) % 100 == 0) { printf(" %s %ld/%ld runs, hits so far %" PRIu64 "\n", on, rep + 1, repeats, hits); fflush(stdout); } + } + } +done: + printf("device_errors=%" PRIu64 "\n", dev_errs); + printf("OMEGA_UNWRITTEN_TRAP: %" PRIu64 "/%" PRIu64 "\n", hits, runs); + for (int i = 0; i < nsizes; i++) free(ain[i]); + free(o); + return (hits || dev_errs) ? 1 : 0; +} +#endif diff --git a/tools/run_unwritten_trap.sh b/tools/run_unwritten_trap.sh new file mode 100755 index 000000000..2d499b070 --- /dev/null +++ b/tools/run_unwritten_trap.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# C3b: build and run the GB10 unwritten-output trap. Forge queue only; the chip +# run is never killed and never timed out. No Python. +# tools/run_unwritten_trap.sh [harness args] (default: --chip --repeats 3000) +# Exit: 0 = clean (no unwritten output), 1 = hits or device error, 2 = refused / NOT_RUN. +set -u +HERE=$(cd "$(dirname "$0")/.." && pwd) +PHYSICS=${PHYSICS:-$HOME/workspace/physics} +refuse() { echo "REFUSED: $*"; echo "OMEGA_UNWRITTEN_TRAP: NOT_RUN"; exit 2; } +[ -d "$PHYSICS/nvrm" ] || refuse "no physics checkout at $PHYSICS" +PIN=$(tr -d '[:space:]' < "$HERE/physics.lock") +[ "$(git -C "$PHYSICS" rev-parse HEAD)" = "$PIN" ] || refuse "physics HEAD is not the physics.lock pin $PIN" +NV=$PHYSICS/third_party/nvidia-open-580.173.02 +BIN=$HERE/build/test_omega_unwritten_trap_gb10 +mkdir -p "$HERE/build" +(cd "$HERE" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread \ + -Isrc -I"$PHYSICS/nvrm" -I"$PHYSICS/m16" \ + -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \ + -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \ + -o "$BIN" tests/test_omega_unwritten_trap_gb10.c src/omega_unwritten_trap.c \ + src/omega_numeric_divsqrt_gb10.c src/omega_numeric_transc.c src/omega_numeric.c src/omega_numeric_provenance.c \ + src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c \ + src/sha256.c "$PHYSICS/nvrm/nvrm.c" "$PHYSICS/m16/m16_native.c") || refuse "chip build failed" +exec 9> /tmp/aien-gb10.lock || refuse "cannot open /tmp/aien-gb10.lock" +flock -x 9 || refuse "cannot take /tmp/aien-gb10.lock" +[ $# -gt 0 ] || set -- --chip --repeats 3000 +"$BIN" "$@" +RC=$? +exec 9>&- +exit $RC