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/nvml/host.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 / nvml / host.om` 942 lines · 19671 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note CUDA++ NVML host tier in Omega: the checks of tests/nvml/nvml_test.c, one for one and in the 3 note same order, run against native/nvml (nvml_step, nvml_errstr) and the RM fake 4 note tests/nvml/rmfake.om, with no foreign code. tests/nvml/gate.om composes this program as 5 note native/nvml/nvml.om query.om step.om errstr.om, tests/nvml/rmfake.om, then this file, and 6 note compiles it with the pinned seeded omc. 7 note 8 note hv_run is the call protocol of native/nvml/api.om (generated as compat/nvml/libnvidia-ml.c): 9 note stage the op and arguments, alternate nvml_step with the one action it requests, 10 note bound the copies, map the status. hv_ioctl, hv_open and hv_close are the test transport of 11 note tests/nvml/transport.c (fault S included). Pointers of the C test become flags and slots: 12 note a device handle is 0 (NULL), 1+index (issued by hv_handle) or 1000 (a foreign pointer); a 13 note scalar out-pointer is 1+slot in HvV (0 is NULL); the caller's output buffer is HvO. 14 note One difference from the C caller: a trap inside a unit ends this program with the trap 15 note status (101..114) instead of reading as NVML_ERROR_UNKNOWN; either way the tier fails. 16 note usage: host ERRSTR_ORACLE.tsv; prints CUDAPP-NVML HOST PASS (N checks), exit 0, or 17 note CUDAPP-NVML HOST FAIL (F of N checks), exit 1; a usage error exits 2. 18 19 global HvA ulong 8 20 global HvG ulong 4 21 global HvO uchar 6144 22 global HvV ulong 4 23 global HvH ulong 4 24 global HvC ulong 4 25 global HvF ulong 4 26 global HvR ulong 1 27 global HvT uchar 2048 28 global HvTs uchar 32 29 30 text HvNm "NVIDIA GB10" 31 text HvU0 "GPU-`fb8e53f0`-3207-e89b-d02f-`acdfe2695b59`" 32 text HvU1 "GPU-`fb8e53f0`-3207-e89b-d02f-`acdfe2695b5a`" 33 text HvUnk "Unknown Error" 34 text HvFl "oadPA902cGnESgthvzxmwyerZXklpbijf" 35 text HvFi "94944U000000000000000000000000000" 36 text HvFc "`000000112222234445556666667777770`" 37 text HvFr "000000003FUUUUUU333U34UUUU30U00U0" 38 text HvFail "FAIL check " 39 text HvNL "\n" 40 text HvPass "CUDAPP-NVML HOST PASS (" 41 text HvBad "CUDAPP-NVML HOST FAIL (" 42 text HvOf " of " 43 text HvChk " checks)\n" 44 text HvUse "usage: host ERRSTR_ORACLE.tsv\n" 45 46 const HvMAX ulong `18446744073709551615` 47 const HvNA32 ulong `4294967295` 48 const HvFOR ulong 1000 49 50 note Decimal digits of v to fd. 51 fn hv_num fd int v ulong to void 52 rev = new uchar 32 0 53 out = new uchar 32 0 54 x = v 55 n = ulong 0 56 while true bound 32 57 put rev n uchar add rem x 10 48 58 n = add n 1 59 x = div x 10 60 if eq x 0 61 break 62 end 63 end 64 for i ulong n 65 put out i get rev sub sub n 1 i 66 end 67 w = write fd out 0 n 68 end 69 70 fn hv_ck ok bool to void 71 put HvC 0 add get HvC 0 1 72 if not ok 73 put HvC 1 add get HvC 1 1 74 w = write 1 HvFail 0 len HvFail 75 hv_num 1 get HvC 0 76 w = write 1 HvNL 0 1 77 end 78 end 79 80 fn hv_rc got ulong wt ulong to void 81 hv_ck eq got wt 82 end 83 84 note The caller's output buffer: fill, little-endian reads and writes. 85 fn hv_fill v ulong n ulong to void 86 for i ulong n 87 put HvO i uchar v 88 end 89 end 90 91 fn hv_o32 at ulong to ulong 92 r = ulong 0 93 for i ulong 4 94 r = or r shl ulong get HvO add at i mul 8 i 95 end 96 ret r 97 end 98 99 fn hv_o64 at ulong to ulong 100 r = ulong 0 101 for i ulong 8 102 r = or r shl ulong get HvO add at i mul 8 i 103 end 104 ret r 105 end 106 107 fn hv_p32 at ulong v ulong to void 108 for i ulong 4 109 put HvO add at i uchar and shr v mul 8 i 255 110 end 111 end 112 113 note strcmp(HvO, text) == 0 for the three expected strings. 114 fn hv_isnm to bool 115 n = len HvNm 116 for i ulong n 117 if ne get HvO i get HvNm i 118 ret false 119 end 120 end 121 ret eq get HvO n 0 122 end 123 124 fn hv_isu0 to bool 125 n = len HvU0 126 for i ulong n 127 if ne get HvO i get HvU0 i 128 ret false 129 end 130 end 131 ret eq get HvO n 0 132 end 133 134 fn hv_isu1 to bool 135 n = len HvU1 136 for i ulong n 137 if ne get HvO i get HvU1 i 138 ret false 139 end 140 end 141 ret eq get HvO n 0 142 end 143 144 note fake_reset of tests/nvml/transport.c. 145 fn hv_reset st edit ulong 64 c ulong to void 146 for i ulong 64 147 put st i 0 148 end 149 put st 5 c 150 put HvC 2 0 151 end 152 153 note One fake step; a trap or refusal counts as a violation and reads as transport status 1. 154 fn hv_fstep st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 155 r = nvml_fake st h p 156 if ne r 0 157 put HvC 2 add get HvC 2 1 158 put st 13 add get st 13 1 159 ret 1 160 end 161 put HvR 0 get st 6 162 ret 0 163 end 164 165 note Copy the header and parameter spans between the step buffer and the fake (in when tofk). 166 fn hv_xfer b edit uchar BN h edit uchar HN p edit uchar PN hl ulong pl ulong tofk bool to void 167 for i ulong hl 168 if tofk 169 put h i get b i 170 else 171 put b i get h i 172 end 173 end 174 for j ulong pl 175 if tofk 176 put p j get b add PO j 177 else 178 put b add PO j get p j 179 end 180 end 181 end 182 183 note omega2_nvrm_ioctl over the fake: copy the request in, one step, copy the reply back. 184 fn hv_ioctl s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 185 hl = get s 11 186 pl = get s 12 187 if or gt hl HN gt pl PN 188 ret 32 189 end 190 if and and eq get st 5 83 eq get s 10 42 ge hl 12 191 if eq g32 b 8 `545259792` 192 ret 1 193 end 194 end 195 hv_xfer b h p hl pl true 196 put st 0 1 197 put st 1 get s 9 198 put st 2 get s 10 199 put st 3 hl 200 put st 4 pl 201 r = hv_fstep st h p 202 hv_xfer b h p hl pl false 203 ret r 204 end 205 206 fn hv_open s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 207 n = get s 13 208 if or eq n 0 gt n PN 209 ret 32 210 end 211 for i ulong n 212 put p i get b add PO i 213 end 214 put st 0 2 215 put st 7 n 216 ret hv_fstep st h p 217 end 218 219 fn hv_close s edit ulong SN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 220 put st 0 3 221 put st 1 get s 9 222 ret hv_fstep st h p 223 end 224 225 note nvml_act: perform the requested action; false is a malformed request. 226 fn hv_act s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to bool 227 k = get s 8 228 put HvR 0 0 229 if eq k 1 230 if gt get s 11 PO 231 ret false 232 end 233 if gt get s 12 sub OO PO 234 ret false 235 end 236 put s 15 hv_ioctl s b st h p 237 put s 14 get HvR 0 238 ret true 239 end 240 if eq k 2 241 if eq get s 13 0 242 ret false 243 end 244 if gt get s 13 sub OO PO 245 ret false 246 end 247 put s 15 hv_open s b st h p 248 put s 14 get HvR 0 249 ret true 250 end 251 if eq k 3 252 put s 15 hv_close s st h p 253 put s 14 get HvR 0 254 ret true 255 end 256 ret false 257 end 258 259 note The step reported done: bound the copies like nvml_run, copy out, map the status. 260 fn hv_fin s edit ulong SN b edit uchar BN to ulong 261 k = get s 7 262 sp = get HvA 7 263 if or gt k get HvA 5 and ne k 0 eq get HvA 6 0 264 ret 999 265 end 266 if ne get s 27 0 267 if or eq sp 0 gt get s 5 HvNA32 268 ret 999 269 end 270 end 271 for i ulong k 272 put HvO i get b add OO i 273 end 274 if ne get s 27 0 275 put HvV sub sp 1 get s 5 276 end 277 v = get s 6 278 if or le v 30 eq v 999 279 ret v 280 end 281 ret 999 282 end 283 284 note nvml_run: HvA holds op, four arguments, the output capacity, the output-pointer flag and 285 note the scalar slot (1+index into HvV, 0 for NULL). Returns the nvmlReturn_t value. 286 fn hv_run s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 287 rc = ulong 999 288 for i ulong 5 289 put s i get HvA i 290 end 291 put s 22 0 292 for n ulong 4096 293 if ne nvml_step s b 0 294 break 295 end 296 if eq get s 8 0 297 rc = hv_fin s b 298 break 299 end 300 if not hv_act s b st h p 301 break 302 end 303 end 304 put s 22 0 305 ret rc 306 end 307 308 fn hv_stage op ulong a1 ulong a2 ulong a3 ulong a4 ulong to void 309 put HvA 0 op 310 put HvA 1 a1 311 put HvA 2 a2 312 put HvA 3 a3 313 put HvA 4 a4 314 end 315 316 fn hv_io cap ulong outok ulong sp ulong to void 317 put HvA 5 cap 318 put HvA 6 outok 319 put HvA 7 sp 320 end 321 322 note API call arguments: hv_g sets HvG 0..2 before each entry point below. 323 fn hv_g a ulong b ulong c ulong to void 324 put HvG 0 a 325 put HvG 1 b 326 put HvG 2 c 327 end 328 329 fn hv_nz v ulong to ulong 330 if ne v 0 331 ret 1 332 end 333 ret 0 334 end 335 336 note nvml_index: the index of a handle hv_handle issued, or UINT64_MAX. 337 fn hv_idx d ulong to ulong 338 if and ge d 1 le d 8 339 ret sub d 1 340 end 341 ret HvMAX 342 end 343 344 fn hv_init s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 345 hv_stage 1 0 0 0 0 346 hv_io 0 0 0 347 ret hv_run s b st h p 348 end 349 350 fn hv_shut s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 351 hv_stage 2 0 0 0 0 352 hv_io 0 0 0 353 ret hv_run s b st h p 354 end 355 356 note count: G0 the scalar slot. 357 fn hv_count s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 358 sp = get HvG 0 359 hv_stage 3 0 hv_nz sp 0 0 360 hv_io 0 0 sp 361 ret hv_run s b st h p 362 end 363 364 note handle: G0 the index, G1 the handle slot (1+index into HvH, 0 for NULL). 365 fn hv_handle s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 366 hs = get HvG 1 367 put HvV 3 0 368 hv_stage 4 get HvG 0 hv_nz hs 0 0 369 hv_io 0 0 4 370 rc = hv_run s b st h p 371 if eq rc 0 372 i = get HvV 3 373 if ge i 8 374 ret 999 375 end 376 put HvH sub hs 1 add i 1 377 end 378 ret rc 379 end 380 381 note name and uuid: G0 the device, G1 the buffer flag, G2 the length. 382 fn hv_name s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 383 hv_stage 5 hv_idx get HvG 0 get HvG 1 get HvG 2 0 384 hv_io get HvG 2 get HvG 1 0 385 ret hv_run s b st h p 386 end 387 388 fn hv_uuid s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 389 hv_stage 6 hv_idx get HvG 0 get HvG 1 get HvG 2 0 390 hv_io get HvG 2 get HvG 1 0 391 ret hv_run s b st h p 392 end 393 394 note temperature: G0 the device, G1 the sensor, G2 the scalar slot. 395 fn hv_temp s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 396 sp = get HvG 2 397 hv_stage 7 hv_idx get HvG 0 hv_nz sp get HvG 1 0 398 hv_io 0 0 sp 399 ret hv_run s b st h p 400 end 401 402 note memory (24 bytes) and utilization (8 bytes): G0 the device, G1 the output flag. 403 fn hv_mem s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 404 hv_stage 8 hv_idx get HvG 0 get HvG 1 0 0 405 hv_io 24 get HvG 1 0 406 ret hv_run s b st h p 407 end 408 409 fn hv_util s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 410 hv_stage 9 hv_idx get HvG 0 get HvG 1 0 0 411 hv_io 8 get HvG 1 0 412 ret hv_run s b st h p 413 end 414 415 note processes: G0 the device, G1 the count slot, G2 the infos flag; capacity is 24 per entry. 416 fn hv_procs s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to ulong 417 sp = get HvG 1 418 wc = ulong 0 419 if ne sp 0 420 wc = get HvV sub sp 1 421 end 422 hv_stage 10 hv_idx get HvG 0 hv_nz sp wc get HvG 2 423 hv_io mul wc 24 get HvG 2 sp 424 ret hv_run s b st h p 425 end 426 427 note nvmlErrorString: the slot of the cached text, or 32 for the static "Unknown Error". 428 fn hv_errstr code ulong to ulong 429 o = new uchar 64 0 430 r = nvml_errstr code o 431 n = and r 255 432 sl = and shr r 8 255 433 if and lt n 64 lt sl 32 434 if eq get HvTs sl 0 435 for i ulong 64 436 put HvT add mul sl 64 i get o i 437 end 438 put HvT add mul sl 64 n 0 439 put HvTs sl 1 440 end 441 ret sl 442 end 443 ret 32 444 end 445 446 note strcmp(nvmlErrorString(code), line[wo..wo+wn)) == 0. 447 fn hv_streq sl ulong w edit uchar 65536 wo ulong wn ulong to bool 448 if eq sl 32 449 if ne wn len HvUnk 450 ret false 451 end 452 for i ulong wn 453 if ne get HvUnk i get w add wo i 454 ret false 455 end 456 end 457 ret true 458 end 459 if ge wn 64 460 ret false 461 end 462 for i ulong wn 463 if ne get HvT add mul sl 64 i get w add wo i 464 ret false 465 end 466 end 467 ret eq get HvT add mul sl 64 wn 0 468 end 469 470 note strtoll(line, NULL, 10) over fb[at..lim), then (nvmlReturn_t)(int)(unsigned) as the shell 471 note widens it: the low 32 bits, sign-extended. 472 fn hv_strtoll fb edit uchar 65536 at ulong lim ulong to ulong 473 i = at 474 while lt i lim bound 999999 475 if and ne get fb i 32 ne get fb i 9 476 break 477 end 478 i = add i 1 479 end 480 minus = false 481 if lt i lim 482 if eq get fb i 45 483 minus = true 484 i = add i 1 485 else 486 if eq get fb i 43 487 i = add i 1 488 end 489 end 490 end 491 mag = ulong 0 492 while lt i lim bound 999999 493 if or lt get fb i 48 gt get fb i 57 494 break 495 end 496 mag = add mul mag 10 ulong sub get fb i 48 497 i = add i 1 498 end 499 if minus 500 mag = sub 0 mag 501 end 502 mag = and mag HvNA32 503 if ge mag `2147483648` 504 mag = or mag `18446744069414584320` 505 end 506 ret mag 507 end 508 509 note One oracle line fb[ls..ln): false when it has no tab, else its check. 510 fn hv_row fb edit uchar 65536 ls ulong ln ulong to bool 511 tab = ls 512 while lt tab ln bound 999999 513 if eq get fb tab 9 514 break 515 end 516 tab = add tab 1 517 end 518 if ge tab ln 519 ret false 520 end 521 sl = hv_errstr hv_strtoll fb ls tab 522 hv_ck hv_streq sl fb add tab 1 sub sub ln tab 1 523 ret true 524 end 525 526 fn hv_rows fb edit uchar 65536 used ulong to ulong 527 rows = ulong 0 528 ls = ulong 0 529 while lt ls used bound 999999 530 ln = ls 531 while lt ln used bound 999999 532 if eq get fb ln 10 533 break 534 end 535 ln = add ln 1 536 end 537 if hv_row fb ls ln 538 rows = add rows 1 539 end 540 ls = add ln 1 541 end 542 ret rows 543 end 544 545 note errstrings: every row of the oracle, then the row count and pointer stability. 546 fn hv_errs ap edit uchar 4096 an ulong to void 547 fb = new uchar 65536 0 548 fd = fopen ap 0 an 0 0 549 hv_ck ge fd 0 550 if lt fd 0 551 ret 552 end 553 used = ulong 0 554 while lt used 65536 bound 999999 555 k = read int fd fb used sub 65536 used 556 if le k 0 557 break 558 end 559 used = add used ulong k 560 end 561 c = fclose int fd 562 hv_ck eq hv_rows fb used 37 563 hv_ck eq hv_errstr 0 hv_errstr 0 564 hv_ck eq hv_errstr 31 hv_errstr 999 565 end 566 567 note Output checks over HvO (and HvV), kept out of the callers' registers. 568 fn hv_memok to bool 569 if ne hv_o64 0 `131072000000` 570 ret false 571 end 572 if ne hv_o64 8 `102400000000` 573 ret false 574 end 575 ret eq hv_o64 16 `28672000000` 576 end 577 578 fn hv_utilok to bool 579 if ne hv_o32 0 42 580 ret false 581 end 582 ret eq hv_o32 4 13 583 end 584 585 fn hv_pok at ulong pid ulong used ulong to bool 586 if ne hv_o32 at pid 587 ret false 588 end 589 ret eq hv_o64 add at 8 used 590 end 591 592 note Both entries report no GPU or compute instance. 593 fn hv_naok to bool 594 if ne hv_o32 16 HvNA32 595 ret false 596 end 597 if ne hv_o32 20 HvNA32 598 ret false 599 end 600 if ne hv_o32 40 HvNA32 601 ret false 602 end 603 ret eq hv_o32 44 HvNA32 604 end 605 606 note Fault b: entry i is pid 1000+i using (1000+i)*65536 bytes. 607 fn hv_bok to bool 608 nb = ulong 0 609 for i ulong 250 610 o = mul i 24 611 if ne hv_o32 o add 1000 i 612 nb = add nb 1 613 else 614 if ne hv_o64 add o 8 mul add 1000 i 65536 615 nb = add nb 1 616 end 617 end 618 end 619 ret eq nb 0 620 end 621 622 note Fault i: the second entry's memory is NVML_VALUE_NOT_AVAILABLE. 623 fn hv_iok to bool 624 if ne get HvV 0 2 625 ret false 626 end 627 if ne hv_o64 8 `351272960` 628 ret false 629 end 630 if ne hv_o32 24 4242 631 ret false 632 end 633 ret eq hv_o64 32 HvMAX 634 end 635 636 note Every fd closed, every RM object freed, no request outside the RM contract. 637 fn hv_clean st edit ulong 64 to void 638 hv_ck eq get st 14 0 639 hv_ck eq get st 15 0 640 hv_ck eq get st 16 0 641 hv_ck eq get st 8 get st 9 642 hv_ck eq get st 13 0 643 end 644 645 fn hv_healthy s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void 646 put HvV 0 77 647 put HvV 1 0 648 put HvH 0 0 649 put HvH 1 0 650 hv_reset st 0 651 hv_g 1 0 0 652 hv_rc hv_count s b st h p 1 653 hv_g 0 1 0 654 hv_rc hv_handle s b st h p 1 655 hv_rc hv_shut s b st h p 1 656 hv_ck eq get st 8 0 657 hv_rc hv_init s b st h p 0 658 hv_g 1 0 0 659 hv_rc hv_count s b st h p 0 660 hv_ck eq get HvV 0 1 661 hv_g 0 0 0 662 hv_rc hv_count s b st h p 2 663 hv_g 0 1 0 664 hv_rc hv_handle s b st h p 0 665 hv_ck ne get HvH 0 0 666 hv_g 1 2 0 667 hv_rc hv_handle s b st h p 2 668 hv_g 0 0 0 669 hv_rc hv_handle s b st h p 2 670 d = get HvH 0 671 hv_fill 120 128 672 hv_g d 1 96 673 hv_rc hv_name s b st h p 0 674 hv_ck hv_isnm 675 hv_g d 1 11 676 hv_rc hv_name s b st h p 7 677 hv_fill 120 128 678 hv_g d 1 12 679 hv_rc hv_name s b st h p 0 680 hv_ck hv_isnm 681 hv_g 0 1 64 682 hv_rc hv_name s b st h p 2 683 hv_g HvFOR 1 64 684 hv_rc hv_name s b st h p 2 685 hv_g d 0 64 686 hv_rc hv_name s b st h p 2 687 hv_fill 120 128 688 hv_g d 1 96 689 hv_rc hv_uuid s b st h p 0 690 hv_ck hv_isu0 691 hv_g d 1 40 692 hv_rc hv_uuid s b st h p 7 693 hv_fill 120 128 694 hv_g d 1 41 695 hv_rc hv_uuid s b st h p 0 696 hv_ck hv_isu0 697 hv_g d 0 80 698 hv_rc hv_uuid s b st h p 2 699 hv_g d 0 2 700 hv_rc hv_temp s b st h p 0 701 hv_ck eq get HvV 1 40 702 hv_g d 1 2 703 hv_rc hv_temp s b st h p 2 704 hv_g d 0 0 705 hv_rc hv_temp s b st h p 2 706 hv_fill 165 24 707 hv_g d 1 0 708 hv_rc hv_mem s b st h p 0 709 hv_ck hv_memok 710 hv_g d 0 0 711 hv_rc hv_mem s b st h p 2 712 hv_p32 0 77 713 hv_p32 4 77 714 hv_g d 1 0 715 hv_rc hv_util s b st h p 0 716 hv_ck hv_utilok 717 hv_g d 0 0 718 hv_rc hv_util s b st h p 2 719 put HvV 0 0 720 hv_g d 1 0 721 hv_rc hv_procs s b st h p 7 722 hv_ck eq get HvV 0 2 723 put HvV 0 1 724 hv_g d 1 1 725 hv_rc hv_procs s b st h p 7 726 hv_ck eq get HvV 0 2 727 put HvV 0 2 728 hv_g d 1 0 729 hv_rc hv_procs s b st h p 2 730 hv_g d 0 1 731 hv_rc hv_procs s b st h p 2 732 hv_fill 0 120 733 put HvV 0 5 734 hv_g d 1 1 735 hv_rc hv_procs s b st h p 0 736 hv_ck eq get HvV 0 2 737 hv_ck hv_pok 0 68451 `351272960` 738 hv_ck hv_pok 24 4242 `278003712` 739 hv_ck hv_naok 740 hv_ck eq hv_o32 48 0 741 hv_rc hv_shut s b st h p 0 742 hv_g 1 0 0 743 hv_rc hv_count s b st h p 1 744 hv_g d 1 64 745 hv_rc hv_name s b st h p 1 746 hv_rc hv_shut s b st h p 1 747 hv_clean st 748 end 749 750 note nvmlInit/nvmlShutdown keep a reference count; only the last shutdown tears down. 751 fn hv_refcount s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void 752 put HvV 0 0 753 hv_reset st 0 754 hv_rc hv_init s b st h p 0 755 opens = get st 8 756 hv_ck eq opens 2 757 hv_rc hv_init s b st h p 0 758 hv_ck eq get st 8 opens 759 hv_rc hv_shut s b st h p 0 760 hv_g 1 0 0 761 hv_rc hv_count s b st h p 0 762 hv_ck eq get st 9 0 763 hv_rc hv_shut s b st h p 0 764 hv_g 1 0 0 765 hv_rc hv_count s b st h p 1 766 hv_clean st 767 hv_rc hv_init s b st h p 0 768 hv_rc hv_shut s b st h p 0 769 hv_clean st 770 end 771 772 note A fault-table return code: a digit, F for GPU_IS_LOST (15) or U for UNKNOWN (999). 773 fn hv_code c uchar to ulong 774 if eq c 85 775 ret 999 776 end 777 if eq c 70 778 ret 15 779 end 780 ret ulong sub c 48 781 end 782 783 note Fault COUNT: the device count, then (fault 0 aside) both handles, their UUIDs and sensors. 784 fn hv_cnt s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void 785 hv_g 1 0 0 786 hv_rc hv_count s b st h p get HvF 3 787 if eq get HvF 0 48 788 hv_ck eq get HvV 0 0 789 hv_g 0 1 0 790 hv_rc hv_handle s b st h p 2 791 ret 792 end 793 hv_ck eq get HvV 0 2 794 put HvH 2 0 795 put HvH 1 0 796 hv_g 0 3 0 797 hv_rc hv_handle s b st h p 0 798 hv_g 1 2 0 799 hv_rc hv_handle s b st h p 0 800 hv_ck ne get HvH 2 get HvH 1 801 hv_g get HvH 1 1 96 802 hv_rc hv_uuid s b st h p 0 803 hv_ck hv_isu1 804 hv_g get HvH 2 1 96 805 hv_rc hv_uuid s b st h p 0 806 hv_ck hv_isu0 807 hv_g get HvH 1 0 2 808 hv_rc hv_temp s b st h p 0 809 hv_ck eq get HvV 1 41 810 hv_g 2 1 0 811 hv_rc hv_handle s b st h p 2 812 end 813 814 note Fault PROCS: the process list and the letter's extra checks. 815 fn hv_pcall s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void 816 letter = get HvF 0 817 put HvV 0 256 818 hv_fill 0 6144 819 hv_g get HvH 0 1 1 820 hv_rc hv_procs s b st h p get HvF 3 821 if eq letter 108 822 hv_ck eq get HvV 0 0 823 end 824 if eq letter 98 825 hv_ck eq get HvV 0 250 826 hv_ck hv_bok 827 put HvV 0 249 828 hv_g get HvH 0 1 1 829 hv_rc hv_procs s b st h p 7 830 hv_ck eq get HvV 0 250 831 end 832 if eq letter 105 833 hv_ck hv_iok 834 end 835 end 836 837 note The faulted call of kinds NAME..UTIL, which must return the table's code. 838 fn hv_call s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN to void 839 kind = get HvF 2 840 d = get HvH 0 841 if eq kind 2 842 hv_g d 1 96 843 hv_rc hv_name s b st h p get HvF 3 844 end 845 if eq kind 3 846 hv_g d 1 96 847 hv_rc hv_uuid s b st h p get HvF 3 848 end 849 if eq kind 4 850 hv_g d 0 2 851 hv_rc hv_temp s b st h p get HvF 3 852 end 853 if eq kind 5 854 hv_g d 1 0 855 hv_rc hv_mem s b st h p get HvF 3 856 end 857 if eq kind 6 858 hv_g d 1 0 859 hv_rc hv_util s b st h p get HvF 3 860 end 861 end 862 863 note one(): row f of the fault table; HvF holds its letter, init code, call kind and call code. 864 fn hv_one s edit ulong SN b edit uchar BN st edit ulong 64 h edit uchar HN p edit uchar PN f ulong to void 865 put HvF 0 ulong get HvFl f 866 put HvF 1 hv_code get HvFi f 867 put HvF 2 ulong sub get HvFc f 48 868 put HvF 3 hv_code get HvFr f 869 put HvV 0 0 870 put HvV 1 0 871 put HvH 0 0 872 hv_reset st get HvF 0 873 r = hv_init s b st h p 874 hv_ck eq r get HvF 1 875 if ne r 0 876 hv_g 1 0 0 877 hv_rc hv_count s b st h p 1 878 hv_clean st 879 ret 880 end 881 kind = get HvF 2 882 if ne kind 1 883 hv_g 0 1 0 884 hv_rc hv_handle s b st h p 0 885 end 886 if eq kind 1 887 hv_cnt s b st h p 888 end 889 hv_call s b st h p 890 if eq kind 7 891 hv_pcall s b st h p 892 end 893 if eq get HvF 0 102 894 hv_rc hv_shut s b st h p 999 895 hv_g 1 0 0 896 hv_rc hv_count s b st h p 1 897 hv_ck eq get st 14 0 898 hv_ck eq get st 13 0 899 ret 900 end 901 hv_rc hv_shut s b st h p 0 902 hv_clean st 903 end 904 905 fn main to int 906 c = argcnt 907 if ne c 2 908 w = write 2 HvUse 0 len HvUse 909 ret 2 910 end 911 s = new ulong SN 0 912 b = new uchar BN 0 913 st = new ulong 64 0 914 h = new uchar HN 0 915 p = new uchar PN 0 916 ap = new uchar 4096 0 917 an = argread 1 ap 0 4096 918 if lt an 0 919 hv_ck false 920 else 921 hv_errs ap ulong an 922 end 923 hv_healthy s b st h p 924 hv_refcount s b st h p 925 for f ulong 33 926 hv_one s b st h p f 927 end 928 hv_healthy s b st h p 929 hv_ck eq get HvC 2 0 930 if ne get HvC 1 0 931 w = write 1 HvBad 0 len HvBad 932 hv_num 1 get HvC 1 933 w = write 1 HvOf 0 len HvOf 934 hv_num 1 get HvC 0 935 w = write 1 HvChk 0 len HvChk 936 ret 1 937 end 938 w = write 1 HvPass 0 len HvPass 939 hv_num 1 get HvC 0 940 w = write 1 HvChk 0 len HvChk 941 ret 0 942 end