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/omega-mv/blob/main/gpu/cuda-crack/gen/bw_enc_sm121.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / cuda-crack / gen / bw_enc_sm121.om` 551 lines ยท 12113 bytes Raw Blame History 1 note bw_enc_sm121.om: the sm_121 instruction encoder of CUDApp (aien-dev/CUDApp#79, OM-GPU-RETIRE). 2 note It turns a solved BlackwellIR program into machine code: four 32-bit words per instruction, 3 note little-endian, padded with NOPs to a multiple of 8 and at least 32 instructions. 4 note It replaces encode_single_insn and omega_bw_encode_program of src/omega_blackwell_codegen.c, 5 note which stays compiled only behind CUDAPP_MIGRATION_PENDING_C_ENCODER as the differential oracle 6 note (and in the freestanding build, which has no native binding yet). 7 note 8 note Input (bw_om_encode in src/omega_blackwell_codegen.c packs it; 8 ulong per instruction, at most 1024 instructions): 9 note 0 op (the BlackwellIROpcode number) 1 dst_vreg 2 src1_vreg 3 src2_vreg 4 src3_vreg 10 note 5 ureg (the five vreg fields are C int, passed as 64-bit two's complement: negative = none) 11 note 6 imm or control shl 32 12 note 7 is_uniform or predicate_p0 shl 1 or predicate_not shl 2 or bar_reg shl 8 13 note or dst_subreg shl 16 or src1_subreg shl 24 or src2_subreg shl 32 or src3_subreg shl 40 14 note phys: vreg_to_phys 0..255 then uvreg_to_phys at 256..287 (C int, two's complement). 15 note pad 1: omega_bw_encode_program (pad to the multiple of 8, at least 32); pad 0: exactly n instructions. 16 note Result: the bytes written, or 0 when an instruction is refused (unknown op, an offset outside its 17 note field, a BSSY delta below 2, a barrier register above 15) or n is above 1024. 18 note Every constant is the decimal form of the C encoder's hex word (conversions by Wolfram, 19 note evidence/CUDAPP-OM-ENCODER/wolfram-constants.txt). 20 21 const NEG ulong `9223372036854775808` 22 const NOPW ulong 31000 23 const NOPC ulong `1032192` 24 25 fn put4 w edit ulong 4 a ulong b ulong c ulong d ulong to void 26 put w 0 a 27 put w 1 b 28 put w 2 c 29 put w 3 d 30 end 31 32 note the physical register of one operand field: phys + subreg, or dflt when the vreg is negative 33 fn preg phys view ulong 288 v ulong sb ulong dflt ulong to ulong 34 if ge v NEG 35 ret dflt 36 end 37 ret add get phys v sb 38 end 39 40 note 1 when a vreg field is given (not negative), else 0 41 fn pres v ulong to ulong 42 if ge v NEG 43 ret 0 44 end 45 ret 1 46 end 47 48 note Only constant loads have uniform destinations; IMAD uses is_uniform for its source. 49 fn isuld op ulong to bool 50 ret or eq op 6 eq op 7 51 end 52 53 fn opnds ins view ulong 8192 i ulong phys view ulong 288 o edit ulong 16 to void 54 b = mul i 8 55 f = get ins add b 7 56 put o 0 get ins b 57 put o 1 preg phys get ins add b 1 and shr f 16 255 0 58 put o 2 preg phys get ins add b 2 and shr f 24 255 0 59 put o 3 preg phys get ins add b 3 and shr f 32 255 0 60 put o 4 preg phys get ins add b 4 and shr f 40 255 255 61 u = get ins add b 5 62 put o 5 0 63 if lt u NEG 64 put o 5 get phys add u 256 65 end 66 put o 14 pres u 67 x = get ins add b 6 68 put o 6 and x `4294967295` 69 put o 7 shr x 32 70 put o 8 and f 1 71 put o 9 and shr f 1 1 72 put o 10 and shr f 2 1 73 put o 11 and shr f 8 255 74 put o 12 pres get ins add b 2 75 put o 13 pres get ins add b 3 76 d = get ins add b 1 77 put o 15 pres d 78 if and isuld get o 0 lt d NEG 79 put o 1 get phys add d 256 80 end 81 end 82 83 note the control word: the instruction's own, else the op's default 84 fn ctl o view ulong 16 dflt ulong to ulong 85 c = get o 7 86 if ne c 0 87 ret c 88 end 89 ret dflt 90 end 91 92 note low 8 bits of operand slot k 93 fn rb o view ulong 16 k ulong to ulong 94 ret and get o k 255 95 end 96 97 note slot k when its vreg (presence slot h) is given, else RZ 98 fn rz o view ulong 16 k ulong h ulong to ulong 99 if ne get o h 0 100 ret rb o k 101 end 102 ret 255 103 end 104 105 fn wd o view ulong 16 base ulong to ulong 106 ret or base shl rb o 1 16 107 end 108 109 fn wa o view ulong 16 base ulong to ulong 110 ret or base shl rb o 2 24 111 end 112 113 fn wda o view ulong 16 base ulong to ulong 114 ret or wd o base shl rb o 2 24 115 end 116 117 note the 4-bit guard predicate field: 7 always, 0 @P0, 8 @!P0 118 fn pred o view ulong 16 to ulong 119 if eq get o 9 0 120 ret 7 121 end 122 if eq get o 10 0 123 ret 0 124 end 125 ret 8 126 end 127 128 note a signed 24-bit byte offset (imm read as int32) fits 129 fn off24 imm ulong to bool 130 ret or lt imm `8388608` ge imm `4286578688` 131 end 132 133 note ops 0..14: moves, constants, integer multiply-add, compares and global memory 134 fn enc_a o view ulong 16 w edit ulong 4 to ulong 135 op = get o 0 136 imm = get o 6 137 if eq op 0 138 put4 w NOPW 0 0 ctl o NOPC 139 ret 0 140 end 141 if eq op 1 142 put4 w wd o 29186 255 3840 ctl o `1040896` 143 ret 0 144 end 145 if eq op 2 146 put4 w wd o 30722 imm 3840 ctl o `1040896` 147 ret 0 148 end 149 if eq op 3 150 put4 w wd o 31001 0 shl and imm 255 8 ctl o 926208 151 ret 0 152 end 153 if eq op 4 154 put4 w wd o `4278221698` and shl imm 6 `16776960` 2048 ctl o `1040896` 155 ret 0 156 end 157 if eq op 5 158 put4 w wd o `4278221698` and shl imm 6 `16776960` 2560 ctl o 926208 159 ret 0 160 end 161 if eq op 6 162 put4 w wd o `4278220716` and shl imm 5 `16776960` `134219776` ctl o 926208 163 ret 0 164 end 165 if eq op 7 166 put4 w wd o `4278220716` and shl imm 5 `16776960` `134220288` ctl o 945664 167 ret 0 168 end 169 if eq op 8 170 if ne get o 13 0 171 put4 w wda o 29220 rb o 3 or `126747136` rb o 4 ctl o `2083328` 172 ret 0 173 end 174 if and ne get o 8 0 ne get o 14 0 175 put4 w wda o 31780 rb o 5 or `260964864` rb o 4 ctl o `2083328` 176 ret 0 177 end 178 put4 w wda o 30756 imm or `126747136` rb o 4 ctl o `2083328` 179 ret 0 180 end 181 if eq op 9 182 put4 w wda o 30757 imm or `126746624` rb o 4 ctl o `2083840` 183 ret 0 184 end 185 if eq op 10 186 if and ne get o 8 0 ne get o 14 0 187 put4 w wda o 31756 rb o 5 `200302704` ctl o `3136000` 188 ret 0 189 end 190 put4 w wda o 30732 imm `66085488` ctl o `2087424` 191 ret 0 192 end 193 if eq op 11 194 put4 w wda o 31105 rb o 5 `203299072` ctl o 991744 195 ret 0 196 end 197 if eq op 12 198 if not off24 imm 199 ret 1 200 end 201 put4 w wa o 31110 or rb o 3 shl and imm `16777215` 8 or `202381568` rb o 5 ctl o `1040896` 202 ret 0 203 end 204 if eq op 13 205 put4 w wa o 31110 rb o 3 or `202447104` rb o 5 ctl o `1040896` 206 ret 0 207 end 208 if eq op 14 209 put4 w wda o 29200 rb o 3 `134209791` ctl o `17811968` 210 ret 0 211 end 212 ret 1 213 end 214 215 note ops 15..29: tensor core, shifts, wide and strong loads, stores, fences, atomics 216 fn enc_b o view ulong 16 w edit ulong 4 to ulong 217 op = get o 0 218 imm = get o 6 219 if or eq op 15 eq op 16 220 p = ulong 0 221 if eq op 16 222 p = 262144 223 end 224 put4 w wda o 29244 rb o 3 or or rb o 4 6144 p ctl o `1040896` 225 ret 0 226 end 227 if eq op 17 228 put4 w or wd o 30745 `4278190080` imm or 71168 rb o 2 ctl o `2083328` 229 ret 0 230 end 231 if eq op 18 232 put4 w wda o 30738 imm `126796031` ctl o `2083328` 233 ret 0 234 end 235 if eq op 19 236 put4 w wda o 31105 rb o 5 `203298048` ctl o 991744 237 ret 0 238 end 239 if eq op 20 240 put4 w wda o 31105 rb o 5 `203380992` ctl o 991744 241 ret 0 242 end 243 if eq op 21 244 put4 w wda o 31105 rb o 5 `203364608` ctl o 991744 245 ret 0 246 end 247 if eq op 22 248 a = wa o 31110 249 if ne get o 9 0 250 a = or wa o 2438 shl pred o 12 251 end 252 put4 w a rb o 3 or `202463488` rb o 5 ctl o `1040896` 253 ret 0 254 end 255 if eq op 23 256 put4 w 31122 0 45056 ctl o `1043456` 257 ret 0 258 end 259 if eq op 24 260 put4 w 31122 0 12288 ctl o `1043456` 261 ret 0 262 end 263 if eq op 25 264 put4 w `4278221199` 0 `33554432` ctl o `1042432` 265 ret 0 266 end 267 if eq op 26 268 put4 w wda o 31144 or rb o 3 `2147483648` or `136270080` rb o 5 ctl o `3284480` 269 ret 0 270 end 271 if eq op 27 272 put4 w wda o 31144 or rb o 3 `2147483648` or `203378944` rb o 5 ctl o `3284480` 273 ret 0 274 end 275 if eq op 28 276 put4 w wa o 29196 rb o 3 `66084976` ctl o `2087424` 277 ret 0 278 end 279 if eq op 29 280 put4 w wda o 29202 rb o 3 `126762239` ctl o `2083328` 281 ret 0 282 end 283 ret 1 284 end 285 286 note ops 30..45: floating point, special functions, shuffles, shared memory, exit 287 fn enc_c o view ulong 16 w edit ulong 4 to ulong 288 op = get o 0 289 imm = get o 6 290 if eq op 30 291 put4 w wda o 29217 rb o 3 0 ctl o `5227520` 292 ret 0 293 end 294 if eq op 31 295 put4 w wda o 29217 or rb o 3 `2147483648` 0 ctl o `5227520` 296 ret 0 297 end 298 if eq op 32 299 put4 w wda o 29216 rb o 3 `4194304` ctl o `5227520` 300 ret 0 301 end 302 if eq op 33 303 put4 w wda o 29219 rb o 3 rb o 4 ctl o `5227520` 304 ret 0 305 end 306 if eq op 34 307 c = ulong `66084864` 308 if ne imm 0 309 c = imm 310 end 311 a = or or 29195 shl and get o 1 7 16 shl rb o 2 24 312 put4 w a rb o 3 c ctl o `5227520` 313 ret 0 314 end 315 if eq op 35 316 put4 w wda o 29192 rb o 3 and get o 4 7 ctl o `1034752` 317 ret 0 318 end 319 if eq op 36 320 put4 w wda o 29193 rb o 3 `58720256` ctl o `5227520` 321 ret 0 322 end 323 if eq op 37 324 put4 w wda o 29193 rb o 3 `125829120` ctl o `5227520` 325 ret 0 326 end 327 if eq op 38 328 put4 w wd o 29253 rb o 2 `2102272` ctl o `5235200` 329 ret 0 330 end 331 if eq op 39 332 put4 w wd o 29445 rb o 2 `2158848` ctl o `5120512` 333 ret 0 334 end 335 if eq op 40 336 put4 w wd o 29448 rb o 2 4096 ctl o 926720 337 ret 0 338 end 339 if eq op 41 340 put4 w wd o 29448 rb o 2 5120 ctl o 926720 341 ret 0 342 end 343 if eq op 42 344 put4 w wda o 32649 or `134225664` shl and imm 31 21 917504 ctl o 926720 345 ret 0 346 end 347 if eq op 43 348 put4 w wda o 31108 0 and imm 65535 ctl o `1040896` 349 ret 0 350 end 351 if eq op 44 352 put4 w wa o 29576 rb o 3 and imm 65535 ctl o `1040896` 353 ret 0 354 end 355 if eq op 45 356 a = ulong 31053 357 if ne get o 9 0 358 a = 2381 359 end 360 put4 w a 0 `58720256` ctl o `1042944` 361 ret 0 362 end 363 ret 1 364 end 365 366 note op 46: BRA. rel = imm - 1 as int32; low 6 bits at w0 18..23, rel arithmetic-shifted by 6 at w1 bit 2 367 fn enc_bra o view ulong 16 w edit ulong 4 to ulong 368 imm = get o 6 369 rel = and sub imm 1 `4294967295` 370 s = shr rel 6 371 c = ulong `58720256` 372 if ge rel `2147483648` 373 s = or s `4227858432` 374 c = `58982399` 375 end 376 d = get o 7 377 if eq d 0 378 d = `1042944` 379 if and eq imm 0 eq get o 9 0 380 d = NOPC 381 end 382 end 383 a = or or 2375 shl pred o 12 shl and rel 63 18 384 put4 w a and shl s 2 `4294967295` c d 385 ret 0 386 end 387 388 note ops 46..59: branches, reconvergence, barriers, wide shared loads, three-source integer ops 389 fn enc_d o view ulong 16 w edit ulong 4 to ulong 390 op = get o 0 391 imm = get o 6 392 bar = get o 11 393 if eq op 46 394 ret enc_bra o w 395 end 396 if eq op 47 397 put4 w wd o 29448 rb o 2 2048 ctl o 926720 398 ret 0 399 end 400 if eq op 48 401 put4 w 31517 0 65536 ctl o `1043456` 402 ret 0 403 end 404 if eq op 49 405 put4 w wda o 31108 255 `134219776` ctl o 927744 406 ret 0 407 end 408 if eq op 50 409 put4 w wa o 31112 rb o 3 `134220031` ctl o `1040896` 410 ret 0 411 end 412 if eq op 51 413 a = or or 29202 shl rb o 1 16 shl rz o 2 12 24 414 put4 w a rz o 3 13 or or `126746624` shl and imm 255 8 rb o 4 ctl o `2083328` 415 ret 0 416 end 417 if eq op 52 418 a = or or 29209 shl rb o 1 16 shl rz o 2 12 24 419 put4 w a rz o 3 13 or 1536 rb o 4 ctl o `2083328` 420 ret 0 421 end 422 if eq op 53 423 a = or or 29223 shl rb o 1 16 shl rz o 2 12 24 424 put4 w a rz o 3 13 or `126746624` rb o 4 ctl o `2083328` 425 ret 0 426 end 427 if eq op 54 428 if or or lt imm 2 ge imm `2147483648` ge bar 16 429 ret 1 430 end 431 a = or or 2373 shl pred o 12 shl bar 16 432 put4 w a and mul sub imm 1 16 `4294967295` `58720768` ctl o `1040896` 433 ret 0 434 end 435 if eq op 55 436 if ge bar 16 437 ret 1 438 end 439 a = or or 2369 shl pred o 12 shl bar 16 440 put4 w a 0 `58720768` ctl o `1042944` 441 ret 0 442 end 443 if eq op 56 444 if not off24 imm 445 ret 1 446 end 447 put4 w wda o 31105 or rb o 5 shl and imm `16777215` 8 `203299584` ctl o 991744 448 ret 0 449 end 450 if eq op 57 451 if not off24 imm 452 ret 1 453 end 454 put4 w wda o 31105 or rb o 5 shl and imm `16777215` 8 `203300096` ctl o 991744 455 ret 0 456 end 457 if eq op 58 458 if ge imm `8388608` 459 ret 1 460 end 461 put4 w wda o 31108 shl and imm `16777215` 8 3072 ctl o `1042432` 462 ret 0 463 end 464 if eq op 59 465 put4 w wd o 29448 rb o 2 3072 ctl o 926720 466 ret 0 467 end 468 ret 1 469 end 470 471 note ops 60..63 (Training R5): SHFL.BFLY (SHFL.DOWN's words with w1 bit 26), F2FP.BF16.F32.PACK_AB, 472 note ATOMG.E.ADD.F32.FTZ.RN.STRONG.SYS and .GPU (no dst vreg encodes RZ, presence slot 15). 473 note Constants by Wolfram: FromDigits of `0c001f00` 7f89 `000e0000` `000e2400` 723e 10ff `004fc400` 79a3 `80000000` 474 note `0c1f5300` `0c1ef300` `00321e00` base 16 = `201334528` 32649 917504 926720 29246 4351 `5227520` 31139 `2147483648` 475 note `203379456` `203354880` `3284480`. 476 fn enc_e o view ulong 16 w edit ulong 4 to ulong 477 op = get o 0 478 if eq op 60 479 put4 w wda o 32649 or `201334528` shl and get o 6 31 21 917504 ctl o 926720 480 ret 0 481 end 482 if eq op 61 483 put4 w wda o 29246 rb o 3 4351 ctl o `5227520` 484 ret 0 485 end 486 if or eq op 62 eq op 63 487 s = ulong `203379456` 488 if eq op 63 489 s = `203354880` 490 end 491 a = or or 31139 shl rz o 1 15 16 shl rb o 2 24 492 put4 w a or rb o 3 `2147483648` or s rb o 5 ctl o `3284480` 493 ret 0 494 end 495 ret 1 496 end 497 498 fn enc1 o view ulong 16 w edit ulong 4 to ulong 499 op = get o 0 500 if lt op 15 501 ret enc_a o w 502 end 503 if lt op 30 504 ret enc_b o w 505 end 506 if lt op 46 507 ret enc_c o w 508 end 509 if lt op 60 510 ret enc_d o w 511 end 512 ret enc_e o w 513 end 514 515 note the 16 bytes of instruction i, each word little-endian 516 fn store code edit uchar 16384 i ulong w view ulong 4 to void 517 for k ulong 4 518 x = get w k 519 q = add mul i 16 mul k 4 520 for j ulong 4 521 put code add q j uchar and shr x mul j 8 255 522 end 523 end 524 end 525 526 fn bw_enc_sm121 ins view ulong 8192 phys view ulong 288 n ulong pad ulong code edit uchar 16384 to ulong 527 o = new ulong 16 0 528 w = new ulong 4 0 529 if gt n 1024 530 ret 0 531 end 532 cnt = n 533 if ne pad 0 534 cnt = mul div add n 7 8 8 535 if lt cnt 32 536 cnt = 32 537 end 538 end 539 for i ulong cnt 540 if lt i n 541 opnds ins i phys edit o 542 if ne enc1 view o edit w 0 543 ret 0 544 end 545 else 546 put4 edit w NOPW 0 0 NOPC 547 end 548 store code i view w 549 end 550 ret mul cnt 16 551 end