Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/evidence/tools-om-2/2026-11-06/coverage/own30b_decode_profile.c.gcov # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / evidence / tools-om-2 / 2026-11-06 / coverage / own30b_decode_profile.c.gcov` 280 lines · 14213 bytes Raw Blame History 1 -: 0:Source:own30b_decode_profile.c 2 -: 0:Graph:own30b_diff.gcno 3 -: 0:Data:own30b_diff.gcda 4 -: 0:Runs:6 5 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 6 -: 2:/* Link-only recorder for OWN-30B decode. No production launcher changes. 7 -: 3: * Link with -Wl,--wrap=omega_gpu_session_launch, this object and src/cudapp_om_own30b_prof.c. 8 -: 4: * Measures HOST times: elapsed_ns is submit-to-second-marker, NOT GPU cycles. 9 -: 5: * Only complete sequences of 48 x (qkv, attention, o, router, gu, down) + head 10 -: 6: * following a head are retained. Prefill, controls and partial steps are rejected. 11 -: 7: * No allocation or I/O in the measured path. Dump raw integer totals at exit. 12 -: 8: * 13 -: 9: * The classifier, the sequence check, the token table and the dump text are the seeded Omega unit 14 -: 10: * om/tools/own30b_prof.om (omega_own30b_prof). This file keeps the wrap: the clock, the real launch and the 15 -: 11: * stderr writes. -DCUDAPP_MIGRATION_PENDING_C_TOOLS_OWN30B builds the former C body, kept as the oracle. 16 -: 12: */ 17 -: 13:#include "omega_gpu_session.h" 18 -: 14:#include "omega_blackwell_codegen_moe.h" 19 -: 15:#include "omega_blackwell_codegen_attn.h" 20 -: 16:#include "omega_blackwell_codegen_router.h" 21 -: 17:#include "omega_blackwell_codegen_bf16.h" 22 -: 18:#include 23 -: 19:#include 24 -: 20:#include 25 -: 21: 26 -: 22:enum { QKV, ATTN, O, ROUTER, GU, DOWN, HEAD, OTHER, STAGES = OTHER }; 27 -: 23:__attribute__((unused)) static const char *names[STAGES] = { "qkv", "attention", "o", "router", "gate_up", "down", "lm_head" }; 28 -: 24: 29 -: 25:#ifdef CUDAPP_MIGRATION_PENDING_C_TOOLS_OWN30B 30 -: 26:typedef struct { uint64_t calls, bytes, session_ns, submit_wait_ns, gap_before_ns; } Row; 31 -: 27:typedef struct { Row stage[STAGES]; uint64_t end_ns, start_ns; uint32_t pos; } Token; 32 -: 28:static Token pending, tokens[4096]; 33 -: 29:static size_t used, dropped; 34 -: 30:static int armed, invalid; 35 -: 31:static uint64_t last_end; 36 -: 32: 37 function classify called `2728850` returned 100% blocks executed 100% 38 `2728850`: 33:static int classify(const OmegaGpuLaunch *l, uint64_t *bytes) { 39 `2728850`: 34: *bytes = 0; 40 `2728850`: 35: if (!l || !l->args) return OTHER; 41 branch 0 taken `2727361` (fallthrough) 42 branch 1 taken 1489 43 branch 2 taken 114 (fallthrough) 44 branch 3 taken `2727247` 45 `2727247`: 36: if (l->n_args == OMEGA_FP8_ARGS_WORDS) { 46 branch 0 taken `1809704` (fallthrough) 47 branch 1 taken 917543 48 `1809704`: 37: uint32_t n = l->args[8] / 4u, g = l->grid_y, k; 49 -: 38: int s; 50 `1809704`: 39: if (g == 1 && n == 5120) { s = QKV; k = 2048; } 51 branch 0 taken 904820 (fallthrough) 52 branch 1 taken 904884 53 branch 2 taken 452410 (fallthrough) 54 branch 3 taken 452410 55 `1357294`: 40: else if (g == 1 && n == 2048) { s = O; k = 4096; } 56 branch 0 taken 452410 (fallthrough) 57 branch 1 taken 904884 58 branch 2 taken 452402 (fallthrough) 59 branch 3 taken 8 60 904892: 41: else if (g == 8 && n == 1536) { s = GU; k = 2048; } 61 branch 0 taken 904770 (fallthrough) 62 branch 1 taken 122 63 branch 2 taken 452400 (fallthrough) 64 branch 3 taken 452370 65 452492: 42: else if (g == 8 && n == 2048) { s = DOWN; k = 768; } 66 branch 0 taken 452370 (fallthrough) 67 branch 1 taken 122 68 branch 2 taken 452360 (fallthrough) 69 branch 3 taken 10 70 132: 43: else return OTHER; 71 `1809572`: 44: *bytes = (uint64_t)g * n * k; 72 `1809572`: 45: return s; 73 -: 46: } 74 917543: 47: if (l->n_args == OMEGA_DATTN_ARGS_WORDS && l->num_elements == 4096) { 75 branch 0 taken 452563 (fallthrough) 76 branch 1 taken 464980 77 branch 2 taken 452430 (fallthrough) 78 branch 3 taken 133 79 452430: 48: *bytes = 2ull * 4 * ((uint64_t)l->args[18] + 1) * 256; 80 452430: 49: return ATTN; 81 -: 50: } 82 465113: 51: if (l->n_args == OMEGA_ROUTER_ARGS_WORDS && l->num_elements == 2048) { 83 branch 0 taken 452558 (fallthrough) 84 branch 1 taken 12555 85 branch 2 taken 452417 (fallthrough) 86 branch 3 taken 141 87 452417: 52: *bytes = 128ull * 2048 * 2; 88 452417: 53: return ROUTER; 89 -: 54: } 90 12696: 55: if (l->n_args == OMEGA_BF16_ARGS_WORDS && l->num_elements == 151936) { 91 branch 0 taken 9737 (fallthrough) 92 branch 1 taken 2959 93 branch 2 taken 9624 (fallthrough) 94 branch 3 taken 113 95 9624: 56: *bytes = 151936ull * 2048 * 2; 96 9624: 57: return HEAD; 97 -: 58: } 98 3072: 59: return OTHER; 99 -: 60:} 100 -: 61: 101 function record called `2728850` returned 100% blocks executed 100% 102 `2728850`: 62:static void record(int s, uint64_t bytes, uint64_t begin, uint64_t end, uint64_t elapsed, int rc) { 103 `2728850`: 63: if (armed) { 104 branch 0 taken `2728164` (fallthrough) 105 branch 1 taken 686 106 `2728164`: 64: int expected = pending.pos < 288 ? (int)(pending.pos % 6) : HEAD; 107 branch 0 taken `2719395` (fallthrough) 108 branch 1 taken 8769 109 `2728164`: 65: if (rc || s != expected || pending.pos > 288) invalid = 1; 110 branch 0 taken `2726754` (fallthrough) 111 branch 1 taken 1410 112 branch 2 taken `2476240` (fallthrough) 113 branch 3 taken 250514 114 branch 4 taken 0 (fallthrough) 115 branch 5 taken `2476240` 116 `2728164`: 66: if (!invalid) { 117 branch 0 taken `2428378` (fallthrough) 118 branch 1 taken 299786 119 `2428378`: 67: Row *r = &pending.stage[s]; 120 `2428378`: 68: r->calls++; 121 `2428378`: 69: r->bytes += bytes; 122 `2428378`: 70: r->session_ns += end - begin; 123 `2428378`: 71: r->submit_wait_ns += elapsed; 124 `2428378`: 72: r->gap_before_ns += begin - last_end; 125 `2428378`: 73: pending.pos++; 126 -: 74: } 127 -: 75: } 128 `2728850`: 76: if (s == HEAD) { 129 branch 0 taken 9624 (fallthrough) 130 branch 1 taken `2719226` 131 9624: 77: if (armed && !invalid && pending.pos == 289) { 132 branch 0 taken 9615 (fallthrough) 133 branch 1 taken 9 134 branch 2 taken 7899 (fallthrough) 135 branch 3 taken 1716 136 branch 4 taken 7899 (fallthrough) 137 branch 5 taken 0 138 7899: 78: pending.end_ns = end; 139 7899: 79: if (used < sizeof tokens / sizeof tokens[0]) tokens[used++] = pending; 140 branch 0 taken 7795 (fallthrough) 141 branch 1 taken 104 142 104: 80: else dropped++; 143 -: 81: } 144 9624: 82: memset(&pending, 0, sizeof pending); 145 9624: 83: pending.start_ns = end; 146 9624: 84: armed = !rc; 147 9624: 85: invalid = 0; 148 -: 86: } 149 `2728850`: 87: last_end = end; 150 `2728850`: 88:} 151 -: 89: 152 -: 90:#ifndef OWN30B_PROFILE_TEST 153 function dump called 6 returned 100% blocks executed 100% 154 6: 91:__attribute__((destructor)) static void dump(void) { 155 6: 92: fprintf(stderr, "DECODE_PROFILE semantics=host_session_and_submit_wait weight_bytes_exclude_scales pure_gpu_time=UNKNOWN tokens=%zu dropped=%zu\n", used, dropped); 156 call 0 returned 6 157 7801: 93: for (size_t t = 0; t < used; ++t) { 158 branch 0 taken 7795 159 branch 1 taken 6 (fallthrough) 160 7795: 94: fprintf(stderr, "DECODE_TOKEN token=%zu wall_ns=%" PRIu64 " launches=%u\n", t, tokens[t].end_ns - tokens[t].start_ns, tokens[t].pos); 161 call 0 returned 7795 162 62360: 95: for (int s = 0; s < STAGES; ++s) { 163 branch 0 taken 54565 164 branch 1 taken 7795 (fallthrough) 165 54565: 96: Row *r = &tokens[t].stage[s]; 166 54565: 97: fprintf(stderr, "DECODE_STAGE token=%zu stage=%s calls=%" PRIu64 " bytes=%" PRIu64 " session_ns=%" PRIu64 " submit_wait_ns=%" PRIu64 " gap_before_ns=%" PRIu64 "\n", 167 call 0 returned 54565 168 -: 98: t, names[s], r->calls, r->bytes, r->session_ns, r->submit_wait_ns, r->gap_before_ns); 169 -: 99: } 170 -: 100: } 171 6: 101:} 172 -: 102:#endif 173 -: 103: 174 -: 104:/* Test accessors: retained tokens, and word w of token t in the Omega layout (5 s + f, 35 end, 36 start, 37 pos). */ 175 function prof_used called 6 returned 100% blocks executed 100% 176 6: 105:__attribute__((unused)) static uint64_t prof_used(void) { return used; } 177 function prof_tok called 0 returned 0% blocks executed 0% 178 #####: 106:__attribute__((unused)) static uint64_t prof_tok(size_t t, unsigned w) { 179 #####: 107: const Token *k = &tokens[t]; 180 #####: 108: if (w < 35) { 181 branch 0 never executed (fallthrough) 182 branch 1 never executed 183 #####: 109: const Row *r = &k->stage[w / 5]; 184 #####: 110: const uint64_t f[5] = { r->calls, r->bytes, r->session_ns, r->submit_wait_ns, r->gap_before_ns }; 185 #####: 111: return f[w % 5]; 186 -: 112: } 187 #####: 113: return w == 35 ? k->end_ns : w == 36 ? k->start_ns : k->pos; 188 branch 0 never executed (fallthrough) 189 branch 1 never executed 190 branch 2 never executed (fallthrough) 191 branch 3 never executed 192 -: 114:} 193 -: 115:#else 194 -: 116:#include "cudapp_native.h" 195 -: 117:#include 196 -: 118: 197 -: 119:/* Omega state: see om/tools/own30b_prof.om. 64 header words plus 4096 tokens of 38 words. */ 198 -: 120:enum { OW_STATE = 155712, OW_TOK0 = 64, OW_TOKW = 38, OW_OUT = 2048 }; 199 -: 121:static uint64_t ow_state[OW_STATE]; 200 -: 122:static uint8_t ow_out[OW_OUT]; 201 -: 123: 202 -: 124:static uint64_t ow_call(uint64_t op, const uint64_t a[16]) { 203 -: 125: uint64_t r = 0; 204 -: 126: if (omega_own30b_prof(&r, op, ow_state, OW_STATE, a, 16, ow_out, OW_OUT)) { 205 -: 127: fputs("own30b_decode_profile: omega_own30b_prof trapped\n", stderr); 206 -: 128: abort(); 207 -: 129: } 208 -: 130: return r; 209 -: 131:} 210 -: 132: 211 -: 133:static int classify(const OmegaGpuLaunch *l, uint64_t *bytes) { 212 -: 134: int has = l && l->args; 213 -: 135: uint64_t a[16] = { (uint64_t)has, has ? l->n_args : 0, has && l->n_args > 8 ? l->args[8] : 0, has ? l->grid_y : 0, 214 -: 136: has ? l->num_elements : 0, has && l->n_args > 18 ? l->args[18] : 0, OMEGA_FP8_ARGS_WORDS, 215 -: 137: OMEGA_DATTN_ARGS_WORDS, OMEGA_ROUTER_ARGS_WORDS, OMEGA_BF16_ARGS_WORDS }; 216 -: 138: int s = (int)ow_call(0, a); 217 -: 139: *bytes = ow_state[5]; 218 -: 140: return s; 219 -: 141:} 220 -: 142: 221 -: 143:static void record(int s, uint64_t bytes, uint64_t begin, uint64_t end, uint64_t elapsed, int rc) { 222 -: 144: const uint64_t a[16] = { (uint64_t)s, bytes, begin, end, elapsed, rc != 0 }; 223 -: 145: ow_call(1, a); 224 -: 146:} 225 -: 147: 226 -: 148:#ifndef OWN30B_PROFILE_TEST 227 -: 149:__attribute__((destructor)) static void dump(void) { 228 -: 150: uint64_t a[16] = { 0 }; 229 -: 151: fwrite(ow_out, 1, ow_call(2, a), stderr); 230 -: 152: for (uint64_t t = 0; t < ow_state[0]; ++t) { 231 -: 153: a[0] = t; 232 -: 154: fwrite(ow_out, 1, ow_call(3, a), stderr); 233 -: 155: } 234 -: 156:} 235 -: 157:#endif 236 -: 158: 237 -: 159:__attribute__((unused)) static uint64_t prof_used(void) { return ow_state[0]; } 238 -: 160:__attribute__((unused)) static uint64_t prof_tok(size_t t, unsigned w) { return ow_state[OW_TOK0 + t * OW_TOKW + w]; } 239 -: 161:#endif 240 -: 162: 241 -: 163:#if !defined(OWN30B_PROFILE_TEST) && !defined(OWN30B_PROFILE_DIFF) 242 -: 164:int __real_omega_gpu_session_launch(const OmegaGpuLaunch *, uint64_t *, uint32_t *); 243 -: 165:int __wrap_omega_gpu_session_launch(const OmegaGpuLaunch *l, uint64_t *elapsed, uint32_t *marker) { 244 -: 166: uint64_t bytes, local_elapsed = 0; 245 -: 167: int s = classify(l, &bytes); 246 -: 168: uint64_t begin = omega_gpu_session_now_ns(); 247 -: 169: int rc = __real_omega_gpu_session_launch(l, &local_elapsed, marker); 248 -: 170: uint64_t end = omega_gpu_session_now_ns(); 249 -: 171: if (elapsed) *elapsed = local_elapsed; 250 -: 172: record(s, bytes, begin, end, local_elapsed, rc); 251 -: 173: return rc; 252 -: 174:} 253 -: 175:#endif 254 -: 176: 255 -: 177:#ifdef OWN30B_PROFILE_TEST 256 -: 178:#include 257 -: 179:int main(void) { 258 -: 180: uint32_t args[32] = {0}; 259 -: 181: OmegaGpuLaunch l = { .args = args, .n_args = OMEGA_FP8_ARGS_WORDS, .grid_y = 8 }; 260 -: 182: uint64_t bytes; 261 -: 183: args[8] = 2048 * 4; 262 -: 184: assert(classify(&l, &bytes) == DOWN && bytes == 8ull * 2048 * 768); 263 -: 185: l.grid_y = 7; 264 -: 186: assert(classify(&l, &bytes) == OTHER); 265 -: 187: record(HEAD, 0, 0, 1, 1, 0); 266 -: 188: for (unsigned i = 0; i < 289; i++) record(i < 288 ? i % 6 : HEAD, 10, 2 + i * 3, 4 + i * 3, 1, 0); 267 -: 189: assert(prof_used() == 1 && prof_tok(0, 37) == 289); 268 -: 190: uint64_t sum = 0; 269 -: 191: for (unsigned s = 0; s < STAGES; s++) sum += prof_tok(0, 5 * s + 2) + prof_tok(0, 5 * s + 4); 270 -: 192: assert(sum == prof_tok(0, 35) - prof_tok(0, 36)); 271 -: 193: /* Swapped/missing/failed stages must never become a decode timing. */ 272 -: 194: record(O, 0, 1000, 1001, 1, 0); 273 -: 195: record(HEAD, 0, 1002, 1003, 1, 0); 274 -: 196: assert(prof_used() == 1); 275 -: 197: record(QKV, 0, 1004, 1005, 1, -1); 276 -: 198: record(HEAD, 0, 1006, 1007, 1, 0); 277 -: 199: assert(prof_used() == 1); 278 -: 200: printf("PROFILE_HOST_PASS sequence, accounting, malformed shape, missing stage, failed launch; %s\n", names[HEAD]); 279 -: 201:} 280 -: 202:#endif