interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / mk / tensor.mk

114 lines · 7176 bytes Raw Blame History
1# M20 OMEGA_TENSOR (docs/tensor/M20_OMEGA_TENSOR.md): semantic tensor layer +
2# CPU realization. Files under src/tensor/ and tests/test_omega_tensor.c.
3# Picked up by `-include mk/*.mk`. Not part of `all` or `test`. CPU only:
4# opens no device, never touches the GB10.
5#
6# test-tensor CPU tests plain and with ASan/UBSan, then
7# test-tensor-no-hooks
8# test-tensor-no-hooks builds src/tensor/*.c with the default (library)
9# flags and requires, via nm, that the test-only
10# hook omega_tensor_test_set_storage_generation is
11# absent. Only the test binaries define
12# OMEGA_TENSOR_TEST_HOOKS.
13# test-tensor-mutations applies each MUT: source mutation in a scratch copy
14# and proves test-tensor's binary then fails
15# test-m20-receipt tests/test_m20_receipt.sh: content-addressed M20
16# receipt writer tools/m20_receipt.sh (fixtures only)
17# test-tensor-e1-reduce alias of test-tensor (the reduction seam always
18# calls omega_reduce_cpu, E1 WP-D, omega #134)
19# test-tensor-store crash-safe storage lifetime (omega_tensor_store):
20# plain + ASan/UBSan, then test-tensor-no-hooks
21ifndef TENSOR_MK
22TENSOR_MK := 1
23.PHONY: test-tensor test-tensor-no-hooks test-tensor-mutations test-tensor-e1-reduce test-tensor-store
24TENSOR_CFLAGS = -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -Isrc/tensor \
25 -DOMEGA_NUMERIC_CPU_ONLY
26TENSOR_SRCS = src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c \
27 src/omega_numeric_reduce.c src/omega_numeric_transc.c
28TENSOR_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c \
29 src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c
30TENSOR_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
31# CR-5 tests are #included by tests/test_omega_tensor.c: rebuild when they change.
32TENSOR_HDRS += tests/tensor_reduce_multi_tests.inc
33# Test builds only: compiles the test-only storage-generation hook.
34TENSOR_TEST_FLAGS = -DOMEGA_TENSOR_TEST_HOOKS
35TENSOR_HOOK_SYMS = omega_tensor_test_set_storage_generation omega_tensor_store_test_set_crash_step
36# Crash-safe storage lifetime (omega_tensor_store); targets at the end of this file.
37TENSOR_STORE_SRCS = src/tensor/omega_tensor_store.c
38TENSOR_STORE_HDRS = src/tensor/omega_tensor_store.h
39
40TENSOR_OMC ?= seed/out/omc
41TENSOR_OM_CORE = src/tensor/tensor_shape.om src/tensor/tensor_ops.om src/train/tg_sha256.om \
42 src/tensor/omega_tensor_cpu.om src/tensor/omega_tensor_gb10.om src/tensor/omega_tensor.om
43TENSOR_STORE_OM_SRCS = src/tensor/tensor_shape.om src/tensor/tensor_ops.om src/train/tg_sha256.om \
44 src/tensor/omega_tensor_cpu.om src/tensor/omega_tensor.om src/tensor/omega_tensor_store.om
45
46$(OUT_DIR)/test_omega_tensor: src/tensor/test_tensor.om $(TENSOR_OM_CORE) $(TENSOR_OMC)
47 @mkdir -p $(OUT_DIR)
48 (printf 'om2\n'; sed -e '/^om2$$/d' -e 's/^export fn /fn /' $(TENSOR_OM_CORE) src/tensor/test_tensor.om) | $(TENSOR_OMC) > $@ && chmod +x $@
49
50test-tensor: $(OUT_DIR)/test_omega_tensor
51 ./$(OUT_DIR)/test_omega_tensor
52
53# Default (library) build of the tensor sources: no OMEGA_TENSOR_TEST_HOOKS.
54# Fails if any test-only hook symbol is defined or referenced in the objects.
55test-tensor-no-hooks: src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $(TENSOR_HDRS) \
56 $(TENSOR_STORE_SRCS) $(TENSOR_STORE_HDRS)
57 @mkdir -p $(OUT_DIR)/tensor-lib
58 gcc $(TENSOR_CFLAGS) -O2 -c -o $(OUT_DIR)/tensor-lib/omega_tensor.o src/tensor/omega_tensor.c
59 gcc $(TENSOR_CFLAGS) -O2 -c -o $(OUT_DIR)/tensor-lib/omega_tensor_cpu.o src/tensor/omega_tensor_cpu.c
60 gcc $(TENSOR_CFLAGS) -O2 -c -o $(OUT_DIR)/tensor-lib/omega_tensor_reduce_seam.o src/tensor/omega_tensor_reduce_seam.c
61 gcc $(TENSOR_CFLAGS) -O2 -c -o $(OUT_DIR)/tensor-lib/omega_tensor_store.o src/tensor/omega_tensor_store.c
62 @if nm $(OUT_DIR)/tensor-lib/omega_tensor_store.o | grep -q "\b_exit\b"; then \
63 echo "test-tensor-no-hooks: FAIL (crash hook _exit referenced by default omega_tensor_store.o)"; exit 1; fi
64 @nm $(OUT_DIR)/tensor-lib/omega_tensor.o | grep -q " T omega_tensor_ctx_create\b" \
65 || { echo "test-tensor-no-hooks: FAIL (nm sanity: omega_tensor_ctx_create not found)"; exit 1; }
66 @for s in $(TENSOR_HOOK_SYMS); do \
67 if nm $(OUT_DIR)/tensor-lib/*.o | grep -q "\b$$s\b"; then \
68 echo "test-tensor-no-hooks: FAIL ($$s present in default build)"; exit 1; fi; \
69 done; echo "test-tensor-no-hooks: PASS (test-only hook absent from default build)"
70
71test-tensor-mutations:
72 tools/tensor_mutations.sh
73
74# Kept as an alias: the seam now always calls omega_reduce_cpu (E1 WP-D, #134 merged).
75test-tensor-e1-reduce: test-tensor
76
77.PHONY: test-m20-receipt
78test-m20-receipt:
79 tests/test_m20_receipt.sh
80
81# Crash-safe storage lifetime (src/tensor/omega_tensor_store.{c,h}): round
82# trip, crash at every commit phase (fork + test-only hook), torn writes,
83# crafted journals. Plain and ASan/UBSan, then test-tensor-no-hooks. Writes
84# only under $TMPDIR (default /tmp). Its mutants run in test-tensor-mutations.
85
86$(OUT_DIR)/test_omega_tensor_store: src/tensor/test_tensor_store.om $(TENSOR_STORE_OM_SRCS) $(TENSOR_OMC)
87 @mkdir -p $(OUT_DIR)
88 (printf 'om2\n'; sed -e '/^om2$$/d' -e 's/^export fn /fn /' $(TENSOR_STORE_OM_SRCS) src/tensor/test_tensor_store.om) | $(TENSOR_OMC) > $@ && chmod +x $@
89
90test-tensor-store: $(OUT_DIR)/test_omega_tensor_store
91 @rm -rf $(OUT_DIR)/tensor_store_scratch && mkdir -p $(OUT_DIR)/tensor_store_scratch
92 ./$(OUT_DIR)/test_omega_tensor_store $(OUT_DIR)/tensor_store_scratch
93
94# ---- GB10 realization table (M20 cut gb10) ---------------------------------
95# test-tensor-gb10-host PHYSICS_DIR=<physics checkout at physics.lock>:
96# builds the GB10 table + tests/test_omega_tensor_gb10.c
97# against physics and runs host self checks only (no
98# --chip, no device), the nm no-CPU-fallback check and
99# the GB10 MUT: mutants (tools/tensor_mutations.sh --gb10)
100# test-tensor-gb10-chip the chip parity gate: tests/run_tensor_chip.sh (pins,
101# clean trees, /tmp/aien-gb10.lock, receipt). Refuses
102# unless GB10_CHIP_RUN=1 is set, so it never runs by
103# accident. Never pass a quiet flag.
104.PHONY: test-tensor-gb10-host test-tensor-gb10-chip
105test-tensor-gb10-host:
106 @test -n "$(PHYSICS_DIR)" && test -d "$(PHYSICS_DIR)" \
107 || { echo "test-tensor-gb10-host: set PHYSICS_DIR to the physics checkout"; exit 2; }
108 tools/tensor_mutations.sh --gb10 "$(PHYSICS_DIR)"
109
110test-tensor-gb10-chip:
111 @test "$$GB10_CHIP_RUN" = 1 || { echo "test-tensor-gb10-chip: chip run refused (set GB10_CHIP_RUN=1; forge only)"; exit 2; }
112 @test -n "$(PHYSICS_DIR)" || { echo "test-tensor-gb10-chip: set PHYSICS_DIR"; exit 2; }
113 tests/run_tensor_chip.sh --physics-dir "$(PHYSICS_DIR)"
114endif