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-LAUNCH2 / investigation / launch2-attempt3 / 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 | fn lh i ulong to long |
| 787 | ret long mapget long get launch 0 mul i 24 8 |
| 788 | end |
| 789 | fn allocate i ulong n ulong flags ulong to long |
| 790 | ret gpumem n flags long get launch 0 mul i 24 |
| 791 | end |
| 792 | fn queueinit to void |
| 793 | ctxsizes |
| 794 | r = allocate 3 1024 0xa6000002 |
| 795 | r = allocate 4 4096 0xa6000002 |
| 796 | r = allocate 5 4096 0xa6000002 |
| 797 | n = roundup mul add get dev 8 get dev 10 get dev 7 4096 |
| 798 | r = allocate 6 n 0xe4000002 |
| 799 | r = allocate 7 4096 0xa6000002 |
| 800 | zeromap lh 3 0 1024 |
| 801 | zeromap lh 4 0 8 |
| 802 | zeromap lh 5 0 8 |
| 803 | zeromap lh 6 0 n |
| 804 | zeromap lh 7 0 64 |
| 805 | note USER signal ABI: kind 1 at 0, value at 8, no interrupt event. |
| 806 | r = checked mapset lh 7 0 8 1 |
| 807 | r = checked mapset lh 7 8 8 get launch 2 |
| 808 | for i ulong get dev 7 bound 9223372036854775807 |
| 809 | p = mul i get dev 8 |
| 810 | r = checked mapset lh 6 add p 16 4 mul sub get dev 7 i get dev 8 |
| 811 | r = checked mapset lh 6 add p 20 4 mul get dev 10 get dev 7 |
| 812 | end |
| 813 | for i ulong 16 |
| 814 | r = checked mapset lh 3 mul i 64 4 1 |
| 815 | end |
| 816 | stepbegin stqueue get dev 2 |
| 817 | zerohdr |
| 818 | hput 32 4 1024 |
| 819 | hput 36 4 get dev 2 |
| 820 | hput 40 4 2 |
| 821 | hput 44 4 100 |
| 822 | hput 48 4 7 |
| 823 | hput 80 4 get dev 8 |
| 824 | hput 84 4 get dev 9 |
| 825 | note gfx942 AQL queues require no EOP allocation (ROCT queues.c). |
| 826 | r = checked kfdctl int get dev 0 3227011842 hdr 0 88 lh 3 lh 4 lh 5 long 0 lh 6 |
| 827 | put launch 7 hget 52 4 |
| 828 | stepend |
| 829 | belloff = hget 24 8 |
| 830 | put launch 9 rem belloff 8192 |
| 831 | stepbegin stbell belloff |
| 832 | put launch 8 ulong checked kfdmap int get dev 0 sub belloff rem belloff 8192 8192 |
| 833 | stepend |
| 834 | end |
| 835 | fn packet id ulong to void |
| 836 | slot = mul rem id 16 64 |
| 837 | zerohdr |
| 838 | note First dword kept INVALID until every other field is published. |
| 839 | hput 0 2 1 |
| 840 | hput 2 2 2 |
| 841 | hput 4 2 64 |
| 842 | hput 6 2 1 |
| 843 | hput 8 2 1 |
| 844 | hput 12 4 mul get launch 5 64 |
| 845 | hput 16 4 get launch 6 |
| 846 | hput 20 4 1 |
| 847 | hput 24 4 get el 10 |
| 848 | hput 28 4 get el 9 |
| 849 | hput 32 8 add mapaddr lh 0 get el 6 |
| 850 | hput 40 8 mapaddr lh 1 |
| 851 | hput 56 8 mapaddr lh 7 |
| 852 | r = checked mapset lh 3 slot 4 1 |
| 853 | r = checked mapwrite lh 3 add slot 4 hdr 4 60 |
| 854 | cpufence |
| 855 | note type KERNEL_DISPATCH=2, barrier=1, acquire/release SYSTEM=2, dimensions=2. |
| 856 | r = checked mapset lh 3 slot 4 0x00021502 |
| 857 | cpufence |
| 858 | r = checked mapset lh 4 0 8 add id 1 |
| 859 | cpufence |
| 860 | r = checked mapset long get launch 8 get launch 9 8 id |
| 861 | end |
| 862 | fn deadline start long to void |
| 863 | now = monons |
| 864 | if lt now start |
| 865 | steprow 110 false |
| 866 | exit 75 |
| 867 | end |
| 868 | if gt ulong sub now start get launch 3 |
| 869 | steprow 110 false |
| 870 | exit 75 |
| 871 | end |
| 872 | end |
| 873 | fn dispatch to void |
| 874 | stepbegin stdispatch get launch 2 |
| 875 | start = monons |
| 876 | if lt start 0 |
| 877 | steprow ulong neg start false |
| 878 | exit 74 |
| 879 | end |
| 880 | for i ulong get launch 2 bound 9223372036854775807 |
| 881 | while ge sub i mapget lh 5 0 8 16 bound 9223372036854775807 |
| 882 | deadline start |
| 883 | cpurelax |
| 884 | end |
| 885 | packet i |
| 886 | end |
| 887 | stepend |
| 888 | stepbegin stwait get launch 2 |
| 889 | while ne mapget lh 7 8 8 0 bound 9223372036854775807 |
| 890 | deadline start |
| 891 | cpurelax |
| 892 | end |
| 893 | cpufence |
| 894 | stepend |
| 895 | elapsed = sub monons start |
| 896 | emit timed |
| 897 | printnum ulong elapsed |
| 898 | emit repeatlabel |
| 899 | printnum get launch 2 |
| 900 | emit newline |
| 901 | end |
| 902 | fn teardown to void |
| 903 | stepbegin stcleanup 0 |
| 904 | zerohdr |
| 905 | hput 0 4 get launch 7 |
| 906 | r = checked kfdctl int get dev 0 3221768963 hdr 0 8 |
| 907 | r = checked mapdrop long get launch 8 |
| 908 | for i ulong add get launch 1 8 bound 9223372036854775807 |
| 909 | gpufree long get launch 0 mul i 24 |
| 910 | end |
| 911 | r = checked mapdrop long get launch 0 |
| 912 | r = checked fclose int get dev 1 |
| 913 | r = checked fclose int get dev 0 |
| 914 | r = checked fclose int get el 0 |
| 915 | stepend |
| 916 | end |
| 917 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 918 | text runmode "run" |
| 919 | text inspectmode "inspect" |
| 920 | text vaddmode "vadd" |
| 921 | text parsed "OMEGA elf=accepted image_bytes=" |
| 922 | text argslabel " kernarg_bytes=" |
| 923 | text passed "OMEGA vadd=PASS count=256\n" |
| 924 | global config ulong 3 |
| 925 | fn mode name view uchar * to bool |
| 926 | n = patharg 1 |
| 927 | if ne n len name |
| 928 | ret false |
| 929 | end |
| 930 | for i ulong n bound 4096 |
| 931 | if ne get pathbuf i get name i |
| 932 | ret false |
| 933 | end |
| 934 | end |
| 935 | ret true |
| 936 | end |
| 937 | fn configread to void |
| 938 | fd = argfile 6 0 |
| 939 | put config 0 ulong fd |
| 940 | size = filesize fd |
| 941 | span 0 48 size |
| 942 | note Eight ASCII bytes OMKFD001. |
| 943 | if ne fword fd 0 8 0x31303044464b4d4f |
| 944 | exit 64 |
| 945 | end |
| 946 | if ne fword fd 8 8 get el 8 |
| 947 | exit 64 |
| 948 | end |
| 949 | put launch 4 fword fd 16 8 |
| 950 | put launch 2 fword fd 24 8 |
| 951 | put launch 3 fword fd 32 8 |
| 952 | put config 1 fword fd 40 8 |
| 953 | if gt get config 1 div get el 8 8 |
| 954 | exit 64 |
| 955 | end |
| 956 | put config 2 add 48 mul get config 1 16 |
| 957 | span get config 2 get el 8 size |
| 958 | if ne add get config 2 get el 8 size |
| 959 | exit 64 |
| 960 | end |
| 961 | if or eq get launch 4 0 eq get launch 2 0 |
| 962 | exit 64 |
| 963 | end |
| 964 | if or gt get launch 2 9223372036854775807 eq get launch 3 0 |
| 965 | exit 64 |
| 966 | end |
| 967 | for i ulong get config 1 bound 9223372036854775807 |
| 968 | p = add 48 mul i 16 |
| 969 | off = fword fd p 8 |
| 970 | span off 8 get el 8 |
| 971 | if ne rem off 8 0 |
| 972 | exit 64 |
| 973 | end |
| 974 | if gt fword fd add p 8 8 get launch 1 |
| 975 | exit 64 |
| 976 | end |
| 977 | if ne fword fd add get config 2 off 8 0 |
| 978 | exit 64 |
| 979 | end |
| 980 | for j ulong i bound 9223372036854775807 |
| 981 | if eq off fword fd add 48 mul j 16 8 |
| 982 | exit 64 |
| 983 | end |
| 984 | end |
| 985 | end |
| 986 | end |
| 987 | fn prepare to void |
| 988 | n = mul add get launch 1 8 24 |
| 989 | put launch 0 ulong checked mapnew -1 0 n 3 34 |
| 990 | r = allocate 0 get el 7 0xe0000001 |
| 991 | stepbegin stload get el 7 |
| 992 | loadelf r |
| 993 | stepend |
| 994 | r = allocate 1 get el 8 0xa4000002 |
| 995 | r = allocate 2 get launch 4 0xa0000001 |
| 996 | end |
| 997 | fn loadinputs to void |
| 998 | for i ulong get launch 1 bound 9223372036854775807 |
| 999 | fd = argfile add i 7 0 |
| 1000 | size = filesize fd |
| 1001 | if eq size 0 |
| 1002 | exit 64 |
| 1003 | end |
| 1004 | h = allocate add i 8 size 0xa0000001 |
| 1005 | filecopy fd 0 h 0 size |
| 1006 | r = checked fclose fd |
| 1007 | end |
| 1008 | filecopy int get config 0 get config 2 lh 1 0 get el 8 |
| 1009 | for i ulong get config 1 bound 9223372036854775807 |
| 1010 | p = add 48 mul i 16 |
| 1011 | off = fword int get config 0 p 8 |
| 1012 | idx = fword int get config 0 add p 8 8 |
| 1013 | h = lh 2 |
| 1014 | if lt idx get launch 1 |
| 1015 | h = lh add idx 8 |
| 1016 | end |
| 1017 | r = checked mapset lh 1 off 8 mapaddr h |
| 1018 | end |
| 1019 | r = checked fclose int get config 0 |
| 1020 | end |
| 1021 | fn vaddinputs to void |
| 1022 | if ne get el 8 28 |
| 1023 | exit 65 |
| 1024 | end |
| 1025 | h = allocate 8 1024 0xa0000001 |
| 1026 | h = allocate 9 1024 0xa0000001 |
| 1027 | note IEEE754 binary32 1 + 1 = 2; exact independent host oracle in the gate. |
| 1028 | for i ulong 256 |
| 1029 | r = checked mapset lh 8 mul i 4 4 0x3f800000 |
| 1030 | r = checked mapset lh 9 mul i 4 4 0x3f800000 |
| 1031 | r = checked mapset lh 2 mul i 4 4 0x7fc00000 |
| 1032 | end |
| 1033 | r = checked mapset lh 1 0 8 mapaddr lh 8 |
| 1034 | r = checked mapset lh 1 8 8 mapaddr lh 9 |
| 1035 | r = checked mapset lh 1 16 8 mapaddr lh 2 |
| 1036 | r = checked mapset lh 1 24 4 256 |
| 1037 | end |
| 1038 | fn vaddcheck to void |
| 1039 | for i ulong 256 |
| 1040 | if ne mapget lh 2 mul i 4 4 0x40000000 |
| 1041 | steprow 5 false |
| 1042 | exit 76 |
| 1043 | end |
| 1044 | end |
| 1045 | emit passed |
| 1046 | end |
| 1047 | fn main to int |
| 1048 | if lt argcnt 4 |
| 1049 | ret 64 |
| 1050 | end |
| 1051 | isinspect = mode inspectmode |
| 1052 | isvadd = mode vaddmode |
| 1053 | isrun = mode runmode |
| 1054 | if not or isinspect or isvadd isrun |
| 1055 | ret 64 |
| 1056 | end |
| 1057 | parseelf 2 3 |
| 1058 | if isinspect |
| 1059 | emit parsed |
| 1060 | printnum get el 7 |
| 1061 | emit argslabel |
| 1062 | printnum get el 8 |
| 1063 | emit newline |
| 1064 | r = checked fclose int get el 0 |
| 1065 | ret 0 |
| 1066 | end |
| 1067 | if isvadd |
| 1068 | if ne argcnt 4 |
| 1069 | ret 64 |
| 1070 | end |
| 1071 | put launch 1 2 |
| 1072 | put launch 2 1 |
| 1073 | put launch 3 10000000000 |
| 1074 | put launch 4 1024 |
| 1075 | put launch 5 4 |
| 1076 | put launch 6 1 |
| 1077 | else |
| 1078 | if lt argcnt 8 |
| 1079 | ret 64 |
| 1080 | end |
| 1081 | put launch 1 sub ulong argcnt 8 |
| 1082 | put launch 5 argnum 4 |
| 1083 | put launch 6 argnum 5 |
| 1084 | if or eq get launch 5 0 gt get launch 5 div ulong 4294967295 64 |
| 1085 | ret 64 |
| 1086 | end |
| 1087 | if or eq get launch 6 0 gt get launch 6 4294967295 |
| 1088 | ret 64 |
| 1089 | end |
| 1090 | configread |
| 1091 | end |
| 1092 | connectkfd |
| 1093 | prepare |
| 1094 | if isvadd |
| 1095 | vaddinputs |
| 1096 | else |
| 1097 | loadinputs |
| 1098 | end |
| 1099 | queueinit |
| 1100 | dispatch |
| 1101 | stepbegin streadback get launch 4 |
| 1102 | if isvadd |
| 1103 | vaddcheck |
| 1104 | else |
| 1105 | fd = argfile sub ulong argcnt 1 577 |
| 1106 | savefile fd lh 2 get launch 4 |
| 1107 | r = checked fclose fd |
| 1108 | end |
| 1109 | stepend |
| 1110 | teardown |
| 1111 | ret 0 |
| 1112 | end |
| 1113 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 1114 | note Shared CLI unsigned parser; append after aql.om, kernarg.om, records.om or ring.om. |
| 1115 | note A uint64 text needs at most 20 decimal digits or 0x plus 16 hexadecimal digits. |
| 1116 | note Buffer 21 permits the extra byte that makes an overlong value refuse, not truncate. |
| 1117 | note WolframLanguageEvaluator: {2^64-1,Quotient[2^64-1,10],Mod[2^64-1,10]} -> |
| 1118 | note {18446744073709551615,1844674407370955161,5} (integer range, dimensionless). |
| 1119 | fn argnum i ulong to ulong |
| 1120 | ab = new uchar 21 0 |
| 1121 | n = argread i ab 0 21 |
| 1122 | if lt n 1 |
| 1123 | exit 2 |
| 1124 | end |
| 1125 | k = ulong n |
| 1126 | s = ulong 0 |
| 1127 | hex = false |
| 1128 | if gt k 2 |
| 1129 | if and eq get ab 0 48 eq get ab 1 120 |
| 1130 | hex = true |
| 1131 | s = ulong 2 |
| 1132 | end |
| 1133 | end |
| 1134 | m = sub k s |
| 1135 | if hex |
| 1136 | if gt m 16 |
| 1137 | exit 2 |
| 1138 | end |
| 1139 | end |
| 1140 | v = ulong 0 |
| 1141 | for j ulong m |
| 1142 | d = ulong get ab add j s |
| 1143 | dv = ulong 16 |
| 1144 | if and ge d 48 le d 57 |
| 1145 | dv = sub d 48 |
| 1146 | end |
| 1147 | if hex |
| 1148 | if and ge d 97 le d 102 |
| 1149 | dv = sub d 87 |
| 1150 | end |
| 1151 | if eq dv 16 |
| 1152 | exit 2 |
| 1153 | end |
| 1154 | v = or shl v 4 dv |
| 1155 | else |
| 1156 | if gt dv 9 |
| 1157 | exit 2 |
| 1158 | end |
| 1159 | if gt v 1844674407370955161 |
| 1160 | exit 2 |
| 1161 | end |
| 1162 | if and eq v 1844674407370955161 gt dv 5 |
| 1163 | exit 2 |
| 1164 | end |
| 1165 | v = add mul v 10 dv |
| 1166 | end |
| 1167 | end |
| 1168 | ret v |
| 1169 | end |
| 1170 | note Full write or exit 74. Applies to files and pipes, including partial writes and EINTR. |
| 1171 | fn emit b view uchar * to void |
| 1172 | p = ulong 0 |
| 1173 | while lt p len b bound 999999 |
| 1174 | r = write 1 b p sub len b p |
| 1175 | if eq r neg long 4 |
| 1176 | continue |
| 1177 | end |
| 1178 | if le r 0 |
| 1179 | exit 74 |
| 1180 | end |
| 1181 | p = add p ulong r |
| 1182 | end |
| 1183 | end |