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 / tools / ampfam.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note ampfam: the plan, control and verdicts of tools/ampere_families.c (SM86 producer coverage of the |
| 3 | note existing Blackwell generator families). The C shell calls one generator, the SM121 encoder or the |
| 4 | note SM86 encoder when this unit asks for it and prints the text it returns; this unit owns the order of |
| 5 | note the 133 producer steps, each generator's specification, which steps must encode and which must be |
| 6 | note refused, the short-circuit of a failing step and the message with the oracle's source line. |
| 7 | note facts f (ulong 32), the C header constants: 0 OMEGA_PATTN_MODE_FUSED, 1 _ATTEND, 2 _APPEND, |
| 8 | note 3 OMEGA_TC2_EPI_F32, 4 OMEGA_TC2_EPI_SWIGLU, 5 OMEGA_DEC_AXPY, 6 OMEGA_DEC_XBOUND, 7 OMEGA_DEC_RES, |
| 9 | note 8 OMEGA_DEC_GATHER, 9 OMEGA_DEC_RES_ADD | OMEGA_DEC_RES_NORM, 10 OMEGA_QG_IN_F32, 11 OMEGA_QG_IN_BF16, |
| 10 | note 12 OMEGA_GDN_COPY, 13 OMEGA_GDN_ZERO, 14 OMEGA_TERN_LAYOUT_ROWMAJOR, 15 OMEGA_TERN_LAYOUT_BLOCK, |
| 11 | note 16 OMEGA_TERN_MAX_K, 17 OMEGA_TERN_CHUNK_MAX, 18 OMEGA_TERN_EPI_F32. |
| 12 | note state s (ulong 64, all 0 at the start): 0 step, 1 phase, 2 rc of the last call (int64 bits, written by |
| 13 | note the shell), 3 SM121 length a, 4 SM86 length b (written by the shell), 5 expectation (0 encode, |
| 14 | note 1 refuse), 6 source line, 9 generator id, 10 initial SM86 length, 16..23 the generator fields. |
| 15 | note Returns 1 (call generator s 9 with s 16..23), 2 (SM121 encoder, a = 0), 3 (SM86 encoder, b = s 10), |
| 16 | note 4 + 256 * length (print o 0 to stderr, exit 1), 5 + 256 * length (print o 0 to stdout, exit 0), |
| 17 | note 0 (abort: called again after the end). |
| 18 | const AFPLAN ulong 1048576 |
| 19 | const AFSKIP ulong 1048577 |
| 20 | const AFEND ulong 1048578 |
| 21 | fn af_s o edit uchar 128 p ulong w ulong n ulong to ulong |
| 22 | i = ulong 0 |
| 23 | while lt i n bound 9 |
| 24 | put o add p i uchar and shr w mul i 8 255 |
| 25 | i = add i 1 |
| 26 | end |
| 27 | ret add p n |
| 28 | end |
| 29 | fn af_nd v ulong to ulong |
| 30 | n = ulong 1 |
| 31 | x = div v 10 |
| 32 | while ne x 0 bound 20 |
| 33 | n = add n 1 |
| 34 | x = div x 10 |
| 35 | end |
| 36 | ret n |
| 37 | end |
| 38 | fn af_u o edit uchar 128 p ulong v ulong to ulong |
| 39 | w = af_nd v |
| 40 | k = add p w |
| 41 | x = v |
| 42 | for i ulong w |
| 43 | k = sub k 1 |
| 44 | put o k uchar add 48 rem x 10 |
| 45 | x = div x 10 |
| 46 | end |
| 47 | ret add p w |
| 48 | end |
| 49 | note af_cnt: passes of `for (v = lo; v <= hi; ++v)`. |
| 50 | fn af_cnt lo ulong hi ulong to ulong |
| 51 | if lt hi lo |
| 52 | ret ulong 0 |
| 53 | end |
| 54 | ret add sub hi lo 1 |
| 55 | end |
| 56 | note af_set: generator g, expectation ex, line ln, fields cleared (a C designated initializer). |
| 57 | fn af_set s edit ulong 64 g ulong ex ulong ln ulong to ulong |
| 58 | put s 9 g |
| 59 | put s 5 ex |
| 60 | put s 6 ln |
| 61 | for i ulong 8 |
| 62 | put s add 16 i ulong 0 |
| 63 | end |
| 64 | ret AFPLAN |
| 65 | end |
| 66 | fn af_fl s edit ulong 64 k ulong v ulong to ulong |
| 67 | put s add 16 k v |
| 68 | ret AFPLAN |
| 69 | end |
| 70 | fn af_f4 s edit ulong 64 a ulong b ulong c ulong d ulong to ulong |
| 71 | x = af_fl s 0 a |
| 72 | x = af_fl s 1 b |
| 73 | x = af_fl s 2 c |
| 74 | ret af_fl s 3 d |
| 75 | end |
| 76 | note af_sa: decode_attn depth 1..4 (line 44); prefill_attn FUSED..ATTEND, APPEND encodes (50), the |
| 77 | note others are refused (51). |
| 78 | fn af_sa s edit ulong 64 f view ulong 32 i ulong to ulong |
| 79 | x = ulong 0 |
| 80 | if lt i 4 |
| 81 | x = af_set s 1 0 44 |
| 82 | ret af_fl s 0 add i 1 |
| 83 | end |
| 84 | i = sub i 4 |
| 85 | n = af_cnt get f 0 get f 1 |
| 86 | if lt i n |
| 87 | m = add get f 0 i |
| 88 | if eq m get f 2 |
| 89 | x = af_set s 2 0 50 |
| 90 | x = af_fl s 2 1 |
| 91 | else |
| 92 | x = af_set s 2 1 51 |
| 93 | end |
| 94 | x = af_fl s 0 4 |
| 95 | ret af_fl s 1 m |
| 96 | end |
| 97 | ret sub i n |
| 98 | end |
| 99 | note af_sb: the fixed bf16, fp8 GEMV/GEMM and router steps (lines 54..68). |
| 100 | fn af_sb s edit ulong 64 i ulong to ulong |
| 101 | x = ulong 0 |
| 102 | if lt i 3 |
| 103 | x = af_set s 3 0 54 |
| 104 | x = af_f4 s 256 1 4 1 |
| 105 | if eq i 1 |
| 106 | x = af_set s 3 0 55 |
| 107 | x = af_f4 s 256 1 4 1 |
| 108 | x = af_fl s 4 1 |
| 109 | end |
| 110 | if eq i 2 |
| 111 | x = af_set s 3 0 57 |
| 112 | x = af_f4 s 256 1 4 1 |
| 113 | x = af_fl s 5 256 |
| 114 | x = af_fl s 6 2 |
| 115 | end |
| 116 | ret AFPLAN |
| 117 | end |
| 118 | if lt i 6 |
| 119 | x = af_set s 4 0 59 |
| 120 | if eq i 4 |
| 121 | x = af_set s 4 0 60 |
| 122 | x = af_fl s 4 1 |
| 123 | end |
| 124 | if eq i 5 |
| 125 | x = af_set s 5 0 61 |
| 126 | x = af_fl s 4 1 |
| 127 | end |
| 128 | ret af_f4 s 256 8 1 8 |
| 129 | end |
| 130 | if lt i 8 |
| 131 | x = af_set s 6 0 63 |
| 132 | if eq i 7 |
| 133 | x = af_set s 6 0 64 |
| 134 | x = af_fl s 4 1 |
| 135 | end |
| 136 | ret af_f4 s 256 8 2 8 |
| 137 | end |
| 138 | if lt i 10 |
| 139 | x = af_set s 7 0 66 |
| 140 | if eq i 9 |
| 141 | x = af_set s 7 0 68 |
| 142 | x = af_fl s 2 256 |
| 143 | x = af_fl s 3 1 |
| 144 | end |
| 145 | x = af_fl s 0 8 |
| 146 | ret af_fl s 1 1 |
| 147 | end |
| 148 | ret sub i 10 |
| 149 | end |
| 150 | note af_sc: pf_copy, rl, mc and the tensor-core probe, peak, bandwidth and GEMM steps (lines 69..78). |
| 151 | fn af_sc s edit ulong 64 i ulong to ulong |
| 152 | x = ulong 0 |
| 153 | if eq i 0 |
| 154 | ret af_set s 8 0 69 |
| 155 | end |
| 156 | if eq i 1 |
| 157 | x = af_set s 9 0 71 |
| 158 | x = af_fl s 0 128 |
| 159 | x = af_fl s 1 32 |
| 160 | ret af_fl s 2 1 |
| 161 | end |
| 162 | if eq i 2 |
| 163 | x = af_set s 10 0 73 |
| 164 | x = af_fl s 0 128 |
| 165 | ret af_fl s 1 4 |
| 166 | end |
| 167 | if eq i 3 |
| 168 | ret af_set s 11 0 74 |
| 169 | end |
| 170 | if eq i 4 |
| 171 | x = af_set s 12 0 75 |
| 172 | ret af_f4 s 2 2 8 128 |
| 173 | end |
| 174 | if eq i 5 |
| 175 | x = af_set s 13 0 76 |
| 176 | x = af_fl s 0 2 |
| 177 | x = af_fl s 1 1 |
| 178 | ret af_fl s 2 128 |
| 179 | end |
| 180 | if eq i 6 |
| 181 | x = af_set s 14 0 78 |
| 182 | ret af_f4 s 128 2 2 4 |
| 183 | end |
| 184 | ret sub i 7 |
| 185 | end |
| 186 | note af_sd: tc2 epi F32..SWIGLU by direct 0..1 (F32 encodes, line 83; the others are refused, 84); |
| 187 | note dec kinds AXPY..XBOUND (line 91). |
| 188 | fn af_sd s edit ulong 64 f view ulong 32 i ulong to ulong |
| 189 | x = ulong 0 |
| 190 | n = mul af_cnt get f 3 get f 4 2 |
| 191 | if lt i n |
| 192 | e = add get f 3 div i 2 |
| 193 | if eq e get f 3 |
| 194 | x = af_set s 15 0 83 |
| 195 | else |
| 196 | x = af_set s 15 1 84 |
| 197 | end |
| 198 | x = af_f4 s 128 2 2 4 |
| 199 | x = af_fl s 4 2 |
| 200 | x = af_fl s 5 e |
| 201 | x = af_fl s 6 rem i 2 |
| 202 | ret af_fl s 7 256 |
| 203 | end |
| 204 | i = sub i n |
| 205 | n = af_cnt get f 5 get f 6 |
| 206 | if lt i n |
| 207 | k = add get f 5 i |
| 208 | x = af_set s 16 0 91 |
| 209 | x = af_fl s 0 k |
| 210 | if eq k get f 5 |
| 211 | x = af_fl s 1 256 |
| 212 | end |
| 213 | if eq k get f 7 |
| 214 | x = af_fl s 2 get f 9 |
| 215 | end |
| 216 | if eq k get f 8 |
| 217 | x = af_fl s 3 256 |
| 218 | x = af_fl s 1 256 |
| 219 | end |
| 220 | ret AFPLAN |
| 221 | end |
| 222 | ret sub i n |
| 223 | end |
| 224 | note af_se: pq in_type F32..BF16 (95), qgemm (98), qmma probe (99), qmma peak (100), f2e4 probe (101), |
| 225 | note all refused. |
| 226 | fn af_se s edit ulong 64 f view ulong 32 i ulong to ulong |
| 227 | x = ulong 0 |
| 228 | n = af_cnt get f 10 get f 11 |
| 229 | if lt i n |
| 230 | x = af_set s 17 1 95 |
| 231 | x = af_fl s 0 128 |
| 232 | ret af_fl s 1 add get f 10 i |
| 233 | end |
| 234 | i = sub i n |
| 235 | if eq i 0 |
| 236 | x = af_set s 18 1 98 |
| 237 | ret af_f4 s 128 4 8 128 |
| 238 | end |
| 239 | if eq i 1 |
| 240 | x = af_set s 19 1 99 |
| 241 | x = af_fl s 0 0 |
| 242 | ret af_fl s 1 8 |
| 243 | end |
| 244 | if eq i 2 |
| 245 | x = af_set s 20 1 100 |
| 246 | ret af_f4 s 2 2 8 128 |
| 247 | end |
| 248 | if eq i 3 |
| 249 | ret af_set s 21 1 101 |
| 250 | end |
| 251 | ret sub i 4 |
| 252 | end |
| 253 | note af_sf: per shape 0..1, decode_attn256 depth 1..4 by prep by multi (112), then prefill_attn256 |
| 254 | note refused (117); shape 1 is 16 q heads, 2 kv heads, 4 q heads per CTA. |
| 255 | fn af_sf s edit ulong 64 i ulong to ulong |
| 256 | x = ulong 0 |
| 257 | if ge i 34 |
| 258 | ret sub i 34 |
| 259 | end |
| 260 | sh = div i 17 |
| 261 | j = rem i 17 |
| 262 | if lt j 16 |
| 263 | x = af_set s 22 0 112 |
| 264 | x = af_fl s 0 add div j 4 1 |
| 265 | x = af_fl s 1 rem div j 2 2 |
| 266 | x = af_fl s 2 rem j 2 |
| 267 | if eq sh 1 |
| 268 | x = af_fl s 3 16 |
| 269 | x = af_fl s 4 2 |
| 270 | x = af_fl s 5 4 |
| 271 | end |
| 272 | ret AFPLAN |
| 273 | end |
| 274 | x = af_set s 23 1 117 |
| 275 | if eq sh 1 |
| 276 | x = af_fl s 0 16 |
| 277 | x = af_fl s 1 2 |
| 278 | end |
| 279 | ret AFPLAN |
| 280 | end |
| 281 | note af_sg: ratio 2..3 by state_bf16 0..1: gdn (bf16 refused 122, f32 encodes 123), gdn_multi (124), |
| 282 | note gdn_prep (125), gdn_scan refused (127), gdn_post refused (128); gdn_copy COPY..ZERO (132). |
| 283 | fn af_sg s edit ulong 64 f view ulong 32 i ulong to ulong |
| 284 | x = ulong 0 |
| 285 | if lt i 20 |
| 286 | c = div i 5 |
| 287 | k = rem i 5 |
| 288 | bf = rem c 2 |
| 289 | if eq k 0 |
| 290 | if eq bf 1 |
| 291 | x = af_set s 24 1 122 |
| 292 | else |
| 293 | x = af_set s 24 0 123 |
| 294 | end |
| 295 | end |
| 296 | if eq k 1 |
| 297 | x = af_set s 25 0 124 |
| 298 | end |
| 299 | if eq k 2 |
| 300 | x = af_set s 26 0 125 |
| 301 | end |
| 302 | if eq k 3 |
| 303 | x = af_set s 27 1 127 |
| 304 | end |
| 305 | if eq k 4 |
| 306 | x = af_set s 28 1 128 |
| 307 | end |
| 308 | x = af_fl s 0 add 2 div c 2 |
| 309 | ret af_fl s 1 bf |
| 310 | end |
| 311 | i = sub i 20 |
| 312 | n = af_cnt get f 12 get f 13 |
| 313 | if lt i n |
| 314 | x = af_set s 29 0 132 |
| 315 | ret af_fl s 0 add get f 12 i |
| 316 | end |
| 317 | ret sub i n |
| 318 | end |
| 319 | note af_sh: ternary GEMV, k of 256, 2560, 8192, OMEGA_TERN_MAX_K by the five layouts by epilogue 0..1 |
| 320 | note (144); a k above OMEGA_TERN_CHUNK_MAX with the f32 epilogue is skipped. |
| 321 | fn af_sh s edit ulong 64 f view ulong 32 i ulong to ulong |
| 322 | x = ulong 0 |
| 323 | if ge i 40 |
| 324 | ret sub i 40 |
| 325 | end |
| 326 | ki = div i 10 |
| 327 | sh = rem div i 2 5 |
| 328 | e = rem i 2 |
| 329 | k = get f 16 |
| 330 | if eq ki 0 |
| 331 | k = ulong 256 |
| 332 | end |
| 333 | if eq ki 1 |
| 334 | k = ulong 2560 |
| 335 | end |
| 336 | if eq ki 2 |
| 337 | k = ulong 8192 |
| 338 | end |
| 339 | if and gt k get f 17 eq e get f 18 |
| 340 | ret AFSKIP |
| 341 | end |
| 342 | x = af_set s 30 0 144 |
| 343 | lay = get f 14 |
| 344 | r = shl ulong 1 sh |
| 345 | if gt sh 2 |
| 346 | lay = get f 15 |
| 347 | r = shl ulong 1 sub sh 2 |
| 348 | end |
| 349 | x = af_f4 s k lay r 4 |
| 350 | x = af_fl s 4 1 |
| 351 | ret af_fl s 5 e |
| 352 | end |
| 353 | note af_plan: plans step i; AFPLAN, AFSKIP, or AFEND past the last step. |
| 354 | fn af_plan s edit ulong 64 f view ulong 32 i ulong to ulong |
| 355 | i = af_sa s f i |
| 356 | if ge i AFPLAN |
| 357 | ret i |
| 358 | end |
| 359 | i = af_sb s i |
| 360 | if ge i AFPLAN |
| 361 | ret i |
| 362 | end |
| 363 | i = af_sc s i |
| 364 | if ge i AFPLAN |
| 365 | ret i |
| 366 | end |
| 367 | i = af_sd s f i |
| 368 | if ge i AFPLAN |
| 369 | ret i |
| 370 | end |
| 371 | i = af_se s f i |
| 372 | if ge i AFPLAN |
| 373 | ret i |
| 374 | end |
| 375 | i = af_sf s i |
| 376 | if ge i AFPLAN |
| 377 | ret i |
| 378 | end |
| 379 | i = af_sg s f i |
| 380 | if ge i AFPLAN |
| 381 | ret i |
| 382 | end |
| 383 | i = af_sh s f i |
| 384 | if ge i AFPLAN |
| 385 | ret i |
| 386 | end |
| 387 | ret AFEND |
| 388 | end |
| 389 | note af_bad: the verdict of the SM86 call: encode needs rc 0 and b == a, refuse needs rc -2 and b == 0. |
| 390 | fn af_bad s view ulong 64 to ulong |
| 391 | rc = get s 2 |
| 392 | if eq get s 5 0 |
| 393 | if or ne rc 0 ne get s 3 get s 4 |
| 394 | ret ulong 1 |
| 395 | end |
| 396 | ret ulong 0 |
| 397 | end |
| 398 | if or ne rc sub ulong 0 2 ne get s 4 0 |
| 399 | ret ulong 1 |
| 400 | end |
| 401 | ret ulong 0 |
| 402 | end |
| 403 | note af_fail: "Ampere family producer failed at line %d\n" or "Ampere unsupported family accepted at |
| 404 | note line %d\n". |
| 405 | fn af_fail s edit ulong 64 o edit uchar 128 to ulong |
| 406 | put s 1 4 |
| 407 | p = ulong 0 |
| 408 | if eq get s 5 0 |
| 409 | note s "Ampere family producer failed at line " |
| 410 | p = af_s o p 7358993333125934401 8 |
| 411 | p = af_s o p 8246126623597358433 8 |
| 412 | p = af_s o p 7359007570909291631 8 |
| 413 | p = af_s o p 8386019596710996321 8 |
| 414 | p = af_s o p 35620016188448 6 |
| 415 | else |
| 416 | note s "Ampere unsupported family accepted at line " |
| 417 | p = af_s o p 8439857243694853441 8 |
| 418 | p = af_s o p 8390891584458421102 8 |
| 419 | p = af_s o p 7811895293743490149 8 |
| 420 | p = af_s o p 8390317583334711417 8 |
| 421 | p = af_s o p 7596482355684992101 8 |
| 422 | p = af_s o p 2123118 3 |
| 423 | end |
| 424 | p = af_u o p get s 6 |
| 425 | put o p uchar 10 |
| 426 | ret add 4 shl add p 1 8 |
| 427 | end |
| 428 | fn af_done s edit ulong 64 o edit uchar 128 to ulong |
| 429 | put s 1 5 |
| 430 | p = ulong 0 |
| 431 | note s "Ampere extended existing generator families encoded (host only)\n" |
| 432 | p = af_s o p 7286935739088006465 8 |
| 433 | p = af_s o p 2334101988908037240 8 |
| 434 | p = af_s o p 7453010382218164325 8 |
| 435 | p = af_s o p 8386109761109976864 8 |
| 436 | p = af_s o p 7811895293743493743 8 |
| 437 | p = af_s o p 8026380341519541609 8 |
| 438 | p = af_s o p 8317981558328026468 8 |
| 439 | p = af_s o p 732249921040621684 8 |
| 440 | ret add 5 shl p 8 |
| 441 | end |
| 442 | fn ampfam f view ulong 32 s edit ulong 64 o edit uchar 128 to ulong |
| 443 | ph = get s 1 |
| 444 | rc = get s 2 |
| 445 | if gt ph 3 |
| 446 | ret ulong 0 |
| 447 | end |
| 448 | if eq ph 1 |
| 449 | if ne rc 0 |
| 450 | ret af_fail s o |
| 451 | end |
| 452 | put s 1 2 |
| 453 | ret ulong 2 |
| 454 | end |
| 455 | if eq ph 2 |
| 456 | if ne rc 0 |
| 457 | ret af_fail s o |
| 458 | end |
| 459 | put s 1 3 |
| 460 | put s 10 get s 5 |
| 461 | ret ulong 3 |
| 462 | end |
| 463 | if eq ph 3 |
| 464 | if ne af_bad s 0 |
| 465 | ret af_fail s o |
| 466 | end |
| 467 | put s 0 add get s 0 1 |
| 468 | end |
| 469 | for t ulong 64 |
| 470 | r = af_plan s f get s 0 |
| 471 | if eq r AFPLAN |
| 472 | put s 1 1 |
| 473 | ret ulong 1 |
| 474 | end |
| 475 | if ne r AFSKIP |
| 476 | ret af_done s o |
| 477 | end |
| 478 | put s 0 add get s 0 1 |
| 479 | end |
| 480 | ret ulong 0 |
| 481 | end |