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 / sparse-silicon.om

502 lines · 11559 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Native differential probe. FD3 is the issuer table. Fork before either
3note process opens RM. The producer exits after import, closing all source
4note aliases before the worker validates inputs and publishes its command.
5
6fn probe_bank to ulong
7 if eq probe_layout 4
8 ret 1
9 end
10 ret 0
11end
12
13fn probe_decay to ulong
14 if eq probe_layout 4
15 ret 0x3f4ccccd
16 end
17 ret 0x3f000000
18end
19
20fn probe_start b ulong to ulong
21 if and eq probe_layout 4 eq b 1
22 ret 126
23 end
24 if and eq probe_layout 1 eq b 1
25 ret sub probe_n 3
26 end
27 ret b
28end
29
30fn probe_seed i ulong to ulong
31 if ne probe_layout 0
32 if eq rem i probe_n probe_start div i probe_n
33 if eq probe_layout 4
34 ret 0x3f19999a
35 end
36 ret 0x3f800000
37 end
38 ret 0
39 end
40 if eq rem add rem i probe_n div div i probe_n probe_planes 3 0
41 ret 0x3f800000
42 end
43 ret 0
44end
45
46fn probe_offset row ulong to ulong
47 if eq probe_layout 4
48 if eq row 1
49 ret 0
50 end
51 ret row
52 end
53 if eq probe_layout 1
54 ret row
55 end
56 if eq probe_layout 2
57 if lt row sub probe_n 1
58 ret 0
59 end
60 if eq row probe_n
61 ret probe_n
62 end
63 ret 64
64 end
65 ret mul div row 2 2
66end
67
68fn probe_source arc ulong to ulong
69 if and or eq probe_layout 1 eq probe_layout 4 ne arc 0
70 ret sub arc 1
71 end
72 ret arc
73end
74
75fn probe_fill m view ulong 16 i ulong tok long to bool
76 if eq i 0
77 for j ulong 16
78 if ne mapset tok mul j 8 8 get m j 0
79 ret false
80 end
81 end
82 end
83 if eq i 1
84 if ne mapset tok 0 4 0x41525431 0
85 ret false
86 end
87 if or ne mapset tok 4 4 probe_n 0 ne mapset tok 8 4 probe_n 0
88 ret false
89 end
90 for j ulong add probe_n 1
91 if ne mapset tok add 12 mul j 4 4 probe_offset j 0
92 ret false
93 end
94 end
95 off = mul add probe_n 4 4
96 for j ulong probe_n
97 if ne mapset tok add off mul j 4 4 probe_source j 0
98 ret false
99 end
100 end
101 end
102 if eq i 2
103 for j ulong probe_n
104 weight = ulong 0x3f000000
105 if ne and j 1 0
106 weight = ulong 0x3f400000
107 end
108 if ne probe_layout 0
109 weight = ulong 0x3f800000
110 end
111 if eq probe_layout 4
112 weight = ulong 0x3f333333
113 end
114 if ne mapset tok mul j 4 4 weight 0
115 ret false
116 end
117 end
118 end
119 if eq i add 3 probe_bank
120 for j ulong mul mul probe_n probe_batch probe_planes
121 if ne mapset tok mul j 4 4 probe_seed j 0
122 ret false
123 end
124 end
125 end
126 ret true
127end
128
129fn probe_match probe_scores view uint * words ulong to int
130 tok = get ar_maps sub ulong 4 probe_bank
131 base = add 4 mul words ulong get probe_scores 1
132 for i ulong words
133 if ne get probe_scores add base i uint mapget tok mul i 4 4
134 ret 31
135 end
136 end
137 probe_log ps_words words
138 ret 0
139end
140
141text pb_queries "measured_queries="
142text pb_elapsed "measured_query_ns="
143note The timing supervisor measures only between the ready/go and done bytes
144note on private FD14/FD13. Inputs, code and queries are resident by then.
145fn pb_sync begin bool to bool
146 signalbuf = new uchar 1 1
147 if ne write 14 signalbuf 0 1 1
148 ret false
149 end
150 if begin
151 ret eq read 13 signalbuf 0 1 1
152 end
153 ret true
154end
155
156fn pb_iteration topo view uint * weights view uint * scores edit uint * to int
157 put scores 1 0
158 if gt probe_hops 1
159 for i ulong mul probe_n probe_batch
160 put scores add i 4 uint probe_seed i
161 end
162 end
163 if eq probe_planes 1
164 for hop ulong probe_hops
165 if ne arboris_relax_step topo weights scores 0
166 ret 51
167 end
168 end
169 else
170 if ne arboris_spread_step topo weights scores 0
171 ret 51
172 end
173 end
174 ret 0
175end
176
177fn pb_cpu topo view uint * weights view uint * scores edit uint * to int
178 if not pb_sync true
179 ret 50
180 end
181 start = monons
182 now = start
183 queries = ulong 0
184 while lt sub now start 8000000000 bound 0xffffffff
185 if ne pb_iteration topo weights scores 0
186 ret 51
187 end
188 queries = add queries 1
189 now = monons
190 end
191 if not pb_sync false
192 ret 52
193 end
194 probe_log pb_queries queries
195 probe_log pb_elapsed ulong sub now start
196 ret 0
197end
198
199note Each benchmark iteration is an independent read-only query from the same
200note input bank. Discard its fenced output after the timing sample. No epoch
201note is committed, and no production caller gains this fixture-only operation.
202fn pb_discard m view ulong 16 to bool
203 if not ar_snapshot_matches m
204 ret false
205 end
206 seq = get ar_fenced_seq 0
207 if or ne get nvret 0 seq ne get nvput 0 seq
208 ret false
209 end
210 if not ar_device_receipt get ar_maps 5 seq
211 ret false
212 end
213 put ar_fenced_seq 0 0
214 ar_drop_compute
215 ret true
216end
217
218text pb_seq "submitted_seq="
219text pb_retired "retired_seq="
220text pb_receipt_seq "receipt_seq="
221text pb_receipt_status "receipt_status="
222text pb_wfi "wfi_marker="
223text pb_flushed "flush_marker="
224text pb_final "completion_marker="
225text pb_qmd "qmd_semaphore="
226fn pb_failure reason ulong queries ulong to void
227 probe_log ps_rc reason
228 probe_log pb_queries queries
229 probe_log pb_seq get nvput 0
230 probe_log pb_retired get nvret 0
231 probe_log pb_receipt_seq mapget get ar_maps 5 48 8
232 probe_log pb_receipt_status mapget get ar_maps 5 56 8
233 probe_log pb_wfi mapget get gbmem 3 0 4
234 probe_log pb_flushed mapget get gbmem 3 16 4
235 probe_log pb_final mapget get gbmem 3 32 4
236 probe_log pb_qmd mapget get gbmem 2 8192 4
237end
238
239fn pb_gpu table long h view ulong 2 m view ulong 16 to int
240 if not pb_sync true
241 ret 50
242 end
243 start = monons
244 now = start
245 queries = ulong 0
246 while lt sub now start 8000000000 bound 0xffffffff
247 if not pb_discard m
248 ret 53
249 end
250 reason = probe_execute_sparse table h m
251 if ne reason 0
252 pb_failure reason queries
253 ret 54
254 end
255 queries = add queries 1
256 now = monons
257 end
258 if not pb_sync false
259 ret 52
260 end
261 probe_log pb_queries queries
262 probe_log pb_elapsed ulong sub now start
263 ret 0
264end
265
266fn probe_copy_seeds scores edit uint * words ulong to void
267 tok = get ar_maps add 3 probe_bank
268 base = add 4 mul words probe_bank
269 for i ulong words
270 put scores add base i uint mapget tok mul i 4 4
271 end
272end
273
274fn probe_expected probe_topo view uint * probe_weights view uint * to int
275 probe_scores = new uint 800004 0
276 put probe_scores 0 uint probe_batch
277 put probe_scores 1 uint probe_bank
278 put probe_scores 2 uint probe_decay
279 words = mul mul probe_n probe_batch probe_planes
280 probe_copy_seeds probe_scores words
281 start = monons
282 result = ulong 1
283 if eq probe_planes 1
284 for hop ulong probe_hops
285 result = arboris_relax_step probe_topo probe_weights part probe_scores 0 add 4 mul words 2
286 if ne result 0
287 ret 30
288 end
289 end
290 else
291 result = arboris_spread_step probe_topo probe_weights part probe_scores 0 add 4 mul words 2
292 end
293 if ne result 0
294 ret 30
295 end
296 elapsed = sub monons start
297 probe_log ps_cpu ulong elapsed
298 if eq get ps_signed 0 4
299 if ne pb_cpu probe_topo probe_weights part probe_scores 0 add 4 mul words 2 0
300 ret 55
301 end
302 end
303 ret probe_match probe_scores words
304end
305
306fn probe_compare to int
307 probe_topo = new uint 200004 0
308 probe_weights = new uint 100000 0
309 nt = add 4 mul probe_n 2
310 for i ulong nt
311 put probe_topo i uint mapget get ar_maps 1 mul i 4 4
312 end
313 for i ulong probe_n
314 put probe_weights i uint mapget get ar_maps 2 mul i 4 4
315 end
316 ret probe_expected part probe_topo 0 nt part probe_weights 0 probe_n
317end
318
319fn probe_open_sparse m view ulong 16 to bool
320 if eq probe_layout 4
321 if not ar_open_query m probe_n 3
322 ret false
323 end
324 put ar_query_variant 0 probe_n
325 put ar_query_variant 1 probe_hops
326 ret ar_bind_sparse_code m
327 end
328 if eq probe_layout 1
329 ret ar_open_query m probe_n probe_hops
330 end
331 if eq probe_layout 2
332 ret ar_open_query m sub probe_n 2 1
333 end
334 ret ar_step_open m
335end
336
337fn probe_execute_sparse table long h view ulong 2 meta view ulong 16 to ulong
338 if eq probe_layout 0
339 ret ar_sparse_hop table 42 h meta 0x3f000000 0
340 end
341 spec = new ulong 3 0
342 put spec 0 probe_n
343 if eq probe_layout 2
344 put spec 0 sub probe_n 2
345 end
346 put spec 1 probe_hops
347 put spec 2 probe_decay
348 ret ar_sparse_query table 42 h meta spec
349end
350
351fn probe_run table long h view ulong 2 meta edit ulong 16 to int
352 offsets = new ulong 6 0
353 if ne arboris_plan_sparse meta 0x10000000 4096 offsets 0
354 ret 1
355 end
356 if not caproot_validate table 42 h meta
357 ret 2
358 end
359 rc = probe_import meta offsets
360 if ne rc 0
361 ret rc
362 end
363 if not probe_open_sparse meta
364 ret 22
365 end
366 if not probe_arm_signer table meta h probe_decay
367 ret 47
368 end
369 start = monons
370 hop = probe_execute_sparse table h meta
371 elapsed = sub monons start
372 probe_log ps_rc hop
373 if ne hop 0
374 ret 23
375 end
376 probe_log ps_gpu ulong elapsed
377 if eq get ps_signed 0 3
378 rc = pb_gpu table h meta
379 if ne rc 0
380 ret rc
381 end
382 end
383 rc = probe_compare
384 if ne rc 0
385 ret rc
386 end
387 hashes = new uchar 96 0
388 if not ar_step_digests meta get nvret 0 hashes
389 ret 35
390 end
391 probe_digest ps_input part hashes 0 32
392 probe_digest ps_code part hashes 32 32
393 probe_digest ps_output part hashes 64 32
394 if not probe_witness table meta h
395 ret 39
396 end
397 ret 0
398end
399
400fn probe_model_meta m edit ulong 16 to void
401 put m 0 arboris_sparse_magic
402 put m 1 probe_n
403 put m 2 probe_batch
404 put m 3 probe_n
405 put m 4 probe_planes
406 put m 6 probe_bank
407end
408
409note Independent closed-form fixture with empty rows and two incoming arcs on
410note odd destinations. Weights and seeds are dyadic, so no floating oracle
411note shares the rounding or traversal implementation being checked.
412fn probe_golden v ulong b ulong plane ulong to ulong
413 if eq probe_layout 4
414 first = probe_start b
415 if or lt v first gt v add first probe_hops
416 ret 0
417 end
418 score = f32of 0x3f19999a
419 factor = mul f32of 0x3f333333 f32of probe_decay
420 for distance ulong sub v first bound 2
421 score = mul score factor
422 end
423 ret bitsof score
424 end
425 if ne probe_layout 0
426 b = probe_start b
427 if eq v b
428 ret 0x3f800000
429 end
430 if eq probe_layout 1
431 if and gt v b le v add b probe_hops
432 ret sub 0x3f800000 shl sub v b 23
433 end
434 else
435 if eq v sub probe_n 2
436 ret 0x3f000000
437 end
438 end
439 ret 0
440 end
441 raw = ulong 0
442 discounted = ulong 0
443 if ne and v 1 0
444 if eq rem add sub v 1 b 3 0
445 raw = ulong 0x3f000000
446 discounted = ulong 0x3e800000
447 end
448 if eq rem add v b 3 0
449 raw = ulong 0x3f400000
450 discounted = ulong 0x3ec00000
451 end
452 end
453 if and eq probe_planes 2 eq plane 0
454 ret raw
455 end
456 if eq rem add v b 3 0
457 ret 0x3f800000
458 end
459 ret discounted
460end
461
462fn probe_reference to int
463 m = new ulong 16 0
464 offsets = new ulong 6 0
465 probe_model_meta m
466 if ne arboris_plan_sparse m 0x10000000 4096 offsets 0
467 ret 40
468 end
469 for i ulong 6
470 size = ar_region_bytes m offsets i
471 tok = mapnew neg int 1 0 size 3 34
472 if le tok 0
473 ret 41
474 end
475 put ar_maps i tok
476 if not probe_fill m i tok
477 ret 42
478 end
479 end
480 dest = get ar_maps sub ulong 4 probe_bank
481 cells = div get m 11 4
482 for i ulong cells
483 row = div i probe_n
484 score = probe_golden rem i probe_n div row probe_planes rem row probe_planes
485 if ne mapset dest mul i 4 4 score 0
486 ret 43
487 end
488 end
489 rc = probe_compare
490 if ne rc 0
491 ret rc
492 end
493 ctx = new ulong 40 0
494 hash = new uchar 32 0
495 sha256_init ctx
496 if not ar_hash_mapping ctx dest get m 11
497 ret 44
498 end
499 sha256_final ctx hash
500 probe_digest ps_output hash
501 ret 0
502end