Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/backend/amd/kfd/launch/plan.om # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / backend / amd / kfd / launch / plan.om` 611 lines · 14349 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note OMPLAN01 trusted first-party dispatch plans; all file and relocation bounds preflight before KFD. 3 note ps: planmap,fd,size,ncode,nfile,nbuf,ndisp,nprompt,ngen,tok,strOff,strLen,dataOff,dataLen,bufOff,promptOff,dispOff,codemeta,filemeta,dispmeta,packets,argbytes,ids,bufoffsets,VRAMbytes,GTTbytes. 4 global ps ulong 26 5 global planoptions ulong 1 6 text planmode "plan" 7 text planstep "OMEGA_STEP " 8 text plantok " tok=" 9 text planus " us=" 10 text planready "OMEGA_PLAN ready\n" 11 text plandone "OMEGA_PLAN complete\n" 12 text planids "OMEGA_PLAN ids=[" 13 text plancomma "," 14 text planend "]\n" 15 text planrefusallabel "OMEGA refuse plan field=" 16 text preason0 "add-overflow\n" 17 text preason1 "multiply-overflow\n" 18 text preason2 "span-offset\n" 19 text preason3 "span-size\n" 20 text preason4 "word-width\n" 21 text preason5 "padding\n" 22 text preason6 "magic\n" 23 text preason7 "code-count\n" 24 text preason8 "count\n" 25 text preason9 "token-index\n" 26 text preason10 "argc\n" 27 text preason11 "pool-layout\n" 28 text preason12 "data-layout\n" 29 text preason13 "name\n" 30 text preason14 "buffer-size\n" 31 text preason15 "buffer-flags\n" 32 text preason16 "buffer-kind\n" 33 text preason17 "zero-buffer\n" 34 text preason18 "data-index\n" 35 text preason19 "file-index\n" 36 text preason20 "widen-size\n" 37 text preason21 "duplicate-relocation\n" 38 text preason22 "relocation-alignment\n" 39 text preason23 "relocation-pointer\n" 40 text preason24 "relocation-buffer\n" 41 text preason25 "code-index\n" 42 text preason26 "grid\n" 43 text preason27 "workgroup\n" 44 text preason28 "kernarg-size\n" 45 text preason29 "relocation-count\n" 46 text preason30 "ring-size\n" 47 text preason31 "token-buffer\n" 48 text preason32 "dispatch-end\n" 49 fn planrefuse reason view uchar * to void 50 r = write 1 planrefusallabel 0 len planrefusallabel 51 r = write 1 reason 0 len reason 52 exit 64 53 end 54 fn padd a ulong b ulong to ulong 55 if or gt a `9223372036854775807` gt b sub ulong `9223372036854775807` a 56 planrefuse preason0 57 end 58 ret add a b 59 end 60 fn pmul a ulong b ulong to ulong 61 if ne b 0 62 if gt a div ulong `9223372036854775807` b 63 planrefuse preason1 64 end 65 end 66 ret mul a b 67 end 68 fn pspan off ulong n ulong total ulong to void 69 if gt off total 70 planrefuse preason2 71 end 72 if gt n sub total off 73 planrefuse preason3 74 end 75 end 76 fn pw off ulong width ulong to ulong 77 pspan off width get ps 2 78 if gt width 8 79 planrefuse preason4 80 end 81 b = new uchar 8 0 82 r = checked mapread long get ps 0 off b 0 width 83 v = ulong 0 84 for i ulong width bound 8 85 v = or v shl ulong get b i mul i 8 86 end 87 ret v 88 end 89 fn planpad off ulong limit ulong to ulong 90 last = roundup off 8 91 pspan off sub last off limit 92 for i ulong sub last off bound 7 93 if ne pw add off i 1 0 94 planrefuse preason5 95 end 96 end 97 ret last 98 end 99 fn pb i ulong byteoff ulong to ulong 100 ret pw add add get ps 14 pmul i 48 byteoff 8 101 end 102 fn cm i ulong byteoff ulong to ulong 103 ret mapget long get ps 17 add pmul i 96 byteoff 8 104 end 105 fn fm i ulong byteoff ulong to ulong 106 ret mapget long get ps 18 add pmul i 16 byteoff 8 107 end 108 fn dm i ulong byteoff ulong to ulong 109 ret mapget long get ps 19 add pmul i 32 byteoff 8 110 end 111 fn restoreel i ulong to void 112 for j ulong 12 113 put el j cm i mul j 8 114 end 115 end 116 fn planhead to void 117 fd = argfile 2 0 118 put ps 1 ulong fd 119 put ps 2 filesize fd 120 pspan 0 96 get ps 2 121 put ps 0 ulong checked mapnew fd 0 get ps 2 1 2 122 if ne pw 0 8 0x31304e414c504d4f 123 planrefuse preason6 124 end 125 for i ulong 7 126 put ps add i 3 pw mul add i 1 8 8 127 end 128 if eq get ps 3 0 129 planrefuse preason7 130 end 131 for i ulong 4 132 if eq get ps add i 5 0 133 planrefuse preason8 134 end 135 end 136 if ge get ps 9 get ps 5 137 planrefuse preason9 138 end 139 expected = padd 3 padd get ps 3 get ps 4 140 put planoptions 0 0 141 if ne ulong argcnt expected 142 if ne ulong argcnt padd expected 1 143 planrefuse preason10 144 end 145 put planoptions 0 argnum expected 146 end 147 for i ulong 4 148 put ps add 10 i pw add sub get ps 2 32 mul i 8 8 149 end 150 if ne padd get ps 10 get ps 11 get ps 12 151 planrefuse preason11 152 end 153 if ne padd get ps 12 get ps 13 sub get ps 2 32 154 planrefuse preason12 155 end 156 put ps 14 padd 64 pmul get ps 3 16 157 put ps 15 padd get ps 14 pmul get ps 5 48 158 put ps 16 planpad padd get ps 15 pmul get ps 7 4 get ps 10 159 pspan 64 sub get ps 16 64 get ps 10 160 pspan get ps 16 pmul get ps 6 32 get ps 10 161 steps = sub padd get ps 7 get ps 8 1 162 n = pmul steps get ps 6 163 put ps 17 ulong checked mapnew -1 0 pmul get ps 3 96 3 34 164 put ps 18 ulong checked mapnew -1 0 pmul padd get ps 4 1 16 3 34 165 put ps 19 ulong checked mapnew -1 0 pmul get ps 6 32 3 34 166 put ps 22 ulong checked mapnew -1 0 pmul get ps 8 4 3 34 167 end 168 fn planname i ulong to ulong 169 pos = add 64 mul i 16 170 off = pw pos 8 171 n = pw add pos 8 8 172 pspan off n get ps 11 173 if or eq n 0 gt n len pathbuf 174 planrefuse preason13 175 end 176 r = checked mapread long get ps 0 add get ps 10 off pathbuf 0 n 177 ret n 178 end 179 fn plansaveel i ulong to void 180 for j ulong 12 181 r = checked mapset long get ps 17 add mul i 96 mul j 8 8 get el j 182 end 183 end 184 fn plancode i ulong to void 185 fd = argfile add 3 i 0 186 n = planname i 187 parseopen fd n 188 plansaveel i 189 end 190 fn plancodes to void 191 for i ulong get ps 3 bound `9223372036854775807` 192 plancode i 193 end 194 end 195 fn planfiles to void 196 for i ulong get ps 4 bound `9223372036854775807` 197 fd = argfile add add 3 get ps 3 i 0 198 r = checked mapset long get ps 18 mul i 16 8 ulong fd 199 r = checked mapset long get ps 18 add mul i 16 8 8 filesize fd 200 end 201 end 202 fn planbufcheck i ulong to void 203 n = pb i 0 204 kind = pb i 8 205 idx = pb i 16 206 off = pb i 24 207 size = pb i 32 208 flags = pb i 40 209 if or eq n 0 gt n `9223372036854771712` 210 planrefuse preason14 211 end 212 if not or eq flags 1 eq flags 2 213 planrefuse preason15 214 end 215 if gt kind 3 216 planrefuse preason16 217 end 218 if eq kind 0 219 if or ne idx 0 or ne off 0 ne size 0 220 planrefuse preason17 221 end 222 else 223 if eq kind 3 224 if ne idx 0 225 planrefuse preason18 226 end 227 pspan off size get ps 13 228 else 229 if ge idx get ps 4 230 planrefuse preason19 231 end 232 pspan off size fm idx 8 233 end 234 end 235 if eq kind 2 236 if ne rem size 2 0 237 planrefuse preason20 238 end 239 size = pmul size 2 240 end 241 pspan 0 size n 242 end 243 fn planduplicate pos ulong count ulong off ulong to void 244 for k ulong count bound `9223372036854775807` 245 if eq off pw add pos mul k 16 4 246 planrefuse preason21 247 end 248 end 249 end 250 fn planrelone p ulong raw ulong size ulong to void 251 off = pw p 4 252 if ne rem off 8 0 253 planrefuse preason22 254 end 255 pspan off 8 size 256 if ne pw add raw off 8 0 257 planrefuse preason23 258 end 259 idx = pw add p 4 4 260 if ge idx get ps 5 261 planrefuse preason24 262 end 263 pspan pw add p 8 8 1 pb idx 0 264 end 265 fn planreloc pos ulong raw ulong size ulong count ulong to void 266 for j ulong count bound `9223372036854775807` 267 planrelone add pos mul j 16 raw size 268 planduplicate pos j pw add pos mul j 16 4 269 end 270 end 271 fn planshape pos ulong to void 272 pspan pos 32 get ps 10 273 code = pw pos 4 274 if ge code get ps 3 275 planrefuse preason25 276 end 277 gx = pw add pos 4 4 278 gy = pw add pos 8 4 279 if or eq gx 0 or gt gx div ulong `4294967295` 64 eq gy 0 280 planrefuse preason26 281 end 282 if or ne pw add pos 12 4 1 or ne pw add pos 16 4 64 ne pw add pos 28 4 0 283 planrefuse preason27 284 end 285 if ne pw add pos 20 4 cm code 64 286 planrefuse preason28 287 end 288 end 289 fn planstore i ulong pos ulong reloc ulong to void 290 r = checked mapset long get ps 19 mul i 32 8 pos 291 r = checked mapset long get ps 19 add mul i 32 8 8 reloc 292 r = checked mapset long get ps 19 add mul i 32 16 8 get ps 21 293 end 294 fn plandispcheck pos ulong i ulong to ulong 295 planshape pos 296 size = pw add pos 20 4 297 count = pw add pos 24 4 298 if gt count div size 8 299 planrefuse preason29 300 end 301 raw = add pos 32 302 reloc = padd raw size 303 last = padd reloc pmul count 16 304 pspan pos sub last pos get ps 10 305 planreloc reloc raw size count 306 planstore i pos reloc 307 put ps 21 padd get ps 21 roundup padd size 1 16 308 ret planpad last get ps 10 309 end 310 fn planring to void 311 note Keep the established 1024-byte AQL minimum, grow for the complete step. 312 slots = ulong 16 313 while lt slots padd get ps 6 1 bound 63 314 slots = pmul slots 2 315 end 316 note CREATE_QUEUE ring_size is a 32-bit byte count; reject unrepresentable rings. 317 if gt slots div ulong `4294967295` 64 318 planrefuse preason30 319 end 320 put launch 10 slots 321 end 322 fn plancheck to void 323 planhead 324 plancodes 325 planfiles 326 for i ulong get ps 5 bound `9223372036854775807` 327 planbufcheck i 328 end 329 if or lt pb get ps 9 0 4 ne pb get ps 9 40 2 330 planrefuse preason31 331 end 332 pos = get ps 16 333 for i ulong get ps 6 bound `9223372036854775807` 334 pos = plandispcheck pos i 335 end 336 if ne pos get ps 10 337 planrefuse preason32 338 end 339 planlayout 340 planring 341 end 342 fn bufoffset i ulong to ulong 343 ret mapget long get ps 23 mul i 8 8 344 end 345 fn bufhandle i ulong to long 346 ret lh add add 7 get ps 3 pb i 40 347 end 348 fn planlayout to void 349 put ps 23 ulong checked mapnew -1 0 pmul get ps 5 8 3 34 350 for i ulong get ps 5 bound `9223372036854775807` 351 slot = add 23 pb i 40 352 r = checked mapset long get ps 23 mul i 8 8 get ps slot 353 put ps slot padd get ps slot roundup pb i 0 4096 354 end 355 end 356 fn planarenas to void 357 for i ulong 2 358 size = get ps add 24 i 359 if ne size 0 360 flags = ulong 0xa0000001 361 if eq i 1 362 flags = ulong 0xa6000002 363 end 364 h = allocate add add 8 get ps 3 i size flags 365 end 366 end 367 end 368 fn widenchunk h long off ulong n ulong to void 369 for i ulong div n 2 bound 2048 370 v = shl ulong get chunk mul i 2 16 371 v = or v shl ulong get chunk add mul i 2 1 24 372 r = checked mapset h add off mul i 4 4 v 373 end 374 end 375 fn planwiden fd int off ulong h long dst ulong n ulong to void 376 pos = ulong 0 377 while lt pos n bound `9223372036854775807` 378 size = sub n pos 379 if gt size len chunk 380 size = len chunk 381 end 382 r = checked pread fd chunk 0 size long add off pos 383 if or eq r 0 ne rem ulong r 2 0 384 exit 65 385 end 386 widenchunk h add dst mul pos 2 ulong r 387 pos = add pos ulong r 388 end 389 end 390 fn planbufload i ulong to void 391 h = bufhandle i 392 base = bufoffset i 393 kind = pb i 8 394 used = pb i 32 395 if eq kind 0 396 used = ulong 0 397 else 398 if eq kind 3 399 filecopy int get ps 1 add get ps 12 pb i 24 h base used 400 else 401 fd = int fm pb i 16 0 402 if eq kind 2 403 planwiden fd pb i 24 h base used 404 used = mul used 2 405 else 406 filecopy fd pb i 24 h base used 407 end 408 end 409 end 410 zeromap h add base used sub pb i 0 used 411 end 412 fn planargs i ulong to void 413 pos = dm i 0 414 raw = add pos 32 415 size = pw add pos 20 4 416 argoff = dm i 16 417 filecopy int get ps 1 raw lh 1 argoff size 418 for j ulong pw add pos 24 4 bound `9223372036854775807` 419 p = add dm i 8 mul j 16 420 off = pw p 4 421 idx = pw add p 4 4 422 value = padd mapaddr bufhandle idx padd bufoffset idx pw add p 8 8 423 r = checked mapset lh 1 add argoff off 8 value 424 end 425 end 426 fn plantemplate i ulong to void 427 pos = dm i 0 428 code = pw pos 4 429 zerohdr 430 hput 0 4 1 431 hput 4 2 64 432 hput 6 2 1 433 hput 8 2 1 434 hput 12 4 mul pw add pos 4 4 64 435 hput 16 4 pw add pos 8 4 436 hput 20 4 1 437 note Descriptor metadata is group then private; the packet is private then group. 438 hput 24 4 cm code 80 439 hput 28 4 cm code 72 440 hput 32 8 padd mapaddr lh add 8 code cm code 48 441 hput 40 8 padd mapaddr lh 1 dm i 16 442 if eq add i 1 get ps 6 443 hput 56 8 mapaddr lh 7 444 end 445 r = checked mapwrite long get ps 20 mul i 64 hdr 0 64 446 end 447 fn planload to void 448 n = padd 10 get ps 3 449 put launch 0 ulong checked mapnew -1 0 pmul n 24 3 34 450 put launch 1 sub n 8 451 put launch 2 1 452 put launch 3 get planoptions 0 453 r = allocate 1 get ps 21 0xa0000001 454 for i ulong get ps 3 bound `9223372036854775807` 455 restoreel i 456 h = allocate add 8 i get el 7 0xe0000001 457 loadelf h 458 end 459 planarenas 460 for i ulong get ps 5 bound `9223372036854775807` 461 planbufload i 462 end 463 queueinit 464 put ps 20 ulong checked mapnew -1 0 pmul get ps 6 64 3 34 465 for i ulong get ps 6 bound `9223372036854775807` 466 planargs i 467 plantemplate i 468 end 469 cpufence 470 emit planready 471 end 472 fn plantimeout start long to void 473 now = monons 474 if lt now start 475 exit 74 476 end 477 slowdispatch ulong sub now start 478 if and ne get launch 3 0 gt ulong sub now start get launch 3 479 stepbegin stwait 0 480 steprow 110 false 481 exit 75 482 end 483 end 484 fn plancopy sent ulong to void 485 pos = ulong 0 486 size = pmul get ps 6 64 487 ringbytes = pmul get launch 10 64 488 while lt pos size bound `9223372036854775807` 489 slot = rem add mul rem sent get launch 10 64 pos ringbytes 490 n = sub size pos 491 if gt n len chunk 492 n = len chunk 493 end 494 if gt n sub ringbytes slot 495 n = sub ringbytes slot 496 end 497 r = checked mapread long get ps 20 pos chunk 0 n 498 r = checked mapwrite lh 3 slot chunk 0 n 499 pos = add pos n 500 end 501 end 502 fn planpublish sent ulong start long to void 503 while gt padd sub sent mapget lh 5 128 8 get ps 6 get launch 10 bound `9223372036854775807` 504 plantimeout start 505 cpurelax 506 end 507 note Invalidate all owned slots, copy all bodies, then publish aligned headers. 508 for i ulong get ps 6 bound `9223372036854775807` 509 r = checked mapset lh 3 mul rem add sent i get launch 10 64 4 1 510 end 511 cpufence 512 plancopy sent 513 cpufence 514 for i ulong get ps 6 bound `9223372036854775807` 515 r = checked mapset lh 3 mul rem add sent i get launch 10 64 4 0x00021502 516 end 517 cpufence 518 r = checked mapset lh 5 56 8 add sent get ps 6 519 cpufence 520 r = checked mapset long get launch 8 get launch 9 8 sub add sent get ps 6 1 521 end 522 fn recordtoken step ulong tok long to void 523 if ge add step 1 get ps 7 524 idx = sub add step 1 get ps 7 525 r = checked mapset long get ps 22 mul idx 4 4 mapget tok bufoffset get ps 9 4 526 end 527 end 528 fn printids to void 529 emit planids 530 for i ulong get ps 8 bound `9223372036854775807` 531 if ne i 0 532 emit plancomma 533 end 534 printnum mapget long get ps 22 mul i 4 4 535 end 536 emit planend 537 end 538 fn planrun to void 539 sent = ulong 0 540 steps = sub add get ps 7 get ps 8 1 541 tok = bufhandle get ps 9 542 for step ulong steps bound `9223372036854775807` 543 if lt step get ps 7 544 r = checked mapset tok bufoffset get ps 9 4 pw add get ps 15 mul step 4 4 545 end 546 r = checked mapset lh 7 8 8 1 547 cpufence 548 put dispatchalarm 0 0 549 start = monons 550 if lt start 0 551 exit 74 552 end 553 planpublish sent start 554 sent = add sent get ps 6 555 while ne mapget lh 7 8 8 0 bound `9223372036854775807` 556 plantimeout start 557 cpurelax 558 end 559 cpufence 560 elapsed = sub monons start 561 if lt elapsed 0 562 exit 74 563 end 564 slowdispatch ulong elapsed 565 recordtoken step tok 566 emit planstep 567 printnum step 568 emit plantok 569 printnum mapget tok bufoffset get ps 9 4 570 emit planus 571 printnum div ulong elapsed 1000 572 emit newline 573 end 574 end 575 fn planfree to void 576 zerohdr 577 hput 0 4 get launch 7 578 r = checked kfdctl int get dev 0 `3221768963` hdr 0 8 579 r = checked mapdrop long get launch 8 580 for i ulong add get launch 1 8 bound `9223372036854775807` 581 if ne mapget long get launch 0 mul i 24 8 0 582 gpufree long get launch 0 mul i 24 583 end 584 end 585 for i ulong get ps 3 bound `9223372036854775807` 586 r = checked fclose int cm i 0 587 end 588 for i ulong get ps 4 bound `9223372036854775807` 589 r = checked fclose int fm i 0 590 end 591 r = checked fclose int get dev 1 592 r = checked fclose int get dev 0 593 r = checked fclose int get ps 1 594 r = checked mapdrop long get ps 0 595 for i ulong 4 596 r = checked mapdrop long get ps add 17 i 597 end 598 r = checked mapdrop long get launch 0 599 r = checked mapdrop long get ps 23 600 emit plandone 601 printids 602 r = checked mapdrop long get ps 22 603 end 604 fn planmain to int 605 plancheck 606 connectkfd 607 planload 608 planrun 609 planfree 610 ret 0 611 end