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 / train / omega-llm / tools / wpatch / wpbuild.om

800 lines · 15248 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note wpbuild: the Omega build driver for ollm, wpatch and its test driver wpcheck. CPU only.
3note Usage: wpbuild REPO OUT OMC OMEGA_MV CORE (all five required; CORE is a taskset core number).
4note Steps, in order (any failure prints one WPBUILD FAIL line and exits nonzero):
5note 1. Compiler pin: the sha256 of OMC (read from sha256sum) must equal OMCPIN.
6note 2. SHA-256: git show of om/sha256/sha256-om2.om at omega-mv pin e5b32567 into OUT/sha256-source.om;
7note its sha256 (read from sha256sum) must equal SHASRC.
8note 3. Vendoring, done here in Omega: the layout block (from the line `layout shactx 104` through the
9note next line `end`) goes to OUT/sha256-layout.om. Every other line except `om2` goes to
10note OUT/sha256-functions.om, with a leading `export fn ` made `fn `, and on lines that do not start
11note with `note` each whole word ([A-Za-z0-9_] run) in OLDW renamed to the word at the same position
12note in NEWW. OUT/sha256-vendored.om is `om2`, layout, functions; OUT/sha256.diff is diff -u of the
13note source against it (a review record, not an input).
14note 4. wpcheck: OUT/wpcheck-all.om is `om2`, layout, functions, wpcheck.om; compiled to OUT/wpcheck.
15note 5. Net pins: `OUT/wpcheck sum` (the vendored Omega SHA-256) of native/omegallm/net/http.om,
16note json.om and jsonw.om must equal NPHTTP, NPJSON and NPJSONW (the pins of the aarch64 ollm build).
17note 6. ollm: OUT/ollm.om is the line `om2`, then native/omegallm/ net/http.om net/json.om
18note net/jsonw.om math.om data.om lpool.om model.om adam.om ckpt.om bpe.om cli.om lio.om serve.om
19note nogpu.om, plain concatenation in that order (the aarch64 ollm source); compiled to OUT/ollm.
20note 7. wpatch: OUT/wpatch-all.om is `om2`, layout, OUT/ollm.om without its `om2` line and with
21note `fn main to int` (exactly one such line) renamed `fn wpollm to int`, functions, wpatch.om;
22note compiled to OUT/wpatch.
23note Each compile runs taskset -c CORE nice -n 19 OMC into a .new file, which is made executable and
24note renamed over the target. A compile error removes the .new file and exits with omc's status.
25note Finally sha256sum prints OMC, the SHA source, ollm.om, ollm, both compositions and both binaries.
26note Exit codes: 2 usage, 3 a pinned digest differs (compiler, SHA source or net source), 4 main
27note count, 5 I/O or capacity, 6 a tool failed (its status is printed), otherwise omc's own status.
28om2
29
30global sb uchar 65536
31global sl ulong 128
32global pb uchar 4096
33global pn ulong 1
34global av uchar 4096
35global ap ulong 2
36global stb uchar 4
37global inb uchar 8388608
38global bn ulong 1
39global ob uchar 8388608
40global obn ulong 1
41global lay uchar 4096
42global lan ulong 1
43global fns uchar 65536
44global fnn ulong 1
45global cap uchar 4096
46global capn ulong 1
47global dig uchar 32
48text PIN "e5b32567a7aff3ce594e3254a622a846a6cd190b:om/sha256/sha256-om2.om"
49text SHASRC "dbf002dd6aa36585632b9d01d98ac3f0bd2fa0f0475082940de53638847994bb"
50text OMCPIN "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f"
51text NPHTTP "aff258ecd3858454056811a5e6fe1f660f9d650a7207d6c41885105110e046a7"
52text NPJSON "456254fc754ea35103ced480407b24fc1a3896d094b90ae0e9623e7b6594e2d2"
53text NPJSONW "464f649e8207495f5d67fe8795d31e42ea3ccebd9ed547274dab802d4f7c5f21"
54text SHTTP "/train/omega-llm/native/net/http.om"
55text SJSON "/train/omega-llm/native/net/json.om"
56text SJSONW "/train/omega-llm/native/net/jsonw.om"
57text SMATH "/train/omega-llm/native/math.om"
58text SDATA "/train/omega-llm/native/data.om"
59text SLPOOL "/train/omega-llm/native/lpool.om"
60text SMODEL "/train/omega-llm/native/model.om"
61text SADAM "/train/omega-llm/native/adam.om"
62text SCKPT "/train/omega-llm/native/ckpt.om"
63text SBPE "/train/omega-llm/native/bpe.om"
64text SSPEC "/train/omega-llm/native/spec.om"
65text SCLI "/train/omega-llm/native/cli.om"
66text SLIO "/train/omega-llm/native/lio.om"
67text SSERVE "/train/omega-llm/native/serve.om"
68text SNOGPU "/train/omega-llm/native/nogpu.om"
69text CSUM "sum"
70text OLDW "kinit iv sched rounds compress run blocks finish tobuf absorb "
71text NEWW "wskinit wsiv wssched wsround wscomp wsrun wsblks wsfin wstobuf wsabsb "
72text GIT "/usr/bin/git"
73text GC "-C"
74text GSHOW "show"
75text SUM "/usr/bin/sha256sum"
76text DIFF "/usr/bin/diff"
77text DU "-u"
78text TSET "/usr/bin/taskset"
79text TC "-c"
80text NICE "/usr/bin/nice"
81text NN "-n"
82text N19 "19"
83text OM2 "om2"
84text LSTART "layout shactx 104"
85text LEND "end"
86text EXPFN "export fn "
87text NOTE "note"
88text MAINL "fn main to int"
89text WPOLLM "fn wpollm to int\n"
90text OM2NL "om2\n"
91text FSRC "/sha256-source.om"
92text FLAY "/sha256-layout.om"
93text FFNS "/sha256-functions.om"
94text FVEN "/sha256-vendored.om"
95text FDIF "/sha256.diff"
96text FOLLM "/ollm.om"
97text FONEW "/ollm.new"
98text FOL "/ollm"
99text FWPS "/train/omega-llm/tools/wpatch/wpatch.om"
100text FCKS "/train/omega-llm/tools/wpatch/wpcheck.om"
101text FWALL "/wpatch-all.om"
102text FCALL "/wpcheck-all.om"
103text FWNEW "/wpatch.new"
104text FCNEW "/wpcheck.new"
105text FWP "/wpatch"
106text FCK "/wpcheck"
107text MUSAGE "WPBUILD FAIL usage: wpbuild REPO OUT OMC OMEGA_MV CORE\n"
108text MIO "WPBUILD FAIL I/O or capacity: "
109text MTOOL "WPBUILD FAIL tool exit "
110text MSHA "WPBUILD FAIL SHA-256 source digest differs from the pin\n"
111text MOMCP "WPBUILD FAIL omc digest differs from the pin\n"
112text MNET "WPBUILD FAIL net source digest differs from the pin: "
113text MMAIN "WPBUILD FAIL ollm.om must hold exactly one line `fn main to int`, found "
114text MOMC "WPBUILD FAIL omc exit "
115text MOK "WPBUILD PASS\n"
116text NL "\n"
117
118note ---- output, slots and argument packets --------------------------------------------------
119fn say s view uchar * to void
120r = write 1 s 0 len s
121end
122fn saynum v ulong to void
123x = v
124n = ulong 0
125while ge x 10
126put dig n uchar add 48 rem x 10
127x = div x 10
128n = add n 1
129end
130put dig n uchar add 48 x
131for i ulong add n 1
132r = write 1 dig sub n i 1
133end
134end
135fn saypb to void
136r = write 1 pb 0 get pn 0
137end
138fn die c ulong m view uchar * to void
139say m
140exit int c
141end
142fn dieio to void
143say MIO
144saypb
145say NL
146exit 5
147end
148fn pclear to void
149put pn 0 0
150end
151fn pbyte b uchar to void
152n = get pn 0
153if ge n 4095
154dieio
155end
156put pb n b
157put pn 0 add n 1
158end
159fn ptext s view uchar * to void
160for i ulong len s
161pbyte get s i
162end
163end
164note Slot k is 512 bytes of sb at k * 512, its length in sl.
165fn pslot k ulong to void
166o = mul k 512
167for i ulong get sl k
168pbyte get sb add o i
169end
170end
171fn keepat k ulong to void
172n = get pn 0
173if gt n 512
174dieio
175end
176o = mul k 512
177for i ulong n
178put sb add o i get pb i
179end
180put sl k n
181end
182fn argslot i ulong k ulong to void
183r = argread i pb 0 512
184if le r 0
185die 2 MUSAGE
186end
187put pn 0 ulong r
188keepat k
189end
190note slot k = slot base followed by text s
191fn under k ulong base ulong s view uchar * to void
192pclear
193pslot base
194ptext s
195keepat k
196end
197fn aclear to void
198put ap 0 2
199put ap 1 0
200end
201fn apb to void
202p = get ap 0
203n = get pn 0
204if or gt add add p n 2 len av ge get ap 1 64
205dieio
206end
207put av p uchar and n 255
208put av add p 1 uchar shr n 8
209for i ulong n
210put av add add p 2 i get pb i
211end
212put ap 0 add add p 2 n
213put ap 1 add get ap 1 1
214end
215fn atext s view uchar * to void
216pclear
217ptext s
218apb
219end
220fn aslot k ulong to void
221pclear
222pslot k
223apb
224end
225fn popen k ulong fl int to int
226pclear
227pslot k
228r = fopen pb 0 get pn 0 fl 420
229if lt r 0
230dieio
231end
232ret int r
233end
234fn redir s int d int to void
235if ne s d
236if ne dupfd s d 0 long d
237exit 127
238end
239end
240end
241note Run the packet in av with stdin fi and stdout fo (-1 inherits); return the exit status, or
242note 256 + the signal number when the child was killed.
243fn spawn fi int fo int to ulong
244put av 0 uchar and get ap 1 255
245put av 1 uchar shr get ap 1 8
246pid = fork
247if lt pid 0
248dieio
249end
250if eq pid 0
251if ge fi 0
252redir fi 0
253end
254if ge fo 0
255redir fo 1
256end
257r = execprog av 0 get ap 0
258exit 127
259end
260if ge fi 0
261r = fclose fi
262end
263if ge fo 0
264r = fclose fo
265end
266w = waitpid int pid stb 0 4 0
267if ne w long pid
268dieio
269end
270if ne get stb 0 0
271ret add 256 ulong and get stb 0 127
272end
273ret ulong get stb 1
274end
275fn tool fi int fo int to void
276x = spawn fi fo
277if ne x 0
278say MTOOL
279saynum x
280say NL
281exit 6
282end
283end
284fn waitok pid long to void
285w = waitpid int pid stb 0 4 0
286bad = or ne get stb 0 0 ne get stb 1 0
287if or ne w pid bad
288say MTOOL
289saynum ulong get stb 1
290say NL
291exit 6
292end
293end
294note Run the packet with stdout read back through a pipe into cap (at most 4096 bytes).
295fn capture to void
296put av 0 uchar and get ap 1 255
297put av 1 uchar shr get ap 1 8
298pf = new uchar 8 0
299if ne pipefds pf 0 8 0 0
300dieio
301end
302rd = int or ulong get pf 0 shl ulong get pf 1 8
303wr = int or ulong get pf 4 shl ulong get pf 5 8
304pid = fork
305if lt pid 0
306dieio
307end
308if eq pid 0
309r = fclose rd
310redir wr 1
311r = execprog av 0 get ap 0
312exit 127
313end
314r = fclose wr
315n = ulong 0
316k = long 1
317while gt k 0
318k = read rd cap n sub len cap n
319if gt k 0
320n = add n ulong k
321end
322end
323r = fclose rd
324put capn 0 n
325waitok pid
326end
327
328note ---- whole files ---------------------------------------------------------------------------
329fn slurp k ulong to void
330fd = popen k 0
331n = ulong 0
332k2 = long 1
333while gt k2 0
334if eq n len inb
335dieio
336end
337k2 = read fd inb n sub len inb n
338if lt k2 0
339dieio
340end
341n = add n ulong k2
342end
343r = fclose fd
344put bn 0 n
345end
346fn obyte b uchar to void
347n = get obn 0
348if ge n len ob
349dieio
350end
351put ob n b
352put obn 0 add n 1
353end
354fn otext s view uchar * to void
355for i ulong len s
356obyte get s i
357end
358end
359fn obig o ulong n ulong to void
360for i ulong n
361obyte get inb add o i
362end
363end
364fn olay to void
365for i ulong get lan 0
366obyte get lay i
367end
368end
369fn ofns to void
370for i ulong get fnn 0
371obyte get fns i
372end
373end
374note Write ob to slot k, created or truncated.
375fn spill k ulong to void
376fd = popen k 577
377n = get obn 0
378p = ulong 0
379while lt p n
380r = write fd ob p sub n p
381if le r 0
382dieio
383end
384p = add p ulong r
385end
386if ne fclose fd 0
387dieio
388end
389put obn 0 0
390end
391
392note ---- line tests on inb -----------------------------------------------------------------------
393note end of the line starting at o (index of its LF, or bn)
394fn eol o ulong to ulong
395n = get bn 0
396e = o
397while lt e n
398if eq get inb e 10
399ret e
400end
401e = add e 1
402end
403ret n
404end
405fn lineis o ulong e ulong s view uchar * to bool
406if ne sub e o len s
407ret false
408end
409for i ulong len s
410if ne get inb add o i get s i
411ret false
412end
413end
414ret true
415end
416fn starts o ulong e ulong s view uchar * to bool
417if lt sub e o len s
418ret false
419end
420for i ulong len s
421if ne get inb add o i get s i
422ret false
423end
424end
425ret true
426end
427fn wordch c ulong to bool
428a = and ge c 48 le c 57
429b = and ge c 65 le c 90
430d = and ge c 97 le c 122
431ret or or a b or d eq c 95
432end
433note position (0..9) of inb[o..e) among the words of OLDW, or 10
434fn oldword o ulong e ulong to ulong
435w = ulong 0
436s = ulong 0
437for i ulong len OLDW
438if eq get OLDW i 32
439if eq sub i s sub e o
440same = true
441for j ulong sub i s
442if ne get OLDW add s j get inb add o j
443same = false
444end
445end
446if same
447ret w
448end
449end
450w = add w 1
451s = add i 1
452end
453end
454ret 10
455end
456fn fbyte b uchar to void
457n = get fnn 0
458if ge n len fns
459dieio
460end
461put fns n b
462put fnn 0 add n 1
463end
464fn newword w ulong to void
465k = ulong 0
466for i ulong len NEWW
467c = get NEWW i
468if eq c 32
469k = add k 1
470else
471if eq k w
472fbyte c
473end
474end
475end
476end
477note one functions line inb[o..e) plus its LF (when e < bn)
478fn fnline o ulong e ulong to void
479p = o
480if starts o e EXPFN
481p = add o 7
482end
483if starts o e NOTE
484for i ulong sub e p
485fbyte get inb add p i
486end
487else
488while lt p e
489if wordch ulong get inb p
490q = p
491while and lt q e wordch ulong get inb q
492q = add q 1
493end
494w = oldword p q
495if lt w 10
496newword w
497else
498for i ulong sub q p
499fbyte get inb add p i
500end
501end
502p = q
503else
504fbyte get inb p
505p = add p 1
506end
507end
508end
509if lt e get bn 0
510fbyte 10
511end
512end
513fn lbyte b uchar to void
514n = get lan 0
515if ge n len lay
516dieio
517end
518put lay n b
519put lan 0 add n 1
520end
521note Split the SHA source in inb into lay and fns (step 3).
522fn split to void
523n = get bn 0
524put lan 0 0
525put fnn 0 0
526o = ulong 0
527inl = false
528while lt o n
529e = eol o
530if inl
531for i ulong sub e o
532lbyte get inb add o i
533end
534lbyte 10
535if lineis o e LEND
536inl = false
537end
538else
539if lineis o e LSTART
540inl = true
541for i ulong sub e o
542lbyte get inb add o i
543end
544lbyte 10
545else
546if not lineis o e OM2
547fnline o e
548end
549end
550end
551o = add e 1
552end
553end
554note Append ollm.om (in inb) to ob without `om2` and with main renamed; return the main count.
555fn oollm to ulong
556n = get bn 0
557c = ulong 0
558o = ulong 0
559while lt o n
560e = eol o
561if lineis o e MAINL
562otext WPOLLM
563c = add c 1
564else
565if not lineis o e OM2
566obig o sub e o
567if lt e n
568obyte 10
569end
570end
571end
572o = add e 1
573end
574ret c
575end
576
577note ---- steps -----------------------------------------------------------------------------------
578note slots: 0 REPO, 1 OUT, 2 OMC, 3 OMEGA_MV, 4 CORE, 5 scratch, 6 source, 7 vendored, 8 all, 9 new
579note true when the captured output starts with the 64 hex digits s
580fn capis s view uchar * to bool
581if lt get capn 0 64
582ret false
583end
584for i ulong 64
585if ne get cap i get s i
586ret false
587end
588end
589ret true
590end
591fn stepomc to void
592aclear
593atext SUM
594aslot 2
595capture
596if not capis OMCPIN
597die 3 MOMCP
598end
599end
600fn stepsrc to void
601under 6 1 FSRC
602aclear
603atext GIT
604atext GC
605aslot 3
606atext GSHOW
607atext PIN
608tool -1 popen 6 577
609aclear
610atext SUM
611aslot 6
612capture
613if not capis SHASRC
614die 3 MSHA
615end
616end
617note `OUT/wpcheck sum REPO s` (vendored Omega SHA-256) must print the pin p.
618fn netpin s view uchar * p view uchar * to void
619under 5 1 FCK
620aclear
621aslot 5
622atext CSUM
623under 5 0 s
624aslot 5
625capture
626if not capis p
627say MNET
628pclear
629pslot 5
630saypb
631say NL
632exit 3
633end
634end
635note append the whole file REPO s to ob
636fn ofile s view uchar * to void
637under 5 0 s
638slurp 5
639obig 0 get bn 0
640end
641fn stepollm to void
642netpin SHTTP NPHTTP
643netpin SJSON NPJSON
644netpin SJSONW NPJSONW
645otext OM2NL
646ofile SHTTP
647ofile SJSON
648ofile SJSONW
649ofile SMATH
650ofile SDATA
651ofile SLPOOL
652ofile SMODEL
653ofile SADAM
654ofile SCKPT
655ofile SBPE
656ofile SSPEC
657ofile SCLI
658ofile SLIO
659ofile SSERVE
660ofile SNOGPU
661under 8 1 FOLLM
662spill 8
663under 9 1 FONEW
664compile FOL
665end
666fn stepvend to void
667slurp 6
668split
669under 5 1 FLAY
670olay
671spill 5
672under 5 1 FFNS
673ofns
674spill 5
675under 7 1 FVEN
676otext OM2NL
677olay
678ofns
679spill 7
680under 5 1 FDIF
681aclear
682atext DIFF
683atext DU
684aslot 6
685aslot 7
686x = spawn -1 popen 5 577
687if ne x 1
688say MTOOL
689saynum x
690say NL
691exit 6
692end
693end
694fn compose to void
695under 5 1 FOLLM
696slurp 5
697otext OM2NL
698olay
699c = oollm
700if ne c 1
701say MMAIN
702saynum c
703say NL
704exit 4
705end
706ofns
707under 5 0 FWPS
708slurp 5
709obig 0 get bn 0
710under 8 1 FWALL
711spill 8
712end
713fn composeck to void
714otext OM2NL
715olay
716ofns
717under 5 0 FCKS
718slurp 5
719obig 0 get bn 0
720under 8 1 FCALL
721spill 8
722end
723note Compile slot 8 into slot 9 (the .new file), then rename it to dst (a text under OUT).
724fn compile dst view uchar * to void
725aclear
726atext TSET
727atext TC
728aslot 4
729atext NICE
730atext NN
731atext N19
732aslot 2
733x = spawn popen 8 0 popen 9 577
734if ne x 0
735pclear
736pslot 9
737r = unlink pb 0 get pn 0
738say MOMC
739saynum x
740say NL
741exit int x
742end
743pclear
744pslot 9
745if ne chmod pb 0 get pn 0 493 0
746dieio
747end
748under 5 1 dst
749aclear
750aslot 9
751aslot 5
752put av 0 2
753put av 1 0
754if ne renames av 0 get ap 0 0 0
755dieio
756end
757end
758fn main to int
759if ne argcnt 6
760die 2 MUSAGE
761end
762for i ulong 5
763argslot add i 1 i
764end
765pclear
766pslot 1
767r = makedir pb 0 get pn 0 493
768if and lt r 0 ne r -17
769dieio
770end
771stepomc
772stepsrc
773stepvend
774composeck
775under 9 1 FCNEW
776compile FCK
777stepollm
778compose
779under 9 1 FWNEW
780compile FWP
781aclear
782atext SUM
783aslot 2
784aslot 6
785under 5 1 FOLLM
786aslot 5
787under 5 1 FOL
788aslot 5
789under 5 1 FCALL
790aslot 5
791under 5 1 FCK
792aslot 5
793under 5 1 FWALL
794aslot 5
795under 5 1 FWP
796aslot 5
797tool -1 -1
798say MOK
799ret 0
800end