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/cubin/cubin_elf.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 / cubin / cubin_elf.om` 609 lines · 13399 bytes Raw Blame History 1 note cubin_elf.om: explicitly selected sm_86/sm_121 cubin ELF packer. 2 note It replaces the body of omega_cubin_pack in src/omega_cubin.c, which stays compiled only behind 3 note CUDAPP_MIGRATION_PENDING_C_CORE as the explicit legacy oracle. 4 note 5 note Input (omega_cubin.c packs it): 6 note m: 0 strlen of the name 1 text_len 2 nparams 3 cbank_size 4 gpr_count 5 shared_reserved 7 note 6 target SM (86 or 121; 0 retains historical 121) 7 unused; from 8 parameter triples 8 note nm: the name's first 64 bytes; tx: the text (`16777216` bytes, the C limit 1 shl 24) 9 note o: the output image, little-endian words; byte p is bits 8 (p rem 8) of word p / 8 10 note Result: the image's byte count, or the refusal 1..7 of OMEGA_CUBIN_E_* (an image is never below 8 11 note bytes). On a refusal o 0 holds the detail (PARAMS 0 count, 1 overlap, 2 size, 3 pointer size, 12 note 4 alignment; CBANK 5 end, 6 range; MEM 7 over the output bound), o 1 the parameter, o 2 the end 13 note or the image size, so the C caller prints the oracle's exact message. 14 note Bound: the output view holds `134217728` bytes; an image above it (the in-file shared reservation plus the 15 note text plus a few KiB of headers over 128 MiB) 16 note is refused with 7 where the C oracle would allocate it. Arrays stop at `16777216` elements (error 23). 17 note Every constant is the decimal form of the C writer's hex or text (conversions by Wolfram, 18 note evidence/CUDAPP-OM-CUBIN/wolfram-constants.txt). 19 20 const TXN ulong `16777216` 21 const OWN ulong `16777216` 22 const OBYTES ulong `134217728` 23 const MLEN ulong 104 24 const PBASE ulong 896 25 26 fn parbase m view ulong MLEN to ulong 27 if eq get m 6 86 28 ret 352 29 end 30 ret PBASE 31 end 32 33 fn smtarget m view ulong MLEN to ulong 34 if eq get m 6 0 35 ret 121 36 end 37 ret get m 6 38 end 39 40 note 1 when the image carries .note.nv.tkinfo (sm_121 only: its strings name sm_121; sm_86 has none) 41 fn tkon m view ulong MLEN to ulong 42 if eq smtarget m 121 43 ret 1 44 end 45 ret 0 46 end 47 48 note one byte into the word image 49 fn pb o edit ulong OWN p ulong v ulong to void 50 k = shr p 3 51 s = shl and p 7 3 52 w = and get o k not shl 255 s 53 put o k or w shl and v 255 s 54 end 55 56 fn p16 o edit ulong OWN p ulong v ulong to void 57 pb o p v 58 pb o add p 1 shr v 8 59 end 60 61 fn p32 o edit ulong OWN p ulong v ulong to void 62 p16 o p v 63 p16 o add p 2 shr v 16 64 end 65 66 fn p64 o edit ulong OWN p ulong v ulong to void 67 p32 o p v 68 p32 o add p 4 shr v 32 69 end 70 71 note the k low bytes of v at p; gives p + k 72 fn ps o edit ulong OWN p ulong v ulong k ulong to ulong 73 for i ulong k 74 pb o add p i shr v mul i 8 75 end 76 ret add p k 77 end 78 79 note the n name bytes at p; gives p + n 80 fn pn o edit ulong OWN p ulong nm view uchar 64 n ulong to ulong 81 for i ulong n 82 pb o add p i ulong get nm i 83 end 84 ret add p n 85 end 86 87 fn al x ulong a ulong to ulong 88 ret mul div add x sub a 1 a a 89 end 90 91 fn isal c uchar to ulong 92 if or or and ge c 65 le c 90 and ge c 97 le c 122 eq c 95 93 ret 1 94 end 95 ret 0 96 end 97 98 fn isan c uchar to ulong 99 if or ne isal c 0 and ge c 48 le c 57 100 ret 1 101 end 102 ret 0 103 end 104 105 note name_ok of the C writer: 1..64 bytes, [A-Za-z_][A-Za-z0-9_]* 106 fn nmok nm view uchar 64 n ulong to ulong 107 if or eq n 0 gt n 64 108 ret 0 109 end 110 if eq isal get nm 0 0 111 ret 0 112 end 113 for i ulong n 114 if eq isan get nm i 0 115 ret 0 116 end 117 end 118 ret 1 119 end 120 121 fn pfail o edit ulong OWN d ulong i ulong to ulong 122 put o 0 d 123 put o 1 i 124 ret 3 125 end 126 127 note one parameter against the running end e: 0 good, else the detail 1..4 of the C order 128 fn pbad of ulong sz ulong pt ulong e ulong to ulong 129 if lt of e 130 ret 1 131 end 132 if not or or or eq sz 8 eq sz 4 eq sz 2 eq sz 1 133 ret 2 134 end 135 if and ne pt 0 ne sz 8 136 ret 3 137 end 138 if and eq sz 8 ne and of 7 0 139 ret 4 140 end 141 if and eq sz 4 ne and of 3 0 142 ret 4 143 end 144 if and eq sz 2 ne and of 1 0 145 ret 4 146 end 147 ret 0 148 end 149 150 note the parameter walk and the bank checks, in the C order 151 fn pchk m view ulong MLEN o edit ulong OWN to ulong 152 e = parbase m 153 np = get m 2 154 for i ulong np 155 b = add 8 mul i 3 156 d = pbad get m b get m add b 1 get m add b 2 e 157 if ne d 0 158 ret pfail o d i 159 end 160 e = add get m b get m add b 1 161 end 162 cb = get m 3 163 if gt e cb 164 put o 0 5 165 put o 2 e 166 ret 4 167 end 168 if or gt cb 1024 lt cb parbase m 169 put o 0 6 170 ret 4 171 end 172 ret 0 173 end 174 175 fn chk m view ulong MLEN nm view uchar 64 o edit ulong OWN to ulong 176 if not or eq smtarget m 86 eq smtarget m 121 177 ret 1 178 end 179 if eq nmok nm get m 0 0 180 ret 1 181 end 182 tl = get m 1 183 if or or eq tl 0 ne and tl 15 0 gt tl TXN 184 ret 2 185 end 186 if gt get m 2 32 187 ret pfail o 0 0 188 end 189 if gt get m 4 255 190 ret 5 191 end 192 if ne and get m 5 3 0 193 ret 6 194 end 195 ret pchk m o 196 end 197 198 note L: 1..10 section offsets, 11 shoff, 12 phoff, 13 total, 14 .nv.info. size, 199 note 15 the offset of section 11 (.note.nv.tkinfo, sm_121 only) 200 fn lay m view ulong MLEN l edit ulong 16 to void 201 n = get m 0 202 f = ulong 64 203 put l 1 f 204 f = add f add add 117 mul 16 tkon m mul 3 n 205 put l 2 f 206 f = add f add n 2 207 f = al f 8 208 put l 3 f 209 f = add f 96 210 f = al f 128 211 put l 4 f 212 f = add f get m 1 213 f = al f 16 214 put l 5 f 215 f = add f get m 3 216 f = al f 4 217 put l 6 f 218 f = add f 36 219 f = al f 4 220 put l 7 f 221 f = add f 36 222 il = add 48 mul 16 get m 2 223 put l 14 il 224 f = al f 4 225 put l 8 f 226 f = add f il 227 put l 9 f 228 f = add f get m 5 229 f = al f 4 230 put l 10 f 231 f = add f 32 232 if eq tkon m 1 233 f = al f 4 234 put l 15 f 235 f = add f 120 236 end 237 f = al f 8 238 put l 11 f 239 put l 12 add f add 704 mul 64 tkon m 240 put l 13 add f add 984 mul 64 tkon m 241 end 242 243 note zero words 0 .. ceil(total / 8) - 1, in parts of 4096 (a loop stops at `1000000` passes) 244 fn wzero o edit ulong OWN total ulong to void 245 nw = shr add total 7 3 246 nc = shr add nw 4095 12 247 for c ulong nc 248 for j ulong 4096 249 k = add shl c 12 j 250 if lt k nw 251 put o k 0 252 end 253 end 254 end 255 end 256 257 fn txw tx view uchar TXN q ulong to ulong 258 w = ulong 0 259 for i ulong 8 260 w = or w shl ulong get tx add q i mul i 8 261 end 262 ret w 263 end 264 265 note the text at p (a multiple of 128), whole words: text_len is a multiple of 16 266 fn wtext o edit ulong OWN tx view uchar TXN p ulong tl ulong to void 267 nw = shr tl 3 268 nc = shr add nw 4095 12 269 b = shr p 3 270 for c ulong nc 271 for j ulong 4096 272 k = add shl c 12 j 273 if lt k nw 274 put o add b k txw tx shl k 3 275 end 276 end 277 end 278 end 279 280 note ELF header: 0x7f E L F, ELFCLASS64, LSB, version 1, ELFOSABI_NV 0x41 as one word; ABI version 8 281 fn whdr o edit ulong OWN l view ulong 16 m view ulong MLEN to void 282 p64 o 0 `4684026196722992511` 283 if eq smtarget m 86 284 pb o 7 51 285 end 286 if eq smtarget m 86 287 pb o 8 7 288 else 289 pb o 8 8 290 end 291 p16 o 16 2 292 p16 o 18 190 293 if eq smtarget m 86 294 p32 o 20 130 295 else 296 p32 o 20 1 297 end 298 p64 o 32 get l 12 299 p64 o 40 get l 11 300 if eq smtarget m 86 301 note ELF EF_CUDA_SM86 | EF_CUDA_VIRTUAL_SM86 | 64-bit addressing and unified texture mode. 302 p32 o 48 or shl ulong 86 16 or shl ulong 5 8 ulong 86 303 else 304 p32 o 48 `100694274` 305 end 306 p16 o 52 64 307 p16 o 54 56 308 p16 o 56 5 309 p16 o 58 64 310 p16 o 60 add 11 tkon m 311 p16 o 62 1 312 end 313 314 note .shstrtab from p (its first byte is the 0 already there) 315 fn wshs o edit ulong OWN p ulong nm view uchar 64 n ulong tk ulong to void 316 q = add p 1 317 q = ps o q `7022363563455443758` 8 318 q = add ps o q 98 1 1 319 q = add ps o q `27691700481979182` 7 1 320 q = add ps o q `27691700398420782` 7 1 321 q = ps o q `51077770998830` 6 322 q = add pn o q nm n 1 323 q = ps o q `8317708033571843630` 8 324 q = ps o q `50785646698868` 6 325 q = add pn o q nm n 1 326 q = add ps o q `8027224783864622638` 8 1 327 q = ps o q `8101253776481349166` 8 328 q = add ps o q 29793 2 1 329 q = ps o q `8027224783864622638` 8 330 q = ps o q 46 1 331 q = add pn o q nm n 1 332 q = ps o q `8241983636974759470` 8 333 q = ps o q `8243121572516095077` 8 334 q = add ps o q `206936761718` 5 1 335 q = ps o q `8533809357193702958` 8 336 if eq tk 1 337 q = add ps o q `31356346816619310` 7 1 338 q = ps o q `8533809357193702958` 8 339 q = ps o q `31356346815968302` 7 340 else 341 q = ps o q `31356346816619310` 7 342 end 343 end 344 345 note .symtab: null, the .text section symbol, the function, the .nv.constant0 section symbol 346 fn wsym o edit ulong OWN p ulong tl ulong to void 347 pb o add p 28 3 348 p16 o add p 30 4 349 p32 o add p 48 1 350 pb o add p 52 18 351 pb o add p 53 16 352 p16 o add p 54 4 353 p64 o add p 64 tl 354 pb o add p 76 3 355 p16 o add p 78 5 356 end 357 358 note .nv.info: attributes 0x2f (registers), 0x11, 0x12 359 fn wginfo o edit ulong OWN p ulong gpr ulong to void 360 p16 o p 12036 361 p16 o add p 2 8 362 p32 o add p 4 2 363 p32 o add p 8 gpr 364 p16 o add p 12 4356 365 p16 o add p 14 8 366 p32 o add p 16 2 367 p16 o add p 24 4612 368 p16 o add p 26 8 369 p32 o add p 28 2 370 end 371 372 note .nv.compat: nine little-endian words of the reference container 373 fn wcompat o edit ulong OWN p ulong to void 374 p32 o p 2306 375 p32 o add p 4 131586 376 p32 o add p 8 328962 377 p32 o add p 12 `16844547` 378 p32 o add p 16 770 379 p32 o add p 20 67074 380 p32 o add p 24 527108 381 end 382 383 note attribute 0x37 then one 0x17 per parameter from p; gives the parameter end 384 fn wpar o edit ulong OWN p ulong m view ulong MLEN to ulong 385 p16 o p 14084 386 p16 o add p 2 4 387 p32 o add p 4 130 388 q = add p 8 389 e = parbase m 390 np = get m 2 391 for i ulong np 392 b = add 8 mul i 3 393 of = get m b 394 p16 o q 5892 395 p16 o add q 2 12 396 p32 o add q 8 or i shl sub of parbase m 16 397 ty = ulong `1175552` 398 if ne get m add b 2 0 399 ty = `2225408` 400 end 401 p32 o add q 12 ty 402 q = add q 16 403 if gt add of get m add b 1 e 404 e = add of get m add b 1 405 end 406 end 407 ret e 408 end 409 410 note the attributes after the parameters, from q 411 fn wtail o edit ulong OWN q ulong e ulong gpr ulong base ulong to void 412 p16 o q 6403 413 p16 o add q 2 sub e base 414 p16 o add q 4 2564 415 p16 o add q 6 8 416 p32 o add q 8 3 417 p32 o add q 12 or base shl sub e base 16 418 p16 o add q 16 20483 419 p16 o add q 20 6915 420 p16 o add q 22 gpr 421 p16 o add q 24 24323 422 p16 o add q 26 257 423 p16 o add q 28 18946 424 p16 o add q 32 13828 425 p16 o add q 34 4 426 end 427 428 note .note.nv.cuinfo: namesz 12, descsz 8, type 0x3e8, "NVIDIA Corp", 2, sm 121, 130 429 fn wnote o edit ulong OWN p ulong sm ulong to void 430 p32 o p 12 431 p32 o add p 4 8 432 p32 o add p 8 1000 433 q = ps o add p 12 `4836937782729987662` 8 434 q = ps o q `7369327` 3 435 p16 o add p 24 2 436 p16 o add p 26 sm 437 p32 o add p 28 130 438 end 439 440 note .note.nv.tkinfo, which the sm_121 driver requires (CUDApp#68): namesz 12, descsz 96, type 2000, 441 note "NVIDIA Corp", then 2, 0 and the offsets 1 8 34 52 of the strings "cudapp", "CUDApp omega_cubin 442 note sm_121", "Build omega_cubin" and "-arch sm_121" in the blob from p + 48 (its bytes 64.. stay 0) 443 fn wtk o edit ulong OWN p ulong to void 444 p32 o p 12 445 p32 o add p 4 96 446 p32 o add p 8 2000 447 q = ps o add p 12 `4836937782729987662` 8 448 q = ps o q `7369327` 3 449 p32 o add p 24 2 450 p32 o add p 32 1 451 p32 o add p 36 8 452 p32 o add p 40 34 453 p32 o add p 44 52 454 q = ps o add p 48 `31648760991146752` 8 455 q = ps o q `8007523764898387267` 8 456 q = ps o q `7094686049299293549` 8 457 q = ps o q `3616776899442798185` 8 458 q = ps o q `2334109707079385137` 8 459 q = ps o q `8458709397083090287` 8 460 q = ps o q `7165896803008538978` 8 461 q = ps o q `3544950142621917288` 8 462 end 463 464 fn sh1 o edit ulong OWN b ulong nm ulong ty ulong fl ulong to void 465 p32 o b nm 466 p32 o add b 4 ty 467 p64 o add b 8 fl 468 end 469 470 fn sh2 o edit ulong OWN b ulong of ulong sz ulong lk ulong inf ulong to void 471 p64 o add b 24 of 472 p64 o add b 32 sz 473 p32 o add b 40 lk 474 p32 o add b 44 inf 475 end 476 477 fn sh3 o edit ulong OWN b ulong a ulong es ulong to void 478 p64 o add b 48 a 479 p64 o add b 56 es 480 end 481 482 note section headers 1..5 483 fn wsha o edit ulong OWN l view ulong 16 m view ulong MLEN to void 484 n = get m 0 485 b = add get l 11 64 486 sh1 o b 1 3 0 487 sh2 o b get l 1 add add 117 mul 16 tkon m mul 3 n 0 0 488 sh3 o b 1 0 489 b = add b 64 490 sh1 o b 11 3 0 491 sh2 o b get l 2 add n 2 0 0 492 sh3 o b 1 0 493 b = add b 64 494 sh1 o b 19 2 0 495 sh2 o b get l 3 96 2 2 496 sh3 o b 8 24 497 b = add b 64 498 sh1 o b 27 1 6 499 sh2 o b get l 4 get m 1 3 2 500 sh3 o b 128 0 501 b = add b 64 502 sh1 o b add 34 n 1 66 503 sh2 o b get l 5 get m 3 3 4 504 sh3 o b 16 0 505 end 506 507 note section headers 6..11 508 fn wshb o edit ulong OWN l view ulong 16 m view ulong MLEN to void 509 n = get m 0 510 b = add get l 11 384 511 sh1 o b add 49 mul 2 n `1879048192` 0 512 sh2 o b get l 6 36 3 0 513 sh3 o b 4 0 514 b = add b 64 515 sh1 o b add 58 mul 2 n `1879048326` 0 516 sh2 o b get l 7 36 0 0 517 sh3 o b 4 0 518 b = add b 64 519 sh1 o b add 69 mul 2 n `1879048192` 64 520 sh2 o b get l 8 get l 14 3 4 521 sh3 o b 4 0 522 b = add b 64 523 sh1 o b add 79 mul 3 n 8 3 524 sh2 o b get l 9 get m 5 0 0 525 sh3 o b 1 0 526 b = add b 64 527 sh1 o b add 101 mul 3 n 7 `16777280` 528 sh2 o b get l 10 32 mul 11 tkon m 2 529 sh3 o b 4 0 530 if eq tkon m 1 531 b = add b 64 532 sh1 o b add 117 mul 3 n 7 `33554432` 533 sh2 o b get l 15 120 0 0 534 sh3 o b 4 0 535 end 536 end 537 538 fn ph1 o edit ulong OWN b ulong ty ulong fl ulong of ulong to void 539 p32 o b ty 540 p32 o add b 4 fl 541 p64 o add b 8 of 542 p64 o add b 48 8 543 end 544 545 fn ph2 o edit ulong OWN b ulong fs ulong ms ulong to void 546 p64 o add b 32 fs 547 p64 o add b 40 ms 548 end 549 550 note program headers: PHDR, LOAD R (the table), LOAD R|E (text), LOAD R|W (shared), LOAD R (bank) 551 fn wph o edit ulong OWN l view ulong 16 m view ulong MLEN to void 552 b = get l 12 553 ph1 o b 6 4 b 554 ph2 o b 280 280 555 ph1 o add b 56 1 4 b 556 ph2 o add b 56 280 280 557 ph1 o add b 112 1 5 get l 4 558 ph2 o add b 112 get m 1 get m 1 559 ph1 o add b 168 1 6 get l 9 560 ph2 o add b 168 0 get m 5 561 ph1 o add b 224 1 4 get l 5 562 ph2 o add b 224 get m 3 get m 3 563 end 564 565 note .nv.info.: attribute 0x37, the parameters, then the tail 566 fn winfo o edit ulong OWN l view ulong 16 m view ulong MLEN to void 567 p = get l 8 568 e = wpar o p m 569 q = add add p 8 mul 16 get m 2 570 wtail o q e get m 4 parbase m 571 end 572 573 note every section payload and both header tables into the zeroed image 574 fn wbody o edit ulong OWN l view ulong 16 m view ulong MLEN nm view uchar 64 tx view uchar TXN to void 575 whdr o l m 576 n = get m 0 577 wshs o get l 1 nm n tkon m 578 q = pn o add get l 2 1 nm n 579 wsym o get l 3 get m 1 580 wtext o tx get l 4 get m 1 581 wginfo o get l 6 get m 4 582 wcompat o get l 7 583 winfo o l m 584 wnote o get l 10 smtarget m 585 if eq tkon m 1 586 wtk o get l 15 587 end 588 wsha o l m 589 wshb o l m 590 wph o l m 591 end 592 593 fn cubin_elf m view ulong 104 nm view uchar 64 tx view uchar `16777216` o edit ulong `16777216` to ulong 594 l = new ulong 16 0 595 rc = chk m nm o 596 if ne rc 0 597 ret rc 598 end 599 lay m edit l 600 t = get l 13 601 if gt t OBYTES 602 put o 0 7 603 put o 2 t 604 ret 7 605 end 606 wzero o t 607 wbody o view l m nm tx 608 ret t 609 end