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 / om / gpu / inkling2 / arboris / check-arboris.om

289 lines · 7465 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Pure OM-2 CPU host gate for Inkling-2-Mini Arboris prefetch adapter and
3note online sum-over-paths looped cross-layer co-activation prefetcher.
4note Compose after om/gpu/inkling2/arboris/prefetch.om.
5
6fn ckStaticHints to int
7 scores = new uint 6 0
8 experts = new uint 6 0
9 recs = new uint 6 0
10 badRecs = new uint 3 0
11 note Node 0: exp 5 score 0.5 (0x3f000000)
12 note Node 1: exp 5 score 0.75 (0x3f400000) -> max wins (0.75)
13 note Node 2: exp 2 score 0.75 (0x3f400000) -> tie with exp 5, lower ID (2) wins first
14 note Node 3: 0xffffffff score 1.0 (0x3f800000) -> ignored
15 note Node 4: exp 9 score 0.0 -> zero score never issues I/O
16 note Node 5: exp 7 score 0.25 (0x3e800000) -> 3rd
17 put scores 0 0x3f000000
18 put experts 0 5
19 put scores 1 0x3f400000
20 put experts 1 5
21 put scores 2 0x3f400000
22 put experts 2 2
23 put scores 3 0x3f800000
24 put experts 3 0xffffffff
25 put scores 4 0
26 put experts 4 9
27 put scores 5 0x3e800000
28 put experts 5 7
29 cnt = ik_arboris_expert_hints scores experts recs
30 if ne cnt 3
31 ret 11
32 end
33 if or ne get recs 0 3 ne get recs 1 2
34 ret 12
35 end
36 if or ne get recs 2 3 ne get recs 3 5
37 ret 13
38 end
39 if or ne get recs 4 3 ne get recs 5 7
40 ret 14
41 end
42 note Budget cap: 2-word slice -> only top 1 (exp 2)
43 cnt2 = ik_arboris_expert_hints scores experts part recs 0 2
44 if or ne cnt2 1 ne get recs 1 2
45 ret 15
46 end
47 note Reject odd outbuf length
48 if ne ik_arboris_expert_hints scores experts badRecs -1
49 ret 16
50 end
51 note Reject score > 1.0 (0x3f800001)
52 put scores 0 0x3f800001
53 if ne ik_arboris_expert_hints scores experts recs -1
54 ret 17
55 end
56 note Reject out-of-range expert ID 128
57 put scores 0 0x3f000000
58 put experts 0 128
59 if ne ik_arboris_expert_hints scores experts recs -1
60 ret 18
61 end
62 note Reject mismatched input lengths
63 put experts 0 5
64 if ne ik_arboris_expert_hints part scores 0 5 experts recs -1
65 ret 19
66 end
67 note Reject negative zero (0x80000000), NaN (0x7fc00000), and sentinel with score > 1.0
68 put scores 0 0x80000000
69 if ne ik_arboris_expert_hints scores experts recs -1
70 ret 41
71 end
72 put scores 0 0x7fc00000
73 if ne ik_arboris_expert_hints scores experts recs -1
74 ret 42
75 end
76 put scores 0 0x3f800001
77 put experts 0 0xffffffff
78 if ne ik_arboris_expert_hints scores experts recs -1
79 ret 43
80 end
81 note Reject invalid records in ik_arboris_send_hints before any write
82 put recs 0 99
83 put recs 1 2
84 if ik_arboris_send_hints 1 recs 1
85 ret 44
86 end
87 put recs 0 3
88 put recs 1 128
89 if ik_arboris_send_hints 1 recs 1
90 ret 45
91 end
92 if ik_arboris_send_hints 1 recs 4
93 ret 46
94 end
95 ret 0
96end
97
98fn ckOnlineAndLoop to int
99 ikArbResetAll
100 idsA = new uint 8 0
101 idsB = new uint 8 0
102 idsC = new uint 8 0
103 scores = new ulong 128 0
104 resident = new long 3072 -1
105 recs = new uint 16 0
106 note Train L0 -> L1 across two tokens (8 active experts each):
107 note Token 1: L0={10..17} -> L1={1..8}
108 note Token 2: L0={10,11,20..25} -> L1={1,2,30..35}
109 for k ulong 8
110 put idsA k uint add 10 k
111 put idsB k uint add 1 k
112 end
113 ikArbResetToken
114 ikArbUpdate 0 idsA
115 ikArbUpdate 1 idsB
116
117 put idsC 0 10
118 put idsC 1 11
119 for k ulong 6
120 put idsC add k 2 uint add 20 k
121 end
122 put idsB 0 1
123 put idsB 1 2
124 for k ulong 6
125 put idsB add k 2 uint add 30 k
126 end
127 ikArbResetToken
128 ikArbUpdate 0 idsC
129 ikArbUpdate 1 idsB
130
131 note Query L0={10..17}:
132 note tgt 1, 2: from 10(2) + 11(2) + 12..17(1 each = 6) = 10
133 note tgt 3..8: from 10..17(1 each) = 8
134 note tgt 30..35: from 10(1) + 11(1) = 2
135 ikArbScoreNext 0 idsA scores
136 if or ne get scores 1 10 ne get scores 2 10
137 ret 21
138 end
139 if or ne get scores 3 8 ne get scores 8 8
140 ret 22
141 end
142 if ne get scores 30 2
143 ret 23
144 end
145
146 note Mark L1 expert 1 as already resident -> PickTopK must skip 1 and pick 2 first!
147 put resident add ulong 128 1 0
148 got = ikArbPickTopK 1 scores resident part recs 0 4
149 if ne got 2
150 ret 24
151 end
152 if or ne get recs 0 3 ne get recs 1 2
153 ret 25
154 end
155 if or ne get recs 2 3 ne get recs 3 3
156 ret 26
157 end
158
159 note Verify looped core pass wrap L17 -> L6 (core_start=6, core_end=18, num_passes=3):
160 note First, confirm ikArbResetToken blocks cross-token L17 -> L6 learning.
161 for k ulong 8
162 put idsA k uint add 40 k
163 put idsB k uint add 50 k
164 put idsC k uint add 60 k
165 end
166 ikArbResetToken
167 ikArbUpdate 17 idsA
168 ikArbResetToken
169 ikArbUpdate 6 idsB
170 ikArbScoreNext 23 idsA scores
171 if ne get scores 50 0
172 ret 27
173 end
174 note Confirm L23 -> L0 (coda to stem) without reset does NOT learn transition 23.
175 ikArbResetToken
176 ikArbUpdate 23 idsA
177 ikArbUpdate 0 idsB
178 ikArbScoreNext 23 idsA scores
179 if ne get scores 50 0
180 ret 35
181 end
182 note Intra-token looped core pass wrap (passes 0/1): L17 -> L6 WITHOUT reset learns transition 23!
183 ikArbResetToken
184 ikArbUpdate 17 idsA
185 ikArbUpdate 6 idsB
186 ikArbScoreNext 23 idsA scores
187 if ne get scores 50 8
188 ret 28
189 end
190 note Transition 17 (L17 -> L18 on pass 2) must remain separate from transition 23.
191 ikArbScoreNext 17 idsA scores
192 if ne get scores 50 0
193 ret 36
194 end
195 note Now learn pass 2 exit L17 -> L18 into transition 17 with distinct targets 60..67.
196 ikArbResetToken
197 ikArbUpdate 17 idsA
198 ikArbUpdate 18 idsC
199 ikArbScoreNext 17 idsA scores
200 if or ne get scores 60 8 ne get scores 50 0
201 ret 37
202 end
203 got = ikArbPickTopK 18 scores resident part recs 0 2
204 if or ne got 1 ne get recs 1 60
205 ret 38
206 end
207 note Transition 23 must still predict L6 targets 50..57 without pollution from L18.
208 ikArbScoreNext 23 idsA scores
209 if or ne get scores 50 8 ne get scores 60 0
210 ret 39
211 end
212 got = ikArbPickTopK 6 scores resident part recs 0 2
213 if or ne got 1 ne get recs 1 50
214 ret 40
215 end
216 note Verify non-adjacent layer skip (L0 -> L5) does NOT corrupt transition 4!
217 ikArbResetToken
218 ikArbUpdate 0 idsA
219 ikArbUpdate 5 idsB
220 ikArbScoreNext 4 idsA scores
221 if ne get scores 50 0
222 ret 29
223 end
224 note Verify repeated L6 -> L6 and L0 -> L0 without reset do NOT corrupt transition 23!
225 ikArbResetToken
226 ikArbUpdate 6 idsA
227 ikArbUpdate 6 idsB
228 ikArbUpdate 0 idsA
229 ikArbUpdate 0 idsB
230 ikArbScoreNext 23 idsA scores
231 if ne get scores 50 8
232 ret 30
233 end
234 note Verify ikArbPickTopK rejects invalid nextLayer and odd outbuf
235 badRecs = new uint 3 0
236 if ne ikArbPickTopK 24 scores resident recs -1
237 ret 33
238 end
239 if ne ikArbPickTopK 1 scores resident badRecs -1
240 ret 34
241 end
242 ret 0
243end
244
245fn ckDomainShiftAndHalve to int
246 ikArbResetAll
247 ids = new uint 8 0
248 scores = new ulong 128 0
249 note Fill all 16 slots of (trans 5, src 3) with targets 10..25 (count=1 each),
250 note then observe new target 99 twice -> must replace a stale entry and score > 0.
251 for i ulong 16
252 ikArbBumpEdge 5 3 add 10 i
253 end
254 ikArbBumpEdge 5 3 99
255 ikArbBumpEdge 5 3 99
256 put ids 0 3
257 for k ulong 7
258 put ids add k 1 127
259 end
260 ikArbScoreNext 5 ids scores
261 if eq get scores 99 0
262 ret 31
263 end
264 note Test ikArbHalveRow directly on a saturated slot
265 rowBase = mul add mul ulong 6 128 4 16
266 put ikArbEdges rowBase ikArbPack 59999 77
267 ikArbBumpEdge 6 4 77
268 ent = get ikArbEdges rowBase
269 if or ne ulong shr ent 16 30000 ne ulong and ent 65535 77
270 ret 32
271 end
272 ret 0
273end
274
275fn main to int
276 rc = ckStaticHints
277 if ne rc 0
278 ret rc
279 end
280 rc = ckOnlineAndLoop
281 if ne rc 0
282 ret rc
283 end
284 rc = ckDomainShiftAndHalve
285 if ne rc 0
286 ret rc
287 end
288 ret 0
289end