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 / seed / helix / helix-build-jit.sh

132 lines · 4872 bytes Raw Blame History
1#!/bin/sh
2# seed/helix/helix-build-jit.sh -- Build dual-strand zero-CUDA Proof-Carrying SM121 JIT binaries
3# (`q36-helix-native` and `q36-helix-decode`) without modifying any file in `om/gpu/q36/`.
4#
5# Composes `seed/helix/helix_jit.om` directly into `q36Done` (and `qhDone` for decode),
6# verifies bit-for-bit equality between Strand A (`omc_A`) and Strand B (`omc_B_fast`),
7# and confirms static zero-CUDA ELFs (`ldd: not a dynamic executable`).
8#
9# Usage:
10# sh seed/helix/helix-build-jit.sh OMC_A OMC_B OUT_DIR
11set -eu
12OMC_A=${1:?usage: helix-build-jit.sh OMC_A OMC_B OUT_DIR}
13OMC_B=${2:?usage: helix-build-jit.sh OMC_A OMC_B OUT_DIR}
14OUT=${3:?usage: helix-build-jit.sh OMC_A OMC_B OUT_DIR}
15mkdir -p "$OUT"
16
17sha() { sha256sum "$1" | cut -d' ' -f1; }
18
19# Prepare clean composed inputs:
20# - rename local `rb` in bw_hazard.om -> `hzrb` to avoid colliding with `fn rb` in bw_enc_sm121.om
21# - inject `hxEvolveQ36Buf cnt` inside `q36Done` right before upload to VRAM (only on pass 2 when qCodeMap/qdCodeMap > 0!)
22# - inject `hxPrintSummary` right after pass-2 `qEmitAll` / `qdEmitAll`
23sed 's/\brb\b/hzrb/g' gpu/nvidia/om/codegen/bw_hazard.om > "$OUT/bw_hazard_clean.om"
24
25# Native runner hook: evolve q36Buf when hxActive == 1 (actual VRAM upload pass)
26awk '
27/^cnt = get q36Pc 0$/ { print; print "hxEvolveQ36Buf cnt"; next }
28{ print }
29' om/gpu/q36/emit_fast.om > "$OUT/emit_fast_nat.om"
30
31awk '
32/^put qCodeMap 0 cm$/ { print; print "put hxActive 0 1"; next }
33/^if ne get qCodeFail 0 0$/ { print "hxPrintSummary"; print; next }
34{ print }
35' om/gpu/q36/native_run.om > "$OUT/native_run_hx.om"
36
37{
38 printf 'om2\n'
39 cat gpu/nvidia/native/nvrm/context.om \
40 gpu/nvidia/native/blackwell/vector.om \
41 gpu/nvidia/native/blackwell/launch.om \
42 gpu/nvidia/native/blackwell/batch.om \
43 om/encoder/bw_enc_sm121.om \
44 "$OUT/bw_hazard_clean.om" \
45 "$OUT/emit_fast_nat.om" \
46 seed/helix/helix_jit.om \
47 om/gpu/q36/arboris/prefetch.om \
48 "$OUT/native_run_hx.om"
49} > "$OUT/q36_helix_native.om"
50
51"$OMC_A" < "$OUT/q36_helix_native.om" > "$OUT/q36-helix-native.A"
52"$OMC_B" < "$OUT/q36_helix_native.om" > "$OUT/q36-helix-native.B"
53cmp -s "$OUT/q36-helix-native.A" "$OUT/q36-helix-native.B" || { echo "FAIL: q36-helix-native diverged across strands" >&2; exit 1; }
54mv "$OUT/q36-helix-native.A" "$OUT/q36-helix-native"
55rm -f "$OUT/q36-helix-native.B"
56chmod +x "$OUT/q36-helix-native"
57
58# Real-weight 35B decode runner hook: evolve q36Buf AND qhBuf when hxActive == 1
59awk '
60/^cnt = get q36Pc 0$/ { print; print "hxEvolveQ36Buf cnt"; next }
61{ print }
62' om/gpu/q36/emit_fast.om > "$OUT/emit_fast_dec.om"
63
64awk '
65/^cnt = get qhPc 0$/ { print; print "hxEvolveQhBuf cnt"; next }
66{ print }
67' om/gpu/q36/head/emit_head.om > "$OUT/emit_head_dec.om"
68
69cat > "$OUT/helix_jit_head_ext.om" <<'EOF'
70fn hxEvolveQhBuf cnt ulong to void
71if eq get hxActive 0 0
72ret
73end
74hxEnsureInit
75if eq get hxGenome 0 0
76ret
77end
78if or eq cnt 0 gt cnt 2048
79put hxStats 3 add get hxStats 3 1
80ret
81end
82put hxStats 0 add get hxStats 0 1
83for i ulong mul cnt 4 bound 8192
84v = get qhBuf i
85put hxRef i v
86put hxCand i v
87end
88if hxRunCore cnt
89for i ulong mul cnt 4 bound 8192
90put qhBuf i get hxCand i
91end
92end
93end
94EOF
95
96awk '
97/^put qdCodeMap 0 cm$/ { print; print "put hxActive 0 1"; next }
98/^if ne get qdCodeFail 0 0$/ { print "hxPrintSummary"; print; next }
99{ print }
100' om/gpu/q36/decode/decode_run.om > "$OUT/decode_run_hx.om"
101
102awk '/^fn main / { exit } { print }' "$OUT/decode_run_hx.om" > "$OUT/decode_run_hx_pre.om"
103awk '/^fn main / { p=1 } p { print }' "$OUT/decode_run_hx.om" > "$OUT/decode_run_hx_main.om"
104
105{
106 printf 'om2\n'
107 cat gpu/nvidia/native/nvrm/context.om \
108 gpu/nvidia/native/blackwell/vector.om \
109 gpu/nvidia/native/blackwell/launch.om \
110 gpu/nvidia/native/blackwell/batch.om \
111 om/encoder/bw_enc_sm121.om \
112 "$OUT/bw_hazard_clean.om" \
113 "$OUT/emit_fast_dec.om" \
114 om/gpu/q36/emit_prefill.om \
115 "$OUT/emit_head_dec.om" \
116 seed/helix/helix_jit.om \
117 "$OUT/helix_jit_head_ext.om" \
118 om/gpu/q36/arboris/prefetch.om \
119 "$OUT/decode_run_hx_pre.om" \
120 om/gpu/q36/decode/prefill_host.om \
121 "$OUT/decode_run_hx_main.om"
122} > "$OUT/q36_helix_decode.om"
123
124"$OMC_A" < "$OUT/q36_helix_decode.om" > "$OUT/q36-helix-decode.A"
125"$OMC_B" < "$OUT/q36_helix_decode.om" > "$OUT/q36-helix-decode.B"
126cmp -s "$OUT/q36-helix-decode.A" "$OUT/q36-helix-decode.B" || { echo "FAIL: q36-helix-decode diverged across strands" >&2; exit 1; }
127mv "$OUT/q36-helix-decode.A" "$OUT/q36-helix-decode"
128rm -f "$OUT/q36-helix-decode.B"
129chmod +x "$OUT/q36-helix-decode"
130
131printf 'PASS q36-helix-native dual-strand identical (%s, %s bytes)\n' "$(sha "$OUT/q36-helix-native")" "$(wc -c < "$OUT/q36-helix-native")"
132printf 'PASS q36-helix-decode dual-strand identical (%s, %s bytes)\n' "$(sha "$OUT/q36-helix-decode")" "$(wc -c < "$OUT/q36-helix-decode")"