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