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 / om-encoder.mk

88 lines · 7217 bytes Raw Blame History
1# The sm_121 instruction encoder in seeded Omega (om/encoder/bw_enc_sm121.om, twin of aien-dev/CUDApp#79), linked
2# through the omega-bridge native binding src/omega_om_units.c that om/units.sh generates. The C encoder in
3# src/omega_blackwell_codegen.c is migration-pending: the freestanding build and the oracle builds only.
4# make test-om-encoder (no Omega tools needed)
5# 1. the golden-word fixture verifiers (nvcc/nvdisasm oracles) through the .om encoder;
6# 2. a build with CUDAPP_MIGRATION_PENDING_ENCODER_DIFF encodes every codegen fixture both ways and must log
7# only SAME lines; 3. its red check: the same build with one flipped output bit must abort.
8# make test-om-encoder-corpus every kernel of the sm121dis corpus (tools/sm121dis/corpus.sh) built three ways:
9# .om (OUT_DIR), C oracle ($(OUT_DIR)-enc-c), diff ($(OUT_DIR)-enc-diff); the .om and C kernel sets must be
10# identical file for file, and the diff build must log no DIFFER line. The num_*.bin kernels come from the
11# numeric encoder (build/test_omega_{divsqrt,ldst}_gb10_cpu, shared by all three runs), not from this one.
12# make test-om-encoder-mutants three mutant .om encoders, each compiled by the pinned omc, must go red
13# The binding itself regenerates byte for byte in tests/gates/run.sh om-units (om/units.sh --check). The mutants need
14# OMEGA_OMC (default seed/out/omc, born from the seed by seed/omega-from-seed.sh) and OMEGA_BRIDGE_DIR (an
15# aien-dev/omega-bridge checkout at om/omega-bridge.lock); without them they exit 3 (NOT_RUN), never PASS.
16OMEGA_OMC ?= seed/out/omc
17OMEGA_BRIDGE_DIR ?= ../omega-bridge
18OM_ENC_DIR = $(OUT_DIR)/om-encoder
19OM_ENC_TEST_DEPS = tests/test_omega_codegen_freestanding.c src/omega_blackwell_codegen.h src/omega_blackwell_matmul.h
20OM_ENC_SRCS = src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c
21OM_ENC_BUILD = gcc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -Isrc
22# The mutant bindings keep the other units, so sha256_* (src/omega_api_decl.h) still resolves; only the encoder changes.
23OM_ENC_OTHER_UNITS = om/sha256/sha256-om2.om om/blake3/b3unit.om
24
25.PHONY: test-om-encoder test-om-encoder-corpus test-om-encoder-mutants test-om-encoder-guard
26$(OM_ENC_DIR)/codegen_om: $(OM_ENC_TEST_DEPS) $(OM_ENC_SRCS) src/omega_om_units.c src/omega_native.h
27 @mkdir -p $(OM_ENC_DIR)
28 $(OM_ENC_BUILD) -o $@ tests/test_omega_codegen_freestanding.c $(OM_ENC_SRCS) src/omega_om_units.c
29$(OM_ENC_DIR)/codegen_diff: $(OM_ENC_TEST_DEPS) $(OM_ENC_SRCS) src/omega_om_units.c src/omega_native.h
30 @mkdir -p $(OM_ENC_DIR)
31 $(OM_ENC_BUILD) -DCUDAPP_MIGRATION_PENDING_ENCODER_DIFF -o $@ tests/test_omega_codegen_freestanding.c \
32 $(OM_ENC_SRCS) src/omega_om_units.c
33$(OM_ENC_DIR)/codegen_diff_red: $(OM_ENC_TEST_DEPS) $(OM_ENC_SRCS) src/omega_om_units.c src/omega_native.h
34 @mkdir -p $(OM_ENC_DIR)
35 $(OM_ENC_BUILD) -DCUDAPP_MIGRATION_PENDING_ENCODER_DIFF -DCUDAPP_ENCODER_DIFF_SELFTEST -o $@ \
36 tests/test_omega_codegen_freestanding.c $(OM_ENC_SRCS) src/omega_om_units.c
37
38test-om-encoder: test-om-encoder-guard $(OM_ENC_DIR)/codegen_om $(OM_ENC_DIR)/codegen_diff $(OM_ENC_DIR)/codegen_diff_red
39 $(OM_ENC_DIR)/codegen_om --golden
40 rm -f $(OM_ENC_DIR)/diff.log
41 CUDAPP_ENCODER_DIFF_LOG=$(OM_ENC_DIR)/diff.log $(OM_ENC_DIR)/codegen_diff --golden
42 CUDAPP_ENCODER_DIFF_LOG=$(OM_ENC_DIR)/diff.log $(OM_ENC_DIR)/codegen_diff --dump > $(OM_ENC_DIR)/dump_diff.txt
43 @same=$$(grep -c ' SAME$$' $(OM_ENC_DIR)/diff.log); other=$$(grep -vc ' SAME$$' $(OM_ENC_DIR)/diff.log); \
44 if [ "$$same" -eq 0 ] || [ "$$other" -ne 0 ]; then echo "FAIL encoder diff: $$same SAME, $$other other lines"; exit 1; fi; \
45 echo "encoder diff: .om and C byte-identical on $$(grep -c '^insn ' $(OM_ENC_DIR)/diff.log) golden instructions and $$(grep -c '^program ' $(OM_ENC_DIR)/diff.log) fixture programs"
46 @if CUDAPP_ENCODER_DIFF_LOG=$(OM_ENC_DIR)/diff_red.log $(OM_ENC_DIR)/codegen_diff_red --dump > /dev/null 2>&1; then \
47 echo "RED CHECK BROKEN: a flipped bit passed the encoder diff"; exit 1; \
48 else echo "red check: one flipped bit aborts the encoder diff, as it must"; fi
49
50test-om-encoder-corpus:
51 $(MAKE) OUT_DIR=$(OUT_DIR) CUDAPP_ENCODER=om sm121dis-corpus-bins
52 $(MAKE) OUT_DIR=$(OUT_DIR)-enc-c CUDAPP_ENCODER=c sm121dis-corpus-bins
53 $(MAKE) OUT_DIR=$(OUT_DIR)-enc-diff CUDAPP_ENCODER=diff sm121dis-corpus-bins
54 rm -rf $(OM_ENC_DIR)/k-om $(OM_ENC_DIR)/k-c $(OM_ENC_DIR)/k-diff $(OM_ENC_DIR)/corpus-diff.log
55 @mkdir -p $(OM_ENC_DIR)
56 sh tools/sm121dis/corpus.sh $(OUT_DIR) $(OM_ENC_DIR)/k-om
57 sh tools/sm121dis/corpus.sh $(OUT_DIR)-enc-c $(OM_ENC_DIR)/k-c
58 CUDAPP_ENCODER_DIFF_LOG=$(abspath $(OM_ENC_DIR))/corpus-diff.log sh tools/sm121dis/corpus.sh $(OUT_DIR)-enc-diff $(OM_ENC_DIR)/k-diff
59 diff -r $(OM_ENC_DIR)/k-om $(OM_ENC_DIR)/k-c
60 diff -r $(OM_ENC_DIR)/k-om $(OM_ENC_DIR)/k-diff
61 @if grep -v ' SAME$$' $(OM_ENC_DIR)/corpus-diff.log; then echo "FAIL corpus encoder diff"; exit 1; fi
62 @echo "encoder corpus: $$(ls $(OM_ENC_DIR)/k-om/*.bin | grep -vc '/num_') distinct codegen kernels identical .om vs C (plus $$(ls $(OM_ENC_DIR)/k-om/num_*.bin | wc -l) numeric-encoder kernels); diff build $$(grep -c '^program ' $(OM_ENC_DIR)/corpus-diff.log) program encodes and $$(grep -c '^insn ' $(OM_ENC_DIR)/corpus-diff.log) single-instruction encodes, all SAME"
63
64# Each mutant is one edit of the .om source, compiled by the pinned omc into its own binding; the hosted
65# fixture test linked with it must fail the golden words or differ from the C-encoded freestanding dump.
66OM_ENC_MUTANTS = 's/^ret or base shl rb o 1 16$$/ret or base shl rb o 1 17/' \
67 's/^p = 262144$$/p = 0/' \
68 's/^const NOPC ulong 1032192$$/const NOPC ulong 1032193/'
69test-om-encoder-mutants: build/test_codegen_freestanding
70 @[ -x $(OMEGA_OMC) ] && [ -f $(OMEGA_BRIDGE_DIR)/src/native.om ] || { echo "NOT_RUN: set OMEGA_OMC and OMEGA_BRIDGE_DIR"; exit 3; }
71 @mkdir -p $(OM_ENC_DIR)
72 ./build/test_codegen_freestanding --dump > $(OM_ENC_DIR)/c-dump.txt
73 @n=0; for m in $(OM_ENC_MUTANTS); do n=$$((n+1)); d=$(OM_ENC_DIR)/mutant$$n; rm -rf $$d; mkdir -p $$d; \
74 sed "$$m" om/encoder/bw_enc_sm121.om > $$d/bw_enc_sm121.om; \
75 if cmp -s $$d/bw_enc_sm121.om om/encoder/bw_enc_sm121.om; then echo "MUTANT $$n BROKEN: '$$m' changed nothing"; exit 1; fi; \
76 OMEGA_UNITS="$(OM_ENC_OTHER_UNITS) $$(pwd)/$$d/bw_enc_sm121.om" OMEGA_UNITS_DEST=$$d OMEGA_OMC=$(abspath $(OMEGA_OMC)) \
77 OMEGA_BRIDGE=$(OMEGA_BRIDGE_DIR) sh om/units.sh > /dev/null || exit 1; \
78 $(OM_ENC_BUILD) -o $$d/codegen tests/test_omega_codegen_freestanding.c $(OM_ENC_SRCS) $$d/omega_om_units.c || exit 1; \
79 g=0; $$d/codegen --golden > $$d/golden.log 2>&1 || g=1; \
80 c=0; $$d/codegen --dump > $$d/dump.txt 2>&1; cmp -s $$d/dump.txt $(OM_ENC_DIR)/c-dump.txt || c=1; \
81 if [ $$g = 0 ] && [ $$c = 0 ]; then echo "MUTANT $$n SURVIVED: '$$m'"; exit 1; fi; \
82 echo "mutant $$n red ('$$m'): golden words $$( [ $$g = 1 ] && echo FAIL || echo pass ), dump vs C $$( [ $$c = 1 ] && echo DIFFERS || echo same )"; \
83 done
84
85# Guard predicate of every opcode this encoder emits, with nvdisasm as the oracle, plus a guard-7 mutant.
86# The script lives next to the encoder so this fragment does not name the oracle binary.
87test-om-encoder-guard:
88 sh om/encoder/guard-gate.sh