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
CUDApp / evidence / AMD-KFD-LAUNCH3 / launch-x86.om
| 1 | target x86linux |
| 2 | om2 |
| 3 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | note Concatenate common, elf, device, dispatch, main, then existing cli.om under om2. |
| 5 | note Fixed arrays below are Linux pathname or ABI records, not input-size limits. |
| 6 | global pathbuf uchar 4096 |
| 7 | global chunk uchar 4096 |
| 8 | global hdr uchar 88 |
| 9 | global ids uchar 4 |
| 10 | global one uchar 1 |
| 11 | text newline "\n" |
| 12 | text failed "OMEGA error=" |
| 13 | text kfdpath "/dev/kfd" |
| 14 | global stepname uchar 64 |
| 15 | note This internal label buffer holds only the literal step names below, never caller input. |
| 16 | global stepstate ulong 2 |
| 17 | text stepprefix "OMEGA step " |
| 18 | text stepok " ok errno=0" |
| 19 | text stepfail " fail errno=" |
| 20 | text stepbefore " phase=before detail=" |
| 21 | text stepafter " phase=after detail=" |
| 22 | text stopen "open_kfd" |
| 23 | text stversion "version" |
| 24 | text sttop "topology" |
| 25 | text stnode "topology_node" |
| 26 | text strender "render_open" |
| 27 | text stvm "acquire_vm" |
| 28 | text streserve "memory_reserve" |
| 29 | text stalloc "memory_alloc" |
| 30 | text stmap "memory_map" |
| 31 | text stbind "memory_cpu_map" |
| 32 | text stqueue "queue_create" |
| 33 | text stbell "doorbell_map" |
| 34 | text stload "code_object_load" |
| 35 | text stdispatch "dispatch" |
| 36 | text stwait "signal_wait" |
| 37 | text streadback "readback" |
| 38 | text stcleanup "cleanup" |
| 39 | fn steprow err ulong before bool to void |
| 40 | r = write 1 stepprefix 0 len stepprefix |
| 41 | r = write 1 stepname 0 get stepstate 0 |
| 42 | if eq err 0 |
| 43 | r = write 1 stepok 0 len stepok |
| 44 | else |
| 45 | r = write 1 stepfail 0 len stepfail |
| 46 | printnum err |
| 47 | end |
| 48 | if before |
| 49 | r = write 1 stepbefore 0 len stepbefore |
| 50 | else |
| 51 | r = write 1 stepafter 0 len stepafter |
| 52 | end |
| 53 | printnum get stepstate 1 |
| 54 | r = write 1 newline 0 len newline |
| 55 | end |
| 56 | fn stepbegin name view uchar * detail ulong to void |
| 57 | for i ulong len name bound 64 |
| 58 | put stepname i get name i |
| 59 | end |
| 60 | put stepstate 0 len name |
| 61 | put stepstate 1 detail |
| 62 | steprow 0 true |
| 63 | end |
| 64 | fn stepend to void |
| 65 | steprow 0 false |
| 66 | end |
| 67 | fn stepresult r long to long |
| 68 | if lt r 0 |
| 69 | steprow ulong neg r false |
| 70 | else |
| 71 | stepend |
| 72 | end |
| 73 | ret r |
| 74 | end |
| 75 | fn checked r long to long |
| 76 | if lt r 0 |
| 77 | steprow ulong neg r false |
| 78 | emit failed |
| 79 | if eq r -9223372036854775808 |
| 80 | exit 74 |
| 81 | end |
| 82 | printnum ulong neg r |
| 83 | emit newline |
| 84 | exit 74 |
| 85 | end |
| 86 | ret r |
| 87 | end |
| 88 | fn printnum v ulong to void |
| 89 | b = new uchar 20 0 |
| 90 | p = ulong 20 |
| 91 | while gt v 9 bound 20 |
| 92 | p = sub p 1 |
| 93 | put b p uchar add rem v 10 48 |
| 94 | v = div v 10 |
| 95 | end |
| 96 | p = sub p 1 |
| 97 | put b p uchar add v 48 |
| 98 | emit part b p sub 20 p |
| 99 | end |
| 100 | fn roundup n ulong a ulong to ulong |
| 101 | if gt n sub 9223372036854775807 sub a 1 |
| 102 | exit 65 |
| 103 | end |
| 104 | ret mul div add n sub a 1 a a |
| 105 | end |
| 106 | fn patharg i ulong to ulong |
| 107 | n = argread i pathbuf 0 len pathbuf |
| 108 | if lt n 1 |
| 109 | exit 64 |
| 110 | end |
| 111 | ret ulong n |
| 112 | end |
| 113 | fn argfile i ulong flags int to int |
| 114 | n = patharg i |
| 115 | ret int checked fopen pathbuf 0 n flags 384 |
| 116 | end |
| 117 | fn filesize fd int to ulong |
| 118 | n = checked fseek fd 0 2 |
| 119 | r = checked fseek fd 0 0 |
| 120 | ret ulong n |
| 121 | end |
| 122 | fn zerohdr to void |
| 123 | for i ulong 88 |
| 124 | put hdr i 0 |
| 125 | end |
| 126 | end |
| 127 | fn hput off ulong width ulong v ulong to void |
| 128 | for i ulong width |
| 129 | put hdr add off i uchar and shr v mul i 8 255 |
| 130 | end |
| 131 | end |
| 132 | fn hget off ulong width ulong to ulong |
| 133 | v = ulong 0 |
| 134 | for i ulong width |
| 135 | v = or v shl ulong get hdr add off i mul i 8 |
| 136 | end |
| 137 | ret v |
| 138 | end |
| 139 | fn fword fd int off ulong width ulong to ulong |
| 140 | b = new uchar 8 0 |
| 141 | r = pread fd b 0 width long off |
| 142 | if ne r long width |
| 143 | exit 65 |
| 144 | end |
| 145 | v = ulong 0 |
| 146 | for i ulong width |
| 147 | v = or v shl ulong get b i mul i 8 |
| 148 | end |
| 149 | ret v |
| 150 | end |
| 151 | fn byteat fd int off ulong to uchar |
| 152 | r = pread fd one 0 1 long off |
| 153 | if ne r 1 |
| 154 | exit 65 |
| 155 | end |
| 156 | ret get one 0 |
| 157 | end |
| 158 | fn filecopy fd int src ulong dst long off ulong n ulong to void |
| 159 | p = ulong 0 |
| 160 | while lt p n bound 9223372036854775807 |
| 161 | k = sub n p |
| 162 | if gt k len chunk |
| 163 | k = len chunk |
| 164 | end |
| 165 | r = checked pread fd chunk 0 k long add src p |
| 166 | if eq r 0 |
| 167 | exit 65 |
| 168 | end |
| 169 | r = checked mapwrite dst add off p chunk 0 ulong r |
| 170 | p = add p ulong r |
| 171 | end |
| 172 | end |
| 173 | fn zeromap dst long off ulong n ulong to void |
| 174 | for i ulong len chunk bound 4096 |
| 175 | put chunk i 0 |
| 176 | end |
| 177 | p = ulong 0 |
| 178 | while lt p n bound 9223372036854775807 |
| 179 | k = sub n p |
| 180 | if gt k len chunk |
| 181 | k = len chunk |
| 182 | end |
| 183 | r = checked mapwrite dst add off p chunk 0 k |
| 184 | p = add p k |
| 185 | end |
| 186 | end |
| 187 | fn savefile fd int src long n ulong to void |
| 188 | p = ulong 0 |
| 189 | while lt p n bound 9223372036854775807 |
| 190 | k = sub n p |
| 191 | if gt k len chunk |
| 192 | k = len chunk |
| 193 | end |
| 194 | r = checked mapread src p chunk 0 k |
| 195 | q = ulong 0 |
| 196 | while lt q k bound 9223372036854775807 |
| 197 | r = checked write fd chunk q sub k q |
| 198 | if eq r 0 |
| 199 | exit 74 |
| 200 | end |
| 201 | q = add q ulong r |
| 202 | end |
| 203 | p = add p k |
| 204 | end |
| 205 | end |
| 206 | fn span off ulong n ulong total ulong to void |
| 207 | if gt off total |
| 208 | exit 65 |
| 209 | end |
| 210 | if gt n sub total off |
| 211 | exit 65 |
| 212 | end |
| 213 | end |
| 214 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 215 | note ELF64 HSA v5 gfx942 images emitted by backend/amd/gfx942/hsaco.om. |
| 216 | note el: fd,size,phoff,phnum,shoff,shnum,kdVA,imageBytes,kernarg,group,private,kdFile. |
| 217 | global el ulong 12 |
| 218 | fn ew off ulong width ulong to ulong |
| 219 | ret fword int get el 0 off width |
| 220 | end |
| 221 | fn ph i ulong to ulong |
| 222 | ret add get el 2 mul i 56 |
| 223 | end |
| 224 | fn sh i ulong to ulong |
| 225 | ret add get el 4 mul i 64 |
| 226 | end |
| 227 | fn vaoff va ulong n ulong to ulong |
| 228 | for i ulong get el 3 bound 65535 |
| 229 | p = ph i |
| 230 | if eq ew p 4 1 |
| 231 | base = ew add p 16 8 |
| 232 | if ge va base |
| 233 | d = sub va base |
| 234 | sz = ew add p 32 8 |
| 235 | if le d sz |
| 236 | if le n sub sz d |
| 237 | ret add ew add p 8 8 d |
| 238 | end |
| 239 | end |
| 240 | end |
| 241 | end |
| 242 | end |
| 243 | exit 65 |
| 244 | end |
| 245 | fn symmatch off ulong size ulong namelen ulong to bool |
| 246 | if lt size add namelen 4 |
| 247 | ret false |
| 248 | end |
| 249 | for i ulong namelen bound 4096 |
| 250 | if ne byteat int get el 0 add off i get pathbuf i |
| 251 | ret false |
| 252 | end |
| 253 | end |
| 254 | if ne byteat int get el 0 add off namelen 46 |
| 255 | ret false |
| 256 | end |
| 257 | if ne byteat int get el 0 add add off namelen 1 107 |
| 258 | ret false |
| 259 | end |
| 260 | if ne byteat int get el 0 add add off namelen 2 100 |
| 261 | ret false |
| 262 | end |
| 263 | ret eq byteat int get el 0 add add off namelen 3 0 |
| 264 | end |
| 265 | fn acceptsym s ulong to void |
| 266 | if or ne ew add s 4 1 17 ne ew add s 16 8 64 |
| 267 | exit 65 |
| 268 | end |
| 269 | v = ew add s 8 8 |
| 270 | if ne get el 6 0 |
| 271 | if ne get el 6 v |
| 272 | exit 65 |
| 273 | end |
| 274 | end |
| 275 | if ne rem v 64 0 |
| 276 | exit 65 |
| 277 | end |
| 278 | put el 6 v |
| 279 | end |
| 280 | fn findsym sec ulong namelen ulong to void |
| 281 | linkidx = ew add sec 40 4 |
| 282 | if ge linkidx get el 5 |
| 283 | exit 65 |
| 284 | end |
| 285 | strsec = sh linkidx |
| 286 | if ne ew add strsec 4 4 3 |
| 287 | exit 65 |
| 288 | end |
| 289 | strbase = ew add strsec 24 8 |
| 290 | strsize = ew add strsec 32 8 |
| 291 | span strbase strsize get el 1 |
| 292 | base = ew add sec 24 8 |
| 293 | size = ew add sec 32 8 |
| 294 | span base size get el 1 |
| 295 | if or ne ew add sec 56 8 24 ne rem size 24 0 |
| 296 | exit 65 |
| 297 | end |
| 298 | for i ulong div size 24 bound 9223372036854775807 |
| 299 | s = add base mul i 24 |
| 300 | noff = ew s 4 |
| 301 | if ge noff strsize |
| 302 | exit 65 |
| 303 | end |
| 304 | if symmatch add strbase noff sub strsize noff namelen |
| 305 | acceptsym s |
| 306 | end |
| 307 | end |
| 308 | end |
| 309 | fn segment i ulong to void |
| 310 | p = ph i |
| 311 | if eq ew p 4 1 |
| 312 | base = ew add p 16 8 |
| 313 | sz = ew add p 32 8 |
| 314 | memsz = ew add p 40 8 |
| 315 | span ew add p 8 8 sz get el 1 |
| 316 | if gt sz memsz |
| 317 | exit 65 |
| 318 | end |
| 319 | span base memsz 9223372036854775807 |
| 320 | last = add base memsz |
| 321 | if gt last get el 7 |
| 322 | put el 7 last |
| 323 | end |
| 324 | for j ulong i bound 65535 |
| 325 | q = ph j |
| 326 | if eq ew q 4 1 |
| 327 | qb = ew add q 16 8 |
| 328 | qe = add qb ew add q 40 8 |
| 329 | if and lt base qe lt qb last |
| 330 | exit 65 |
| 331 | end |
| 332 | end |
| 333 | end |
| 334 | end |
| 335 | end |
| 336 | fn parseelf objarg ulong namearg ulong to void |
| 337 | fd = argfile objarg 0 |
| 338 | put el 0 ulong fd |
| 339 | put el 1 filesize fd |
| 340 | span 0 64 get el 1 |
| 341 | if or ne ew 0 4 1179403647 ne ew 4 4 1073807618 |
| 342 | exit 65 |
| 343 | end |
| 344 | if or ne ew 8 1 3 ne ew 16 4 14680067 |
| 345 | exit 65 |
| 346 | end |
| 347 | if or ne ew 20 4 1 ne ew 52 2 64 |
| 348 | exit 65 |
| 349 | end |
| 350 | if or ne ew 54 2 56 ne ew 58 2 64 |
| 351 | exit 65 |
| 352 | end |
| 353 | note gfx942 machine selection; XNACK/SRAMECC any or enabled are accepted. |
| 354 | if ne and ew 48 4 255 76 |
| 355 | exit 65 |
| 356 | end |
| 357 | put el 2 ew 32 8 |
| 358 | put el 3 ew 56 2 |
| 359 | put el 4 ew 40 8 |
| 360 | put el 5 ew 60 2 |
| 361 | span get el 2 mul get el 3 56 get el 1 |
| 362 | span get el 4 mul get el 5 64 get el 1 |
| 363 | for i ulong get el 3 bound 65535 |
| 364 | segment i |
| 365 | end |
| 366 | if eq get el 7 0 |
| 367 | exit 65 |
| 368 | end |
| 369 | namelen = patharg namearg |
| 370 | for i ulong get el 5 bound 65535 |
| 371 | s = sh i |
| 372 | t = ew add s 4 4 |
| 373 | if or eq t 4 eq t 9 |
| 374 | if ne ew add s 32 8 0 |
| 375 | exit 65 |
| 376 | end |
| 377 | end |
| 378 | if or eq t 2 eq t 11 |
| 379 | findsym s namelen |
| 380 | end |
| 381 | end |
| 382 | if eq get el 6 0 |
| 383 | exit 65 |
| 384 | end |
| 385 | d = vaoff get el 6 64 |
| 386 | put el 11 d |
| 387 | put el 8 ew add d 8 4 |
| 388 | put el 9 ew d 4 |
| 389 | put el 10 ew add d 4 4 |
| 390 | note This writer declares no private segment or hidden ABI arguments. |
| 391 | if or ne get el 10 0 gt get el 9 65536 |
| 392 | exit 65 |
| 393 | end |
| 394 | if ne and ew add d 56 2 1024 0 |
| 395 | exit 65 |
| 396 | end |
| 397 | entry = bitcast long ew add d 16 8 |
| 398 | if lt entry 0 |
| 399 | exit 65 |
| 400 | end |
| 401 | v = add get el 6 ulong entry |
| 402 | q = vaoff v 4 |
| 403 | end |
| 404 | fn loadelf dst long to void |
| 405 | for i ulong get el 3 bound 65535 |
| 406 | p = ph i |
| 407 | if eq ew p 4 1 |
| 408 | filecopy int get el 0 ew add p 8 8 dst ew add p 16 8 ew add p 32 8 |
| 409 | zeromap dst add ew add p 16 8 ew add p 32 8 sub ew add p 40 8 ew add p 32 8 |
| 410 | end |
| 411 | end |
| 412 | end |
| 413 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 414 | note dev: kfd,render,gpu,simds,simdpercu,arrays,arraysperengine,xcc,ctxperxcc,ctl,debug. |
| 415 | global dev ulong 11 |
| 416 | global dirbuf uchar 4096 |
| 417 | global nodepath uchar 4096 |
| 418 | global noden ulong 1 |
| 419 | global nodeerr long 1 |
| 420 | global nodenum ulong 1 |
| 421 | text selected "OMEGA topology selected node=" |
| 422 | text gpulabel " gpu_id=" |
| 423 | text minorlabel " render_minor=" |
| 424 | text cpuskip "OMEGA topology skip CPU gpu_id=0\n" |
| 425 | text nodes "/sys/class/kfd/kfd/topology/nodes/" |
| 426 | text props "/properties" |
| 427 | text gpufile "/gpu_id" |
| 428 | text render "/dev/dri/renderD" |
| 429 | text gfxkey "gfx_target_version" |
| 430 | text drmkey "drm_render_minor" |
| 431 | text simdkey "simd_count" |
| 432 | text cukey "simd_per_cu" |
| 433 | text arrkey "array_count" |
| 434 | text engkey "simd_arrays_per_engine" |
| 435 | text xcckey "num_xcc" |
| 436 | text absent "OMEGA device=absent errno=2\n" |
| 437 | fn addpath b view uchar * p ulong to ulong |
| 438 | span p len b len pathbuf |
| 439 | for i ulong len b bound 4096 |
| 440 | put pathbuf add p i get b i |
| 441 | end |
| 442 | ret add p len b |
| 443 | end |
| 444 | fn nodefile suffix view uchar * to long |
| 445 | n = get noden 0 |
| 446 | for i ulong n bound 4096 |
| 447 | put pathbuf i get nodepath i |
| 448 | end |
| 449 | n = addpath suffix n |
| 450 | ret fopen pathbuf 0 n 0 0 |
| 451 | end |
| 452 | fn propvalue fd int key view uchar * to ulong |
| 453 | r = fseek fd 0 0 |
| 454 | if lt r 0 |
| 455 | put nodeerr 0 r |
| 456 | ret 0 |
| 457 | end |
| 458 | idx = ulong 0 |
| 459 | match = true |
| 460 | value = ulong 0 |
| 461 | number = false |
| 462 | while true bound 9223372036854775807 |
| 463 | r = read fd one 0 1 |
| 464 | if le r 0 |
| 465 | put nodeerr 0 r |
| 466 | if eq r 0 |
| 467 | put nodeerr 0 -22 |
| 468 | end |
| 469 | ret 0 |
| 470 | end |
| 471 | c = get one 0 |
| 472 | if eq c 10 |
| 473 | if and match number |
| 474 | ret value |
| 475 | end |
| 476 | idx = ulong 0 |
| 477 | match = true |
| 478 | number = false |
| 479 | value = ulong 0 |
| 480 | continue |
| 481 | end |
| 482 | if number |
| 483 | if match |
| 484 | if or lt c 48 gt c 57 |
| 485 | put nodeerr 0 -22 |
| 486 | ret 0 |
| 487 | end |
| 488 | if gt value div sub ulong 18446744073709551615 ulong sub c 48 10 |
| 489 | put nodeerr 0 -22 |
| 490 | ret 0 |
| 491 | end |
| 492 | value = add mul value 10 ulong sub c 48 |
| 493 | end |
| 494 | else |
| 495 | if eq c 32 |
| 496 | if ne idx len key |
| 497 | match = false |
| 498 | end |
| 499 | number = true |
| 500 | else |
| 501 | if lt idx len key |
| 502 | if ne c get key idx |
| 503 | match = false |
| 504 | end |
| 505 | else |
| 506 | match = false |
| 507 | end |
| 508 | idx = add idx 1 |
| 509 | end |
| 510 | end |
| 511 | end |
| 512 | ret 0 |
| 513 | end |
| 514 | fn nodecheck to bool |
| 515 | put nodeerr 0 0 |
| 516 | stepbegin stnode get nodenum 0 |
| 517 | fd = nodefile gpufile |
| 518 | if lt fd 0 |
| 519 | r = stepresult fd |
| 520 | ret false |
| 521 | end |
| 522 | v = ulong 0 |
| 523 | while true bound 9223372036854775807 |
| 524 | r = read int fd one 0 1 |
| 525 | if lt r 0 |
| 526 | put nodeerr 0 r |
| 527 | break |
| 528 | end |
| 529 | if eq r 0 |
| 530 | break |
| 531 | end |
| 532 | c = get one 0 |
| 533 | if eq c 10 |
| 534 | break |
| 535 | end |
| 536 | if or lt c 48 gt c 57 |
| 537 | put nodeerr 0 -22 |
| 538 | break |
| 539 | end |
| 540 | if gt v 429496729 |
| 541 | put nodeerr 0 -22 |
| 542 | break |
| 543 | end |
| 544 | v = add mul v 10 ulong sub c 48 |
| 545 | end |
| 546 | r = fclose int fd |
| 547 | if lt get nodeerr 0 0 |
| 548 | r = stepresult get nodeerr 0 |
| 549 | ret false |
| 550 | end |
| 551 | if eq v 0 |
| 552 | stepend |
| 553 | emit cpuskip |
| 554 | ret false |
| 555 | end |
| 556 | if gt v 4294967295 |
| 557 | r = stepresult -22 |
| 558 | ret false |
| 559 | end |
| 560 | fd = nodefile props |
| 561 | if lt fd 0 |
| 562 | r = stepresult fd |
| 563 | ret false |
| 564 | end |
| 565 | gfx = propvalue int fd gfxkey |
| 566 | if or ne gfx 90402 lt get nodeerr 0 0 |
| 567 | r = fclose int fd |
| 568 | r = stepresult get nodeerr 0 |
| 569 | ret false |
| 570 | end |
| 571 | put dev 1 propvalue int fd drmkey |
| 572 | put dev 3 propvalue int fd simdkey |
| 573 | put dev 4 propvalue int fd cukey |
| 574 | put dev 5 propvalue int fd arrkey |
| 575 | put dev 6 propvalue int fd engkey |
| 576 | put dev 7 propvalue int fd xcckey |
| 577 | r = fclose int fd |
| 578 | if lt get nodeerr 0 0 |
| 579 | r = stepresult get nodeerr 0 |
| 580 | ret false |
| 581 | end |
| 582 | put dev 2 v |
| 583 | stepend |
| 584 | emit selected |
| 585 | printnum get nodenum 0 |
| 586 | emit gpulabel |
| 587 | printnum v |
| 588 | emit minorlabel |
| 589 | printnum get dev 1 |
| 590 | emit newline |
| 591 | ret true |
| 592 | end |
| 593 | fn nodigit c uchar to void |
| 594 | put nodenum 0 add mul get nodenum 0 10 ulong sub c 48 |
| 595 | end |
| 596 | fn topology to void |
| 597 | note O_DIRECTORY differs across ARM64 and x86. getdnts verifies the read-only fd. |
| 598 | stepbegin sttop 0 |
| 599 | dfd = int checked fopen nodes 0 len nodes 0 0 |
| 600 | found = false |
| 601 | while not found bound 9223372036854775807 |
| 602 | r = checked getdnts dfd dirbuf 0 len dirbuf |
| 603 | if eq r 0 |
| 604 | stepbegin sttop 0 |
| 605 | steprow 19 false |
| 606 | exit 66 |
| 607 | end |
| 608 | p = ulong 0 |
| 609 | while lt p ulong r bound 4096 |
| 610 | span p 20 ulong r |
| 611 | sz = add ulong get dirbuf add p 16 shl ulong get dirbuf add p 17 8 |
| 612 | if lt sz 20 |
| 613 | exit 66 |
| 614 | end |
| 615 | span p sz ulong r |
| 616 | c = get dirbuf add p 19 |
| 617 | if and ge c 48 le c 57 |
| 618 | n = len nodes |
| 619 | for i ulong n bound 4096 |
| 620 | put nodepath i get nodes i |
| 621 | end |
| 622 | j = add p 19 |
| 623 | put nodenum 0 0 |
| 624 | while true bound 4096 |
| 625 | if ge j add p sz |
| 626 | exit 66 |
| 627 | end |
| 628 | if eq get dirbuf j 0 |
| 629 | break |
| 630 | end |
| 631 | if ge n len nodepath |
| 632 | exit 66 |
| 633 | end |
| 634 | c = get dirbuf j |
| 635 | if or lt c 48 gt c 57 |
| 636 | exit 66 |
| 637 | end |
| 638 | nodigit c |
| 639 | put nodepath n get dirbuf j |
| 640 | n = add n 1 |
| 641 | j = add j 1 |
| 642 | end |
| 643 | put noden 0 n |
| 644 | if nodecheck |
| 645 | found = true |
| 646 | break |
| 647 | end |
| 648 | end |
| 649 | p = add p sz |
| 650 | end |
| 651 | end |
| 652 | r = checked fclose dfd |
| 653 | stepbegin sttop get nodenum 0 |
| 654 | stepend |
| 655 | n = addpath render 0 |
| 656 | minor = get dev 1 |
| 657 | if gt minor 4294967295 |
| 658 | exit 66 |
| 659 | end |
| 660 | b = new uchar 10 0 |
| 661 | p = ulong 10 |
| 662 | while gt minor 9 bound 10 |
| 663 | p = sub p 1 |
| 664 | put b p uchar add rem minor 10 48 |
| 665 | minor = div minor 10 |
| 666 | end |
| 667 | p = sub p 1 |
| 668 | put b p uchar add minor 48 |
| 669 | n = addpath part b p sub 10 p n |
| 670 | stepbegin strender get dev 1 |
| 671 | note No arbitrary alternate minor: ACQUIRE_VM must bind the selected GPU's render device. |
| 672 | put dev 1 ulong checked fopen pathbuf 0 n 2 0 |
| 673 | stepend |
| 674 | end |
| 675 | fn connectkfd to void |
| 676 | stepbegin stopen 0 |
| 677 | fd = fopen kfdpath 0 len kfdpath 2 0 |
| 678 | if eq fd -2 |
| 679 | steprow 2 false |
| 680 | emit absent |
| 681 | exit 77 |
| 682 | end |
| 683 | put dev 0 ulong checked fd |
| 684 | stepend |
| 685 | stepbegin stversion 0 |
| 686 | zerohdr |
| 687 | r = checked kfdctl int fd 2148027137 hdr 0 8 |
| 688 | if or ne hget 0 4 1 lt hget 4 4 14 |
| 689 | steprow 22 false |
| 690 | exit 67 |
| 691 | end |
| 692 | stepend |
| 693 | topology |
| 694 | stepbegin stvm get dev 2 |
| 695 | zerohdr |
| 696 | hput 0 4 get dev 1 |
| 697 | hput 4 4 get dev 2 |
| 698 | r = checked kfdctl int get dev 0 1074285333 hdr 0 8 |
| 699 | stepend |
| 700 | for i ulong 4 |
| 701 | put ids i uchar and shr get dev 2 mul i 8 255 |
| 702 | end |
| 703 | end |
| 704 | fn ctxsizes to void |
| 705 | if or eq get dev 4 0 eq get dev 7 0 |
| 706 | exit 66 |
| 707 | end |
| 708 | if eq get dev 6 0 |
| 709 | exit 66 |
| 710 | end |
| 711 | cu = div div get dev 3 get dev 4 get dev 7 |
| 712 | if eq cu 0 |
| 713 | exit 66 |
| 714 | end |
| 715 | waves = mul cu 40 |
| 716 | maxwaves = mul div div get dev 5 get dev 6 get dev 6 512 |
| 717 | if lt maxwaves waves |
| 718 | waves = maxwaves |
| 719 | end |
| 720 | if eq waves 0 |
| 721 | exit 66 |
| 722 | end |
| 723 | ctl = roundup add 40 add mul waves 8 8 4096 |
| 724 | wg = roundup mul cu add add ulong 0x80000 0x4000 add ulong 0x10000 0x1000 4096 |
| 725 | put dev 8 add ctl wg |
| 726 | put dev 9 ctl |
| 727 | put dev 10 roundup mul waves 32 64 |
| 728 | if gt get dev 8 4294967295 |
| 729 | exit 66 |
| 730 | end |
| 731 | end |
| 732 | fn mapgpu kh ulong to void |
| 733 | zerohdr |
| 734 | hput 0 8 kh |
| 735 | hput 16 4 1 |
| 736 | r = checked kfdctl int get dev 0 3222817560 hdr 0 24 ids 0 4 |
| 737 | if ne hget 20 4 1 |
| 738 | steprow 5 false |
| 739 | exit 68 |
| 740 | end |
| 741 | end |
| 742 | note Allocation record on the caller's table: CPU handle, KFD handle, byte size (24 bytes). |
| 743 | fn gpumem n ulong flags ulong table long rec ulong to long |
| 744 | sz = roundup n 4096 |
| 745 | stepbegin streserve div rec 24 |
| 746 | h = checked kfdres sz |
| 747 | stepend |
| 748 | stepbegin stalloc div rec 24 |
| 749 | zerohdr |
| 750 | hput 8 8 sz |
| 751 | hput 32 4 get dev 2 |
| 752 | hput 36 4 flags |
| 753 | r = checked kfdctl int get dev 0 3223866134 hdr 0 40 h |
| 754 | kh = hget 16 8 |
| 755 | moff = hget 24 8 |
| 756 | stepend |
| 757 | r = checked mapset table rec 8 ulong h |
| 758 | r = checked mapset table add rec 8 8 kh |
| 759 | r = checked mapset table add rec 16 8 sz |
| 760 | stepbegin stmap div rec 24 |
| 761 | mapgpu kh |
| 762 | stepend |
| 763 | stepbegin stbind div rec 24 |
| 764 | r = checked mapbind h int get dev 1 moff 3 |
| 765 | stepend |
| 766 | ret h |
| 767 | end |
| 768 | fn gpufree table long rec ulong to void |
| 769 | kh = mapget table add rec 8 8 |
| 770 | zerohdr |
| 771 | hput 0 8 kh |
| 772 | hput 16 4 1 |
| 773 | r = checked kfdctl int get dev 0 3222817561 hdr 0 24 ids 0 4 |
| 774 | if ne hget 20 4 1 |
| 775 | exit 68 |
| 776 | end |
| 777 | r = checked mapdrop long mapget table rec 8 |
| 778 | zerohdr |
| 779 | hput 0 8 kh |
| 780 | r = checked kfdctl int get dev 0 1074285335 hdr 0 8 |
| 781 | end |
| 782 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 783 | note launch: table,ninputs,repeats,timeoutns,outbytes,groupsX,groupsY,queueid,bell,belloff. |
| 784 | global launch ulong 10 |
| 785 | text timed "OMEGA dispatch_ns=" |
| 786 | text repeatlabel " packets=" |
| 787 | note Diagnostics retain CPU-side inputs only; no additional device writes. |
| 788 | global queueinput ulong 11 |
| 789 | note diagstate: vadd,full doorbell offset,last packet slot. |
| 790 | global diagstate ulong 3 |
| 791 | text diagprefix "OMEGA diag " |
| 792 | text diagspace " " |
| 793 | text dread "queue_read_pointer" |
| 794 | text dwrite "queue_write_pointer" |
| 795 | text dkind "signal_kind" |
| 796 | text dvalue "signal_value" |
| 797 | text dheader "ring_header" |
| 798 | text dslot "ring_slot_byte_offset" |
| 799 | text dout "output_word_" |
| 800 | text dqueue "create_queue_input_qword_" |
| 801 | text did "queue_id" |
| 802 | text dbell "doorbell_offset" |
| 803 | text dentry "kernel_code_entry_byte_offset" |
| 804 | text drsrc1 "compute_pgm_rsrc1" |
| 805 | text drsrc2 "compute_pgm_rsrc2" |
| 806 | text drsrc3 "compute_pgm_rsrc3" |
| 807 | text dprops "kernel_code_properties" |
| 808 | text dgroup "group_segment_size" |
| 809 | text dprivate "private_segment_size" |
| 810 | text dargsize "kernarg_size" |
| 811 | text dobject "packet_kernel_object" |
| 812 | text dargaddr "packet_kernarg_address" |
| 813 | text dnan "output_first8_nan_fill_count" |
| 814 | text dsum "output_first8_expected_vadd_sum_count" |
| 815 | text dtimeout "wait_timeout_ns" |
| 816 | fn diag name view uchar * value ulong to void |
| 817 | emit diagprefix |
| 818 | emit name |
| 819 | emit diagspace |
| 820 | printnum value |
| 821 | emit newline |
| 822 | end |
| 823 | fn diagindexed name view uchar * index ulong value ulong to void |
| 824 | emit diagprefix |
| 825 | emit name |
| 826 | printnum index |
| 827 | emit diagspace |
| 828 | printnum value |
| 829 | emit newline |
| 830 | end |
| 831 | fn lh i ulong to long |
| 832 | ret long mapget long get launch 0 mul i 24 8 |
| 833 | end |
| 834 | fn allocate i ulong n ulong flags ulong to long |
| 835 | ret gpumem n flags long get launch 0 mul i 24 |
| 836 | end |
| 837 | fn diagnostics to void |
| 838 | cpufence |
| 839 | diag dread mapget lh 5 0 8 |
| 840 | diag dwrite mapget lh 4 0 8 |
| 841 | diag dkind mapget lh 7 0 8 |
| 842 | diag dvalue mapget lh 7 8 8 |
| 843 | diag dslot get diagstate 2 |
| 844 | diag dheader mapget lh 3 get diagstate 2 4 |
| 845 | diag dobject mapget lh 3 add get diagstate 2 32 8 |
| 846 | diag dargaddr mapget lh 3 add get diagstate 2 40 8 |
| 847 | diag did get launch 7 |
| 848 | diag dbell get diagstate 1 |
| 849 | for i ulong 11 |
| 850 | diagindexed dqueue i get queueinput i |
| 851 | end |
| 852 | diag dentry mapget lh 0 add get el 6 16 8 |
| 853 | diag drsrc1 mapget lh 0 add get el 6 48 4 |
| 854 | diag drsrc2 mapget lh 0 add get el 6 52 4 |
| 855 | diag drsrc3 mapget lh 0 add get el 6 44 4 |
| 856 | diag dprops and mapget lh 0 add get el 6 56 4 65535 |
| 857 | diag dgroup mapget lh 0 get el 6 4 |
| 858 | diag dprivate mapget lh 0 add get el 6 4 4 |
| 859 | diag dargsize mapget lh 0 add get el 6 8 4 |
| 860 | count = div get launch 4 4 |
| 861 | if gt count 8 |
| 862 | count = ulong 8 |
| 863 | end |
| 864 | nan = ulong 0 |
| 865 | sum = ulong 0 |
| 866 | for i ulong count |
| 867 | word = mapget lh 2 mul i 4 4 |
| 868 | diagindexed dout i word |
| 869 | if eq word 0x7fc00000 |
| 870 | nan = add nan 1 |
| 871 | end |
| 872 | if eq word 0x40000000 |
| 873 | sum = add sum 1 |
| 874 | end |
| 875 | end |
| 876 | diag dnan nan |
| 877 | if ne get diagstate 0 0 |
| 878 | diag dsum sum |
| 879 | end |
| 880 | end |
| 881 | fn queueinit to void |
| 882 | ctxsizes |
| 883 | r = allocate 3 1024 0xa6000002 |
| 884 | r = allocate 4 4096 0xa6000002 |
| 885 | r = allocate 5 4096 0xa6000002 |
| 886 | n = roundup mul add get dev 8 get dev 10 get dev 7 4096 |
| 887 | r = allocate 6 n 0xe4000002 |
| 888 | r = allocate 7 4096 0xa6000002 |
| 889 | zeromap lh 3 0 1024 |
| 890 | zeromap lh 4 0 8 |
| 891 | zeromap lh 5 0 8 |
| 892 | zeromap lh 6 0 n |
| 893 | zeromap lh 7 0 64 |
| 894 | note USER signal ABI: kind 1 at 0, value at 8, no interrupt event. |
| 895 | r = checked mapset lh 7 0 8 1 |
| 896 | r = checked mapset lh 7 8 8 get launch 2 |
| 897 | for i ulong get dev 7 bound 9223372036854775807 |
| 898 | p = mul i get dev 8 |
| 899 | r = checked mapset lh 6 add p 16 4 mul sub get dev 7 i get dev 8 |
| 900 | r = checked mapset lh 6 add p 20 4 mul get dev 10 get dev 7 |
| 901 | end |
| 902 | for i ulong 16 |
| 903 | r = checked mapset lh 3 mul i 64 4 1 |
| 904 | end |
| 905 | stepbegin stqueue get dev 2 |
| 906 | zerohdr |
| 907 | hput 32 4 1024 |
| 908 | hput 36 4 get dev 2 |
| 909 | hput 40 4 2 |
| 910 | hput 44 4 100 |
| 911 | hput 48 4 7 |
| 912 | hput 80 4 get dev 8 |
| 913 | hput 84 4 get dev 9 |
| 914 | note gfx942 AQL queues require no EOP allocation (ROCT queues.c). |
| 915 | note kfdctl supplies these five mapping addresses in its private ioctl block. |
| 916 | note Reconstruct that input here, before the ioctl returns output fields. |
| 917 | for i ulong 11 |
| 918 | put queueinput i hget mul i 8 8 |
| 919 | end |
| 920 | put queueinput 0 mapaddr lh 3 |
| 921 | put queueinput 1 mapaddr lh 4 |
| 922 | put queueinput 2 mapaddr lh 5 |
| 923 | put queueinput 7 0 |
| 924 | put queueinput 9 mapaddr lh 6 |
| 925 | r = checked kfdctl int get dev 0 3227011842 hdr 0 88 lh 3 lh 4 lh 5 long 0 lh 6 |
| 926 | put launch 7 hget 52 4 |
| 927 | stepend |
| 928 | belloff = hget 24 8 |
| 929 | put diagstate 1 belloff |
| 930 | put launch 9 rem belloff 8192 |
| 931 | stepbegin stbell belloff |
| 932 | put launch 8 ulong checked kfdmap int get dev 0 sub belloff rem belloff 8192 8192 |
| 933 | stepend |
| 934 | end |
| 935 | fn packet id ulong to void |
| 936 | slot = mul rem id 16 64 |
| 937 | put diagstate 2 slot |
| 938 | zerohdr |
| 939 | note First dword kept INVALID until every other field is published. |
| 940 | hput 0 2 1 |
| 941 | hput 2 2 2 |
| 942 | hput 4 2 64 |
| 943 | hput 6 2 1 |
| 944 | hput 8 2 1 |
| 945 | hput 12 4 mul get launch 5 64 |
| 946 | hput 16 4 get launch 6 |
| 947 | hput 20 4 1 |
| 948 | hput 24 4 get el 10 |
| 949 | hput 28 4 get el 9 |
| 950 | hput 32 8 add mapaddr lh 0 get el 6 |
| 951 | hput 40 8 mapaddr lh 1 |
| 952 | hput 56 8 mapaddr lh 7 |
| 953 | r = checked mapset lh 3 slot 4 1 |
| 954 | r = checked mapwrite lh 3 add slot 4 hdr 4 60 |
| 955 | cpufence |
| 956 | note type KERNEL_DISPATCH=2, barrier=1, acquire/release SYSTEM=2, dimensions=2. |
| 957 | r = checked mapset lh 3 slot 4 0x00021502 |
| 958 | cpufence |
| 959 | r = checked mapset lh 4 0 8 add id 1 |
| 960 | cpufence |
| 961 | r = checked mapset long get launch 8 get launch 9 8 id |
| 962 | end |
| 963 | fn deadline start long to void |
| 964 | now = monons |
| 965 | if lt now start |
| 966 | steprow 110 false |
| 967 | diagnostics |
| 968 | exit 75 |
| 969 | end |
| 970 | if gt ulong sub now start get launch 3 |
| 971 | steprow 110 false |
| 972 | diagnostics |
| 973 | exit 75 |
| 974 | end |
| 975 | end |
| 976 | fn dispatch to void |
| 977 | stepbegin stdispatch get launch 2 |
| 978 | diag dtimeout get launch 3 |
| 979 | start = monons |
| 980 | if lt start 0 |
| 981 | steprow ulong neg start false |
| 982 | exit 74 |
| 983 | end |
| 984 | for i ulong get launch 2 bound 9223372036854775807 |
| 985 | while ge sub i mapget lh 5 0 8 16 bound 9223372036854775807 |
| 986 | deadline start |
| 987 | cpurelax |
| 988 | end |
| 989 | packet i |
| 990 | end |
| 991 | stepend |
| 992 | stepbegin stwait get launch 2 |
| 993 | while ne mapget lh 7 8 8 0 bound 9223372036854775807 |
| 994 | deadline start |
| 995 | cpurelax |
| 996 | end |
| 997 | cpufence |
| 998 | stepend |
| 999 | elapsed = sub monons start |
| 1000 | emit timed |
| 1001 | printnum ulong elapsed |
| 1002 | emit repeatlabel |
| 1003 | printnum get launch 2 |
| 1004 | emit newline |
| 1005 | diagnostics |
| 1006 | end |
| 1007 | fn teardown to void |
| 1008 | stepbegin stcleanup 0 |
| 1009 | zerohdr |
| 1010 | hput 0 4 get launch 7 |
| 1011 | r = checked kfdctl int get dev 0 3221768963 hdr 0 8 |
| 1012 | r = checked mapdrop long get launch 8 |
| 1013 | for i ulong add get launch 1 8 bound 9223372036854775807 |
| 1014 | gpufree long get launch 0 mul i 24 |
| 1015 | end |
| 1016 | r = checked mapdrop long get launch 0 |
| 1017 | r = checked fclose int get dev 1 |
| 1018 | r = checked fclose int get dev 0 |
| 1019 | r = checked fclose int get el 0 |
| 1020 | stepend |
| 1021 | end |
| 1022 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 1023 | text runmode "run" |
| 1024 | text inspectmode "inspect" |
| 1025 | text vaddmode "vadd" |
| 1026 | text parsed "OMEGA elf=accepted image_bytes=" |
| 1027 | text argslabel " kernarg_bytes=" |
| 1028 | text passed "OMEGA vadd=PASS count=256\n" |
| 1029 | global config ulong 3 |
| 1030 | fn mode name view uchar * to bool |
| 1031 | n = patharg 1 |
| 1032 | if ne n len name |
| 1033 | ret false |
| 1034 | end |
| 1035 | for i ulong n bound 4096 |
| 1036 | if ne get pathbuf i get name i |
| 1037 | ret false |
| 1038 | end |
| 1039 | end |
| 1040 | ret true |
| 1041 | end |
| 1042 | fn configread to void |
| 1043 | fd = argfile 6 0 |
| 1044 | put config 0 ulong fd |
| 1045 | size = filesize fd |
| 1046 | span 0 48 size |
| 1047 | note Eight ASCII bytes OMKFD001. |
| 1048 | if ne fword fd 0 8 0x31303044464b4d4f |
| 1049 | exit 64 |
| 1050 | end |
| 1051 | if ne fword fd 8 8 get el 8 |
| 1052 | exit 64 |
| 1053 | end |
| 1054 | put launch 4 fword fd 16 8 |
| 1055 | put launch 2 fword fd 24 8 |
| 1056 | put launch 3 fword fd 32 8 |
| 1057 | put config 1 fword fd 40 8 |
| 1058 | if gt get config 1 div get el 8 8 |
| 1059 | exit 64 |
| 1060 | end |
| 1061 | put config 2 add 48 mul get config 1 16 |
| 1062 | span get config 2 get el 8 size |
| 1063 | if ne add get config 2 get el 8 size |
| 1064 | exit 64 |
| 1065 | end |
| 1066 | if or eq get launch 4 0 eq get launch 2 0 |
| 1067 | exit 64 |
| 1068 | end |
| 1069 | if or gt get launch 2 9223372036854775807 eq get launch 3 0 |
| 1070 | exit 64 |
| 1071 | end |
| 1072 | for i ulong get config 1 bound 9223372036854775807 |
| 1073 | p = add 48 mul i 16 |
| 1074 | off = fword fd p 8 |
| 1075 | span off 8 get el 8 |
| 1076 | if ne rem off 8 0 |
| 1077 | exit 64 |
| 1078 | end |
| 1079 | if gt fword fd add p 8 8 get launch 1 |
| 1080 | exit 64 |
| 1081 | end |
| 1082 | if ne fword fd add get config 2 off 8 0 |
| 1083 | exit 64 |
| 1084 | end |
| 1085 | for j ulong i bound 9223372036854775807 |
| 1086 | if eq off fword fd add 48 mul j 16 8 |
| 1087 | exit 64 |
| 1088 | end |
| 1089 | end |
| 1090 | end |
| 1091 | end |
| 1092 | fn prepare to void |
| 1093 | n = mul add get launch 1 8 24 |
| 1094 | put launch 0 ulong checked mapnew -1 0 n 3 34 |
| 1095 | r = allocate 0 get el 7 0xe0000001 |
| 1096 | stepbegin stload get el 7 |
| 1097 | loadelf r |
| 1098 | stepend |
| 1099 | r = allocate 1 get el 8 0xa4000002 |
| 1100 | r = allocate 2 get launch 4 0xa0000001 |
| 1101 | end |
| 1102 | fn loadinputs to void |
| 1103 | for i ulong get launch 1 bound 9223372036854775807 |
| 1104 | fd = argfile add i 7 0 |
| 1105 | size = filesize fd |
| 1106 | if eq size 0 |
| 1107 | exit 64 |
| 1108 | end |
| 1109 | h = allocate add i 8 size 0xa0000001 |
| 1110 | filecopy fd 0 h 0 size |
| 1111 | r = checked fclose fd |
| 1112 | end |
| 1113 | filecopy int get config 0 get config 2 lh 1 0 get el 8 |
| 1114 | for i ulong get config 1 bound 9223372036854775807 |
| 1115 | p = add 48 mul i 16 |
| 1116 | off = fword int get config 0 p 8 |
| 1117 | idx = fword int get config 0 add p 8 8 |
| 1118 | h = lh 2 |
| 1119 | if lt idx get launch 1 |
| 1120 | h = lh add idx 8 |
| 1121 | end |
| 1122 | r = checked mapset lh 1 off 8 mapaddr h |
| 1123 | end |
| 1124 | r = checked fclose int get config 0 |
| 1125 | end |
| 1126 | fn vaddinputs to void |
| 1127 | if ne get el 8 28 |
| 1128 | exit 65 |
| 1129 | end |
| 1130 | h = allocate 8 1024 0xa0000001 |
| 1131 | h = allocate 9 1024 0xa0000001 |
| 1132 | note IEEE754 binary32 1 + 1 = 2; exact independent host oracle in the gate. |
| 1133 | for i ulong 256 |
| 1134 | r = checked mapset lh 8 mul i 4 4 0x3f800000 |
| 1135 | r = checked mapset lh 9 mul i 4 4 0x3f800000 |
| 1136 | r = checked mapset lh 2 mul i 4 4 0x7fc00000 |
| 1137 | end |
| 1138 | r = checked mapset lh 1 0 8 mapaddr lh 8 |
| 1139 | r = checked mapset lh 1 8 8 mapaddr lh 9 |
| 1140 | r = checked mapset lh 1 16 8 mapaddr lh 2 |
| 1141 | r = checked mapset lh 1 24 4 256 |
| 1142 | end |
| 1143 | fn vaddcheck to void |
| 1144 | for i ulong 256 |
| 1145 | if ne mapget lh 2 mul i 4 4 0x40000000 |
| 1146 | steprow 5 false |
| 1147 | exit 76 |
| 1148 | end |
| 1149 | end |
| 1150 | emit passed |
| 1151 | end |
| 1152 | fn main to int |
| 1153 | if lt argcnt 4 |
| 1154 | ret 64 |
| 1155 | end |
| 1156 | isinspect = mode inspectmode |
| 1157 | isvadd = mode vaddmode |
| 1158 | isrun = mode runmode |
| 1159 | if not or isinspect or isvadd isrun |
| 1160 | ret 64 |
| 1161 | end |
| 1162 | parseelf 2 3 |
| 1163 | if isinspect |
| 1164 | emit parsed |
| 1165 | printnum get el 7 |
| 1166 | emit argslabel |
| 1167 | printnum get el 8 |
| 1168 | emit newline |
| 1169 | r = checked fclose int get el 0 |
| 1170 | ret 0 |
| 1171 | end |
| 1172 | if isvadd |
| 1173 | if ne argcnt 4 |
| 1174 | ret 64 |
| 1175 | end |
| 1176 | put launch 1 2 |
| 1177 | put diagstate 0 1 |
| 1178 | put launch 2 1 |
| 1179 | put launch 3 10000000000 |
| 1180 | put launch 4 1024 |
| 1181 | put launch 5 4 |
| 1182 | put launch 6 1 |
| 1183 | else |
| 1184 | if lt argcnt 8 |
| 1185 | ret 64 |
| 1186 | end |
| 1187 | put launch 1 sub ulong argcnt 8 |
| 1188 | put launch 5 argnum 4 |
| 1189 | put launch 6 argnum 5 |
| 1190 | if or eq get launch 5 0 gt get launch 5 div ulong 4294967295 64 |
| 1191 | ret 64 |
| 1192 | end |
| 1193 | if or eq get launch 6 0 gt get launch 6 4294967295 |
| 1194 | ret 64 |
| 1195 | end |
| 1196 | configread |
| 1197 | end |
| 1198 | connectkfd |
| 1199 | prepare |
| 1200 | if isvadd |
| 1201 | vaddinputs |
| 1202 | else |
| 1203 | loadinputs |
| 1204 | end |
| 1205 | queueinit |
| 1206 | dispatch |
| 1207 | stepbegin streadback get launch 4 |
| 1208 | if isvadd |
| 1209 | vaddcheck |
| 1210 | else |
| 1211 | fd = argfile sub ulong argcnt 1 577 |
| 1212 | savefile fd lh 2 get launch 4 |
| 1213 | r = checked fclose fd |
| 1214 | end |
| 1215 | stepend |
| 1216 | teardown |
| 1217 | ret 0 |
| 1218 | end |
| 1219 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 1220 | note Shared CLI unsigned parser; append after aql.om, kernarg.om, records.om or ring.om. |
| 1221 | note A uint64 text needs at most 20 decimal digits or 0x plus 16 hexadecimal digits. |
| 1222 | note Buffer 21 permits the extra byte that makes an overlong value refuse, not truncate. |
| 1223 | note WolframLanguageEvaluator: {2^64-1,Quotient[2^64-1,10],Mod[2^64-1,10]} -> |
| 1224 | note {18446744073709551615,1844674407370955161,5} (integer range, dimensionless). |
| 1225 | fn argnum i ulong to ulong |
| 1226 | ab = new uchar 21 0 |
| 1227 | n = argread i ab 0 21 |
| 1228 | if lt n 1 |
| 1229 | exit 2 |
| 1230 | end |
| 1231 | k = ulong n |
| 1232 | s = ulong 0 |
| 1233 | hex = false |
| 1234 | if gt k 2 |
| 1235 | if and eq get ab 0 48 eq get ab 1 120 |
| 1236 | hex = true |
| 1237 | s = ulong 2 |
| 1238 | end |
| 1239 | end |
| 1240 | m = sub k s |
| 1241 | if hex |
| 1242 | if gt m 16 |
| 1243 | exit 2 |
| 1244 | end |
| 1245 | end |
| 1246 | v = ulong 0 |
| 1247 | for j ulong m |
| 1248 | d = ulong get ab add j s |
| 1249 | dv = ulong 16 |
| 1250 | if and ge d 48 le d 57 |
| 1251 | dv = sub d 48 |
| 1252 | end |
| 1253 | if hex |
| 1254 | if and ge d 97 le d 102 |
| 1255 | dv = sub d 87 |
| 1256 | end |
| 1257 | if eq dv 16 |
| 1258 | exit 2 |
| 1259 | end |
| 1260 | v = or shl v 4 dv |
| 1261 | else |
| 1262 | if gt dv 9 |
| 1263 | exit 2 |
| 1264 | end |
| 1265 | if gt v 1844674407370955161 |
| 1266 | exit 2 |
| 1267 | end |
| 1268 | if and eq v 1844674407370955161 gt dv 5 |
| 1269 | exit 2 |
| 1270 | end |
| 1271 | v = add mul v 10 dv |
| 1272 | end |
| 1273 | end |
| 1274 | ret v |
| 1275 | end |
| 1276 | note Full write or exit 74. Applies to files and pipes, including partial writes and EINTR. |
| 1277 | fn emit b view uchar * to void |
| 1278 | p = ulong 0 |
| 1279 | while lt p len b bound 999999 |
| 1280 | r = write 1 b p sub len b p |
| 1281 | if eq r neg long 4 |
| 1282 | continue |
| 1283 | end |
| 1284 | if le r 0 |
| 1285 | exit 74 |
| 1286 | end |
| 1287 | p = add p ulong r |
| 1288 | end |
| 1289 | end |