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 / tests / arboris / gated-silicon.om

404 lines · 9560 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Four standard somas (including one empty) and one four-warp hub. Both
3note paths encounter ordered child compartments, signed inputs and sigmoid.
4text ps_halves "matching_fp16_elements="
5text ps_mismatch "first_mismatching_pair="
6text ps_expected "expected_pair="
7text ps_actual "actual_pair="
8fn probe_model_meta m edit ulong 16 to void
9 put m 0 arboris_magic
10 put m 1 5
11 put m 2 9
12 put m 3 9
13 put m 4 probe_dim
14 put m 5 4
15 put m 10 mul 56 probe_dim
16 if eq probe_layout 3
17 put m 10 arboris_q4_bytes m
18 end
19end
20
21fn gated_topology words edit uint 34 to void
22 put words 1 3
23 put words 2 3
24 put words 3 4
25 put words 4 5
26 put words 5 9
27 for i ulong 10
28 put words add i 6 uint i
29 end
30 put words 8 1
31 for i ulong 9
32 put words add i 16 uint rem i 5
33 end
34 put words 26 0x1000000
35 put words 27 0x1000000
36 put words 28 2
37 put words 29 3
38 put words 30 4
39 put words 31 0x1000004
40 put words 32 0x2000004
41 put words 33 4
42end
43
44fn gv_test_half i ulong slab ulong to ulong
45 if eq slab 3
46 if eq rem i 3 0
47 ret 0xb800
48 end
49 ret 0x3800
50 end
51 row = div i probe_dim
52 if eq probe_layout 3
53 if lt row 9
54 if lt i 32
55 ret 0
56 end
57 if lt i 64
58 if eq and i 1 0
59 ret 0x3700
60 end
61 ret 0xb700
62 end
63 if eq and i 3 0
64 ret 0x3b00
65 end
66 if eq and i 3 1
67 ret 0xb500
68 end
69 ret 0x3700
70 end
71 if and ge row 18 lt row 23
72 if eq rem i 5 0
73 ret 0x5140
74 end
75 if eq rem i 5 1
76 ret 0x4f80
77 end
78 if eq rem i 5 2
79 ret 0x4780
80 end
81 end
82 end
83 if lt row 9
84 ret 0x3800
85 end
86 if lt row 18
87 if eq rem i 3 0
88 ret 0xb400
89 end
90 ret 0x3800
91 end
92 ret 0x3c00
93end
94
95fn gv_fill_packed m view ulong 16 tok long to bool
96 src = new ushort 7392 0
97 packed = new uint 3700 0
98 for j ulong mul 28 probe_dim
99 put src j ushort gv_test_half j 2
100 end
101 words = div get m 10 4
102 if not arboris_pack_q4_params m part src 0 mul 28 probe_dim part packed 0 words
103 ret false
104 end
105 for j ulong words
106 if ne mapset tok mul j 4 4 ulong get packed j 0
107 ret false
108 end
109 end
110 ret true
111end
112
113fn probe_fill m view ulong 16 i ulong tok long to bool
114 csr = new uint 34 0
115 if eq i 0
116 for j ulong 16
117 if ne mapset tok mul j 8 8 get m j 0
118 ret false
119 end
120 end
121 end
122 if eq i 1
123 gated_topology csr
124 for j ulong len csr
125 if ne mapset tok mul j 4 4 ulong get csr j 0
126 ret false
127 end
128 end
129 end
130 if and eq probe_layout 3 eq i 2
131 ret gv_fill_packed m tok
132 end
133 if or eq i 2 eq i 3
134 pairs = mul 14 probe_dim
135 if eq i 3
136 pairs = div mul 5 probe_dim 2
137 end
138 for j ulong pairs
139 low = gv_test_half mul j 2 i
140 high = gv_test_half add mul j 2 1 i
141 if ne mapset tok mul j 4 4 or low shl high 16 0
142 ret false
143 end
144 end
145 end
146 ret true
147end
148
149fn gv_copy_extent storage edit ushort * tok long base ulong words ulong to void
150 for j ulong words bound 4096
151 value = mapget tok mul j 4 4
152 off = add base mul j 2
153 put storage off ushort and value 65535
154 put storage add off 1 ushort shr value 16
155 end
156end
157
158fn gv_expected m view ulong 16 offsets view ulong 6 expected edit ushort 1320 to int
159 storage = new ushort 28672 0
160 if lt mul len storage 2 get m 12
161 ret 36
162 end
163 for i ulong 4
164 words = div ar_region_bytes m offsets i 4
165 base = div get offsets i 2
166 gv_copy_extent storage get ar_maps i base words
167 end
168 if ne arboris_gated_tick m offsets part storage 0 div get m 12 2 4096 0
169 ret 37
170 end
171 for i ulong mul 5 probe_dim
172 put expected i get storage add div get offsets 4 2 i
173 end
174 ret 0
175end
176
177note Independent fixture: block peak 7/8 makes quantization step 1/8.
178note Both ties (-2.5, 3.5) round to even. Rebuild the canonical input
179note separately, then compare each output with exact and experimental math.
180fn gv_exact_fixture storage edit ushort * desc view ulong 16 exact edit ushort 1320 to void
181 for i ulong mul 28 probe_dim
182 put storage add get desc 9 i ushort gv_test_half i 2
183 end
184 for i ulong mul 5 probe_dim
185 put storage add get desc 13 i ushort gv_test_half i 3
186 end
187 for i ulong mul 5 probe_dim
188 put exact i ushort ag_coordinate storage desc div i probe_dim rem i probe_dim
189 end
190end
191
192fn gv_quant_coordinate storage view ushort * desc view ulong 16 i ulong coeff view uint 64 to ushort
193 soma = div i probe_dim
194 dim = rem i probe_dim
195 prev = ag_load storage desc 13 soma dim
196 g = arboris_cubic_gate mul prev ag_load storage desc 11 soma dim coeff
197 val = fmax f32 0 mul ag_sum storage desc soma dim ag_load storage desc 12 soma dim
198 ret ushort narrow bitsof fma g val mul sub f32 1 g prev 10 15 31
199end
200
201fn gv_quant_fixture storage edit ushort * desc view ulong 16 approx edit ushort 1320 to void
202 coeff = new uint 64 0
203 arboris_cubic_table coeff
204 for i ulong mul 9 probe_dim
205 k = and i 3
206 if and ge i 64 ne k 0
207 bits = ushort 0x3800
208 if eq k 1
209 bits = ushort 0xb400
210 end
211 put storage add get desc 9 i bits
212 end
213 end
214 for i ulong mul 5 probe_dim
215 put approx i gv_quant_coordinate storage desc i coeff
216 end
217end
218
219fn gv_profile_reference m view ulong 16 exact edit ushort 1320 approx edit ushort 1320 to bool
220 fp = new ulong 16 0
221 off = new ulong 6 0
222 desc = new ulong 16 0
223 storage = new ushort 28672 0
224 for i ulong 16
225 put fp i get m i
226 end
227 put fp 10 mul 56 probe_dim
228 if ne arboris_plan_arena fp 1048576 4096 off 0
229 ret false
230 end
231 if not ag_layout fp off div get fp 12 2 4096 desc
232 ret false
233 end
234 gv_copy_extent storage get ar_maps 1 div get off 1 2 34
235 gv_exact_fixture storage desc exact
236 gv_quant_fixture storage desc approx
237 ret true
238end
239
240text gv_changed "changed_fp16_elements="
241text gv_error "max_abs_error_fp32_bits="
242fn gv_result_half i ulong to ulong
243 word = mapget get ar_maps 4 mul div i 2 4 4
244 ret and shr word mul and i 1 16 65535
245end
246fn gv_check_profile m view ulong 16 to int
247 exact = new ushort 1320 0
248 approx = new ushort 1320 0
249 if not gv_profile_reference m exact approx
250 ret 36
251 end
252 changed = ulong 0
253 worst = f32 0
254 for i ulong mul 5 probe_dim
255 half = gv_result_half i
256 if ne half ulong get approx i
257 probe_log ps_mismatch i
258 probe_log ps_expected ulong get approx i
259 probe_log ps_actual half
260 ret 38
261 end
262 if ne half ulong get exact i
263 changed = add changed 1
264 worst = fmax worst fabs sub f32of f16to32 half f32of f16to32 ulong get exact i
265 end
266 end
267 probe_log ps_halves mul 5 probe_dim
268 probe_log gv_changed changed
269 probe_log gv_error bitsof worst
270 ret 0
271end
272
273fn gv_check_output m view ulong 16 offsets view ulong 6 to int
274 if eq probe_layout 3
275 ret gv_check_profile m
276 end
277 ref = new ushort 1320 0
278 rc = gv_expected m offsets ref
279 if ne rc 0
280 ret rc
281 end
282 for i ulong div mul 5 probe_dim 2
283 actual = mapget get ar_maps 4 mul i 4 4
284 expected = ag_u32 ref 0 i
285 if ne expected actual
286 probe_log ps_mismatch i
287 probe_log ps_expected expected
288 probe_log ps_actual actual
289 ret 38
290 end
291 end
292 probe_log ps_halves mul 5 probe_dim
293 ret 0
294end
295
296
297fn probe_run table long h view ulong 2 m edit ulong 16 to int
298 offsets = new ulong 6 0
299 if ne arboris_plan_arena m 1048576 4096 offsets 0
300 ret 1
301 end
302 if not caproot_validate table 42 h m
303 ret 2
304 end
305 rc = probe_import m offsets
306 if ne rc 0
307 ret rc
308 end
309 if not ar_gated_open_profile m 4 eq probe_layout 3
310 ret 22
311 end
312 if not probe_arm_signer table m h 0
313 ret 47
314 end
315 hop = ar_gated_profile_hop table 42 h m eq probe_layout 3
316 probe_log ps_rc hop
317 if ne hop 0
318 ret 23
319 end
320 rc = gv_check_output m offsets
321 if ne rc 0
322 ret rc
323 end
324 hashes = new uchar 96 0
325 if not ar_step_digests m get nvret 0 hashes
326 ret 35
327 end
328 probe_digest ps_input part hashes 0 32
329 probe_digest ps_code part hashes 32 32
330 probe_digest ps_output part hashes 64 32
331 if not probe_witness table m h
332 ret 39
333 end
334 ret 0
335end
336
337fn gv_print_reference ref view ushort 1320 to void
338 data = new uchar 2640 0
339 for i ulong mul 5 probe_dim
340 put data mul i 2 uchar and get ref i 255
341 put data add mul i 2 1 uchar shr get ref i 8
342 end
343 ctx = new ulong 40 0
344 hash = new uchar 32 0
345 sha256_init ctx
346 sha256_update ctx part data 0 mul 10 probe_dim
347 sha256_final ctx hash
348 probe_digest ps_output hash
349end
350
351note Host preflight over anonymous CPU mappings. Exercise both scheduling
352note ranges, a malformed parent depth and an undersized shared memory budget.
353fn probe_reference to int
354 m = new ulong 16 0
355 offsets = new ulong 6 0
356 probe_model_meta m
357 if ne arboris_plan_arena m 1048576 4096 offsets 0
358 ret 40
359 end
360 for i ulong 6
361 tok = mapnew neg int 1 0 ar_region_bytes m offsets i 3 34
362 if le tok 0
363 ret 41
364 end
365 put ar_maps i tok
366 if not probe_fill m i tok
367 ret 42
368 end
369 end
370 if not ar_gv_rows m 4
371 ret 43
372 end
373 saved = get m 13
374 put m 13 32
375 if ar_gv_rows m 4
376 ret 44
377 end
378 put m 13 saved
379 changed = mapset get ar_maps 1 104 4 0x2000000
380 if ar_gv_rows m 4
381 ret 45
382 end
383 changed = mapset get ar_maps 1 104 4 0x1000000
384 ref = new ushort 1320 0
385 exact = new ushort 1320 0
386 rc = int 0
387 if eq probe_layout 3
388 if not gv_profile_reference m exact ref
389 ret 36
390 end
391 else
392 rc = gv_expected m offsets ref
393 end
394 if ne rc 0
395 ret rc
396 end
397 gv_print_reference ref
398 for i ulong 6
399 if ne mapdrop get ar_maps i 0
400 ret 46
401 end
402 end
403 ret 0
404end