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/CUDApp/blob/main/tests/components/proc.om # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / components / proc.om` 633 lines · 11482 bytes Raw Blame History 1 om2 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 note Concatenate into the conductor's om2 program; this unit has no main. 4 note Host forms checked with omega lookup at omega-mv `e5b32567`. 5 note Compiler SHA256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`. 6 note Tool paths are configured by Main; each mutable count is a ulong 1 pool. 7 global HOm uchar 1024 8 global HOn ulong 1 9 global HEnc uchar 1024 10 global HEn ulong 1 11 global HDis uchar 1024 12 global HDn ulong 1 13 global HCc uchar 1024 14 global HCn ulong 1 15 global HSha uchar 1024 16 global HSn ulong 1 17 global HArg uchar 4096 18 global HLen ulong 1 19 global HCnt ulong 1 20 global HSrc uchar `1048576` 21 global HUsed ulong 1 22 text HPFail "component conductor refused\n" 23 text HPComp "build/components/compile.om" 24 25 text HPExec "component exec refusal:" 26 text HPExp " expected=" 27 text HPSt0 " wait[0]=" 28 text HPSt1 " wait[1]=" 29 text HPSt2 " wait[2]=" 30 text HPSt3 " wait[3]=" 31 text HPPipe " exec-pipe=" 32 text HPByte " exec-byte=" 33 text HPArg " argv0=" 34 text HPNew "\n" 35 text HPMinus "-" 36 37 fn hp_require ok bool to void 38 if not ok 39 note Diagnostics must not contaminate the JSON receipt on stdout. 40 r = write 2 HPFail 0 len HPFail 41 exit 90 42 end 43 end 44 45 fn hp_path a view uchar * n ulong to void 46 hp_require and gt n 0 le n len a 47 hp_require le n 4095 48 for i ulong n 49 hp_require ne get a i 0 50 end 51 end 52 53 fn hp_start a view uchar * n ulong to void 54 hp_path a n 55 put HLen 0 2 56 put HCnt 0 0 57 put HArg 0 0 58 put HArg 1 0 59 hp_arg a n 60 end 61 62 fn hp_arg a view uchar * n ulong to void 63 hp_require le n len a 64 hp_require le n 4092 65 hp_require lt get HCnt 0 64 66 p = get HLen 0 67 hp_require and ge p 2 le p 4096 68 hp_require le add n 2 sub 4096 p 69 for i ulong n 70 hp_require ne get a i 0 71 end 72 put HArg p uchar and n 255 73 put HArg add p 1 uchar shr n 8 74 for i ulong n 75 put HArg add add p 2 i get a i 76 end 77 put HLen 0 add add p 2 n 78 c = add get HCnt 0 1 79 put HCnt 0 c 80 put HArg 0 uchar and c 255 81 put HArg 1 uchar shr c 8 82 end 83 84 note Main can select tools without borrowing a global pool as a function argument. 85 fn hp_tool which ulong to void 86 p = new uchar 1024 0 87 n = ulong 0 88 hp_require le which 3 89 if eq which 0 90 n = get HOn 0 91 hp_require le n 1024 92 for i ulong n 93 put p i get HOm i 94 end 95 end 96 if eq which 1 97 n = get HCn 0 98 hp_require le n 1024 99 for i ulong n 100 put p i get HCc i 101 end 102 end 103 if eq which 2 104 n = get HDn 0 105 hp_require le n 1024 106 for i ulong n 107 put p i get HDis i 108 end 109 end 110 if eq which 3 111 n = get HSn 0 112 hp_require le n 1024 113 for i ulong n 114 put p i get HSha i 115 end 116 end 117 hp_start p n 118 end 119 120 note Retry budgets are finite; exhausting one refuses instead of reporting success. 121 fn hp_get fd int b edit uchar * off ulong n ulong to long 122 for tries ulong 64 123 r = read fd b off n 124 if ne r -4 125 ret r 126 end 127 end 128 hp_require false 129 ret -4 130 end 131 132 fn hp_put fd int b view uchar * off ulong n ulong to long 133 for tries ulong 64 134 r = write fd b off n 135 if ne r -4 136 ret r 137 end 138 end 139 hp_require false 140 ret -4 141 end 142 143 fn hp_open p view uchar * n ulong flags int mode int to int 144 hp_path p n 145 for tries ulong 64 146 r = fopen p 0 n flags mode 147 if ne r -4 148 hp_require ge r 0 149 ret int r 150 end 151 end 152 hp_require false 153 ret -1 154 end 155 156 note On Linux close releases the descriptor even when it reports EINTR; never retry it. 157 fn hp_close fd int to void 158 r = fclose fd 159 hp_require eq r 0 160 end 161 162 note Fill one chunk; independent short-read boundaries cannot create false mismatches. 163 fn hp_fill fd int b edit uchar * off ulong n ulong to ulong 164 hp_require le n 4096 165 hp_require le off len b 166 hp_require le n sub len b off 167 used = ulong 0 168 while lt used n bound 4096 169 r = hp_get fd b add off used sub n used 170 hp_require ge r 0 171 if eq r 0 172 ret used 173 end 174 hp_require le ulong r sub n used 175 used = add used ulong r 176 end 177 ret used 178 end 179 180 fn hp_wpart fd int b view uchar * off ulong n ulong to void 181 hp_require le n 4096 182 hp_require le off len b 183 hp_require le n sub len b off 184 used = ulong 0 185 while lt used n bound 4096 186 r = hp_put fd b add off used sub n used 187 hp_require gt r 0 188 hp_require le ulong r sub n used 189 used = add used ulong r 190 end 191 end 192 193 fn hp_write path view uchar * n ulong b view uchar * used ulong to void 194 hp_require le used len b 195 fd = hp_open path n or int 577 524288 420 196 off = ulong 0 197 note Each outer pass completes up to 4096 bytes, even under one-byte short writes. 198 while lt off used bound 999999 199 step = sub used off 200 if gt step 4096 201 step = 4096 202 end 203 hp_wpart fd b off step 204 off = add off step 205 end 206 hp_close fd 207 end 208 209 fn hp_read path view uchar * n ulong b edit uchar * cap ulong to ulong 210 probe = new uchar 1 0 211 hp_require le cap len b 212 fd = hp_open path n 524288 0 213 used = ulong 0 214 while lt used cap bound 999999 215 step = sub cap used 216 if gt step 4096 217 step = 4096 218 end 219 k = hp_fill fd b used step 220 used = add used k 221 if lt k step 222 hp_close fd 223 ret used 224 end 225 end 226 note Exact-capacity input is accepted only after a separate EOF probe. 227 r = hp_get fd probe 0 1 228 hp_require eq r 0 229 hp_close fd 230 ret used 231 end 232 233 fn hp_cat path view uchar * n ulong to void 234 b = new uchar 4096 0 235 hp_require le get HUsed 0 len HSrc 236 fd = hp_open path n 524288 0 237 for chunk ulong 999999 238 k = hp_fill fd b 0 4096 239 p = get HUsed 0 240 hp_require le k sub len HSrc p 241 for i ulong k 242 put HSrc add p i get b i 243 end 244 put HUsed 0 add p k 245 if lt k 4096 246 hp_close fd 247 ret 248 end 249 end 250 hp_require false 251 end 252 253 fn hp_fdok fd int to void 254 b = new uchar 128 0 255 for tries ulong 64 256 r = fstat fd b 0 128 257 if ne r -4 258 hp_require eq r 0 259 ret 260 end 261 end 262 hp_require false 263 end 264 265 note Copy into an unused descriptor above stderr, without changing the parent's table. 266 note Called only after fork; this single-threaded child performs no concurrent opens. 267 fn hp_save fd int to int 268 b = new uchar 128 0 269 for cand ulong 65536 270 if ge cand 3 271 r = fstat int cand b 0 128 272 if eq r -4 273 continue 274 end 275 if eq r -9 276 for tries ulong 64 277 r = dupfd fd int cand 524288 278 if ne r -4 279 if eq r long cand 280 ret int cand 281 end 282 ret -1 283 end 284 end 285 ret -1 286 end 287 if ne r 0 288 ret -1 289 end 290 end 291 end 292 ret -1 293 end 294 295 note A failed child writes the exec-error pipe and exits 127, never an expected tool exit. 296 fn hp_childbad errfd int to void 297 b = new uchar 1 1 298 for tries ulong 64 299 r = write errfd b 0 1 300 if eq r 1 301 exit 127 302 end 303 if ne r -4 304 break 305 end 306 end 307 note If the error cannot be reported, force a signaled status that the parent refuses. 308 r = killpid int getpid 9 309 exit 127 310 end 311 312 fn hp_dupto fd int target int errfd int to void 313 if eq fd target 314 ret 315 end 316 for tries ulong 64 317 r = dupfd fd target 0 318 if ne r -4 319 if ne r long target 320 hp_childbad errfd 321 end 322 ret 323 end 324 end 325 hp_childbad errfd 326 end 327 328 fn hp_child infd int outfd int rd int wr int to void 329 errfd = wr 330 if lt wr 3 331 errfd = hp_save wr 332 if lt errfd 0 333 hp_childbad wr 334 end 335 r = fclose wr 336 if ne r 0 337 hp_childbad errfd 338 end 339 end 340 r = fclose rd 341 if ne r 0 342 hp_childbad errfd 343 end 344 saved = int -1 345 if ge infd 0 346 saved = hp_save infd 347 if lt saved 0 348 hp_childbad errfd 349 end 350 end 351 note Preserve stdin first, so even the input=1/output=0 swap is well-defined. 352 if ge outfd 0 353 if eq outfd 1 354 temp = hp_save outfd 355 if lt temp 0 356 hp_childbad errfd 357 end 358 hp_dupto temp 1 errfd 359 r = fclose temp 360 if ne r 0 361 hp_childbad errfd 362 end 363 else 364 hp_dupto outfd 1 errfd 365 end 366 end 367 if ge saved 0 368 hp_dupto saved 0 errfd 369 r = fclose saved 370 if ne r 0 371 hp_childbad errfd 372 end 373 end 374 if gt infd 2 375 r = fclose infd 376 if ne r 0 377 hp_childbad errfd 378 end 379 end 380 if and gt outfd 2 ne outfd infd 381 r = fclose outfd 382 if ne r 0 383 hp_childbad errfd 384 end 385 end 386 r = execprog HArg 0 get HLen 0 387 hp_childbad errfd 388 end 389 390 note Validate the complete canonical list before execprog can trap in a child. 391 fn hp_args to void 392 total = get HLen 0 393 count = get HCnt 0 394 hp_require and ge total 4 le total 4096 395 hp_require and ge count 1 le count 64 396 head = or ulong get HArg 0 shl ulong get HArg 1 8 397 hp_require eq head count 398 p = ulong 2 399 for record ulong count 400 hp_require le p sub total 2 401 n = or ulong get HArg p shl ulong get HArg add p 1 8 402 p = add p 2 403 hp_require le n sub total p 404 if eq record 0 405 hp_require gt n 0 406 end 407 for i ulong n 408 hp_require ne get HArg add p i 0 409 end 410 p = add p n 411 end 412 hp_require eq p total 413 end 414 415 416 fn hp_u32 b view uchar * off ulong to ulong 417 v = ulong 0 418 for i ulong 4 419 v = or v shl ulong get b add off i mul i 8 420 end 421 ret v 422 end 423 424 fn hp_wait pid long st edit uchar 4 to void 425 for tries ulong 64 426 r = waitpid int pid st 0 4 0 427 if ne r -4 428 hp_require eq r pid 429 ret 430 end 431 end 432 hp_require false 433 end 434 435 fn hp_say label view uchar * to void 436 hp_wpart 2 label 0 len label 437 end 438 439 fn hp_diag label view uchar * value long to void 440 digits = new uchar 32 0 441 hp_say label 442 v = value 443 if lt v 0 444 hp_say HPMinus 445 v = neg v 446 end 447 n = hp_num ulong v digits 448 hp_wpart 2 digits 0 n 449 end 450 451 fn hp_argv0 to void 452 hp_say HPArg 453 n = or ulong get HArg 2 shl ulong get HArg 3 8 454 used = ulong 0 455 while lt used n bound 4096 456 r = long -4 457 for tries ulong 64 458 r = write 2 HArg add used 4 sub n used 459 if ne r -4 460 break 461 end 462 end 463 if le r 0 464 ret 465 end 466 used = add used ulong r 467 end 468 hp_say HPNew 469 end 470 471 fn hp_result expected long st view uchar 4 piperc long marker uchar to void 472 ok = eq piperc 0 473 ok = and ok eq get st 0 0 474 ok = and ok eq get st 2 0 475 ok = and ok eq get st 3 0 476 ok = and ok eq long get st 1 expected 477 if not ok 478 hp_say HPExec 479 hp_diag HPExp expected 480 hp_diag HPSt0 long get st 0 481 hp_diag HPSt1 long get st 1 482 hp_diag HPSt2 long get st 2 483 hp_diag HPSt3 long get st 3 484 hp_diag HPPipe piperc 485 hp_diag HPByte long marker 486 hp_argv0 487 end 488 hp_require ok 489 end 490 491 fn hp_exec infd int outfd int expected long to void 492 ends = new uchar 8 0 493 st = new uchar 4 0 494 probe = new uchar 1 0 495 hp_require and ge expected 0 le expected 255 496 hp_args 497 if ge infd 0 498 hp_fdok infd 499 end 500 if ge outfd 0 501 hp_fdok outfd 502 end 503 r = long -4 504 for tries ulong 64 505 r = pipefds ends 0 8 524288 506 if ne r -4 507 break 508 end 509 end 510 hp_require eq r 0 511 rd = int hp_u32 ends 0 512 wr = int hp_u32 ends 4 513 pid = fork 514 if eq pid 0 515 hp_child infd outfd rd wr 516 exit 127 517 end 518 if lt pid 0 519 hp_close rd 520 hp_close wr 521 hp_require false 522 end 523 hp_close wr 524 hp_wait pid st 525 r = hp_get rd probe 0 1 526 hp_close rd 527 note Error-pipe EOF and all four wait-status bytes are checked together. 528 hp_result expected st r get probe 0 529 end 530 531 note The global source is written directly, never passed across a global-borrow boundary. 532 fn hp_src fd int to void 533 hp_require le get HUsed 0 len HSrc 534 off = ulong 0 535 while lt off get HUsed 0 bound 999999 536 step = sub get HUsed 0 off 537 if gt step 4096 538 step = 4096 539 end 540 used = ulong 0 541 while lt used step bound 4096 542 r = long -4 543 for tries ulong 64 544 r = write fd HSrc add off used sub step used 545 if ne r -4 546 break 547 end 548 end 549 hp_require gt r 0 550 hp_require le ulong r sub step used 551 used = add used ulong r 552 end 553 off = add off step 554 end 555 end 556 557 fn hp_build path view uchar * n ulong to void 558 hp_path path n 559 fd = hp_open HPComp len HPComp or int 577 524288 420 560 hp_src fd 561 hp_close fd 562 infd = hp_open HPComp len HPComp 524288 0 563 outfd = hp_open path n or int 577 524288 420 564 hp_tool 0 565 hp_exec infd outfd 0 566 hp_close infd 567 hp_close outfd 568 for tries ulong 64 569 r = chmod path 0 n 493 570 if ne r -4 571 hp_require eq r 0 572 ret 573 end 574 end 575 hp_require false 576 end 577 578 fn hp_equal a view uchar * b view uchar * used ulong to bool 579 hp_require le used len a 580 hp_require le used len b 581 for i ulong used 582 if ne get a i get b i 583 ret false 584 end 585 end 586 ret true 587 end 588 589 fn hp_cmp a view uchar * an ulong b view uchar * bn ulong to bool 590 left = new uchar 4096 0 591 right = new uchar 4096 0 592 af = hp_open a an 524288 0 593 bf = hp_open b bn 524288 0 594 for chunk ulong 999999 595 ac = hp_fill af left 0 4096 596 bc = hp_fill bf right 0 4096 597 if ne ac bc 598 hp_close af 599 hp_close bf 600 ret false 601 end 602 if not hp_equal left right ac 603 hp_close af 604 hp_close bf 605 ret false 606 end 607 if lt ac 4096 608 hp_close af 609 hp_close bf 610 ret true 611 end 612 end 613 hp_require false 614 ret false 615 end 616 617 fn hp_num value ulong dst edit uchar 32 to ulong 618 rev = new uchar 32 0 619 v = value 620 n = ulong 0 621 while true bound 32 622 put rev n uchar add rem v 10 48 623 n = add n 1 624 v = div v 10 625 if eq v 0 626 break 627 end 628 end 629 for i ulong n 630 put dst i get rev sub sub n 1 i 631 end 632 ret n 633 end