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 / native / arboris.om

659 lines · 15929 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note native/arboris.om: Pillar 5 - Arboris 1 us Associative CPU Bypass + Warp-Compacted Early Exit Gating
3note + OMG Native Semantic-Graph Recall, 3-Layer Guided Decoding & Hippocampus->Cortex Sleep Export.
4note Pure seeded OM-2 library unit (compose under `om2` or `target a64macos\nom2`).
5
6const ARB_CAP ulong 4096
7const ARB_MASK ulong 4095
8const ARB_MAX_PROBE ulong 32
9const ARB_MAX_NGRAM ulong 8
10const ARB_MAX_TOK ulong 512
11const ARB_WARP_SZ ulong 32
12const ARB_MAX_WARPS ulong 16
13
14const ARB_EXIT_CPU ulong 0
15const ARB_EXIT_L1 ulong 1
16const ARB_EXIT_L2 ulong 2
17const ARB_EXIT_CONTESTED ulong 99
18
19const ARB_OMG_CAP ulong 256
20const ARB_OMG_SLEN ulong 64
21
22note Open-addressed associative table (4096 slots, L1/L2 resident for sub-microsecond probe)
23global arb_key ulong 4096
24global arb_sig ulong 4096
25global arb_len uchar 4096
26global arb_tok ulong 4096
27global arb_conf ulong 4096
28global arb_hits ulong 4096
29global arb_stat ulong 8
30
31note Per-token bypass / adaptive-loop / spclip routing arrays + dense compacted active list + warp ballot masks
32global arb_bypass_conf ulong 512
33global arb_loop_delta ulong 512
34global arb_sp_jsd ulong 512
35global arb_exit_layer ulong 512
36global arb_active_idx ulong 512
37global arb_warp_mask ulong 16
38global arb_cfg ulong 8
39
40note OMG semantic-graph Hippocampus->Cortex memory (256 verified subgraphs, up to 64 tokens each)
41global arb_omg_n ulong 1
42global arb_omg_sem ulong 256
43global arb_omg_io ulong 256
44global arb_omg_opm ulong 256
45global arb_omg_mtok ulong 256
46global arb_omg_util ulong 256
47global arb_omg_slen ulong 256
48global arb_omg_act ulong 256
49global arb_omg_toks ulong 16384
50
51note 3-layer guided decoding step buffers (OMG vocab <= 512)
52global arb_omg_logits f64 512
53global arb_omg_mask uchar 512
54global arb_omg_biased f64 512
55
56note ---- Self-contained Wolfram-verified f64 log for JSD strand disagreement (matches math.om) ----
57
58fn arb_flog x f64 to f64
59if ne x x
60ret x
61end
62if lt x 0.0
63ret bitcast f64 ulong 9221120237041090560
64end
65if eq x 0.0
66ret bitcast f64 ulong 18442240474082181120
67end
68b = bitcast ulong x
69if eq b 9218868437227405312
70ret x
71end
72e = long 0
73if lt b 4503599627370496
74b = bitcast ulong mul x 18014398509481984.0
75e = long -54
76end
77e = add e sub long shr b 52 1023
78m = bitcast f64 or and b 4503599627370495 4607182418800017408
79if gt m 1.4142135623730951
80m = mul m 0.5
81e = add e 1
82end
83f = sub m 1.0
84s = div f add f 2.0
85z = mul s s
86q = add mul z 0.043478260869565216 0.047619047619047616
87q = add mul q z 0.05263157894736842
88q = add mul q z 0.058823529411764705
89q = add mul q z 0.06666666666666667
90q = add mul q z 0.07692307692307693
91q = add mul q z 0.09090909090909091
92q = add mul q z 0.1111111111111111
93q = add mul q z 0.14285714285714285
94q = add mul q z 0.2
95q = add mul q z 0.3333333333333333
96q = add mul q z 1.0
97lm = mul add s s q
98fe = f64 e
99ret add mul fe 0.6931471803691238 add lm mul fe 1.9082149292705877e-10
100end
101
102note ---- Fast FNV-1a-64 + SplitMix64 Context N-Gram Hashing ----
103
104fn arb_smx x ulong to ulong
105z = add x 0x9e3779b97f4a7c15
106z = mul xor z shr z 30 0xbf58476d1ce4e5b9
107z = mul xor z shr z 27 0x94d049bb133111eb
108ret xor z shr z 31
109end
110
111fn arboris_fnv64_ngram ctx view ulong * off ulong n ulong to ulong
112h = ulong 0xcbf29ce484222325
113for i ulong n bound 16
114w = get ctx add off i
115for b ulong 4
116by = and shr w mul b 8 255
117h = mul xor h by 0x100000001b3
118end
119end
120if eq h 0
121h = ulong 1
122end
123ret h
124end
125
126fn arboris_sig64_ngram ctx view ulong * off ulong n ulong to ulong
127s = mul n 0x9e3779b97f4a7c15
128for i ulong n bound 16
129s = arb_smx xor s get ctx add off i
130end
131ret s
132end
133
134note ---- Open-Addressed Associative Pattern Table ----
135
136fn arboris_clear to void
137for i ulong ARB_CAP bound 4096
138put arb_key i 0
139put arb_sig i 0
140put arb_len i 0
141put arb_tok i 0
142put arb_conf i 0
143put arb_hits i 0
144end
145for j ulong 8
146put arb_stat j 0
147end
148for t ulong ARB_MAX_TOK bound 512
149put arb_bypass_conf t 0
150put arb_loop_delta t 0
151put arb_sp_jsd t 0
152put arb_exit_layer t ARB_EXIT_CONTESTED
153put arb_active_idx t 0
154put arb_omg_logits t 0.0f64
155put arb_omg_mask t 1
156put arb_omg_biased t 0.0f64
157end
158for w ulong ARB_MAX_WARPS bound 16
159put arb_warp_mask w 0
160end
161put arb_omg_n 0 0
162for m ulong ARB_OMG_CAP bound 256
163put arb_omg_sem m 0
164put arb_omg_io m 0
165put arb_omg_opm m 0
166put arb_omg_mtok m 0
167put arb_omg_util m 0
168put arb_omg_slen m 0
169put arb_omg_act m 0
170end
171put arb_cfg 0 900000
172put arb_cfg 1 50000
173put arb_cfg 2 100
174put arb_cfg 3 25000
175put arb_cfg 4 900000
176put arb_cfg 5 2000
177put arb_cfg 6 2500
178put arb_cfg 7 0
179end
180
181fn arboris_slot_match slot ulong h ulong sg ulong n ulong to bool
182if ne get arb_key slot h
183ret false
184end
185if ne get arb_sig slot sg
186ret false
187end
188ret eq ulong get arb_len slot n
189end
190
191fn arboris_slot_store slot ulong h ulong sg ulong n ulong pred_tok ulong conf ulong to void
192put arb_key slot h
193put arb_sig slot sg
194put arb_len slot uchar n
195put arb_tok slot pred_tok
196put arb_conf slot conf
197put arb_hits slot 1
198put arb_stat 0 add get arb_stat 0 1
199put arb_stat 1 add get arb_stat 1 1
200end
201
202fn arboris_slot_update slot ulong pred_tok ulong conf ulong to void
203put arb_hits slot add get arb_hits slot 1
204put arb_stat 1 add get arb_stat 1 1
205if eq get arb_tok slot pred_tok
206if gt conf get arb_conf slot
207put arb_conf slot conf
208end
209else
210put arb_conf slot 0
211put arb_stat 5 add get arb_stat 5 1
212end
213end
214
215note Insert or reinforce context n-gram -> predicted token.
216note Ambiguous continuations (same n-gram seen with different pred_tok) automatically demote conf to 0.
217fn arboris_put ctx view ulong * off ulong n ulong pred_tok ulong conf_micro ulong to bool
218if or eq n 0 gt n ARB_MAX_NGRAM
219ret false
220end
221if gt add off n len ctx
222ret false
223end
224if gt conf_micro 1000000
225ret false
226end
227h = arboris_fnv64_ngram ctx off n
228sg = arboris_sig64_ngram ctx off n
229idx = and h ARB_MASK
230for p ulong ARB_MAX_PROBE bound 32
231slot = and add idx p ARB_MASK
232if eq get arb_key slot 0
233arboris_slot_store slot h sg n pred_tok conf_micro
234ret true
235end
236if arboris_slot_match slot h sg n
237arboris_slot_update slot pred_tok conf_micro
238ret true
239end
240put arb_stat 4 add get arb_stat 4 1
241end
242ret false
243end
244
245note Probe associative pattern table in ~1 us; out_res[0]=pred_tok, out_res[1]=conf_micro
246fn arboris_probe ctx view ulong * off ulong n ulong out_res edit ulong 2 to bool
247if or eq n 0 gt n ARB_MAX_NGRAM
248ret false
249end
250if gt add off n len ctx
251ret false
252end
253put arb_stat 2 add get arb_stat 2 1
254h = arboris_fnv64_ngram ctx off n
255sg = arboris_sig64_ngram ctx off n
256idx = and h ARB_MASK
257for p ulong ARB_MAX_PROBE bound 32
258slot = and add idx p ARB_MASK
259if eq get arb_key slot 0
260ret false
261end
262if arboris_slot_match slot h sg n
263cf = get arb_conf slot
264if eq cf 0
265ret false
266end
267put out_res 0 get arb_tok slot
268put out_res 1 cf
269put arb_stat 3 add get arb_stat 3 1
270ret true
271end
272end
273ret false
274end
275
276note ---- 1 us Associative CPU Sequence Bypass (Zero GPU Matmuls) ----
277
278fn arboris_probe_pos seq view ulong * pos ulong max_ng ulong th ulong out_res edit ulong 2 to bool
279ng = max_ng
280if gt ng add pos 1
281ng = add pos 1
282end
283if gt ng ARB_MAX_NGRAM
284ng = ARB_MAX_NGRAM
285end
286while ge ng 2 bound 8
287off = sub add pos 1 ng
288if arboris_probe seq off ng out_res
289if ge get out_res 1 th
290ret true
291end
292end
293ng = sub ng 1
294end
295ret false
296end
297
298note Scan seq[0..n_seq), populate out_pred[pos], arb_bypass_conf[pos], and arb_active_idx[0..n_contested).
299note Returns count of tokens bypassed on CPU with zero GPU matmuls; sets arb_stat[6] = n_contested.
300fn arboris_bypass_seq seq view ulong * n_gram ulong thresh_micro ulong out_pred edit ulong * to ulong
301n_seq = len seq
302if or gt n_seq ARB_MAX_TOK gt n_seq len out_pred
303ret 0
304end
305res = new ulong 2 0
306n_bypass = ulong 0
307n_cont = ulong 0
308for pos ulong n_seq bound 512
309put arb_bypass_conf pos 0
310put out_pred pos 0
311if arboris_probe_pos seq pos n_gram thresh_micro res
312put out_pred pos get res 0
313put arb_bypass_conf pos get res 1
314put arb_exit_layer pos ARB_EXIT_CPU
315n_bypass = add n_bypass 1
316else
317put arb_exit_layer pos ARB_EXIT_CONTESTED
318put arb_active_idx n_cont pos
319n_cont = add n_cont 1
320end
321end
322put arb_stat 6 n_cont
323ret n_bypass
324end
325
326note ---- d9b7422 Adaptive Loop Exit + spclip Strand Disagreement Warp Compaction ----
327
328fn arboris_set_thresholds bypass_th ulong delta_th ulong jsd_th ulong l1_delta_th ulong to void
329put arb_cfg 0 bypass_th
330put arb_cfg 1 delta_th
331put arb_cfg 2 jsd_th
332put arb_cfg 3 l1_delta_th
333end
334
335fn arboris_set_token_signals t ulong bypass_conf ulong loop_delta_micro ulong sp_jsd_milli ulong to void
336if lt t ARB_MAX_TOK
337put arb_bypass_conf t bypass_conf
338put arb_loop_delta t loop_delta_micro
339put arb_sp_jsd t sp_jsd_milli
340end
341end
342
343note Compute Jensen-Shannon Disagreement in milli-nats between two strand probability vectors (matches spclip)
344fn arboris_jsd_milli pa view f64 * pb view f64 * to ulong
345v = len pa
346if or eq v 0 ne v len pb
347ret 0
348end
349ha = 0.0f64
350hb = 0.0f64
351hm = 0.0f64
352for j ulong v bound 4096
353va = get pa j
354vb = get pb j
355if gt va 1.0e-15f64
356ha = sub ha mul va arb_flog va
357end
358if gt vb 1.0e-15f64
359hb = sub hb mul vb arb_flog vb
360end
361vm = mul 0.5 add va vb
362if gt vm 1.0e-15f64
363hm = sub hm mul vm arb_flog vm
364end
365end
366jsd = sub hm mul 0.5 add ha hb
367if lt jsd 0.0
368jsd = 0.0f64
369end
370ret ulong add mul jsd 1000.0 0.5
371end
372
373note Classify tokens and compact contested tokens into dense arb_active_idx[] + 32-bit arb_warp_mask[].
374note Returns n_active (number of contested tokens routed to deeper LTP0 passes).
375fn arboris_compact_one t ulong n_act ulong to ulong
376jsd = get arb_sp_jsd t
377bc = get arb_bypass_conf t
378dl = get arb_loop_delta t
379disagree = ge jsd get arb_cfg 2
380if and not disagree ge bc get arb_cfg 0
381put arb_exit_layer t ARB_EXIT_CPU
382ret n_act
383end
384if and not disagree lt dl get arb_cfg 3
385put arb_exit_layer t ARB_EXIT_L1
386ret n_act
387end
388if and not disagree lt dl get arb_cfg 1
389put arb_exit_layer t ARB_EXIT_L2
390ret n_act
391end
392put arb_exit_layer t ARB_EXIT_CONTESTED
393put arb_active_idx n_act t
394wid = div t 32
395lane = rem t 32
396put arb_warp_mask wid or get arb_warp_mask wid shl ulong 1 lane
397ret add n_act 1
398end
399
400fn arboris_compact_mask n_tok ulong to ulong
401if gt n_tok ARB_MAX_TOK
402ret 0
403end
404n_warps = div add n_tok 31 32
405for w ulong n_warps bound 16
406put arb_warp_mask w 0
407end
408n_act = ulong 0
409for t ulong n_tok bound 512
410n_act = arboris_compact_one t n_act
411end
412put arb_stat 7 n_act
413ret n_act
414end
415
416fn arboris_popcnt32 mask ulong to ulong
417m = and mask 0xffffffff
418c = ulong 0
419for i ulong 32
420if ne and shr m i 1 0
421c = add c 1
422end
423end
424ret c
425end
426
427fn arboris_popcnt64 mask ulong to ulong
428c = ulong 0
429for i ulong 64
430if ne and shr mask i 1 0
431c = add c 1
432end
433end
434ret c
435end
436
437note ---- OMG Semantic-Graph Recall + 3-Layer Guided Decoding + Hippocampus->Cortex Sleep Export ----
438
439fn arboris_omg_find sem_id ulong to ulong
440cnt = get arb_omg_n 0
441for m ulong cnt bound 256
442if eq get arb_omg_sem m sem_id
443ret m
444end
445end
446ret ARB_OMG_CAP
447end
448
449fn arboris_omg_victim to ulong
450cnt = get arb_omg_n 0
451if lt cnt ARB_OMG_CAP
452put arb_omg_n 0 add cnt 1
453ret cnt
454end
455best = ulong 0
456bu = get arb_omg_util 0
457for m ulong ARB_OMG_CAP bound 256
458u = get arb_omg_util m
459if lt u bu
460bu = u
461best = m
462end
463end
464ret best
465end
466
467note Hippocampus->Cortex online insert on verified oracle pass; returns slot index (0..255).
468fn arboris_insert_verified_omg sem_id ulong io_sig ulong op_mask ulong macro_tok ulong utility_milli ulong to long
469if eq sem_id 0
470ret long -1
471end
472idx = arboris_omg_find sem_id
473if lt idx ARB_OMG_CAP
474put arb_omg_util idx add get arb_omg_util idx utility_milli
475put arb_omg_mtok idx macro_tok
476ret long idx
477end
478slot = arboris_omg_victim
479put arb_omg_sem slot sem_id
480put arb_omg_io slot io_sig
481put arb_omg_opm slot op_mask
482put arb_omg_mtok slot macro_tok
483put arb_omg_util slot utility_milli
484put arb_omg_slen slot 0
485ret long slot
486end
487
488fn arboris_set_omg_stream slot ulong pos ulong tok ulong to void
489if and lt slot ARB_OMG_CAP lt pos ARB_OMG_SLEN
490put arb_omg_toks add mul slot ARB_OMG_SLEN pos tok
491if ge add pos 1 get arb_omg_slen slot
492put arb_omg_slen slot add pos 1
493end
494end
495end
496
497note Exact OMG subgraph recall via ~1 us spreading activation over SEMANTIC_ID, IO signature, and opcode cues.
498note out_res: [0]=best_slot, [1]=best_sem_id, [2]=best_macro_tok, [3]=peak_activation_milli.
499fn arboris_omg_score m ulong cue_sem ulong cue_io ulong cue_opm ulong to ulong
500act = ulong 0
501if and ne cue_sem 0 eq get arb_omg_sem m cue_sem
502act = add act 4000
503end
504if and ne cue_io 0 eq get arb_omg_io m cue_io
505act = add act 2000
506end
507ov = arboris_popcnt64 and get arb_omg_opm m cue_opm
508act = add act mul ov 250
509ub = div get arb_omg_util m 10
510if gt ub 500
511ub = ulong 500
512end
513ret add act ub
514end
515
516fn arboris_omg_recall cue_sem ulong cue_io ulong cue_opm ulong out_res edit ulong 4 to bool
517cnt = get arb_omg_n 0
518if eq cnt 0
519ret false
520end
521best = ulong 0
522bact = ulong 0
523for m ulong cnt bound 256
524act = arboris_omg_score m cue_sem cue_io cue_opm
525put arb_omg_act m act
526if gt act bact
527bact = act
528best = m
529end
530end
531if eq bact 0
532ret false
533end
534put out_res 0 best
535put out_res 1 get arb_omg_sem best
536put out_res 2 get arb_omg_mtok best
537put out_res 3 bact
538put arb_cfg 7 get arb_omg_mtok best
539ret true
540end
541
542note 3-layer guided decoding step:
543note (a) gsamp/OMG bitmask wall (illegal tokens zeroed via -1e300 logit floor)
544note (b) Arboris 1 us logit bias toward recalled high-activation OMG opcode/macro
545note (c) LTP0 deep-compute trigger (set to 1 when peak_act < ltp0_act_thresh OR jsd_milli >= jsd_thresh)
546note out_step: [0]=selected_tok, [1]=need_ltp0 (0 or 1), [2]=peak_act, [3]=jsd_milli
547fn arboris_set_omg_step_in tok ulong logit f64 valid uchar to void
548if lt tok ARB_MAX_TOK
549put arb_omg_logits tok logit
550put arb_omg_mask tok valid
551end
552end
553
554fn arboris_set_guide_cfg bias_gain_milli ulong ltp0_act_th ulong bias_tok ulong to void
555put arb_cfg 5 bias_gain_milli
556put arb_cfg 6 ltp0_act_th
557put arb_cfg 7 bias_tok
558end
559
560fn arboris_guide_pick v ulong btok ulong b_on bool gain f64 to ulong
561best_tok = ulong 0
562best_val = -1.0e300f64
563found = false
564for c ulong v bound 512
565if eq get arb_omg_mask c 0
566put arb_omg_biased c -1.0e300f64
567else
568lv = get arb_omg_logits c
569if and b_on eq c btok
570lv = add lv gain
571end
572put arb_omg_biased c lv
573if or not found gt lv best_val
574best_val = lv
575best_tok = c
576found = true
577end
578end
579end
580ret best_tok
581end
582
583fn arboris_guide_omg_step v ulong peak_act ulong jsd_milli ulong out_step edit ulong 4 to ulong
584if or eq v 0 gt v ARB_MAX_TOK
585ret 0
586end
587gain = div f64 get arb_cfg 5 1000.0
588b_on = ge peak_act get arb_cfg 6
589best_tok = arboris_guide_pick v get arb_cfg 7 b_on gain
590need_ltp0 = ulong 0
591if or lt peak_act get arb_cfg 6 ge jsd_milli get arb_cfg 2
592need_ltp0 = ulong 1
593end
594put out_step 0 best_tok
595put out_step 1 need_ltp0
596put out_step 2 peak_act
597put out_step 3 jsd_milli
598ret best_tok
599end
600
601note Export high-utility OMG traces (records: sem_id, io_sig, op_mask, macro_tok, util, len, toks...)
602note into out_buf for Hippocampus->Cortex sleep consolidation (fcachem / sp_solve.om).
603fn arboris_export_one m ulong pos ulong out_buf edit ulong * to ulong
604sl = get arb_omg_slen m
605put out_buf pos get arb_omg_sem m
606put out_buf add pos 1 get arb_omg_io m
607put out_buf add pos 2 get arb_omg_opm m
608put out_buf add pos 3 get arb_omg_mtok m
609put out_buf add pos 4 get arb_omg_util m
610put out_buf add pos 5 sl
611base = mul m ARB_OMG_SLEN
612dst = add pos 6
613for k ulong sl bound 64
614put out_buf add dst k get arb_omg_toks add base k
615end
616ret add 6 sl
617end
618
619fn arboris_export_sleep_traces min_util ulong out_buf edit ulong * out_cnt edit ulong 1 to ulong
620cnt = get arb_omg_n 0
621cap = len out_buf
622pos = ulong 0
623n_exp = ulong 0
624for m ulong cnt bound 256
625if ge get arb_omg_util m min_util
626need = add 6 get arb_omg_slen m
627if gt add pos need cap
628break
629end
630pos = add pos arboris_export_one m pos out_buf
631n_exp = add n_exp 1
632end
633end
634put out_cnt 0 n_exp
635ret pos
636end
637
638text arb_cli_ok "ARBORIS_SELFTEST PASS\n"
639
640fn cmdarboris to void
641arboris_clear
642sq = new ulong 4 0
643put sq 0 11
644put sq 1 22
645put sq 2 33
646put sq 3 44
647ok = arboris_put sq 0 3 99 950000
648if not ok
649exit 1
650end
651res = new ulong 2 0
652if not arboris_probe sq 0 3 res
653exit 2
654end
655if or ne get res 0 99 lt get res 1 900000
656exit 3
657end
658w = write 1 arb_cli_ok 0 len arb_cli_ok
659end