Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/extra-units-gate.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / extra-units-gate.om` 797 lines ยท 15196 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/extra-units-gate.om: OMEGA-GPU-EXTRA-UNITS, the gate of the pure-Omega units of Sovereign Intelligence layer 'gpu', in 3 note seeded Omega (Linux AArch64). Build from the repository root (OM-2 program mode; seed/ng/sha256.om supplies 4 note sh_dat, sh_all, sh_dig): 5 note { printf 'om2\n'; cat seed/ng/sha256.om gpu/extra-units-gate.om; } | seed/out/omc > gpu-extra-units-gate 6 note Run from the repository root: gpu-extra-units-gate OMC SCRATCH 7 note OMC the compiler under test; its sha256 must equal the first word of seed/out/omc.sha256, or nothing 8 note runs (exit 69, nothing written) 9 note SCRATCH a new directory (created 0700), at most 1024 bytes of path; an existing one is refused (exit 2) 10 note Units. gpu/extra-units.tsv lists every unit, one per line: NAME then the paths of its parts, single spaces; a line 11 note starting with # is a comment and an empty line is skipped. NAME is 1 to 249 of A-Z a-z 0-9 _ and appears once 12 note (249 leaves room for the longest scratch suffix, ".1.err", inside a 255-byte file name). 13 note The parts are concatenated in order, each followed by a newline (the composition of gpu/extra-units.tsv), into 14 note SCRATCH/NAME.om and compiled twice by OMC: each compile exits 0 with empty stderr, and both outputs hold the same 15 note bytes. A malformed or repeated row, a missing part, a failed compile, two different outputs or a table with no 16 note unit is a FAIL line. The runner (gpu/README.md) also requires the exact unit count. 17 note Control, must be caught: a compiler one byte longer fails the digest check. 18 note Output: one line per unit, then OMEGA-GPU-EXTRA-UNITS PASS|FAIL units=U controls=C caught=K hardware=NOT_RUN. 19 note Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 69 compiler digest refused. Every input is length-checked; a trap 20 note exit (101..114) would be a defect of this gate, never a pass. 21 note This gate checks that the units compile reproducibly with this repository's compiler. It does not run them: 22 note their behaviour checks are still C, Python and shell in upstream repos (gpu/README.md lists them). 23 text t_pin "seed/out/omc.sha256" 24 text t_tab "gpu/extra-units.tsv" 25 text t_om ".om" 26 text t_b1 ".1" 27 text t_b2 ".2" 28 text t_e1 ".1.err" 29 text t_e2 ".2.err" 30 text t_badname "units.tsv: name outside A-Z a-z 0-9 _" 31 text t_dup "units.tsv: name repeated, or more than 64 KiB of names" 32 text t_empty "units.tsv names no unit" 33 text t_plus "omc-plus-one" 34 text t_usage "usage: gpu-extra-units-gate OMC SCRATCH (run from the omega-mv repository root)\n" 35 text t_refd "OMEGA-GPU-EXTRA-UNITS REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n" 36 text t_nopin "OMEGA-GPU-EXTRA-UNITS INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n" 37 text t_noscr "OMEGA-GPU-EXTRA-UNITS INVALID: SCRATCH exists or cannot be made\n" 38 text t_notab "OMEGA-GPU-EXTRA-UNITS INVALID: cannot read gpu/extra-units.tsv\n" 39 text t_long "OMEGA-GPU-EXTRA-UNITS INVALID: SCRATCH path longer than 1024 bytes\n" 40 text t_ok "ok " 41 text t_fail "FAIL " 42 text t_unit "unit " 43 text t_ctl "control " 44 text t_bytes " bytes=" 45 text t_sha " sha256=" 46 text t_exit " exit=" 47 text t_src "source unreadable: " 48 text t_big "output unreadable or over 16 MiB" 49 text t_cmp "compile" 50 text t_stderr " stderr not empty" 51 text t_twice " two builds differ" 52 text t_write "cannot write the composed unit in SCRATCH" 53 text t_row "units.tsv: malformed row (name 1..249 bytes, at least one part)" 54 text t_plong "units.tsv: a part path is longer than 4000 bytes" 55 text t_caught " caught" 56 text t_esc " ESCAPED" 57 text t_sum "OMEGA-GPU-EXTRA-UNITS " 58 text t_pass "PASS" 59 text t_fl "FAIL" 60 text t_su " units=" 61 text t_sc " controls=" 62 text t_sk " caught=" 63 text t_hw " hardware=NOT_RUN\n" 64 global g_pa uchar 4096 65 global g_scr uchar 4096 66 global g_omc uchar 4096 67 global g_nm uchar 256 68 global g_av uchar 8192 69 global g_b uchar `16777216` 70 global g_u uchar `1048576` 71 global g_o uchar 8192 72 global g_hx uchar 64 73 global g_pin uchar 64 74 global g_d1 uchar 32 75 global g_stb uchar 4 76 global g_n ulong 32 77 global g_seen uchar 65536 78 note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length, 79 note 6 buffer length, 7 table length, 8 units, 11 failures, 12 controls, 13 caught, 14 name length, 15 g_seen length, 80 note 16 unit rows 81 note ---- output 82 fn oc c ulong to void 83 n = get g_n 5 84 put g_o n uchar c 85 put g_n 5 add n 1 86 end 87 fn ot t view uchar * to void 88 for i ulong len t bound 4096 89 oc ulong get t i 90 end 91 end 92 fn onm to void 93 for i ulong get g_n 14 bound 256 94 oc ulong get g_nm i 95 end 96 end 97 fn onum v ulong to void 98 if ge v 10 99 onum div v 10 100 end 101 oc add 48 rem v 10 102 end 103 fn ohex to void 104 for j ulong 32 105 b = get sh_dig j 106 oc ulong sh_hexd uint shr b 4 107 oc ulong sh_hexd uint and b 15 108 end 109 end 110 fn ohx to void 111 for j ulong 64 112 oc ulong get g_hx j 113 end 114 end 115 fn oflush to void 116 r = write 1 g_o 0 get g_n 5 117 put g_n 5 0 118 end 119 fn onl to void 120 oc 10 121 oflush 122 end 123 note a failed check: FAIL KIND NAME then the reason; counts a failure 124 fn ofail kind view uchar * why view uchar * to void 125 ot t_fail 126 ot kind 127 onm 128 oc 32 129 ot why 130 onl 131 put g_n 11 add get g_n 11 1 132 end 133 note ---- paths: g_pa[0, g_n 0) 134 fn pclr to void 135 put g_n 0 0 136 end 137 fn pc c ulong to void 138 n = get g_n 0 139 put g_pa n uchar c 140 put g_n 0 add n 1 141 end 142 fn pt t view uchar * to void 143 for i ulong len t bound 4096 144 pc ulong get t i 145 end 146 end 147 fn pscr to void 148 for j ulong get g_n 2 bound 4096 149 pc ulong get g_scr j 150 end 151 end 152 fn pnm to void 153 for j ulong get g_n 14 bound 256 154 pc ulong get g_nm j 155 end 156 end 157 note scratch file NAME then suffix 158 fn psn suf view uchar * to void 159 pclr 160 pscr 161 pnm 162 pt suf 163 end 164 note scratch file named by a text 165 fn pst t view uchar * suf view uchar * to void 166 pclr 167 pscr 168 pt t 169 pt suf 170 end 171 note scratch file named by a text alone 172 fn psc t view uchar * to void 173 pclr 174 pscr 175 pt t 176 end 177 fn nmset t view uchar * to void 178 for i ulong len t bound 256 179 put g_nm i get t i 180 end 181 put g_n 14 len t 182 end 183 note ---- files 184 fn fopn fl ulong mode ulong to int 185 r = fopen g_pa 0 get g_n 0 int fl int mode 186 if lt r 0 187 ret -1 188 end 189 ret int r 190 end 191 fn frd to int 192 ret fopn 524288 0 193 end 194 fn fwr to int 195 ret fopn 524865 420 196 end 197 fn fexe to int 198 r = unlink g_pa 0 get g_n 0 199 ret fopn 524865 448 200 end 201 fn fclo fd int to void 202 if ge fd 0 203 r = fclose fd 204 end 205 end 206 note append the file at g_pa to g_b; false when unreadable or past the buffer 207 fn bload to bool 208 fd = frd 209 if lt fd 0 210 ret false 211 end 212 n = get g_n 6 213 ok = true 214 while true bound `16777218` 215 x = read fd g_b n sub len g_b n 216 if lt x 0 217 ok = false 218 break 219 end 220 if eq x 0 221 break 222 end 223 n = add n ulong x 224 if ge n len g_b 225 ok = false 226 break 227 end 228 end 229 fclo fd 230 put g_n 6 n 231 ret ok 232 end 233 note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe) 234 fn bsave exe bool to bool 235 fd = int -1 236 if exe 237 fd = fexe 238 else 239 fd = fwr 240 end 241 if lt fd 0 242 ret false 243 end 244 n = get g_n 6 245 o = ulong 0 246 ok = true 247 while lt o n bound `16777217` 248 x = write fd g_b o sub n o 249 if le x 0 250 ok = false 251 break 252 end 253 o = add o ulong x 254 end 255 fclo fd 256 ret ok 257 end 258 note sha256 of the file at g_pa into sh_dig; false when unreadable or past 16 MiB 259 fn fhash to bool 260 fd = frd 261 if lt fd 0 262 ret false 263 end 264 n = ulong 0 265 ok = true 266 while true bound `16777218` 267 x = read fd sh_dat n sub len sh_dat n 268 if lt x 0 269 ok = false 270 break 271 end 272 if eq x 0 273 break 274 end 275 n = add n ulong x 276 if ge n len sh_dat 277 ok = false 278 break 279 end 280 end 281 fclo fd 282 if not ok 283 ret false 284 end 285 sh_all n 286 ret true 287 end 288 note the size of the file at g_pa, or 2^63 when unreadable 289 fn fsize to ulong 290 put g_n 6 0 291 if not bload 292 ret shl ulong 1 63 293 end 294 ret get g_n 6 295 end 296 note sh_dig equals the hex in g_hx 297 fn digeq to bool 298 for j ulong 32 299 b = get sh_dig j 300 if ne get g_hx mul j 2 sh_hexd uint shr b 4 301 ret false 302 end 303 if ne get g_hx add mul j 2 1 sh_hexd uint and b 15 304 ret false 305 end 306 end 307 ret true 308 end 309 fn dsave to void 310 for j ulong 32 311 put g_d1 j get sh_dig j 312 end 313 end 314 fn dsame to bool 315 for j ulong 32 316 if ne get g_d1 j get sh_dig j 317 ret false 318 end 319 end 320 ret true 321 end 322 note ---- processes 323 fn aclr to void 324 put g_n 3 2 325 put g_n 4 0 326 put g_av 0 0 327 put g_av 1 0 328 end 329 note append g_pa as one argument 330 fn apa to void 331 p = get g_n 3 332 n = get g_n 0 333 for j ulong n bound 4096 334 put g_av add add p 2 j get g_pa j 335 end 336 put g_av p uchar and n 255 337 put g_av add p 1 uchar shr n 8 338 put g_n 3 add p add n 2 339 c = add get g_n 4 1 340 put g_n 4 c 341 put g_av 0 uchar and c 255 342 put g_av 1 uchar shr c 8 343 end 344 fn atx t view uchar * to void 345 pclr 346 pt t 347 apa 348 end 349 fn redir s int d int to void 350 if ne dupfd s d 0 long d 351 exit 127 352 end 353 end 354 note run the argument list with stdin, stdout, stderr fds (closed here): the exit code, 256 + the signal, 512 355 note when a file could not be opened, 1000 when the child passed the 600 s deadline (killed) 356 fn spawn fi int fo int fe int to ulong 357 if or lt fi 0 or lt fo 0 lt fe 0 358 fclo fi 359 fclo fo 360 fclo fe 361 ret 512 362 end 363 pid = fork 364 if lt pid 0 365 exit 2 366 end 367 if eq pid 0 368 redir fi 0 369 redir fo 1 370 redir fe 2 371 r = execprog g_av 0 get g_n 3 372 exit 127 373 end 374 fclo fi 375 fclo fo 376 fclo fe 377 t0 = monons 378 while true bound `1000000000` 379 r = waitpid int pid g_stb 0 len g_stb 1 380 if eq r pid 381 x = ulong get g_stb 0 382 if ne x 0 383 ret add 256 x 384 end 385 ret ulong get g_stb 1 386 end 387 if lt r 0 388 exit 2 389 end 390 if gt sub monons t0 `600000000000` 391 r = killpid int pid 9 392 r = waitpid int pid g_stb 0 len g_stb 0 393 ret 1000 394 end 395 q = sleepns 200000 396 end 397 exit 2 398 end 399 note OMC < SCRATCH/NAME.om > SCRATCH/NAME.SUF 2> SCRATCH/NAME.ERR 400 fn omc suf view uchar * err view uchar * to ulong 401 psn t_om 402 fi = frd 403 aclr 404 pclr 405 for j ulong get g_n 1 bound 4096 406 pc ulong get g_omc j 407 end 408 apa 409 psn suf 410 fo = fexe 411 psn err 412 fe = fwr 413 ret spawn fi fo fe 414 end 415 note ---- the compiler digest 416 note the first 64 characters of seed/out/omc.sha256 into g_pin; false unless lowercase hex 417 fn pinread to bool 418 pclr 419 pt t_pin 420 put g_n 6 0 421 if not bload 422 ret false 423 end 424 if lt get g_n 6 64 425 ret false 426 end 427 for j ulong 64 428 c = get g_b j 429 ok = or and ge c 48 le c 57 and ge c 97 le c 102 430 if not ok 431 ret false 432 end 433 put g_pin j c 434 end 435 ret true 436 end 437 note the file at g_pa hashes to g_pin 438 fn pinok to bool 439 if not fhash 440 ret false 441 end 442 for j ulong 64 443 put g_hx j get g_pin j 444 end 445 ret digeq 446 end 447 note ---- units 448 note g_u[i] is c, for i below e (never reads at or past e) 449 fn uis i ulong e ulong c ulong to bool 450 if ge i e 451 ret false 452 end 453 ret eq ulong get g_u i c 454 end 455 fn uisnt i ulong e ulong c ulong to bool 456 if ge i e 457 ret false 458 end 459 ret ne ulong get g_u i c 460 end 461 note append one newline to g_b (units.sh writes one after every part) 462 fn nl to bool 463 n = get g_n 6 464 if ge add n 1 len g_b 465 ret false 466 end 467 put g_b n 10 468 put g_n 6 add n 1 469 ret true 470 end 471 note a missing or unreadable part: FAIL unit NAME source unreadable: PATH (the path is in g_pa, at most 4000 bytes) 472 fn psrcfail to void 473 ot t_fail 474 ot t_unit 475 onm 476 oc 32 477 ot t_src 478 for q ulong get g_n 0 bound 4096 479 oc ulong get g_pa q 480 end 481 onl 482 put g_n 11 add get g_n 11 1 483 end 484 note compose the parts g_u[s, e) into g_b as gpu/extra-units.tsv does: each part's bytes, then one newline; false 485 note (reported) when a part is unreadable or its path is longer than 4000 bytes 486 fn compose s ulong e ulong to bool 487 put g_n 6 0 488 i = s 489 while lt i e bound `1048576` 490 while uis i e 32 bound `1048576` 491 i = add i 1 492 end 493 if ge i e 494 break 495 end 496 j = i 497 while uisnt j e 32 bound `1048576` 498 j = add j 1 499 end 500 if gt sub j i 4000 501 ofail t_unit t_plong 502 ret false 503 end 504 pclr 505 for q ulong sub j i bound 4096 506 pc ulong get g_u add i q 507 end 508 if not bload 509 psrcfail 510 ret false 511 end 512 if not nl 513 ofail t_unit t_big 514 ret false 515 end 516 i = j 517 end 518 ret true 519 end 520 note compile the composed unit twice; true when both exit 0 with empty stderr and equal bytes 521 fn build to bool 522 psn t_om 523 if not bsave false 524 ofail t_unit t_write 525 ret false 526 end 527 r1 = omc t_b1 t_e1 528 r2 = omc t_b2 t_e2 529 if or ne r1 0 ne r2 0 530 ot t_fail 531 ot t_unit 532 onm 533 oc 32 534 ot t_cmp 535 ot t_exit 536 onum r1 537 oc 47 538 onum r2 539 onl 540 put g_n 11 add get g_n 11 1 541 ret false 542 end 543 psn t_e1 544 s1 = fsize 545 psn t_e2 546 s2 = fsize 547 if or ne s1 0 ne s2 0 548 ofail t_unit t_stderr 549 ret false 550 end 551 psn t_b1 552 if not fhash 553 ofail t_unit t_big 554 ret false 555 end 556 dsave 557 psn t_b2 558 if not fhash 559 ofail t_unit t_big 560 ret false 561 end 562 if not dsame 563 ofail t_unit t_twice 564 ret false 565 end 566 psn t_b1 567 sz = fsize 568 psn t_b1 569 if not fhash 570 ofail t_unit t_big 571 ret false 572 end 573 ot t_ok 574 ot t_unit 575 onm 576 ot t_bytes 577 onum sz 578 ot t_sha 579 ohex 580 onl 581 put g_n 8 add get g_n 8 1 582 ret true 583 end 584 note one table row [s, e): NAME then parts; # starts a comment line; an empty line is skipped 585 fn urow s ulong e ulong to void 586 if or eq s e eq get g_u s 35 587 ret 588 end 589 put g_n 14 0 590 k = s 591 while uisnt k e 32 bound `1048576` 592 k = add k 1 593 end 594 if or ge k e or eq k s gt sub k s 249 595 ofail t_unit t_row 596 ret 597 end 598 for q ulong sub k s bound 256 599 put g_nm q get g_u add s q 600 end 601 put g_n 14 sub k s 602 put g_n 16 add get g_n 16 1 603 if not nameok 604 ofail t_unit t_badname 605 ret 606 end 607 if not nameadd 608 ofail t_unit t_dup 609 ret 610 end 611 if compose k e 612 z = build 613 end 614 end 615 note a unit name uses only A-Z a-z 0-9 _ (A-Z a-z 0-9 _), so it names a file in SCRATCH 616 fn nameok to bool 617 for q ulong get g_n 14 bound 256 618 c = get g_nm q 619 d = and ge c 48 le c 57 620 u = and ge c 65 le c 90 621 l = and ge c 97 le c 122 622 ok = or or d u or l eq c 95 623 if not ok 624 ret false 625 end 626 end 627 ret true 628 end 629 note record the name in g_seen (names joined by newlines); false when it is already there or g_seen is full 630 fn nameadd to bool 631 n = get g_n 15 632 m = get g_n 14 633 p = ulong 0 634 while lt p n bound 65536 635 q = p 636 while and lt q n ne get g_seen q 10 bound 65536 637 q = add q 1 638 end 639 if nameat p q 640 ret false 641 end 642 p = add q 1 643 end 644 if ge add add n m 1 len g_seen 645 ret false 646 end 647 for j ulong m bound 256 648 put g_seen add n j get g_nm j 649 end 650 put g_seen add n m 10 651 put g_n 15 add add n m 1 652 ret true 653 end 654 note g_seen[p, q) equals the current name 655 fn nameat p ulong q ulong to bool 656 if ne sub q p get g_n 14 657 ret false 658 end 659 for j ulong sub q p bound 256 660 if ne get g_seen add p j get g_nm j 661 ret false 662 end 663 end 664 ret true 665 end 666 fn table to bool 667 pclr 668 pt t_tab 669 put g_n 6 0 670 if not bload 671 ret false 672 end 673 n = get g_n 6 674 if ge n len g_u 675 ret false 676 end 677 for q ulong n bound `1048576` 678 put g_u q get g_b q 679 end 680 put g_n 7 n 681 s = ulong 0 682 while lt s n bound `1048576` 683 e = s 684 while uisnt e n 10 bound `1048576` 685 e = add e 1 686 end 687 urow s e 688 s = add e 1 689 end 690 if eq get g_n 16 0 691 nmset t_tab 692 ofail t_unit t_empty 693 end 694 ret true 695 end 696 note ---- controls 697 fn caught c bool what view uchar * to void 698 put g_n 12 add get g_n 12 1 699 nmset what 700 if c 701 ot t_ok 702 ot t_ctl 703 onm 704 ot t_caught 705 onl 706 put g_n 13 add get g_n 13 1 707 else 708 ofail t_ctl t_esc 709 end 710 end 711 note a compiler one byte longer must fail the digest check 712 fn cwrong to void 713 pclr 714 for j ulong get g_n 1 bound 4096 715 pc ulong get g_omc j 716 end 717 put g_n 6 0 718 ok = bload 719 n = get g_n 6 720 put g_b n 0 721 put g_n 6 add n 1 722 psc t_plus 723 ok = and ok bsave true 724 psc t_plus 725 c = and ok not pinok 726 caught c t_plus 727 end 728 note ---- main 729 fn ausage to int 730 r = write 2 t_usage 0 len t_usage 731 ret 2 732 end 733 fn main to int 734 if ne argcnt 3 735 ret ausage 736 end 737 r = argread 1 g_omc 0 4095 738 if lt r 1 739 ret ausage 740 end 741 put g_n 1 ulong r 742 if not pinread 743 r = write 2 t_nopin 0 len t_nopin 744 ret 2 745 end 746 pclr 747 for j ulong get g_n 1 bound 4096 748 pc ulong get g_omc j 749 end 750 if not pinok 751 r = write 2 t_refd 0 len t_refd 752 ret 69 753 end 754 r = argread 2 g_scr 0 4094 755 if lt r 1 756 ret ausage 757 end 758 if gt r 1024 759 r = write 2 t_long 0 len t_long 760 ret 2 761 end 762 n = ulong r 763 x = makedir g_scr 0 n 448 764 if ne x 0 765 r = write 2 t_noscr 0 len t_noscr 766 ret 2 767 end 768 put g_scr n 47 769 put g_n 2 add n 1 770 if not table 771 r = write 2 t_notab 0 len t_notab 772 ret 2 773 end 774 cwrong 775 f = get g_n 11 776 ot t_sum 777 if eq f 0 778 ot t_pass 779 else 780 ot t_fl 781 end 782 ot t_su 783 onum get g_n 8 784 ot t_sc 785 onum get g_n 12 786 ot t_sk 787 onum get g_n 13 788 ot t_hw 789 oflush 790 if ne f 0 791 ret 1 792 end 793 if ne get g_n 12 get g_n 13 794 ret 1 795 end 796 ret 0 797 end