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 / spread_v2_silicon.om

633 lines · 15182 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Pure OM-2 GB10 silicon differential parity & benchmark harness for Arboris 5-region spreading activation.
3note Tests BOTH Mode 0 (B=1) and Mode 1 (B=32, B=37, B=64) across:
4note - Fixed-hop single-submit NVRM command list (zero host round-trip per hop)
5note - Early-exit convergence loop (checking SpreadReceipt.changed_count == 0 in coherent UVM)
6note - Isolated nodes, high-degree hubs, cycles with hop decay, early convergence before max_hops
7note - Bit-exact differential parity (0 word mismatches) against om/arboris_spread_cpu.om
8note - End-to-end CPU OM-2 vs GB10 latency benchmarks (~10K edges to ~100K edges, B=1..64)
9
10global sp_slabs long 5
11global sp_guards long 4
12global sp_hdr ulong 16
13global sp_offs ulong 5
14global sp_msz ulong 5
15global sp_rcpt ulong 8
16global sp_vas ulong 10
17global sp_drv uint 224
18global sp_bank uint 240
19global sp_q0 uint 96
20global sp_q1 uint 96
21global sp_code0 uchar 16384
22global sp_code1 uchar 16384
23note Static CPU buffers (zero heap): max V=16384, E=98304, max state = 4096*64*2 = 524288 u32 words (2 MiB)
24global sp_cpu_csr uint 262144
25global sp_cpu_state uint 524288
26global sp_outbuf uchar 256
27
28fn sp_putc c uchar to void
29 put sp_outbuf 0 c
30 unused = write 1 sp_outbuf 0 1
31end
32
33fn sp_putu v ulong to void
34 buf = new uchar 24 0
35 if eq v 0
36 sp_putc 48
37 ret
38 end
39 n = ulong 0
40 x = v
41 while gt x 0 bound 24
42 put buf n uchar add 48 rem x 10
43 x = div x 10
44 n = add n 1
45 end
46 while gt n 0 bound 24
47 n = sub n 1
48 sp_putc get buf n
49 end
50end
51
52fn sp_puts_tag a uchar b uchar c uchar d uchar to void
53 put sp_outbuf 0 a
54 put sp_outbuf 1 b
55 put sp_outbuf 2 c
56 put sp_outbuf 3 d
57 put sp_outbuf 4 32
58 unused = write 1 sp_outbuf 0 5
59end
60
61fn sp_print_line tag0 uchar tag1 uchar tag2 uchar tag3 uchar v0 ulong v1 ulong to void
62 sp_puts_tag tag0 tag1 tag2 tag3
63 sp_putu v0
64 sp_putc 32
65 sp_putu v1
66 sp_putc 10
67end
68
69fn sp_open_gpu to bool
70 if not nvfull
71 ret false
72 end
73 if not nvchan
74 ret false
75 end
76 c = new uchar 16384 0
77 note gbmem[0]=cmd(64K), [1]=cbank(16K), [2]=qmd+sem+scratch(128K), [3]=mark(4K), [4]=code0..3(16K), [5]=spare(4K)
78 sizes = new ulong 6 0
79 put sizes 0 65536
80 put sizes 1 16384
81 put sizes 2 131072
82 put sizes 3 4096
83 put sizes 4 16384
84 put sizes 5 4096
85 for i ulong 6
86 tok = nvalloc get sizes i false
87 if le tok 0
88 ret false
89 end
90 put gbmem i tok
91 end
92 sz = bw_arboris_spread_emit_mode0 c
93 if or eq sz 0 ne mapwrite get gbmem 4 0 c 0 sz long sz
94 ret false
95 end
96 sz = bw_arboris_spread_emit_mode1 c
97 if or eq sz 0 ne mapwrite get gbmem 4 4096 c 0 sz long sz
98 ret false
99 end
100 sz = bw_arboris_spread_emit_mode2 c
101 if or eq sz 0 ne mapwrite get gbmem 4 8192 c 0 sz long sz
102 ret false
103 end
104 sz = bw_arboris_spread_emit_mode3 c
105 if or eq sz 0 ne mapwrite get gbmem 4 12288 c 0 sz long sz
106 ret false
107 end
108 ret true
109end
110
111fn sp_free_arena to void
112 for j ulong 5
113 i = sub ulong 4 j
114 tok = get sp_slabs i
115 if gt tok 0
116 unused = nvdrop tok
117 put sp_slabs i 0
118 end
119 end
120 for j ulong 4
121 g = get sp_guards j
122 if gt g 0
123 unused = mapdrop g
124 put sp_guards j 0
125 end
126 end
127end
128
129fn sp_alloc_arena to bool
130 sp_free_arena
131 for i ulong 5
132 tok = nvalloc get sp_msz i false
133 if le tok 0
134 sp_free_arena
135 ret false
136 end
137 put sp_slabs i tok
138 if lt i 4
139 va = get nvnext 0
140 g = maphold va 4096
141 if le g 0
142 sp_free_arena
143 ret false
144 end
145 put sp_guards i g
146 put nvnext 0 add va 4096
147 end
148 end
149 for k ulong 16
150 if ne mapset get sp_slabs 0 mul k 8 8 get sp_hdr k 0
151 ret false
152 end
153 end
154 ret true
155end
156
157note Build deterministic test graph directly into sp_cpu_csr (Slab 1 format):
158note kind=0: V=256, E=768 (isolated nodes 0..7, hub node 8 with in-deg 64, cycles + forward chains)
159note kind=1: scalable graph with V nodes, 6 incoming edges per non-isolated node (for benchmarks).
160fn sp_build_graph v_cnt ulong deg ulong to ulong
161 note Plan header first to get off_in_src and off_in_weight
162 e_cnt = ulong 0
163 for v ulong v_cnt bound 65536
164 put sp_cpu_csr v uint e_cnt
165 if ge v 8
166 if and eq v 8 ge v_cnt 128
167 e_cnt = add e_cnt 64
168 else
169 e_cnt = add e_cnt deg
170 end
171 end
172 end
173 put sp_cpu_csr v_cnt uint e_cnt
174 ret e_cnt
175end
176
177fn sp_edge_weight v ulong k ulong to uint
178 sel = and add v k 3
179 if eq sel 1
180 ret 0x3f000000
181 end
182 if eq sel 2
183 ret 0x3f400000
184 end
185 if eq sel 3
186 ret 0x3f600000
187 end
188 ret 0x3e800000
189end
190
191fn sp_fill_node_edges v ulong cnt ulong e_start ulong v_cnt ulong to ulong
192 e = e_start
193 for k ulong cnt bound 64
194 t = add mul v 7 mul k 13
195 u = rem add t 3 v_cnt
196 if eq u v
197 u = rem add v 1 v_cnt
198 end
199 idx = add div get sp_hdr 11 4 e
200 put sp_cpu_csr idx uint u
201 widx = add div get sp_hdr 12 4 e
202 w = sp_edge_weight v k
203 put sp_cpu_csr widx w
204 e = add e 1
205 end
206 ret e
207end
208
209fn sp_fill_edges v_cnt ulong deg ulong to void
210 e = ulong 0
211 for v ulong v_cnt bound 65536
212 if ge v 8
213 cnt = deg
214 if and eq v 8 ge v_cnt 128
215 cnt = ulong 64
216 end
217 e = sp_fill_node_edges v cnt e v_cnt
218 end
219 end
220end
221
222fn sp_init_seeds v_cnt ulong batch ulong stride ulong to void
223 plane = mul v_cnt stride
224 for i ulong mul plane 2 bound 524288
225 put sp_cpu_state i 0
226 end
227 for b ulong batch bound 65535
228 note Distinct seed nodes per batch element (avoid isolated 0..7)
229 s0 = add 8 rem mul b 11 sub v_cnt 8
230 s1 = add 8 rem add mul b 17 5 sub v_cnt 8
231 put sp_cpu_state add mul s0 stride b 0x3f800000
232 put sp_cpu_state add mul s1 stride b 0x3f400000
233 end
234end
235
236fn sp_upload_arena to bool
237 csr_words = div add get sp_hdr 12 sub get sp_hdr 12 get sp_hdr 11 4
238 for i ulong csr_words bound 262144
239 if ne mapset get sp_slabs 1 mul i 4 4 ulong get sp_cpu_csr i 0
240 ret false
241 end
242 end
243 plane = mul get sp_hdr 1 get sp_hdr 4
244 for i ulong plane bound 262144
245 if ne mapset get sp_slabs 2 mul i 4 4 ulong get sp_cpu_state i 0
246 ret false
247 end
248 if ne mapset get sp_slabs 3 mul i 4 4 0 0
249 ret false
250 end
251 end
252 for k ulong 8
253 if ne mapset get sp_slabs 4 mul k 8 8 0 0
254 ret false
255 end
256 end
257 ret true
258end
259
260fn sp_pack_hop_local cb_va ulong to bool
261 hdr = new ulong 16 0
262 vas = new ulong 10 0
263 drv = new uint 224 0
264 bank = new uint 240 0
265 q0 = new uint 96 0
266 q1 = new uint 96 0
267 for i ulong 16
268 put hdr i get sp_hdr i
269 end
270 for i ulong 10
271 put vas i get sp_vas i
272 end
273 gbdriver cb_va
274 for i ulong 224
275 put drv i get gbcb i
276 end
277 if ne bw_arboris_spread_pack_qmd hdr vas drv bank q0 q1 0
278 ret false
279 end
280 for i ulong 240
281 put sp_bank i get bank i
282 end
283 for i ulong 96
284 put gbq0 i get q0 i
285 put gbq1 i get q1 i
286 end
287 ret true
288end
289
290fn sp_emit_one_hop hop ulong to bool
291 mode = get sp_hdr 7
292 cb_va = add mapaddr get gbmem 1 mul hop 1024
293 q_base = mapaddr get gbmem 2
294 q0_va = add q_base mul hop 512
295 q1_va = add add q_base 4096 mul hop 512
296 sem_va = add add q_base 8192 mul hop 64
297 put sp_vas 0 add mapaddr get gbmem 4 mul mode 4096
298 put sp_vas 1 cb_va
299 put sp_vas 2 add q_base 16384
300 put sp_vas 3 sem_va
301 put sp_vas 4 q0_va
302 put sp_vas 5 q1_va
303 put sp_vas 6 mapaddr get sp_slabs 1
304 put sp_vas 7 mapaddr get sp_slabs 2
305 put sp_vas 8 mapaddr get sp_slabs 3
306 put sp_vas 9 mapaddr get sp_slabs 4
307
308 if not sp_pack_hop_local cb_va
309 ret false
310 end
311 gbdma cb_va 224
312 for i ulong 224
313 gbemit get sp_bank i
314 end
315 gbdma add cb_va 896 16
316 for i ulong 16
317 gbemit get sp_bank add 224 i
318 end
319 gbinline q0_va false
320 gbdma sem_va 1
321 gbemit 1
322 gbinline q1_va true
323 ret true
324end
325
326fn sp_submit_and_wait to bool
327 mark = get gbmem 3
328 if ne mapset mark 0 4 0 0
329 ret false
330 end
331 if ne mapset mark 16 4 0 0
332 ret false
333 end
334 bytes = get gbused 0
335 if ne mapwrite get gbmem 0 0 gbcmd 0 bytes long bytes
336 ret false
337 end
338 if not nvsend get gbmem 0 0 uint div bytes 4
339 ret false
340 end
341 if not nvwait mark 16 1179010630 5000000000
342 ret false
343 end
344 ret eq mapget mark 0 4 1145324612
345end
346
347note Path 1: Fixed-hop single-submit NVRM command list (zero host round-trip per hop).
348fn sp_gpu_run_fixed hops ulong to bool
349 put gbused 0 0
350 gbsetup
351 mark = mapaddr get gbmem 3
352 for h ulong hops bound 16
353 if not sp_emit_one_hop h
354 ret false
355 end
356 gbrel add mark 32 uint add 1 h
357 gbflush
358 next_b = xor get sp_hdr 8 1
359 put sp_hdr 8 next_b
360 end
361 gbtail
362 ret sp_submit_and_wait
363end
364
365note Path 2: Early-exit convergence loop checking SpreadReceipt.changed_count == 0 in coherent UVM.
366fn sp_gpu_run_early max_hops ulong to ulong
367 for h ulong max_hops bound 64
368 if ne mapset get sp_slabs 4 0 8 0 0
369 ret 999
370 end
371 put gbused 0 0
372 gbsetup
373 if not sp_emit_one_hop 0
374 ret 999
375 end
376 gbtail
377 if not sp_submit_and_wait
378 ret 999
379 end
380 changed = mapget get sp_slabs 4 0 8
381 next_b = xor get sp_hdr 8 1
382 put sp_hdr 8 next_b
383 if eq changed 0
384 ret add h 1
385 end
386 end
387 ret max_hops
388end
389
390fn sp_compare_bank bank ulong plane ulong to ulong
391 slab = get sp_slabs add 2 bank
392 cpu_base = mul bank plane
393 bad = ulong 0
394 for i ulong plane bound 262144
395 gv = uint mapget slab mul i 4 4
396 cv = get sp_cpu_state add cpu_base i
397 if ne gv cv
398 if lt bad 4
399 sp_print_line 77 73 83 77 i ulong gv
400 sp_print_line 67 80 85 86 i ulong cv
401 end
402 bad = add bad 1
403 end
404 end
405 ret bad
406end
407
408fn sp_plan_local to bool
409 hdr = new ulong 16 0
410 offs = new ulong 5 0
411 msz = new ulong 5 0
412 for i ulong 16
413 put hdr i get sp_hdr i
414 end
415 if ne arboris_spread_plan hdr 0x40000000 4096 offs msz 0
416 ret false
417 end
418 for i ulong 16
419 put sp_hdr i get hdr i
420 end
421 for i ulong 5
422 put sp_offs i get offs i
423 put sp_msz i get msz i
424 end
425 ret true
426end
427
428fn sp_copy_bank_out state view uint * bank ulong plane ulong to void
429 base = mul bank plane
430 for i ulong plane bound 262144
431 put sp_cpu_state add base i get state add base i
432 end
433end
434
435fn sp_cpu_run_local hops ulong early_mode ulong t_out edit ulong 1 to bool
436 hdr = new ulong 16 0
437 rcpt = new ulong 8 0
438 csr = new uint 262144 0
439 state = new uint 524288 0
440 for i ulong 16
441 put hdr i get sp_hdr i
442 end
443 csr_words = div add get hdr 12 sub get hdr 12 get hdr 11 4
444 for i ulong csr_words bound 262144
445 put csr i get sp_cpu_csr i
446 end
447 plane = mul get hdr 1 get hdr 4
448 for i ulong plane bound 262144
449 put state i get sp_cpu_state i
450 end
451 t0 = monons
452 if ne early_mode 0
453 if ne arboris_spread_cpu_run hdr csr state rcpt 0
454 ret false
455 end
456 else
457 for h ulong hops bound 64
458 if ne arboris_spread_cpu_hop hdr csr state rcpt 0
459 ret false
460 end
461 end
462 end
463 t1 = monons
464 put t_out 0 div ulong sub t1 t0 1000
465 for i ulong 16
466 put sp_hdr i get hdr i
467 end
468 for i ulong 8
469 put sp_rcpt i get rcpt i
470 end
471 sp_copy_bank_out state get hdr 8 plane
472 ret true
473end
474
475fn sp_prep_case cid ulong v_cnt ulong deg ulong batch ulong hops ulong to ulong
476 e_cnt = sp_build_graph v_cnt deg
477 for k ulong 16
478 put sp_hdr k 0
479 end
480 put sp_hdr 0 0x4152425300000001
481 put sp_hdr 1 v_cnt
482 put sp_hdr 2 e_cnt
483 put sp_hdr 3 batch
484 put sp_hdr 5 hops
485 put sp_hdr 6 0x3f000000
486 if gt batch 1
487 put sp_hdr 7 1
488 end
489 if ge cid 10
490 put sp_hdr 7 add get sp_hdr 7 2
491 end
492 put sp_hdr 9 add 100 cid
493 put sp_hdr 10 1
494 if not sp_plan_local
495 ret 10
496 end
497 sp_fill_edges v_cnt deg
498 sp_init_seeds v_cnt batch get sp_hdr 4
499 if not sp_alloc_arena
500 ret 11
501 end
502 if not sp_upload_arena
503 ret 12
504 end
505 ret 0
506end
507
508fn sp_finish_case cid ulong gpu_hops ulong cpu_us ulong gpu_us ulong to ulong
509 sp_print_line 67 65 83 69 cid gpu_hops
510 sp_print_line 84 73 77 69 cpu_us gpu_us
511 sp_free_arena
512 ret 0
513end
514
515note Run one differential parity case.
516note early_mode: 1 = early-exit convergence, 0 = fixed-hop single-submit.
517fn sp_run_case cid ulong v_cnt ulong deg ulong batch ulong hops ulong early_mode ulong to ulong
518 cpu_t = new ulong 1 0
519 rc = sp_prep_case cid v_cnt deg batch hops
520 if ne rc 0
521 ret rc
522 end
523
524 note Run GPU
525 t0 = monons
526 gpu_hops = hops
527 if ne early_mode 0
528 gpu_hops = sp_gpu_run_early hops
529 if eq gpu_hops 999
530 ret 13
531 end
532 else
533 if not sp_gpu_run_fixed hops
534 ret 14
535 end
536 end
537 t1 = monons
538 gpu_us = div ulong sub t1 t0 1000
539 gpu_bank = get sp_hdr 8
540
541 note Run CPU OM-2 oracle from bank 0
542 put sp_hdr 8 0
543 if not sp_cpu_run_local hops early_mode cpu_t
544 ret 15
545 end
546 if ne early_mode 0
547 if ne gpu_hops get sp_rcpt 2
548 sp_print_line 68 73 70 70 gpu_hops get sp_rcpt 2
549 sp_print_line 66 65 68 87 sp_compare_bank gpu_bank mul v_cnt get sp_hdr 4 mapget get sp_slabs 4 0 8
550 sp_print_line 80 73 78 71 mapget get sp_slabs 2 32 4 mapget get sp_slabs 2 52 4
551 sp_print_line 80 79 78 71 mapget get sp_slabs 3 32 4 mapget get sp_slabs 3 52 4
552 ret 17
553 end
554 end
555 if ne gpu_bank get sp_hdr 8
556 ret 18
557 end
558 if ne sp_compare_bank gpu_bank mul v_cnt get sp_hdr 4 0
559 ret 19
560 end
561 ret sp_finish_case cid gpu_hops get cpu_t 0 gpu_us
562end
563
564fn main to int
565 if not sp_open_gpu
566 ret 1
567 end
568 note Case 2 FIRST: Mode 0 (B=1), Fixed-hop single-submit, V=256, H=4
569 rc = sp_run_case 2 256 3 1 4 0
570 if ne rc 0
571 ret int add 200 rc
572 end
573 note Case 1: Mode 0 (B=1), Early-exit convergence, V=256, hub+isolated+cycles, max_hops=12
574 rc = sp_run_case 1 256 3 1 12 1
575 if ne rc 0
576 ret int add 100 rc
577 end
578 note Case 3: Mode 1 (B=32), Early-exit convergence, V=256, max_hops=12
579 rc = sp_run_case 3 256 3 32 12 1
580 if ne rc 0
581 ret int add 300 rc
582 end
583 note Case 4: Mode 1 (B=37, non-multiple-of-32 -> stride=64), Early-exit, V=256, max_hops=12
584 rc = sp_run_case 4 256 3 37 12 1
585 if ne rc 0
586 ret int add 400 rc
587 end
588 note Case 5: Mode 1 (B=64), Fixed-hop single-submit, V=256, H=4
589 rc = sp_run_case 5 256 3 64 4 0
590 if ne rc 0
591 ret int add 500 rc
592 end
593
594 note Benchmark & routing sweep cases (6..9, all bit-exact checked too!)
595 note Case 6 (small ~10K edges): V=2048, deg=5 (~10.2K edges), B=1, H=4 fixed-hop
596 rc = sp_run_case 6 2048 5 1 4 0
597 if ne rc 0
598 ret int add 600 rc
599 end
600 note Case 7 (large ~98K edges, B=1): V=16384, deg=6 (~98.3K edges), B=1, H=4 fixed-hop
601 rc = sp_run_case 7 16384 6 1 4 0
602 if ne rc 0
603 ret int add 700 rc
604 end
605 note Case 8 (batched B=32): V=4096, deg=6 (~24.6K edges), B=32, H=4 fixed-hop
606 rc = sp_run_case 8 4096 6 32 4 0
607 if ne rc 0
608 ret int add 800 rc
609 end
610 note Case 9 (batched B=64): V=4096, deg=6 (~24.6K edges), B=64, H=4 fixed-hop
611 rc = sp_run_case 9 4096 6 64 4 0
612 if ne rc 0
613 ret int add 900 rc
614 end
615 note Case 10 (Mode 2 sum, B=1): V=256, deg=3, B=1, H=4 fixed-hop
616 rc = sp_run_case 10 256 3 1 4 0
617 if ne rc 0
618 ret int add 1000 rc
619 end
620 note Case 11 (Mode 3 sum, 35B MoE L->L+1 shape): V=512, deg=32, B=64, H=1 fixed-hop
621 rc = sp_run_case 11 512 32 64 1 0
622 if ne rc 0
623 ret int add 1100 rc
624 end
625 note Case 12 (Mode 3 sum, batched B=64): V=4096, deg=6, B=64, H=4 fixed-hop
626 rc = sp_run_case 12 4096 6 64 4 0
627 if ne rc 0
628 ret int add 1200 rc
629 end
630
631 unused = nvstop
632 ret 0
633end