interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / native / btwave / main.om

545 lines · 7308 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note BTWAVE-P0: Main Driver, Self-Test, Deterministic Trace, and CLI (native/btwave/main.om).
3
4global Obuf uchar 65536
5global Olen ulong 2
6
7text Tbt6 "BT6 "
8text Tbtall "BT6_ALL 729 "
9text Tswar "SWAR32 "
10text Thc3 "HC3 "
11text Th16 "H16 "
12text Tsha "SHA "
13text Tldg "LDG "
14text Tend "END "
15text Tipc1 "IPC PASS coreA="
16text Tipc2 " coreB="
17text Tipc3 " rounds="
18text Tipc4 " contrib="
19text Tipc5 " extract="
20text Tipc6 " odraft_refused="
21text Tipc7 " elapsed_ns="
22text Ctrace "trace"
23text Cself "selftest"
24text Cipc "ipc"
25text Ctrapt "trap-trit"
26text Ctrapd "trap-dup"
27text Ctrapr "trap-req"
28text Covf "ovf-probe"
29
30fn oflush to void
31n = get Olen 0
32if gt n 0
33x = write 1 Obuf 0 n
34put Olen 0 0
35end
36end
37
38fn oputc ch uchar to void
39n = get Olen 0
40if ge n 65500
41oflush
42n = 0
43end
44put Obuf n ch
45put Olen 0 add n 1
46end
47
48fn ostr s view uchar * to void
49for i ulong len s
50oputc get s i
51end
52end
53
54fn osp to void
55oputc 32
56end
57
58fn onl to void
59oputc 10
60end
61
62fn ou64 v ulong to void
63dg = new uchar 24 0
64if eq v 0
65oputc 48
66ret
67end
68k = ulong 0
69x = v
70while gt x 0 bound 24
71put dg k uchar add 48 and rem x 10 0xff
72x = div x 10
73k = add k 1
74end
75for i ulong k
76oputc get dg sub sub k 1 i
77end
78end
79
80fn oi64 v long to void
81if ge v 0
82ou64 ulong v
83ret
84end
85oputc 45
86vp = neg add v 1
87ou64 add ulong vp 1
88end
89
90fn eq_txt a view uchar * n ulong b view uchar * to bool
91if ne n len b
92ret false
93end
94for i ulong n
95if ne get a i get b i
96ret false
97end
98end
99ret true
100end
101
102fn emit_bt6_one u long to void
103w = bt6enc u
104wa = open w
105ostr Tbt6
106oi64 u
107osp
108ou64 shr wa 32
109osp
110ou64 and wa M32
111osp
112oi64 bt6dec w
113osp
114oi64 bt6dec t32neg w
115osp
116oi64 t32pow w
117onl
118end
119
120fn calc_bt6_stats st edit long 4 to void
121bij = long 0
122nsym = long 0
123zcnt = long 0
124tpow = long 0
125for idx ulong 729
126u = sub long idx 364
127w = bt6enc u
128if eq bt6dec w u
129bij = add bij 1
130end
131if eq open bt6enc neg u open t32neg w
132nsym = add nsym 1
133end
134pw = t32pow w
135if eq pw 0
136zcnt = add zcnt 1
137end
138tpow = add tpow pw
139end
140put st 0 bij
141put st 1 nsym
142put st 2 zcnt
143put st 3 tpow
144end
145
146fn build_swar_vec mulk ulong addk ulong to Trit32
147p = ulong 0
148n = ulong 0
149for i ulong 32
150rm = rem add mul mulk i addk 3
151ib = shl ulong 1 i
152if eq rm 2
153p = or p ib
154else
155if eq rm 0
156n = or n ib
157end
158end
159end
160ret Trit32mk or shl p 32 n
161end
162
163fn emit_swar to long
164wa = build_swar_vec 1 0
165wb = build_swar_vec 2 1
166ra = open wa
167rb = open wb
168dab = t32dot wa wb
169daa = t32dot wa wa
170dbb = t32dot wb wb
171pab = t32pow t32mul wa wb
172ostr Tswar
173ou64 shr ra 32
174osp
175ou64 and ra M32
176osp
177ou64 shr rb 32
178osp
179ou64 and rb M32
180osp
181oi64 dab
182osp
183oi64 daa
184osp
185oi64 dbb
186osp
187oi64 pab
188onl
189if or ne dab 10 or ne daa 21 or ne dbb 21 ne pab 10
190ret 1
191end
192ret 0
193end
194
195fn calc_hc3_ok to long
196ok = long 0
197for m ulong 16
198if eq hc3dec hc3enc m m
199ok = add ok 1
200end
201end
202ret ok
203end
204
205fn emit_hc3 to long
206ok = calc_hc3_ok
207cf = open hc3enc 0
208cz = open hc3enc 7
209cl = open hc3enc 15
210oob = hc3dec Trit32mk 7
211ostr Thc3
212oi64 ok
213osp
214ou64 shr cf 32
215osp
216ou64 and cf M32
217osp
218ou64 shr cz 32
219osp
220ou64 and cz M32
221osp
222ou64 shr cl 32
223osp
224ou64 and cl M32
225osp
226ou64 oob
227onl
228if or ne ok 16 ne oob 99
229ret 1
230end
231ret 0
232end
233
234fn h16_ok01 st edit long 5 to void
235ok0 = long 0
236ok1 = long 0
237for s ulong 32
238w = h16enc s
239if eq h16dec w long s
240ok0 = add ok0 1
241end
242for c ulong 16
243if eq h16dec t32flip w c long s
244ok1 = add ok1 1
245end
246end
247end
248put st 0 ok0
249put st 1 ok1
250end
251
252fn h16_ok2 st edit long 5 to void
253ok2 = long 0
254w5 = h16enc 5
255w21 = h16enc 21
256for c1 ulong 16
257for c2 ulong 16
258if lt c1 c2
259if eq h16dec t32flip t32flip w5 c1 c2 5
260ok2 = add ok2 1
261end
262if eq h16dec t32flip t32flip w21 c1 c2 21
263ok2 = add ok2 1
264end
265if eq h16dec t32eras t32eras w5 c1 c2 5
266ok2 = add ok2 1
267end
268end
269end
270end
271put st 2 ok2
272end
273
274fn h16_ok3 st edit long 5 to void
275ok3 = long 0
276w13 = h16enc 13
277for c1 ulong 16
278for c2 ulong 16
279if lt c1 c2
280for c3 ulong 16
281if lt c2 c3
282if eq h16dec t32flip t32flip t32flip w13 c1 c2 c3 13
283ok3 = add ok3 1
284end
285if eq h16dec t32eras t32eras t32eras w13 c1 c2 c3 13
286ok3 = add ok3 1
287end
288end
289end
290end
291end
292end
293put st 3 ok3
294end
295
296fn h16_ref4 st edit long 5 to void
297rf = long 0
298w0 = h16enc 0
299for a ulong 8
300for b ulong 8
301if lt a b
302for c ulong 8
303if lt b c
304for d ulong 8
305if lt c d
306rx = t32flip t32flip w0 add mul 2 a 1 add mul 2 b 1
307rx = t32flip t32flip rx add mul 2 c 1 add mul 2 d 1
308if eq h16dec rx -1
309rf = add rf 1
310end
311end
312end
313end
314end
315end
316end
317end
318put st 4 rf
319end
320
321fn sha_abc_hi64 to ulong
322m = new uchar 3 0
323dg = new uchar 32 0
324put m 0 97
325put m 1 98
326put m 2 99
327sha256_slice view m dg
328ret rd64be view dg 0
329end
330
331fn run_ldg_suite emit bool to int
332ev = new long 7 0
333ldg_reset
334init_cases
335bad = int 0
336for cid ulong 16
337o = mul cid 7
338for j ulong 7 unroll
339put ev j get Lcases add o j
340end
341st = ldg_step ev
342if ne st get Lexp cid
343bad = 1
344end
345if gt get Lstate 2 get Lstate 1
346bad = 2
347end
348if emit
349ostr Tldg
350ou64 cid
351osp
352oi64 st
353osp
354oi64 get Lresp 0
355osp
356ou64 get Lstate 0
357osp
358ou64 get Lstate 1
359osp
360ou64 get Lstate 2
361osp
362ou64 ldg_chid
363onl
364end
365end
366if emit
367ostr Tend
368ou64 get Lstate 3
369osp
370ou64 get Lstate 4
371osp
372ou64 get Lstate 5
373osp
374ou64 get Lstate 1
375osp
376ou64 get Lstate 2
377onl
378end
379if or ne get Lstate 1 90 ne get Lstate 2 90
380bad = 3
381end
382ret bad
383end
384
385fn cmd_trace to int
386bs = new long 4 0
387hs = new long 5 0
388emit_bt6_one -364
389emit_bt6_one -243
390emit_bt6_one -40
391emit_bt6_one -1
392emit_bt6_one 0
393emit_bt6_one 1
394emit_bt6_one 40
395emit_bt6_one 243
396emit_bt6_one 364
397calc_bt6_stats bs
398ostr Tbtall
399oi64 get bs 0
400osp
401oi64 get bs 1
402osp
403oi64 get bs 2
404osp
405oi64 get bs 3
406onl
407rc1 = emit_swar
408rc2 = emit_hc3
409h16_ok01 hs
410h16_ok2 hs
411h16_ok3 hs
412h16_ref4 hs
413ostr Th16
414oi64 get hs 0
415osp
416oi64 get hs 1
417osp
418oi64 get hs 2
419osp
420oi64 get hs 3
421osp
422oi64 get hs 4
423onl
424ostr Tsha
425ou64 sha_abc_hi64
426onl
427rc3 = run_ldg_suite true
428oflush
429ret int add add rc1 rc2 long rc3
430end
431
432fn cmd_selftest to int
433bs = new long 4 0
434hs = new long 5 0
435calc_bt6_stats bs
436if or ne get bs 0 729 or ne get bs 1 729 or ne get bs 2 1 ne get bs 3 2916
437ret 10
438end
439if ne bt6tor 364 1 -364
440ret 11
441end
442if ne calc_hc3_ok 16
443ret 12
444end
445if ne hc3dec Trit32mk 7 99
446ret 13
447end
448h16_ok01 hs
449h16_ok2 hs
450h16_ok3 hs
451h16_ref4 hs
452if or ne get hs 0 32 or ne get hs 1 512 or ne get hs 2 360 or ne get hs 3 1120 ne get hs 4 70
453ret 14
454end
455if ne sha_abc_hi64 13436514500253700074
456ret 15
457end
458if ne t32dot h16enc 0 h16enc 16 -16
459ret 16
460end
461rc = run_ldg_suite false
462if ne rc 0
463ret add 20 rc
464end
465ret 0
466end
467
468fn cmd_ipc to int
469rc = ipc_run
470if ne rc 0
471ret rc
472end
473ostr Tipc1
474oi64 get IpcOut 0
475ostr Tipc2
476oi64 get IpcOut 1
477ostr Tipc3
478oi64 get IpcOut 2
479ostr Tipc4
480oi64 get IpcOut 3
481ostr Tipc5
482oi64 get IpcOut 4
483ostr Tipc6
484oi64 get IpcOut 5
485ostr Tipc7
486oi64 get IpcOut 6
487onl
488oflush
489ret 0
490end
491
492fn cmd_ovf_probe to int
493ev = new long 7 0
494ldg_reset
495put ev 0 1
496put ev 1 1
497put ev 2 10
498put ev 3 0
499put ev 4 4611686018427387904
500put ev 5 0
501put ev 6 0
502st = ldg_step ev
503if ne st -6
504ret 41
505end
506ret 0
507end
508
509fn main to int
510abuf = new uchar 64 0
511ac = argcnt
512if ne ac 2
513ret 2
514end
515al = argread 1 abuf 0 64
516if lt al 0
517ret 2
518end
519nl = ulong al
520if eq_txt view abuf nl Ctrace
521ret cmd_trace
522end
523if eq_txt view abuf nl Cself
524ret cmd_selftest
525end
526if eq_txt view abuf nl Cipc
527ret cmd_ipc
528end
529if eq_txt view abuf nl Ctrapt
530badt = Trit32mk 0x0000000100000001
531ret int and open badt 1
532end
533if eq_txt view abuf nl Ctrapd
534badd = WaveDupmk 0x0000000100000002
535ret int and open badd 1
536end
537if eq_txt view abuf nl Ctrapr
538badr = bt6enc 365
539ret int and open badr 1
540end
541if eq_txt view abuf nl Covf
542ret cmd_ovf_probe
543end
544ret 2
545end