yang
This project has not described itself yet.
Brought by drakestapleton
yang / src / ufbi_check1_kernels.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note src/ufbi_check1_kernels.om: Pure Seeded-OM-2 SM121 Direct SASS Emitter for Check #1 |
| 3 | note (4D Massive Free Scalar Masked Helmholtz Stencil, CTA Parallel Dot Product, AXPY, Mask-Copy). |
| 4 | note Composed after om/encoder/bw_enc_sm121.om. |
| 5 | note Honors all SM121 silicon laws (Antibodies #13-#15: 6-cycle ALU floor, BB leader pinning, |
| 6 | note disjoint LDS/LDG address registers before qW0/qW1, zero B0 nesting). |
| 7 | |
| 8 | const UZ ulong 255 |
| 9 | global uPc ulong 1 |
| 10 | global uGuard ulong 1 |
| 11 | global uCodeBuf ulong 8192 |
| 12 | |
| 13 | fn ucw st ulong wb ulong rbar ulong wt ulong yld ulong to ulong |
| 14 | a = or shl st 9 shl yld 13 |
| 15 | b = or shl wb 14 shl rbar 17 |
| 16 | ret or or a b shl wt 20 |
| 17 | end |
| 18 | |
| 19 | fn uAlu4 to ulong |
| 20 | ret ucw 6 7 7 0 0 |
| 21 | end |
| 22 | fn uCmp to ulong |
| 23 | ret ucw 14 7 7 0 0 |
| 24 | end |
| 25 | fn uLd to ulong |
| 26 | ret ucw 2 0 1 0 1 |
| 27 | end |
| 28 | fn uSt to ulong |
| 29 | ret ucw 4 7 1 0 1 |
| 30 | end |
| 31 | fn uW0 to ulong |
| 32 | ret ucw 6 7 7 1 0 |
| 33 | end |
| 34 | fn uW1 to ulong |
| 35 | ret ucw 6 7 7 2 0 |
| 36 | end |
| 37 | fn uWall to ulong |
| 38 | ret ucw 6 7 7 7 0 |
| 39 | end |
| 40 | fn uShfl to ulong |
| 41 | ret ucw 4 0 7 0 1 |
| 42 | end |
| 43 | fn uSafe to ulong |
| 44 | ret ucw 6 7 7 7 0 |
| 45 | end |
| 46 | |
| 47 | fn uEmitRaw o edit ulong 16 atPc ulong to void |
| 48 | w = new ulong 4 0 |
| 49 | if ne get uGuard 0 0 |
| 50 | put o 9 1 |
| 51 | end |
| 52 | if eq get uGuard 0 2 |
| 53 | put o 10 1 |
| 54 | end |
| 55 | put uGuard 0 0 |
| 56 | if ne get o 2 UZ |
| 57 | put o 12 1 |
| 58 | end |
| 59 | if ne get o 3 UZ |
| 60 | put o 13 1 |
| 61 | end |
| 62 | if ne enc1 o w 0 |
| 63 | exit 3 |
| 64 | end |
| 65 | base = mul atPc 4 |
| 66 | for i ulong 4 |
| 67 | put uCodeBuf add base i get w i |
| 68 | end |
| 69 | end |
| 70 | |
| 71 | fn uic op ulong dst ulong a ulong b ulong imm ulong ctrl ulong to void |
| 72 | o = new ulong 16 0 |
| 73 | put o 0 op |
| 74 | put o 1 dst |
| 75 | put o 2 a |
| 76 | put o 3 b |
| 77 | put o 4 UZ |
| 78 | put o 5 4 |
| 79 | put o 6 and imm 0xffffffff |
| 80 | put o 7 ctrl |
| 81 | pc = get uPc 0 |
| 82 | uEmitRaw o pc |
| 83 | put uPc 0 add pc 1 |
| 84 | end |
| 85 | |
| 86 | fn uic4 op ulong dst ulong a ulong b ulong c ulong ctrl ulong to void |
| 87 | o = new ulong 16 0 |
| 88 | put o 0 op |
| 89 | put o 1 dst |
| 90 | put o 2 a |
| 91 | put o 3 b |
| 92 | put o 4 c |
| 93 | put o 5 4 |
| 94 | put o 6 0 |
| 95 | put o 7 ctrl |
| 96 | pc = get uPc 0 |
| 97 | uEmitRaw o pc |
| 98 | put uPc 0 add pc 1 |
| 99 | end |
| 100 | |
| 101 | fn uicImm op ulong dst ulong a ulong c ulong imm ulong ctrl ulong to void |
| 102 | o = new ulong 16 0 |
| 103 | put o 0 op |
| 104 | put o 1 dst |
| 105 | put o 2 a |
| 106 | put o 3 UZ |
| 107 | put o 4 c |
| 108 | put o 5 4 |
| 109 | put o 6 and imm 0xffffffff |
| 110 | put o 7 ctrl |
| 111 | pc = get uPc 0 |
| 112 | uEmitRaw o pc |
| 113 | put uPc 0 add pc 1 |
| 114 | end |
| 115 | |
| 116 | fn uBraFwd gd ulong to ulong |
| 117 | pos = get uPc 0 |
| 118 | put uGuard 0 gd |
| 119 | uic 46 UZ UZ UZ 0 uAlu4 |
| 120 | ret pos |
| 121 | end |
| 122 | |
| 123 | fn uPatch pos ulong gd ulong to void |
| 124 | o = new ulong 16 0 |
| 125 | put o 0 46 |
| 126 | put o 1 UZ |
| 127 | put o 2 UZ |
| 128 | put o 3 UZ |
| 129 | put o 4 UZ |
| 130 | put o 5 4 |
| 131 | put o 6 and sub get uPc 0 pos 0xffffffff |
| 132 | put o 7 uAlu4 |
| 133 | put uGuard 0 gd |
| 134 | uEmitRaw o pos |
| 135 | end |
| 136 | |
| 137 | fn uLit d ulong x ulong to void |
| 138 | uic 2 d UZ UZ x uAlu4 |
| 139 | end |
| 140 | |
| 141 | fn uParam d ulong off ulong to void |
| 142 | uic 4 d UZ UZ add 896 off ucw 4 0 7 0 1 |
| 143 | uic 0 UZ UZ UZ 0 uW0 |
| 144 | end |
| 145 | |
| 146 | fn uStart ptrs ulong to void |
| 147 | uic 7 4 UZ UZ 856 ucw 4 2 7 0 1 |
| 148 | for i ulong ptrs bound 8 |
| 149 | uic 5 mul i 2 UZ UZ add 896 mul i 8 ucw 4 0 7 0 1 |
| 150 | end |
| 151 | uic 3 14 UZ UZ 33 ucw 4 0 7 0 1 |
| 152 | uic 3 15 UZ UZ 37 ucw 4 0 7 0 1 |
| 153 | uic 0 UZ UZ UZ 0 uWall |
| 154 | end |
| 155 | |
| 156 | fn uBar to void |
| 157 | uic 0 UZ UZ UZ 0 uWall |
| 158 | uic 48 UZ UZ UZ 0 uSafe |
| 159 | end |
| 160 | |
| 161 | fn uWarpBflySum acc ulong tmp ulong to void |
| 162 | d = ulong 16 |
| 163 | while ge d 1 bound 5 |
| 164 | uic 60 tmp acc UZ d uShfl |
| 165 | uic 30 acc acc tmp 0 uW0 |
| 166 | d = shr d 1 |
| 167 | end |
| 168 | end |
| 169 | |
| 170 | fn uDone to void |
| 171 | uic 0 UZ UZ UZ 0 uWall |
| 172 | uic 45 UZ UZ UZ 0 uSafe |
| 173 | while or lt get uPc 0 32 ne rem get uPc 0 8 0 bound 2048 |
| 174 | uic 0 UZ UZ UZ 0 uSafe |
| 175 | end |
| 176 | w = new ulong 4 0 |
| 177 | n = get uPc 0 |
| 178 | for pc ulong n bound 2048 |
| 179 | base = mul pc 4 |
| 180 | for i ulong 4 |
| 181 | put w i get uCodeBuf add base i |
| 182 | end |
| 183 | uCodeWrite w |
| 184 | end |
| 185 | end |
| 186 | |
| 187 | note ========================================================================= |
| 188 | note Kernel 0: k_helm4d (Masked 4D 9-point Helmholtz Stencil) |
| 189 | note Args: |
| 190 | note ptr0 (R0:R1) = x (f32[N]) |
| 191 | note ptr1 (R2:R3) = y (f32[N]) |
| 192 | note ptr2 (R4:R5) = mask (f32[N], 0.0 on frozen/boundary, 1.0 on active interior) |
| 193 | note off 24 = N |
| 194 | note off 28 = L |
| 195 | note off 32 = L2 |
| 196 | note off 36 = L3 |
| 197 | note off 40 = negL (0 - L as u32) |
| 198 | note off 44 = negL2 (0 - L2 as u32) |
| 199 | note off 48 = negL3 (0 - L3 as u32) |
| 200 | note off 52 = diag_f32_bits (8.0 + ma^2) |
| 201 | note ========================================================================= |
| 202 | fn uEmitHelm4d to bool |
| 203 | uStart 3 |
| 204 | uParam 20 24 |
| 205 | uParam 21 28 |
| 206 | uParam 22 32 |
| 207 | uParam 23 36 |
| 208 | uParam 24 40 |
| 209 | uParam 25 44 |
| 210 | uParam 26 48 |
| 211 | uParam 27 52 |
| 212 | note gidx (R16) = CTAID.X (R15) * 256 + TID.X (R14) |
| 213 | uicImm 8 16 15 14 256 uAlu4 |
| 214 | uic 28 UZ 16 20 0 uCmp |
| 215 | bOob = uBraFwd 1 |
| 216 | |
| 217 | note Load mask[gidx] into R17 |
| 218 | uicImm 9 28 16 4 4 uAlu4 |
| 219 | uic 11 17 28 UZ 0 uLd |
| 220 | uic 0 UZ UZ UZ 0 uW0 |
| 221 | |
| 222 | note Check mask != 0 (f32 0.0 is 0u32; 1.0 is 0x3f800000 >= 1) |
| 223 | uLit 18 1 |
| 224 | uic 28 UZ 17 18 0 uCmp |
| 225 | bZero = uBraFwd 2 |
| 226 | |
| 227 | note Active strictly-interior site: load x[gidx] and 8 neighbors |
| 228 | note Batch 1: x[gidx], x[gidx+1], x[gidx-1], x[gidx+L] |
| 229 | uLit 19 0xffffffff |
| 230 | uic 14 30 16 18 0 uAlu4 |
| 231 | uic 14 31 16 19 0 uAlu4 |
| 232 | uic 14 32 16 21 0 uAlu4 |
| 233 | uicImm 9 34 16 0 4 uAlu4 |
| 234 | uicImm 9 36 30 0 4 uAlu4 |
| 235 | uicImm 9 38 31 0 4 uAlu4 |
| 236 | uicImm 9 40 32 0 4 uAlu4 |
| 237 | uic 11 42 34 UZ 0 uLd |
| 238 | uic 11 43 36 UZ 0 uLd |
| 239 | uic 11 44 38 UZ 0 uLd |
| 240 | uic 11 45 40 UZ 0 uLd |
| 241 | uic 0 UZ UZ UZ 0 uW0 |
| 242 | uic 30 46 43 44 0 uAlu4 |
| 243 | uic 30 46 46 45 0 uAlu4 |
| 244 | |
| 245 | note Batch 2: x[gidx-L], x[gidx+L2], x[gidx-L2], x[gidx+L3] |
| 246 | uic 14 30 16 24 0 uAlu4 |
| 247 | uic 14 31 16 22 0 uAlu4 |
| 248 | uic 14 32 16 25 0 uAlu4 |
| 249 | uic 14 33 16 23 0 uAlu4 |
| 250 | uicImm 9 34 30 0 4 uAlu4 |
| 251 | uicImm 9 36 31 0 4 uAlu4 |
| 252 | uicImm 9 38 32 0 4 uAlu4 |
| 253 | uicImm 9 40 33 0 4 uAlu4 |
| 254 | uic 11 43 34 UZ 0 uLd |
| 255 | uic 11 44 36 UZ 0 uLd |
| 256 | uic 11 45 38 UZ 0 uLd |
| 257 | uic 11 47 40 UZ 0 uLd |
| 258 | uic 0 UZ UZ UZ 0 uW0 |
| 259 | uic 30 46 46 43 0 uAlu4 |
| 260 | uic 30 46 46 44 0 uAlu4 |
| 261 | uic 30 46 46 45 0 uAlu4 |
| 262 | uic 30 46 46 47 0 uAlu4 |
| 263 | |
| 264 | note Batch 3: x[gidx-L3] |
| 265 | uic 14 30 16 26 0 uAlu4 |
| 266 | uicImm 9 34 30 0 4 uAlu4 |
| 267 | uic 11 43 34 UZ 0 uLd |
| 268 | uic 0 UZ UZ UZ 0 uW0 |
| 269 | uic 30 46 46 43 0 uAlu4 |
| 270 | |
| 271 | note val = diag * x[gidx] - sum_neighbors |
| 272 | uic 32 48 27 42 0 uAlu4 |
| 273 | uic 31 48 48 46 0 uAlu4 |
| 274 | |
| 275 | note Store y[gidx] = val |
| 276 | uicImm 9 34 16 2 4 uAlu4 |
| 277 | uic 12 UZ 34 48 0 uSt |
| 278 | uic 0 UZ UZ UZ 0 uW1 |
| 279 | bDone = uBraFwd 0 |
| 280 | |
| 281 | note Zero path: y[gidx] = 0.0 |
| 282 | uPatch bZero 2 |
| 283 | uic 1 48 UZ UZ 0 uAlu4 |
| 284 | uicImm 9 34 16 2 4 uAlu4 |
| 285 | uic 12 UZ 34 48 0 uSt |
| 286 | uic 0 UZ UZ UZ 0 uW1 |
| 287 | |
| 288 | uPatch bDone 0 |
| 289 | uPatch bOob 1 |
| 290 | ret true |
| 291 | end |
| 292 | |
| 293 | note ========================================================================= |
| 294 | note Kernel 1: k_dot_cta (256-thread CTA parallel dot product -> part[ctaid]) |
| 295 | note Args: |
| 296 | note ptr0 (R0:R1) = u (f32[N]) |
| 297 | note ptr1 (R2:R3) = v (f32[N]) |
| 298 | note ptr2 (R4:R5) = part (f32[grid_x]) |
| 299 | note off 24 = N |
| 300 | note SMEM: 32 bytes (8 warp partial sums) |
| 301 | note ========================================================================= |
| 302 | fn uEmitDotCta to bool |
| 303 | uStart 3 |
| 304 | uParam 20 24 |
| 305 | note gidx (R16) = CTAID.X * 256 + TID.X |
| 306 | uicImm 8 16 15 14 256 uAlu4 |
| 307 | uic 1 22 UZ UZ 0 uAlu4 |
| 308 | uic 28 UZ 16 20 0 uCmp |
| 309 | bSkip = uBraFwd 1 |
| 310 | |
| 311 | uicImm 9 24 16 0 4 uAlu4 |
| 312 | uicImm 9 26 16 2 4 uAlu4 |
| 313 | uic 11 28 24 UZ 0 uLd |
| 314 | uic 11 29 26 UZ 0 uLd |
| 315 | uic 0 UZ UZ UZ 0 uW0 |
| 316 | uic 32 22 28 29 0 uAlu4 |
| 317 | |
| 318 | uPatch bSkip 1 |
| 319 | note All 256 threads in CTA participate in warp butterfly sum |
| 320 | uWarpBflySum 22 23 |
| 321 | |
| 322 | note lane = tid & 31 (R30), warp = tid >> 5 (R31), smem_off = warp << 2 (R32) |
| 323 | uic 18 30 14 UZ 31 uAlu4 |
| 324 | uic 17 31 14 UZ 5 uAlu4 |
| 325 | uicImm 8 32 31 UZ 4 uAlu4 |
| 326 | uLit 33 1 |
| 327 | uic 28 UZ 30 33 0 uCmp |
| 328 | bNotLane0 = uBraFwd 1 |
| 329 | uic 50 UZ 32 22 0 uSt |
| 330 | uic 0 UZ UZ UZ 0 uW1 |
| 331 | uPatch bNotLane0 1 |
| 332 | |
| 333 | uBar |
| 334 | |
| 335 | note Only tid == 0 sums the 8 warp slots in SMEM and writes part[ctaid] |
| 336 | uic 28 UZ 14 33 0 uCmp |
| 337 | bNotT0 = uBraFwd 1 |
| 338 | note Precompute 8 disjoint SMEM byte offsets 0..28 in R34..R41 |
| 339 | uLit 34 0 |
| 340 | uLit 35 4 |
| 341 | uLit 36 8 |
| 342 | uLit 37 12 |
| 343 | uLit 38 16 |
| 344 | uLit 39 20 |
| 345 | uLit 40 24 |
| 346 | uLit 41 28 |
| 347 | uic 49 42 34 UZ 0 uLd |
| 348 | uic 49 43 35 UZ 0 uLd |
| 349 | uic 49 44 36 UZ 0 uLd |
| 350 | uic 49 45 37 UZ 0 uLd |
| 351 | uic 0 UZ UZ UZ 0 uW0 |
| 352 | uic 30 42 42 43 0 uAlu4 |
| 353 | uic 30 44 44 45 0 uAlu4 |
| 354 | uic 30 42 42 44 0 uAlu4 |
| 355 | uic 49 46 38 UZ 0 uLd |
| 356 | uic 49 47 39 UZ 0 uLd |
| 357 | uic 49 48 40 UZ 0 uLd |
| 358 | uic 49 49 41 UZ 0 uLd |
| 359 | uic 0 UZ UZ UZ 0 uW0 |
| 360 | uic 30 46 46 47 0 uAlu4 |
| 361 | uic 30 48 48 49 0 uAlu4 |
| 362 | uic 30 46 46 48 0 uAlu4 |
| 363 | uic 30 42 42 46 0 uAlu4 |
| 364 | uicImm 9 50 15 4 4 uAlu4 |
| 365 | uic 12 UZ 50 42 0 uSt |
| 366 | uic 0 UZ UZ UZ 0 uW1 |
| 367 | uPatch bNotT0 1 |
| 368 | ret true |
| 369 | end |
| 370 | |
| 371 | note ========================================================================= |
| 372 | note Kernel 2: k_axpy (y[i] = a * x[i] + b * y[i]) |
| 373 | note Args: |
| 374 | note ptr0 (R0:R1) = x (f32[N]) |
| 375 | note ptr1 (R2:R3) = y (f32[N]) |
| 376 | note off 16 = N |
| 377 | note off 20 = a_f32_bits |
| 378 | note off 24 = b_f32_bits |
| 379 | note ========================================================================= |
| 380 | fn uEmitAxpy to bool |
| 381 | uStart 2 |
| 382 | uParam 20 16 |
| 383 | uParam 21 20 |
| 384 | uParam 22 24 |
| 385 | uicImm 8 16 15 14 256 uAlu4 |
| 386 | uic 28 UZ 16 20 0 uCmp |
| 387 | bOob = uBraFwd 1 |
| 388 | |
| 389 | uicImm 9 24 16 0 4 uAlu4 |
| 390 | uicImm 9 26 16 2 4 uAlu4 |
| 391 | uic 11 28 24 UZ 0 uLd |
| 392 | uic 11 29 26 UZ 0 uLd |
| 393 | uic 0 UZ UZ UZ 0 uW0 |
| 394 | uic 32 30 22 29 0 uAlu4 |
| 395 | uic4 33 30 21 28 30 uAlu4 |
| 396 | uic 12 UZ 26 30 0 uSt |
| 397 | uic 0 UZ UZ UZ 0 uW1 |
| 398 | |
| 399 | uPatch bOob 1 |
| 400 | ret true |
| 401 | end |
| 402 | |
| 403 | note ========================================================================= |
| 404 | note Kernel 3: k_mask_copy (y[i] = mask[i] * x[i]) |
| 405 | note Args: |
| 406 | note ptr0 (R0:R1) = x (f32[N]) |
| 407 | note ptr1 (R2:R3) = y (f32[N]) |
| 408 | note ptr2 (R4:R5) = mask (f32[N]) |
| 409 | note off 24 = N |
| 410 | note ========================================================================= |
| 411 | fn uEmitMaskCopy to bool |
| 412 | uStart 3 |
| 413 | uParam 20 24 |
| 414 | uicImm 8 16 15 14 256 uAlu4 |
| 415 | uic 28 UZ 16 20 0 uCmp |
| 416 | bOob = uBraFwd 1 |
| 417 | |
| 418 | uicImm 9 24 16 0 4 uAlu4 |
| 419 | uicImm 9 26 16 2 4 uAlu4 |
| 420 | uicImm 9 28 16 4 4 uAlu4 |
| 421 | uic 11 30 24 UZ 0 uLd |
| 422 | uic 11 31 28 UZ 0 uLd |
| 423 | uic 0 UZ UZ UZ 0 uW0 |
| 424 | uic 32 30 30 31 0 uAlu4 |
| 425 | uic 12 UZ 26 30 0 uSt |
| 426 | uic 0 UZ UZ UZ 0 uW1 |
| 427 | |
| 428 | uPatch bOob 1 |
| 429 | ret true |
| 430 | end |