From fec517402ab8d1c228ddec911aa0b1603186896d Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 12:57:12 -0500 Subject: [PATCH 1/5] M20 gb10: GB10 realization table + parity gate (NOT_RUN) - src/tensor/omega_tensor_gb10.c: GB10 table. Elementwise via E1 omega_gb10_execute_simt_op (explicit op map; unmapped ops refused with OMEGA_NUMERIC_ERR_NOT_ENCODED, no CPU fallback), reduce via omega_reduce_gb10 (OMEGA_REDUCE_GB10_MAX_N, declared-order strcmp), reduce_rows SUM batched through the E1 REDUCE_SUM warp kernel. - omega_tensor.h: optional reduce_rows table entry; GB10 table decls. - omega_tensor.c: matmul does a block of outputs per FMUL call and per row reduction (same bits; needed so the chip gate is a few hundred launches, not ~66k). No Tensor Core, no FFMA. - tests/test_omega_tensor_gb10.c: host self checks + --chip parity gate (CPU vs GB10 value ids) with in-process mutants WRONG_REDUCE_ORDER, FFMA_MATMUL, SWAPPED_OPERAND that must be caught. - tests/run_tensor_chip.sh: pinned, locked, receipted chip run; no quiet flag. - mk/tensor.mk: test-tensor-gb10-host, test-tensor-gb10-chip. - tools/tensor_mutations.sh --gb10: nm no-CPU-fallback check + 3 MUT: mutants. - Doc rows: GB10 parity NOT_RUN; Tensor Core MISSING_IMPLEMENTATION (why). Co-Authored-By: Claude Opus 5.5 --- docs/tensor/M20_OMEGA_TENSOR.md | 4 +- mk/tensor.mk | 21 ++ src/tensor/omega_tensor.c | 46 ++- src/tensor/omega_tensor.h | 26 ++ src/tensor/omega_tensor_gb10.c | 159 +++++++++ tests/run_tensor_chip.sh | 156 +++++++++ tests/test_omega_tensor_gb10.c | 562 ++++++++++++++++++++++++++++++++ tools/tensor_mutations.sh | 62 ++++ 8 files changed, 1023 insertions(+), 13 deletions(-) create mode 100644 src/tensor/omega_tensor_gb10.c create mode 100755 tests/run_tensor_chip.sh create mode 100644 tests/test_omega_tensor_gb10.c diff --git a/docs/tensor/M20_OMEGA_TENSOR.md b/docs/tensor/M20_OMEGA_TENSOR.md index d9943a439..213632aeb 100644 --- a/docs/tensor/M20_OMEGA_TENSOR.md +++ b/docs/tensor/M20_OMEGA_TENSOR.md @@ -153,8 +153,8 @@ removed. Order and padding mutations are caught by the E1 WP-D suite. | Determinism | PASS (CPU) | repeated run same value id; frozen KAT value id in the test | | Test-only hook not in library | PASS (CPU) | `omega_tensor_test_set_storage_generation` exists only under `-DOMEGA_TENSOR_TEST_HOOKS` (test builds in `mk/tensor.mk`); `test-tensor-no-hooks` (run by `test-tensor`) builds the default objects and fails if `nm` shows the symbol | | CI | WIRED | `host-suites-2.yml` job `tensor`: `test-tensor` + `test-tensor-mutations` on the AArch64 hosted runner (not the Spark, not a qualification) | -| GB10 parity | NOT_RUN | no GB10 realization table yet; no chip run in this work | -| GB10 general matmul (Tensor Core beyond narrow K/tile) | MISSING_IMPLEMENTATION | | +| GB10 parity | NOT_RUN | GB10 table `src/tensor/omega_tensor_gb10.c` (E1 SIMT elementwise, `omega_reduce_gb10`, matmul = FMUL_RNE products + E1 tree, batched per block) and gate `tests/test_omega_tensor_gb10.c` + `tests/run_tensor_chip.sh` written (branch hive/M20-gb10); no forge host or chip receipt yet | +| GB10 general matmul (Tensor Core beyond narrow K/tile) | MISSING_IMPLEMENTATION | not built on purpose: MMA accumulates with fused, differently ordered additions, so it cannot give the declared bits; it needs its own declared bounded contract first. The GB10 table uses SIMT FMUL + the E1 tree instead | | Crash-safe storage lifetime | PASS (CPU) | host PASS, forge log HIVE-M20-lifetime-light-182200 (`test-tensor-store` 314/0 plain + ASan/UBSan, 6/6 store mutants caught, hook absent from default build). `src/tensor/omega_tensor_store.{c,h}`: content-addressed payloads + checksummed journal, temp/fsync/rename/fsync-dir commit; recovery replays the journal, re-hashes every payload, refuses torn/short/corrupt records (typed errors), keeps generations monotonic; `test-tensor-store` (round trip, fork crash at all 8 commit phases, journal/payload truncated at every byte and bit-flipped, crafted journals) + 6 store mutants in `test-tensor-mutations` | | Reproducible receipt | PASS (CPU) | writer implemented and host-tested: `tools/m20_receipt.sh` writes `/.json` (0444, exclusive, never overwritten), QUALIFIED only with GB10 parity GB10 PASS + matching chip evidence; `test-m20-receipt` + 11 receipt mutants in `test-tensor-mutations`, forge log HIVE-M20-receipt-175835. No real M20 receipt has been written yet because the GB10 parity evidence does not exist. | | E1 numeric closure | PASS (on main) | E1 PASSED on main 4863803; receipt merged in omega#177 | diff --git a/mk/tensor.mk b/mk/tensor.mk index f6555a3a1..da3f641ee 100644 --- a/mk/tensor.mk +++ b/mk/tensor.mk @@ -100,4 +100,25 @@ test-tensor-store: $(OUT_DIR)/test_omega_tensor_store $(OUT_DIR)/test_omega_tens ./$(OUT_DIR)/test_omega_tensor_store ./$(OUT_DIR)/test_omega_tensor_store_asan $(MAKE) --no-print-directory test-tensor-no-hooks + +# ---- GB10 realization table (M20 cut gb10) --------------------------------- +# test-tensor-gb10-host PHYSICS_DIR=: +# builds the GB10 table + tests/test_omega_tensor_gb10.c +# against physics and runs host self checks only (no +# --chip, no device), the nm no-CPU-fallback check and +# the GB10 MUT: mutants (tools/tensor_mutations.sh --gb10) +# test-tensor-gb10-chip the chip parity gate: tests/run_tensor_chip.sh (pins, +# clean trees, /tmp/aien-gb10.lock, receipt). Refuses +# unless GB10_CHIP_RUN=1 is set, so it never runs by +# accident. Never pass a quiet flag. +.PHONY: test-tensor-gb10-host test-tensor-gb10-chip +test-tensor-gb10-host: + @test -n "$(PHYSICS_DIR)" && test -d "$(PHYSICS_DIR)" \ + || { echo "test-tensor-gb10-host: set PHYSICS_DIR to the physics checkout"; exit 2; } + tools/tensor_mutations.sh --gb10 "$(PHYSICS_DIR)" + +test-tensor-gb10-chip: + @test "$$GB10_CHIP_RUN" = 1 || { echo "test-tensor-gb10-chip: chip run refused (set GB10_CHIP_RUN=1; forge only)"; exit 2; } + @test -n "$(PHYSICS_DIR)" || { echo "test-tensor-gb10-chip: set PHYSICS_DIR"; exit 2; } + tests/run_tensor_chip.sh --physics-dir "$(PHYSICS_DIR)" endif diff --git a/src/tensor/omega_tensor.c b/src/tensor/omega_tensor.c index 27636890d..51c21390d 100644 --- a/src/tensor/omega_tensor.c +++ b/src/tensor/omega_tensor.c @@ -911,6 +911,9 @@ int omega_tensor_reduce(OmegaTensorCtx *ctx, OmegaTensorReduceOp op, OmegaTensor return rc; } +/* Products per matmul block (elements): bounds the scratch of one block. */ +#define MATMUL_BLOCK_ELEMS ((uint64_t)1 << 20) + int omega_tensor_matmul(OmegaTensorCtx *ctx, OmegaTensor a, OmegaTensor b, OmegaTensor *out) { TensorSlot *xa, *xb; StorageSlot *sa, *sb; @@ -947,26 +950,47 @@ int omega_tensor_matmul(OmegaTensorCtx *ctx, OmegaTensor a, OmegaTensor b, Omega uint64_t batches = va.elements / (M * K); float *A = malloc((size_t)va.elements * sizeof(float)); float *BT = malloc((size_t)vb.elements * sizeof(float)); - float *prod = malloc((size_t)K * sizeof(float)); - if (!A || !BT || !prod) { free(A); free(BT); free(prod); return OMEGA_TENSOR_ERR_CAPACITY; } + /* Outputs are done in blocks: the products of a whole block go through + * one elementwise FMUL call and one row reduction (reduce_rows, or one + * reduce per row), so a device realization needs a few launches per + * block instead of two per output. Same bits: FMUL is per element and + * every row is reduced in the declared order. */ + uint64_t outs = batches * M * N; + uint64_t blk = MATMUL_BLOCK_ELEMS / K; + if (blk == 0) blk = 1; + if (blk > outs) blk = outs; + float *pa = malloc((size_t)(blk * K) * sizeof(float)); + float *pb = malloc((size_t)(blk * K) * sizeof(float)); + float *prod = malloc((size_t)(blk * K) * sizeof(float)); + if (!A || !BT || !pa || !pb || !prod) { + free(A); free(BT); free(pa); free(pb); free(prod); + return OMEGA_TENSOR_ERR_CAPACITY; + } gather(sa, &va, A); gather(sb, &vb, BT); void *buf; rc = new_dense(ctx, OMEGA_DT_F32, br + 2, sho, out, &buf); if (!rc) { float *o = buf; - for (uint64_t bt = 0; bt < batches && !rc; bt++) - for (uint64_t i = 0; i < M && !rc; i++) - for (uint64_t j = 0; j < N && !rc; j++) { - const float *ar = A + (bt * M + i) * K; - const float *bc = BT + (bt * N + j) * K; - int nrc = ctx->real->elementwise(OMEGA_NOP_FMUL, ar, bc, NULL, prod, (size_t)K); - if (!nrc) nrc = ctx->real->reduce(OMEGA_TR_SUM, prod, (size_t)K, &o[(bt * M + i) * N + j]); - if (nrc) rc = numeric_fail(ctx, nrc, *out); - } + for (uint64_t o0 = 0; o0 < outs && !rc; o0 += blk) { + uint64_t cnt = outs - o0 < blk ? outs - o0 : blk; + for (uint64_t q = 0; q < cnt; q++) { + uint64_t e = o0 + q, j = e % N, i = (e / N) % M, bt = e / (N * M); + memcpy(pa + q * K, A + (bt * M + i) * K, (size_t)K * sizeof(float)); + memcpy(pb + q * K, BT + (bt * N + j) * K, (size_t)K * sizeof(float)); + } + int nrc = ctx->real->elementwise(OMEGA_NOP_FMUL, pa, pb, NULL, prod, (size_t)(cnt * K)); + if (!nrc && ctx->real->reduce_rows) + nrc = ctx->real->reduce_rows(OMEGA_TR_SUM, prod, (size_t)cnt, (size_t)K, o + o0); + for (uint64_t q = 0; !nrc && !ctx->real->reduce_rows && q < cnt; q++) + nrc = ctx->real->reduce(OMEGA_TR_SUM, prod + q * K, (size_t)K, &o[o0 + q]); + if (nrc) rc = numeric_fail(ctx, nrc, *out); + } } free(A); free(BT); + free(pa); + free(pb); free(prod); return rc; } diff --git a/src/tensor/omega_tensor.h b/src/tensor/omega_tensor.h index a848630bc..5cd340b7a 100644 --- a/src/tensor/omega_tensor.h +++ b/src/tensor/omega_tensor.h @@ -209,10 +209,36 @@ typedef struct { * omega_ref_fsetp_pred(sel_op, a[i], b[i]) bit for bit. * NULL: the CMP_* binary ops return OMEGA_TENSOR_ERR_REALIZATION. */ int (*compare)(OmegaNumericOp sel_op, const float *a, const float *b, float *out, size_t n); + /* Optional (NULL = the semantic layer calls reduce once per row): + * out[r] = reduce(op, x[r*n .. r*n + n)) for r < rows, every row in + * OMEGA_TENSOR_REDUCE_DECLARED_ORDER, so the bits equal one reduce call + * per row. Lets a device realization batch many short rows (matmul + * outputs) into a few launches. Added by M20 cut gb10. */ + int (*reduce_rows)(OmegaTensorReduceOp op, const float *x, size_t rows, size_t n, float *out); } OmegaTensorRealization; const OmegaTensorRealization *omega_tensor_cpu_realization(void); +/* + * GB10 realization (src/tensor/omega_tensor_gb10.c, M20 cut gb10). Needs the + * physics checkout to build; opens the device on every call. + * elementwise: E1 omega_gb10_execute_simt_op, in chunks of at most + * OMEGA_NUMERIC_MAX_COUNT. Only the ops the tensor layer uses + * and that have a GB10 E1 kernel are mapped; any other op is + * refused with OMEGA_NUMERIC_ERR_NOT_ENCODED before a device + * is opened. Never falls back to the CPU. + * reduce: E1 omega_reduce_gb10 (n <= OMEGA_REDUCE_GB10_MAX_N), after + * the same declared-order strcmp as the CPU seam. + * reduce_rows: SUM batches all rows per tree level through the E1 + * REDUCE_SUM warp kernel (same patch words as + * omega_reduce_gb10 SUM); other ops call omega_reduce_gb10 per + * row. Matmul is therefore FMUL_RNE products + the E1 tree, + * bit-exact with the CPU table. No Tensor Core, no FFMA. + */ +const OmegaTensorRealization *omega_tensor_gb10_realization(void); +/* E1 op name the GB10 table submits for op, or NULL if op is refused. */ +const char *omega_tensor_gb10_op_name(OmegaNumericOp op); + typedef struct OmegaTensorCtx OmegaTensorCtx; /* capacity = number of storage slots and of tensor descriptor slots. */ diff --git a/src/tensor/omega_tensor_gb10.c b/src/tensor/omega_tensor_gb10.c new file mode 100644 index 000000000..0ae052602 --- /dev/null +++ b/src/tensor/omega_tensor_gb10.c @@ -0,0 +1,159 @@ +/* + * GB10 realization of M20 OMEGA_TENSOR (docs/tensor/M20_OMEGA_TENSOR.md, + * declared in omega_tensor.h). Every arithmetic step runs on the GB10 through + * an E1 entry point; this file only maps ops, checks, pads and moves data. + * + * elementwise omega_gb10_execute_simt_op (E1 SIMT ops), chunks of at most + * OMEGA_NUMERIC_MAX_COUNT elements. The op map below lists only + * the ops the tensor layer submits AND that have a GB10 E1 + * kernel; every other op is refused with + * OMEGA_NUMERIC_ERR_NOT_ENCODED before a device is opened. + * reduce omega_reduce_gb10 (E1 WP-D), n <= OMEGA_REDUCE_GB10_MAX_N, + * after the declared-order strcmp the CPU seam also makes. + * reduce_rows SUM: every tree level of every row in one pass of E1 + * REDUCE_SUM warp launches (each row padded with -0.0 to whole + * tiles of 32, lane 0 of each warp gathered on the host: data + * movement only). Same patch words and order as + * omega_reduce_gb10 SUM. MAX/MIN/MEAN: omega_reduce_gb10 per row. + * + * There is no CPU fallback: this file never calls omega_numeric_cpu_realize, + * omega_reduce_cpu or any reference tier (mk/tensor.mk checks with nm). + * Matmul is the semantic layer's FMUL_RNE products + the E1 tree, so it is + * bit-exact with the CPU table. A Tensor Core matmul is not provided: MMA + * accumulates with fused, differently ordered additions and would need its + * own declared bounded contract (doc row stays MISSING_IMPLEMENTATION). + */ +#include "omega_tensor.h" + +#include +#include + +#include "omega_numeric.h" +#include "omega_numeric_reduce.h" + +_Static_assert(sizeof(OMEGA_REDUCE_DECLARED_ORDER) == sizeof(OMEGA_TENSOR_REDUCE_DECLARED_ORDER), + "tensor reduce order must equal the E1 reduction order"); +_Static_assert(OMEGA_NUMERIC_MAX_COUNT % 32u == 0, "chunks must be whole warps"); + +/* Ops the semantic layer submits (omega_tensor.c: unary SQRT, BINARY_MAP, + * fma FFMA_V, matmul FMUL, cast conversions) -> E1 GB10 op name. Ops that + * are absent (EXP, LOG, uniform-c FFMA, MUFU seeds, LDS/SHFL, ...) are + * refused. */ +static const char *const GB10_OP_NAME[OMEGA_NOP_COUNT] = { + [OMEGA_NOP_FADD] = "FADD", [OMEGA_NOP_FSUB] = "FSUB", + [OMEGA_NOP_FMUL] = "FMUL", [OMEGA_NOP_DIV] = "DIV", + [OMEGA_NOP_SQRT] = "SQRT", [OMEGA_NOP_FFMA_V] = "FFMA_V", + [OMEGA_NOP_FMNMX_MIN] = "FMNMX_MIN", [OMEGA_NOP_FMNMX_MAX] = "FMNMX_MAX", + [OMEGA_NOP_FSETP_SEL] = "FSETP_SEL", [OMEGA_NOP_FSETP_LT_SEL] = "FSETP_LT_SEL", + [OMEGA_NOP_FSETP_LE_SEL] = "FSETP_LE_SEL", [OMEGA_NOP_FSETP_GT_SEL] = "FSETP_GT_SEL", + [OMEGA_NOP_FSETP_EQ_SEL] = "FSETP_EQ_SEL", [OMEGA_NOP_FSETP_NE_SEL] = "FSETP_NE_SEL", + [OMEGA_NOP_FSETP_NUM_SEL] = "FSETP_NUM_SEL", [OMEGA_NOP_FSETP_NAN_SEL] = "FSETP_NAN_SEL", + [OMEGA_NOP_FSETP_LTU_SEL] = "FSETP_LTU_SEL", [OMEGA_NOP_FSETP_LEU_SEL] = "FSETP_LEU_SEL", + [OMEGA_NOP_FSETP_GTU_SEL] = "FSETP_GTU_SEL", [OMEGA_NOP_FSETP_GEU_SEL] = "FSETP_GEU_SEL", + [OMEGA_NOP_FSETP_EQU_SEL] = "FSETP_EQU_SEL", [OMEGA_NOP_FSETP_NEU_SEL] = "FSETP_NEU_SEL", + [OMEGA_NOP_F32_TO_F16] = "F32_TO_F16", [OMEGA_NOP_F32_TO_BF16] = "F32_TO_BF16", + [OMEGA_NOP_F16_TO_F32] = "F16_TO_F32", [OMEGA_NOP_BF16_TO_F32] = "BF16_TO_F32", +}; + +const char *omega_tensor_gb10_op_name(OmegaNumericOp op) { + if ((unsigned)op >= OMEGA_NOP_COUNT) return NULL; + return GB10_OP_NAME[op]; +} + +static int gb10_elementwise(OmegaNumericOp op, const float *a, const float *b, const float *c, + float *out, size_t n) { + const char *name = omega_tensor_gb10_op_name(op); + if (!name) return OMEGA_NUMERIC_ERR_NOT_ENCODED; /* no silent CPU fallback; MUT:GB10_NO_CPU_FALLBACK */ + const OmegaNumericOpInfo *info = omega_numeric_op_find(name); + if (!info || info->op != op || !info->gb10_encoded) return OMEGA_NUMERIC_ERR_NOT_ENCODED; + if (!a || !out || n == 0) return OMEGA_NUMERIC_ERR_BAD_ARGS; + for (size_t base = 0; base < n; base += OMEGA_NUMERIC_MAX_COUNT) { + size_t cnt = n - base < OMEGA_NUMERIC_MAX_COUNT ? n - base : OMEGA_NUMERIC_MAX_COUNT; + int rc = omega_gb10_execute_simt_op(name, a + base, b ? b + base : NULL, c ? c + base : NULL, + out + base, cnt); + if (rc != OMEGA_NUMERIC_OK) return rc; + } + return OMEGA_NUMERIC_OK; +} + +static int map_reduce_op(OmegaTensorReduceOp op, OmegaReduceOp *r) { + switch (op) { + case OMEGA_TR_SUM: *r = OMEGA_RED_SUM; return OMEGA_NUMERIC_OK; + case OMEGA_TR_MAX: *r = OMEGA_RED_MAX; return OMEGA_NUMERIC_OK; + case OMEGA_TR_MIN: *r = OMEGA_RED_MIN; return OMEGA_NUMERIC_OK; + case OMEGA_TR_MEAN: *r = OMEGA_RED_MEAN; return OMEGA_NUMERIC_OK; + default: return OMEGA_NUMERIC_ERR_BAD_ARGS; + } +} + +static int gb10_reduce(OmegaTensorReduceOp op, const float *x, size_t n, float *out) { + if (strcmp(OMEGA_REDUCE_DECLARED_ORDER, OMEGA_TENSOR_REDUCE_DECLARED_ORDER) != 0) + return OMEGA_NUMERIC_ERR_BAD_ARGS; + /* size limit first, so it is refused even before the buffers are looked at */ + if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS; /* MUT:GB10_REDUCE_MAX_N */ + OmegaReduceOp r; + if (map_reduce_op(op, &r) != OMEGA_NUMERIC_OK || !x || !out || n == 0) return OMEGA_NUMERIC_ERR_BAD_ARGS; + return omega_reduce_gb10(r, x, n, out); +} + +/* SUM of rows rows of n values, all rows per level in shared launches. + * Level: each row's len values are padded with -0.0 to a whole number of + * 32-tiles; REDUCE_SUM leaves tile t's warp-tree sum in lane 0 of warp t. */ +static int gb10_sum_rows(const float *x, size_t rows, size_t n, float *out) { + size_t padded = (n + 31u) & ~(size_t)31u; + if (rows > SIZE_MAX / padded) return OMEGA_NUMERIC_ERR_OPERANDS; + float *cur = malloc(rows * n * sizeof(float)); + float *lvl = malloc(rows * padded * sizeof(float)); + float *res = malloc(rows * padded * sizeof(float)); + int rc = OMEGA_NUMERIC_OK; + if (!cur || !lvl || !res) { rc = OMEGA_NUMERIC_ERR_BAD_ARGS; goto done; } + memcpy(cur, x, rows * n * sizeof(float)); + const float pad = omega_bits_to_float(OMEGA_REDUCE_SUM_PAD_BITS); + size_t len = n; + do { /* at least one level, as declared */ + size_t pl = (len + 31u) & ~(size_t)31u, tiles = pl / 32u, total = rows * pl; + for (size_t r = 0; r < rows; r++) { + memcpy(lvl + r * pl, cur + r * len, len * sizeof(float)); + for (size_t i = len; i < pl; i++) lvl[r * pl + i] = pad; + } + for (size_t base = 0; base < total && rc == OMEGA_NUMERIC_OK; base += OMEGA_NUMERIC_MAX_COUNT) { + size_t cnt = total - base < OMEGA_NUMERIC_MAX_COUNT ? total - base : OMEGA_NUMERIC_MAX_COUNT; + rc = omega_gb10_execute_simt_op("REDUCE_SUM", lvl + base, NULL, NULL, res + base, cnt); + } + if (rc != OMEGA_NUMERIC_OK) goto done; + for (size_t r = 0; r < rows; r++) + for (size_t t = 0; t < tiles; t++) cur[r * tiles + t] = res[r * pl + t * 32u]; + len = tiles; + } while (len > 1); + memcpy(out, cur, rows * sizeof(float)); +done: + free(cur); + free(lvl); + free(res); + return rc; +} + +static int gb10_reduce_rows(OmegaTensorReduceOp op, const float *x, size_t rows, size_t n, float *out) { + if (strcmp(OMEGA_REDUCE_DECLARED_ORDER, OMEGA_TENSOR_REDUCE_DECLARED_ORDER) != 0) + return OMEGA_NUMERIC_ERR_BAD_ARGS; + if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS; /* MUT:GB10_ROWS_MAX_N */ + OmegaReduceOp r; + if (map_reduce_op(op, &r) != OMEGA_NUMERIC_OK || !x || !out || n == 0 || rows == 0) + return OMEGA_NUMERIC_ERR_BAD_ARGS; + if (op == OMEGA_TR_SUM) return gb10_sum_rows(x, rows, n, out); + for (size_t i = 0; i < rows; i++) { + int rc = omega_reduce_gb10(r, x + i * n, n, &out[i]); + if (rc != OMEGA_NUMERIC_OK) return rc; + } + return OMEGA_NUMERIC_OK; +} + +static const OmegaTensorRealization GB10_REALIZATION = { + .name = "GB10_E1_SIMT", + .reduce_order = OMEGA_TENSOR_REDUCE_DECLARED_ORDER, + .elementwise = gb10_elementwise, + .reduce = gb10_reduce, + .reduce_rows = gb10_reduce_rows, +}; + +const OmegaTensorRealization *omega_tensor_gb10_realization(void) { return &GB10_REALIZATION; } diff --git a/tests/run_tensor_chip.sh b/tests/run_tensor_chip.sh new file mode 100755 index 000000000..6d6e97909 --- /dev/null +++ b/tests/run_tensor_chip.sh @@ -0,0 +1,156 @@ +#!/bin/bash +# tests/run_tensor_chip.sh -- M20 OMEGA_TENSOR GB10 parity chip run. +# +# GB10_CHIP_RUN=1 tests/run_tensor_chip.sh --physics-dir DIR [--evidence-dir DIR] +# +# Pattern of tests/run_reduce_chip.sh, without any quiet-flag option (this +# script never creates or touches ~/workspace/.spark-quiet). +# 1. Refuses unless GB10_CHIP_RUN=1. The omega tree (this repo) must be clean; +# the run commit is its HEAD. The physics checkout must be clean and at the +# commit in physics.lock. +# 2. Builds tests/test_omega_tensor_gb10.c with the CPU table, the GB10 table +# and the E1 GB10 executors, -ffp-contract=off, into +# build/tensor-runs//, and refuses a binary with libm math or CUDA +# symbols. +# 3. Runs it with --chip under /tmp/aien-gb10.lock (waits for the lock; no +# timeout; the chip test is never killed). +# 4. PASS needs exit status 0 and the lines "TENSOR_GB10_HOST: PASS", +# "TENSOR_GB10_PARITY: PASS", "TENSOR_GB10_MUTANTS: PASS" and +# "M20 Tensor GB10 Verdict: PASS", and clean trees with unmoved HEADs after. +# 5. Writes a content-addressed receipt /.json (mode +# 0444, never overwritten) for PASS and FAIL alike, plus the log and binary +# as blobs/.{log,bin}. The evidence dir must lie outside the trees. +# Shell + coreutils + git + jq + gcc. No Python. Exit 0 PASS, 1 FAIL, 2 refused. +set -u +SELF_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) +OMEGA=$(cd "$SELF_DIR/.." && pwd) +PHYS="" +EVID=$HOME/workspace/evidence-out/M20-TENSOR-GB10 +while [ $# -gt 0 ]; do + case $1 in + --physics-dir) PHYS=$2; shift 2 ;; + --evidence-dir) EVID=$2; shift 2 ;; + *) echo "unknown argument $1" >&2; exit 2 ;; + esac +done +die() { echo "run_tensor_chip: $*" >&2; exit 2; } +[ "${GB10_CHIP_RUN:-}" = 1 ] || die "chip run refused: GB10_CHIP_RUN=1 is not set" +[ -n "$PHYS" ] && [ -d "$PHYS" ] || die "--physics-dir is required" +PHYS=$(cd "$PHYS" && pwd) +[ -z "$(git -C "$OMEGA" status --porcelain)" ] || die "omega tree is dirty; refusing" +COMMIT=$(git -C "$OMEGA" rev-parse HEAD) +LOCKED=$(tr -d ' \n' < "$OMEGA/physics.lock") +PHEAD=$(git -C "$PHYS" rev-parse HEAD) +[ "$PHEAD" = "$LOCKED" ] || die "physics checkout is at $PHEAD, physics.lock pins $LOCKED" +[ -z "$(git -C "$PHYS" status --porcelain)" ] || die "physics checkout is dirty" +mkdir -p "$EVID/blobs" +EVID=$(cd "$EVID" && pwd) +case "$EVID/" in "$OMEGA/"*|"$PHYS/"*) die "evidence dir must be outside the omega tree and physics checkout" ;; esac + +STARTED=$(date -u +%Y-%m-%dT%H:%M:%SZ) +RUN_ID=$(date -u +%Y%m%dT%H%M%SZ)-${COMMIT:0:12} +mkdir -p "$OMEGA/build/tensor-runs" || die "cannot create build/tensor-runs" +# one fresh directory per invocation, so concurrent runs never share files +OUT=$(mktemp -d "$OMEGA/build/tensor-runs/$RUN_ID.XXXXXX") || die "cannot create a run directory" +RUN_ID=$(basename "$OUT") +BIN=$OUT/test_omega_tensor_gb10 +NV=$PHYS/third_party/nvidia-open-580.173.02 +FAIL_REASON="" +(cd "$OMEGA" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off \ + -Isrc -Isrc/tensor -I"$PHYS/forge" -I"$PHYS/nvrm" -I"$PHYS/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_tensor_gb10.c src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c \ + src/tensor/omega_tensor_reduce_seam.c src/tensor/omega_tensor_gb10.c \ + src/omega_numeric_reduce.c src/omega_numeric_transc.c src/omega_numeric_reduce_gb10.c \ + src/omega_numeric.c src/omega_numeric_gb10.c src/omega_numeric_divsqrt_gb10.c \ + src/omega_numeric_provenance.c src/omega_blackwell_codegen.c \ + src/omega_blackwell_encoder.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c \ + src/forge_realization.c src/aegis_verification.c src/sha256.c \ + "$PHYS/forge/forge_descriptor.c" "$PHYS/forge/forge_realize.c" "$PHYS/sha256_clean.c" \ + "$PHYS/nvrm/nvrm.c" "$PHYS/m16/m16_native.c") > "$OUT/build.log" 2>&1 || FAIL_REASON="build failed" +if [ -z "$FAIL_REASON" ]; then + nm -u "$BIN" | grep -Eq '\b(sqrtf?|expf?|logf?|powf?|fmaf?|sinf?|cosf?|roundf?|fabsf?)\b' && FAIL_REASON="libm symbols in binary" + nm -u "$BIN" | grep -Eq 'libcuda(rt)?\.so|\b(cuInit|cuCtx|cuMem|cuStream|cudaMalloc)\b' && FAIL_REASON="CUDA symbols in binary" +fi +STATUS=-1 +BIN_SHA_BUILT="" +[ -z "$FAIL_REASON" ] && { BIN_SHA_BUILT=$(sha256sum "$BIN" | cut -d' ' -f1); [ -n "$BIN_SHA_BUILT" ] || FAIL_REASON="cannot hash binary after build"; } +if [ -z "$FAIL_REASON" ]; then + # waits for the lock; no timeout; never killed + GB10_CHIP_RUN=1 flock /tmp/aien-gb10.lock "$BIN" --chip > "$OUT/tensor.log" 2> "$OUT/tensor.stderr" + STATUS=$? + echo "$STATUS" > "$OUT/tensor.status" + [ "$STATUS" = 0 ] || FAIL_REASON="test binary exit status $STATUS" + for k in TENSOR_GB10_HOST TENSOR_GB10_PARITY TENSOR_GB10_MUTANTS; do + grep -q "^$k: PASS" "$OUT/tensor.log" || FAIL_REASON="${FAIL_REASON:-no $k PASS line}" + done + grep -qx 'M20 Tensor GB10 Verdict: PASS' "$OUT/tensor.log" || FAIL_REASON="${FAIL_REASON:-verdict line is not PASS}" +fi +FINISHED=$(date -u +%Y-%m-%dT%H:%M:%SZ) +[ -z "$(git -C "$OMEGA" status --porcelain)" ] && CLEAN_AFTER=true || { CLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-omega tree dirty after run}"; } +[ "$(git -C "$OMEGA" rev-parse HEAD)" = "$COMMIT" ] && HEAD_SAME=true || { HEAD_SAME=false; FAIL_REASON="${FAIL_REASON:-HEAD moved during run}"; } +[ -z "$(git -C "$PHYS" status --porcelain)" ] && PCLEAN_AFTER=true || { PCLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-physics dirty after run}"; } +[ "$(git -C "$PHYS" rev-parse HEAD)" = "$PHEAD" ] && PHEAD_SAME=true || { PHEAD_SAME=false; FAIL_REASON="${FAIL_REASON:-physics HEAD moved during run}"; } + +# store_blob SRC EXT -> prints the digest. An existing blob is trusted only if +# its content hashes to its name; a new one is copied to a temp name, checked, +# sealed and moved into place without overwriting. +store_blob() { + local src=$1 ext=$2 d dst tmp have + d=$(sha256sum "$src" | cut -d' ' -f1); [ -n "$d" ] || die "cannot hash $src" + dst=$EVID/blobs/$d.$ext + if [ -e "$dst" ]; then + have=$(sha256sum "$dst" | cut -d' ' -f1) + [ "$have" = "$d" ] || die "existing blob $dst does not match its digest" + else + tmp=$(mktemp "$EVID/blobs/.tmp.XXXXXX") || die "cannot create temp blob" + cp "$src" "$tmp" || { rm -f "$tmp"; die "cannot store $ext blob"; } + have=$(sha256sum "$tmp" | cut -d' ' -f1) + [ "$have" = "$d" ] || { rm -f "$tmp"; die "stored $ext blob does not match its digest"; } + chmod 0444 "$tmp" || { rm -f "$tmp"; die "cannot seal $ext blob"; } + mv -n "$tmp" "$dst"; rm -f "$tmp" + have=$(sha256sum "$dst" | cut -d' ' -f1) + [ "$have" = "$d" ] || die "blob $dst does not match its digest after publish" + fi + echo "$d" +} +BIN_SHA=""; LOG_SHA="" +if [ -f "$BIN" ]; then BIN_SHA=$(store_blob "$BIN" bin) || exit 2; fi +[ -z "$BIN_SHA_BUILT" ] || [ "$BIN_SHA" = "$BIN_SHA_BUILT" ] || FAIL_REASON="${FAIL_REASON:-binary changed between build and receipt}" +if [ -f "$OUT/tensor.log" ]; then LOG_SHA=$(store_blob "$OUT/tensor.log" log) || exit 2; fi +VERDICT=PASS; [ -n "$FAIL_REASON" ] && VERDICT=FAIL +line() { grep "^$1" "$OUT/tensor.log" 2>/dev/null | head -1; } +TMP=$OUT/receipt.json +jq -n --arg suite M20_TENSOR_GB10_PARITY --arg status "$VERDICT" --arg reason "$FAIL_REASON" \ + --arg run_id "$RUN_ID" --arg commit "$COMMIT" --arg physics "$PHEAD" --arg pin "$LOCKED" \ + --argjson clean_after "$CLEAN_AFTER" --argjson head_same "$HEAD_SAME" \ + --argjson pclean_after "$PCLEAN_AFTER" --argjson phead_same "$PHEAD_SAME" \ + --arg started "$STARTED" --arg finished "$FINISHED" \ + --arg order "RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \ + --arg mm_order "MATMUL_V1_FMUL_RNE_PRODUCTS_THEN_E1_REDUCE_SUM_RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \ + --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg exit_status "$STATUS" \ + --arg host_line "$(line TENSOR_GB10_HOST:)" --arg parity "$(line TENSOR_GB10_PARITY:)" \ + --arg mutants "$(line TENSOR_GB10_MUTANTS:)" --arg cases "$(line 'cases:')" \ + --arg verdict_line "$(line 'M20 Tensor GB10 Verdict:')" \ + --arg host "$(uname -n)" --arg kernel "$(uname -r)" \ + '{suite:$suite,status:$status,reason:$reason,run_id:$run_id,started_utc:$started,finished_utc:$finished, + omega_commit:$commit,omega_tree_clean_before:true,omega_tree_clean_after:$clean_after, + omega_commit_unchanged_after:$head_same,physics_commit:$physics,physics_lock_pin:$pin, + physics_tree_clean_before:true,physics_tree_clean_after:$pclean_after,physics_commit_unchanged_after:$phead_same, + reduce_declared_order:$order,matmul_declared_order:$mm_order,binary_sha256:$bin,chip_log_sha256:$log, + chip_exit_status:$exit_status,cases_line:$cases,host_line:$host_line,parity_line:$parity, + mutants_line:$mutants,verdict_line:$verdict_line, + realization:{elementwise:"E1 omega_gb10_execute_simt_op (chunks <= 65536)", + reduce:"E1 omega_reduce_gb10 (MEAN final division is its declared host step)", + reduce_rows_sum:"E1 REDUCE_SUM warp kernel via omega_gb10_execute_simt_op, all rows per level", + matmul:"FMUL_RNE products + E1 tree; no Tensor Core, no FFMA"}, + mutants:["WRONG_REDUCE_ORDER","FFMA_MATMUL","SWAPPED_OPERAND"],quiet_flag:"not used", + host:$host,kernel:$kernel}' > "$TMP" || die "receipt json (jq) failed, no receipt written" +[ -s "$TMP" ] || die "empty receipt, not written" +[ "$VERDICT" != PASS ] || { [ -n "$BIN_SHA" ] && [ -n "$LOG_SHA" ]; } || die "PASS without binary and log digests refused" +DIG=$(sha256sum "$TMP" | cut -d' ' -f1) +(set -o noclobber; cat "$TMP" > "$EVID/$DIG.json") || die "receipt $DIG.json already exists" +chmod 0444 "$EVID/$DIG.json" +echo "receipt: $EVID/$DIG.json status=$VERDICT ${FAIL_REASON}" +[ "$VERDICT" = PASS ] diff --git a/tests/test_omega_tensor_gb10.c b/tests/test_omega_tensor_gb10.c new file mode 100644 index 000000000..0b4d20ba7 --- /dev/null +++ b/tests/test_omega_tensor_gb10.c @@ -0,0 +1,562 @@ +/* + * M20 OMEGA_TENSOR GB10 parity gate (docs/tensor/M20_OMEGA_TENSOR.md). + * + * test_omega_tensor_gb10 host self checks only; opens no device + * test_omega_tensor_gb10 --chip host self checks, then the parity gate + * and the mutant sweep on the GB10. Needs + * GB10_CHIP_RUN=1 in the environment; run + * it through tests/run_tensor_chip.sh + * (lock, pins, receipt), never directly. + * + * Parity: every case runs through the CPU table and the GB10 table from the + * same seeded inputs; both must return OK and give the same value id + * (omega_tensor_value_id: dtype + shape + values, any NaN = canonical NaN, + * -0 != +0). Cases: general matmul (1x1x1, 129x3x257, odd K across the + * 32-lane tile edges, broadcast batches, a transposed view operand, special + * values), reductions with n across warp/tile edges (31, 32, 33, 1023, 1024, + * 1025, 32769) for SUM/MAX/MIN/MEAN, multi-row reductions along both axes, + * elementwise binary/unary/fma/cast over a grid of specials (NaN, -0, inf, + * subnormals) plus random bit patterns, broadcast elementwise and one call + * longer than a launch chunk. + * + * Mutants (in-process realization tables over a base table: the CPU table in + * host mode, the GB10 table in chip mode): WRONG_REDUCE_ORDER (rows reduced + * reversed), FFMA_MATMUL (matmul products pairwise contracted with FFMA), + * SWAPPED_OPERAND (a and b exchanged). Each must give a different value id on + * at least one case where both sides returned OK; a mutant that is not caught + * fails the test. No libm, no CUDA. + */ +#include +#include +#include + +#include "omega_numeric.h" +#include "omega_numeric_reduce.h" +#include "omega_tensor.h" + +static int g_pass, g_fail; +#define CHECK(cond, ...) do { if (cond) g_pass++; else { g_fail++; \ + printf("FAIL %s:%d: ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0) + +/* ---- inputs ---------------------------------------------------------------- */ +static uint64_t g_rng; +static uint64_t rnd(void) { g_rng ^= g_rng << 13; g_rng ^= g_rng >> 7; g_rng ^= g_rng << 17; return g_rng; } + +static const uint32_t SPECIALS[] = { + 0x00000000U, 0x80000000U, 0x7f800000U, 0xff800000U, 0x7fc00000U, 0x7fa00001U, 0xffc00123U, + 0x00000001U, 0x80000001U, 0x007fffffU, 0x00800000U, 0x7f7fffffU, 0xff7fffffU, 0x3f800000U, + 0xbf800000U, 0x3f000000U, 0x4b800000U, 0x33800000U, 0x3effffffU, 0x7f000000U, +}; +#define NSPECIAL (sizeof(SPECIALS) / sizeof(SPECIALS[0])) + +/* any FP32: 1/4 specials, 1/4 small-range normals, 1/2 raw bit patterns */ +static float rand_f32(void) { + uint64_t r = rnd(); + switch (r & 3u) { + case 0: return omega_bits_to_float(SPECIALS[(r >> 8) % NSPECIAL]); + case 1: return omega_bits_to_float((uint32_t)((r >> 32) & 0x807fffffU) | ((uint32_t)(120 + ((r >> 8) % 16)) << 23)); + default: return omega_bits_to_float((uint32_t)(r >> 16)); + } +} +/* finite values over a moderate exponent range (sums keep their bits) */ +static float rand_mod(void) { + uint64_t r = rnd(); + return omega_bits_to_float((uint32_t)((r >> 32) & 0x807fffffU) | ((uint32_t)(110 + ((r >> 8) % 30)) << 23)); +} + +/* ---- cases ----------------------------------------------------------------- */ +typedef enum { K_MM, K_MM_T, K_RED, K_BIN, K_UN, K_FMA, K_CAST, K_BCAST_ADD, K_BCAST_FMA, K_BIG_ADD } Kind; +enum { MUT_ORDER = 1u, MUT_FFMA = 2u, MUT_SWAP = 4u }; + +typedef struct { + char name[64]; + Kind kind; + int op; /* reduce / binary op, cast kind */ + int dist; /* 0 rand_mod, 1 rand_f32 */ + uint32_t ra, rb, axis; + uint64_t sa[4], sb[4]; + unsigned mut; /* mutants that run this case */ +} Case; + +#define MAX_CASES 160 +static Case g_cases[MAX_CASES]; +static size_t g_ncases; + +static Case *add_case(const char *name, Kind k, unsigned mut) { + if (g_ncases >= MAX_CASES) { printf("FAIL too many cases\n"); exit(2); } + Case *c = &g_cases[g_ncases++]; + memset(c, 0, sizeof(*c)); + snprintf(c->name, sizeof(c->name), "%s", name); + c->kind = k; + c->mut = mut; + return c; +} +static void mm_case(const char *name, uint32_t ra, const uint64_t *sa, uint32_t rb, const uint64_t *sb, + int dist, unsigned mut) { + Case *c = add_case(name, K_MM, mut); + c->ra = ra; c->rb = rb; c->dist = dist; + memcpy(c->sa, sa, ra * sizeof(uint64_t)); + memcpy(c->sb, sb, rb * sizeof(uint64_t)); +} + +static const char *RED_NAME[OMEGA_TR_COUNT] = { "SUM", "MAX", "MIN", "MEAN" }; +static const char *BIN_NAME[OMEGA_TB_COUNT] = { + "ADD", "SUB", "MUL", "DIV", "MIN", "MAX", "SEL_GE", "SEL_LT", "SEL_LE", "SEL_GT", "SEL_EQ", "SEL_NE", + "SEL_NUM", "SEL_NAN", "SEL_LTU", "SEL_LEU", "SEL_GTU", "SEL_GEU", "SEL_EQU", "SEL_NEU", +}; + +static void build_cases(void) { + char nm[64]; + /* general matmul */ + mm_case("mm_1x1x1", 2, (uint64_t[]){ 1, 1 }, 2, (uint64_t[]){ 1, 1 }, 0, 0); + mm_case("mm_129x3x257", 2, (uint64_t[]){ 129, 3 }, 2, (uint64_t[]){ 3, 257 }, 0, 0); + static const uint64_t KS[] = { 31, 32, 33, 63, 64, 65, 1023, 1024, 1025 }; + for (size_t i = 0; i < sizeof(KS) / sizeof(KS[0]); i++) { + snprintf(nm, sizeof(nm), "mm_2x%llux3", (unsigned long long)KS[i]); + unsigned mut = (KS[i] == 33 || KS[i] == 65) ? (MUT_ORDER | MUT_FFMA) : 0; + mm_case(nm, 2, (uint64_t[]){ 2, KS[i] }, 2, (uint64_t[]){ KS[i], 3 }, 0, mut); + } + mm_case("mm_bcast_3x1x4x5_2x5x6", 4, (uint64_t[]){ 3, 1, 4, 5 }, 3, (uint64_t[]){ 2, 5, 6 }, 0, MUT_FFMA); + mm_case("mm_bcast_2x3x33_33x4", 3, (uint64_t[]){ 2, 3, 33 }, 2, (uint64_t[]){ 33, 4 }, 0, MUT_FFMA); + mm_case("mm_specials_3x33x2", 2, (uint64_t[]){ 3, 33 }, 2, (uint64_t[]){ 33, 2 }, 1, 0); + Case *t = add_case("mm_viewT_5x7x3", K_MM_T, 0); + t->ra = 2; t->sa[0] = 7; t->sa[1] = 5; t->rb = 2; t->sb[0] = 7; t->sb[1] = 3; + /* reductions with n across warp/tile edges */ + static const uint64_t NS[] = { 31, 32, 33, 1023, 1024, 1025, 32769 }; + for (int op = 0; op < OMEGA_TR_COUNT; op++) { + for (size_t i = 0; i < sizeof(NS) / sizeof(NS[0]); i++) { + snprintf(nm, sizeof(nm), "red_%s_n%llu", RED_NAME[op], (unsigned long long)NS[i]); + unsigned mut = (op == OMEGA_TR_SUM && (NS[i] == 33 || NS[i] == 1025)) ? MUT_ORDER : 0; + Case *c = add_case(nm, K_RED, mut); + c->op = op; c->ra = 1; c->sa[0] = NS[i]; + } + for (int s = 0; s < 2; s++) { + snprintf(nm, sizeof(nm), "red_%s_specials_n%d", RED_NAME[op], s ? 1025 : 33); + Case *c = add_case(nm, K_RED, 0); + c->op = op; c->dist = 1; c->ra = 1; c->sa[0] = s ? 1025 : 33; + } + snprintf(nm, sizeof(nm), "red_%s_rows_3x1025_axis1", RED_NAME[op]); + Case *c = add_case(nm, K_RED, 0); + c->op = op; c->ra = 2; c->sa[0] = 3; c->sa[1] = 1025; c->axis = 1; + snprintf(nm, sizeof(nm), "red_%s_cols_1025x3_axis0", RED_NAME[op]); + c = add_case(nm, K_RED, 0); + c->op = op; c->ra = 2; c->sa[0] = 1025; c->sa[1] = 3; c->axis = 0; + } + /* elementwise */ + for (int op = 0; op < OMEGA_TB_COUNT; op++) { + snprintf(nm, sizeof(nm), "bin_%s", BIN_NAME[op]); + unsigned mut = (op == OMEGA_TB_SUB || op == OMEGA_TB_DIV || op == OMEGA_TB_SEL_LT) ? MUT_SWAP : 0; + Case *c = add_case(nm, K_BIN, mut); + c->op = op; + } + add_case("un_SQRT", K_UN, 0); + add_case("fma_FFMA_V", K_FMA, 0); + static const char *CAST_NAME[4] = { "cast_F32_TO_F16", "cast_F32_TO_BF16", "cast_F16_TO_F32", "cast_BF16_TO_F32" }; + for (int k = 0; k < 4; k++) add_case(CAST_NAME[k], K_CAST, 0)->op = k; + add_case("bcast_add_4x1x3_5x1", K_BCAST_ADD, MUT_SWAP); + add_case("bcast_fma_2x1_1x3_3", K_BCAST_FMA, 0); + add_case("big_add_70001", K_BIG_ADD, 0); +} + +/* specials grid (a, b over all pairs) then random bit patterns */ +#define ELEM_N (NSPECIAL * NSPECIAL + 600u) +static void elem_inputs(float *a, float *b, float *c) { + size_t i = 0; + for (size_t p = 0; p < NSPECIAL; p++) + for (size_t q = 0; q < NSPECIAL; q++, i++) { + a[i] = omega_bits_to_float(SPECIALS[p]); + b[i] = omega_bits_to_float(SPECIALS[q]); + if (c) c[i] = omega_bits_to_float(SPECIALS[(p + q) % NSPECIAL]); + } + for (; i < ELEM_N; i++) { a[i] = rand_f32(); b[i] = rand_f32(); if (c) c[i] = rand_f32(); } +} + +static uint64_t nelem(uint32_t r, const uint64_t *s) { uint64_t n = 1; for (uint32_t i = 0; i < r; i++) n *= s[i]; return n; } + +static int mk(OmegaTensorCtx *ctx, uint32_t rank, const uint64_t *shape, int dist, OmegaTensor *out) { + uint64_t n = nelem(rank, shape); + float *d = malloc((size_t)n * sizeof(float)); + if (!d) return OMEGA_TENSOR_ERR_CAPACITY; + for (uint64_t i = 0; i < n; i++) d[i] = dist ? rand_f32() : rand_mod(); + int rc = omega_tensor_from_f32(ctx, rank, shape, d, out); + free(d); + return rc; +} + +static int run_body(OmegaTensorCtx *ctx, const Case *c, OmegaTensor *out) { + OmegaTensor a = { 0, 0 }, b = { 0, 0 }, x = { 0, 0 }; + int rc; + switch (c->kind) { + case K_MM: + rc = mk(ctx, c->ra, c->sa, c->dist, &a); + if (!rc) rc = mk(ctx, c->rb, c->sb, c->dist, &b); + return rc ? rc : omega_tensor_matmul(ctx, a, b, out); + case K_MM_T: + rc = mk(ctx, c->ra, c->sa, 0, &x); + if (!rc) rc = omega_tensor_transpose(ctx, x, &a); + if (!rc) rc = mk(ctx, c->rb, c->sb, 0, &b); + return rc ? rc : omega_tensor_matmul(ctx, a, b, out); + case K_RED: + rc = mk(ctx, c->ra, c->sa, c->dist, &a); + return rc ? rc : omega_tensor_reduce(ctx, (OmegaTensorReduceOp)c->op, a, c->axis, false, out); + case K_BIN: case K_UN: case K_FMA: { + float *va = malloc(ELEM_N * sizeof(float)), *vb = malloc(ELEM_N * sizeof(float)), + *vc = malloc(ELEM_N * sizeof(float)); + OmegaTensor tc = { 0, 0 }; + uint64_t s = ELEM_N; + rc = (va && vb && vc) ? OMEGA_TENSOR_OK : OMEGA_TENSOR_ERR_CAPACITY; + if (!rc) elem_inputs(va, vb, vc); + if (!rc) rc = omega_tensor_from_f32(ctx, 1, &s, va, &a); + if (!rc) rc = omega_tensor_from_f32(ctx, 1, &s, vb, &b); + if (!rc) rc = omega_tensor_from_f32(ctx, 1, &s, vc, &tc); + free(va); free(vb); free(vc); + if (rc) return rc; + if (c->kind == K_BIN) return omega_tensor_binary(ctx, (OmegaTensorBinaryOp)c->op, a, b, out); + if (c->kind == K_UN) return omega_tensor_unary(ctx, OMEGA_TU_SQRT, a, out); + return omega_tensor_fma(ctx, a, b, tc, out); + } + case K_CAST: { + uint64_t s = ELEM_N; + if (c->op < 2) { + float *va = malloc(ELEM_N * sizeof(float)), *vb = malloc(ELEM_N * sizeof(float)); + rc = (va && vb) ? OMEGA_TENSOR_OK : OMEGA_TENSOR_ERR_CAPACITY; + if (!rc) elem_inputs(va, vb, NULL); + if (!rc) rc = omega_tensor_from_f32(ctx, 1, &s, va, &a); + free(va); free(vb); + return rc ? rc : omega_tensor_cast(ctx, a, c->op == 0 ? OMEGA_DT_F16 : OMEGA_DT_BF16, out); + } + static const uint16_t SP16[] = { 0x0000, 0x8000, 0x7c00, 0xfc00, 0x7e00, 0x7d01, 0x0001, 0x8001, + 0x03ff, 0x0400, 0x7bff, 0x3c00, 0x7f80, 0xff80, 0x7fc0, 0x7f81, + 0x0080, 0x007f }; + uint16_t *h = malloc(ELEM_N * sizeof(uint16_t)); + if (!h) return OMEGA_TENSOR_ERR_CAPACITY; + for (size_t i = 0; i < ELEM_N; i++) + h[i] = i < sizeof(SP16) / sizeof(SP16[0]) ? SP16[i] : (uint16_t)(rnd() >> 24); + OmegaDType dt = c->op == 2 ? OMEGA_DT_F16 : OMEGA_DT_BF16; + rc = omega_tensor_from_data(ctx, dt, 1, &s, h, &a); + free(h); + return rc ? rc : omega_tensor_cast(ctx, a, OMEGA_DT_F32, out); + } + case K_BCAST_ADD: + rc = mk(ctx, 3, (uint64_t[]){ 4, 1, 3 }, 1, &a); + if (!rc) rc = mk(ctx, 2, (uint64_t[]){ 5, 1 }, 1, &b); + return rc ? rc : omega_tensor_binary(ctx, OMEGA_TB_SUB, a, b, out); + case K_BCAST_FMA: { + OmegaTensor tc = { 0, 0 }; + rc = mk(ctx, 2, (uint64_t[]){ 2, 1 }, 1, &a); + if (!rc) rc = mk(ctx, 2, (uint64_t[]){ 1, 3 }, 1, &b); + if (!rc) rc = mk(ctx, 1, (uint64_t[]){ 3 }, 1, &tc); + return rc ? rc : omega_tensor_fma(ctx, a, b, tc, out); + } + case K_BIG_ADD: + rc = mk(ctx, 1, (uint64_t[]){ 70001 }, 1, &a); + if (!rc) rc = mk(ctx, 1, (uint64_t[]){ 70001 }, 1, &b); + return rc ? rc : omega_tensor_binary(ctx, OMEGA_TB_ADD, a, b, out); + } + return OMEGA_TENSOR_ERR_BAD_ARGS; +} + +static uint64_t seed_of(const char *s) { + uint64_t h = 0xcbf29ce484222325ULL; + for (; *s; s++) { h ^= (uint8_t)*s; h *= 0x100000001b3ULL; } + return h ? h : 1; +} + +/* Runs one case through real; status and value id (zeroed unless OK). */ +static int run_case(const OmegaTensorRealization *real, const Case *c, uint8_t id[32]) { + OmegaTensorCtx *ctx; + memset(id, 0, 32); + int rc = omega_tensor_ctx_create(64, real, &ctx); + if (rc) return rc; + g_rng = seed_of(c->name); + OmegaTensor out = { 0, 0 }; + rc = run_body(ctx, c, &out); + if (!rc) rc = omega_tensor_value_id(ctx, out, id); + omega_tensor_ctx_destroy(ctx); + return rc; +} + +static void hex8(const uint8_t id[32], char s[17]) { + for (int i = 0; i < 8; i++) snprintf(s + 2 * i, 3, "%02x", id[i]); +} + +typedef struct { size_t cases, both_ok, differ, not_ok; } Cmp; + +/* Reference CPU vs test table over the cases selected by mask (0 = all). */ +static Cmp compare(const OmegaTensorRealization *test, unsigned mask, const char *tag, bool verbose) { + Cmp r = { 0, 0, 0, 0 }; + for (size_t i = 0; i < g_ncases; i++) { + const Case *c = &g_cases[i]; + if (mask && !(c->mut & mask)) continue; + uint8_t ia[32], ib[32]; + int ra = run_case(omega_tensor_cpu_realization(), c, ia); + int rb = run_case(test, c, ib); + r.cases++; + bool ok = ra == OMEGA_TENSOR_OK && rb == OMEGA_TENSOR_OK; + bool eq = ok && memcmp(ia, ib, 32) == 0; + if (ok) r.both_ok++; else r.not_ok++; + if (ok && !eq) r.differ++; + if (verbose || !eq) { + char ha[17], hb[17]; + hex8(ia, ha); hex8(ib, hb); + printf("%s_CASE %s cpu=%s rc=%d test=%s rc=%d %s\n", tag, c->name, ha, ra, hb, rb, + eq ? "EQUAL" : ok ? "DIFFER" : "NOT_OK"); + } + } + return r; +} + +/* ---- mutant realizations over a base table ---------------------------------- */ +static const OmegaTensorRealization *g_base; + +static int base_rows(OmegaTensorReduceOp op, const float *x, size_t rows, size_t n, float *out) { + if (g_base->reduce_rows) return g_base->reduce_rows(op, x, rows, n, out); + for (size_t r = 0; r < rows; r++) { + int rc = g_base->reduce(op, x + r * n, n, &out[r]); + if (rc) return rc; + } + return 0; +} +static int pass_elem(OmegaNumericOp op, const float *a, const float *b, const float *c, float *out, size_t n) { + return g_base->elementwise(op, a, b, c, out, n); +} +static int pass_reduce(OmegaTensorReduceOp op, const float *x, size_t n, float *out) { + return base_rows(op, x, 1, n, out); +} + +/* WRONG_REDUCE_ORDER: every row reduced back to front. */ +static int m_order_rows(OmegaTensorReduceOp op, const float *x, size_t rows, size_t n, float *out) { + float *rev = malloc(rows * n * sizeof(float)); + if (!rev) return OMEGA_NUMERIC_ERR_BAD_ARGS; + for (size_t r = 0; r < rows; r++) + for (size_t i = 0; i < n; i++) rev[r * n + i] = x[r * n + n - 1 - i]; + int rc = base_rows(op, rev, rows, n, out); + free(rev); + return rc; +} +static int m_order_reduce(OmegaTensorReduceOp op, const float *x, size_t n, float *out) { + return m_order_rows(op, x, 1, n, out); +} + +/* FFMA_MATMUL: remembers the operands of the last FMUL; a SUM over exactly + * those products is replaced by r[k] = FFMA(a[2k], b[2k], a[2k+1]*b[2k+1]) + * (contracted, one rounding less) and the tree over r. */ +static float *st_a, *st_b; +static size_t st_n; +static int m_ffma_elem(OmegaNumericOp op, const float *a, const float *b, const float *c, float *out, size_t n) { + st_n = 0; + if (op == OMEGA_NOP_FMUL && b) { + float *na = realloc(st_a, n * sizeof(float)), *nb = realloc(st_b, n * sizeof(float)); + if (na) st_a = na; + if (nb) st_b = nb; + if (na && nb) { memcpy(st_a, a, n * sizeof(float)); memcpy(st_b, b, n * sizeof(float)); st_n = n; } + } + return g_base->elementwise(op, a, b, c, out, n); +} +static int m_ffma_rows(OmegaTensorReduceOp op, const float *x, size_t rows, size_t n, float *out) { + if (op != OMEGA_TR_SUM || st_n != rows * n || n < 2) { st_n = 0; return base_rows(op, x, rows, n, out); } + st_n = 0; + size_t h = n / 2, m = (n + 1) / 2; + float *ae = malloc(rows * h * sizeof(float)), *be = malloc(rows * h * sizeof(float)); + float *ao = malloc(rows * h * sizeof(float)), *bo = malloc(rows * h * sizeof(float)); + float *q = malloc(rows * h * sizeof(float)), *f = malloc(rows * h * sizeof(float)); + float *rr = malloc(rows * m * sizeof(float)); + int rc = (ae && be && ao && bo && q && f && rr) ? 0 : OMEGA_NUMERIC_ERR_BAD_ARGS; + if (!rc) { + for (size_t r = 0; r < rows; r++) + for (size_t k = 0; k < h; k++) { + ae[r * h + k] = st_a[r * n + 2 * k]; be[r * h + k] = st_b[r * n + 2 * k]; + ao[r * h + k] = st_a[r * n + 2 * k + 1]; bo[r * h + k] = st_b[r * n + 2 * k + 1]; + } + rc = g_base->elementwise(OMEGA_NOP_FMUL, ao, bo, NULL, q, rows * h); + if (!rc) rc = g_base->elementwise(OMEGA_NOP_FFMA_V, ae, be, q, f, rows * h); + } + if (!rc) { + for (size_t r = 0; r < rows; r++) { + for (size_t k = 0; k < h; k++) rr[r * m + k] = f[r * h + k]; + if (m > h) rr[r * m + h] = x[r * n + n - 1]; + } + rc = base_rows(OMEGA_TR_SUM, rr, rows, m, out); + } + free(ae); free(be); free(ao); free(bo); free(q); free(f); free(rr); + return rc; +} +static int m_ffma_reduce(OmegaTensorReduceOp op, const float *x, size_t n, float *out) { + return m_ffma_rows(op, x, 1, n, out); +} + +/* SWAPPED_OPERAND: a and b exchanged in every two-operand call. */ +static int m_swap_elem(OmegaNumericOp op, const float *a, const float *b, const float *c, float *out, size_t n) { + return b ? g_base->elementwise(op, b, a, c, out, n) : g_base->elementwise(op, a, b, c, out, n); +} + +typedef struct { const char *name; unsigned mask; OmegaTensorRealization table; } Mutant; +static const Mutant MUTANTS[] = { + { "WRONG_REDUCE_ORDER", MUT_ORDER, + { .name = "MUTANT_WRONG_REDUCE_ORDER", .reduce_order = OMEGA_TENSOR_REDUCE_DECLARED_ORDER, + .elementwise = pass_elem, .reduce = m_order_reduce, .reduce_rows = m_order_rows } }, + { "FFMA_MATMUL", MUT_FFMA, + { .name = "MUTANT_FFMA_MATMUL", .reduce_order = OMEGA_TENSOR_REDUCE_DECLARED_ORDER, + .elementwise = m_ffma_elem, .reduce = m_ffma_reduce, .reduce_rows = m_ffma_rows } }, + { "SWAPPED_OPERAND", MUT_SWAP, + { .name = "MUTANT_SWAPPED_OPERAND", .reduce_order = OMEGA_TENSOR_REDUCE_DECLARED_ORDER, + .elementwise = m_swap_elem, .reduce = pass_reduce, .reduce_rows = base_rows } }, +}; +#define NMUTANTS (sizeof(MUTANTS) / sizeof(MUTANTS[0])) + +/* Every mutant over base must differ on >= 1 case where both sides were OK. */ +static size_t run_mutants(const OmegaTensorRealization *base, const char *tag) { + g_base = base; + size_t caught = 0; + for (size_t i = 0; i < NMUTANTS; i++) { + char t[96]; + snprintf(t, sizeof(t), "%s_MUTANT_%s", tag, MUTANTS[i].name); + Cmp r = compare(&MUTANTS[i].table, MUTANTS[i].mask, t, false); + bool ok = r.differ > 0; + caught += ok; + printf("%s: %s (%zu of %zu cases differ, %zu not OK)\n", t, ok ? "caught" : "NOT CAUGHT", + r.differ, r.cases, r.not_ok); + CHECK(ok, "mutant %s not caught over %s", MUTANTS[i].name, base->name); + CHECK(r.not_ok == 0, "mutant %s: %zu cases did not run OK on both sides", MUTANTS[i].name, r.not_ok); + } + free(st_a); free(st_b); st_a = st_b = NULL; st_n = 0; + return caught; +} + +/* ---- host self checks (no device) ------------------------------------------- */ +/* Ops the semantic layer submits (omega_tensor.c), listed independently. */ +static const OmegaNumericOp USED_OPS[] = { + OMEGA_NOP_SQRT, OMEGA_NOP_FFMA_V, OMEGA_NOP_FMUL, OMEGA_NOP_FADD, OMEGA_NOP_FSUB, OMEGA_NOP_DIV, + OMEGA_NOP_FMNMX_MIN, OMEGA_NOP_FMNMX_MAX, OMEGA_NOP_FSETP_SEL, OMEGA_NOP_FSETP_LT_SEL, + OMEGA_NOP_FSETP_LE_SEL, OMEGA_NOP_FSETP_GT_SEL, OMEGA_NOP_FSETP_EQ_SEL, OMEGA_NOP_FSETP_NE_SEL, + OMEGA_NOP_FSETP_NUM_SEL, OMEGA_NOP_FSETP_NAN_SEL, OMEGA_NOP_FSETP_LTU_SEL, OMEGA_NOP_FSETP_LEU_SEL, + OMEGA_NOP_FSETP_GTU_SEL, OMEGA_NOP_FSETP_GEU_SEL, OMEGA_NOP_FSETP_EQU_SEL, OMEGA_NOP_FSETP_NEU_SEL, + OMEGA_NOP_F32_TO_F16, OMEGA_NOP_F32_TO_BF16, OMEGA_NOP_F16_TO_F32, OMEGA_NOP_BF16_TO_F32, +}; +#define NUSED (sizeof(USED_OPS) / sizeof(USED_OPS[0])) + +static bool is_used(OmegaNumericOp op) { + for (size_t i = 0; i < NUSED; i++) if (USED_OPS[i] == op) return true; + return false; +} + +/* The map is right iff every used op names its own encoded E1 op and passes + * the pre-submission check, and every other op is unmapped. Returns the + * number of problems. */ +static int check_map(const char *(*name_of)(OmegaNumericOp), bool verbose) { + static float a[32], b[32], c[32], o[32]; + for (int i = 0; i < 32; i++) { a[i] = 1.0f; b[i] = 2.0f; c[i] = 0.5f; } + int bad = 0; + for (int op = 0; op < OMEGA_NOP_COUNT; op++) { + const char *nm = name_of((OmegaNumericOp)op); + if (!is_used((OmegaNumericOp)op)) { + if (nm) { bad++; if (verbose) printf(" map: op %d not used by the tensor layer but mapped to %s\n", op, nm); } + continue; + } + const OmegaNumericOpInfo *info = nm ? omega_numeric_op_find(nm) : NULL; + if (!info || info->op != (OmegaNumericOp)op || !info->gb10_encoded) { + bad++; + if (verbose) printf(" map: used op %d -> %s is not its own GB10-encoded op\n", op, nm ? nm : "(none)"); + continue; + } + char err[256]; + int rc = omega_numeric_submit_check(nm, a, b, c, o, 32, err, sizeof(err)); + if (rc != OMEGA_NUMERIC_OK) { bad++; if (verbose) printf(" map: %s refused: %s\n", nm, err); } + } + return bad; +} +static const char *mut_map_wrong_op(OmegaNumericOp op) { + return op == OMEGA_NOP_FSUB ? "FADD" : omega_tensor_gb10_op_name(op); +} +static const char *mut_map_exp(OmegaNumericOp op) { + return op == OMEGA_NOP_EXP ? "EXP" : omega_tensor_gb10_op_name(op); +} +static const char *mut_map_uniform_ffma(OmegaNumericOp op) { + return op == OMEGA_NOP_FFMA_V ? "FFMA" : omega_tensor_gb10_op_name(op); +} + +static void host_checks(void) { + const OmegaTensorRealization *g = omega_tensor_gb10_realization(); + CHECK(g && g->name && g->elementwise && g->reduce && g->reduce_rows && g->reduce_order, + "GB10 table incomplete"); + CHECK(g && strcmp(g->reduce_order, OMEGA_TENSOR_REDUCE_DECLARED_ORDER) == 0 && + strcmp(g->reduce_order, OMEGA_REDUCE_DECLARED_ORDER) == 0, "GB10 table order string"); + OmegaTensorCtx *ctx = NULL; + CHECK(omega_tensor_ctx_create(8, g, &ctx) == OMEGA_TENSOR_OK, "ctx_create refused the GB10 table"); + omega_tensor_ctx_destroy(ctx); + /* counterexample: the same table with another order string is refused */ + OmegaTensorRealization wrong = *g; + wrong.reduce_order = "SEQUENTIAL_LEFT_TO_RIGHT"; + ctx = NULL; + CHECK(omega_tensor_ctx_create(8, &wrong, &ctx) == OMEGA_TENSOR_ERR_REALIZATION && !ctx, + "GB10 table with a wrong order string accepted"); + + /* op map, and its counterexamples */ + CHECK(check_map(omega_tensor_gb10_op_name, true) == 0, "GB10 op map"); + CHECK(check_map(mut_map_wrong_op, false) > 0, "map check missed FSUB->FADD"); + CHECK(check_map(mut_map_exp, false) > 0, "map check missed EXP (no GB10 kernel)"); + CHECK(check_map(mut_map_uniform_ffma, false) > 0, "map check missed FFMA_V->FFMA (uniform c)"); + + /* refusals before any device is opened: ops without a GB10 kernel (or not + * used by the tensor layer) and sizes past OMEGA_REDUCE_GB10_MAX_N */ + static const OmegaNumericOp REFUSED[] = { OMEGA_NOP_EXP, OMEGA_NOP_LOG, OMEGA_NOP_FFMA, OMEGA_NOP_MUFU_RCP, + OMEGA_NOP_LDS_STS, OMEGA_NOP_SHFL_DOWN, OMEGA_NOP_REDUCE_SUM }; + float a[4] = { 1.0f, 2.0f, 3.0f, 4.0f }, b[4] = { 1.0f, 1.0f, 1.0f, 1.0f }, o[4]; + for (size_t i = 0; i < sizeof(REFUSED) / sizeof(REFUSED[0]); i++) { + int rc = g->elementwise(REFUSED[i], a, b, b, o, 4); + CHECK(rc == OMEGA_NUMERIC_ERR_NOT_ENCODED, "GB10 table did not refuse op %d (rc %d)", REFUSED[i], rc); + } + CHECK(g->elementwise((OmegaNumericOp)OMEGA_NOP_COUNT, a, b, b, o, 4) == OMEGA_NUMERIC_ERR_NOT_ENCODED, + "GB10 table did not refuse an out-of-range op"); + float r1; + CHECK(g->reduce(OMEGA_TR_SUM, NULL, OMEGA_REDUCE_GB10_MAX_N + 1, &r1) == OMEGA_NUMERIC_ERR_OPERANDS, + "reduce past OMEGA_REDUCE_GB10_MAX_N not refused as OPERANDS"); + CHECK(g->reduce_rows(OMEGA_TR_SUM, NULL, 1, OMEGA_REDUCE_GB10_MAX_N + 1, &r1) == OMEGA_NUMERIC_ERR_OPERANDS, + "reduce_rows past OMEGA_REDUCE_GB10_MAX_N not refused as OPERANDS"); + CHECK(g->reduce((OmegaTensorReduceOp)OMEGA_TR_COUNT, a, 4, &r1) == OMEGA_NUMERIC_ERR_BAD_ARGS, + "unknown reduce op not refused"); + + /* the harness itself, on the CPU: CPU vs CPU equal on every case, and + * every mutant (over the CPU table) caught */ + Cmp self = compare(omega_tensor_cpu_realization(), 0, "HOST_SELF", false); + CHECK(self.cases == g_ncases && self.both_ok == g_ncases && self.differ == 0, + "harness CPU vs CPU: %zu cases, %zu OK, %zu differ", self.cases, self.both_ok, self.differ); + size_t caught = run_mutants(omega_tensor_cpu_realization(), "HOST"); + printf("HOST_HARNESS_MUTANTS: %s (%zu of %zu caught over the CPU table)\n", + caught == NMUTANTS ? "PASS" : "FAIL", caught, NMUTANTS); +} + +int main(int argc, char **argv) { + bool chip = argc == 2 && strcmp(argv[1], "--chip") == 0; + if (argc > 1 && !chip) { printf("usage: %s [--chip]\n", argv[0]); return 2; } + if (!omega_numeric_fpenv_ok()) { printf("FPCR not RNE/no-FTZ: refusing to run\n"); return 2; } + if (chip) { + const char *e = getenv("GB10_CHIP_RUN"); + if (!e || strcmp(e, "1") != 0) { + printf("--chip needs GB10_CHIP_RUN=1 (run through tests/run_tensor_chip.sh)\n"); + return 2; + } + } + build_cases(); + printf("cases: %zu\n", g_ncases); + host_checks(); + int host_fail = g_fail; + printf("TENSOR_GB10_HOST: %s (%d checks, %d failed)\n", host_fail ? "FAIL" : "PASS", g_pass + g_fail, host_fail); + if (!chip) { + printf("M20 Tensor GB10 host self checks: %s (no device opened)\n", g_fail ? "FAIL" : "PASS"); + return g_fail ? 1 : 0; + } + + const OmegaTensorRealization *g = omega_tensor_gb10_realization(); + Cmp p = compare(g, 0, "TENSOR_GB10", true); + bool parity = p.cases == g_ncases && p.both_ok == g_ncases && p.differ == 0; + CHECK(parity, "GB10 parity: %zu cases, %zu OK on both, %zu differ", p.cases, p.both_ok, p.differ); + printf("TENSOR_GB10_PARITY: %s (%zu of %zu cases bit-exact value ids)\n", parity ? "PASS" : "FAIL", + p.both_ok - p.differ, p.cases); + size_t caught = run_mutants(g, "TENSOR_GB10"); + printf("TENSOR_GB10_MUTANTS: %s (%zu of %zu caught on chip)\n", caught == NMUTANTS ? "PASS" : "FAIL", + caught, NMUTANTS); + printf("%d checks, %d failed\n", g_pass + g_fail, g_fail); + printf("M20 Tensor GB10 Verdict: %s\n", g_fail == 0 && parity && caught == NMUTANTS ? "PASS" : "FAIL"); + return g_fail ? 1 : 0; +} diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh index 871c36878..d497e96fa 100755 --- a/tools/tensor_mutations.sh +++ b/tools/tensor_mutations.sh @@ -8,6 +8,68 @@ set -u cd "$(dirname "$0")/.." || exit 2 SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/tensor-mut.XXXXXX") || exit 2 trap 'rm -rf "$SCRATCH"' EXIT INT TERM + +# --gb10 PHYSICS_DIR: the GB10 realization table (src/tensor/omega_tensor_gb10.c, +# M20 cut gb10). Builds tests/test_omega_tensor_gb10.c against the physics +# checkout and runs it WITHOUT --chip (host self checks, no device). Also +# requires, via nm, that the GB10 table references no CPU or reference tier +# (no silent CPU fallback). Each GB10_MUTATIONS rule must then make the host +# run or the nm check fail. Never opens the device. +if [ "${1:-}" = "--gb10" ]; then + PHYS=${2:-} + [ -n "$PHYS" ] && [ -d "$PHYS" ] || { echo "tensor gb10 mutation sweep: --gb10 needs the physics checkout"; exit 2; } + NV=$PHYS/third_party/nvidia-open-580.173.02 + GFLAGS="-std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -I$PHYS/forge -I$PHYS/nvrm -I$PHYS/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" + GDEPS="src/omega_numeric_reduce.c src/omega_numeric_transc.c src/omega_numeric_reduce_gb10.c src/omega_numeric.c src/omega_numeric_gb10.c \ +src/omega_numeric_divsqrt_gb10.c src/omega_numeric_provenance.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ +src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/forge_realization.c src/aegis_verification.c src/sha256.c \ +$PHYS/forge/forge_descriptor.c $PHYS/forge/forge_realize.c $PHYS/sha256_clean.c $PHYS/nvrm/nvrm.c $PHYS/m16/m16_native.c" + CPU_TIER='\b(omega_numeric_cpu_realize|omega_numeric_reference|omega_numeric_reference_ftz|omega_reduce_cpu|omega_reduce_rows_cpu|omega_reduce_reference|omega_reduce_rows_reference|omega_tensor_seam_reduce_cpu)\b' + GB10_MUTATIONS='GB10_NO_CPU_FALLBACK|s/return OMEGA_NUMERIC_ERR_NOT_ENCODED;/return omega_numeric_cpu_realize(op, a, b, c, out, n);/ +GB10_REDUCE_MAX_N|s/if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS;/(void)0;/ +GB10_ROWS_MAX_N|s/if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS;/(void)0;/' + # gb10_try DIR: 0 if build + host run + nm check all pass, 1 otherwise + gb10_try() { + gcc $GFLAGS -I"$1" -o "$SCRATCH/g" tests/test_omega_tensor_gb10.c "$1/omega_tensor.c" "$1/omega_tensor_cpu.c" \ + "$1/omega_tensor_reduce_seam.c" "$1/omega_tensor_gb10.c" $GDEPS > "$SCRATCH/gbuild.log" 2>&1 || return 2 + gcc $GFLAGS -I"$1" -c -o "$SCRATCH/g.o" "$1/omega_tensor_gb10.c" >> "$SCRATCH/gbuild.log" 2>&1 || return 2 + if nm -u "$SCRATCH/g.o" | grep -Eq "$CPU_TIER"; then echo " nm: GB10 table references a CPU/reference tier"; return 1; fi + "$SCRATCH/g" > "$SCRATCH/grun.log" 2>&1 || return 1 + return 0 + } + gb10_try src/tensor; rc=$? + if [ "$rc" -ne 0 ]; then + head -20 "$SCRATCH/gbuild.log" "$SCRATCH/grun.log" 2>/dev/null + echo "tensor gb10 mutation sweep: FAIL (unmutated GB10 baseline does not pass, rc $rc)"; exit 1 + fi + grep -E '^(TENSOR_GB10_HOST|HOST_HARNESS_MUTANTS|HOST_MUTANT_)' "$SCRATCH/grun.log" + echo "GB10 nm check: PASS (no CPU or reference tier referenced by omega_tensor_gb10.c)" + gfail=0; gtotal=0 + old_ifs=$IFS + IFS=' +' + for m in $GB10_MUTATIONS; do + IFS=$old_ifs + gname=${m%%|*}; gexpr=${m#*|} + gtotal=$((gtotal + 1)) + rm -rf "$SCRATCH/tensor" && cp -r src/tensor "$SCRATCH/tensor" + sed -i "/MUT:$gname/ $gexpr" "$SCRATCH/tensor/omega_tensor_gb10.c" + if cmp -s src/tensor/omega_tensor_gb10.c "$SCRATCH/tensor/omega_tensor_gb10.c"; then + echo "MUTATION $gname: NOT APPLIED (marker or pattern missing)"; gfail=1; continue + fi + gb10_try "$SCRATCH/tensor"; rc=$? + case $rc in + 0) echo "MUTATION $gname: NOT CAUGHT (host checks and nm still pass)"; gfail=1 ;; + 2) head -5 "$SCRATCH/gbuild.log"; echo "MUTATION $gname: does not build (fix the sed expression)"; gfail=1 ;; + *) echo "MUTATION $gname: caught ($(grep -c '^FAIL' "$SCRATCH/grun.log" 2>/dev/null) failing checks)" ;; + esac + done + IFS=$old_ifs + if [ "$gfail" -ne 0 ]; then echo "tensor gb10 mutation sweep: FAIL"; exit 1; fi + echo "tensor gb10 mutation sweep: PASS ($gtotal of $gtotal mutations caught)" + exit 0 +fi DEPS="src/omega_numeric_reduce.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" FLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -O2 -DOMEGA_NUMERIC_CPU_ONLY -DOMEGA_TENSOR_TEST_HOOKS" From 1e06f1637881db81bdb8952732c6d78afd690998 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 13:20:50 -0500 Subject: [PATCH 2/5] M20 gb10: device-failure instrumentation (diagnostics only) Every OMEGA_NUMERIC_ERR_DEVICE return in the three E1 GB10 executors (SIMT, reduce, DIV/SQRT) now prints one GB10_DEVFAIL line to stderr: the step (open, channel, alloc_pb, alloc_buffers, build_kernel, qmd, submit, marker_wait, sem_wait), driver return code, errno, nvrm error text, live allocation count, the wait value and marker word for waits, and elapsed ms. omega_reduce_gb10 names the failing inner launch (GB10_REDUCE_FAIL). The GB10 tensor table logs every E1 call it makes (GB10_CALL: index, kind, op, count, rc, ms). The parity test records the E1 code before the context is destroyed and prints cpu_e1/test_e1 on NOT_OK lines, and marks each case on stderr. tests/run_tensor_chip.sh stores the chip stderr as a blob (chip_stderr_sha256) and counts GB10_DEVFAIL lines and failed calls. No retries, no wait-value changes, return codes unchanged. No parity check, expected value or mutant changed. Co-Authored-By: Claude Opus 5.5 --- src/omega_numeric_divsqrt_gb10.c | 59 +++++++++++++++++++++------ src/omega_numeric_gb10.c | 61 +++++++++++++++++++++------- src/omega_numeric_reduce_gb10.c | 69 ++++++++++++++++++++++++-------- src/tensor/omega_tensor_gb10.c | 45 ++++++++++++++++++--- tests/run_tensor_chip.sh | 15 +++++-- tests/test_omega_tensor_gb10.c | 18 ++++++--- 6 files changed, 210 insertions(+), 57 deletions(-) diff --git a/src/omega_numeric_divsqrt_gb10.c b/src/omega_numeric_divsqrt_gb10.c index cbc9efae4..21069767e 100644 --- a/src/omega_numeric_divsqrt_gb10.c +++ b/src/omega_numeric_divsqrt_gb10.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #ifndef OMEGA_NUMERIC_CPU_ONLY #include "omega_blackwell_submit.h" @@ -983,6 +985,39 @@ int omega_ds_check_qmd(const uint32_t *qmd1, uint64_t code_va, char *err, size_t /* ---- Executor ------------------------------------------------------------------ */ +#ifndef OMEGA_NUMERIC_CPU_ONLY +/* Device-failure diagnostics (M20 GB10 instrumentation). Every + * OMEGA_NUMERIC_ERR_DEVICE return below goes through gb10_devfail, which + * prints one GB10_DEVFAIL line to stderr: the step that failed, the driver + * return code, errno, the nvrm error text, the wait value and the marker word + * for waits, and the elapsed ms since the launch began. It only reports: the + * return code stays OMEGA_NUMERIC_ERR_DEVICE, there is no retry and no wait + * value changes. */ +static double gb10_ms_since(const struct timespec *t0) { + struct timespec t; + timespec_get(&t, TIME_UTC); /* C11; no feature macro needed */ + return (double)(t.tv_sec - t0->tv_sec) * 1e3 + (double)(t.tv_nsec - t0->tv_nsec) / 1e6; +} + +static int gb10_devfail(const char *fn, const char *step, M16NativeContext *ctx, int do_close, int drv_rc, + int saved_errno, long wait_ms, const volatile uint32_t *word, uint32_t want, + const struct timespec *t0) { + double ms = gb10_ms_since(t0); + fprintf(stderr, "GB10_DEVFAIL fn=%s step=%s drv_rc=%d errno=%d rm_err=\"%s\" live_allocs=%u faulted=%u", + fn, step, drv_rc, saved_errno, ctx->rm.err, (unsigned)ctx->rm.live_count, (unsigned)ctx->rm.faulted); + if (wait_ms >= 0) + fprintf(stderr, " wait_ms=%ld word=0x%08x want=0x%08x", wait_ms, word ? (unsigned)*word : 0u, (unsigned)want); + fprintf(stderr, " elapsed_ms=%.3f\n", ms); + if (do_close) m16_native_close(ctx); + return OMEGA_NUMERIC_ERR_DEVICE; +} +/* Plain step: drv_rc is the value the call returned. */ +#define GB10_FAIL(step, close_, rc_) gb10_devfail(__func__, (step), &ctx, (close_), (rc_), errno, -1, NULL, 0u, &t0) +/* Wait step: also log the wait value and the word read. */ +#define GB10_FAIL_WAIT(step, rc_, ms_, w_, want_) \ + gb10_devfail(__func__, (step), &ctx, 1, (rc_), errno, (long)(ms_), (w_), (want_), &t0) +#endif + int omega_ds_gb10_run(OmegaDsOp op, const uint32_t *a, const uint32_t *b, uint32_t *out, size_t count) { char err[256]; int rc = omega_ds_check_args(op, a, b, out, count, err, sizeof(err)); @@ -1017,11 +1052,14 @@ int omega_ds_gb10_run(OmegaDsOp op, const uint32_t *a, const uint32_t *b, uint32 0x2001255e, 0x20000000, 0x2001255f, 0x000fffff, 0x20012557, 0x00000003, 0x20012558, 0x22000000, 0x20012559, 0x00000000, }; + struct timespec t0; + timespec_get(&t0, TIME_UTC); M16NativeContext ctx; - if (m16_native_open(&ctx) != 0) return OMEGA_NUMERIC_ERR_DEVICE; - if (m16_native_create_channel(&ctx) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + int drc_; + if ((drc_ = m16_native_open(&ctx)) != 0) return GB10_FAIL("open", 0, drc_); + if ((drc_ = m16_native_create_channel(&ctx)) != 0) return GB10_FAIL("channel", 1, drc_); NvrmMem large_pb; - if (nvrm_alloc(&ctx.rm, 0x10000, &large_pb) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + if ((drc_ = nvrm_alloc(&ctx.rm, 0x10000, &large_pb)) != 0) return GB10_FAIL("alloc_pb", 1, drc_); ctx.pb_mem = large_pb; size_t bytes = (count * 4 + 0xfffULL) & ~0xfffULL; NvrmMem code_mem, cbank_mem, a_mem, b_mem, out_mem, marker_mem, qmd_mem; @@ -1032,8 +1070,7 @@ int omega_ds_gb10_run(OmegaDsOp op, const uint32_t *a, const uint32_t *b, uint32 nvrm_alloc(&ctx.rm, bytes, &out_mem) != 0 || nvrm_alloc(&ctx.rm, 0x1000, &marker_mem) != 0 || nvrm_alloc(&ctx.rm, 0x10000, &qmd_mem) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("alloc_buffers", 1, -1); } memcpy(a_mem.cpu, a, count * 4); if (b) memcpy(b_mem.cpu, b, count * 4); else memset(b_mem.cpu, 0, count * 4); @@ -1105,19 +1142,17 @@ int omega_ds_gb10_run(OmegaDsOp op, const uint32_t *a, const uint32_t *b, uint32 pb[n++] = (uint32_t)marker_mem.va; pb[n++] = (uint32_t)(marker_mem.va >> 32); pb[n++] = OMEGA_BW_MARKER_COMPLETION_PAYLOAD; pb[n++] = 0; pb[n++] = 0x1 | (1u << 20); - if (m16_native_submit_methods(&ctx, pb, n) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + if ((drc_ = m16_native_submit_methods(&ctx, pb, n)) != 0) return GB10_FAIL("submit", 1, drc_); /* Wait long: closing the channel under a running kernel jams the seat. */ - if (m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 600000) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + if ((drc_ = m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 600000)) != 0) { + return GB10_FAIL_WAIT("marker_wait", drc_, 600000, hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD); } /* The host marker can land before the last CTAs' stores are visible: the * first chip run (receipt 88930d2f...) read the 0x55 fill pattern for * 49,359,680 SQRT outputs. Read only after the QMD's own release * semaphore (written after the grid completes, with its membar) is 6. */ - if (m16_native_wait_marker(hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE, 600000) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + if ((drc_ = m16_native_wait_marker(hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE, 600000)) != 0) { + return GB10_FAIL_WAIT("sem_wait", drc_, 600000, hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE); } __asm__ volatile("dsb sy" ::: "memory"); memcpy(out, out_mem.cpu, count * 4); diff --git a/src/omega_numeric_gb10.c b/src/omega_numeric_gb10.c index ad3410e8d..787065ad2 100644 --- a/src/omega_numeric_gb10.c +++ b/src/omega_numeric_gb10.c @@ -18,8 +18,41 @@ #include #include #include +#include +#include #define OMEGA_BW_SETUP_WORDS_COUNT 18 +/* Device-failure diagnostics (M20 GB10 instrumentation). Every + * OMEGA_NUMERIC_ERR_DEVICE return below goes through gb10_devfail, which + * prints one GB10_DEVFAIL line to stderr: the step that failed, the driver + * return code, errno, the nvrm error text, the wait value and the marker word + * for waits, and the elapsed ms since the launch began. It only reports: the + * return code stays OMEGA_NUMERIC_ERR_DEVICE, there is no retry and no wait + * value changes. */ +static double gb10_ms_since(const struct timespec *t0) { + struct timespec t; + timespec_get(&t, TIME_UTC); /* C11; no feature macro needed */ + return (double)(t.tv_sec - t0->tv_sec) * 1e3 + (double)(t.tv_nsec - t0->tv_nsec) / 1e6; +} + +static int gb10_devfail(const char *fn, const char *step, M16NativeContext *ctx, int do_close, int drv_rc, + int saved_errno, long wait_ms, const volatile uint32_t *word, uint32_t want, + const struct timespec *t0) { + double ms = gb10_ms_since(t0); + fprintf(stderr, "GB10_DEVFAIL fn=%s step=%s drv_rc=%d errno=%d rm_err=\"%s\" live_allocs=%u faulted=%u", + fn, step, drv_rc, saved_errno, ctx->rm.err, (unsigned)ctx->rm.live_count, (unsigned)ctx->rm.faulted); + if (wait_ms >= 0) + fprintf(stderr, " wait_ms=%ld word=0x%08x want=0x%08x", wait_ms, word ? (unsigned)*word : 0u, (unsigned)want); + fprintf(stderr, " elapsed_ms=%.3f\n", ms); + if (do_close) m16_native_close(ctx); + return OMEGA_NUMERIC_ERR_DEVICE; +} +/* Plain step: drv_rc is the value the call returned. */ +#define GB10_FAIL(step, close_, rc_) gb10_devfail(__func__, (step), &ctx, (close_), (rc_), errno, -1, NULL, 0u, &t0) +/* Wait step: also log the wait value and the word read. */ +#define GB10_FAIL_WAIT(step, rc_, ms_, w_, want_) \ + gb10_devfail(__func__, (step), &ctx, 1, (rc_), errno, (long)(ms_), (w_), (want_), &t0) + static const uint32_t NUMERIC_SETUP_WORDS[OMEGA_BW_SETUP_WORDS_COUNT] = { 0x20012061, 0x0000cec0, 0x20012092, 0x00000001, 0x200120a8, 0x0000000f, 0x2001255d, 0x00000003, 0x2001255e, 0x20000000, 0x2001255f, 0x000fffff, 0x20012557, 0x00000003, 0x20012558, 0x22000000, @@ -63,12 +96,15 @@ int omega_gb10_execute_simt_op(const char *op_name, return drc; } + struct timespec t0; + timespec_get(&t0, TIME_UTC); M16NativeContext ctx; - if (m16_native_open(&ctx) != 0) return OMEGA_NUMERIC_ERR_DEVICE; - if (m16_native_create_channel(&ctx) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + int drc_; + if ((drc_ = m16_native_open(&ctx)) != 0) return GB10_FAIL("open", 0, drc_); + if ((drc_ = m16_native_create_channel(&ctx)) != 0) return GB10_FAIL("channel", 1, drc_); NvrmMem large_pb; - if (nvrm_alloc(&ctx.rm, 0x10000, &large_pb) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + if ((drc_ = nvrm_alloc(&ctx.rm, 0x10000, &large_pb)) != 0) return GB10_FAIL("alloc_pb", 1, drc_); ctx.pb_mem = large_pb; size_t bytes = (count * sizeof(float) + 0xfffULL) & ~0xfffULL; @@ -83,8 +119,7 @@ int omega_gb10_execute_simt_op(const char *op_name, nvrm_alloc(&ctx.rm, bytes, &out_mem) != 0 || nvrm_alloc(&ctx.rm, 0x1000, &marker_mem) != 0 || nvrm_alloc(&ctx.rm, 0x10000, &qmd_mem) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("alloc_buffers", 1, -1); } memcpy(a_mem.cpu, in_a, count * sizeof(float)); @@ -96,8 +131,7 @@ int omega_gb10_execute_simt_op(const char *op_name, /* Calibrated sm_121 vecadd with this op's patch; no default instruction. */ size_t out_code_len = 0; if (omega_numeric_build_kernel(info->op, code_mem.cpu, code_mem.size, &out_code_len) != OMEGA_NUMERIC_OK) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("build_kernel", 1, -1); } /* Driver constant bank. Word 223 (c[0x0][0x37c]) is loaded into R1 at @@ -143,8 +177,7 @@ int omega_gb10_execute_simt_op(const char *op_name, if (omega_blackwell_build_qmd0(qmd0_words, qmd0_va, qmd1_va) != 0 || omega_blackwell_build_qmd1(qmd1_words, &qmd_cfg) != 0 || omega_blackwell_verify_qmd_invariants(qmd1_words) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("qmd", 1, -1); } { /* same structural check as submit_check, on the QMD actually submitted */ @@ -227,14 +260,12 @@ int omega_gb10_execute_simt_op(const char *op_name, pb[pb_len++] = 0; pb[pb_len++] = 0x1 | (1u << 20); - if (m16_native_submit_methods(&ctx, pb, pb_len) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + if ((drc_ = m16_native_submit_methods(&ctx, pb, pb_len)) != 0) { + return GB10_FAIL("submit", 1, drc_); } - if (m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + if ((drc_ = m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000)) != 0) { + return GB10_FAIL_WAIT("marker_wait", drc_, 5000, hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD); } memcpy(out_res, out_mem.cpu, count * sizeof(float)); diff --git a/src/omega_numeric_reduce_gb10.c b/src/omega_numeric_reduce_gb10.c index 23e76742f..2cd2aa114 100644 --- a/src/omega_numeric_reduce_gb10.c +++ b/src/omega_numeric_reduce_gb10.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include static unsigned g_last_launches; @@ -279,16 +281,50 @@ static int chunk_check(OmegaReduceOp op, const OmegaNumericPatchInsn *patch, int * omega_numeric_gb10.c (not edited by this lane) that also waits for the QMD * release semaphore before reading results; the shared executor reads after * the host marker only. */ +/* Device-failure diagnostics (M20 GB10 instrumentation). Every + * OMEGA_NUMERIC_ERR_DEVICE return below goes through gb10_devfail, which + * prints one GB10_DEVFAIL line to stderr: the step that failed, the driver + * return code, errno, the nvrm error text, the wait value and the marker word + * for waits, and the elapsed ms since the launch began. It only reports: the + * return code stays OMEGA_NUMERIC_ERR_DEVICE, there is no retry and no wait + * value changes. */ +static double gb10_ms_since(const struct timespec *t0) { + struct timespec t; + timespec_get(&t, TIME_UTC); /* C11; no feature macro needed */ + return (double)(t.tv_sec - t0->tv_sec) * 1e3 + (double)(t.tv_nsec - t0->tv_nsec) / 1e6; +} + +static int gb10_devfail(const char *fn, const char *step, M16NativeContext *ctx, int do_close, int drv_rc, + int saved_errno, long wait_ms, const volatile uint32_t *word, uint32_t want, + const struct timespec *t0) { + double ms = gb10_ms_since(t0); + fprintf(stderr, "GB10_DEVFAIL fn=%s step=%s drv_rc=%d errno=%d rm_err=\"%s\" live_allocs=%u faulted=%u", + fn, step, drv_rc, saved_errno, ctx->rm.err, (unsigned)ctx->rm.live_count, (unsigned)ctx->rm.faulted); + if (wait_ms >= 0) + fprintf(stderr, " wait_ms=%ld word=0x%08x want=0x%08x", wait_ms, word ? (unsigned)*word : 0u, (unsigned)want); + fprintf(stderr, " elapsed_ms=%.3f\n", ms); + if (do_close) m16_native_close(ctx); + return OMEGA_NUMERIC_ERR_DEVICE; +} +/* Plain step: drv_rc is the value the call returned. */ +#define GB10_FAIL(step, close_, rc_) gb10_devfail(__func__, (step), &ctx, (close_), (rc_), errno, -1, NULL, 0u, &t0) +/* Wait step: also log the wait value and the word read. */ +#define GB10_FAIL_WAIT(step, rc_, ms_, w_, want_) \ + gb10_devfail(__func__, (step), &ctx, 1, (rc_), errno, (long)(ms_), (w_), (want_), &t0) + static int run_chunk(OmegaReduceOp op, const float *in, float *out_res, size_t count) { OmegaNumericPatchInsn patch[OMEGA_NUMERIC_PATCH_MAX]; int np = chunk_patch(op, patch); if (np <= 0 || count == 0 || count > OMEGA_NUMERIC_MAX_COUNT || count % 32u) return OMEGA_NUMERIC_ERR_BAD_ARGS; + struct timespec t0; + timespec_get(&t0, TIME_UTC); M16NativeContext ctx; - if (m16_native_open(&ctx) != 0) return OMEGA_NUMERIC_ERR_DEVICE; - if (m16_native_create_channel(&ctx) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + int drc_; + if ((drc_ = m16_native_open(&ctx)) != 0) return GB10_FAIL("open", 0, drc_); + if ((drc_ = m16_native_create_channel(&ctx)) != 0) return GB10_FAIL("channel", 1, drc_); NvrmMem large_pb; - if (nvrm_alloc(&ctx.rm, 0x10000, &large_pb) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } + if ((drc_ = nvrm_alloc(&ctx.rm, 0x10000, &large_pb)) != 0) return GB10_FAIL("alloc_pb", 1, drc_); ctx.pb_mem = large_pb; size_t bytes = (count * sizeof(float) + 0xfffULL) & ~0xfffULL; @@ -298,8 +334,7 @@ static int run_chunk(OmegaReduceOp op, const float *in, float *out_res, size_t c nvrm_alloc(&ctx.rm, bytes, &a_mem) != 0 || nvrm_alloc(&ctx.rm, bytes, &b_mem) != 0 || nvrm_alloc(&ctx.rm, bytes, &c_mem) != 0 || nvrm_alloc(&ctx.rm, bytes, &out_mem) != 0 || nvrm_alloc(&ctx.rm, 0x1000, &marker_mem) != 0 || nvrm_alloc(&ctx.rm, 0x10000, &qmd_mem) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("alloc_buffers", 1, -1); } memcpy(a_mem.cpu, in, count * sizeof(float)); memset(b_mem.cpu, 0, count * sizeof(float)); @@ -308,8 +343,7 @@ static int run_chunk(OmegaReduceOp op, const float *in, float *out_res, size_t c size_t code_len = 0; if (omega_blackwell_encode_vecadd(code_mem.cpu, code_mem.size, &code_len) != 0 || code_len < OMEGA_NUMERIC_PATCH_OFFSET + (size_t)np * 16u) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("build_kernel", 1, -1); } for (int i = 0; i < np; i++) memcpy((uint8_t *)code_mem.cpu + OMEGA_NUMERIC_PATCH_OFFSET + (size_t)i * 16u, patch[i].w, 16); @@ -333,8 +367,7 @@ static int run_chunk(OmegaReduceOp op, const float *in, float *out_res, size_t c if (omega_blackwell_build_qmd0(qmd0_words, qmd0_va, qmd1_va) != 0 || omega_blackwell_build_qmd1(qmd1_words, &qmd_cfg) != 0 || omega_blackwell_verify_qmd_invariants(qmd1_words) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + return GB10_FAIL("qmd", 1, -1); } { /* the structural check again, on the QMD actually submitted and the code image */ char perr[256]; @@ -412,17 +445,15 @@ static int run_chunk(OmegaReduceOp op, const float *in, float *out_res, size_t c pb[pb_len++] = 0; pb[pb_len++] = 0x1 | (1u << 20); - if (m16_native_submit_methods(&ctx, pb, pb_len) != 0) { m16_native_close(&ctx); return OMEGA_NUMERIC_ERR_DEVICE; } - if (m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + if ((drc_ = m16_native_submit_methods(&ctx, pb, pb_len)) != 0) return GB10_FAIL("submit", 1, drc_); + if ((drc_ = m16_native_wait_marker(hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD, 5000)) != 0) { + return GB10_FAIL_WAIT("marker_wait", drc_, 5000, hmarker, OMEGA_BW_MARKER_COMPLETION_PAYLOAD); } /* The host marker can land before the last CTAs' stores are visible (seen * by the DIV/SQRT gate, PR #141). Read only after the QMD's own release * semaphore, written after the grid completes, is DONE. */ - if (m16_native_wait_marker(hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE, 5000) != 0) { - m16_native_close(&ctx); - return OMEGA_NUMERIC_ERR_DEVICE; + if ((drc_ = m16_native_wait_marker(hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE, 5000)) != 0) { + return GB10_FAIL_WAIT("sem_wait", drc_, 5000, hsem, OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE); } __asm__ volatile("dsb sy" ::: "memory"); memcpy(out_res, out_mem.cpu, count * sizeof(float)); @@ -465,7 +496,11 @@ int omega_reduce_gb10(OmegaReduceOp op, const float *x, size_t n, float *out) { if (count > OMEGA_NUMERIC_MAX_COUNT) count = OMEGA_NUMERIC_MAX_COUNT; rc = run_chunk(op, cur + base, res, count); g_last_launches++; - if (rc != OMEGA_NUMERIC_OK) { free(cur); free(res); return rc; } + if (rc != OMEGA_NUMERIC_OK) { + fprintf(stderr, "GB10_REDUCE_FAIL op=%d n=%zu level_len=%zu base=%zu count=%zu inner_launch=%u rc=%d\n", + (int)op, n, len, base, count, g_last_launches, rc); + free(cur); free(res); return rc; + } /* lane 0 of warp w holds tile (base/32 + w); base/32 + w <= base + 32w */ for (size_t w = 0; w < count / 32; w++) cur[base / 32 + w] = res[w * 32]; } diff --git a/src/tensor/omega_tensor_gb10.c b/src/tensor/omega_tensor_gb10.c index 0ae052602..eac79ac4e 100644 --- a/src/tensor/omega_tensor_gb10.c +++ b/src/tensor/omega_tensor_gb10.c @@ -25,8 +25,10 @@ */ #include "omega_tensor.h" +#include #include #include +#include #include "omega_numeric.h" #include "omega_numeric_reduce.h" @@ -60,6 +62,40 @@ const char *omega_tensor_gb10_op_name(OmegaNumericOp op) { return GB10_OP_NAME[op]; } +/* Launch log (M20 GB10 instrumentation). Every E1 call this table makes gets + * a process-wide index and one GB10_CALL line on stderr: kind, op, count, + * return code and elapsed ms. A failed call keeps its failing return code: + * no retry, no fallback. The E1 executors add a GB10_DEVFAIL line naming the + * device step when the failure is a device error. */ +static unsigned long g_gb10_call_index; + +static double gb10_ms_since(const struct timespec *t0) { + struct timespec t; + timespec_get(&t, TIME_UTC); + return (double)(t.tv_sec - t0->tv_sec) * 1e3 + (double)(t.tv_nsec - t0->tv_nsec) / 1e6; +} + +static int gb10_simt_call(const char *name, const float *a, const float *b, const float *c, float *out, + size_t cnt) { + unsigned long idx = ++g_gb10_call_index; + struct timespec t0; + timespec_get(&t0, TIME_UTC); + int rc = omega_gb10_execute_simt_op(name, a, b, c, out, cnt); + fprintf(stderr, "GB10_CALL idx=%lu kind=simt op=%s count=%zu rc=%d ms=%.3f%s\n", idx, name, cnt, rc, + gb10_ms_since(&t0), rc == OMEGA_NUMERIC_OK ? "" : " FAILED"); + return rc; +} + +static int gb10_reduce_call(OmegaReduceOp r, const float *x, size_t n, float *out) { + unsigned long idx = ++g_gb10_call_index; + struct timespec t0; + timespec_get(&t0, TIME_UTC); + int rc = omega_reduce_gb10(r, x, n, out); + fprintf(stderr, "GB10_CALL idx=%lu kind=reduce op=%d n=%zu inner_launches=%u rc=%d ms=%.3f%s\n", idx, (int)r, + n, omega_reduce_gb10_last_launches(), rc, gb10_ms_since(&t0), rc == OMEGA_NUMERIC_OK ? "" : " FAILED"); + return rc; +} + static int gb10_elementwise(OmegaNumericOp op, const float *a, const float *b, const float *c, float *out, size_t n) { const char *name = omega_tensor_gb10_op_name(op); @@ -69,8 +105,7 @@ static int gb10_elementwise(OmegaNumericOp op, const float *a, const float *b, c if (!a || !out || n == 0) return OMEGA_NUMERIC_ERR_BAD_ARGS; for (size_t base = 0; base < n; base += OMEGA_NUMERIC_MAX_COUNT) { size_t cnt = n - base < OMEGA_NUMERIC_MAX_COUNT ? n - base : OMEGA_NUMERIC_MAX_COUNT; - int rc = omega_gb10_execute_simt_op(name, a + base, b ? b + base : NULL, c ? c + base : NULL, - out + base, cnt); + int rc = gb10_simt_call(name, a + base, b ? b + base : NULL, c ? c + base : NULL, out + base, cnt); if (rc != OMEGA_NUMERIC_OK) return rc; } return OMEGA_NUMERIC_OK; @@ -93,7 +128,7 @@ static int gb10_reduce(OmegaTensorReduceOp op, const float *x, size_t n, float * if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS; /* MUT:GB10_REDUCE_MAX_N */ OmegaReduceOp r; if (map_reduce_op(op, &r) != OMEGA_NUMERIC_OK || !x || !out || n == 0) return OMEGA_NUMERIC_ERR_BAD_ARGS; - return omega_reduce_gb10(r, x, n, out); + return gb10_reduce_call(r, x, n, out); } /* SUM of rows rows of n values, all rows per level in shared launches. @@ -118,7 +153,7 @@ static int gb10_sum_rows(const float *x, size_t rows, size_t n, float *out) { } for (size_t base = 0; base < total && rc == OMEGA_NUMERIC_OK; base += OMEGA_NUMERIC_MAX_COUNT) { size_t cnt = total - base < OMEGA_NUMERIC_MAX_COUNT ? total - base : OMEGA_NUMERIC_MAX_COUNT; - rc = omega_gb10_execute_simt_op("REDUCE_SUM", lvl + base, NULL, NULL, res + base, cnt); + rc = gb10_simt_call("REDUCE_SUM", lvl + base, NULL, NULL, res + base, cnt); } if (rc != OMEGA_NUMERIC_OK) goto done; for (size_t r = 0; r < rows; r++) @@ -142,7 +177,7 @@ static int gb10_reduce_rows(OmegaTensorReduceOp op, const float *x, size_t rows, return OMEGA_NUMERIC_ERR_BAD_ARGS; if (op == OMEGA_TR_SUM) return gb10_sum_rows(x, rows, n, out); for (size_t i = 0; i < rows; i++) { - int rc = omega_reduce_gb10(r, x + i * n, n, &out[i]); + int rc = gb10_reduce_call(r, x + i * n, n, &out[i]); if (rc != OMEGA_NUMERIC_OK) return rc; } return OMEGA_NUMERIC_OK; diff --git a/tests/run_tensor_chip.sh b/tests/run_tensor_chip.sh index 6d6e97909..411279ab0 100755 --- a/tests/run_tensor_chip.sh +++ b/tests/run_tensor_chip.sh @@ -19,7 +19,8 @@ # "M20 Tensor GB10 Verdict: PASS", and clean trees with unmoved HEADs after. # 5. Writes a content-addressed receipt /.json (mode # 0444, never overwritten) for PASS and FAIL alike, plus the log and binary -# as blobs/.{log,bin}. The evidence dir must lie outside the trees. +# as blobs/.{log,bin}, and the chip run stderr (GB10_CALL per-call +# timing, GB10_DEVFAIL device step diagnostics) as blobs/.stderr. The evidence dir must lie outside the trees. # Shell + coreutils + git + jq + gcc. No Python. Exit 0 PASS, 1 FAIL, 2 refused. set -u SELF_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) @@ -115,10 +116,16 @@ store_blob() { fi echo "$d" } -BIN_SHA=""; LOG_SHA="" +BIN_SHA=""; LOG_SHA=""; ERR_SHA="" if [ -f "$BIN" ]; then BIN_SHA=$(store_blob "$BIN" bin) || exit 2; fi [ -z "$BIN_SHA_BUILT" ] || [ "$BIN_SHA" = "$BIN_SHA_BUILT" ] || FAIL_REASON="${FAIL_REASON:-binary changed between build and receipt}" if [ -f "$OUT/tensor.log" ]; then LOG_SHA=$(store_blob "$OUT/tensor.log" log) || exit 2; fi +if [ -f "$OUT/tensor.stderr" ]; then ERR_SHA=$(store_blob "$OUT/tensor.stderr" stderr) || exit 2; fi +DEVFAIL_N=0; FAILED_CALLS_N=0 +if [ -f "$OUT/tensor.stderr" ]; then + DEVFAIL_N=$(grep -c "^GB10_DEVFAIL " "$OUT/tensor.stderr") + FAILED_CALLS_N=$(grep -c "^GB10_CALL .* FAILED$" "$OUT/tensor.stderr") +fi VERDICT=PASS; [ -n "$FAIL_REASON" ] && VERDICT=FAIL line() { grep "^$1" "$OUT/tensor.log" 2>/dev/null | head -1; } TMP=$OUT/receipt.json @@ -129,7 +136,8 @@ jq -n --arg suite M20_TENSOR_GB10_PARITY --arg status "$VERDICT" --arg reason "$ --arg started "$STARTED" --arg finished "$FINISHED" \ --arg order "RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \ --arg mm_order "MATMUL_V1_FMUL_RNE_PRODUCTS_THEN_E1_REDUCE_SUM_RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \ - --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg exit_status "$STATUS" \ + --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg errlog "$ERR_SHA" \ + --argjson devfail_n "$DEVFAIL_N" --argjson failed_calls_n "$FAILED_CALLS_N" --arg exit_status "$STATUS" \ --arg host_line "$(line TENSOR_GB10_HOST:)" --arg parity "$(line TENSOR_GB10_PARITY:)" \ --arg mutants "$(line TENSOR_GB10_MUTANTS:)" --arg cases "$(line 'cases:')" \ --arg verdict_line "$(line 'M20 Tensor GB10 Verdict:')" \ @@ -139,6 +147,7 @@ jq -n --arg suite M20_TENSOR_GB10_PARITY --arg status "$VERDICT" --arg reason "$ omega_commit_unchanged_after:$head_same,physics_commit:$physics,physics_lock_pin:$pin, physics_tree_clean_before:true,physics_tree_clean_after:$pclean_after,physics_commit_unchanged_after:$phead_same, reduce_declared_order:$order,matmul_declared_order:$mm_order,binary_sha256:$bin,chip_log_sha256:$log, + chip_stderr_sha256:$errlog,devfail_lines:$devfail_n,failed_gb10_calls:$failed_calls_n, chip_exit_status:$exit_status,cases_line:$cases,host_line:$host_line,parity_line:$parity, mutants_line:$mutants,verdict_line:$verdict_line, realization:{elementwise:"E1 omega_gb10_execute_simt_op (chunks <= 65536)", diff --git a/tests/test_omega_tensor_gb10.c b/tests/test_omega_tensor_gb10.c index 0b4d20ba7..70096aec8 100644 --- a/tests/test_omega_tensor_gb10.c +++ b/tests/test_omega_tensor_gb10.c @@ -262,16 +262,20 @@ static uint64_t seed_of(const char *s) { return h ? h : 1; } -/* Runs one case through real; status and value id (zeroed unless OK). */ -static int run_case(const OmegaTensorRealization *real, const Case *c, uint8_t id[32]) { +/* Runs one case through real; status and value id (zeroed unless OK). + * *e1 gets the underlying E1 code of the last numeric failure (0 if none), + * read before the context is destroyed. Diagnostics only. */ +static int run_case(const OmegaTensorRealization *real, const Case *c, uint8_t id[32], int *e1) { OmegaTensorCtx *ctx; memset(id, 0, 32); + *e1 = 0; int rc = omega_tensor_ctx_create(64, real, &ctx); if (rc) return rc; g_rng = seed_of(c->name); OmegaTensor out = { 0, 0 }; rc = run_body(ctx, c, &out); if (!rc) rc = omega_tensor_value_id(ctx, out, id); + *e1 = omega_tensor_last_numeric_error(ctx); omega_tensor_ctx_destroy(ctx); return rc; } @@ -289,8 +293,10 @@ static Cmp compare(const OmegaTensorRealization *test, unsigned mask, const char const Case *c = &g_cases[i]; if (mask && !(c->mut & mask)) continue; uint8_t ia[32], ib[32]; - int ra = run_case(omega_tensor_cpu_realization(), c, ia); - int rb = run_case(test, c, ib); + int ea, eb; + int ra = run_case(omega_tensor_cpu_realization(), c, ia, &ea); + fprintf(stderr, "GB10_CASE_BEGIN %s %s\n", tag, c->name); /* ties stderr call lines to the case */ + int rb = run_case(test, c, ib, &eb); r.cases++; bool ok = ra == OMEGA_TENSOR_OK && rb == OMEGA_TENSOR_OK; bool eq = ok && memcmp(ia, ib, 32) == 0; @@ -299,8 +305,10 @@ static Cmp compare(const OmegaTensorRealization *test, unsigned mask, const char if (verbose || !eq) { char ha[17], hb[17]; hex8(ia, ha); hex8(ib, hb); - printf("%s_CASE %s cpu=%s rc=%d test=%s rc=%d %s\n", tag, c->name, ha, ra, hb, rb, + printf("%s_CASE %s cpu=%s rc=%d test=%s rc=%d %s", tag, c->name, ha, ra, hb, rb, eq ? "EQUAL" : ok ? "DIFFER" : "NOT_OK"); + if (!ok) printf(" cpu_e1=%d test_e1=%d", ea, eb); /* diagnostics only */ + printf("\n"); } } return r; From 7b7346376242f543167f2c0980b89a74d67fe5cc Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 13:41:10 -0500 Subject: [PATCH 3/5] M20 gb10: first-diff and pre-fill diagnostics for DIFFER cases Test code only. For a DIFFER case the parity program prints TENSOR_GB10_FIRST_DIFF (first differing index, cpu/gb10 bits, number of differing elements, last index) and TENSOR_GB10_FILL (output elements still holding 0x55555555, the pre-fill written by the E1 executors at src/omega_numeric_gb10.c:129, src/omega_numeric_reduce_gb10.c:341 and src/omega_numeric_divsqrt_gb10.c:1077). No src change, no check, expected value or mutant change, no retries. Co-Authored-By: Claude Opus 5.5 --- tests/test_omega_tensor_gb10.c | 73 ++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/tests/test_omega_tensor_gb10.c b/tests/test_omega_tensor_gb10.c index 70096aec8..70ecfb642 100644 --- a/tests/test_omega_tensor_gb10.c +++ b/tests/test_omega_tensor_gb10.c @@ -265,16 +265,33 @@ static uint64_t seed_of(const char *s) { /* Runs one case through real; status and value id (zeroed unless OK). * *e1 gets the underlying E1 code of the last numeric failure (0 if none), * read before the context is destroyed. Diagnostics only. */ -static int run_case(const OmegaTensorRealization *real, const Case *c, uint8_t id[32], int *e1) { +typedef struct { uint8_t *bytes; size_t n, esz; } RawOut; /* output elements, diagnostics only */ + +static size_t dtype_size(OmegaDType d) { return d == OMEGA_DT_F32 ? 4u : 2u; } + +static int run_case(const OmegaTensorRealization *real, const Case *c, uint8_t id[32], int *e1, RawOut *raw) { OmegaTensorCtx *ctx; memset(id, 0, 32); *e1 = 0; + if (raw) { raw->bytes = NULL; raw->n = 0; raw->esz = 0; } int rc = omega_tensor_ctx_create(64, real, &ctx); if (rc) return rc; g_rng = seed_of(c->name); OmegaTensor out = { 0, 0 }; rc = run_body(ctx, c, &out); if (!rc) rc = omega_tensor_value_id(ctx, out, id); + if (!rc && raw) { /* copy the output elements out; a failure here only loses the diagnostics */ + OmegaTensorInfo inf; + if (omega_tensor_info(ctx, out, &inf) == OMEGA_TENSOR_OK && inf.elements > 0) { + size_t esz = dtype_size(inf.dtype), bytes = (size_t)inf.elements * esz; + uint8_t *b = malloc(bytes); + if (b && omega_tensor_read(ctx, out, b, bytes) == OMEGA_TENSOR_OK) { + raw->bytes = b; raw->n = (size_t)inf.elements; raw->esz = esz; + } else { + free(b); + } + } + } *e1 = omega_tensor_last_numeric_error(ctx); omega_tensor_ctx_destroy(ctx); return rc; @@ -284,6 +301,51 @@ static void hex8(const uint8_t id[32], char s[17]) { for (int i = 0; i < 8; i++) snprintf(s + 2 * i, 3, "%02x", id[i]); } +/* ---- DIFFER diagnostics (print only; no check depends on them) ------------- + * The E1 executors pre-fill every output buffer with the byte 0x55 before + * submission (src/omega_numeric_gb10.c:129, src/omega_numeric_reduce_gb10.c:341, + * src/omega_numeric_divsqrt_gb10.c:1077). An output element still holding that + * pattern was most likely read before the chip wrote it. */ +static uint32_t elem_bits(const RawOut *o, size_t i) { + if (o->esz == 4) { uint32_t v; memcpy(&v, o->bytes + i * 4, 4); return v; } + uint16_t h; memcpy(&h, o->bytes + i * 2, 2); return h; +} + +/* TENSOR_GB10_FILL: elements of the output still holding the pre-fill pattern. + * Printed for every DIFFER case, and for any other case where the count is > 0. */ +static void fill_line(const char *name, const char *tag, const RawOut *o, bool always) { + uint32_t pat = o->esz == 4 ? 0x55555555u : 0x5555u; + size_t n = 0; + for (size_t i = 0; i < o->n; i++) n += elem_bits(o, i) == pat; + if (always || n > 0) + printf("TENSOR_GB10_FILL %s count=%zu of %zu pattern=0x%0*x tag=%s\n", name, n, o->n, + (int)(o->esz * 2), (unsigned)pat, tag); +} + +static void diff_detail(const char *name, const char *tag, const RawOut *a, const RawOut *b) { + if (!a->bytes || !b->bytes || a->n != b->n || a->esz != b->esz) { + printf("TENSOR_GB10_FIRST_DIFF %s unavailable (cpu n=%zu esz=%zu, gb10 n=%zu esz=%zu) tag=%s\n", name, + a->n, a->esz, b->n, b->esz, tag); + if (b->bytes) fill_line(name, tag, b, true); + return; + } + size_t first = a->n, last = 0, count = 0; + for (size_t i = 0; i < a->n; i++) + if (elem_bits(a, i) != elem_bits(b, i)) { + if (first == a->n) first = i; + last = i; + count++; + } + if (count == 0) { /* ids differ but bits agree: NaN payloads, which the value id canonicalizes */ + printf("TENSOR_GB10_FIRST_DIFF %s none: 0 differing elements of %zu tag=%s\n", name, a->n, tag); + } else { + int w = (int)(a->esz * 2); + printf("TENSOR_GB10_FIRST_DIFF %s idx=%zu of %zu cpu_bits=0x%0*x gb10_bits=0x%0*x differing=%zu last_idx=%zu tag=%s\n", + name, first, a->n, w, (unsigned)elem_bits(a, first), w, (unsigned)elem_bits(b, first), count, last, tag); + } + fill_line(name, tag, b, true); +} + typedef struct { size_t cases, both_ok, differ, not_ok; } Cmp; /* Reference CPU vs test table over the cases selected by mask (0 = all). */ @@ -294,9 +356,10 @@ static Cmp compare(const OmegaTensorRealization *test, unsigned mask, const char if (mask && !(c->mut & mask)) continue; uint8_t ia[32], ib[32]; int ea, eb; - int ra = run_case(omega_tensor_cpu_realization(), c, ia, &ea); + RawOut oa, ob; + int ra = run_case(omega_tensor_cpu_realization(), c, ia, &ea, &oa); fprintf(stderr, "GB10_CASE_BEGIN %s %s\n", tag, c->name); /* ties stderr call lines to the case */ - int rb = run_case(test, c, ib, &eb); + int rb = run_case(test, c, ib, &eb, &ob); r.cases++; bool ok = ra == OMEGA_TENSOR_OK && rb == OMEGA_TENSOR_OK; bool eq = ok && memcmp(ia, ib, 32) == 0; @@ -310,6 +373,10 @@ static Cmp compare(const OmegaTensorRealization *test, unsigned mask, const char if (!ok) printf(" cpu_e1=%d test_e1=%d", ea, eb); /* diagnostics only */ printf("\n"); } + if (ok && !eq) diff_detail(c->name, tag, &oa, &ob); + else if (ob.bytes) fill_line(c->name, tag, &ob, false); + free(oa.bytes); + free(ob.bytes); } return r; } From 68c9d001fd7f8949fa6aeb11f1d9738b3fbf1920 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 21:22:42 -0500 Subject: [PATCH 4/5] M20 gb10: docs row wording after rebase onto main Co-Authored-By: Claude Sonnet 5.5 --- docs/tensor/M20_OMEGA_TENSOR.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tensor/M20_OMEGA_TENSOR.md b/docs/tensor/M20_OMEGA_TENSOR.md index 213632aeb..27ad811fa 100644 --- a/docs/tensor/M20_OMEGA_TENSOR.md +++ b/docs/tensor/M20_OMEGA_TENSOR.md @@ -159,7 +159,7 @@ removed. Order and padding mutations are caught by the E1 WP-D suite. | Reproducible receipt | PASS (CPU) | writer implemented and host-tested: `tools/m20_receipt.sh` writes `/.json` (0444, exclusive, never overwritten), QUALIFIED only with GB10 parity GB10 PASS + matching chip evidence; `test-m20-receipt` + 11 receipt mutants in `test-tensor-mutations`, forge log HIVE-M20-receipt-175835. No real M20 receipt has been written yet because the GB10 parity evidence does not exist. | | E1 numeric closure | PASS (on main) | E1 PASSED on main 4863803; receipt merged in omega#177 | | Placement: embed + concat (CR-4, answers LT-M21 CR-4) | PASS (CPU) | Host PASS, CPU tier: forge log `HIVE-M20-scatter-light-193431` at pre-stack head d99af69; re-run at stacked head queued (job HIVE-M20-scatter). `omega_tensor_embed(ctx, src, rank, out_shape, start, step, out)` is the exact inverse placement of `omega_tensor_slice` (`src/tensor/omega_tensor.h` slice: per axis start < stop <= dim, step >= 1, out dim = ceil((stop-start)/step)). Declared bits: a new dense tensor, all-zero bits (+0.0) everywhere except src element i copied bit for bit (NaN payload and -0 kept, any dtype) to start + i*step per axis; so slice(embed(x), start, start+(n-1)*step+1, step) == x. `omega_tensor_concat(ctx, n, tensors, axis, out)`: parts joined in array order along axis, bit for bit. Both are pure semantic-layer copies (gather + scatter in `src/tensor/omega_tensor.c`), no realization call, no arithmetic. Typed refusals, nothing created: rank mismatch / rank 0 `ERR_RANK`, step 0 `ERR_BAD_ARGS` (as slice), a placed position outside out_shape or start/step overflow `ERR_BOUNDS`, zero dim `ERR_SHAPE`, > MAX_ELEMS `ERR_CAPACITY`, concat dtype mismatch `ERR_DTYPE`, other-axis mismatch `ERR_SHAPE`, axis >= rank `ERR_AXIS`, n = 0 / NULL `ERR_BAD_ARGS`, stale handle `ERR_STALE`. `test-tensor` test_placement: 60 random embed trials vs an independent index-arithmetic reference, slice(embed(x)) == x, embed(slice(y)) zero off the sliced set, transposed / broadcast / F16 sources, 40 random concat trials vs reference and slice recovery, view parts, every refusal. Mutants `EMBED_START`, `EMBED_STEP`, `CONCAT_AXIS_OFFSET` in `test-tensor-mutations`. Gather is OUT OF SCOPE: M20 has no index tensor op, so gather / gather-backward is not provided | -| GB10 placement (embed, concat) | NOT_RUN | No GB10 realization table exists (row "GB10 parity"); embed and concat call no E1 op, so there is no E1 GB10 kernel to cite. CPU tier only in this work | +| GB10 placement (embed, concat) | NOT_RUN | Embed and concat call no E1 op, so the GB10 table (row "GB10 parity") has no kernel for them and no chip gate covers them. CPU tier only in this work | **M20 verdict: not qualified.** GB10 parity NOT_RUN; receipt writer host PASS, no M20 receipt written yet. From 1e41c53cc772001d016352a85bc437c612d3af16 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 2 Oct 2026 02:09:58 -0500 Subject: [PATCH 5/5] M20 gb10: keep CMP ops out of chip parity, host check for their refusal, docs after rebase After #191 added the six OMEGA_TB_CMP_* mask compare ops, the GB10 parity loop (OMEGA_TB_COUNT) would have run them: the CPU table realizes them, the GB10 table has no compare entry and refuses them, so parity could never pass and BIN_NAME had six NULL names. - The binary parity loop and BIN_NAME stop before OMEGA_TB_CMP_EQ, so the chip case count stays 88 (same cases, names, seeds and expected values). - New host self check (no device): each CMP_* op on the GB10 table returns OMEGA_TENSOR_ERR_REALIZATION, makes no tensor or storage slot, leaves the output handle zero and records no numeric error. Counterexample: the same table with a compare entry set must fail that check. - docs/tensor/M20_OMEGA_TENSOR.md: removed stale "no GB10 table exists" wording, GB10 rows stay NOT_RUN at this head, old chip result at 898bd05 recorded as voided history. Not built or run (builder rule); the forge reports. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- docs/tensor/M20_OMEGA_TENSOR.md | 32 +++++++------ tests/test_omega_tensor_gb10.c | 80 +++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 17 deletions(-) diff --git a/docs/tensor/M20_OMEGA_TENSOR.md b/docs/tensor/M20_OMEGA_TENSOR.md index 27ad811fa..8b19b3222 100644 --- a/docs/tensor/M20_OMEGA_TENSOR.md +++ b/docs/tensor/M20_OMEGA_TENSOR.md @@ -72,8 +72,10 @@ composition program is COMPOSITION-1/2, not M20. - **Meaning vs realization**: `OmegaTensorRealization` is a function table (elementwise E1 op over dense buffers, reduce over a dense row, declared order string). The semantic layer refuses a table whose order string is not - the declared one. CPU fills it now; GB10 SIMT / Tensor Core fill it later. - No GB10 code is referenced by the semantic layer. + the declared one. CPU fills it; a GB10 SIMT table + (`src/tensor/omega_tensor_gb10.c`, M20 cut gb10) is written but its parity + is NOT_RUN; a Tensor Core table would come later. No GB10 code is referenced + by the semantic layer. ### What "beyond the old narrow kernel" means @@ -83,8 +85,9 @@ with no declared FP32 accumulation order, and has no strides, views, broadcast or batch. `src/omega_matvec.*` is a uint64 matrix-vector with fixed maximum shapes. M20 here: any shape up to 2^30 elements, FP32 with a named accumulation order, strided / transposed / sliced / broadcast operands, -broadcast batches. The GB10 realization of this general matmul does not -exist yet. +broadcast batches. The GB10 realization of this general matmul (FMUL_RNE +products + the E1 tree, `src/tensor/omega_tensor_gb10.c`) is written; its +parity is NOT_RUN at this head. ## Multi-axis reduce and unbroadcast (CR-5) @@ -113,8 +116,9 @@ defined by the frozen E1 reduction order above and nothing else. (`OMEGA_TENSOR_ERR_SHAPE`); zero dim (`OMEGA_TENSOR_ERR_SHAPE`); rank > 8 (`OMEGA_TENSOR_ERR_RANK`); non-F32 (`OMEGA_TENSOR_ERR_DTYPE`). - GB10: these ops add no kernel; they call the realization's single-axis - `reduce`. No GB10 realization table exists yet (row "GB10 parity" below), - so GB10 for these ops is NOT_RUN. + `reduce`. The GB10 table (row "GB10 parity" below) is written but its + parity is NOT_RUN, and the chip gate has no case for these two ops, so GB10 + for these ops is NOT_RUN. ## Reduction seam @@ -135,17 +139,17 @@ removed. Order and padding mutations are caught by the E1 WP-D suite. | Immutability / no in-place | PASS (CPU) | no write API exists; input value ids unchanged by every op; outputs never alias inputs | | CPU parity | PASS (CPU) | every op bit-exact vs independent reference (omega_ref_*, omega_ieee_div/sqrt, omega_ref_ffma_int, own tree copy), random + all special pairs | | Transcendental unary ops (EXP2, LOG2, SIGMOID, TANH) | PASS (CPU) | Host PASS, CPU tier: forge log `HIVE-M20-transc-175026` (`test-tensor` + `test-tensor-mutations`, 7/7 mutants caught). Bounded contract, NOT correctly rounded (max ulp EXP2 2, LOG2 2, SIGMOID 3, TANH 3; `docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md`). `test-tensor` section 7b: raw-bit equality with direct `omega_math_*` calls on dense, transposed, strided-slice-with-offset, transpose-of-slice, broadcast row/scalar and rank-0 operands incl. specials; canonical qNaN; unknown op / F16 / stale / missing `transc` entry refused. Mutants `TRANSC_EXP2_LOG2_SWAP`, `UNARY_VIEW_STRIDE` in `test-tensor-mutations` | -| Constants and NEG (`omega_tensor_full`/`zeros`/`ones`, `OMEGA_TU_NEG`; answers LT-M21 CR-2) | PASS (CPU) | Host: PASS, CPU tier: forge log `HIVE-M20-const-light-193345` at pre-stack head 049611c (488 pass, 0 fail plain and ASan/UBSan; 11/11 mutants caught); re-run at stacked head queued. GB10: NOT_RUN (no GB10 tensor realization exists; row GB10 parity). Declared result, one per op: `full(v)` fills every element with the exact F32 bits of `v` (-0.0 and NaN payload kept, no canonicalization; value ids still treat all NaNs as one); `zeros` = bits `0x00000000`; `ones` = `0x3f800000`; shape rules as `from_f32` (rank <= 8, dims >= 1, elements <= 2^30, else typed error; the 2^30 boundary itself is not allocated in tests, only 2^30+1 and 2^31 are refused). `NEG` = flip bit 31 with no arithmetic and no E1 call, so neg(+0) = -0 and neg(-0) = +0 (`0 - x` would give +0, wrong); any NaN in gives the canonical quiet NaN `0x7fc00000`, matching the E1 convention "NaN results are the canonical quiet NaN" (`src/omega_numeric.h:137`); F16/BF16 refused; works with a realization that has no `transc` entry. Tests (`test-tensor` section 7c): bit-exact contents, rank 0 and 8, refusals, NEG on the 20-value special grid vs an independent bit rule, NEG through transpose, strided slice and broadcast views. Mutants `ZEROS_NEG0`, `NEG_SUB`, `NEG_NAN`, `FULL_CANON` in `test-tensor-mutations` | +| Constants and NEG (`omega_tensor_full`/`zeros`/`ones`, `OMEGA_TU_NEG`; answers LT-M21 CR-2) | PASS (CPU) | Host: PASS, CPU tier: forge log `HIVE-M20-const-light-193345` at pre-stack head 049611c (488 pass, 0 fail plain and ASan/UBSan; 11/11 mutants caught); re-run at stacked head queued. GB10: NOT_RUN (no chip run covers these ops; the GB10 table is in row GB10 parity). Declared result, one per op: `full(v)` fills every element with the exact F32 bits of `v` (-0.0 and NaN payload kept, no canonicalization; value ids still treat all NaNs as one); `zeros` = bits `0x00000000`; `ones` = `0x3f800000`; shape rules as `from_f32` (rank <= 8, dims >= 1, elements <= 2^30, else typed error; the 2^30 boundary itself is not allocated in tests, only 2^30+1 and 2^31 are refused). `NEG` = flip bit 31 with no arithmetic and no E1 call, so neg(+0) = -0 and neg(-0) = +0 (`0 - x` would give +0, wrong); any NaN in gives the canonical quiet NaN `0x7fc00000`, matching the E1 convention "NaN results are the canonical quiet NaN" (`src/omega_numeric.h:137`); F16/BF16 refused; works with a realization that has no `transc` entry. Tests (`test-tensor` section 7c): bit-exact contents, rank 0 and 8, refusals, NEG on the 20-value special grid vs an independent bit rule, NEG through transpose, strided slice and broadcast views. Mutants `ZEROS_NEG0`, `NEG_SUB`, `NEG_NAN`, `FULL_CANON` in `test-tensor-mutations` | | GB10 transcendental tensor ops | NOT_RUN | GB10 transcendental tensor ops: NOT_RUN (follow-up). No GB10 `transc` entry; a table without one refuses these ops with `OMEGA_TENSOR_ERR_REALIZATION` | | Unary ops EXP, LOG, RELU (M20 cut ops, LT-M21 CR-1..CR-5) | PASS (CPU) | Host PASS, CPU tier: forge log `HIVE-M20-ops-light-185351` at pre-stack head 1e16a8d, re-run at stacked head queued (`test-tensor` 438 pass / 0 fail plain and ASan/UBSan; `test-tensor-mutations` 10/10 tensor mutants caught). EXP / LOG: `OMEGA_TU_EXP` / `OMEGA_TU_LOG` call the E1 Omega-defined polynomials `omega_math_exp` / `omega_math_log` (`src/omega_numeric.c:458`, `:501`) once per element through the CPU `transc` entry; the result must equal a direct E1 call bit for bit. NOT correctly rounded: E1 checks them only against binary128 within EXP 40 ulp, LOG 4 ulp (`tests/test_omega_numeric.c:376-384`; `docs/numeric/E1_GAP_TABLE.md` row 8 and the `CPU_TIER_INDEPENDENT_ORACLE` line). RELU: no E1 op; tensor-layer bit select with no float arithmetic (`src/tensor/omega_tensor.c` `relu_bits`): x > +0 (incl. +subnormals, +inf) -> x; +0, -0, negatives, -inf -> +0.0; any NaN -> canonical qNaN `OMEGA_QNAN_BITS` 0x7fc00000 (`src/omega_numeric.h:48`, as E1 returns, e.g. `src/omega_numeric.c:459`). Tests: section 7b runs EXP / LOG / RELU raw-bit vs direct E1 (RELU vs an independent field-classifying reference) on dense, transposed, strided-slice, transpose-of-slice, broadcast row/scalar and rank-0 views incl. specials (+-0, +-inf, NaN payloads, subnormals, +-2^31, exp cutoffs 88.7228 / -104); section 7c: RELU explicit bit table (-0 -> +0, NaN payloads -> 0x7fc00000), served without a `transc` entry, F16 / stale refused. Mutants `TRANSC_EXP_LOG_SWAP`, `RELU_NEG_ZERO`, `RELU_NAN_PAYLOAD` | | GB10 EXP / LOG tensor ops | MISSING_IMPLEMENTATION | E1 itself has no GB10 kernel for the Omega exp / log polynomials (`src/omega_numeric.c:585-588`, `gb10_encoded` false (`src/omega_numeric.h:250`); `docs/numeric/E1_GAP_TABLE.md` row 10) | | GB10 RELU tensor op | NOT_RUN | RELU is a tensor-layer bit select with no realization call, so a GB10 context would run the same host code; no GB10 run in this work | | Unary ops RSQRT, ERF, GELU (LT-M21 CR-1 part) | PASS (CPU) | Host PASS, CPU tier: forge log `HIVE-M20-unary2-light-193221` at pre-stack head cc0c66d; re-run at stacked head queued (job `HIVE-M20-unary2`). `OMEGA_TU_RSQRT`, `OMEGA_TU_ERF`, `OMEGA_TU_GELU` appended after `OMEGA_TU_RELU` in the stack (no renumbering); the CPU `transc` entry calls `omega_math_rsqrt` / `omega_math_erf` / `omega_math_gelu` (`src/omega_numeric_transc.h:47,50,53`) once per element, no other arithmetic. Declared result: bit-identical to a direct E1 call on each logical element (raw bits, canonical qNaN `0x7fc00000` per `src/omega_numeric_transc.h:20`). Accuracy is E1's, not the tensor layer's: RSQRT correctly rounded (`OMEGA_TRANSC_MAX_ULP_RSQRT 0`, `src/omega_numeric_transc.h:34`; `docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:45,99`); ERF bounded contract, max 3 ulp (`transc.h:37`; contract `:48,102`); GELU (erf form, `x Phi(x)`) bounded contract, max 3 ulp (`transc.h:40`; contract `:50,105`). Tests: section 7b cases (dense, transpose, strided slice with offset, transpose of slice, broadcast row and scalar, rank 0, F16 / stale / missing-entry refusals) and section 7c (contract edge inputs on dense and step-2 strided slice vs direct E1, plus contract-stated values such as RSQRT(-0) = -inf, ERF(4) = 1, GELU(-inf) = -0). Mutants `TRANSC_RSQRT_ERF_SWAP`, `GELU_VIEW_STRIDE` (9 source mutants in the sweep with these two) | -| GB10 unary ops RSQRT, ERF, GELU | MISSING_IMPLEMENTATION | E1 has no GB10 realization of these sequences (`docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:4`, `:197`: GB10 NOT_RUN) and main has no GB10 `OmegaTensorRealization` table (only `src/tensor/omega_tensor_cpu.c`). A table without a `transc` entry refuses these ops with `OMEGA_TENSOR_ERR_REALIZATION` (`src/tensor/omega_tensor.c:676`). CPU tier only in this cut | +| GB10 unary ops RSQRT, ERF, GELU | MISSING_IMPLEMENTATION | E1 has no GB10 realization of these sequences (`docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:4`, `:197`: GB10 NOT_RUN) and the GB10 `OmegaTensorRealization` table of this PR (`src/tensor/omega_tensor_gb10.c`) has no `transc` entry (main has only `src/tensor/omega_tensor_cpu.c`). A table without a `transc` entry refuses these ops with `OMEGA_TENSOR_ERR_REALIZATION` (`src/tensor/omega_tensor.c:676`). CPU tier only in this cut | | Trig unary ops (SIN, COS) | PASS (CPU) | Answers LT-M21 CR-1 (trig part); branch `hive/M20-trig`, forge job `HIVE-M20-trig`. `OMEGA_TU_SIN`, `OMEGA_TU_COS` appended after `OMEGA_TU_GELU` in the stack (no renumbering); the CPU `transc` entry calls `omega_math_sin` / `omega_math_cos` (`src/omega_numeric_transc.h:51-52`) once per element. Declared result: bit-identical to the direct E1 call on the logical element. Domain (E1 rule, `src/omega_numeric_transc.h:43` `OMEGA_TRANSC_TRIG_MAX_ABS`, `src/omega_numeric_transc.c:517` sincos_core): admitted `abs(x) <= 2^22` inclusive; outside it, +-inf and NaN give the canonical qNaN `0x7fc00000`; sin(+-0) = +-0, cos(+-0) = +1 (`docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:49`). Accuracy: bounded contract, NOT correctly rounded, max 2 ulp each inside the domain (`src/omega_numeric_transc.h:38-39`, observed 1; `docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:103-104`). Tests: SIN/COS join section 7b (dense, transpose, strided slice, transpose of slice, broadcast, rank 0, refusals) and new section 7c (grid incl. +-0, +-2^22, +-nextup(2^22), +-nextdown(2^22), inf, NaN, sNaN, through dense, broadcast and strided-slice views: bit-exact vs E1 plus an independent domain-rule check). Mutants `TRIG_SIN_COS_SWAP`, `TRIG_DOMAIN_NUMBER` (out-of-domain NaN replaced by a number). Host PASS, CPU tier: forge log `HIVE-M20-trig-light-193303` at pre-stack head 2a7da1a (425 pass, 0 fail, ASan/UBSan clean, sweep 9/9); re-run at stacked head queued | | GB10 trig tensor ops (SIN, COS) | MISSING_IMPLEMENTATION | E1 has no GB10 kernel for SIN or COS (`docs/numeric/E1_GAP_TABLE.md:27`: "RSQRT, ERF, SIN, COS, GELU have no GB10 kernel"). No chip work in this cut | | Mask compare CMP_EQ/NE/LT/LE/GT/GE + `omega_tensor_where` (CR-3) | NOT_RUN | Host: NOT_RUN until the forge reports (job `HIVE-M20-mask`; no PASS receipt yet; run at stacked head queued). Declared bits: CMP_P(a, b) = +1.0 (0x3f800000) if the ordered E1 predicate of FSETP_EQ/NE/LT/LE/GT_SEL or FSETP_SEL (GE) holds, else +0.0 (0x00000000), never -0.0; predicate = `omega_ref_fsetp_pred` (`src/omega_numeric.c:322`, masks at :293-308): false if either operand is NaN (CMP_NE included, unlike IEEE !=), -0 == +0. CPU realization: optional `compare` entry, FCMP + FCSEL(+1.0, +0.0) on the same AArch64 conditions as the E1 CPU compare-select (`src/omega_numeric.c:1396-1418`); a table without it refuses CMP_* with `OMEGA_TENSOR_ERR_REALIZATION`. `where(cond, a, b)`: bit copy of a or b (no arithmetic), cond/a/b broadcast together; any cond element other than 0x3f800000 / 0x00000000 (incl. -0.0, NaN, 0.5) refused with new `OMEGA_TENSOR_ERR_MASK` (-12), nothing made. Tests: every predicate on the 20x20 special grid + random pairs vs independent loop (strict bits), where(CMP_P) == SEL_P, broadcast + transposed/sliced views, refusals. Mutants: CMP_FALSE_NEG_ZERO, CMP_EQ_NAN_TRUE, WHERE_ACCEPTS_HALF | -| GB10 mask compare / where (CR-3) | NOT_RUN | No GB10 `compare` entry. E1 has GB10 encodings for the FSETP_

