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
omega-mv / seed / helix / helix-build-jit.sh
| 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 |
| 11 | set -eu |
| 12 | OMC_A=${1:?usage: helix-build-jit.sh OMC_A OMC_B OUT_DIR} |
| 13 | OMC_B=${2:?usage: helix-build-jit.sh OMC_A OMC_B OUT_DIR} |
| 14 | OUT=${3:?usage: helix-build-jit.sh OMC_A OMC_B OUT_DIR} |
| 15 | mkdir -p "$OUT" |
| 16 | |
| 17 | sha() { 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` |
| 23 | sed '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) |
| 26 | awk ' |
| 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 | |
| 31 | awk ' |
| 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" |
| 53 | cmp -s "$OUT/q36-helix-native.A" "$OUT/q36-helix-native.B" || { echo "FAIL: q36-helix-native diverged across strands" >&2; exit 1; } |
| 54 | mv "$OUT/q36-helix-native.A" "$OUT/q36-helix-native" |
| 55 | rm -f "$OUT/q36-helix-native.B" |
| 56 | chmod +x "$OUT/q36-helix-native" |
| 57 | |
| 58 | # Real-weight 35B decode runner hook: evolve q36Buf AND qhBuf when hxActive == 1 |
| 59 | awk ' |
| 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 | |
| 64 | awk ' |
| 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 | |
| 69 | cat > "$OUT/helix_jit_head_ext.om" <<'EOF' |
| 70 | fn hxEvolveQhBuf cnt ulong to void |
| 71 | if eq get hxActive 0 0 |
| 72 | ret |
| 73 | end |
| 74 | hxEnsureInit |
| 75 | if eq get hxGenome 0 0 |
| 76 | ret |
| 77 | end |
| 78 | if or eq cnt 0 gt cnt 2048 |
| 79 | put hxStats 3 add get hxStats 3 1 |
| 80 | ret |
| 81 | end |
| 82 | put hxStats 0 add get hxStats 0 1 |
| 83 | for i ulong mul cnt 4 bound 8192 |
| 84 | v = get qhBuf i |
| 85 | put hxRef i v |
| 86 | put hxCand i v |
| 87 | end |
| 88 | if hxRunCore cnt |
| 89 | for i ulong mul cnt 4 bound 8192 |
| 90 | put qhBuf i get hxCand i |
| 91 | end |
| 92 | end |
| 93 | end |
| 94 | EOF |
| 95 | |
| 96 | awk ' |
| 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 | |
| 102 | awk '/^fn main / { exit } { print }' "$OUT/decode_run_hx.om" > "$OUT/decode_run_hx_pre.om" |
| 103 | awk '/^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" |
| 126 | cmp -s "$OUT/q36-helix-decode.A" "$OUT/q36-helix-decode.B" || { echo "FAIL: q36-helix-decode diverged across strands" >&2; exit 1; } |
| 127 | mv "$OUT/q36-helix-decode.A" "$OUT/q36-helix-decode" |
| 128 | rm -f "$OUT/q36-helix-decode.B" |
| 129 | chmod +x "$OUT/q36-helix-decode" |
| 130 | |
| 131 | printf 'PASS q36-helix-native dual-strand identical (%s, %s bytes)\n' "$(sha "$OUT/q36-helix-native")" "$(wc -c < "$OUT/q36-helix-native")" |
| 132 | printf 'PASS q36-helix-decode dual-strand identical (%s, %s bytes)\n' "$(sha "$OUT/q36-helix-decode")" "$(wc -c < "$OUT/q36-helix-decode")" |