Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/patches/3974cf9300ffd3e5 # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/omega-mv#178 (code only) closed derived `3974cf9300ffd3e5` #178 Imported from GitHub aien-dev/omega-mv#178 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `38919c8d87e02ac6fceeb9984ea3e99783d718ff` · Head `0fc4daf69d85492bc8771ee215aab338618f0d9c` ### Apply it ``` git checkout -b patch-3974cf9300ffd3e5 38919c8d87e02ac6fceeb9984ea3e99783d718ff curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/3974cf9300ffd3e5.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-mv 178 0fc4daf69d85492bc8771ee215aab338618f0d9c ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":178,"url":"https://github.com/aien-dev/omega-mv/pull/178","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:39Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/docs/tensor/M20_OMEGA_TENSOR.md b/docs/tensor/M20_OMEGA_TENSOR.md index 9e32f298b..287dada0c 100644 --- a/docs/tensor/M20_OMEGA_TENSOR.md +++ b/docs/tensor/M20_OMEGA_TENSOR.md @@ -55,7 +55,9 @@ composition program is COMPOSITION-1/2, not M20. `OMEGA_TENSOR_ERR_NOT_CONTIGUOUS`; `omega_tensor_contiguous` makes the copy explicit), broadcast_to (zero strides). Every view is bounds checked against its storage when made. -- **Elementwise**: SQRT; ADD, SUB, MUL, DIV (omega_math_div), MIN, MAX, the +- **Elementwise**: SQRT; EXP2, LOG2, SIGMOID, TANH (E1 bounded contract, not + correctly rounded: bit-exact with the E1 CPU sequences per element, max ulp + EXP2 2, LOG2 2, SIGMOID 3, TANH 3); ADD, SUB, MUL, DIV (omega_math_div), MIN, MAX, the 14 compare-select predicates (out = P(a, b) ? a : b); FMA (a*b+c rounded once). All E1 scalar ops, all operands broadcast together. - **Reductions** along one axis, SUM / MAX / MIN / MEAN, keepdims optional, @@ -102,9 +104,11 @@ removed. Order and padding mutations are caught by the E1 WP-D suite. | Generation safety | PASS (CPU) | use after release, double release, stale view of released storage (read, info, op, matmul, view, id), no ABA on slot reuse, UINT64_MAX retirement | | 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` | +| 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` | | 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 | -| Mutation / refusal | PASS (CPU) | `test-tensor-mutations`: 5/5 source mutations caught; 2 in-process mutant realizations (sequential sum, FFMA chain) caught; wrong order string refused | +| Mutation / refusal | PASS (CPU) | `test-tensor-mutations`: 7/7 source mutations caught; 2 in-process mutant realizations (sequential sum, FFMA chain) caught; wrong order string refused | | 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) | @@ -120,9 +124,15 @@ lifetime and receipt MISSING_IMPLEMENTATION. ## Open seams 1. Reductions: DONE, the seam calls `omega_reduce_cpu` (#134 merged). -2. Transcendentals (#127): the E1 bounded contract is merged (E1 PASS on - main 4863803), so adding EXP / LOG / ... to `OmegaTensorUnaryOp` is a - follow-up, not blocked. +2. Transcendentals (#127): CPU tier host PASS (CPU), forge log + `HIVE-M20-transc-175026`. `OmegaTensorUnaryOp` gained + `OMEGA_TU_EXP2`, `OMEGA_TU_LOG2`, `OMEGA_TU_SIGMOID`, `OMEGA_TU_TANH` + (appended after SQRT, no renumbering). They are bounded-contract ops, not + correctly rounded: the CPU realization's optional `transc` entry calls + `omega_math_exp2/log2/sigmoid/tanh` (`src/omega_numeric_transc.c`) once + 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 diff --git a/mk/tensor.mk b/mk/tensor.mk index 8af258b76..5925bb622 100644 --- a/mk/tensor.mk +++ b/mk/tensor.mk @@ -20,10 +20,10 @@ TENSOR_MK := 1 TENSOR_CFLAGS = -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -Isrc/tensor \ -DOMEGA_NUMERIC_CPU_ONLY TENSOR_SRCS = src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c \ - src/omega_numeric_reduce.c + src/omega_numeric_reduce.c src/omega_numeric_transc.c TENSOR_DEPS = 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 -TENSOR_HDRS = src/tensor/omega_tensor.h src/tensor/omega_tensor_reduce_seam.h src/omega_numeric_reduce.h src/omega_numeric.h src/sha256.h +TENSOR_HDRS = src/tensor/omega_tensor.h src/tensor/omega_tensor_reduce_seam.h src/omega_numeric_reduce.h src/omega_numeric.h src/sha256.h src/omega_numeric_transc.h # Test builds only: compiles the test-only storage-generation hook. TENSOR_TEST_FLAGS = -DOMEGA_TENSOR_TEST_HOOKS TENSOR_HOOK_SYMS = omega_tensor_test_set_storage_generation diff --git a/src/tensor/omega_tensor.c b/src/tensor/omega_tensor.c index 804a60219..9b762dfc4 100644 --- a/src/tensor/omega_tensor.c +++ b/src/tensor/omega_tensor.c @@ -666,10 +666,33 @@ static int elementwise_n(OmegaTensorCtx *ctx, OmegaNumericOp op, unsigned arity, return rc; } +/* Unary ops: gather the operand through its own view descriptor (offset, + * shape, strides, including stride-0 broadcast axes) into a dense buffer, + * then one realization call. SQRT goes through the E1 elementwise op; the + * bounded-contract transcendentals through the realization's transc entry. */ int omega_tensor_unary(OmegaTensorCtx *ctx, OmegaTensorUnaryOp op, OmegaTensor a, OmegaTensor *out) { - if (!ctx) return OMEGA_TENSOR_ERR_BAD_ARGS; + if (!ctx || !out) return OMEGA_TENSOR_ERR_BAD_ARGS; if ((unsigned)op >= OMEGA_TU_COUNT) return OMEGA_TENSOR_ERR_BAD_ARGS; - return elementwise_n(ctx, OMEGA_NOP_SQRT, 1, &a, out); + if (op != OMEGA_TU_SQRT && !ctx->real->transc) return OMEGA_TENSOR_ERR_REALIZATION; + TensorSlot *x; + StorageSlot *s; + int rc = tensor_get(ctx, a, &x, &s); + if (rc) return rc; + OmegaTensorInfo in = x->info; /* copy: slot table may be reused below */ + if (in.dtype != OMEGA_DT_F32) return OMEGA_TENSOR_ERR_DTYPE; + size_t n = (size_t)in.elements; + float *src = malloc(n * sizeof(float)); + if (!src) return OMEGA_TENSOR_ERR_CAPACITY; + gather(s, &in, src); /* MUT:UNARY_VIEW_STRIDE */ + void *buf; + rc = new_dense(ctx, OMEGA_DT_F32, in.rank, in.shape, out, &buf); + if (!rc) { + int nrc = op == OMEGA_TU_SQRT ? ctx->real->elementwise(OMEGA_NOP_SQRT, src, NULL, NULL, buf, n) + : ctx->real->transc(op, src, buf, n); + if (nrc) rc = numeric_fail(ctx, nrc, *out); + } + free(src); + return rc; } int omega_tensor_binary(OmegaTensorCtx *ctx, OmegaTensorBinaryOp op, OmegaTensor a, OmegaTensor b, diff --git a/src/tensor/omega_tensor.h b/src/tensor/omega_tensor.h index 1611c179b..f321587d8 100644 --- a/src/tensor/omega_tensor.h +++ b/src/tensor/omega_tensor.h @@ -104,6 +104,14 @@ typedef struct { uint32_t slot; uint64_t generation; } OmegaTensor; /* Elementwise ops. Every op is an E1 scalar op applied per element. */ typedef enum { OMEGA_TU_SQRT = 0, /* omega_math_sqrt, correctly rounded */ + /* E1 bounded-contract transcendentals (NOT correctly rounded): each is + * the frozen E1 CPU sequence in src/omega_numeric_transc.c applied per + * element, bit-exact with calling it directly; max ulp distance from the + * correctly rounded result per docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md. */ + OMEGA_TU_EXP2, /* omega_math_exp2, <= OMEGA_TRANSC_MAX_ULP_EXP2 (2) */ + OMEGA_TU_LOG2, /* omega_math_log2, <= OMEGA_TRANSC_MAX_ULP_LOG2 (2) */ + OMEGA_TU_SIGMOID, /* omega_math_sigmoid, <= OMEGA_TRANSC_MAX_ULP_SIGMOID (3) */ + OMEGA_TU_TANH, /* omega_math_tanh, <= OMEGA_TRANSC_MAX_ULP_TANH (3) */ OMEGA_TU_COUNT } OmegaTensorUnaryOp; @@ -147,6 +155,10 @@ typedef struct { int (*elementwise)(OmegaNumericOp op, const float *a, const float *b, const float *c, float *out, size_t n); int (*reduce)(OmegaTensorReduceOp op, const float *x, size_t n, float *out); + /* Optional. out[i] = op(a[i]) for the bounded-contract unary ops + * (OMEGA_TU_EXP2 .. OMEGA_TU_TANH), bit-exact with the E1 CPU sequences. + * NULL: those ops return OMEGA_TENSOR_ERR_REALIZATION (other ops work). */ + int (*transc)(OmegaTensorUnaryOp op, const float *a, float *out, size_t n); } OmegaTensorRealization; const OmegaTensorRealization *omega_tensor_cpu_realization(void); diff --git a/src/tensor/omega_tensor_cpu.c b/src/tensor/omega_tensor_cpu.c index 15ec48ad0..d9edb4024 100644 --- a/src/tensor/omega_tensor_cpu.c +++ b/src/tensor/omega_tensor_cpu.c @@ -1,19 +1,38 @@ /* CPU realization of M20 OMEGA_TENSOR: the E1 CPU tier (explicit AArch64 - * instructions in omega_numeric_cpu_realize) for elementwise ops, and the - * reduction seam for reductions. No arithmetic outside those two. */ + * instructions in omega_numeric_cpu_realize) for elementwise ops, the frozen + * E1 transcendental sequences (omega_numeric_transc.c, bounded contract) for + * EXP2 / LOG2 / SIGMOID / TANH, and the reduction seam for reductions. No + * arithmetic outside those three. */ #include "omega_tensor.h" #include "omega_tensor_reduce_seam.h" +#include "omega_numeric_transc.h" static int cpu_elementwise(OmegaNumericOp op, const float *a, const float *b, const float *c, float *out, size_t n) { return omega_numeric_cpu_realize(op, a, b, c, out, n); } +/* One E1 scalar call per element; nothing else touches the value. */ +static float (*const TRANSC_FN[OMEGA_TU_COUNT])(float) = { + [OMEGA_TU_EXP2] = omega_math_exp2, [OMEGA_TU_LOG2] = omega_math_log2, /* MUT:TRANSC_EXP2_LOG2_SWAP */ + [OMEGA_TU_SIGMOID] = omega_math_sigmoid, + [OMEGA_TU_TANH] = omega_math_tanh, +}; + +static int cpu_transc(OmegaTensorUnaryOp op, const float *a, float *out, size_t n) { + if ((unsigned)op >= OMEGA_TU_COUNT || !TRANSC_FN[op] || !a || !out) return OMEGA_NUMERIC_ERR_BAD_ARGS; + if (!omega_numeric_fpenv_ok()) return OMEGA_NUMERIC_ERR_FPENV; + float (*f)(float) = TRANSC_FN[op]; + for (size_t i = 0; i < n; i++) out[i] = f(a[i]); + return OMEGA_NUMERIC_OK; +} + static const OmegaTensorRealization CPU_REALIZATION = { .name = "CPU_E1_TIER", .reduce_order = OMEGA_TENSOR_REDUCE_DECLARED_ORDER, .elementwise = cpu_elementwise, .reduce = omega_tensor_seam_reduce_cpu, + .transc = cpu_transc, }; const OmegaTensorRealization *omega_tensor_cpu_realization(void) { return &CPU_REALIZATION; } diff --git a/tests/test_omega_tensor.c b/tests/test_omega_tensor.c index 60da5939f..4b983fa23 100644 --- a/tests/test_omega_tensor.c +++ b/tests/test_omega_tensor.c @@ -761,6 +761,197 @@ static void test_mutations(void) { free(a); free(b); free(ex); } +/* ---- 7b. bounded-contract transcendentals (E1 WP-B) ---------------------- + * EXP2 / LOG2 / SIGMOID / TANH carry the E1 bounded contract (not correctly + * rounded). The tensor layer adds no arithmetic, so its output must be + * bit-identical (raw bits, NaN included) to calling the E1 function directly + * on the logical element, whatever the view: dense, transposed, strided + * slice with offset, broadcast. Expected indices come from shape arithmetic + * only, never from the tensor's strides. */ +#include "omega_numeric_transc.h" + +typedef struct { OmegaTensorUnaryOp op; float (*f)(float); const char *name; } TranscCase; +static const TranscCase TRANSC_CASES[] = { + {OMEGA_TU_EXP2, omega_math_exp2, "EXP2"}, + {OMEGA_TU_LOG2, omega_math_log2, "LOG2"}, + {OMEGA_TU_SIGMOID, omega_math_sigmoid, "SIGMOID"}, + {OMEGA_TU_TANH, omega_math_tanh, "TANH"}, +}; +#define NTRANSC (sizeof(TRANSC_CASES) / sizeof(TRANSC_CASES[0])) + +/* Extra special inputs for the transcendental ranges (exp2 overflow and + * underflow edges, log2 of negatives and subnormals, saturation of sigmoid + * and tanh). */ +static const uint32_t TRANSC_SPECIALS[] = { + 0x43000000U /* 128 */, 0x42fffffeU, 0xc3150000U /* -149 */, 0xc3160000U /* -150 */, + 0xc2fc0000U /* -126 */, 0x41100000U /* 9 */, 0xc1100000U /* -9 */, 0x42c80000U /* 100 */, + 0xc2c80000U /* -100 */, 0x3f800001U, 0x3f7fffffU, 0x40000000U, 0x3e800000U, 0xbf000000U, + 0x00400000U, 0x80400000U, 0x7fffffffU, 0xffffffffU, +}; +#define NTSPECIAL (sizeof(TRANSC_SPECIALS) / sizeof(TRANSC_SPECIALS[0])) + +static size_t bit_mismatches(const float *a, const float *b, size_t n) { + size_t m = 0; + for (size_t i = 0; i < n; i++) m += omega_float_to_bits(a[i]) != omega_float_to_bits(b[i]); + return m; +} + +/* Run op on view V (logical size n) and compare with f(src[idx[i]]). */ +static void transc_check(const TranscCase *tc, OmegaTensor V, const float *src, const size_t *idx, size_t n, + const char *what) { + float *ex = malloc(n * 4); + for (size_t i = 0; i < n; i++) ex[i] = tc->f(src[idx[i]]); + OmegaTensor O = {0, 0}; + int rc = omega_tensor_unary(g, tc->op, V, &O); + float *got = rc ? NULL : rd(O); + size_t mm = got ? bit_mismatches(ex, got, n) : n; + CHECK(!rc && got && mm == 0, "transc %s %s bit-exact vs direct E1 (rc=%d, %zu of %zu differ)", + tc->name, what, rc, mm, n); + free(got); + free(ex); + if (!rc) omega_tensor_release(g, O); +} + +static void test_transc_unary(void) { + const size_t n = 4096; + float *a = malloc(n * 4); + size_t *idx = malloc(n * sizeof(size_t)); + fill(a, n, rand_f32); + for (size_t i = 0; i < NSPECIAL; i++) a[i] = omega_bits_to_float(SPECIALS[i]); + for (size_t i = 0; i < NTSPECIAL; i++) a[NSPECIAL + i] = omega_bits_to_float(TRANSC_SPECIALS[i]); + for (size_t i = NSPECIAL + NTSPECIAL; i < 1024; i++) /* dense in-range sweep */ + a[i] = omega_bits_to_float((uint32_t)((rnd() >> 32) & 0x807fffffU) | ((uint32_t)(118 + (i % 18)) << 23)); + uint64_t s1[1] = {n}, s2[2] = {64, 64}, s3[3] = {8, 16, 32}; + OmegaTensor A1 = mk(1, s1, a), A2 = mk(2, s2, a), A3 = mk(3, s3, a); + uint8_t id_before[32], id_after[32]; + vid(A2, id_before); + + /* transposed view of [64,64]: out[i][j] = f(a[j*64 + i]) */ + OmegaTensor T = {0, 0}; + int rct = omega_tensor_transpose(g, A2, &T); + CHECK(rct == 0, "transc: transpose view rc=%d", rct); + /* strided slice of [8,16,32] with offset: start {1,2,3} stop {8,15,32} step {2,3,5} -> [4,5,6] */ + uint64_t st[3] = {1, 2, 3}, sp[3] = {8, 15, 32}, se[3] = {2, 3, 5}; + OmegaTensor S = {0, 0}; + int rcs = omega_tensor_slice(g, A3, st, sp, se, &S); + CHECK(rcs == 0, "transc: slice view rc=%d", rcs); + /* transpose of the slice: [4,6,5], strides all non-unit and non-row-major */ + OmegaTensor ST = {0, 0}; + int rcst = rcs ? -1 : omega_tensor_transpose(g, S, &ST); + CHECK(rcst == 0, "transc: transpose of slice rc=%d", rcst); + /* broadcast of a row [1,32] (first 32 elements) to [7,32], and a scalar to [3,5] */ + uint64_t srow[2] = {1, 32}, sb[2] = {7, 32}, ssc[2] = {3, 5}; + OmegaTensor R = mk(2, srow, a + 100), B = {0, 0}, C0, BC = {0, 0}; + int rcb = omega_tensor_broadcast_to(g, R, 2, sb, &B); + CHECK(rcb == 0, "transc: broadcast row rc=%d", rcb); + C0 = mk(0, NULL, a + 5); + int rcc = omega_tensor_broadcast_to(g, C0, 2, ssc, &BC); + CHECK(rcc == 0, "transc: broadcast scalar rc=%d", rcc); + + for (size_t k = 0; k < NTRANSC; k++) { + const TranscCase *tc = &TRANSC_CASES[k]; + for (size_t i = 0; i < n; i++) idx[i] = i; + transc_check(tc, A1, a, idx, n, "dense [4096]"); + if (!rct) { + for (size_t i = 0; i < 64; i++) + for (size_t j = 0; j < 64; j++) idx[i * 64 + j] = j * 64 + i; + transc_check(tc, T, a, idx, 64 * 64, "transpose [64,64]"); + } + if (!rcs) { + for (size_t i = 0; i < 4; i++) + for (size_t j = 0; j < 5; j++) + for (size_t l = 0; l < 6; l++) + idx[(i * 5 + j) * 6 + l] = ((1 + 2 * i) * 16 + (2 + 3 * j)) * 32 + (3 + 5 * l); + transc_check(tc, S, a, idx, 4 * 5 * 6, "strided slice [4,5,6]"); + } + if (!rcst) { + for (size_t i = 0; i < 4; i++) + for (size_t l = 0; l < 6; l++) + for (size_t j = 0; j < 5; j++) + idx[(i * 6 + l) * 5 + j] = ((1 + 2 * i) * 16 + (2 + 3 * j)) * 32 + (3 + 5 * l); + transc_check(tc, ST, a, idx, 4 * 6 * 5, "transpose of slice [4,6,5]"); + } + if (!rcb) { + for (size_t i = 0; i < 7; i++) + for (size_t j = 0; j < 32; j++) idx[i * 32 + j] = 100 + j; + transc_check(tc, B, a, idx, 7 * 32, "broadcast [1,32]->[7,32]"); + } + if (!rcc) { + for (size_t i = 0; i < 15; i++) idx[i] = 5; + transc_check(tc, BC, a, idx, 15, "broadcast scalar->[3,5]"); + } + idx[0] = 5; + transc_check(tc, C0, a, idx, 1, "rank 0"); + } + vid(A2, id_after); + CHECK(memcmp(id_before, id_after, 32) == 0, "transc: input value id unchanged"); + + /* NaN results are the canonical quiet NaN (E1 contract), kept bit-exact */ + float neg[1] = {-1.0f}; + OmegaTensor NG = mk(0, NULL, neg), O = {0, 0}; + int rc = omega_tensor_unary(g, OMEGA_TU_LOG2, NG, &O); + float *got = rc ? NULL : rd(O); + CHECK(got && omega_float_to_bits(got[0]) == 0x7fc00000U, "transc: LOG2(-1) is canonical qNaN 0x%08x", + got ? omega_float_to_bits(got[0]) : 0U); + free(got); + if (!rc) omega_tensor_release(g, O); + + /* refusals: unknown op, wrong dtype, stale handle, missing transc entry */ + uint32_t lt0, ls0, lt1, ls1; + omega_tensor_live_counts(g, <0, &ls0); + const int bad_ops[] = {OMEGA_TU_COUNT, OMEGA_TU_COUNT + 1, 99, -1}; + for (size_t i = 0; i < sizeof(bad_ops) / sizeof(bad_ops[0]); i++) { + rc = omega_tensor_unary(g, (OmegaTensorUnaryOp)bad_ops[i], A1, &O); + CHECK(rc == OMEGA_TENSOR_ERR_BAD_ARGS, "unknown unary op %d refused (rc=%d)", bad_ops[i], rc); + } + OmegaTensor H = {0, 0}; + if (!omega_tensor_cast(g, A1, OMEGA_DT_F16, &H)) { + for (size_t k = 0; k < NTRANSC; k++) { + rc = omega_tensor_unary(g, TRANSC_CASES[k].op, H, &O); + CHECK(rc == OMEGA_TENSOR_ERR_DTYPE, "transc %s on F16 refused (rc=%d)", TRANSC_CASES[k].name, rc); + } + omega_tensor_release(g, H); + } else { + CHECK(0, "transc: F32->F16 cast for dtype refusal"); + } + omega_tensor_live_counts(g, <1, &ls1); + CHECK(lt0 == lt1 && ls0 == ls1, "refused unary ops made no tensors (%u/%u -> %u/%u)", lt0, ls0, lt1, ls1); + OmegaTensor DEAD = mk(1, s1, a); + omega_tensor_release(g, DEAD); + for (size_t k = 0; k < NTRANSC; k++) { + rc = omega_tensor_unary(g, TRANSC_CASES[k].op, DEAD, &O); + CHECK(rc == OMEGA_TENSOR_ERR_STALE, "transc %s on released tensor refused (rc=%d)", TRANSC_CASES[k].name, rc); + } + OmegaTensorRealization notransc = *omega_tensor_cpu_realization(); + notransc.name = "NO_TRANSC_ENTRY"; + notransc.transc = NULL; + OmegaTensorCtx *c = NULL; + rc = omega_tensor_ctx_create(8, ¬ransc, &c); + CHECK(rc == 0, "realization without transc entry accepted for other ops (rc=%d)", rc); + if (!rc) { + OmegaTensor X = {0, 0}, Y = {0, 0}; + omega_tensor_from_f32(c, 1, s1, a, &X); + for (size_t k = 0; k < NTRANSC; k++) { + rc = omega_tensor_unary(c, TRANSC_CASES[k].op, X, &Y); + CHECK(rc == OMEGA_TENSOR_ERR_REALIZATION, "transc %s refused without transc entry (rc=%d)", + TRANSC_CASES[k].name, rc); + } + rc = omega_tensor_unary(c, OMEGA_TU_SQRT, X, &Y); + CHECK(rc == 0, "SQRT still served without transc entry (rc=%d)", rc); + omega_tensor_ctx_destroy(c); + } + + OmegaTensor all[] = {A1, A2, A3, R, C0, NG}; + for (size_t i = 0; i < sizeof(all) / sizeof(all[0]); i++) omega_tensor_release(g, all[i]); + if (!rct) omega_tensor_release(g, T); + if (!rcs) omega_tensor_release(g, S); + if (!rcst) omega_tensor_release(g, ST); + if (!rcb) omega_tensor_release(g, B); + if (!rcc) omega_tensor_release(g, BC); + free(a); + free(idx); +} + /* ---- 8. determinism ------------------------------------------------------- */ static void kat_digest(uint8_t out[32]) { uint64_t save = g_rng; @@ -805,6 +996,7 @@ int main(void) { test_reduce_parity(); test_matmul_parity(); test_mutations(); + test_transc_unary(); test_determinism(); /* every test released what it made */ uint32_t lt, ls; diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh index 6e08af277..393cb5413 100755 --- a/tools/tensor_mutations.sh +++ b/tools/tensor_mutations.sh @@ -8,7 +8,7 @@ set -u cd "$(dirname "$0")/.." || exit 2 SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/tensor-mut.XXXXXX") || exit 2 trap 'rm -rf "$SCRATCH"' EXIT INT TERM -DEPS="src/omega_numeric_reduce.c src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c \ +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" @@ -19,7 +19,9 @@ MUTATIONS='RELEASE_BUMP|omega_tensor.c|s/(\*gen)++/(void)0/ STORAGE_GEN_CHECK|omega_tensor.c|s/ || s->gen != h.generation// BCAST_ZERO_STRIDE|omega_tensor.c|s/o.strides\[d\] = 0;/o.strides[d] = in->strides[sd];/ PERMUTE_STRIDES|omega_tensor.c|s/in->strides\[perm\[d\]\]/in->strides[d]/ -SLICE_OFFSET|omega_tensor.c|s/start\[d\], in->strides\[d\]/start[d], 1/' +SLICE_OFFSET|omega_tensor.c|s/start\[d\], in->strides\[d\]/start[d], 1/ +TRANSC_EXP2_LOG2_SWAP|omega_tensor_cpu.c|s/= omega_math_exp2, \(.*\)= omega_math_log2,/= omega_math_log2, \1= omega_math_exp2,/ +UNARY_VIEW_STRIDE|omega_tensor.c|s/gather(s, .in, src);/dense_strides(in.rank, in.shape, in.strides); gather(s, \&in, src);/' # Baseline: the unmutated build must PASS, otherwise every mutant would # look "caught" (e.g. the test refusing an unsuitable FP environment). ```