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 / kgen / attention_emit.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Exact attention_api.c scheduler, record/meta ABI from omega_gpu_om_ir.h. |
| 3 | note m[6] loop depth scratch is cleared at successful return, never an allocator request. |
| 4 | note m[8..15] loop stack, m[32] batch, m[33..40] batch counts, m[41..43] one reconvergence region. |
| 5 | const AN ulong 65535 |
| 6 | const AA ulong 18446744073709551615 |
| 7 | const AL ulong 4294967295 |
| 8 | const AI ulong 4286578688 |
| 9 | note State slots 0..31 hold shape; 32..239 hold named virtual-register handles. |
| 10 | const A ulong 32 |
| 11 | const B ulong 33 |
| 12 | const C ulong 34 |
| 13 | const TB ulong 35 |
| 14 | const TID ulong 36 |
| 15 | const H ulong 37 |
| 16 | const SEQ ulong 38 |
| 17 | const MAXB ulong 39 |
| 18 | const SCALE ulong 40 |
| 19 | const BSTR ulong 41 |
| 20 | const TSTR ulong 42 |
| 21 | const KVP ulong 43 |
| 22 | const HSTR ulong 44 |
| 23 | const NQH ulong 45 |
| 24 | const CTXOFF ulong 46 |
| 25 | const SPLIT ulong 47 |
| 26 | const KB ulong 48 |
| 27 | const KEND ulong 49 |
| 28 | const C1 ulong 50 |
| 29 | const C4 ulong 51 |
| 30 | const C32 ulong 52 |
| 31 | const C64 ulong 53 |
| 32 | const CS ulong 54 |
| 33 | const CO ulong 55 |
| 34 | const CR ulong 56 |
| 35 | const CR1 ulong 57 |
| 36 | const ZERO ulong 58 |
| 37 | const CR2 ulong 59 |
| 38 | const CR3 ulong 60 |
| 39 | const RR2 ulong 61 |
| 40 | const RR3 ulong 62 |
| 41 | const TID4 ulong 63 |
| 42 | const QROW ulong 64 |
| 43 | const QOFF ulong 65 |
| 44 | const QADDR ulong 66 |
| 45 | const QV ulong 67 |
| 46 | const OADDR ulong 68 |
| 47 | const HQ ulong 69 |
| 48 | const HO ulong 70 |
| 49 | const H0 ulong 71 |
| 50 | const HG ulong 72 |
| 51 | const QSH ulong 73 |
| 52 | const KVH ulong 74 |
| 53 | const KVOFF ulong 75 |
| 54 | const TMP ulong 76 |
| 55 | const TAB ulong 77 |
| 56 | const CA ulong 78 |
| 57 | const CTX ulong 79 |
| 58 | const VB ulong 80 |
| 59 | const PER ulong 81 |
| 60 | const X ulong 82 |
| 61 | const CAND ulong 83 |
| 62 | const DD ulong 84 |
| 63 | const LT ulong 85 |
| 64 | const CH1 ulong 86 |
| 65 | const CK ulong 87 |
| 66 | const RM ulong 88 |
| 67 | const RL ulong 92 |
| 68 | const ACC ulong 96 |
| 69 | const BASE ulong 100 |
| 70 | const SOFF ulong 101 |
| 71 | const OOFF ulong 102 |
| 72 | const ROFF ulong 103 |
| 73 | const J ulong 104 |
| 74 | const SC ulong 105 |
| 75 | const KOFF ulong 109 |
| 76 | const BI ulong 110 |
| 77 | const SL ulong 111 |
| 78 | const TA ulong 112 |
| 79 | const BLK ulong 113 |
| 80 | const KA ulong 114 |
| 81 | const DOT ulong 115 |
| 82 | const DIM ulong 119 |
| 83 | const LO ulong 120 |
| 84 | const HI ulong 121 |
| 85 | const QA ulong 122 |
| 86 | const J1 ulong 123 |
| 87 | const DNEG ulong 124 |
| 88 | const OVER ulong 125 |
| 89 | const OT ulong 126 |
| 90 | const CTXM1 ulong 127 |
| 91 | const CM1 ulong 128 |
| 92 | const CNINF ulong 129 |
| 93 | const NB ulong 130 |
| 94 | const NS ulong 131 |
| 95 | const TSH ulong 132 |
| 96 | const SL1 ulong 133 |
| 97 | const KX ulong 134 |
| 98 | const QQ ulong 136 |
| 99 | const RT ulong 140 |
| 100 | const MW ulong 141 |
| 101 | const RA ulong 142 |
| 102 | const RB ulong 143 |
| 103 | const MC ulong 144 |
| 104 | const MN ulong 145 |
| 105 | const DIFF ulong 146 |
| 106 | const ALPHA ulong 147 |
| 107 | const PARG ulong 151 |
| 108 | const RP ulong 152 |
| 109 | const SW ulong 153 |
| 110 | const LC ulong 154 |
| 111 | const KK ulong 155 |
| 112 | const TT ulong 156 |
| 113 | const OA ulong 157 |
| 114 | const PA ulong 158 |
| 115 | const KO4 ulong 159 |
| 116 | const PV4 ulong 161 |
| 117 | const VA ulong 163 |
| 118 | const RV ulong 164 |
| 119 | const CY ulong 172 |
| 120 | const SQ ulong 173 |
| 121 | const SP ulong 174 |
| 122 | const HH ulong 175 |
| 123 | const NQ ulong 176 |
| 124 | const T4 ulong 177 |
| 125 | const PROW ulong 178 |
| 126 | const POFF ulong 179 |
| 127 | const PADDR ulong 180 |
| 128 | const MADDR ulong 181 |
| 129 | const LADDR ulong 182 |
| 130 | const CP ulong 183 |
| 131 | const INV ulong 184 |
| 132 | const OUTV ulong 185 |
| 133 | const OROW ulong 186 |
| 134 | const OO ulong 187 |
| 135 | const OA64 ulong 188 |
| 136 | const BZ ulong 189 |
| 137 | const BB ulong 190 |
| 138 | const LOUT ulong 191 |
| 139 | const LIN ulong 192 |
| 140 | const LB ulong 193 |
| 141 | const DQ ulong 194 |
| 142 | const DQ4 ulong 195 |
| 143 | const TOFF ulong 196 |
| 144 | const CD4 ulong 197 |
| 145 | const QT ulong 198 |
| 146 | const LAST ulong 199 |
| 147 | const RR ulong 200 |
| 148 | |
| 149 | fn atcw st ulong wb ulong rb ulong wt ulong to ulong |
| 150 | ret or or shl st 9 shl wb 14 or shl rb 17 shl wt 20 |
| 151 | end |
| 152 | fn atrg d ulong a ulong b ulong c ulong to ulong |
| 153 | ret or or d shl a 16 or shl b 32 shl c 48 |
| 154 | end |
| 155 | fn atfld x ulong to ulong |
| 156 | if eq x AN |
| 157 | ret AA |
| 158 | end |
| 159 | ret x |
| 160 | end |
| 161 | fn atnv m edit ulong 512 w ulong to ulong |
| 162 | v = get m 1 |
| 163 | if ge v 256 |
| 164 | put m 4 ulong 1 |
| 165 | ret AN |
| 166 | end |
| 167 | put m add 64 v w |
| 168 | put m 1 add v 1 |
| 169 | ret v |
| 170 | end |
| 171 | fn atv s edit ulong 256 m edit ulong 512 slot ulong w ulong to void |
| 172 | put s slot atnv m w |
| 173 | end |
| 174 | fn atvs s edit ulong 256 m edit ulong 512 lo ulong hi ulong to void |
| 175 | for i ulong sub hi lo |
| 176 | atv s m add lo i 1 |
| 177 | end |
| 178 | end |
| 179 | note ok = opcode | kind << 8 | uniform-source descriptor flag << 16. |
| 180 | note kinds match K_FIXED..K_BSYNC, 10 batch, 11 fixed-in-batch, 12 raw tail. |
| 181 | fn atsched m edit ulong 512 ok ulong im ulong fl ulong to ulong |
| 182 | k = and shr ok 8 255 |
| 183 | pend = get m 3 |
| 184 | ctrl = atcw 6 7 7 pend |
| 185 | if lt k 10 |
| 186 | put m 32 ulong 0 |
| 187 | for j ulong 8 |
| 188 | put m add 33 j ulong 0 |
| 189 | end |
| 190 | if eq k 1 |
| 191 | ctrl = atcw 13 7 7 pend |
| 192 | end |
| 193 | put m 3 ulong 0 |
| 194 | if eq k 2 |
| 195 | ctrl = or atcw 4 0 7 pend 8192 |
| 196 | put m 3 ulong 1 |
| 197 | end |
| 198 | if eq k 3 |
| 199 | ctrl = or atcw 4 2 7 pend 8192 |
| 200 | put m 3 ulong 4 |
| 201 | end |
| 202 | if eq k 4 |
| 203 | ctrl = or atcw 4 7 1 pend 8192 |
| 204 | put m 3 ulong 2 |
| 205 | end |
| 206 | if or eq k 6 eq k 7 |
| 207 | ctrl = atcw 5 7 7 pend |
| 208 | if ne and fl 2 0 |
| 209 | put m 3 pend |
| 210 | end |
| 211 | end |
| 212 | if eq k 8 |
| 213 | ctrl = or atcw 1 7 7 pend 8192 |
| 214 | end |
| 215 | if eq k 9 |
| 216 | ctrl = or atcw 5 7 7 pend 8192 |
| 217 | end |
| 218 | else |
| 219 | if eq k 10 |
| 220 | sb = shr ok 24 |
| 221 | if or ge sb 8 ge get m add 33 sb 4 |
| 222 | put m 4 ulong 3 |
| 223 | ret 0 |
| 224 | end |
| 225 | ctrl = or atcw 4 sb 1 and pend not get m 32 8192 |
| 226 | mask = or shl ulong 1 sb 2 |
| 227 | put m 32 or get m 32 mask |
| 228 | put m add 33 sb add get m add 33 sb 1 |
| 229 | put m 3 or pend mask |
| 230 | else |
| 231 | if eq k 11 |
| 232 | wt = and pend not get m 32 |
| 233 | if ne get m 32 0 |
| 234 | wt = or wt 2 |
| 235 | end |
| 236 | ctrl = atcw 6 7 7 wt |
| 237 | else |
| 238 | ctrl = shr im 32 |
| 239 | end |
| 240 | end |
| 241 | end |
| 242 | ret ctrl |
| 243 | end |
| 244 | fn atemit r edit ulong 8192 m edit ulong 512 ok ulong rg ulong im ulong fl ulong to void |
| 245 | n = get m 0 |
| 246 | if ge n 1024 |
| 247 | put m 4 ulong 2 |
| 248 | ret |
| 249 | end |
| 250 | ctrl = atsched m ok im fl |
| 251 | if ne get m 4 0 |
| 252 | ret |
| 253 | end |
| 254 | n = mul n 8 |
| 255 | put r n and ok 255 |
| 256 | put r add n 1 atfld and rg 65535 |
| 257 | put r add n 2 atfld and shr rg 16 65535 |
| 258 | put r add n 3 atfld and shr rg 32 65535 |
| 259 | put r add n 4 atfld shr rg 48 |
| 260 | put r add n 5 AA |
| 261 | if ne and ok 65536 0 |
| 262 | put r add n 5 ulong 0 |
| 263 | end |
| 264 | put r add n 6 or and im AL shl ctrl 32 |
| 265 | put r add n 7 fl |
| 266 | put m 0 add get m 0 1 |
| 267 | end |
| 268 | fn atfix r edit ulong 8192 m edit ulong 512 op ulong rg ulong im ulong to void |
| 269 | atemit r m op rg im 0 |
| 270 | end |
| 271 | fn atmov r edit ulong 8192 m edit ulong 512 d ulong im ulong to void |
| 272 | atfix r m 2 atrg d AN AN AN im |
| 273 | end |
| 274 | fn atzero r edit ulong 8192 m edit ulong 512 d ulong to void |
| 275 | atfix r m 1 atrg d AN AN AN 0 |
| 276 | end |
| 277 | fn atimm r edit ulong 8192 m edit ulong 512 op ulong d ulong im ulong to void |
| 278 | atemit r m or op 512 atrg d AN AN AN im 0 |
| 279 | end |
| 280 | fn atmad r edit ulong 8192 m edit ulong 512 d ulong a ulong im ulong c ulong to void |
| 281 | atfix r m 8 atrg d a AN c im |
| 282 | end |
| 283 | fn atmr r edit ulong 8192 m edit ulong 512 d ulong a ulong b ulong c ulong to void |
| 284 | atfix r m 8 atrg d a b c 0 |
| 285 | end |
| 286 | fn atwide r edit ulong 8192 m edit ulong 512 d ulong a ulong im ulong c ulong to void |
| 287 | atfix r m 9 atrg d a AN c im |
| 288 | end |
| 289 | fn attwo r edit ulong 8192 m edit ulong 512 op ulong d ulong a ulong b ulong to void |
| 290 | atfix r m op atrg d a b AN 0 |
| 291 | end |
| 292 | fn atshift r edit ulong 8192 m edit ulong 512 d ulong a ulong im ulong to void |
| 293 | atfix r m 17 atrg d a AN AN im |
| 294 | end |
| 295 | fn atand r edit ulong 8192 m edit ulong 512 d ulong a ulong im ulong to void |
| 296 | atfix r m 18 atrg d a AN AN im |
| 297 | end |
| 298 | fn atload r edit ulong 8192 m edit ulong 512 d ulong a ulong to void |
| 299 | atemit r m 66059 atrg d a AN AN 0 0 |
| 300 | end |
| 301 | fn atstore r edit ulong 8192 m edit ulong 512 a ulong b ulong to void |
| 302 | atemit r m 66572 atrg AN a b AN 0 0 |
| 303 | end |
| 304 | fn atlds r edit ulong 8192 m edit ulong 512 d ulong a ulong to void |
| 305 | atemit r m 561 atrg d a AN AN 0 0 |
| 306 | end |
| 307 | fn atsts r edit ulong 8192 m edit ulong 512 a ulong b ulong to void |
| 308 | atemit r m 1074 atrg AN a b AN 0 0 |
| 309 | end |
| 310 | fn atbar r edit ulong 8192 m edit ulong 512 to void |
| 311 | if ne get m 41 0 |
| 312 | put m 4 ulong 4 |
| 313 | ret |
| 314 | end |
| 315 | atemit r m 1328 atrg AN AN AN AN 0 0 |
| 316 | end |
| 317 | fn atshfl r edit ulong 8192 m edit ulong 512 d ulong a ulong off ulong to void |
| 318 | if ne get m 41 0 |
| 319 | put m 4 ulong 4 |
| 320 | ret |
| 321 | end |
| 322 | atemit r m 554 atrg d a AN AN off 0 |
| 323 | end |
| 324 | fn atcmp r edit ulong 8192 m edit ulong 512 a ulong b ulong to void |
| 325 | atemit r m 284 atrg AN a b AN 0 0 |
| 326 | end |
| 327 | fn atback r edit ulong 8192 m edit ulong 512 tgt ulong to void |
| 328 | atemit r m 1838 atrg AN AN AN AN and sub tgt get m 0 AL 6 |
| 329 | end |
| 330 | fn atfwd r edit ulong 8192 m edit ulong 512 to ulong |
| 331 | n = get m 0 |
| 332 | atemit r m 1838 atrg AN AN AN AN 0 2 |
| 333 | ret n |
| 334 | end |
| 335 | fn atpatch r edit ulong 8192 m edit ulong 512 at ulong to void |
| 336 | n = add mul at 8 6 |
| 337 | put r n or and get r n not AL and sub get m 0 at AL |
| 338 | end |
| 339 | fn atloop m edit ulong 512 to void |
| 340 | d = get m 6 |
| 341 | if or ge d 8 ge get m 5 8 |
| 342 | put m 4 ulong 5 |
| 343 | ret |
| 344 | end |
| 345 | put m add 8 d get m 0 |
| 346 | put m 6 add d 1 |
| 347 | end |
| 348 | fn atclose m edit ulong 512 to void |
| 349 | d = get m 6 |
| 350 | if or eq d 0 ge get m 5 8 |
| 351 | put m 4 ulong 5 |
| 352 | ret |
| 353 | end |
| 354 | d = sub d 1 |
| 355 | put m 6 d |
| 356 | n = add 16 mul get m 5 2 |
| 357 | put m n get m add 8 d |
| 358 | put m add n 1 sub get m 0 1 |
| 359 | put m 5 add get m 5 1 |
| 360 | end |
| 361 | fn attail r edit ulong 8192 m edit ulong 512 to void |
| 362 | atemit r m 1581 atrg AN AN AN AN 0 0 |
| 363 | atemit r m 3118 atrg AN AN AN AN shl ulong 1032192 32 0 |
| 364 | end |
| 365 | fn atbatch r edit ulong 8192 m edit ulong 512 op ulong rg ulong im ulong sb ulong to void |
| 366 | ok = or or op 2560 shl sb 24 |
| 367 | if ne op 58 |
| 368 | ok = or ok 65536 |
| 369 | end |
| 370 | atemit r m ok rg im 0 |
| 371 | end |
| 372 | fn atff r edit ulong 8192 m edit ulong 512 rg ulong as ulong bs ulong to void |
| 373 | atemit r m 33 rg 0 or shl as 24 shl bs 32 |
| 374 | end |
| 375 | fn atws r edit ulong 8192 m edit ulong 512 rg ulong subr ulong batch ulong to void |
| 376 | ok = ulong 9 |
| 377 | if ne batch 0 |
| 378 | ok = or ok 2816 |
| 379 | end |
| 380 | atemit r m ok rg 1 shl subr 24 |
| 381 | end |
| 382 | fn atreg r edit ulong 8192 m edit ulong 512 to void |
| 383 | if ne get m 41 0 |
| 384 | put m 4 ulong 6 |
| 385 | ret |
| 386 | end |
| 387 | put m 41 ulong 1 |
| 388 | put m 42 get m 0 |
| 389 | atemit r m 2102 atrg AN AN AN AN 2 0 |
| 390 | atcmp r m get m 44 get m 45 |
| 391 | put m 43 get m 0 |
| 392 | atemit r m 1838 atrg AN AN AN AN 1 2 |
| 393 | end |
| 394 | fn atjoin r edit ulong 8192 m edit ulong 512 drop ulong to void |
| 395 | if ne get m 41 1 |
| 396 | put m 4 ulong 6 |
| 397 | ret |
| 398 | end |
| 399 | at = get m 0 |
| 400 | op = ulong 55 |
| 401 | if ne drop 0 |
| 402 | op = 0 |
| 403 | end |
| 404 | atemit r m or op 2304 atrg AN AN AN AN 0 0 |
| 405 | atpatch r m get m 42 |
| 406 | n = add mul get m 43 8 6 |
| 407 | im = and get r n not AL |
| 408 | dist = and sub at get m 43 AL |
| 409 | put r n or im dist |
| 410 | put m 41 ulong 0 |
| 411 | end |