_SEL compare-select ops (`src/omega_numeric.c:915-934`) but no compare-to-mask kernel; where() is data movement only. CPU tier only in this cut | +| GB10 mask compare / where (CR-3) | NOT_RUN | No GB10 `compare` entry. E1 has GB10 encodings for the FSETP_

_SEL compare-select ops (`src/omega_numeric.c:915-934`) but no compare-to-mask kernel; where() is data movement only. The GB10 table of this PR leaves `compare` NULL on purpose. A host self check in `tests/test_omega_tensor_gb10.c` (no device) requires each of the six CMP_* ops to be refused with `OMEGA_TENSOR_ERR_REALIZATION` with no tensor or storage slot made and no numeric call, and rejects a counterexample table that has a compare entry set. The six CMP_* ops are not chip parity cases (chip case count stays 88). CPU tier only in this cut; NOT_RUN at this head | | General matmul | PASS (CPU) | 1x1x1, 7x13x5, 64x64x64, 129x3x257, 3x1025x2, 1x33x1, strided views, batched broadcast [2,1,3,4]x[5,4,6] | | Reductions | PASS (CPU) | lengths 1..32769 across tile/level edges, every axis of [3,37,5], keepdims, view vs copy, -0 sum | | Multi-axis reduce, sum_to_shape (CR-5) | NOT_RUN | `tests/tensor_reduce_multi_tests.inc` (run by `test-tensor`): every axis subset of a [3,5,4,6] tensor x SUM/MAX/MIN (MEAN single axis) x keepdims vs an independent descending-order reference and vs the explicit single-axis reduce chain; strided view == copy; sum_to_shape(broadcast_to(x, S), shape(x)) exact for 6 shape pairs; refusals (duplicate / out-of-range axes, MEAN over 2 axes, incompatible shape, rank, dtype, stale). Mutants REDUCE_AXES_DESCENDING, REDUCE_AXES_KEEPDIMS, SUM_TO_SHAPE_SIZE1 added (tensor sweep now 27 source mutants at this head, 33 with the 6 store mutants, counted from the MUTATIONS and STORE_MUTATIONS lists in tools/tensor_mutations.sh). Host receipt at a6618da: PASS (919 / 0, 30 of 30 mutants at that head, log LT-M20B-reduce-light-052347); rebased head receipt queued (NOT_RUN until the forge reports). GB10 NOT_RUN | @@ -153,7 +157,7 @@ removed. Order and padding mutations are caught by the E1 WP-D suite. | Determinism | PASS (CPU) | repeated run same value id; frozen KAT value id in the test | | Test-only hook not in library | PASS (CPU) | `omega_tensor_test_set_storage_generation` exists only under `-DOMEGA_TENSOR_TEST_HOOKS` (test builds in `mk/tensor.mk`); `test-tensor-no-hooks` (run by `test-tensor`) builds the default objects and fails if `nm` shows the symbol | | CI | WIRED | `host-suites-2.yml` job `tensor`: `test-tensor` + `test-tensor-mutations` on the AArch64 hosted runner (not the Spark, not a qualification) | -| GB10 parity | NOT_RUN | GB10 table `src/tensor/omega_tensor_gb10.c` (E1 SIMT elementwise, `omega_reduce_gb10`, matmul = FMUL_RNE products + E1 tree, batched per block) and gate `tests/test_omega_tensor_gb10.c` + `tests/run_tensor_chip.sh` written (branch hive/M20-gb10); no forge host or chip receipt yet | +| GB10 parity | NOT_RUN | GB10 table `src/tensor/omega_tensor_gb10.c` (E1 SIMT elementwise, `omega_reduce_gb10`, matmul = FMUL_RNE products + E1 tree, batched per block) and gate `tests/test_omega_tensor_gb10.c` + `tests/run_tensor_chip.sh` written (branch hive/M20-gb10). NOT_RUN at the rebased head: the host gate and the chip gate are queued, no forge receipt yet. History only: a chip run at the pre-rebase head 898bd05 passed (88 of 88 cases bit-exact, 3 of 3 chip mutants caught, receipt `evidence-out/M20-TENSOR-GB10/797c6972cd2ed4804ee2996abd0a1d6d04ea08b7b753b4699896746921676375.json`, log `LT-M20B-gb10-chip-061802`); that result is VOIDED for the rebased head and does not count. The rebase onto main after #191 (CMP_* ops) and #192 needed one fix: the six CMP_* ops are excluded from the parity cases because the GB10 table refuses them (row "GB10 mask compare / where"), the chip case count stays 88, and a host check requires the refusal | | GB10 general matmul (Tensor Core beyond narrow K/tile) | MISSING_IMPLEMENTATION | not built on purpose: MMA accumulates with fused, differently ordered additions, so it cannot give the declared bits; it needs its own declared bounded contract first. The GB10 table uses SIMT FMUL + the E1 tree instead | | Crash-safe storage lifetime | PASS (CPU) | host PASS, forge log HIVE-M20-lifetime-light-182200 (`test-tensor-store` 314/0 plain + ASan/UBSan, 6/6 store mutants caught, hook absent from default build). `src/tensor/omega_tensor_store.{c,h}`: content-addressed payloads + checksummed journal, temp/fsync/rename/fsync-dir commit; recovery replays the journal, re-hashes every payload, refuses torn/short/corrupt records (typed errors), keeps generations monotonic; `test-tensor-store` (round trip, fork crash at all 8 commit phases, journal/payload truncated at every byte and bit-flipped, crafted journals) + 6 store mutants in `test-tensor-mutations` | | Reproducible receipt | PASS (CPU) | writer implemented and host-tested: `tools/m20_receipt.sh` writes `/.json` (0444, exclusive, never overwritten), QUALIFIED only with GB10 parity GB10 PASS + matching chip evidence; `test-m20-receipt` + 11 receipt mutants in `test-tensor-mutations`, forge log HIVE-M20-receipt-175835. No real M20 receipt has been written yet because the GB10 parity evidence does not exist. | @@ -180,7 +184,7 @@ hand-deleted journal restarts the generation numbers. per element, so tensor output is bit-identical to calling E1 directly; error bounds are E1's (`docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md`). GB10 transcendental tensor ops: NOT_RUN (follow-up). -3. GB10 realization table: elementwise through the E1 SIMT ops, reduce - through `omega_reduce_gb10`, matmul either products + tree (bit-exact to - this contract) or a Tensor Core path with its own declared bounded - contract. +3. GB10 realization table: written in M20 cut gb10 (elementwise through the + E1 SIMT ops, reduce through `omega_reduce_gb10`, matmul = FMUL_RNE products + + the E1 tree, bit-exact to this contract), parity NOT_RUN. Still open: a + Tensor Core path with its own declared bounded contract. diff --git a/tests/test_omega_tensor_gb10.c b/tests/test_omega_tensor_gb10.c index 70ecfb642..0ade19df8 100644 --- a/tests/test_omega_tensor_gb10.c +++ b/tests/test_omega_tensor_gb10.c @@ -17,7 +17,10 @@ * 1025, 32769) for SUM/MAX/MIN/MEAN, multi-row reductions along both axes, * elementwise binary/unary/fma/cast over a grid of specials (NaN, -0, inf, * subnormals) plus random bit patterns, broadcast elementwise and one call - * longer than a launch chunk. + * longer than a launch chunk. The six CMP_* mask compare ops (CR-3) are NOT + * parity cases: the GB10 table has no compare entry, so a host self check + * requires it to refuse each with OMEGA_TENSOR_ERR_REALIZATION (nothing made, + * no device call), with a counterexample table that does set compare. * * Mutants (in-process realization tables over a base table: the CPU table in * host mode, the GB10 table in chip mode): WRONG_REDUCE_ORDER (rows reduced @@ -100,7 +103,10 @@ static void mm_case(const char *name, uint32_t ra, const uint64_t *sa, uint32_t } static const char *RED_NAME[OMEGA_TR_COUNT] = { "SUM", "MAX", "MIN", "MEAN" }; -static const char *BIN_NAME[OMEGA_TB_COUNT] = { +/* Sized to the 20 parity binary ops (everything before OMEGA_TB_CMP_EQ). The CMP_* + * ops are not parity cases (the GB10 table has no compare entry), so no name + * is ever looked up for them and no entry stays NULL. */ +static const char *BIN_NAME[OMEGA_TB_CMP_EQ] = { "ADD", "SUB", "MUL", "DIV", "MIN", "MAX", "SEL_GE", "SEL_LT", "SEL_LE", "SEL_GT", "SEL_EQ", "SEL_NE", "SEL_NUM", "SEL_NAN", "SEL_LTU", "SEL_LEU", "SEL_GTU", "SEL_GEU", "SEL_EQU", "SEL_NEU", }; @@ -143,7 +149,9 @@ static void build_cases(void) { c->op = op; c->ra = 2; c->sa[0] = 1025; c->sa[1] = 3; c->axis = 0; } /* elementwise */ - for (int op = 0; op < OMEGA_TB_COUNT; op++) { + /* ops before OMEGA_TB_CMP_EQ only: the 20 cases of the original gate. The + * CMP_* ops are refused by the GB10 table, checked in host_checks. */ + for (int op = 0; op < OMEGA_TB_CMP_EQ; op++) { snprintf(nm, sizeof(nm), "bin_%s", BIN_NAME[op]); unsigned mut = (op == OMEGA_TB_SUB || op == OMEGA_TB_DIV || op == OMEGA_TB_SEL_LT) ? MUT_SWAP : 0; Case *c = add_case(nm, K_BIN, mut); @@ -550,6 +558,63 @@ static const char *mut_map_uniform_ffma(OmegaNumericOp op) { return op == OMEGA_NOP_FFMA_V ? "FFMA" : omega_tensor_gb10_op_name(op); } +/* CR-3 mask compare ops. The GB10 table has no compare entry, so the semantic + * layer must refuse each CMP_* op with OMEGA_TENSOR_ERR_REALIZATION before it + * gathers anything or calls the table: no tensor or storage slot is made, the + * output handle stays zero and no numeric error is recorded (so no device was + * reached). Returns the number of problems. */ +static const OmegaTensorBinaryOp CMP_OPS[] = { + OMEGA_TB_CMP_EQ, OMEGA_TB_CMP_NE, OMEGA_TB_CMP_LT, OMEGA_TB_CMP_LE, OMEGA_TB_CMP_GT, OMEGA_TB_CMP_GE, +}; +#define NCMP_OPS (sizeof(CMP_OPS) / sizeof(CMP_OPS[0])) + +static int check_cmp_refused(const OmegaTensorRealization *real, bool verbose) { + static const uint64_t shape[1] = { 4 }; + static const float da[4] = { 1.0f, 2.0f, 3.0f, 4.0f }, db[4] = { 1.0f, 5.0f, 3.0f, 0.0f }; + OmegaTensorCtx *ctx = NULL; + OmegaTensor a = { 0, 0 }, b = { 0, 0 }; + if (omega_tensor_ctx_create(8, real, &ctx) != OMEGA_TENSOR_OK) { + if (verbose) printf(" cmp: context create refused\n"); + return 1; + } + if (omega_tensor_from_f32(ctx, 1, shape, da, &a) != OMEGA_TENSOR_OK || + omega_tensor_from_f32(ctx, 1, shape, db, &b) != OMEGA_TENSOR_OK) { + if (verbose) printf(" cmp: input tensors not made\n"); + omega_tensor_ctx_destroy(ctx); + return 1; + } + uint32_t t0 = 0, s0 = 0; + omega_tensor_live_counts(ctx, &t0, &s0); + int bad = 0; + for (size_t i = 0; i < NCMP_OPS; i++) { + OmegaTensor out = { 0, 0 }; + int rc = omega_tensor_binary(ctx, CMP_OPS[i], a, b, &out); + uint32_t t1 = 0, s1 = 0; + omega_tensor_live_counts(ctx, &t1, &s1); + if (rc != OMEGA_TENSOR_ERR_REALIZATION) { + bad++; + if (verbose) printf(" cmp: op %d returned %d, expected %d\n", (int)CMP_OPS[i], rc, OMEGA_TENSOR_ERR_REALIZATION); + } + if (t1 != t0 || s1 != s0 || out.slot != 0 || out.generation != 0) { + bad++; + if (verbose) printf(" cmp: op %d made a tensor or storage slot\n", (int)CMP_OPS[i]); + } + if (omega_tensor_last_numeric_error(ctx) != 0) { + bad++; + if (verbose) printf(" cmp: op %d reached a numeric call\n", (int)CMP_OPS[i]); + } + } + omega_tensor_ctx_destroy(ctx); + return bad; +} + +/* counterexample table: the GB10 table WITH a compare entry (a stub that fills +0.0) */ +static int cmp_stub(OmegaNumericOp sel_op, const float *a, const float *b, float *out, size_t n) { + (void)sel_op; (void)a; (void)b; + for (size_t i = 0; i < n; i++) out[i] = 0.0f; + return OMEGA_NUMERIC_OK; +} + static void host_checks(void) { const OmegaTensorRealization *g = omega_tensor_gb10_realization(); CHECK(g && g->name && g->elementwise && g->reduce && g->reduce_rows && g->reduce_order, @@ -591,6 +656,15 @@ static void host_checks(void) { CHECK(g->reduce((OmegaTensorReduceOp)OMEGA_TR_COUNT, a, 4, &r1) == OMEGA_NUMERIC_ERR_BAD_ARGS, "unknown reduce op not refused"); + /* CR-3 compare: no compare entry, each CMP_* op refused with ERR_REALIZATION, + * nothing made, no device call; and the counterexample: the same table with + * a compare entry set must fail this very check */ + CHECK(g->compare == NULL, "GB10 table has a compare entry (CMP_* must be refused)"); + CHECK(check_cmp_refused(g, true) == 0, "GB10 table does not refuse the CMP_* ops cleanly"); + OmegaTensorRealization with_cmp = *g; + with_cmp.compare = cmp_stub; + CHECK(check_cmp_refused(&with_cmp, false) > 0, "CMP refusal check missed a table with a compare entry"); + /* the harness itself, on the CPU: CPU vs CPU equal on every case, and * every mutant (over the CPU table) caught */ Cmp self = compare(omega_tensor_cpu_realization(), 0, "HOST_SELF", false);