interplane.Get Omega
Read in your language

omega-helix

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

omega-helix / scripts / build.sh

447 lines · 13119 bytes Raw Blame History
1#!/bin/sh
2# Build Omega Helix (ollm) binaries from pure seeded Omega (.om) sources.
3#
4# Usage:
5# sh scripts/build.sh # default: TARGET=gb10 (Linux AArch64 + GB10 SM121 GPU)
6# TARGET=aarch64 sh scripts/build.sh # Linux AArch64 CPU + OpenAI HTTP server
7# TARGET=macos sh scripts/build.sh # Apple Silicon macOS Mach-O CPU binary
8# TARGET=macos-metal sh scripts/build.sh # Apple Silicon macOS Mach-O + Metal GPU binary
9# TARGET=x86linux sh scripts/build.sh # Linux x86-64 CPU binary
10# TARGET=x86efi sh scripts/build.sh # Bare-metal x86-64 UEFI application
11# TARGET=a64efi sh scripts/build.sh # Bare-metal AArch64 UEFI application
12# TARGET=tok sh scripts/build.sh # Standalone pure-Omega BPE tokenizer (ollm-tok)
13# TARGET=wtrain sh scripts/build.sh # Pure-Omega fine-tune & eval driver (wtrain)
14# TARGET=openwaldo sh scripts/build.sh # Pure-Omega OpenWALDO JSONL ingestor (ollm-waldo)
15# TARGET=univ sh scripts/build.sh # Pure-Omega Universal zero-cap LLM engine (ollm-univ)
16# TARGET=interchange sh scripts/build.sh # Pure-Omega Safetensors/HF/GGUF converter (ollm-interchange)
17# TARGET=aien-m16 sh scripts/build.sh # Pure-Omega /dev/aien-gpu M16 hardware gate (aien-m16-om)
18# TARGET=dna sh scripts/build.sh # Pure-Omega OLLMBF01 + OLLMSP02 DNA engine (ollm-dna)
19# TARGET=dna-gb10 sh scripts/build.sh # Pure-Omega GB10 SM121 OLLMBF01 + OLLMSP02 engine (ollm-dna-gb10)
20#
21# Env:
22# OMC Path to seeded omc compiler (auto-detected if unset)
23# OUT Output directory (default: ./build)
24set -eu
25
26here=$(cd "$(dirname "$0")/.." && pwd)
27TARGET=${TARGET:-gb10}
28OUT=${OUT:-$here/build}
29src=$here/native
30
31find_omc() {
32 if [ -n "${OMC:-}" ] && [ -x "$OMC" ]; then
33 printf '%s\n' "$OMC"
34 return 0
35 fi
36 for cand in \
37 "$(command -v omc 2>/dev/null || true)" \
38 "$HOME/.local/bin/omc" \
39 "$HOME/canon/omega-mv/seed/out/omc" \
40 "$here/../omega-mv/seed/out/omc" \
41 "$here/../omega-mv-macos/seed/out/omc"
42 do
43 if [ -n "$cand" ] && [ -x "$cand" ]; then
44 printf '%s\n' "$cand"
45 return 0
46 fi
47 done
48 echo "error: seeded 'omc' compiler not found." >&2
49 echo " Install omc from https://interplane.io/omega/ or set OMC=/path/to/omc" >&2
50 exit 1
51}
52
53OMC=$(find_omc)
54mkdir -p "$OUT"
55
56host_target_hdr() {
57 case "$(uname -s)/$(uname -m)" in
58 Darwin/arm64) printf 'target a64macos\n' ;;
59 Linux/x86_64|Linux/amd64) printf 'target x86linux\n' ;;
60 esac
61}
62
63is_omega_ng() {
64 cand=$1
65 [ -n "$cand" ] && [ -x "$cand" ] || return 1
66 hdr=$(printf '@ng front-ir\nfn main to int\nret 0\nend\n' | "$cand" 2>/dev/null | dd bs=1 count=6 2>/dev/null | tr -d '\0' || true)
67 [ "$hdr" = "OSC1IR" ]
68}
69
70build_ng_from_src() {
71 ng_src=$1
72 {
73 host_target_hdr
74 cat "$ng_src/ir.om" "$ng_src/front.om" "$ng_src/opt.om" "$ng_src/a64.om" "$ng_src/main.om"
75 } > "$OUT/ng.om"
76 "$OMC" < "$OUT/ng.om" > "$OUT/ng.tmp"
77 chmod +x "$OUT/ng.tmp"
78 mv -f "$OUT/ng.tmp" "$OUT/ng"
79 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
80 codesign -s - -f "$OUT/ng" >/dev/null 2>&1
81 fi
82 printf '%s\n' "$OUT/ng"
83}
84
85find_ng() {
86 if [ -n "${NG:-}" ]; then
87 if is_omega_ng "$NG"; then
88 printf '%s\n' "$NG"
89 return 0
90 fi
91 echo "error: NG='$NG' is not an executable Omega ng compiler." >&2
92 exit 1
93 fi
94 if is_omega_ng "$OUT/ng"; then
95 printf '%s\n' "$OUT/ng"
96 return 0
97 fi
98 if [ -n "${OMEGA_MV:-}" ]; then
99 if [ -f "$OMEGA_MV/seed/ng/src/ir.om" ] && [ -f "$OMEGA_MV/seed/ng/src/a64.om" ]; then
100 build_ng_from_src "$OMEGA_MV/seed/ng/src"
101 return 0
102 fi
103 echo "error: OMEGA_MV='$OMEGA_MV' missing seed/ng/src." >&2
104 exit 1
105 fi
106 for cand in \
107 "$HOME/.local/bin/ng" \
108 "$(command -v ng 2>/dev/null || true)"
109 do
110 if is_omega_ng "$cand"; then
111 printf '%s\n' "$cand"
112 return 0
113 fi
114 done
115 for root in \
116 "$HOME/workspace/omega-mv-macos" \
117 "$HOME/canon/omega-mv" \
118 "$here/../omega-mv" \
119 "$here/../omega-mv-macos"
120 do
121 if [ -f "$root/seed/ng/src/ir.om" ] && [ -f "$root/seed/ng/src/a64.om" ]; then
122 build_ng_from_src "$root/seed/ng/src"
123 return 0
124 fi
125 done
126 echo "error: 'ng' compiler or omega-mv seed/ng/src not found (set NG=/path/to/ng or OMEGA_MV=/path/to/omega-mv)." >&2
127 exit 1
128}
129
130if [ "$TARGET" = macos-metal ]; then
131 NG=$(find_ng)
132 om_file="$OUT/ollm-metal.om"
133 {
134 printf 'target macos\nom2\n'
135 cat \
136 "$src/math.om" \
137 "$src/data.om" \
138 "$src/gpu/mpool.om" \
139 "$src/model.om" \
140 "$src/adam.om" \
141 "$src/ckpt.om" \
142 "$src/bpe.om" \
143 "$src/spec.om" \
144 "$src/norev.om" \
145 "$src/cli.om" \
146 "$src/noserve.om" \
147 "$src/gpu/metal_io.om" \
148 "$src/gpu/metal_msl.om" \
149 "$src/gpu/metal_macos.om"
150 } > "$om_file"
151 { printf '@ng front-ir\n'; cat "$om_file"; } | "$NG" > "$OUT/ollm-metal.ir"
152 { printf '@ng opt\n'; cat "$OUT/ollm-metal.ir"; } | "$NG" > "$OUT/ollm-metal.opt.ir"
153 { printf '@ng a64 macho\n'; cat "$OUT/ollm-metal.opt.ir"; } | "$NG" > "$OUT/ollm-metal.tmp"
154 chmod +x "$OUT/ollm-metal.tmp"
155 mv -f "$OUT/ollm-metal.tmp" "$OUT/ollm-metal"
156 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
157 codesign -s - -f "$OUT/ollm-metal" >/dev/null 2>&1
158 fi
159 printf 'built %s (%s bytes, target=%s, ng=%s)\n' \
160 "$OUT/ollm-metal" "$(wc -c < "$OUT/ollm-metal" | tr -d ' ')" "$TARGET" "$NG"
161 exit 0
162fi
163
164if [ "$TARGET" = tok ]; then
165 {
166 host_target_hdr
167 cat "$src/tok/tkcore.om" "$src/tok/tkfit.om" "$src/tok/tkio.om" "$src/tok/tkcli.om"
168 } > "$OUT/ollm-tok.om"
169 "$OMC" < "$OUT/ollm-tok.om" > "$OUT/ollm-tok.tmp"
170 chmod +x "$OUT/ollm-tok.tmp"
171 mv -f "$OUT/ollm-tok.tmp" "$OUT/ollm-tok"
172 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
173 codesign -s - -f "$OUT/ollm-tok" >/dev/null 2>&1
174 fi
175 printf 'built %s (%s bytes)\n' "$OUT/ollm-tok" "$(wc -c < "$OUT/ollm-tok" | tr -d ' ')"
176 exit 0
177fi
178
179if [ "$TARGET" = wtrain ]; then
180 drv=$here/tools/wdrive
181 { sed 's/^fn main to int$/fn wbmain to int/' "$drv/wbuild.om"; cat "$drv/wtrain.om"; } > "$OUT/wtrain.om"
182 "$OMC" < "$OUT/wtrain.om" > "$OUT/wtrain.tmp"
183 chmod +x "$OUT/wtrain.tmp"
184 mv -f "$OUT/wtrain.tmp" "$OUT/wtrain"
185 printf 'built %s (%s bytes)\n' "$OUT/wtrain" "$(wc -c < "$OUT/wtrain" | tr -d ' ')"
186 exit 0
187fi
188
189if [ "$TARGET" = openwaldo ]; then
190 {
191 host_target_hdr
192 printf 'om2\n'
193 cat "$src/net/json.om" "$here/tools/openwaldo/waldo_ingest.om"
194 } > "$OUT/ollm-waldo.om"
195 "$OMC" < "$OUT/ollm-waldo.om" > "$OUT/ollm-waldo.tmp"
196 chmod +x "$OUT/ollm-waldo.tmp"
197 mv -f "$OUT/ollm-waldo.tmp" "$OUT/ollm-waldo"
198 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
199 codesign -s - -f "$OUT/ollm-waldo" >/dev/null 2>&1
200 fi
201 printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
202 "$OUT/ollm-waldo" "$(wc -c < "$OUT/ollm-waldo" | tr -d ' ')" "$TARGET" "$OMC"
203 exit 0
204fi
205
206if [ "$TARGET" = univ ]; then
207 u=$src/univ
208 {
209 host_target_hdr
210 printf 'om2\n'
211 cat "$u/umath.om" "$u/uarena.om" "$u/uadam.om" "$u/uckpt.om" "$u/umodel.om" "$u/udistill.om" "$u/ugrammar.om" "$u/ucli.om"
212 } > "$OUT/ollm-univ.om"
213 "$OMC" < "$OUT/ollm-univ.om" > "$OUT/ollm-univ.tmp"
214 chmod +x "$OUT/ollm-univ.tmp"
215 mv -f "$OUT/ollm-univ.tmp" "$OUT/ollm-univ"
216 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
217 codesign -s - -f "$OUT/ollm-univ" >/dev/null 2>&1
218 fi
219 printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
220 "$OUT/ollm-univ" "$(wc -c < "$OUT/ollm-univ" | tr -d ' ')" "$TARGET" "$OMC"
221 exit 0
222fi
223
224if [ "$TARGET" = interchange ]; then
225 u=$src/univ
226 {
227 host_target_hdr
228 printf 'om2\n'
229 cat "$src/net/json.om" "$src/net/jsonw.om" "$u/umath.om" "$u/uarena.om" "$u/uckpt.om" "$u/interchange.om"
230 } > "$OUT/ollm-interchange.om"
231 "$OMC" < "$OUT/ollm-interchange.om" > "$OUT/ollm-interchange.tmp"
232 chmod +x "$OUT/ollm-interchange.tmp"
233 mv -f "$OUT/ollm-interchange.tmp" "$OUT/ollm-interchange"
234 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
235 codesign -s - -f "$OUT/ollm-interchange" >/dev/null 2>&1
236 fi
237 printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
238 "$OUT/ollm-interchange" "$(wc -c < "$OUT/ollm-interchange" | tr -d ' ')" "$TARGET" "$OMC"
239 exit 0
240fi
241
242if [ "$TARGET" = aien-m16 ]; then
243 "$OMC" < "$src/gpu/aien_m16.om" > "$OUT/aien-m16-om.tmp"
244 chmod +x "$OUT/aien-m16-om.tmp"
245 mv -f "$OUT/aien-m16-om.tmp" "$OUT/aien-m16-om"
246 printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
247 "$OUT/aien-m16-om" "$(wc -c < "$OUT/aien-m16-om" | tr -d ' ')" "$TARGET" "$OMC"
248 exit 0
249fi
250
251if [ "$TARGET" = dna ]; then
252 u=$src/univ
253 {
254 host_target_hdr
255 printf 'om2\n'
256 cat "$u/umath.om" "$u/spdna.om" "$u/spdna_nogpu.om"
257 } > "$OUT/ollm-dna.om"
258 "$OMC" < "$OUT/ollm-dna.om" > "$OUT/ollm-dna.tmp"
259 chmod +x "$OUT/ollm-dna.tmp"
260 mv -f "$OUT/ollm-dna.tmp" "$OUT/ollm-dna"
261 if [ "$(uname -s)" = Darwin ] && command -v codesign >/dev/null 2>&1; then
262 codesign -s - -f "$OUT/ollm-dna" >/dev/null 2>&1
263 fi
264 printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
265 "$OUT/ollm-dna" "$(wc -c < "$OUT/ollm-dna" | tr -d ' ')" "$TARGET" "$OMC"
266 exit 0
267fi
268
269if [ "$TARGET" = dna-gb10 ]; then
270 u=$src/univ
271 g=$src/gpu
272 {
273 printf 'om2\n'
274 cat "$u/umath.om" "$u/spdna.om" "$g/context.om" "$g/vector.om" "$g/launch.om" "$g/batch.om" "$g/gk.om" "$g/gr.om" "$g/bf_kernels.om" "$g/bf_dna.om"
275 } > "$OUT/ollm-dna-gb10.om"
276 "$OMC" < "$OUT/ollm-dna-gb10.om" > "$OUT/ollm-dna-gb10.tmp"
277 chmod +x "$OUT/ollm-dna-gb10.tmp"
278 mv -f "$OUT/ollm-dna-gb10.tmp" "$OUT/ollm-dna-gb10"
279 printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
280 "$OUT/ollm-dna-gb10" "$(wc -c < "$OUT/ollm-dna-gb10" | tr -d ' ')" "$TARGET" "$OMC"
281 exit 0
282fi
283
284lead=
285pre=
286pool=lpool.om
287plat=lio.om
288rev_mod=rev.om
289post=$src/noserve.om
290bin=ollm
291
292case "$TARGET" in
293 aarch64)
294 lead=om2
295 pre="$src/net/http.om $src/net/json.om $src/net/jsonw.om"
296 post=$src/serve.om
297 bin=ollm
298 ;;
299 gb10)
300 lead=om2
301 pre="$src/net/http.om $src/net/json.om $src/net/jsonw.om"
302 post=$src/serve.om
303 bin=ollm-gb10
304 ;;
305 macos)
306 lead='target a64macos
307om2'
308 plat=mio.om
309 post=$src/noserve.om
310 bin=ollm-macos
311 ;;
312 x86linux)
313 lead='target x86linux
314om2'
315 pool=xpool.om
316 plat=lio.om
317 rev_mod=norev.om
318 post=$src/noserve.om
319 bin=ollm-x86linux
320 ;;
321 x86efi)
322 lead='target x86efi'
323 pool=epool.om
324 plat=eio.om
325 rev_mod=norev.om
326 post=$src/noserve.om
327 bin=ollm.efi
328 ;;
329 a64efi)
330 lead='target a64efi'
331 pool=epool.om
332 plat=eio.om
333 rev_mod=norev.om
334 post=$src/noserve.om
335 bin=ollm-aa64.efi
336 EFIRT=${EFIRT:-$(dirname "$OMC")/../a64efi/efirt.om}
337 if [ ! -f "$EFIRT" ]; then
338 echo "error: a64efi requires efirt.om (set EFIRT=/path/to/efirt.om)" >&2
339 exit 1
340 fi
341 ;;
342 *)
343 echo "error: unknown TARGET '$TARGET' (expected: gb10, aarch64, macos, macos-metal, x86linux, x86efi, a64efi, tok, wtrain, openwaldo, univ, interchange, aien-m16, dna, dna-gb10)" >&2
344 exit 2
345 ;;
346esac
347
348om_file="$OUT/$bin.om"
349{
350 [ -z "$lead" ] || printf '%s\n' "$lead"
351 [ "$TARGET" != a64efi ] || cat "$EFIRT"
352 # shellcheck disable=SC2086
353 [ -z "$pre" ] || cat $pre
354 cat \
355 "$src/math.om" \
356 "$src/data.om" \
357 "$src/$pool" \
358 "$src/model.om" \
359 "$src/adam.om" \
360 "$src/ckpt.om" \
361 "$src/bpe.om" \
362 "$src/spec.om"
363 if [ "$TARGET" != x86efi ] && [ "$TARGET" != a64efi ]; then
364 cat \
365 "$src/$rev_mod" \
366 "$src/arboris.om" \
367 "$src/sp_solve.om" \
368 "$src/spiral.om" \
369 "$src/apu_weave.om" \
370 "$src/omg.om" \
371 "$src/pillars_cli.om"
372 else
373 cat "$src/$rev_mod"
374 cat <<'EOF'
375fn cmdspforge to void
376exit 2
377end
378fn cmdspcryst to void
379exit 2
380end
381fn cmdspweval to void
382exit 2
383end
384fn cmdspwsamp to void
385exit 2
386end
387fn cmdapuweave to void
388exit 2
389end
390fn sp2_is_sp2 ai ulong to bool
391ret false
392end
393fn cmdomg to void
394exit 2
395end
396fn cmdomg_cli to void
397exit 2
398end
399fn cmdarboris to void
400exit 2
401end
402fn cmdarboris_cli to void
403exit 2
404end
405EOF
406 fi
407 cat \
408 "$src/cli.om" \
409 "$src/$plat" \
410 "$post"
411 [ "$TARGET" = gb10 ] || cat "$src/nogpu.om"
412 if [ "$TARGET" = macos ]; then
413 cat "$src/apu_fabric_macos.om"
414 elif [ "$TARGET" = aarch64 ] || [ "$TARGET" = x86linux ]; then
415 cat "$src/apu_fabric_linux.om" "$src/apu_fabric_nogpu.om"
416 fi
417} > "$om_file"
418
419if [ "$TARGET" = gb10 ]; then
420 g=$src/gpu
421 cat \
422 "$g/context.om" \
423 "$g/vector.om" \
424 "$g/launch.om" \
425 "$g/batch.om" \
426 "$g/gk.om" \
427 "$g/gr.om" \
428 "$g/gb.om" \
429 "$g/gg.om" \
430 "$g/gt.om" \
431 "$g/gm.om" \
432 "$g/ring.om" \
433 "$g/ejit.om" \
434 "$src/apu_fabric_linux.om" \
435 "$src/apu_fabric_gb10.om" >> "$om_file"
436fi
437
438"$OMC" < "$om_file" > "$OUT/$bin.tmp"
439chmod +x "$OUT/$bin.tmp"
440mv -f "$OUT/$bin.tmp" "$OUT/$bin"
441
442if [ "$TARGET" = macos ] && command -v codesign >/dev/null 2>&1; then
443 codesign -s - -f "$OUT/$bin" >/dev/null 2>&1
444fi
445
446printf 'built %s (%s bytes, target=%s, omc=%s)\n' \
447 "$OUT/$bin" "$(wc -c < "$OUT/$bin" | tr -d ' ')" "$TARGET" "$OMC"