Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tools/tensor_mutations.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tools / tensor_mutations.sh` 207 lines ยท 13621 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # M20 OMEGA_TENSOR mutation sweep, a thin adapter over tools/mutation_runner.sh. 18 # For each rule marked MUT: in src/tensor/*.c the runner copies the tree 19 # to a scratch directory, breaks that one rule, rebuilds the CPU test there and 20 # requires the test to FAIL. A mutation that does not apply, does not build or 21 # is not caught fails the sweep. The adapter maps the runner verdicts back to 22 # the legacy stdout lines. CPU only, no device. Shell only (no Python). 23 set -u 24 cd "$(dirname "$0")/.." || exit 2 25 SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/tensor-mut.XXXXXX") || exit 2 26 trap 'rm -rf "$SCRATCH"' EXIT INT TERM 27 28 # --gb10 PHYSICS_DIR: the GB10 realization table (src/tensor/omega_tensor_gb10.c, 29 # M20 cut gb10). Builds tests/test_omega_tensor_gb10.c against the physics 30 # checkout and runs it WITHOUT --chip (host self checks, no device). Also 31 # requires, via nm, that the GB10 table references no CPU or reference tier 32 # (no silent CPU fallback). Each GB10_MUTATIONS rule must then make the host 33 # run or the nm check fail. Never opens the device. 34 if [ "${1:-}" = "--gb10" ]; then 35 PHYS=${2:-} 36 [ -n "$PHYS" ] && [ -d "$PHYS" ] || { echo "tensor gb10 mutation sweep: --gb10 needs the physics checkout"; exit 2; } 37 NV=$PHYS/third_party/nvidia-open-580.173.02 38 GFLAGS="-std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -I$PHYS/forge -I$PHYS/nvrm -I$PHYS/m16 \ 39 -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" 40 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 \ 41 src/omega_numeric_divsqrt_gb10.c src/omega_numeric_provenance.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ 42 src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/forge_realization.c src/aegis_verification.c src/omega_om_units.c \ 43 $PHYS/forge/forge_descriptor.c $PHYS/forge/forge_realize.c $PHYS/sha256_clean.c $PHYS/nvrm/nvrm.c $PHYS/m16/m16_native.c" 44 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|omega_tensor_cpu_realization|omega_ds_cpu_semantic|omega_ds_host_exec)\b' 45 GB10_MUTATIONS='GB10_NO_CPU_FALLBACK|s/return OMEGA_NUMERIC_ERR_NOT_ENCODED;/return omega_numeric_cpu_realize(op, a, b, c, out, n);/ 46 GB10_TRANSC_NO_CPU_FALLBACK|s/if (k < 0) return OMEGA_NUMERIC_ERR_NOT_ENCODED;/if (k < 0) return omega_tensor_cpu_realization()->transc(op, a, out, n);/ 47 GB10_TRANSC_EXP_LOG_SWAP|s/\[OMEGA_TU_EXP\] = 1 + OMEGA_DS_EXP, \[OMEGA_TU_LOG\] = 1 + OMEGA_DS_LOG,/[OMEGA_TU_EXP] = 1 + OMEGA_DS_LOG, [OMEGA_TU_LOG] = 1 + OMEGA_DS_EXP,/ 48 GB10_REDUCE_MAX_N|s/if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS;/(void)0;/ 49 GB10_ROWS_MAX_N|s/if (n > OMEGA_REDUCE_GB10_MAX_N) return OMEGA_NUMERIC_ERR_OPERANDS;/(void)0;/' 50 # gb10_try DIR: 0 if build + host run + nm check all pass, 1 otherwise 51 gb10_try() { 52 gcc $GFLAGS -I"$1" -o "$SCRATCH/g" tests/test_omega_tensor_gb10.c "$1/omega_tensor.c" "$1/omega_tensor_cpu.c" \ 53 "$1/omega_tensor_reduce_seam.c" "$1/omega_tensor_gb10.c" $GDEPS > "$SCRATCH/gbuild.log" 2>&1 || return 2 54 gcc $GFLAGS -I"$1" -c -o "$SCRATCH/g.o" "$1/omega_tensor_gb10.c" >> "$SCRATCH/gbuild.log" 2>&1 || return 2 55 if nm -u "$SCRATCH/g.o" | grep -Eq "$CPU_TIER"; then echo " nm: GB10 table references a CPU/reference tier"; return 1; fi 56 "$SCRATCH/g" > "$SCRATCH/grun.log" 2>&1 || return 1 57 return 0 58 } 59 gb10_try src/tensor; rc=$? 60 if [ "$rc" -ne 0 ]; then 61 head -20 "$SCRATCH/gbuild.log" "$SCRATCH/grun.log" 2>/dev/null 62 echo "tensor gb10 mutation sweep: FAIL (unmutated GB10 baseline does not pass, rc $rc)"; exit 1 63 fi 64 grep -E '^(TENSOR_GB10_HOST|HOST_HARNESS_MUTANTS|HOST_MUTANT_)' "$SCRATCH/grun.log" 65 echo "GB10 nm check: PASS (no CPU or reference tier referenced by omega_tensor_gb10.c)" 66 gfail=0; gtotal=0 67 old_ifs=$IFS 68 IFS=' 69 ' 70 for m in $GB10_MUTATIONS; do 71 IFS=$old_ifs 72 gname=${m%%|*}; gexpr=${m#*|} 73 gtotal=$((gtotal + 1)) 74 rm -rf "$SCRATCH/tensor" && cp -r src/tensor "$SCRATCH/tensor" 75 sed -i "/MUT:$gname/ $gexpr" "$SCRATCH/tensor/omega_tensor_gb10.c" 76 if cmp -s src/tensor/omega_tensor_gb10.c "$SCRATCH/tensor/omega_tensor_gb10.c"; then 77 echo "MUTATION $gname: NOT APPLIED (marker or pattern missing)"; gfail=1; continue 78 fi 79 gb10_try "$SCRATCH/tensor"; rc=$? 80 case $rc in 81 0) echo "MUTATION $gname: NOT CAUGHT (host checks and nm still pass)"; gfail=1 ;; 82 2) head -5 "$SCRATCH/gbuild.log"; echo "MUTATION $gname: does not build (fix the sed expression)"; gfail=1 ;; 83 *) echo "MUTATION $gname: caught ($(grep -c '^FAIL' "$SCRATCH/grun.log" 2>/dev/null) failing checks)" ;; 84 esac 85 done 86 IFS=$old_ifs 87 if [ "$gfail" -ne 0 ]; then echo "tensor gb10 mutation sweep: FAIL"; exit 1; fi 88 echo "tensor gb10 mutation sweep: PASS ($gtotal of $gtotal mutations caught)" 89 exit 0 90 fi 91 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 \ 92 src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c" 93 FLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -O2 -DOMEGA_NUMERIC_CPU_ONLY -DOMEGA_TENSOR_TEST_HOOKS" 94 95 # name|file|sed expression (applied only to the line carrying MUT:) 96 # Reduction order and padding mutations live in the E1 WP-D suite 97 # (test-numeric-reduce-cpu, RED_DIFFERENT_ORDER_CAUGHT): the seam calls it. 98 MUTATIONS='RELEASE_BUMP|omega_tensor.c|s/(\*gen)++/(void)0/ 99 STORAGE_GEN_CHECK|omega_tensor.c|s/ || s->gen != h.generation// 100 BCAST_ZERO_STRIDE|omega_tensor.c|s/o.strides\[d\] = 0;/o.strides[d] = in->strides[sd];/ 101 PERMUTE_STRIDES|omega_tensor.c|s/in->strides\[perm\[d\]\]/in->strides[d]/ 102 SLICE_OFFSET|omega_tensor.c|s/start\[d\], in->strides\[d\]/start[d], 1/ 103 TRANSC_EXP2_LOG2_SWAP|omega_tensor_cpu.c|s/= omega_math_exp2, \(.*\)= omega_math_log2,/= omega_math_log2, \1= omega_math_exp2,/ 104 UNARY_VIEW_STRIDE|omega_tensor.c|s/gather(s, .in, src);/dense_strides(in.rank, in.shape, in.strides); gather(s, \&in, src);/ 105 TRANSC_EXP_LOG_SWAP|omega_tensor_cpu.c|s/= omega_math_exp, \(.*\)= omega_math_log,/= omega_math_log, \1= omega_math_exp,/ 106 RELU_NEG_ZERO|omega_tensor.c|s/if (u >> 31) return 0U;/if (u >> 31) return u == 0x80000000U ? u : 0U;/ 107 RELU_NAN_PAYLOAD|omega_tensor.c|s/return OMEGA_QNAN_BITS;/return u;/ 108 TRANSC_RSQRT_ERF_SWAP|omega_tensor_cpu.c|s/= omega_math_rsqrt, \(.*\)= omega_math_erf,/= omega_math_erf, \1= omega_math_rsqrt,/ 109 GELU_VIEW_STRIDE|omega_tensor.c|s/gather(s, .in, src);/if (op == OMEGA_TU_GELU) { dense_strides(in.rank, in.shape, in.strides); } gather(s, \&in, src);/ 110 TRIG_SIN_COS_SWAP|omega_tensor_cpu.c|s/= omega_math_sin, \(.*\)= omega_math_cos,/= omega_math_cos, \1= omega_math_sin,/ 111 TRIG_DOMAIN_NUMBER|omega_tensor_cpu.c|s/out\[i\] = f(a\[i\]);/{ out[i] = f(a[i]); if ((op == OMEGA_TU_SIN || op == OMEGA_TU_COS) \&\& out[i] != out[i]) out[i] = 0.0f; }/ 112 ZEROS_NEG0|omega_tensor.c|s/shape, 0.0f, out)/shape, -0.0f, out)/ 113 NEG_SUB|omega_tensor.c|s/return u ^ 0x80000000U;/return omega_float_to_bits(0.0f - omega_bits_to_float(u));/ 114 NEG_NAN|omega_tensor.c|s/return 0x7fc00000U;/return u ^ 0x80000000U;/ 115 FULL_CANON|omega_tensor.c|s/uint32_t u = omega_float_to_bits(value);/uint32_t u = canon_bits(OMEGA_DT_F32, (const uint8_t *)\&value);/ 116 EMBED_START|omega_tensor.c|s/start\[d\], ds\[d\]/start[d] + 1, ds[d]/ 117 EMBED_STEP|omega_tensor.c|s/ds\[d\], st, /ds[d], 1, / 118 CONCAT_AXIS_OFFSET|omega_tensor.c|s/aoff \* ds\[axis\]/aoff/ 119 CMP_FALSE_NEG_ZERO|omega_tensor_cpu.c|s/zero = 0.0f;/zero = -0.0f;/ 120 CMP_EQ_NAN_TRUE|omega_tensor.c|s/OMEGA_NOP_FSETP_EQ_SEL,/OMEGA_NOP_FSETP_EQU_SEL,/ 121 WHERE_ACCEPTS_HALF|omega_tensor.c|s/u != OMEGA_TENSOR_MASK_FALSE_BITS)/u != OMEGA_TENSOR_MASK_FALSE_BITS \&\& u != 0x3f000000U)/ 122 REDUCE_AXES_DESCENDING|omega_tensor.c|s/for (uint32_t d = in.rank; d-- > 0;)/for (uint32_t d = 0; d < in.rank; d++)/ 123 REDUCE_AXES_KEEPDIMS|omega_tensor.c|s/keep\[n\] = keepdims;/keep[n] = keepdims \&\& false;/ 124 SUM_TO_SHAPE_SIZE1|omega_tensor.c|s/ax\[n\] = d; keep\[n\] = true; n++;/(void)0;/' 125 126 STORE_MUTATIONS='TSTORE_HASH_VERIFY|s/memcmp(dig, sl->payload_sha, 32) != 0 || memcmp(vid, sl->value_id, 32) != 0/0/ 127 TSTORE_SHORT_RECORD|s/len != HDR_BYTES + count \* REC_BYTES/0/ 128 TSTORE_GEN_RESET|s/sl->gen = r->gen + 1;/sl->gen = 1;/ 129 TSTORE_RENAME_BEFORE_WRITE|s/const char \*wpath = tmp;/const char *wpath = final;/ 130 TSTORE_RECORD_SUM|s/memcmp(sum, in + REC_SUM, 32) != 0/0/ 131 TSTORE_HEADER_SUM|s/memcmp(sum, st->jbuf + HDR_SUM, 32) != 0/0/' 132 STORE_SRCS="src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c" 133 # The runner reads its own env var ONLY; the legacy sweep never did. 134 unset ONLY 135 fail=0 136 total=0 137 138 # run_block ROWSFILE BUILDCMD TESTCMD: run the shared runner (marker reader, 139 # baseline check on) and print one legacy "MUTATION : ..." line per 140 # mutant, in row order. Returns 3 if the unmutated baseline does not pass. 141 # Sets fail=1 if the runner reported fewer or more verdict lines than rows. 142 # Legacy notes that need no mapping beyond the verdict: KILLED note 143 # " failing case(s), first: ..." becomes "caught ( failing checks)", 144 # "harness exit" (nonzero exit, no FAIL line) becomes "caught (0 failing 145 # checks)". The 5-line build-log head the old script printed on a build error 146 # is replaced by the runner's one-line build error note. 147 run_block() { 148 rb_rows=$1 149 "tools/mutation_runner.sh" -k marker -m "$rb_rows" -t "$3" -b "$2" -c "src tests" -f FAIL -B \ 150 > "$SCRATCH/rb.out" 2> "$SCRATCH/rb.err" 151 if grep -q 'unmutated baseline does not pass' "$SCRATCH/rb.out"; then 152 cat "$SCRATCH/rb.err"; return 3 153 fi 154 rb_seen=0 155 while IFS= read -r rb_l; do 156 rb_id=${rb_l%% *}; rb_r=${rb_l#* }; rb_st=${rb_r%% *} 157 rb_note=${rb_l#*\(}; rb_note=${rb_note%)} 158 total=$((total + 1)); rb_seen=$((rb_seen + 1)) 159 case $rb_st in 160 KILLED) 161 rb_n=$(printf '%s\n' "$rb_note" | sed -n 's/^\([0-9][0-9]*\) failing case.*/\1/p') 162 echo "MUTATION $rb_id: caught (${rb_n:-0} failing checks)" ;; 163 SURVIVED*) echo "MUTATION $rb_id: NOT CAUGHT (tests still pass)"; fail=1 ;; 164 *) 165 case $rb_note in 166 "build failed"*) echo "$rb_note"; echo "MUTATION $rb_id: does not build (fix the sed expression)" ;; 167 *) echo "MUTATION $rb_id: NOT APPLIED (marker or pattern missing)" ;; 168 esac 169 fail=1 ;; 170 esac 171 done < "$SCRATCH/rb.err" 172 # The legacy sweep walked the rows itself, so a row could not be skipped. 173 # A runner that died, was killed or reported nothing must not pass silently: 174 # one verdict line per row is required. 175 rb_want=$(grep -c '|' "$rb_rows") 176 if [ "$rb_seen" -ne "$rb_want" ]; then 177 echo "MUTATION $rb_rows: runner reported $rb_seen verdicts for $rb_want rows (runner died or reported nothing)" 178 fail=1 179 fi 180 } 181 182 # Main block. Rows are name|file|sed expression; the file column is relative 183 # to src/tensor, the runner wants it relative to the tree root. 184 printf '%s\n' "$MUTATIONS" | sed 's#^\([A-Z0-9_]*\)|#\1|src/tensor/#' > "$SCRATCH/main.rows" 185 # Baseline: the unmutated build must PASS, otherwise every mutant would 186 # look "caught" (e.g. the test refusing an unsuitable FP environment). 187 if ! run_block "$SCRATCH/main.rows" \ 188 "gcc $FLAGS -Isrc -Isrc/tensor -o .tensor_t tests/test_omega_tensor.c src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $DEPS" \ 189 ./.tensor_t; then 190 echo "tensor mutation sweep: FAIL (unmutated baseline does not pass)"; exit 1 191 fi 192 # M20 receipt writer mutants (MUT: markers in tools/m20_receipt.sh), own sweep. 193 tools/m20_receipt_mutations.sh || fail=1 194 195 # Crash-safe storage lifetime (omega_tensor_store.c): each mutant rebuilds 196 # tests/test_omega_tensor_store.c against the mutated copy and must FAIL it. 197 # (Skipping the fsync before rename is not observable without power loss, so 198 # it is not a mutant here.) Rows are name|expr, the file is implied. 199 printf '%s\n' "$STORE_MUTATIONS" | sed 's#^\([A-Z0-9_]*\)|#\1|src/tensor/omega_tensor_store.c|#' > "$SCRATCH/store.rows" 200 if ! run_block "$SCRATCH/store.rows" \ 201 "gcc $FLAGS -Isrc -Isrc/tensor -o .tstore_t tests/test_omega_tensor_store.c src/tensor/omega_tensor_store.c $STORE_SRCS $DEPS" \ 202 ./.tstore_t; then 203 echo "MUTATION store baseline: unmutated store test does not pass"; fail=1 204 fi 205 206 if [ "$fail" -ne 0 ]; then echo "tensor mutation sweep: FAIL"; exit 1; fi 207 echo "tensor mutation sweep: PASS ($total of $total mutations caught)"