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 / om / components / rowpipe.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Exact source: CUDApp b759afc3 src/omega_blackwell_codegen_moe2.c and moe.h. |
| 3 | note Concatenate bw_alloc,bw_effect,bw_project,rowpipe. No solving or encoding here. |
| 4 | note Frozen spec8:0K,1lane_bytes,2rows,3warps,4mutant MUST0,5..7reserved MUST0. |
| 5 | note Unlike ignored C tuning fields this interface never silently accepts variants. |
| 6 | note Returns0 unsolved IR,1 refused spec,2 emitter capacity. Outputs zero on refusal. |
| 7 | note stats4=count,vregs,uvregs,sharedBytes; launch declares one CTA barrier. |
| 8 | note SB_B data waits only at first takeover; SB_RD protects each load address. |
| 9 | note Runtime loop consumes every issued B set before EXIT; branch/reconvergence order unchanged. |
| 10 | note Private state32..41shape,42..48branchsites,49partial,50step,51row,52word, |
| 11 | note 53weight,54dot/acc,55dot,56scale,57sharedoffset;10..12lowering scratch. |
| 12 | note Shape admission does not solve resources: caller globally allocates with limit128. |
| 13 | fn rp_check spec view ulong 8 to uint |
| 14 | if or eq get spec 0 0 gt get spec 0 32768 |
| 15 | ret 1 |
| 16 | end |
| 17 | if and ne get spec 1 8 ne get spec 1 16 |
| 18 | ret 1 |
| 19 | end |
| 20 | if and ne get spec 2 1 and ne get spec 2 2 and ne get spec 2 4 ne get spec 2 8 |
| 21 | ret 1 |
| 22 | end |
| 23 | if or eq get spec 3 0 gt get spec 3 32 |
| 24 | ret 1 |
| 25 | end |
| 26 | for j ulong 4 |
| 27 | if ne get spec add j 4 0 |
| 28 | ret 1 |
| 29 | end |
| 30 | end |
| 31 | if ne rem get spec 0 mul get spec 1 32 0 |
| 32 | ret 1 |
| 33 | end |
| 34 | ks = div get spec 0 mul get spec 1 32 |
| 35 | if or gt ks 16 gt mul mul get spec 2 ks get spec 1 128 |
| 36 | ret 1 |
| 37 | end |
| 38 | if gt get spec 0 mul get spec 3 512 |
| 39 | ret 1 |
| 40 | end |
| 41 | if ge add mul sub get spec 2 1 get spec 0 get spec 1 shl ulong 1 23 |
| 42 | ret 1 |
| 43 | end |
| 44 | ret 0 |
| 45 | end |
| 46 | fn rp_zero ins edit ulong 8192 m edit ulong 2048 stats edit ulong 4 to void |
| 47 | for j ulong 8192 |
| 48 | put ins j 0 |
| 49 | end |
| 50 | for j ulong 2048 |
| 51 | put m j 0 |
| 52 | end |
| 53 | for j ulong 4 |
| 54 | put stats j 0 |
| 55 | end |
| 56 | end |
| 57 | fn rp_widx row ulong step ulong to ulong |
| 58 | ret add ulong 64 mul add mul row 16 step 2 |
| 59 | end |
| 60 | fn rp_regrow m edit ulong 2048 s edit ulong 64 r edit ulong 512 row ulong to void |
| 61 | uv = bc_vreg s m 1 false |
| 62 | put r add 32 mul row 2 uv |
| 63 | uv = bc_vreg s m 1 false |
| 64 | put r add 33 mul row 2 uv |
| 65 | for step ulong get s 36 |
| 66 | idx = rp_widx row step |
| 67 | uv = bc_vreg s m get s 38 false |
| 68 | put r idx uv |
| 69 | uv = bc_vreg s m get s 38 false |
| 70 | put r add idx 1 uv |
| 71 | end |
| 72 | end |
| 73 | fn rp_regs m edit ulong 2048 s edit ulong 64 r edit ulong 512 to void |
| 74 | uv = bc_vreg s m 2 true |
| 75 | for j ulong 24 |
| 76 | w = ulong 1 |
| 77 | if or lt j 3 or and ge j 14 le j 16 and ge j 18 le j 19 |
| 78 | w = 2 |
| 79 | end |
| 80 | put r j bc_vreg s m w false |
| 81 | end |
| 82 | put r 24 bc_vreg s m 4 false |
| 83 | for row ulong get s 34 |
| 84 | rp_regrow m s r row |
| 85 | end |
| 86 | for step ulong get s 36 |
| 87 | put r add 320 mul step 2 bc_vreg s m 1 false |
| 88 | put r add 321 mul step 2 bc_vreg s m 1 false |
| 89 | end |
| 90 | for j ulong 7 |
| 91 | w = ulong 1 |
| 92 | if lt j 5 |
| 93 | w = 2 |
| 94 | end |
| 95 | put r add j 25 bc_vreg s m w false |
| 96 | end |
| 97 | for j ulong 5 |
| 98 | put r add j 48 bc_vreg s m 1 false |
| 99 | end |
| 100 | for j ulong 9 |
| 101 | w = ulong 1 |
| 102 | if eq j 0 |
| 103 | w = 2 |
| 104 | end |
| 105 | put r add j 352 bc_vreg s m w false |
| 106 | end |
| 107 | for j ulong get s 41 |
| 108 | put r add 384 mul j 2 bc_vreg s m 2 false |
| 109 | put r add 385 mul j 2 bc_vreg s m 1 false |
| 110 | end |
| 111 | end |
| 112 | fn rp_start ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 113 | bc_node s 7 0 BCNONE BCNONE BCNONE |
| 114 | put s 22 856 |
| 115 | put s 23 1 |
| 116 | bc_emit ins s 4 |
| 117 | for j ulong 7 |
| 118 | op = ulong 4 |
| 119 | if lt j 3 |
| 120 | op = 5 |
| 121 | end |
| 122 | bc_node s op get r j BCNONE BCNONE BCNONE |
| 123 | put s 22 add ulong 896 mul j 8 |
| 124 | if ge j 3 |
| 125 | put s 22 add ulong 920 mul sub j 3 4 |
| 126 | end |
| 127 | bc_emit ins s 2 |
| 128 | end |
| 129 | for j ulong 3 |
| 130 | bc_node s 3 get r add j 7 BCNONE BCNONE BCNONE |
| 131 | put s 22 33 |
| 132 | if eq j 1 |
| 133 | put s 22 37 |
| 134 | end |
| 135 | if eq j 2 |
| 136 | put s 22 38 |
| 137 | end |
| 138 | bc_emit ins s 2 |
| 139 | end |
| 140 | bc_inst ins s 2 get r 12 BCNONE 1 |
| 141 | bc_shift ins s get r 10 get r 7 0 5 |
| 142 | bc_mask ins s get r 11 get r 7 0 31 |
| 143 | bc_imm ins s get r 13 get r 9 BCNONE 1 |
| 144 | bc_wide ins s get r 14 get r 13 get r 0 16 |
| 145 | put s 8 0 |
| 146 | bc_mem ins s 56 get r 15 get r 14 2 |
| 147 | put s 8 8 |
| 148 | bc_mem ins s 56 get r 16 get r 14 3 |
| 149 | bc_node s 8 get r 17 get r 9 get r 4 BCNONE |
| 150 | bc_emit ins s 0 |
| 151 | bc_wide ins s get r 18 get r 17 get r 1 1 |
| 152 | bc_node s 8 get r 17 get r 9 get r 5 BCNONE |
| 153 | bc_emit ins s 0 |
| 154 | bc_wide ins s get r 19 get r 17 get r 2 1 |
| 155 | bc_imm ins s get r 20 get r 11 BCNONE get s 33 |
| 156 | bc_shift ins s get r 21 get r 11 0 get s 39 |
| 157 | bc_imm ins s get r 21 get r 21 BCNONE 4 |
| 158 | bc_imm ins s get r 22 get r 8 get r 10 get s 35 |
| 159 | bc_imm ins s get r 23 get r 22 BCNONE 1 |
| 160 | end |
| 161 | fn rp_clamp ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 162 | bc_imm ins s get r 356 get r 7 BCNONE 1 |
| 163 | put s 8 mul mul sub get s 41 1 32 get s 35 |
| 164 | put s 9 0 |
| 165 | bc_imad ins s 8 get r 356 get r 12 get r 356 |
| 166 | bc_imm ins s get r 358 get r 356 BCNONE 4294967295 |
| 167 | bc_imm ins s get r 358 get r 12 get r 358 sub get s 32 1 |
| 168 | bc_shift ins s get r 357 get r 358 0 31 |
| 169 | bc_imm ins s get r 358 get r 356 BCNONE 1 |
| 170 | put s 8 and sub ulong 0 get s 32 4294967295 |
| 171 | put s 9 0 |
| 172 | bc_imad ins s 8 get r 358 get r 12 get r 358 |
| 173 | bc_node s 8 get r 359 get r 357 get r 358 BCNONE |
| 174 | bc_emit ins s 0 |
| 175 | bc_imm ins s get r 359 get r 359 get r 356 4294967295 |
| 176 | bc_imm ins s get r 360 get r 358 BCNONE 1 |
| 177 | bc_imm ins s get r 360 get r 12 get r 360 1 |
| 178 | bc_node s 8 get r 360 get r 357 get r 360 BCNONE |
| 179 | bc_emit ins s 0 |
| 180 | bc_imm ins s get r 360 get r 360 get r 356 4294967295 |
| 181 | bc_wide ins s get r add 384 mul sub get s 41 1 2 get r 360 get r 18 4 |
| 182 | bc_imm ins s get r 355 get r 359 BCNONE 4 |
| 183 | end |
| 184 | fn rp_stage ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 185 | put s 49 rem get s 32 mul get s 35 32 |
| 186 | bc_wide ins s get r 352 get r 7 get r 18 4 |
| 187 | bc_imm ins s get r 353 get r 7 BCNONE 4 |
| 188 | for j ulong get s 41 |
| 189 | put s 8 mul mul j 128 get s 35 |
| 190 | put s 9 0 |
| 191 | bc_imad ins s 9 get r add 384 mul j 2 get r 12 get r 352 |
| 192 | end |
| 193 | if ne get s 49 0 |
| 194 | rp_clamp ins s r |
| 195 | end |
| 196 | for j ulong get s 41 |
| 197 | put s 8 0 |
| 198 | kind = ulong 3 |
| 199 | if eq j 0 |
| 200 | kind = 2 |
| 201 | end |
| 202 | put s 10 get r add 385 mul j 2 |
| 203 | put s 11 get r add 384 mul j 2 |
| 204 | bc_mem ins s 11 get s 10 get s 11 kind |
| 205 | end |
| 206 | for j ulong get s 41 |
| 207 | if and ne get s 49 0 eq j sub get s 41 1 |
| 208 | bc_node s 50 BCNONE get r 355 get r add 385 mul j 2 BCNONE |
| 209 | bc_emit ins s 5 |
| 210 | else |
| 211 | put s 8 mul mul j 128 get s 35 |
| 212 | put s 9 0 |
| 213 | bc_imad ins s 8 get r 354 get r 12 get r 353 |
| 214 | bc_node s 50 BCNONE get r 354 get r add 385 mul j 2 BCNONE |
| 215 | bc_emit ins s 5 |
| 216 | end |
| 217 | end |
| 218 | bc_node s 48 BCNONE BCNONE BCNONE BCNONE |
| 219 | bc_emit ins s 6 |
| 220 | bc_imm ins s get r 31 get r 11 BCNONE mul get s 33 4 |
| 221 | end |
| 222 | fn rp_loadrow ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 223 | put s 8 mul get s 51 get s 32 |
| 224 | put s 12 mul get s 50 32 |
| 225 | put s 12 mul get s 12 get s 33 |
| 226 | put s 8 add get s 8 get s 12 |
| 227 | put s 12 rp_widx get s 51 get s 50 |
| 228 | put s 12 get r add get s 12 1 |
| 229 | bc_mem ins s get s 11 get s 12 get r 25 get s 10 |
| 230 | put s 10 12 |
| 231 | end |
| 232 | fn rp_issue ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 233 | bc_wide ins s get r 25 get r 22 get r 15 mul get s 34 get s 32 |
| 234 | bc_wide ins s get r 25 get r 20 get r 25 1 |
| 235 | bc_shift ins s get r 30 get r 22 0 get s 40 |
| 236 | bc_wide ins s get r 26 get r 30 get r 16 div get s 32 32 |
| 237 | bc_wide ins s get r 26 get r 21 get r 26 1 |
| 238 | put s 10 11 |
| 239 | put s 11 56 |
| 240 | if eq get s 33 16 |
| 241 | put s 11 57 |
| 242 | end |
| 243 | for step ulong get s 36 |
| 244 | for row ulong get s 34 |
| 245 | put s 50 step |
| 246 | put s 51 row |
| 247 | rp_loadrow ins s r |
| 248 | end |
| 249 | end |
| 250 | for step ulong get s 36 |
| 251 | if eq step 0 |
| 252 | put s 8 0 |
| 253 | bc_mem ins s 11 get r 321 get r 26 get s 10 |
| 254 | else |
| 255 | put s 8 mul mul step get s 37 4 |
| 256 | put s 9 0 |
| 257 | bc_imad ins s 9 get r 27 get r 12 get r 26 |
| 258 | put s 8 0 |
| 259 | bc_mem ins s 11 get r add 321 mul step 2 get r 27 12 |
| 260 | end |
| 261 | put s 10 12 |
| 262 | end |
| 263 | bc_imm ins s get r 22 get r 6 get r 22 1 |
| 264 | end |
| 265 | fn rp_takerow ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 266 | idx = rp_widx get s 51 get s 50 |
| 267 | for word ulong get s 38 |
| 268 | bc_node s 8 get r idx get r add idx 1 BCNONE BCNONE |
| 269 | put s 22 1 |
| 270 | put s 23 or shl word 16 shl word 24 |
| 271 | bc_emit ins s get s 10 |
| 272 | put s 10 0 |
| 273 | end |
| 274 | end |
| 275 | fn rp_take ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 276 | put s 10 13 |
| 277 | for step ulong get s 36 |
| 278 | for row ulong get s 34 |
| 279 | put s 50 step |
| 280 | put s 51 row |
| 281 | rp_takerow ins s r |
| 282 | end |
| 283 | end |
| 284 | for step ulong get s 36 |
| 285 | put s 10 get r add 320 mul step 2 |
| 286 | put s 11 get r add 321 mul step 2 |
| 287 | bc_imm ins s get s 10 get s 11 BCNONE 1 |
| 288 | end |
| 289 | end |
| 290 | fn rp_decode ins edit ulong 8192 s edit ulong 64 r view ulong 512 wq ulong word ulong byteidx ulong to void |
| 291 | if lt byteidx 3 |
| 292 | put s 8 shl ulong 1 sub ulong 20 mul byteidx 8 |
| 293 | put s 9 word |
| 294 | bc_imad ins s 8 get r 48 wq BCNONE |
| 295 | else |
| 296 | bc_shift ins s get r 48 wq word 4 |
| 297 | end |
| 298 | bc_mask ins s get r 49 get r 48 0 shl ulong 127 20 |
| 299 | bc_mask ins s get r 50 wq word shl ulong 128 mul byteidx 8 |
| 300 | put s 8 1 |
| 301 | if lt byteidx 3 |
| 302 | put s 8 shl ulong 1 sub ulong 24 mul byteidx 8 |
| 303 | end |
| 304 | put s 9 0 |
| 305 | bc_imad ins s 8 get r 51 get r 50 get r 49 |
| 306 | end |
| 307 | fn rp_dotrow ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 308 | put s 53 get r rp_widx get s 51 get s 50 |
| 309 | put s 54 get r add 33 mul get s 51 2 |
| 310 | for byteidx ulong 4 |
| 311 | rp_decode ins s r get s 53 get s 52 byteidx |
| 312 | put s 9 byteidx |
| 313 | bc_ffma ins s get s 54 get r 51 get r 24 get s 54 |
| 314 | end |
| 315 | end |
| 316 | fn rp_step ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 317 | put s 57 mul get s 50 128 |
| 318 | put s 57 mul get s 57 get s 33 |
| 319 | put s 56 get r add 320 mul get s 50 2 |
| 320 | for row ulong get s 34 |
| 321 | bc_inst ins s 1 get r add 33 mul row 2 BCNONE 0 |
| 322 | end |
| 323 | for word ulong get s 38 |
| 324 | put s 52 word |
| 325 | bc_node s 58 get r 24 get r 31 BCNONE BCNONE |
| 326 | put s 22 mul word 16 |
| 327 | put s 22 add get s 22 get s 57 |
| 328 | bc_emit ins s 2 |
| 329 | for row ulong get s 34 |
| 330 | put s 51 row |
| 331 | rp_dotrow ins s r |
| 332 | end |
| 333 | end |
| 334 | for row ulong get s 34 |
| 335 | put s 9 0 |
| 336 | put s 54 get r add 32 mul row 2 |
| 337 | put s 55 get r add 33 mul row 2 |
| 338 | bc_ffma ins s get s 54 get s 55 get s 56 get s 54 |
| 339 | end |
| 340 | end |
| 341 | fn rp_compute ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 342 | for row ulong get s 34 |
| 343 | bc_inst ins s 1 get r add 32 mul row 2 BCNONE 0 |
| 344 | end |
| 345 | for step ulong get s 36 |
| 346 | put s 50 step |
| 347 | rp_step ins s r |
| 348 | end |
| 349 | end |
| 350 | fn rp_store ins edit ulong 8192 s edit ulong 64 r view ulong 512 to void |
| 351 | for row ulong get s 34 |
| 352 | put s 54 get r add 32 mul row 2 |
| 353 | for j ulong 5 |
| 354 | bc_node s 42 get r 52 get s 54 BCNONE BCNONE |
| 355 | put s 22 shr ulong 16 j |
| 356 | bc_emit ins s 2 |
| 357 | bc_node s 30 get s 54 get s 54 get r 52 BCNONE |
| 358 | bc_emit ins s 0 |
| 359 | end |
| 360 | end |
| 361 | bc_wide ins s get r 28 get r 23 get r 19 mul get s 34 4 |
| 362 | bc_pred ins s get r 11 get r 12 |
| 363 | put s 45 get s 0 |
| 364 | bc_node s 54 BCNONE BCNONE BCNONE BCNONE |
| 365 | put s 22 2 |
| 366 | bc_emit ins s 9 |
| 367 | put s 46 bc_branch ins s add get s 0 1 true |
| 368 | for row ulong get s 34 |
| 369 | bc_wide ins s get r 29 get r 12 get r 28 mul row 4 |
| 370 | bc_node s 12 BCNONE get r 29 get r add 32 mul row 2 BCNONE |
| 371 | put s 21 0 |
| 372 | bc_emit ins s 5 |
| 373 | end |
| 374 | put s 47 get s 0 |
| 375 | bc_node s 55 BCNONE BCNONE BCNONE BCNONE |
| 376 | bc_emit ins s 10 |
| 377 | bc_patch ins get s 46 get s 47 |
| 378 | bc_patch ins get s 45 add get s 47 1 |
| 379 | end |
| 380 | fn bc_rowpipe spec view ulong 8 ins edit ulong 8192 m edit ulong 2048 stats edit ulong 4 to uint |
| 381 | s = new ulong 64 0 |
| 382 | r = new ulong 512 0 |
| 383 | rp_zero ins m stats |
| 384 | if ne rp_check spec 0 |
| 385 | ret 1 |
| 386 | end |
| 387 | for j ulong 4 |
| 388 | put s add j 32 get spec j |
| 389 | end |
| 390 | put s 36 div get spec 0 mul get spec 1 32 |
| 391 | put s 37 div mul get spec 1 32 128 |
| 392 | put s 38 div get spec 1 4 |
| 393 | put s 39 bc_log div ulong 128 get spec 1 |
| 394 | put s 40 bc_log div ulong 128 get spec 2 |
| 395 | put s 10 mul get spec 3 32 |
| 396 | put s 41 add get spec 0 get s 10 |
| 397 | put s 41 sub get s 41 1 |
| 398 | put s 41 div get s 41 get s 10 |
| 399 | rp_regs m s r |
| 400 | rp_start ins s r |
| 401 | rp_stage ins s r |
| 402 | bc_pred ins s get r 22 get r 3 |
| 403 | put s 42 bc_branch ins s add get s 0 1 true |
| 404 | rp_issue ins s r |
| 405 | put s 43 get s 0 |
| 406 | rp_take ins s r |
| 407 | bc_pred ins s get r 22 get r 3 |
| 408 | put s 44 bc_branch ins s add get s 0 1 true |
| 409 | rp_issue ins s r |
| 410 | bc_patch ins get s 44 get s 0 |
| 411 | rp_compute ins s r |
| 412 | rp_store ins s r |
| 413 | bc_imm ins s get r 23 get r 6 get r 23 1 |
| 414 | bc_pred ins s get r 23 get r 3 |
| 415 | put s 48 bc_branch ins s add get s 0 1 true |
| 416 | at = bc_branch ins s get s 43 false |
| 417 | bc_patch ins get s 42 get s 0 |
| 418 | bc_patch ins get s 48 get s 0 |
| 419 | bc_node s 45 BCNONE BCNONE BCNONE BCNONE |
| 420 | bc_emit ins s 7 |
| 421 | at = bc_branch ins s get s 0 false |
| 422 | bc_tail ins at |
| 423 | if ne get s 3 0 |
| 424 | rp_zero ins m stats |
| 425 | ret 2 |
| 426 | end |
| 427 | put stats 0 get s 0 |
| 428 | put stats 1 get s 4 |
| 429 | put stats 2 get s 5 |
| 430 | put stats 3 mul get s 32 4 |
| 431 | if ne rem get s 32 mul get s 35 32 0 |
| 432 | put stats 3 add get stats 3 16 |
| 433 | end |
| 434 | ret 0 |
| 435 | end |