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
omega-mv / gpu / nvidia / om / tools / artexp.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note artexp: the decisions of tools/artifact_export.c (offline handoff of one CUDApp GPU realization). |
| 3 | note This unit reads the command line one argument at a time, checks it against the frozen v1 |
| 4 | note contracts, picks the kernel and its launch shape, writes the attention semantic-spec text, the |
| 5 | note manifest strings and every message, and decides the exit status. The C shell keeps the library |
| 6 | note calls (spec init, code generation, cbank arguments, SHA-256, register declaration, QMD templates, |
| 7 | note export) and the writes to stdout and stderr; it calls them when this unit asks. |
| 8 | note facts f (ulong 8): 0 OMEGA_GPU_MATMUL_MAX_CTAS, 1 OMEGA_ARTIFACT_OK. |
| 9 | note token t: the shell copies argv[s 1] (NUL included, at most 131072 bytes) when asked (return 1), the |
| 10 | note 32 hash bytes (returns 6, 9), or after the export the NUL-separated texts (return 14). |
| 11 | note state s (ulong 128, all 0 at the start; the shell writes 2 and 3 once, 18, 21..24 after calls): |
| 12 | note 0 phase, 1 argument index, 2 length of argv[s 1], 3 argc, 4 pending flag, 5 mode (1 matmul, |
| 13 | note 2 attention), 6 --out index, 7 --contract-id index, 8 its length is 64, 9 the frozen id it names |
| 14 | note (1 matmul-bf16-v1, 2 gqa-causal-v1), 10 --commit index, 11 its length is 40, 12 it is lowercase |
| 15 | note hex, 13 m, 14 k, 15 n, 16 q-heads, 17 kv-heads, 18 rc of the last call (int64 bits), 19 grid x of |
| 16 | note the matmul, 20 log2 GQA, 21 heads per CTA, 22 register peak, 23 declared registers, 24 declared ok, |
| 17 | note 25 exit status; QMD config 32 threads per block, 33 threads x, 34 grid x, 35 grid y, |
| 18 | note 36 elements, 37 shared bytes, 38 registers; manifest 40 grid x, 41 grid y, 42..44 block x y z, |
| 19 | note 45 shared bytes, 46 cbank words, 47 parameter count; 64..75 parameters (offset | size << 16 | |
| 20 | note pointer << 32); 80..83 the semantic spec id (32 bytes, little-endian words). |
| 21 | note Returns: 1 load argv[s 1] into t and s 2; 2 + 256 * length: o to stderr, exit s 25; |
| 22 | note 3 omega_matmul_spec_init(m, k, n, BF16); 4 omega_blackwell_codegen_matmul; 5 ..._matmul_tensor_loop |
| 23 | note with grid s 19; 6 the spec id into t; 7 the matmul cbank arguments; 8 the attention code with |
| 24 | note log2 GQA s 20; 9 + 256 * length: SHA-256 of o into t; 10 heads per CTA into s 21; 11 cbank word 14 = |
| 25 | note q-heads; 12 registers into s 22..24; 13 the QMD templates (rc 1 when either refuses); 14 the export |
| 26 | note with the 13 NUL-separated manifest texts in o; 15 + 256 * length: o to stdout, exit 0; 0 abort. |
| 27 | fn ae_s o edit uchar 262144 p ulong w ulong n ulong to ulong |
| 28 | i = ulong 0 |
| 29 | while lt i n bound 9 |
| 30 | put o add p i uchar and shr w mul i 8 255 |
| 31 | i = add i 1 |
| 32 | end |
| 33 | ret add p n |
| 34 | end |
| 35 | fn ae_nd v ulong to ulong |
| 36 | n = ulong 1 |
| 37 | x = div v 10 |
| 38 | while ne x 0 bound 20 |
| 39 | n = add n 1 |
| 40 | x = div x 10 |
| 41 | end |
| 42 | ret n |
| 43 | end |
| 44 | fn ae_u o edit uchar 262144 p ulong v ulong to ulong |
| 45 | w = ae_nd v |
| 46 | k = add p w |
| 47 | x = v |
| 48 | for i ulong w |
| 49 | k = sub k 1 |
| 50 | put o k uchar add 48 rem x 10 |
| 51 | x = div x 10 |
| 52 | end |
| 53 | ret add p w |
| 54 | end |
| 55 | note ae_d: %d of an int held as int64 bits. |
| 56 | fn ae_d o edit uchar 262144 p ulong v ulong to ulong |
| 57 | if ne and shr v 63 1 0 |
| 58 | put o p uchar 45 |
| 59 | ret ae_u o add p 1 sub ulong 0 v |
| 60 | end |
| 61 | ret ae_u o p v |
| 62 | end |
| 63 | note ae_cp: the NUL-terminated text of t at at, appended at p; returns p after it. |
| 64 | fn ae_cp o edit uchar 262144 p ulong t view uchar 262144 at ulong to ulong |
| 65 | q = p |
| 66 | i = at |
| 67 | while lt i 262144 bound 262144 |
| 68 | c = get t i |
| 69 | if eq c uchar 0 |
| 70 | break |
| 71 | end |
| 72 | put o q c |
| 73 | q = add q 1 |
| 74 | i = add i 1 |
| 75 | end |
| 76 | ret q |
| 77 | end |
| 78 | note ae_skip: the offset after the NUL-terminated text of t at at. |
| 79 | fn ae_skip t view uchar 262144 at ulong to ulong |
| 80 | i = at |
| 81 | while lt i 262144 bound 262144 |
| 82 | if eq get t i uchar 0 |
| 83 | ret add i 1 |
| 84 | end |
| 85 | i = add i 1 |
| 86 | end |
| 87 | ret i |
| 88 | end |
| 89 | fn ae_m8 t view uchar 262144 pos ulong w ulong n ulong to ulong |
| 90 | for i ulong n |
| 91 | if ne ulong get t add pos i and shr w mul i 8 255 |
| 92 | ret ulong 0 |
| 93 | end |
| 94 | end |
| 95 | ret ulong 1 |
| 96 | end |
| 97 | note ae_hx: the value of a hex digit, 99 for any other byte. |
| 98 | fn ae_hx c ulong to ulong |
| 99 | if and ge c 48 le c 57 |
| 100 | ret sub c 48 |
| 101 | end |
| 102 | if and ge c 97 le c 102 |
| 103 | ret sub c 87 |
| 104 | end |
| 105 | if and ge c 65 le c 70 |
| 106 | ret sub c 55 |
| 107 | end |
| 108 | ret ulong 99 |
| 109 | end |
| 110 | fn ae_sp c ulong to ulong |
| 111 | if eq c 32 |
| 112 | ret ulong 1 |
| 113 | end |
| 114 | if and ge c 9 le c 13 |
| 115 | ret ulong 1 |
| 116 | end |
| 117 | ret ulong 0 |
| 118 | end |
| 119 | note ae_num: num() of the C, strtoul(s, &e, 0) in the C locale kept when it ends the text and is at most |
| 120 | note 0xffffffff, else 0: spaces, a sign, 0x/0X hex when a hex digit follows, 0 octal, decimal; an |
| 121 | note overflow (ULONG_MAX) is 0; a minus sign negates modulo 2^64. |
| 122 | fn ae_num t view uchar 262144 n ulong to ulong |
| 123 | i = ulong 0 |
| 124 | while lt i n bound 262144 |
| 125 | if eq ae_sp ulong get t i 0 |
| 126 | break |
| 127 | end |
| 128 | i = add i 1 |
| 129 | end |
| 130 | ng = ulong 0 |
| 131 | if lt i n |
| 132 | c = ulong get t i |
| 133 | if eq c 43 |
| 134 | i = add i 1 |
| 135 | end |
| 136 | if eq c 45 |
| 137 | ng = ulong 1 |
| 138 | i = add i 1 |
| 139 | end |
| 140 | end |
| 141 | b = ulong 10 |
| 142 | if lt i n |
| 143 | if eq get t i uchar 48 |
| 144 | b = ulong 8 |
| 145 | if lt add i 2 n |
| 146 | c = ulong get t add i 1 |
| 147 | if or eq c 120 eq c 88 |
| 148 | if lt ae_hx ulong get t add i 2 16 |
| 149 | b = ulong 16 |
| 150 | i = add i 2 |
| 151 | end |
| 152 | end |
| 153 | end |
| 154 | end |
| 155 | end |
| 156 | st = i |
| 157 | v = ulong 0 |
| 158 | ov = ulong 0 |
| 159 | while lt i n bound 262144 |
| 160 | d = ae_hx ulong get t i |
| 161 | if ge d b |
| 162 | break |
| 163 | end |
| 164 | if gt v div sub sub ulong 0 1 d b |
| 165 | ov = ulong 1 |
| 166 | end |
| 167 | v = add mul v b d |
| 168 | i = add i 1 |
| 169 | end |
| 170 | if or eq i st ne i n |
| 171 | ret ulong 0 |
| 172 | end |
| 173 | if ne ov 0 |
| 174 | ret ulong 0 |
| 175 | end |
| 176 | if ne ng 0 |
| 177 | v = sub ulong 0 v |
| 178 | end |
| 179 | if gt v 4294967295 |
| 180 | ret ulong 0 |
| 181 | end |
| 182 | ret v |
| 183 | end |
| 184 | note ae_flag: 1 --out, 2 --contract-id, 3 --commit, 4 --m, 5 --k, 6 --n, 7 --q-heads, 8 --kv-heads, 0 other. |
| 185 | fn ae_flag t view uchar 262144 n ulong to ulong |
| 186 | note s "--out" |
| 187 | e = ulong 0 |
| 188 | if eq n 5 |
| 189 | e = ulong 1 |
| 190 | e = and e ae_m8 t 0 500186426669 5 |
| 191 | end |
| 192 | if ne e 0 |
| 193 | ret ulong 1 |
| 194 | end |
| 195 | note s "--contract-id" |
| 196 | e = ulong 0 |
| 197 | if eq n 13 |
| 198 | e = ulong 1 |
| 199 | e = and e ae_m8 t 0 7021802786688019757 8 |
| 200 | e = and e ae_m8 t 8 431261316195 5 |
| 201 | end |
| 202 | if ne e 0 |
| 203 | ret ulong 2 |
| 204 | end |
| 205 | note s "--commit" |
| 206 | e = ulong 0 |
| 207 | if eq n 8 |
| 208 | e = ulong 1 |
| 209 | e = and e ae_m8 t 0 8388356097741892909 8 |
| 210 | end |
| 211 | if ne e 0 |
| 212 | ret ulong 3 |
| 213 | end |
| 214 | note s "--m" |
| 215 | e = ulong 0 |
| 216 | if eq n 3 |
| 217 | e = ulong 1 |
| 218 | e = and e ae_m8 t 0 7154989 3 |
| 219 | end |
| 220 | if ne e 0 |
| 221 | ret ulong 4 |
| 222 | end |
| 223 | note s "--k" |
| 224 | e = ulong 0 |
| 225 | if eq n 3 |
| 226 | e = ulong 1 |
| 227 | e = and e ae_m8 t 0 7023917 3 |
| 228 | end |
| 229 | if ne e 0 |
| 230 | ret ulong 5 |
| 231 | end |
| 232 | note s "--n" |
| 233 | e = ulong 0 |
| 234 | if eq n 3 |
| 235 | e = ulong 1 |
| 236 | e = and e ae_m8 t 0 7220525 3 |
| 237 | end |
| 238 | if ne e 0 |
| 239 | ret ulong 6 |
| 240 | end |
| 241 | note s "--q-heads" |
| 242 | e = ulong 0 |
| 243 | if eq n 9 |
| 244 | e = ulong 1 |
| 245 | e = and e ae_m8 t 0 7233173974647123245 8 |
| 246 | e = and e ae_m8 t 8 115 1 |
| 247 | end |
| 248 | if ne e 0 |
| 249 | ret ulong 7 |
| 250 | end |
| 251 | note s "--kv-heads" |
| 252 | e = ulong 0 |
| 253 | if eq n 10 |
| 254 | e = ulong 1 |
| 255 | e = and e ae_m8 t 0 7018130138796338477 8 |
| 256 | e = and e ae_m8 t 8 29540 2 |
| 257 | end |
| 258 | if ne e 0 |
| 259 | ret ulong 8 |
| 260 | end |
| 261 | ret ulong 0 |
| 262 | end |
| 263 | fn ae_mode t view uchar 262144 n ulong to ulong |
| 264 | note s "matmul" |
| 265 | e = ulong 0 |
| 266 | if eq n 6 |
| 267 | e = ulong 1 |
| 268 | e = and e ae_m8 t 0 119251603317101 6 |
| 269 | end |
| 270 | if ne e 0 |
| 271 | ret ulong 1 |
| 272 | end |
| 273 | note s "attention" |
| 274 | e = ulong 0 |
| 275 | if eq n 9 |
| 276 | e = ulong 1 |
| 277 | e = and e ae_m8 t 0 8028075828261975137 8 |
| 278 | e = and e ae_m8 t 8 110 1 |
| 279 | end |
| 280 | if ne e 0 |
| 281 | ret ulong 2 |
| 282 | end |
| 283 | ret ulong 0 |
| 284 | end |
| 285 | fn ae_cid t view uchar 262144 n ulong to ulong |
| 286 | note s "647116fc1ba1e1394982fc8ba181ce565293f160a6b56afc0f02b2128a675704" |
| 287 | e = ulong 0 |
| 288 | if eq n 64 |
| 289 | e = ulong 1 |
| 290 | e = and e ae_m8 t 0 7162471842286351414 8 |
| 291 | e = and e ae_m8 t 8 4121692394664059441 8 |
| 292 | e = and e ae_m8 t 16 7077516104993093940 8 |
| 293 | e = and e ae_m8 t 24 3906139728515707233 8 |
| 294 | e = and e ae_m8 t 32 3474018477578727989 8 |
| 295 | e = and e ae_m8 t 40 7162519142831109729 8 |
| 296 | e = and e ae_m8 t 48 3616727373085435440 8 |
| 297 | e = and e ae_m8 t 56 3760566390553469240 8 |
| 298 | end |
| 299 | if ne e 0 |
| 300 | ret ulong 1 |
| 301 | end |
| 302 | note s "003696e422bba7274877ba9e01a61076ea0f862f32760cbaa06c60f85a115359" |
| 303 | e = ulong 0 |
| 304 | if eq n 64 |
| 305 | e = ulong 1 |
| 306 | e = and e ae_m8 t 0 3775483481970389040 8 |
| 307 | e = and e ae_m8 t 8 3977302312323527218 8 |
| 308 | e = and e ae_m8 t 16 7293968145964283956 8 |
| 309 | e = and e ae_m8 t 24 3906644189691064624 8 |
| 310 | e = and e ae_m8 t 32 7364007956564697445 8 |
| 311 | e = and e ae_m8 t 40 7017280228115821107 8 |
| 312 | e = and e ae_m8 t 48 4063988723899314273 8 |
| 313 | e = and e ae_m8 t 56 4122257337479160117 8 |
| 314 | end |
| 315 | if ne e 0 |
| 316 | ret ulong 2 |
| 317 | end |
| 318 | ret ulong 0 |
| 319 | end |
| 320 | fn ae_lhex t view uchar 262144 n ulong to ulong |
| 321 | for i ulong n |
| 322 | c = ulong get t i |
| 323 | if not or and ge c 48 le c 57 and ge c 97 le c 102 |
| 324 | ret ulong 0 |
| 325 | end |
| 326 | end |
| 327 | ret ulong 1 |
| 328 | end |
| 329 | note ae_val: the value after a flag. |
| 330 | fn ae_val s edit ulong 128 t view uchar 262144 to ulong |
| 331 | k = get s 4 |
| 332 | i = get s 1 |
| 333 | n = get s 2 |
| 334 | if eq k 1 |
| 335 | put s 6 i |
| 336 | end |
| 337 | if eq k 2 |
| 338 | put s 7 i |
| 339 | put s 8 ulong 0 |
| 340 | if eq n 64 |
| 341 | put s 8 ulong 1 |
| 342 | end |
| 343 | put s 9 ae_cid t n |
| 344 | end |
| 345 | if eq k 3 |
| 346 | put s 10 i |
| 347 | put s 11 ulong 0 |
| 348 | if eq n 40 |
| 349 | put s 11 ulong 1 |
| 350 | end |
| 351 | put s 12 ae_lhex t n |
| 352 | end |
| 353 | if ge k 4 |
| 354 | put s add 9 k ae_num t n |
| 355 | end |
| 356 | ret ulong 0 |
| 357 | end |
| 358 | fn ae_usg o edit uchar 262144 p ulong to ulong |
| 359 | note s "usage: artifact-export matmul --m M --k K --n N --contract-id HEX --out PREFIX --commit HEX\n" |
| 360 | p = ae_s o p 6998658028134298485 8 |
| 361 | p = ae_s o p 3275352098986357874 8 |
| 362 | p = ae_s o p 7863412984233621605 8 |
| 363 | p = ae_s o p 3255293755857400929 8 |
| 364 | p = ae_s o p 2336010503560437869 8 |
| 365 | p = ae_s o p 2327833714973548619 8 |
| 366 | p = ae_s o p 7021802786688019757 8 |
| 367 | p = ae_s o p 4992275802573599843 8 |
| 368 | p = ae_s o p 2338623226871881816 8 |
| 369 | p = ae_s o p 3251696002696303184 8 |
| 370 | p = ae_s o p 2338610025220498221 8 |
| 371 | p = ae_s o p 173557064 4 |
| 372 | note s " artifact-export attention --q-heads H --kv-heads H --contract-id HEX --out PREFIX --commit HEX\n" |
| 373 | p = ae_s o p 6998629143283769376 8 |
| 374 | p = ae_s o p 3275352098986357874 8 |
| 375 | p = ae_s o p 6998721855778486373 8 |
| 376 | p = ae_s o p 7957695015376221300 8 |
| 377 | p = ae_s o p 7018130138708389152 8 |
| 378 | p = ae_s o p 7722878552682558308 8 |
| 379 | p = ae_s o p 2338323001011350902 8 |
| 380 | p = ae_s o p 8389765627588190280 8 |
| 381 | p = ae_s o p 2334106150831874418 8 |
| 382 | p = ae_s o p 8462031896691885384 8 |
| 383 | p = ae_s o p 6361693212185206900 8 |
| 384 | p = ae_s o p 7596848471616597280 8 |
| 385 | p = ae_s o p 11374235754612 6 |
| 386 | ret p |
| 387 | end |
| 388 | note ae_exit: the text o 0..p - 1 to stderr and exit status e. |
| 389 | fn ae_exit s edit ulong 128 p ulong e ulong to ulong |
| 390 | put s 0 99 |
| 391 | put s 25 e |
| 392 | ret add 2 shl p 8 |
| 393 | end |
| 394 | fn ae_usage s edit ulong 128 o edit uchar 262144 to ulong |
| 395 | ret ae_exit s ae_usg o 0 2 |
| 396 | end |
| 397 | note ae_ctr: the commit and frozen-contract refusals; 0 when the arguments pass them. |
| 398 | fn ae_ctr s edit ulong 128 o edit uchar 262144 to ulong |
| 399 | if or or eq get s 6 0 eq get s 7 0 eq get s 8 0 |
| 400 | ret ae_usage s o |
| 401 | end |
| 402 | p = ulong 0 |
| 403 | if or eq get s 10 0 eq get s 11 0 |
| 404 | note s "--commit must be a 40-hex source revision\n" |
| 405 | p = ae_s o p 8388356097741892909 8 |
| 406 | p = ae_s o p 7305437230073736480 8 |
| 407 | p = ae_s o p 7307140080464847136 8 |
| 408 | p = ae_s o p 7305808869231632504 8 |
| 409 | p = ae_s o p 8028074707559739936 8 |
| 410 | p = ae_s o p 2670 2 |
| 411 | ret ae_exit s ae_usg o p 2 |
| 412 | end |
| 413 | if eq get s 12 0 |
| 414 | note s "--commit must be lowercase 40-hex\n" |
| 415 | p = ae_s o p 8388356097741892909 8 |
| 416 | p = ae_s o p 7305437230073736480 8 |
| 417 | p = ae_s o p 7017578424494418976 8 |
| 418 | p = ae_s o p 7307140080464848243 8 |
| 419 | p = ae_s o p 2680 2 |
| 420 | ret ae_exit s p 2 |
| 421 | end |
| 422 | md = get s 5 |
| 423 | if eq md 1 |
| 424 | if ne get s 9 1 |
| 425 | note s "contract id is not matmul-bf16-v1\n" |
| 426 | p = ae_s o p 8386654075301556067 8 |
| 427 | p = ae_s o p 7935469438779025696 8 |
| 428 | p = ae_s o p 8461547236690523247 8 |
| 429 | p = ae_s o p 8515522056226483564 8 |
| 430 | p = ae_s o p 2609 2 |
| 431 | ret ae_exit s p 3 |
| 432 | end |
| 433 | b = ulong 0 |
| 434 | if gt get s 13 8192 |
| 435 | b = ulong 1 |
| 436 | end |
| 437 | if gt get s 14 16384 |
| 438 | b = ulong 1 |
| 439 | end |
| 440 | if gt get s 15 8192 |
| 441 | b = ulong 1 |
| 442 | end |
| 443 | if ne b 0 |
| 444 | note s "shape outside matmul-bf16-v1 bounds (m<=8192,k<=16384,n<=8192)\n" |
| 445 | p = ae_s o p 8462017844901668979 8 |
| 446 | p = ae_s o p 7020303013988889460 8 |
| 447 | p = ae_s o p 3559640502715641204 8 |
| 448 | p = ae_s o p 8462090115260755254 8 |
| 449 | p = ae_s o p 4412521754026796142 8 |
| 450 | p = ae_s o p 4412519572481585464 8 |
| 451 | p = ae_s o p 4354466492506650161 8 |
| 452 | p = ae_s o p 2860045451737149 7 |
| 453 | ret ae_exit s p 3 |
| 454 | end |
| 455 | end |
| 456 | if eq md 2 |
| 457 | if ne get s 9 2 |
| 458 | note s "contract id is not gqa-causal-v1\n" |
| 459 | p = ae_s o p 8386654075301556067 8 |
| 460 | p = ae_s o p 7935469438779025696 8 |
| 461 | p = ae_s o p 7146475323396224111 8 |
| 462 | p = ae_s o p 3564086098625000801 8 |
| 463 | p = ae_s o p 10 1 |
| 464 | ret ae_exit s p 3 |
| 465 | end |
| 466 | b = ulong 0 |
| 467 | if gt get s 16 64 |
| 468 | b = ulong 1 |
| 469 | end |
| 470 | if gt get s 17 64 |
| 471 | b = ulong 1 |
| 472 | end |
| 473 | if ne b 0 |
| 474 | note s "heads outside gqa-causal-v1 bounds (hq<=64,hkv<=64)\n" |
| 475 | p = ae_s o p 8462017904829883752 8 |
| 476 | p = ae_s o p 8171535668735472500 8 |
| 477 | p = ae_s o p 7809650176819408225 8 |
| 478 | p = ae_s o p 7959390383684810285 8 |
| 479 | p = ae_s o p 4412526427079996260 8 |
| 480 | p = ae_s o p 4412531938597549110 8 |
| 481 | p = ae_s o p 170472502 4 |
| 482 | ret ae_exit s p 3 |
| 483 | end |
| 484 | end |
| 485 | ret ulong 0 |
| 486 | end |
| 487 | note ae_mm: the matmul shape checks; returns the spec-init request. |
| 488 | fn ae_mm s edit ulong 128 o edit uchar 262144 to ulong |
| 489 | m = get s 13 |
| 490 | k = get s 14 |
| 491 | n = get s 15 |
| 492 | if or or eq m 0 eq k 0 eq n 0 |
| 493 | ret ae_usage s o |
| 494 | end |
| 495 | b = ulong 0 |
| 496 | if ne rem m 16 0 |
| 497 | b = ulong 1 |
| 498 | end |
| 499 | if ne rem n 8 0 |
| 500 | b = ulong 1 |
| 501 | end |
| 502 | if ne rem k 16 0 |
| 503 | b = ulong 1 |
| 504 | end |
| 505 | if ne b 0 |
| 506 | p = ulong 0 |
| 507 | note s "matmul-bf16-v1 export needs m%16 == 0, n%8 == 0, k%16 == 0 (got " |
| 508 | p = ae_s o p 7074429841272234349 8 |
| 509 | p = ae_s o p 7286878580719890790 8 |
| 510 | p = ae_s o p 7308814929777094776 8 |
| 511 | p = ae_s o p 3904943502533026917 8 |
| 512 | p = ae_s o p 7935391128637750560 8 |
| 513 | p = ae_s o p 3184080383941556261 8 |
| 514 | p = ae_s o p 4412718627017812768 8 |
| 515 | p = ae_s o p 2338616595357642784 8 |
| 516 | p = ae_u o p m |
| 517 | put o p uchar 120 |
| 518 | p = ae_u o add p 1 k |
| 519 | put o p uchar 120 |
| 520 | p = ae_u o add p 1 n |
| 521 | note s ")\n" |
| 522 | p = ae_s o p 2601 2 |
| 523 | ret ae_exit s p 3 |
| 524 | end |
| 525 | put s 0 5 |
| 526 | ret ulong 3 |
| 527 | end |
| 528 | note ae_at: the attention head checks and the GQA ratio; returns the attention code request. |
| 529 | fn ae_at s edit ulong 128 o edit uchar 262144 to ulong |
| 530 | hq = get s 16 |
| 531 | hk = get s 17 |
| 532 | if or eq hq 0 eq hk 0 |
| 533 | ret ae_usage s o |
| 534 | end |
| 535 | if ne rem hq hk 0 |
| 536 | ret ae_usage s o |
| 537 | end |
| 538 | r = div hq hk |
| 539 | l = ulong 0 |
| 540 | while lt shl ulong 1 l r bound 64 |
| 541 | l = add l 1 |
| 542 | end |
| 543 | if ne shl ulong 1 l r |
| 544 | p = ulong 0 |
| 545 | note s "GQA ratio is not a power of two\n" |
| 546 | p = ae_s o p 7598805614076186951 8 |
| 547 | p = ae_s o p 8390045716468801647 8 |
| 548 | p = ae_s o p 8243126013477806368 8 |
| 549 | p = ae_s o p 751951003437657888 8 |
| 550 | ret ae_exit s p 3 |
| 551 | end |
| 552 | put s 20 l |
| 553 | put s 0 8 |
| 554 | ret ulong 8 |
| 555 | end |
| 556 | note ae_chk: every check after the last argument. |
| 557 | fn ae_chk s edit ulong 128 o edit uchar 262144 to ulong |
| 558 | x = ae_ctr s o |
| 559 | if ne x 0 |
| 560 | ret x |
| 561 | end |
| 562 | md = get s 5 |
| 563 | if eq md 1 |
| 564 | ret ae_mm s o |
| 565 | end |
| 566 | if eq md 2 |
| 567 | ret ae_at s o |
| 568 | end |
| 569 | ret ae_usage s o |
| 570 | end |
| 571 | fn ae_msg s edit ulong 128 o edit uchar 262144 w ulong n ulong to ulong |
| 572 | p = ae_s o 0 w n |
| 573 | ret ae_exit s p 3 |
| 574 | end |
| 575 | fn ae_prm s edit ulong 128 i ulong off ulong sz ulong pt ulong to ulong |
| 576 | put s add 64 i or or off shl sz 16 shl pt 32 |
| 577 | ret ulong 0 |
| 578 | end |
| 579 | fn ae_cfg s edit ulong 128 tb ulong gx ulong gy ulong el ulong sh ulong to ulong |
| 580 | put s 32 tb |
| 581 | put s 33 tb |
| 582 | put s 34 gx |
| 583 | put s 35 gy |
| 584 | put s 36 el |
| 585 | put s 37 sh |
| 586 | put s 40 gx |
| 587 | put s 41 gy |
| 588 | put s 42 tb |
| 589 | put s 43 1 |
| 590 | put s 44 1 |
| 591 | put s 45 sh |
| 592 | put s 0 10 |
| 593 | ret ulong 0 |
| 594 | end |
| 595 | note ae_mmcfg: the matmul launch: CTA (x, y) over 16 x 8 tiles, 32 threads, 1024 shared bytes, three pointer |
| 596 | note parameters at 0x380, 10 cbank words. |
| 597 | fn ae_mmcfg s edit ulong 128 to ulong |
| 598 | m = get s 13 |
| 599 | gy = div m 16 |
| 600 | el = and mul m get s 15 4294967295 |
| 601 | gx = get s 19 |
| 602 | x = ae_cfg s 32 gx gy el 1024 |
| 603 | put s 46 10 |
| 604 | put s 47 3 |
| 605 | for i ulong 3 |
| 606 | x = ae_prm s i add 896 mul i 8 8 1 |
| 607 | end |
| 608 | ret ulong 7 |
| 609 | end |
| 610 | note ae_atcfg: the attention launch: 128 threads, q-heads / heads-per-CTA CTAs, (3 * hpc + 1) * 128 * 4 shared |
| 611 | note bytes, four pointers at 0x380 then eight u32 at 0x3a0, 16 cbank words. |
| 612 | fn ae_atcfg s edit ulong 128 to ulong |
| 613 | hq = get s 16 |
| 614 | hp = get s 21 |
| 615 | sh = add mul 3 hp 1 |
| 616 | sh = and mul sh 512 4294967295 |
| 617 | gx = div hq hp |
| 618 | el = and mul hq 128 4294967295 |
| 619 | x = ae_cfg s 128 gx 1 el sh |
| 620 | put s 46 16 |
| 621 | put s 47 12 |
| 622 | for i ulong 4 |
| 623 | x = ae_prm s i add 896 mul i 8 8 1 |
| 624 | end |
| 625 | for i ulong 8 |
| 626 | x = ae_prm s add 4 i add 928 mul i 4 4 0 |
| 627 | end |
| 628 | ret ulong 11 |
| 629 | end |
| 630 | fn ae_spec s edit ulong 128 t view uchar 262144 to ulong |
| 631 | for i ulong 4 |
| 632 | w = ulong 0 |
| 633 | for j ulong 8 |
| 634 | c = ulong get t add mul i 8 j |
| 635 | w = or w shl c mul j 8 |
| 636 | end |
| 637 | put s add 80 i w |
| 638 | end |
| 639 | ret ulong 0 |
| 640 | end |
| 641 | note ae_stext: "omega-attention-spec/1\nhead_dim=128\nq_heads=%u\nkv_heads=%u\nlog2_gqa=%u\n", hashed by |
| 642 | note the shell. |
| 643 | fn ae_stext s edit ulong 128 o edit uchar 262144 to ulong |
| 644 | p = ulong 0 |
| 645 | note s "omega-attention-spec/1\nhead_dim=128\nq_heads=" |
| 646 | p = ae_s o p 8386033877510352239 8 |
| 647 | p = ae_s o p 3273676477860570484 8 |
| 648 | p = ae_s o p 7496858609312428147 8 |
| 649 | p = ae_s o p 4426309888593125733 8 |
| 650 | p = ae_s o p 7307195334516027953 8 |
| 651 | p = ae_s o p 1030972513 4 |
| 652 | p = ae_u o p get s 16 |
| 653 | note s "\nkv_heads=" |
| 654 | p = ae_s o p 7233173975486327562 8 |
| 655 | p = ae_s o p 15731 2 |
| 656 | p = ae_u o p get s 17 |
| 657 | note s "\nlog2_gqa=" |
| 658 | p = ae_s o p 8171604718975413258 8 |
| 659 | p = ae_s o p 15713 2 |
| 660 | p = ae_u o p get s 20 |
| 661 | put o p uchar 10 |
| 662 | put s 0 9 |
| 663 | ret add 9 shl add p 1 8 |
| 664 | end |
| 665 | fn ae_hex o edit uchar 262144 p ulong s view ulong 128 to ulong |
| 666 | q = p |
| 667 | for i ulong 32 |
| 668 | w = get s add 80 div i 8 |
| 669 | b = and shr w mul rem i 8 8 255 |
| 670 | for j ulong 2 |
| 671 | d = shr b mul sub 1 j 4 |
| 672 | d = and d 15 |
| 673 | if lt d 10 |
| 674 | put o q uchar add 48 d |
| 675 | else |
| 676 | put o q uchar add 87 d |
| 677 | end |
| 678 | q = add q 1 |
| 679 | end |
| 680 | end |
| 681 | put o q uchar 0 |
| 682 | ret add q 1 |
| 683 | end |
| 684 | note ae_mmtx: the matmul manifest texts up to the bounds. |
| 685 | fn ae_mmtx s edit ulong 128 o edit uchar 262144 to ulong |
| 686 | p = ulong 0 |
| 687 | note s "matmul\0matmul-bf16-v1\0bf16\0fp32\0abs<=1e-5*max(1,abs(ref))\0m=" |
| 688 | p = ae_s o p 7854397001737462125 8 |
| 689 | p = ae_s o p 7377509083436119137 8 |
| 690 | p = ae_s o p 7377459352022365745 8 |
| 691 | p = ae_s o p 14130306676176433 8 |
| 692 | p = ae_s o p 3271074843431494241 8 |
| 693 | p = ae_s o p 3184370909023382069 8 |
| 694 | p = ae_s o p 2983183344158859873 8 |
| 695 | p = ae_s o p 1030553641 4 |
| 696 | p = ae_u o p get s 13 |
| 697 | note s ",k=" |
| 698 | p = ae_s o p 4025132 3 |
| 699 | p = ae_u o p get s 14 |
| 700 | note s ",n=" |
| 701 | p = ae_s o p 4025900 3 |
| 702 | p = ae_u o p get s 15 |
| 703 | note s "\0m<=8192,k<=16384,n<=8192\0" |
| 704 | p = ae_s o p 3618977893184204032 8 |
| 705 | p = ae_s o p 4049640075044875052 8 |
| 706 | p = ae_s o p 4121136969678728244 8 |
| 707 | p = ae_s o p 50 2 |
| 708 | p = ae_hex o p s |
| 709 | note s "omega_matmul_bf16\0" |
| 710 | p = ae_s o p 7020372266091638127 8 |
| 711 | p = ae_s o p 3559640717464006004 8 |
| 712 | p = ae_s o p 54 2 |
| 713 | ret p |
| 714 | end |
| 715 | fn ae_attx s edit ulong 128 o edit uchar 262144 to ulong |
| 716 | p = ulong 0 |
| 717 | note s "gqa-causal-attention\0gqa-causal-v1\0f32-kv\0fp32\0rel<=1e-3,abs<=1e-4\0r>=1,base=0,hq=" |
| 718 | p = ae_s o p 8319662965227876711 8 |
| 719 | p = ae_s o p 7954892360015244385 8 |
| 720 | p = ae_s o p 7021506545597770100 8 |
| 721 | p = ae_s o p 3273098177709957933 8 |
| 722 | p = ae_s o p 7722884132346278262 8 |
| 723 | p = ae_s o p 8214620916834238582 8 |
| 724 | p = ae_s o p 3687714932041477221 8 |
| 725 | p = ae_s o p 7291676601532703020 8 |
| 726 | p = ae_s o p 3184393749937533997 8 |
| 727 | p = ae_s o p 7506427719172972898 8 |
| 728 | p = ae_s o p 15729 2 |
| 729 | p = ae_u o p get s 16 |
| 730 | note s ",hkv=" |
| 731 | p = ae_s o p 263979755564 5 |
| 732 | p = ae_u o p get s 17 |
| 733 | note s ",hd=128\0hq<=64,hkv<=64,hd=128,rows+base<=4096\0" |
| 734 | p = ae_s o p 15817785760573484 8 |
| 735 | p = ae_s o p 7506432086480023912 8 |
| 736 | p = ae_s o p 7506432086480025195 8 |
| 737 | p = ae_s o p 8030529705426894180 8 |
| 738 | p = ae_s o p 4352011477019489143 8 |
| 739 | p = ae_s o p 232887694397 6 |
| 740 | p = ae_hex o p s |
| 741 | note s "omega_gqa_attention_causal\0" |
| 742 | p = ae_s o p 8171604920838221167 8 |
| 743 | p = ae_s o p 8389754706680962913 8 |
| 744 | p = ae_s o p 8319662966067588969 8 |
| 745 | p = ae_s o p 27745 3 |
| 746 | ret p |
| 747 | end |
| 748 | note ae_texts: the 13 manifest texts in the order op, contract name, precision, accumulation, tolerance, |
| 749 | note shape, bounds, semantic spec id, kernel function, minimum driver, requires, tool version, |
| 750 | note qualification. |
| 751 | fn ae_texts s edit ulong 128 o edit uchar 262144 to ulong |
| 752 | p = ulong 0 |
| 753 | if eq get s 5 1 |
| 754 | p = ae_mmtx s o |
| 755 | else |
| 756 | p = ae_attx s o |
| 757 | end |
| 758 | note s "580.173.02\0sm_121,nvidia-cubin-abi-v8\0cudapp-artifact-export/1\0" |
| 759 | p = ae_s o p 3329065233924765749 8 |
| 760 | p = ae_s o p 3616776899440685616 8 |
| 761 | p = ae_s o p 7019251898354904113 8 |
| 762 | p = ae_s o p 7002374394533471021 8 |
| 763 | p = ae_s o p 8458604767632779618 8 |
| 764 | p = ae_s o p 8390875903532491108 8 |
| 765 | p = ae_s o p 8675390235105912425 8 |
| 766 | p = ae_s o p 54079886880624 7 |
| 767 | note s "offline-disassembly=PASS;device-load=NOT_RUN;device-exec=NOT_RUN\0" |
| 768 | p = ae_s o p 3271142103423805039 8 |
| 769 | p = ae_s o p 7882833662175308132 8 |
| 770 | p = ae_s o p 6004214541099560034 8 |
| 771 | p = ae_s o p 3271130008963605563 8 |
| 772 | p = ae_s o p 6075160447930167148 8 |
| 773 | p = ae_s o p 8531335275003335263 8 |
| 774 | p = ae_s o p 7162263158351291241 8 |
| 775 | p = ae_s o p 5644508277368639037 8 |
| 776 | p = ae_s o p 0 1 |
| 777 | put s 0 14 |
| 778 | ret ulong 14 |
| 779 | end |
| 780 | note ae_done: after the export: t holds the rc name and the error, or the id, the contract id and PREFIX. |
| 781 | fn ae_done s edit ulong 128 f view ulong 8 t view uchar 262144 o edit uchar 262144 to ulong |
| 782 | p = ulong 0 |
| 783 | if ne get s 18 get f 1 |
| 784 | note s "artifact-export refused: " |
| 785 | p = ae_s o p 8386654023577793121 8 |
| 786 | p = ae_s o p 2338619929466004781 8 |
| 787 | p = ae_s o p 4207599498436175218 8 |
| 788 | p = ae_s o p 32 1 |
| 789 | p = ae_cp o p t 0 |
| 790 | note s ": " |
| 791 | p = ae_s o p 8250 2 |
| 792 | p = ae_cp o p t ae_skip t 0 |
| 793 | put o p uchar 10 |
| 794 | ret ae_exit s add p 1 3 |
| 795 | end |
| 796 | at = ulong 0 |
| 797 | note s "artifact_id=" |
| 798 | p = ae_s o p 8386654023577793121 8 |
| 799 | p = ae_s o p 1029990751 4 |
| 800 | p = ae_cp o p t at |
| 801 | at = ae_skip t at |
| 802 | note s "\nop=" |
| 803 | p = ae_s o p 1030778634 4 |
| 804 | if eq get s 5 1 |
| 805 | note s "matmul" |
| 806 | p = ae_s o p 119251603317101 6 |
| 807 | else |
| 808 | note s "gqa-causal-attention" |
| 809 | p = ae_s o p 8319662965227876711 8 |
| 810 | p = ae_s o p 7954892360015244385 8 |
| 811 | p = ae_s o p 1852795252 4 |
| 812 | end |
| 813 | note s "\ncontract_id=" |
| 814 | p = ae_s o p 7161130726890365706 8 |
| 815 | p = ae_s o p 263677632372 5 |
| 816 | p = ae_cp o p t at |
| 817 | at = ae_skip t at |
| 818 | note s "\ncubin=" |
| 819 | p = ae_s o p 17291372481831690 7 |
| 820 | p = ae_cp o p t at |
| 821 | note s ".cubin\n" |
| 822 | p = ae_s o p 2936148669588270 7 |
| 823 | put s 0 99 |
| 824 | ret add 15 shl p 8 |
| 825 | end |
| 826 | note ae_args: phases 0..3, the command line. |
| 827 | fn ae_args s edit ulong 128 t view uchar 262144 o edit uchar 262144 to ulong |
| 828 | ph = get s 0 |
| 829 | i = get s 1 |
| 830 | ac = get s 3 |
| 831 | if eq ph 0 |
| 832 | if lt ac 2 |
| 833 | ret ae_usage s o |
| 834 | end |
| 835 | put s 1 1 |
| 836 | put s 0 1 |
| 837 | ret ulong 1 |
| 838 | end |
| 839 | if eq ph 1 |
| 840 | put s 5 ae_mode t get s 2 |
| 841 | i = ulong 2 |
| 842 | end |
| 843 | if eq ph 2 |
| 844 | k = ae_flag t get s 2 |
| 845 | if or eq k 0 ge add i 1 ac |
| 846 | ret ae_usage s o |
| 847 | end |
| 848 | put s 4 k |
| 849 | put s 1 add i 1 |
| 850 | put s 0 3 |
| 851 | ret ulong 1 |
| 852 | end |
| 853 | if eq ph 3 |
| 854 | x = ae_val s t |
| 855 | i = add i 1 |
| 856 | end |
| 857 | put s 1 i |
| 858 | if lt i ac |
| 859 | put s 0 2 |
| 860 | ret ulong 1 |
| 861 | end |
| 862 | ret ae_chk s o |
| 863 | end |
| 864 | fn artexp f view ulong 8 s edit ulong 128 t view uchar 262144 o edit uchar 262144 to ulong |
| 865 | ph = get s 0 |
| 866 | rc = get s 18 |
| 867 | p = ulong 0 |
| 868 | if lt ph 4 |
| 869 | ret ae_args s t o |
| 870 | end |
| 871 | if eq ph 5 |
| 872 | if ne rc 0 |
| 873 | note s "spec refused\n" |
| 874 | p = ae_s o p 7378429047948537971 8 |
| 875 | p = ae_s o p 44634043253 5 |
| 876 | ret ae_exit s p 3 |
| 877 | end |
| 878 | m = get s 13 |
| 879 | n = get s 15 |
| 880 | gx = div n 8 |
| 881 | put s 0 6 |
| 882 | if eq get s 14 16 |
| 883 | put s 19 gx |
| 884 | ret ulong 4 |
| 885 | end |
| 886 | b = div get f 0 div m 16 |
| 887 | if eq b 0 |
| 888 | b = ulong 1 |
| 889 | end |
| 890 | if gt gx b |
| 891 | gx = b |
| 892 | end |
| 893 | put s 19 gx |
| 894 | ret ulong 5 |
| 895 | end |
| 896 | if eq ph 6 |
| 897 | if ne rc 0 |
| 898 | note s "codegen refused\n" |
| 899 | p = ae_s o p 2336916751408983907 8 |
| 900 | p = ae_s o p 748834984615634290 8 |
| 901 | ret ae_exit s p 3 |
| 902 | end |
| 903 | put s 0 7 |
| 904 | ret ulong 6 |
| 905 | end |
| 906 | if eq ph 7 |
| 907 | x = ae_spec s t |
| 908 | ret ae_mmcfg s |
| 909 | end |
| 910 | if eq ph 8 |
| 911 | if ne rc 0 |
| 912 | note s "attention codegen refused: " |
| 913 | p = ae_s o p 8028075828261975137 8 |
| 914 | p = ae_s o p 7306920402471821422 8 |
| 915 | p = ae_s o p 7310315702801539182 8 |
| 916 | p = ae_s o p 2112100 3 |
| 917 | p = ae_d o p rc |
| 918 | put o p uchar 10 |
| 919 | ret ae_exit s add p 1 3 |
| 920 | end |
| 921 | ret ae_stext s o |
| 922 | end |
| 923 | if eq ph 9 |
| 924 | x = ae_spec s t |
| 925 | put s 0 12 |
| 926 | ret ulong 10 |
| 927 | end |
| 928 | if eq ph 12 |
| 929 | ret ae_atcfg s |
| 930 | end |
| 931 | if eq ph 10 |
| 932 | put s 0 11 |
| 933 | ret ulong 12 |
| 934 | end |
| 935 | if eq ph 11 |
| 936 | put s 38 get s 23 |
| 937 | if eq get s 24 0 |
| 938 | note s "declared registers refused\n" |
| 939 | p = ae_s o p 7234314139196417380 8 |
| 940 | p = ae_s o p 7310594991672619552 8 |
| 941 | p = ae_s o p 8319668472529318770 8 |
| 942 | p = ae_s o p 681061 3 |
| 943 | ret ae_exit s p 3 |
| 944 | end |
| 945 | put s 0 13 |
| 946 | ret ulong 13 |
| 947 | end |
| 948 | if eq ph 13 |
| 949 | if ne rc 0 |
| 950 | note s "QMD template refused\n" |
| 951 | p = ae_s o p 8101242854141349201 8 |
| 952 | p = ae_s o p 7378429047983071596 8 |
| 953 | p = ae_s o p 44634043253 5 |
| 954 | ret ae_exit s p 3 |
| 955 | end |
| 956 | ret ae_texts s o |
| 957 | end |
| 958 | if eq ph 14 |
| 959 | ret ae_done s f t o |
| 960 | end |
| 961 | ret ulong 0 |
| 962 | end |