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 / evidence / tools-om-2 / 2026-11-06 / coverage / artifact_export.c.gcov
| 1 | -: 0:Source:artifact_export.c |
| 2 | -: 0:Graph:ae_cov-artifact_export.gcno |
| 3 | -: 0:Data:ae_cov-artifact_export.gcda |
| 4 | -: 0:Runs:116 |
| 5 | -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 6 | -: 2:/* artifact-export: offline handoff for one CUDApp-generated GPU realization. |
| 7 | -: 3: * |
| 8 | -: 4: * artifact-export matmul --m M --k K --n N --contract-id HEX --out PREFIX --commit HEX |
| 9 | -: 5: * artifact-export attention --q-heads HQ --kv-heads HKV --contract-id HEX --out PREFIX --commit HEX |
| 10 | -: 6: * |
| 11 | -: 7: * Opens no device. Emits a cubin, zero-VA QMD templates, cbank bytes, a |
| 12 | -: 8: * canonical manifest and a JSON mirror. An artifact is immutable: export |
| 13 | -: 9: * refuses (I/O) when any PREFIX.* output already exists or is a symlink, and |
| 14 | -: 10: * refuses a PREFIX too long for every output path. |
| 15 | -: 11: * Exit: 0 ok, 2 usage, 3 refusal, 4 I/O. */ |
| 16 | -: 12:#include <stdio.h> |
| 17 | -: 13:#include <stdlib.h> |
| 18 | -: 14:#include <string.h> |
| 19 | -: 15: |
| 20 | -: 16:#include "omega_blackwell_codegen.h" |
| 21 | -: 17:#include "omega_blackwell_matmul.h" |
| 22 | -: 18:#include "omega_blackwell_qmd.h" |
| 23 | -: 19:#include "omega_gpu_attention_api.h" |
| 24 | -: 20:#include "omega_gpu_matmul_api.h" |
| 25 | -: 21:#include "omega_native_artifact.h" |
| 26 | -: 22:#include "sha256.h" |
| 27 | -: 23:#ifdef CUDAPP_MIGRATION_PENDING_C_TOOLS_ARTEXP |
| 28 | function usage called 49 returned 100% blocks executed 100% |
| 29 | 49: 24:static void usage(void) { |
| 30 | 49: 25: fprintf(stderr, |
| 31 | call 0 returned 49 |
| 32 | -: 26: "usage: artifact-export matmul --m M --k K --n N --contract-id HEX --out PREFIX --commit HEX\n" |
| 33 | -: 27: " artifact-export attention --q-heads H --kv-heads H --contract-id HEX --out PREFIX --commit HEX\n"); |
| 34 | 49: 28:} |
| 35 | -: 29: |
| 36 | function num called 283 returned 100% blocks executed 100% |
| 37 | 283: 30:static uint32_t num(const char *s) { |
| 38 | 283: 31: char *e = NULL; |
| 39 | 283: 32: unsigned long v = strtoul(s, &e, 0); |
| 40 | call 0 returned 283 |
| 41 | 283: 33: return (e && *e == 0 && v <= 0xfffffffful) ? (uint32_t)v : 0; |
| 42 | branch 0 taken 283 (fallthrough) |
| 43 | branch 1 taken 0 |
| 44 | branch 2 taken 276 (fallthrough) |
| 45 | branch 3 taken 7 |
| 46 | branch 4 taken 268 (fallthrough) |
| 47 | branch 5 taken 8 |
| 48 | -: 34:} |
| 49 | -: 35: |
| 50 | function hex32 called 22 returned 100% blocks executed 100% |
| 51 | 22: 36:static void hex32(const uint8_t b[32], char out[65]) { |
| 52 | -: 37: static const char h[] = "0123456789abcdef"; |
| 53 | 726: 38: for (int i = 0; i < 32; i++) { out[2 * i] = h[b[i] >> 4]; out[2 * i + 1] = h[b[i] & 15]; } |
| 54 | branch 0 taken 704 |
| 55 | branch 1 taken 22 (fallthrough) |
| 56 | 22: 39: out[64] = 0; |
| 57 | 22: 40:} |
| 58 | -: 41: |
| 59 | function main called 116 returned 100% blocks executed 92% |
| 60 | 116: 42:int main(int argc, char **argv) { |
| 61 | 116: 43: const char *mode, *out = NULL, *contract = NULL, *commit = NULL; |
| 62 | 116: 44: uint32_t m = 0, k = 0, n = 0, hq = 0, hkv = 0; |
| 63 | 116: 45: if (argc < 2) { usage(); return 2; } |
| 64 | branch 0 taken 1 (fallthrough) |
| 65 | branch 1 taken 115 |
| 66 | call 2 returned 1 |
| 67 | 115: 46: mode = argv[1]; |
| 68 | 714: 47: for (int i = 2; i < argc; i++) { |
| 69 | branch 0 taken 608 |
| 70 | branch 1 taken 106 (fallthrough) |
| 71 | 608: 48: if (strcmp(argv[i], "--out") == 0 && i + 1 < argc) out = argv[++i]; |
| 72 | branch 0 taken 111 (fallthrough) |
| 73 | branch 1 taken 497 |
| 74 | branch 2 taken 110 (fallthrough) |
| 75 | branch 3 taken 1 |
| 76 | 498: 49: else if (strcmp(argv[i], "--contract-id") == 0 && i + 1 < argc) contract = argv[++i]; |
| 77 | branch 0 taken 104 (fallthrough) |
| 78 | branch 1 taken 394 |
| 79 | branch 2 taken 103 (fallthrough) |
| 80 | branch 3 taken 1 |
| 81 | 395: 50: else if (strcmp(argv[i], "--commit") == 0 && i + 1 < argc) commit = argv[++i]; |
| 82 | branch 0 taken 104 (fallthrough) |
| 83 | branch 1 taken 291 |
| 84 | branch 2 taken 103 (fallthrough) |
| 85 | branch 3 taken 1 |
| 86 | 292: 51: else if (strcmp(argv[i], "--m") == 0 && i + 1 < argc) m = num(argv[++i]); |
| 87 | branch 0 taken 77 (fallthrough) |
| 88 | branch 1 taken 215 |
| 89 | branch 2 taken 76 (fallthrough) |
| 90 | branch 3 taken 1 |
| 91 | call 4 returned 76 |
| 92 | 216: 52: else if (strcmp(argv[i], "--k") == 0 && i + 1 < argc) k = num(argv[++i]); |
| 93 | branch 0 taken 76 (fallthrough) |
| 94 | branch 1 taken 140 |
| 95 | branch 2 taken 75 (fallthrough) |
| 96 | branch 3 taken 1 |
| 97 | call 4 returned 75 |
| 98 | 141: 53: else if (strcmp(argv[i], "--n") == 0 && i + 1 < argc) n = num(argv[++i]); |
| 99 | branch 0 taken 76 (fallthrough) |
| 100 | branch 1 taken 65 |
| 101 | branch 2 taken 75 (fallthrough) |
| 102 | branch 3 taken 1 |
| 103 | call 4 returned 75 |
| 104 | 66: 54: else if (strcmp(argv[i], "--q-heads") == 0 && i + 1 < argc) hq = num(argv[++i]); |
| 105 | branch 0 taken 29 (fallthrough) |
| 106 | branch 1 taken 37 |
| 107 | branch 2 taken 28 (fallthrough) |
| 108 | branch 3 taken 1 |
| 109 | call 4 returned 28 |
| 110 | 38: 55: else if (strcmp(argv[i], "--kv-heads") == 0 && i + 1 < argc) hkv = num(argv[++i]); |
| 111 | branch 0 taken 30 (fallthrough) |
| 112 | branch 1 taken 8 |
| 113 | branch 2 taken 29 (fallthrough) |
| 114 | branch 3 taken 1 |
| 115 | call 4 returned 29 |
| 116 | 9: 56: else { usage(); return 2; } |
| 117 | call 0 returned 9 |
| 118 | -: 57: } |
| 119 | 106: 58: if (!out || !contract || strlen(contract) != 64) { usage(); return 2; } |
| 120 | branch 0 taken 102 (fallthrough) |
| 121 | branch 1 taken 4 |
| 122 | branch 2 taken 101 (fallthrough) |
| 123 | branch 3 taken 1 |
| 124 | branch 4 taken 2 (fallthrough) |
| 125 | branch 5 taken 99 |
| 126 | call 6 returned 7 |
| 127 | 99: 59: if (!commit || strlen(commit) != 40) { fprintf(stderr, "--commit must be a 40-hex source revision\n"); usage(); return 2; } |
| 128 | branch 0 taken 98 (fallthrough) |
| 129 | branch 1 taken 1 |
| 130 | branch 2 taken 2 (fallthrough) |
| 131 | branch 3 taken 96 |
| 132 | call 4 returned 3 |
| 133 | call 5 returned 3 |
| 134 | 3790: 60: for (const char *h = commit; *h; h++) { |
| 135 | branch 0 taken 3699 |
| 136 | branch 1 taken 91 (fallthrough) |
| 137 | 3699: 61: if (!((*h >= '0' && *h <= '9') || (*h >= 'a' && *h <= 'f'))) { |
| 138 | branch 0 taken 3698 (fallthrough) |
| 139 | branch 1 taken 1 |
| 140 | branch 2 taken 1101 (fallthrough) |
| 141 | branch 3 taken 2597 |
| 142 | branch 4 taken 1098 (fallthrough) |
| 143 | branch 5 taken 4 |
| 144 | branch 6 taken 1 (fallthrough) |
| 145 | branch 7 taken 1097 |
| 146 | 5: 62: fprintf(stderr, "--commit must be lowercase 40-hex\n"); return 2; |
| 147 | call 0 returned 5 |
| 148 | -: 63: } |
| 149 | -: 64: } |
| 150 | -: 65: /* The frozen v1 ids and bounds. An export under a frozen id but outside the |
| 151 | -: 66: * frozen range would let a consumer admit an artifact the contract forbids |
| 152 | -: 67: * (REVIEW C-11). */ |
| 153 | 91: 68: if (strcmp(mode, "matmul") == 0) { |
| 154 | branch 0 taken 60 (fallthrough) |
| 155 | branch 1 taken 31 |
| 156 | 60: 69: if (strcmp(contract, "647116fc1ba1e1394982fc8ba181ce565293f160a6b56afc0f02b2128a675704") != 0) { |
| 157 | branch 0 taken 2 (fallthrough) |
| 158 | branch 1 taken 58 |
| 159 | 2: 70: fprintf(stderr, "contract id is not matmul-bf16-v1\n"); return 3; |
| 160 | call 0 returned 2 |
| 161 | -: 71: } |
| 162 | 58: 72: if (m > 8192u || k > 16384u || n > 8192u) { |
| 163 | branch 0 taken 55 (fallthrough) |
| 164 | branch 1 taken 3 |
| 165 | branch 2 taken 53 (fallthrough) |
| 166 | branch 3 taken 2 |
| 167 | branch 4 taken 2 (fallthrough) |
| 168 | branch 5 taken 51 |
| 169 | 7: 73: fprintf(stderr, "shape outside matmul-bf16-v1 bounds (m<=8192,k<=16384,n<=8192)\n"); return 3; |
| 170 | call 0 returned 7 |
| 171 | -: 74: } |
| 172 | 31: 75: } else if (strcmp(mode, "attention") == 0) { |
| 173 | branch 0 taken 27 (fallthrough) |
| 174 | branch 1 taken 4 |
| 175 | 27: 76: if (strcmp(contract, "003696e422bba7274877ba9e01a61076ea0f862f32760cbaa06c60f85a115359") != 0) { |
| 176 | branch 0 taken 2 (fallthrough) |
| 177 | branch 1 taken 25 |
| 178 | 2: 77: fprintf(stderr, "contract id is not gqa-causal-v1\n"); return 3; |
| 179 | call 0 returned 2 |
| 180 | -: 78: } |
| 181 | 25: 79: if (hq > 64u || hkv > 64u) { |
| 182 | branch 0 taken 24 (fallthrough) |
| 183 | branch 1 taken 1 |
| 184 | branch 2 taken 2 (fallthrough) |
| 185 | branch 3 taken 22 |
| 186 | 3: 80: fprintf(stderr, "heads outside gqa-causal-v1 bounds (hq<=64,hkv<=64)\n"); return 3; |
| 187 | call 0 returned 3 |
| 188 | -: 81: } |
| 189 | -: 82: } |
| 190 | -: 83: |
| 191 | -: 84: OmegaNativeArtifact a; |
| 192 | 77: 85: memset(&a, 0, sizeof a); |
| 193 | -: 86: OmegaBlackwellKernel kern; |
| 194 | 77: 87: memset(&kern, 0, sizeof kern); |
| 195 | -: 88: uint32_t q0[OMEGA_ARTIFACT_QMD_WORDS], q1[OMEGA_ARTIFACT_QMD_WORDS]; |
| 196 | -: 89: uint32_t cbank[32]; |
| 197 | -: 90: OmegaCubinParam params[16]; |
| 198 | 77: 91: size_t nparams = 0; |
| 199 | 77: 92: char spec_hex[65], *spec_hexp = spec_hex; |
| 200 | 77: 93: memset(q0, 0, sizeof q0); memset(q1, 0, sizeof q1); memset(cbank, 0, sizeof cbank); |
| 201 | -: 94: OmegaBlackwellQmdConfig cfg; |
| 202 | 77: 95: memset(&cfg, 0, sizeof cfg); |
| 203 | -: 96: |
| 204 | 77: 97: if (strcmp(mode, "matmul") == 0) { |
| 205 | branch 0 taken 51 (fallthrough) |
| 206 | branch 1 taken 26 |
| 207 | -: 98: OmegaMatMulSpec spec; |
| 208 | 51: 99: memset(&spec, 0, sizeof spec); |
| 209 | 59: 100: if (!m || !k || !n) { usage(); return 2; } |
| 210 | branch 0 taken 33 (fallthrough) |
| 211 | branch 1 taken 18 |
| 212 | branch 2 taken 32 (fallthrough) |
| 213 | branch 3 taken 1 |
| 214 | branch 4 taken 2 (fallthrough) |
| 215 | branch 5 taken 30 |
| 216 | call 6 returned 21 |
| 217 | -: 101: /* Both kernels below tile C in 16 x 8 blocks and step K by 16; they have no edge handling. */ |
| 218 | 30: 102: if (m % 16u || n % 8u || k % 16u) { |
| 219 | branch 0 taken 26 (fallthrough) |
| 220 | branch 1 taken 4 |
| 221 | branch 2 taken 24 (fallthrough) |
| 222 | branch 3 taken 2 |
| 223 | branch 4 taken 2 (fallthrough) |
| 224 | branch 5 taken 22 |
| 225 | 8: 103: fprintf(stderr, "matmul-bf16-v1 export needs m%%16 == 0, n%%8 == 0, k%%16 == 0 (got %ux%ux%u)\n", m, k, n); |
| 226 | call 0 returned 8 |
| 227 | 8: 104: return 3; |
| 228 | -: 105: } |
| 229 | 22*: 106: if (omega_matmul_spec_init(&spec, m, k, n, OMEGA_MATMUL_PRECISION_BF16) != 0) { fprintf(stderr, "spec refused\n"); return 3; } |
| 230 | call 0 returned 22 |
| 231 | branch 1 taken 0 (fallthrough) |
| 232 | branch 2 taken 22 |
| 233 | call 3 never executed |
| 234 | -: 107: /* K = 16: the single-tile kernel (the G2 W1 artifact, evidence/MAX-INTEROP/G2). Its CTA (x, y) computes |
| 235 | -: 108: * exactly the 16 x 8 tile at row 16y, column 8x and has no column loop, so grid_x must be n / 8; the |
| 236 | -: 109: * exporter used to write grid_x = 1, which leaves columns 8..n-1 of C unwritten whenever n > 8. |
| 237 | -: 110: * K > 16: the looped kernel (omega-mv 5e29b826, FB-1 cut 1b, chip parity 18/18), which accumulates the |
| 238 | -: 111: * whole K on the chip; its CTA (x, y) owns row tile y and column tiles x, x + grid_x, ... The single-tile |
| 239 | -: 112: * kernel refuses K != 16, so without the looped kernel every export above K = 16 inside the contract's |
| 240 | -: 113: * k <= 16384 was refused. Both read row-major A (m x k bf16) and B (k x n bf16) and write row-major |
| 241 | -: 114: * C (m x n f32) through the same three pointer words. The looped grid_x follows the matmul API's CTA |
| 242 | -: 115: * budget (launch_shape). */ |
| 243 | 22: 116: uint32_t gx = n / 8u; |
| 244 | 22: 117: if (k == 16u) { |
| 245 | branch 0 taken 15 (fallthrough) |
| 246 | branch 1 taken 7 |
| 247 | 15*: 118: if (omega_blackwell_codegen_matmul(&spec, &kern) != 0) { fprintf(stderr, "codegen refused\n"); return 3; } |
| 248 | call 0 returned 15 |
| 249 | branch 1 taken 0 (fallthrough) |
| 250 | branch 2 taken 15 |
| 251 | call 3 never executed |
| 252 | -: 119: } else { |
| 253 | 7: 120: uint32_t budget = OMEGA_GPU_MATMUL_MAX_CTAS / (m / 16u); |
| 254 | 7*: 121: if (budget == 0) budget = 1; |
| 255 | branch 0 taken 0 (fallthrough) |
| 256 | branch 1 taken 7 |
| 257 | 7: 122: if (gx > budget) gx = budget; |
| 258 | branch 0 taken 3 (fallthrough) |
| 259 | branch 1 taken 4 |
| 260 | 7*: 123: if (omega_blackwell_codegen_matmul_tensor_loop(&spec, gx, 0, &kern) != 0) { fprintf(stderr, "codegen refused\n"); return 3; } |
| 261 | call 0 returned 7 |
| 262 | branch 1 taken 0 (fallthrough) |
| 263 | branch 2 taken 7 |
| 264 | call 3 never executed |
| 265 | -: 124: } |
| 266 | 22: 125: hex32(spec.spec_id, spec_hex); |
| 267 | call 0 returned 22 |
| 268 | 22: 126: cfg.threads_per_block = 32; cfg.threads_x = 32; |
| 269 | 22: 127: cfg.grid_x = gx; cfg.grid_y = m / 16u; |
| 270 | 22: 128: cfg.num_elements = m * n; cfg.shared_bytes = 1024; |
| 271 | 22: 129: omega_blackwell_build_cbank_args_matmul(cbank, 0, 0, 0, m, k, n); |
| 272 | call 0 returned 22 |
| 273 | 22: 130: params[0] = (OmegaCubinParam){ 0x380, 8, 1 }; |
| 274 | 22: 131: params[1] = (OmegaCubinParam){ 0x388, 8, 1 }; |
| 275 | 22: 132: params[2] = (OmegaCubinParam){ 0x390, 8, 1 }; |
| 276 | 22: 133: nparams = 3; |
| 277 | 22: 134: a.op = "matmul"; a.contract_name = "matmul-bf16-v1"; |
| 278 | 22: 135: a.precision = "bf16"; a.accumulation = "fp32"; |
| 279 | 22: 136: a.tolerance = "abs<=1e-5*max(1,abs(ref))"; |
| 280 | 22: 137: a.grid_x = gx; a.grid_y = cfg.grid_y; a.block_x = 32; a.block_y = 1; a.block_z = 1; |
| 281 | 22: 138: a.shared_bytes = 1024; a.cbank_words = 10; |
| 282 | 26: 139: } else if (strcmp(mode, "attention") == 0) { |
| 283 | branch 0 taken 22 (fallthrough) |
| 284 | branch 1 taken 4 |
| 285 | 25: 140: if (!hq || !hkv || hq % hkv != 0) { usage(); return 2; } |
| 286 | branch 0 taken 20 (fallthrough) |
| 287 | branch 1 taken 2 |
| 288 | branch 2 taken 19 (fallthrough) |
| 289 | branch 3 taken 1 |
| 290 | branch 4 taken 1 (fallthrough) |
| 291 | branch 5 taken 18 |
| 292 | call 6 returned 4 |
| 293 | 18: 141: uint32_t ratio = hq / hkv, log2gqa = 0; |
| 294 | 55: 142: while ((1u << log2gqa) < ratio) log2gqa++; |
| 295 | branch 0 taken 37 |
| 296 | branch 1 taken 18 (fallthrough) |
| 297 | 18: 143: if ((1u << log2gqa) != ratio) { fprintf(stderr, "GQA ratio is not a power of two\n"); return 3; } |
| 298 | branch 0 taken 3 (fallthrough) |
| 299 | branch 1 taken 15 |
| 300 | call 2 returned 3 |
| 301 | 15: 144: int rc = omega_gpu_attention_codegen_hd(true, 12, log2gqa, 128, &kern); |
| 302 | call 0 returned 15 |
| 303 | 15*: 145: if (rc != 0) { fprintf(stderr, "attention codegen refused: %d\n", rc); return 3; } |
| 304 | branch 0 taken 0 (fallthrough) |
| 305 | branch 1 taken 15 |
| 306 | call 2 never executed |
| 307 | -: 146: { |
| 308 | -: 147: char specbuf[160]; |
| 309 | -: 148: uint8_t d[32]; |
| 310 | 15: 149: int n = snprintf(specbuf, sizeof specbuf, |
| 311 | -: 150: "omega-attention-spec/1\nhead_dim=128\nq_heads=%u\nkv_heads=%u\nlog2_gqa=%u\n", |
| 312 | -: 151: hq, hkv, log2gqa); |
| 313 | 15: 152: sha256_hash((const uint8_t *)specbuf, (size_t)n, d); |
| 314 | call 0 returned 15 |
| 315 | 495: 153: for (int i = 0; i < 32; i++) sprintf(spec_hex + 2 * i, "%02x", d[i]); |
| 316 | branch 0 taken 480 |
| 317 | branch 1 taken 15 (fallthrough) |
| 318 | 15: 154: spec_hex[64] = 0; |
| 319 | -: 155: } |
| 320 | -: 156: (void)spec_hexp; |
| 321 | 15: 157: uint32_t hpc = omega_gpu_attention_heads_per_cta(128, log2gqa); |
| 322 | call 0 returned 15 |
| 323 | 15: 158: uint32_t shared = (3u * hpc + 1u) * 128u * 4u; |
| 324 | 15: 159: cfg.threads_per_block = 128; cfg.threads_x = 128; |
| 325 | 15: 160: cfg.grid_x = hq / hpc; cfg.grid_y = 1; |
| 326 | 15: 161: cfg.num_elements = hq * 128u; cfg.shared_bytes = shared; |
| 327 | 15: 162: params[0] = (OmegaCubinParam){ 0x380, 8, 1 }; |
| 328 | 15: 163: params[1] = (OmegaCubinParam){ 0x388, 8, 1 }; |
| 329 | 15: 164: params[2] = (OmegaCubinParam){ 0x390, 8, 1 }; |
| 330 | 15: 165: params[3] = (OmegaCubinParam){ 0x398, 8, 1 }; |
| 331 | 135: 166: for (int i = 0; i < 8; i++) params[4 + i] = (OmegaCubinParam){ (uint32_t)(0x3a0 + 4 * i), 4, 0 }; |
| 332 | branch 0 taken 120 |
| 333 | branch 1 taken 15 (fallthrough) |
| 334 | 15: 167: nparams = 12; |
| 335 | 15: 168: a.op = "gqa-causal-attention"; a.contract_name = "gqa-causal-v1"; |
| 336 | 15: 169: a.precision = "f32-kv"; a.accumulation = "fp32"; |
| 337 | 15: 170: a.tolerance = "rel<=1e-3,abs<=1e-4"; |
| 338 | 15: 171: a.grid_x = cfg.grid_x; a.grid_y = 1; a.block_x = 128; a.block_y = 1; a.block_z = 1; |
| 339 | 15: 172: a.shared_bytes = shared; a.cbank_words = 16; |
| 340 | -: 173: /* Offline template: pointers and runtime strides are loader-supplied; |
| 341 | -: 174: * the query-head count is a contract constant, so bind it. */ |
| 342 | 15: 175: cbank[14] = hq; |
| 343 | -: 176: } else { |
| 344 | 4: 177: usage(); return 2; |
| 345 | call 0 returned 4 |
| 346 | -: 178: } |
| 347 | -: 179: /* Declare peak + 2 rounded up to 8, as every launcher does. A cubin whose REGCOUNT is the allocator |
| 348 | -: 180: * peak loads but faults at run (GB10, G2 window 20261030T235858Z-10fa8c: E5 at peak 32 gave 715, |
| 349 | -: 181: * H1/H2 at 40 and H4 at 34 ran bit-exact; evidence/MAX-INTEROP/G2). */ |
| 350 | 37: 182: cfg.gpr_count = omega_bw_gpr_declared(kern.gpr_count); |
| 351 | call 0 returned 37 |
| 352 | 37*: 183: if (!omega_bw_gpr_declared_ok(cfg.gpr_count, kern.gpr_count)) { fprintf(stderr, "declared registers refused\n"); return 3; } |
| 353 | call 0 returned 37 |
| 354 | branch 1 taken 0 (fallthrough) |
| 355 | branch 2 taken 37 |
| 356 | call 3 never executed |
| 357 | 37: 184: if (omega_blackwell_build_qmd0(q0, 0, 0) != 0 || omega_blackwell_build_qmd1(q1, &cfg) != 0) { |
| 358 | call 0 returned 37 |
| 359 | branch 1 taken 37 (fallthrough) |
| 360 | branch 2 taken 0 |
| 361 | call 3 returned 37 |
| 362 | branch 4 taken 0 (fallthrough) |
| 363 | branch 5 taken 37 |
| 364 | #####: 185: fprintf(stderr, "QMD template refused\n"); return 3; |
| 365 | call 0 never executed |
| 366 | -: 186: } |
| 367 | -: 187: static char shapebuf[128], boundsbuf[128]; |
| 368 | 37: 188: if (strcmp(mode, "matmul") == 0) { |
| 369 | branch 0 taken 22 (fallthrough) |
| 370 | branch 1 taken 15 |
| 371 | 22: 189: snprintf(shapebuf, sizeof shapebuf, "m=%u,k=%u,n=%u", m, k, n); |
| 372 | 22: 190: snprintf(boundsbuf, sizeof boundsbuf, "m<=8192,k<=16384,n<=8192"); |
| 373 | -: 191: } else { |
| 374 | 15: 192: snprintf(shapebuf, sizeof shapebuf, "r>=1,base=0,hq=%u,hkv=%u,hd=128", hq, hkv); |
| 375 | 15: 193: snprintf(boundsbuf, sizeof boundsbuf, "hq<=64,hkv<=64,hd=128,rows+base<=4096"); |
| 376 | -: 194: } |
| 377 | 37: 195: a.shape = shapebuf; |
| 378 | 37: 196: a.bounds = boundsbuf; |
| 379 | 37: 197: a.contract_id_hex = contract; |
| 380 | 37: 198: a.semantic_spec_id_hex = spec_hex; |
| 381 | 37: 199: a.kernel_function = (strcmp(mode, "matmul") == 0) ? "omega_matmul_bf16" : "omega_gqa_attention_causal"; |
| 382 | branch 0 taken 22 (fallthrough) |
| 383 | branch 1 taken 15 |
| 384 | 37: 200: a.text = kern.code; a.text_len = kern.code_size; |
| 385 | 37: 201: a.params = params; a.nparams = nparams; |
| 386 | 37: 202: a.gpr_count = cfg.gpr_count; |
| 387 | 37: 203: a.cbank_offset = 0x380; |
| 388 | 37: 204: a.cbank_args = cbank; |
| 389 | 37: 205: a.qmd0 = q0; a.qmd1 = q1; |
| 390 | 37: 206: a.min_driver = "580.173.02"; |
| 391 | 37: 207: a.requires = "sm_121,nvidia-cubin-abi-v8"; |
| 392 | 37: 208: a.source_commit = commit; |
| 393 | 37: 209: a.tool_version = "cudapp-artifact-export/1"; |
| 394 | 37: 210: a.qualification = "offline-disassembly=PASS;device-load=NOT_RUN;device-exec=NOT_RUN"; |
| 395 | -: 211: |
| 396 | -: 212: char id[OMEGA_ARTIFACT_ID_MAX], err[256]; |
| 397 | 37: 213: int rc = omega_native_artifact_export(&a, out, id, err, sizeof err); |
| 398 | call 0 returned 37 |
| 399 | 37: 214: if (rc != OMEGA_ARTIFACT_OK) { |
| 400 | branch 0 taken 5 (fallthrough) |
| 401 | branch 1 taken 32 |
| 402 | 5: 215: fprintf(stderr, "artifact-export refused: %s: %s\n", omega_native_artifact_rc_name(rc), err); |
| 403 | call 0 returned 5 |
| 404 | call 1 returned 5 |
| 405 | 5: 216: omega_blackwell_kernel_free(&kern); |
| 406 | call 0 returned 5 |
| 407 | 5: 217: return 3; |
| 408 | -: 218: } |
| 409 | 32: 219: printf("artifact_id=%s\nop=%s\ncontract_id=%s\ncubin=%s.cubin\n", id, a.op, contract, out); |
| 410 | call 0 returned 32 |
| 411 | 32: 220: omega_blackwell_kernel_free(&kern); |
| 412 | call 0 returned 32 |
| 413 | 32: 221: return 0; |
| 414 | -: 222:} |
| 415 | -: 223:#else |
| 416 | -: 224:/* Reading the command line, every check against the frozen v1 contracts, the kernel choice and its |
| 417 | -: 225: * grid, the launch configuration and parameter table, the attention semantic-spec text, the manifest |
| 418 | -: 226: * texts, every message and the exit status are om/tools/artexp.om. This shell calls the library when |
| 419 | -: 227: * the unit asks and writes the unit's text. The former C above keeps its line numbers. */ |
| 420 | -: 228:#include "cudapp_native.h" |
| 421 | -: 229: |
| 422 | -: 230:static uint8_t tok[262144], txt[262144]; |
| 423 | -: 231: |
| 424 | -: 232:int main(int argc, char **argv) { |
| 425 | -: 233: const uint64_t f[8] = { OMEGA_GPU_MATMUL_MAX_CTAS, OMEGA_ARTIFACT_OK }; |
| 426 | -: 234: uint64_t s[128]; |
| 427 | -: 235: OmegaMatMulSpec spec; |
| 428 | -: 236: OmegaBlackwellKernel kern; |
| 429 | -: 237: OmegaBlackwellQmdConfig cfg; |
| 430 | -: 238: OmegaNativeArtifact a; |
| 431 | -: 239: uint32_t q0[OMEGA_ARTIFACT_QMD_WORDS], q1[OMEGA_ARTIFACT_QMD_WORDS], cbank[32]; |
| 432 | -: 240: OmegaCubinParam params[16]; |
| 433 | -: 241: memset(s, 0, sizeof s); memset(&spec, 0, sizeof spec); memset(&kern, 0, sizeof kern); |
| 434 | -: 242: memset(&cfg, 0, sizeof cfg); memset(&a, 0, sizeof a); |
| 435 | -: 243: memset(q0, 0, sizeof q0); memset(q1, 0, sizeof q1); memset(cbank, 0, sizeof cbank); |
| 436 | -: 244: memset(params, 0, sizeof params); |
| 437 | -: 245: s[3] = (uint64_t)argc; |
| 438 | -: 246: for (;;) { |
| 439 | -: 247: uint64_t act = 0; |
| 440 | -: 248: if (omega_artexp(&act, f, 8, s, 128, tok, sizeof tok, txt, sizeof txt) != 0) abort(); |
| 441 | -: 249: switch (act & 255) { |
| 442 | -: 250: case 1: { |
| 443 | -: 251: /* Linux caps one argument at MAX_ARG_STRLEN (131072 bytes with its NUL), well inside tok. */ |
| 444 | -: 252: const char *arg = argv[s[1]]; |
| 445 | -: 253: size_t n = strnlen(arg, sizeof tok); |
| 446 | -: 254: if (n == sizeof tok) abort(); |
| 447 | -: 255: memcpy(tok, arg, n + 1); |
| 448 | -: 256: s[2] = n; |
| 449 | -: 257: break; |
| 450 | -: 258: } |
| 451 | -: 259: case 2: |
| 452 | -: 260: fwrite(txt, 1, (size_t)(act >> 8), stderr); |
| 453 | -: 261: omega_blackwell_kernel_free(&kern); |
| 454 | -: 262: return (int)s[25]; |
| 455 | -: 263: case 3: |
| 456 | -: 264: s[18] = (uint64_t)(int64_t)omega_matmul_spec_init(&spec, (uint32_t)s[13], (uint32_t)s[14], (uint32_t)s[15], |
| 457 | -: 265: OMEGA_MATMUL_PRECISION_BF16); |
| 458 | -: 266: break; |
| 459 | -: 267: case 4: s[18] = (uint64_t)(int64_t)omega_blackwell_codegen_matmul(&spec, &kern); break; |
| 460 | -: 268: case 5: |
| 461 | -: 269: s[18] = (uint64_t)(int64_t)omega_blackwell_codegen_matmul_tensor_loop(&spec, (uint32_t)s[19], 0, &kern); |
| 462 | -: 270: break; |
| 463 | -: 271: case 6: memcpy(tok, spec.spec_id, 32); break; |
| 464 | -: 272: case 7: |
| 465 | -: 273: omega_blackwell_build_cbank_args_matmul(cbank, 0, 0, 0, (uint32_t)s[13], (uint32_t)s[14], (uint32_t)s[15]); |
| 466 | -: 274: break; |
| 467 | -: 275: case 8: s[18] = (uint64_t)(int64_t)omega_gpu_attention_codegen_hd(true, 12, (uint32_t)s[20], 128, &kern); break; |
| 468 | -: 276: case 9: sha256_hash(txt, (size_t)(act >> 8), tok); break; |
| 469 | -: 277: case 10: s[21] = omega_gpu_attention_heads_per_cta(128, (uint32_t)s[20]); break; |
| 470 | -: 278: case 11: cbank[14] = (uint32_t)s[16]; break; |
| 471 | -: 279: case 12: |
| 472 | -: 280: s[22] = kern.gpr_count; |
| 473 | -: 281: s[23] = omega_bw_gpr_declared(kern.gpr_count); |
| 474 | -: 282: s[24] = omega_bw_gpr_declared_ok((uint32_t)s[23], kern.gpr_count) != 0; |
| 475 | -: 283: break; |
| 476 | -: 284: case 13: |
| 477 | -: 285: cfg.threads_per_block = (uint32_t)s[32]; cfg.threads_x = (uint32_t)s[33]; |
| 478 | -: 286: cfg.grid_x = (uint32_t)s[34]; cfg.grid_y = (uint32_t)s[35]; |
| 479 | -: 287: cfg.num_elements = (uint32_t)s[36]; cfg.shared_bytes = (uint32_t)s[37]; |
| 480 | -: 288: cfg.gpr_count = (uint32_t)s[38]; |
| 481 | -: 289: s[18] = omega_blackwell_build_qmd0(q0, 0, 0) != 0 || omega_blackwell_build_qmd1(q1, &cfg) != 0; |
| 482 | -: 290: break; |
| 483 | -: 291: case 14: { |
| 484 | -: 292: const char *v[13], *c = (const char *)txt; |
| 485 | -: 293: for (int i = 0; i < 13; i++) { v[i] = c; c += strlen(c) + 1; } |
| 486 | -: 294: a.op = v[0]; a.contract_name = v[1]; a.precision = v[2]; a.accumulation = v[3]; a.tolerance = v[4]; |
| 487 | -: 295: a.shape = v[5]; a.bounds = v[6]; a.semantic_spec_id_hex = v[7]; a.kernel_function = v[8]; |
| 488 | -: 296: a.min_driver = v[9]; a.requires = v[10]; a.tool_version = v[11]; a.qualification = v[12]; |
| 489 | -: 297: a.contract_id_hex = argv[s[7]]; |
| 490 | -: 298: a.source_commit = argv[s[10]]; |
| 491 | -: 299: for (uint64_t i = 0; i < s[47]; i++) { |
| 492 | -: 300: uint64_t w = s[64 + i]; |
| 493 | -: 301: params[i] = (OmegaCubinParam){ (uint32_t)(w & 0xffff), (uint32_t)((w >> 16) & 0xffff), (uint8_t)(w >> 32) }; |
| 494 | -: 302: } |
| 495 | -: 303: a.params = params; a.nparams = (size_t)s[47]; |
| 496 | -: 304: a.text = kern.code; a.text_len = kern.code_size; |
| 497 | -: 305: a.gpr_count = cfg.gpr_count; |
| 498 | -: 306: a.grid_x = (uint32_t)s[40]; a.grid_y = (uint32_t)s[41]; |
| 499 | -: 307: a.block_x = (uint32_t)s[42]; a.block_y = (uint32_t)s[43]; a.block_z = (uint32_t)s[44]; |
| 500 | -: 308: a.shared_bytes = (uint32_t)s[45]; |
| 501 | -: 309: a.cbank_offset = 0x380; |
| 502 | -: 310: a.cbank_args = cbank; a.cbank_words = (size_t)s[46]; |
| 503 | -: 311: a.qmd0 = q0; a.qmd1 = q1; |
| 504 | -: 312: char id[OMEGA_ARTIFACT_ID_MAX], err[256]; |
| 505 | -: 313: id[0] = 0; err[0] = 0; |
| 506 | -: 314: int rc = omega_native_artifact_export(&a, argv[s[6]], id, err, sizeof err); |
| 507 | -: 315: s[18] = (uint64_t)(int64_t)rc; |
| 508 | -: 316: const char *part[3] = { id, argv[s[7]], argv[s[6]] }; |
| 509 | -: 317: if (rc != OMEGA_ARTIFACT_OK) { part[0] = omega_native_artifact_rc_name(rc); part[1] = err; } |
| 510 | -: 318: size_t at = 0; |
| 511 | -: 319: for (int i = 0; i < 3; i++) { |
| 512 | -: 320: size_t n = strlen(part[i]); |
| 513 | -: 321: if (at + n + 1 > sizeof tok) abort(); |
| 514 | -: 322: memcpy(tok + at, part[i], n + 1); |
| 515 | -: 323: at += n + 1; |
| 516 | -: 324: } |
| 517 | -: 325: break; |
| 518 | -: 326: } |
| 519 | -: 327: case 15: |
| 520 | -: 328: fwrite(txt, 1, (size_t)(act >> 8), stdout); |
| 521 | -: 329: omega_blackwell_kernel_free(&kern); |
| 522 | -: 330: return 0; |
| 523 | -: 331: default: |
| 524 | -: 332: abort(); |
| 525 | -: 333: } |
| 526 | -: 334: } |
| 527 | -: 335:} |
| 528 | -: 336:#endif |