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/om/api/apish_shp.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 / om / api / apish_shp.om` 900 lines · 12539 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Shape, alignment, overflow and refusal decisions for the kernel-family API shells. 3 note One ulong result. Multi-field results pack the second field in bits 32..63. 4 note op 1 lane bytes, 2 fp8 defaults, 3 register fit, 4 tgemm bm, 5 tgemm spec, 5 note 6 tgemm size, 7 tern rows and depth, 8 tern warps and ctas, 9 pad 8, 6 note 10 segment bound, 11 segment end, 12 f32 finite, 13 packed bytes, 14 align, 7 note 15 tile 8, 16 cta budget, 17 perm4, 18 pf bm, 19 swiglu source, 20 max mkn, 8 note 21 decode cache bounds, 22 decode register fit, 23 tern pack args, 24 router rows, 9 note 25 router dest, 26 router source, 27 decode splits, 28 power of two, 29 theta. 10 note 30 fp8 mt, 31 tc spec, 32 tc warps, 33 round up, 34 window offset, 35 window ok, 36 quant group. 11 note 37 qgemm rows, 38 qgemm wait, 39 declared registers at most 128. 12 13 fn lane k uint to ulong 14 if eq rem k 512 0 15 ret ulong 16 16 end 17 ret ulong 8 18 end 19 20 fn fp8def mt uint wp uint to ulong 21 m = mt 22 w = wp 23 if eq mt 0 24 m = 4 25 end 26 if eq wp 0 27 w = 16 28 end 29 ret or ulong ulong m shl ulong ulong w 32 30 end 31 32 fn regfit w uint decl uint to ulong 33 p = mul ulong mul ulong 32 ulong w ulong decl 34 if le p ulong 65536 35 ret ulong 1 36 end 37 ret ulong 0 38 end 39 40 fn tgbm rt uint w uint n uint to ulong 41 if ne rt 0 42 ret mul ulong 16 ulong rt 43 end 44 ww = w 45 if eq w 0 46 ww = 16 47 if ne rem n 256 0 48 ww = 8 49 end 50 end 51 if eq ww 16 52 ret ulong 128 53 end 54 ret ulong 64 55 end 56 57 fn tgspec rt uint w uint n uint to ulong 58 ww = w 59 if eq w 0 60 ww = 16 61 if ne rem n 256 0 62 ww = 8 63 end 64 end 65 r = rt 66 if eq rt 0 67 r = 4 68 if eq ww 16 69 r = 8 70 end 71 end 72 ret or ulong ulong r shl ulong ulong ww 32 73 end 74 75 fn tgsz m uint n uint bm uint to ulong 76 if or eq m 0 eq bm 0 77 ret ulong 1 78 end 79 if ne rem m bm 0 80 ret ulong 1 81 end 82 if gt div m bm 65535 83 ret ulong 2 84 end 85 if ge mul ulong ulong m ulong n ulong `4294967296` 86 ret ulong 2 87 end 88 ret ulong 0 89 end 90 91 fn take ksc uint r uint d uint best uint lim uint to uint 92 if eq d 0 93 ret best 94 end 95 if gt d lim 96 ret best 97 end 98 if ne rem ksc d 0 99 ret best 100 end 101 if gt mul r d 16 102 ret best 103 end 104 if gt d best 105 ret d 106 end 107 ret best 108 end 109 fn scan ksc uint r uint d0 uint to uint 110 best = uint 1 111 f = uint 1 112 while le mul ulong f ulong f ulong ksc bound 65537 113 if eq rem ksc f 0 114 q = div ksc f 115 best = take ksc r f best d0 116 best = take ksc r q best d0 117 end 118 f = add f 1 119 end 120 ret best 121 end 122 fn ctz32 x uint to uint 123 if eq x 0 124 ret 32 125 end 126 n = uint 0 127 v = x 128 while eq and v 1 0 bound 31 129 v = shr v 1 130 n = add n 1 131 end 132 ret n 133 end 134 fn invodd a uint to uint 135 x = uint 1 136 for i uint 5 137 x = mul x sub 2 mul a x 138 end 139 ret x 140 end 141 fn largest step uint d0 uint to uint 142 if eq step 0 143 ret 0 144 end 145 ret sub d0 rem d0 step 146 end 147 fn cong0 r uint d0 uint to uint 148 inv = invodd r 149 best = uint 1 150 s = uint 0 151 while le s 16 bound 17 152 pp = mul s inv 153 if and le pp d0 ge pp 2 154 if gt pp best 155 best = pp 156 end 157 end 158 s = add s 1 159 end 160 ret best 161 end 162 fn candhi sg uint inv uint mod uint d0 uint to uint 163 pp = and mul sg inv sub mod 1 164 if gt pp d0 165 ret 0 166 end 167 ret add pp mul div sub d0 pp mod mod 168 end 169 fn conghi r uint d0 uint v uint to uint 170 g = shl 1 v 171 inv = invodd shr r v 172 mod = shl 1 sub 32 v 173 best = uint 1 174 s = uint 0 175 while le s 16 bound 17 176 if eq rem s g 0 177 c = candhi div s g inv mod d0 178 if and ge c 2 gt c best 179 best = c 180 end 181 end 182 s = add s g 183 end 184 ret best 185 end 186 fn cong r uint d0 uint to uint 187 v = ctz32 r 188 if ge v 5 189 d = largest shl 1 sub 32 v d0 190 if ge d 2 191 ret d 192 end 193 ret 1 194 end 195 if eq v 0 196 ret cong0 r d0 197 end 198 ret conghi r d0 v 199 end 200 fn tdepth ksc uint r uint d0 uint to uint 201 d = d0 202 while gt d 1 bound 65537 203 if eq rem ksc d 0 204 if le mul r d 16 205 ret d 206 end 207 end 208 d = sub d 1 209 end 210 ret d 211 end 212 213 fn ternd k uint lay uint R uint gr uint gd uint to ulong 214 nch = div add k 8191 8192 215 ksc = uint 0 216 if ne nch 0 217 ksc = div div k nch 256 218 end 219 r = gr 220 if eq lay 1 221 r = R 222 end 223 if and eq lay 0 eq r 0 224 r = 1 225 end 226 d0 = gd 227 if and eq gd 0 ne r 0 228 d0 = div 16 r 229 end 230 d0 = tdepth ksc r d0 231 ret or ulong ulong r shl ulong ulong d0 32 232 end 233 234 fn ternwc w uint ct uint to ulong 235 ww = w 236 cc = ct 237 if eq w 0 238 ww = 8 239 end 240 if eq ct 0 241 cc = 160 242 end 243 ret or ulong ulong ww shl ulong ulong cc 32 244 end 245 246 fn pad8 n uint to ulong 247 ret ulong mul div add n 7 8 8 248 end 249 250 fn segb i uint cnt uint n uint en uint mu uint to ulong 251 if ge add i 1 cnt 252 ret ulong n 253 end 254 if eq mu 2 255 if eq cnt 0 256 ret ulong 0 257 end 258 ret ulong mul add i 1 div n cnt 259 end 260 ret ulong en 261 end 262 263 fn segend i uint cnt uint n uint en uint pv uint to ulong 264 if or eq cnt 0 gt cnt 4 265 ret ulong 1 266 end 267 if eq en 0 268 ret ulong 1 269 end 270 if and ne i 0 le en pv 271 ret ulong 1 272 end 273 if and eq add i 1 cnt ne en n 274 ret ulong 1 275 end 276 ret ulong 0 277 end 278 279 fn finite u uint to ulong 280 if eq and shr u 23 255 255 281 ret ulong 0 282 end 283 ret ulong 1 284 end 285 286 fn pkbytes e uint k uint to ulong 287 ret mul mul ulong add div k 4 1 ulong e ulong 16 288 end 289 290 fn alignok lo uint mask uint to ulong 291 if eq and lo mask 0 292 ret ulong 1 293 end 294 ret ulong 0 295 end 296 297 fn tile8 c0 uint to ulong 298 if eq rem c0 8 0 299 ret ulong 1 300 end 301 ret ulong 0 302 end 303 304 fn ctabud segs uint ov uint to ulong 305 if ne ov 0 306 ret ulong ov 307 end 308 if ge segs 64 309 ret ulong 2 310 end 311 if ge segs 8 312 ret ulong 12 313 end 314 ret ulong 96 315 end 316 317 fn perm4 q uint to ulong 318 h = and q 3 319 o = uint 0 320 if eq h 1 321 o = 2 322 end 323 if eq h 2 324 o = 1 325 end 326 if eq h 3 327 o = 3 328 end 329 ret ulong or and q `4294967292` o 330 end 331 332 fn pfbm rt uint to ulong 333 r = rt 334 if eq rt 0 335 r = 8 336 end 337 ret mul ulong 16 ulong r 338 end 339 340 fn swsrc p uint n uint to ulong 341 G = div p 16 342 h = rem p 16 343 i = uint perm4 add mul 8 G rem h 8 344 if lt h 8 345 ret ulong i 346 end 347 ret ulong add div n 2 i 348 end 349 350 fn maxmnk m uint k uint n uint to ulong 351 if or eq m 0 or eq k 0 eq n 0 352 ret ulong 0 353 end 354 if or gt m 8192 or gt k 16384 gt n 262144 355 ret ulong 0 356 end 357 ret ulong 1 358 end 359 360 fn dcache layers uint mx uint rot uint to ulong 361 if or eq layers 0 gt layers 64 362 ret ulong 1 363 end 364 if or eq mx 0 or gt mx 131072 ne rem mx 256 0 365 ret ulong 1 366 end 367 if or lt rot 2 or gt rot 256 ne rem rot 2 0 368 ret ulong 1 369 end 370 ret ulong 0 371 end 372 373 fn dreg decl uint to ulong 374 if le mul ulong 256 ulong decl ulong 65536 375 ret ulong 1 376 end 377 ret ulong 0 378 end 379 380 fn tpack n uint k uint lay uint R uint np uint to ulong 381 if or eq n 0 ne rem k 16 0 382 ret ulong 1 383 end 384 if lt np n 385 ret ulong 1 386 end 387 step = uint 1 388 if eq lay 1 389 step = R 390 end 391 if eq step 0 392 ret ulong 1 393 end 394 if ne rem np mul 2 step 0 395 ret ulong 1 396 end 397 ret ulong 0 398 end 399 400 fn rrows s uint to ulong 401 if eq s 0 402 ret ulong 16 403 end 404 ret ulong s 405 end 406 407 fn rtdst g uint ex uint q uint e uint to ulong 408 ret ulong add mul add mul g e ex 4 q 409 end 410 411 fn rtsrc ex uint k uint g uint q uint to ulong 412 ret ulong add add mul ex k mul 4 g q 413 end 414 415 fn dsplit pos uint per uint mx uint to ulong 416 p = per 417 if eq per 0 418 p = 256 419 end 420 if ne rem p 256 0 421 ret ulong 1 422 end 423 sp = div add pos p p 424 if gt sp mx 425 ret ulong 2 426 end 427 ret shl ulong ulong sp 32 428 end 429 430 fn vy2 v uint to ulong 431 if eq v 0 432 ret ulong 0 433 end 434 if eq and v sub v 1 0 435 ret ulong 1 436 end 437 ret ulong 0 438 end 439 440 fn thok lo uint hi uint to ulong 441 t = bitcast f64 or ulong ulong lo shl ulong ulong hi 32 442 if gt t 0.0f64 443 ret ulong 1 444 end 445 ret ulong 0 446 end 447 448 fn fp8mt mt uint segs uint to ulong 449 if ne mt 0 450 ret ulong mt 451 end 452 if lt segs 8 453 ret ulong 8 454 end 455 ret ulong 4 456 end 457 fn tcsp rt uint ct uint n uint to ulong 458 r = rt 459 c = ct 460 if eq rt 0 461 r = 4 462 end 463 if eq ct 0 464 c = 1 465 if eq rem n 128 0 466 c = 2 467 end 468 end 469 ret or ulong ulong r shl ulong ulong c 32 470 end 471 fn tcw w uint to ulong 472 if eq w 0 473 ret ulong 8 474 end 475 ret ulong w 476 end 477 fn rup v uint q uint to ulong 478 if eq q 0 479 ret ulong 0 480 end 481 ret ulong mul div add v sub q 1 q q 482 end 483 fn woff kp uint col0 uint to ulong 484 ret mul mul ulong div col0 8 ulong kp ulong 16 485 end 486 fn wok c0 uint cols uint n uint to ulong 487 if ne rem c0 8 0 488 ret ulong 0 489 end 490 if eq cols 0 491 ret ulong 0 492 end 493 if gt c0 n 494 ret ulong 0 495 end 496 if gt cols sub n c0 497 ret ulong 0 498 end 499 ret ulong 1 500 end 501 fn qgrp kb uint to ulong 502 g = uint 32 503 while and gt g 0 ne rem kb g 0 bound 32 504 g = sub g 1 505 end 506 ret ulong g 507 end 508 fn qrt rt uint to ulong 509 if eq rt 0 510 ret ulong 4 511 end 512 ret ulong rt 513 end 514 fn qwait set uint w uint to ulong 515 if eq set 0 516 ret ulong 45 517 end 518 ret ulong w 519 end 520 fn le128 d uint to ulong 521 if gt d 128 522 ret ulong 0 523 end 524 ret ulong 1 525 end 526 527 fn roomok n uint pos uint mx uint to ulong 528 if eq n 0 529 ret ulong 1 530 end 531 if gt pos mx 532 ret ulong 1 533 end 534 room = sub mx pos 535 if gt n room 536 ret ulong 1 537 end 538 ret ulong 0 539 end 540 fn pa256b m uint pos uint mx uint to ulong 541 if gt m 32768 542 ret ulong 1 543 end 544 ret roomok m pos mx 545 end 546 fn qydiv qh uint pc uint to ulong 547 if eq pc 0 548 ret shl ulong ulong 1 32 549 end 550 ret ulong div qh pc 551 end 552 fn qfbyt rows uint qh uint to ulong 553 pairs = div add rows 1 2 554 ret mul ulong mul ulong pairs ulong qh ulong 1024 555 end 556 fn gxatt m uint to ulong 557 ret ulong div add m 7 8 558 end 559 fn kvsb mx uint to ulong 560 ret mul ulong mx ulong 512 561 end 562 fn hostb n uint w uint to ulong 563 ret mul ulong mul ulong n ulong w ulong 4 564 end 565 fn vy16 v uint to ulong 566 if gt v 16 567 ret ulong 1 568 end 569 ret ulong 0 570 end 571 fn splt mx uint to ulong 572 ret ulong div mx 256 573 end 574 fn plane kvh uint mx uint to ulong 575 ret add mul ulong mul ulong kvh ulong mx ulong 512 ulong 8256 576 end 577 fn persok p uint to ulong 578 if eq p 0 579 ret ulong 1 580 end 581 if eq p 256 582 ret ulong 1 583 end 584 ret ulong 0 585 end 586 fn stride need uint got uint mask uint to ulong 587 if lt got need 588 ret ulong 1 589 end 590 if ne and got mask 0 591 ret ulong 1 592 end 593 ret ulong 0 594 end 595 fn mtfit n uint pos uint vy uint to ulong 596 smax = add div add pos sub n 1 256 1 597 prod = mul ulong mul ulong mul ulong n ulong vy ulong smax ulong 6192 598 if gt prod ulong `67108864` 599 ret ulong 1 600 end 601 ret ulong 0 602 end 603 fn mtgrp left uint p0 uint t0 uint vy uint to ulong 604 n = left 605 if gt n 128 606 n = uint 128 607 end 608 pos = add p0 t0 609 while and gt n 1 eq mtfit n pos vy 1 bound 128 610 n = sub n 1 611 end 612 smax = add div add pos sub n 1 256 1 613 ret or ulong ulong n shl ulong ulong smax 32 614 end 615 fn mtbig n uint vy uint sm uint to ulong 616 ps = mul ulong mul ulong vy ulong sm ulong 6192 617 if gt mul ulong n ulong ps ulong `67108864` 618 ret ulong 1 619 end 620 ret ulong 0 621 end 622 fn smaxp pos uint n uint to ulong 623 ret ulong add div add pos sub n 1 256 1 624 end 625 fn mtps vy uint sm uint to ulong 626 ret mul ulong mul ulong vy ulong sm ulong 6192 627 end 628 fn p2bad v uint to ulong 629 if eq v 0 630 ret ulong 1 631 end 632 if ne and v sub v 1 0 633 ret ulong 1 634 end 635 ret ulong 0 636 end 637 638 fn nkbad n uint k uint to ulong 639 if eq n 0 640 ret ulong 1 641 end 642 if gt n `1073741824` 643 ret ulong 1 644 end 645 if eq k 0 646 ret ulong 1 647 end 648 if ne rem k 256 0 649 ret ulong 1 650 end 651 if gt k 16384 652 ret ulong 2 653 end 654 if and gt k 8192 ne rem k 512 0 655 ret ulong 2 656 end 657 ret ulong 0 658 end 659 fn layok lay uint R uint to ulong 660 if gt lay 1 661 ret ulong 1 662 end 663 if and eq lay 1 ne R 2 664 if ne R 4 665 ret ulong 1 666 end 667 end 668 ret ulong 0 669 end 670 fn tritok v uint to ulong 671 if eq v 0 672 ret ulong 1 673 end 674 if eq v 1 675 ret ulong 1 676 end 677 if eq v 255 678 ret ulong 1 679 end 680 ret ulong 0 681 end 682 fn qset k uint to ulong 683 if ne rem k 128 0 684 ret ulong 0 685 end 686 kb = div k 128 687 if le kb 32 688 ret ulong 0 689 end 690 ret qgrp kb 691 end 692 fn pfargs n uint k uint lay uint to ulong 693 if eq n 0 694 ret ulong 1 695 end 696 if eq k 0 697 ret ulong 1 698 end 699 if ne rem n 128 0 700 ret ulong 1 701 end 702 if ne rem k 128 0 703 ret ulong 1 704 end 705 if gt lay 1 706 ret ulong 1 707 end 708 if and eq lay 1 ne rem n 256 0 709 ret ulong 1 710 end 711 ret ulong 0 712 end 713 714 715 fn apishp op uint a uint b uint c uint d uint e uint to ulong 716 if eq op 1 717 ret lane a 718 end 719 if eq op 2 720 ret fp8def a b 721 end 722 if eq op 3 723 ret regfit a b 724 end 725 if eq op 4 726 ret tgbm a b c 727 end 728 if eq op 5 729 ret tgspec a b c 730 end 731 if eq op 6 732 ret tgsz a b c 733 end 734 if eq op 7 735 ret ternd a b c d e 736 end 737 if eq op 8 738 ret ternwc a b 739 end 740 if eq op 9 741 ret pad8 a 742 end 743 if eq op 10 744 ret segb a b c d e 745 end 746 if eq op 11 747 ret segend a b c d e 748 end 749 if eq op 12 750 ret finite a 751 end 752 if eq op 13 753 ret pkbytes a b 754 end 755 if eq op 14 756 ret alignok a b 757 end 758 if eq op 15 759 ret tile8 a 760 end 761 if eq op 16 762 ret ctabud a b 763 end 764 if eq op 17 765 ret perm4 a 766 end 767 if eq op 18 768 ret pfbm a 769 end 770 if eq op 19 771 ret swsrc a b 772 end 773 if eq op 20 774 ret maxmnk a b c 775 end 776 if eq op 21 777 ret dcache a b c 778 end 779 if eq op 22 780 ret dreg a 781 end 782 if eq op 23 783 ret tpack a b c d e 784 end 785 if eq op 24 786 ret rrows a 787 end 788 if eq op 25 789 ret rtdst a b c d 790 end 791 if eq op 26 792 ret rtsrc a b c d 793 end 794 if eq op 27 795 ret dsplit a b c 796 end 797 if eq op 28 798 ret vy2 a 799 end 800 if eq op 29 801 ret thok a b 802 end 803 if eq op 30 804 ret fp8mt a b 805 end 806 if eq op 31 807 ret tcsp a b c 808 end 809 if eq op 32 810 ret tcw a 811 end 812 if eq op 33 813 ret rup a b 814 end 815 if eq op 34 816 ret woff a b 817 end 818 if eq op 35 819 ret wok a b c 820 end 821 if eq op 36 822 ret qgrp a 823 end 824 if eq op 37 825 ret qrt a 826 end 827 if eq op 38 828 ret qwait a b 829 end 830 if eq op 39 831 ret le128 a 832 end 833 if eq op 40 834 ret roomok a b c 835 end 836 if eq op 41 837 ret qydiv a b 838 end 839 if eq op 42 840 ret qfbyt a b 841 end 842 if eq op 43 843 ret gxatt a 844 end 845 if eq op 44 846 ret kvsb a 847 end 848 if eq op 45 849 ret hostb a b 850 end 851 if eq op 46 852 ret pa256b a b c 853 end 854 if eq op 47 855 ret vy16 a 856 end 857 if eq op 48 858 ret splt a 859 end 860 if eq op 49 861 ret plane a b 862 end 863 if eq op 50 864 ret persok a 865 end 866 if eq op 51 867 ret stride a b c 868 end 869 if eq op 52 870 ret mtgrp a b c d 871 end 872 if eq op 53 873 ret mtbig a b c 874 end 875 if eq op 54 876 ret smaxp a b 877 end 878 if eq op 55 879 ret mtps a b 880 end 881 if eq op 56 882 ret p2bad a 883 end 884 if eq op 57 885 ret nkbad a b 886 end 887 if eq op 58 888 ret layok a b 889 end 890 if eq op 59 891 ret tritok a 892 end 893 if eq op 60 894 ret qset a 895 end 896 if eq op 61 897 ret pfargs a b c 898 end 899 ret ulong 0 900 end