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 / bw-matmul-realize-om / 2026-11-06 / repeat-om_bw_matmul_oracle.c.gcov
| 1 | -: 0:Source:/home/drakestapleton/work/cudastack/lanes/BwMatmulRealize/tests/om_bw_matmul_oracle.c |
| 2 | -: 1:#if defined(CUDAPP_MIGRATION_PENDING_BW_MATMUL) && CUDAPP_MIGRATION_PENDING_BW_MATMUL |
| 3 | -: 2:/* Frozen b774723 independent verification oracle; never production linked. */ |
| 4 | -: 3:#define omega_matmul_spec_init oracle_omega_matmul_spec_init |
| 5 | -: 4:#define omega_matmul_cpu_oracle_i32 oracle_omega_matmul_cpu_oracle_i32 |
| 6 | -: 5:#define omega_matmul_cpu_oracle_f16 oracle_omega_matmul_cpu_oracle_f16 |
| 7 | -: 6:#define omega_matmul_cpu_oracle_bf16 oracle_omega_matmul_cpu_oracle_bf16 |
| 8 | -: 7:#define omega_fp16_to_fp32 oracle_omega_fp16_to_fp32 |
| 9 | -: 8:#define omega_bf16_to_fp32 oracle_omega_bf16_to_fp32 |
| 10 | -: 9:#define omega_fp32_to_fp16 oracle_omega_fp32_to_fp16 |
| 11 | -: 10:#define omega_fp32_to_bf16 oracle_omega_fp32_to_bf16 |
| 12 | -: 11:#define omega_blackwell_kernel_free oracle_omega_blackwell_kernel_free |
| 13 | -: 12:#define omega_blackwell_bind_matmul_realization oracle_omega_blackwell_bind_matmul_realization |
| 14 | -: 13:#define omega_blackwell_codegen_matmul oracle_omega_blackwell_codegen_matmul |
| 15 | -: 14:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 16 | -: 15:#include "omega_blackwell_matmul.h" |
| 17 | -: 16:#include "sha256.h" |
| 18 | -: 17:#ifndef OMEGA_GPU_NO_POSIX |
| 19 | -: 18:#include <stdlib.h> |
| 20 | -: 19:#endif |
| 21 | -: 20:#include <string.h> |
| 22 | -: 21:#ifdef OMEGA_GPU_NO_POSIX |
| 23 | -: 22:#include "cudapp_native.h" |
| 24 | -: 23:#endif |
| 25 | -: 24: |
| 26 | function oracle_omega_matmul_spec_init called 1001 returned 100% blocks executed 100% |
| 27 | 1001: 25:int omega_matmul_spec_init(OmegaMatMulSpec *spec, uint32_t m, uint32_t k, uint32_t n, OmegaMatMulPrecision precision) { |
| 28 | 1001: 26: if (!spec || m == 0 || k == 0 || n == 0) return -1; |
| 29 | branch 0 taken 1000 (fallthrough) |
| 30 | branch 1 taken 1 |
| 31 | branch 2 taken 900 (fallthrough) |
| 32 | branch 3 taken 100 |
| 33 | branch 4 taken 810 (fallthrough) |
| 34 | branch 5 taken 90 |
| 35 | branch 6 taken 81 (fallthrough) |
| 36 | branch 7 taken 729 |
| 37 | 729: 27: if (m > OMEGA_BW_MATMUL_MAX_M || k > OMEGA_BW_MATMUL_MAX_K || n > OMEGA_BW_MATMUL_MAX_N) return -1; |
| 38 | branch 0 taken 243 (fallthrough) |
| 39 | branch 1 taken 486 |
| 40 | branch 2 taken 135 (fallthrough) |
| 41 | branch 3 taken 108 |
| 42 | branch 4 taken 30 (fallthrough) |
| 43 | branch 5 taken 105 |
| 44 | -: 28: |
| 45 | 105: 29: spec->m = m; |
| 46 | 105: 30: spec->k = k; |
| 47 | 105: 31: spec->n = n; |
| 48 | 105: 32: spec->precision = precision; |
| 49 | -: 33: |
| 50 | -: 34: /* Canonical spec_id computed over (m, k, n, precision) */ |
| 51 | -: 35: uint8_t spec_buf[16]; |
| 52 | 105: 36: spec_buf[0] = (uint8_t)(m & 0xff); |
| 53 | 105: 37: spec_buf[1] = (uint8_t)((m >> 8) & 0xff); |
| 54 | 105: 38: spec_buf[2] = (uint8_t)((m >> 16) & 0xff); |
| 55 | 105: 39: spec_buf[3] = (uint8_t)((m >> 24) & 0xff); |
| 56 | -: 40: |
| 57 | 105: 41: spec_buf[4] = (uint8_t)(k & 0xff); |
| 58 | 105: 42: spec_buf[5] = (uint8_t)((k >> 8) & 0xff); |
| 59 | 105: 43: spec_buf[6] = (uint8_t)((k >> 16) & 0xff); |
| 60 | 105: 44: spec_buf[7] = (uint8_t)((k >> 24) & 0xff); |
| 61 | -: 45: |
| 62 | 105: 46: spec_buf[8] = (uint8_t)(n & 0xff); |
| 63 | 105: 47: spec_buf[9] = (uint8_t)((n >> 8) & 0xff); |
| 64 | 105: 48: spec_buf[10] = (uint8_t)((n >> 16) & 0xff); |
| 65 | 105: 49: spec_buf[11] = (uint8_t)((n >> 24) & 0xff); |
| 66 | -: 50: |
| 67 | 105: 51: spec_buf[12] = (uint8_t)(precision & 0xff); |
| 68 | 105: 52: spec_buf[13] = 0; |
| 69 | 105: 53: spec_buf[14] = 0; |
| 70 | 105: 54: spec_buf[15] = 0; |
| 71 | -: 55: |
| 72 | 105: 56: sha256_hash(spec_buf, sizeof(spec_buf), spec->spec_id); |
| 73 | call 0 returned 105 |
| 74 | 105: 57: return 0; |
| 75 | -: 58:} |
| 76 | -: 59: |
| 77 | function oracle_omega_matmul_cpu_oracle_i32 called 108 returned 100% blocks executed 100% |
| 78 | 108: 60:int omega_matmul_cpu_oracle_i32(const uint32_t *a, const uint32_t *b, uint32_t *c, uint32_t m, uint32_t k, uint32_t n) { |
| 79 | 108: 61: if (!a || !b || !c || m == 0 || k == 0 || n == 0) return -1; |
| 80 | branch 0 taken 107 (fallthrough) |
| 81 | branch 1 taken 1 |
| 82 | branch 2 taken 106 (fallthrough) |
| 83 | branch 3 taken 1 |
| 84 | branch 4 taken 105 (fallthrough) |
| 85 | branch 5 taken 1 |
| 86 | branch 6 taken 104 (fallthrough) |
| 87 | branch 7 taken 1 |
| 88 | branch 8 taken 103 (fallthrough) |
| 89 | branch 9 taken 1 |
| 90 | branch 10 taken 1 (fallthrough) |
| 91 | branch 11 taken 102 |
| 92 | -: 62: |
| 93 | 666: 63: for (uint32_t i = 0; i < m; i++) { |
| 94 | branch 0 taken 564 |
| 95 | branch 1 taken 102 (fallthrough) |
| 96 | 3407: 64: for (uint32_t j = 0; j < n; j++) { |
| 97 | branch 0 taken 2843 |
| 98 | branch 1 taken 564 (fallthrough) |
| 99 | 2843: 65: uint32_t acc = 0; |
| 100 | 16228: 66: for (uint32_t p = 0; p < k; p++) { |
| 101 | branch 0 taken 13385 |
| 102 | branch 1 taken 2843 (fallthrough) |
| 103 | 13385: 67: acc += a[i * k + p] * b[p * n + j]; |
| 104 | -: 68: } |
| 105 | 2843: 69: c[i * n + j] = acc; |
| 106 | -: 70: } |
| 107 | -: 71: } |
| 108 | 102: 72: return 0; |
| 109 | -: 73:} |
| 110 | -: 74: |
| 111 | -: 75: |
| 112 | function oracle_omega_fp16_to_fp32 called 157842 returned 100% blocks executed 100% |
| 113 | 157842: 76:float omega_fp16_to_fp32(uint16_t h) { |
| 114 | 157842: 77: uint32_t sign = (uint32_t)(h & 0x8000) << 16; |
| 115 | 157842: 78: uint32_t exp = (uint32_t)(h & 0x7c00) >> 10; |
| 116 | 157842: 79: uint32_t mant = (uint32_t)(h & 0x03ff); |
| 117 | -: 80: uint32_t val; |
| 118 | 157842: 81: if (exp == 0) { |
| 119 | branch 0 taken 4957 (fallthrough) |
| 120 | branch 1 taken 152885 |
| 121 | 4957: 82: if (mant == 0) { |
| 122 | branch 0 taken 10 (fallthrough) |
| 123 | branch 1 taken 4947 |
| 124 | 10: 83: val = sign; |
| 125 | -: 84: } else { |
| 126 | 4947: 85: exp = 1; |
| 127 | 14797: 86: while ((mant & 0x0400) == 0) { |
| 128 | branch 0 taken 9850 |
| 129 | branch 1 taken 4947 (fallthrough) |
| 130 | 9850: 87: mant <<= 1; |
| 131 | 9850: 88: exp--; |
| 132 | -: 89: } |
| 133 | 4947: 90: mant &= 0x03ff; |
| 134 | 4947: 91: val = sign | ((exp + (127 - 15)) << 23) | (mant << 13); |
| 135 | -: 92: } |
| 136 | 152885: 93: } else if (exp == 31) { |
| 137 | branch 0 taken 4961 (fallthrough) |
| 138 | branch 1 taken 147924 |
| 139 | 4961: 94: val = sign | 0x7f800000 | (mant << 13); |
| 140 | -: 95: } else { |
| 141 | 147924: 96: val = sign | ((exp + (127 - 15)) << 23) | (mant << 13); |
| 142 | -: 97: } |
| 143 | -: 98: float f; |
| 144 | 157842: 99: memcpy(&f, &val, 4); |
| 145 | 157842: 100: return f; |
| 146 | -: 101:} |
| 147 | -: 102: |
| 148 | function oracle_omega_bf16_to_fp32 called 92306 returned 100% blocks executed 100% |
| 149 | 92306: 103:float omega_bf16_to_fp32(uint16_t b) { |
| 150 | 92306: 104: uint32_t val = (uint32_t)b << 16; |
| 151 | -: 105: float f; |
| 152 | 92306: 106: memcpy(&f, &val, 4); |
| 153 | 92306: 107: return f; |
| 154 | -: 108:} |
| 155 | -: 109: |
| 156 | function oracle_omega_fp32_to_fp16 called 165536 returned 100% blocks executed 100% |
| 157 | 165536: 110:uint16_t omega_fp32_to_fp16(float f) { |
| 158 | -: 111:#ifdef OMEGA_GPU_NO_POSIX |
| 159 | -: 112: /* The host cast can import libgcc __truncsfhf2 on x86. Keep the |
| 160 | -: 113: * freestanding conversion in checked, import-free Omega instead. */ |
| 161 | -: 114: uint32_t bits; |
| 162 | -: 115: uint64_t out; |
| 163 | -: 116: memcpy(&bits, &f, sizeof(bits)); |
| 164 | -: 117: if (omega_native_f16(&out, bits) != OMEGA_OK) __builtin_trap(); |
| 165 | -: 118: return (uint16_t)out; |
| 166 | -: 119:#else |
| 167 | 165536: 120: _Float16 h = (_Float16)f; |
| 168 | -: 121: uint16_t u; |
| 169 | 165536: 122: memcpy(&u, &h, 2); |
| 170 | 165536: 123: return u; |
| 171 | -: 124:#endif |
| 172 | -: 125:} |
| 173 | -: 126: |
| 174 | function oracle_omega_fp32_to_bf16 called 100000 returned 100% blocks executed 100% |
| 175 | 100000: 127:uint16_t omega_fp32_to_bf16(float f) { |
| 176 | -: 128:#ifndef OMEGA_GPU_NO_POSIX |
| 177 | 100000: 129: __bf16 b = (__bf16)f; |
| 178 | -: 130: uint16_t u; |
| 179 | 100000: 131: memcpy(&u, &b, 2); |
| 180 | 100000: 132: return u; |
| 181 | -: 133:#else |
| 182 | -: 134: /* Freestanding (cut A.2): the __bf16 cast calls libgcc __truncsfbf2. Same rounding in integer form |
| 183 | -: 135: * (omega_fp32_to_bf16_rne); the hosted cast and it agree on every one of the 2^32 inputs |
| 184 | -: 136: * (make test-codegen-freestanding, bf16 sweep). */ |
| 185 | -: 137: return omega_fp32_to_bf16_rne(f); |
| 186 | -: 138:#endif |
| 187 | -: 139:} |
| 188 | -: 140: |
| 189 | function oracle_omega_matmul_cpu_oracle_f16 called 108 returned 100% blocks executed 100% |
| 190 | 108: 141:int omega_matmul_cpu_oracle_f16(const uint16_t *a, const uint16_t *b, float *c, uint32_t m, uint32_t k, uint32_t n) { |
| 191 | 108: 142: if (!a || !b || !c || m == 0 || k == 0 || n == 0) return -1; |
| 192 | branch 0 taken 107 (fallthrough) |
| 193 | branch 1 taken 1 |
| 194 | branch 2 taken 106 (fallthrough) |
| 195 | branch 3 taken 1 |
| 196 | branch 4 taken 105 (fallthrough) |
| 197 | branch 5 taken 1 |
| 198 | branch 6 taken 104 (fallthrough) |
| 199 | branch 7 taken 1 |
| 200 | branch 8 taken 103 (fallthrough) |
| 201 | branch 9 taken 1 |
| 202 | branch 10 taken 1 (fallthrough) |
| 203 | branch 11 taken 102 |
| 204 | 666: 143: for (uint32_t i = 0; i < m; i++) { |
| 205 | branch 0 taken 564 |
| 206 | branch 1 taken 102 (fallthrough) |
| 207 | 3407: 144: for (uint32_t j = 0; j < n; j++) { |
| 208 | branch 0 taken 2843 |
| 209 | branch 1 taken 564 (fallthrough) |
| 210 | 2843: 145: float sum = 0.0f; |
| 211 | 16228: 146: for (uint32_t p = 0; p < k; p++) { |
| 212 | branch 0 taken 13385 |
| 213 | branch 1 taken 2843 (fallthrough) |
| 214 | 13385: 147: sum += omega_fp16_to_fp32(a[i * k + p]) * omega_fp16_to_fp32(b[p * n + j]); |
| 215 | call 0 returned 13385 |
| 216 | call 1 returned 13385 |
| 217 | -: 148: } |
| 218 | 2843: 149: c[i * n + j] = sum; |
| 219 | -: 150: } |
| 220 | -: 151: } |
| 221 | 102: 152: return 0; |
| 222 | -: 153:} |
| 223 | -: 154: |
| 224 | function oracle_omega_matmul_cpu_oracle_bf16 called 108 returned 100% blocks executed 100% |
| 225 | 108: 155:int omega_matmul_cpu_oracle_bf16(const uint16_t *a, const uint16_t *b, float *c, uint32_t m, uint32_t k, uint32_t n) { |
| 226 | 108: 156: if (!a || !b || !c || m == 0 || k == 0 || n == 0) return -1; |
| 227 | branch 0 taken 107 (fallthrough) |
| 228 | branch 1 taken 1 |
| 229 | branch 2 taken 106 (fallthrough) |
| 230 | branch 3 taken 1 |
| 231 | branch 4 taken 105 (fallthrough) |
| 232 | branch 5 taken 1 |
| 233 | branch 6 taken 104 (fallthrough) |
| 234 | branch 7 taken 1 |
| 235 | branch 8 taken 103 (fallthrough) |
| 236 | branch 9 taken 1 |
| 237 | branch 10 taken 1 (fallthrough) |
| 238 | branch 11 taken 102 |
| 239 | 666: 157: for (uint32_t i = 0; i < m; i++) { |
| 240 | branch 0 taken 564 |
| 241 | branch 1 taken 102 (fallthrough) |
| 242 | 3407: 158: for (uint32_t j = 0; j < n; j++) { |
| 243 | branch 0 taken 2843 |
| 244 | branch 1 taken 564 (fallthrough) |
| 245 | 2843: 159: float sum = 0.0f; |
| 246 | 16228: 160: for (uint32_t p = 0; p < k; p++) { |
| 247 | branch 0 taken 13385 |
| 248 | branch 1 taken 2843 (fallthrough) |
| 249 | 13385: 161: sum += omega_bf16_to_fp32(a[i * k + p]) * omega_bf16_to_fp32(b[p * n + j]); |
| 250 | call 0 returned 13385 |
| 251 | call 1 returned 13385 |
| 252 | -: 162: } |
| 253 | 2843: 163: c[i * n + j] = sum; |
| 254 | -: 164: } |
| 255 | -: 165: } |
| 256 | 102: 166: return 0; |
| 257 | -: 167:} |
| 258 | -: 168:#ifndef OMEGA_GPU_NO_POSIX /* frees what the hosted allocating generators malloc (omega_blackwell_codegen.h, cut A.2) */ |
| 259 | function oracle_omega_blackwell_kernel_free called 5 returned 100% blocks executed 100% |
| 260 | 5: 169:void omega_blackwell_kernel_free(OmegaBlackwellKernel *kernel) { |
| 261 | 5: 170: if (!kernel) return; |
| 262 | branch 0 taken 1 (fallthrough) |
| 263 | branch 1 taken 4 |
| 264 | 4: 171: if (kernel->code) { |
| 265 | branch 0 taken 1 (fallthrough) |
| 266 | branch 1 taken 3 |
| 267 | 1: 172: free(kernel->code); |
| 268 | 1: 173: kernel->code = NULL; |
| 269 | -: 174: } |
| 270 | 4: 175: kernel->code_size = 0; |
| 271 | 4: 176: kernel->insn_count = 0; |
| 272 | -: 177:} |
| 273 | -: 178:#endif |
| 274 | -: 179: |
| 275 | function oracle_omega_blackwell_bind_matmul_realization called 103 returned 100% blocks executed 100% |
| 276 | 103: 180:int omega_blackwell_bind_matmul_realization(const OmegaMatMulSpec *spec, const OmegaBlackwellKernel *kernel, OmegaBlackwellRealizationIdentity *id) { |
| 277 | 103: 181: if (!spec || !kernel || !id) return -1; |
| 278 | branch 0 taken 102 (fallthrough) |
| 279 | branch 1 taken 1 |
| 280 | branch 2 taken 101 (fallthrough) |
| 281 | branch 3 taken 1 |
| 282 | branch 4 taken 1 (fallthrough) |
| 283 | branch 5 taken 100 |
| 284 | -: 182: |
| 285 | 100: 183: memcpy(id->spec_id, spec->spec_id, 32); |
| 286 | -: 184: /* NVIDIA_DGX_SPARK_GB10_SM121 canonical machine descriptor digest */ |
| 287 | 100: 185: const char *machine_str = "NVIDIA_DGX_SPARK_GB10_SM121"; |
| 288 | 100: 186: sha256_hash((const uint8_t *)machine_str, strlen(machine_str), id->machine_id); |
| 289 | call 0 returned 100 |
| 290 | 100: 187: memcpy(id->code_digest, kernel->code_digest, 32); |
| 291 | 100: 188: id->sm_arch = 121; |
| 292 | -: 189: |
| 293 | -: 190: /* Realization ID = SHA-256(spec_id || machine_id || code_digest || sm_arch) */ |
| 294 | -: 191: uint8_t bound[100]; |
| 295 | 100: 192: memcpy(bound + 0, id->spec_id, 32); |
| 296 | 100: 193: memcpy(bound + 32, id->machine_id, 32); |
| 297 | 100: 194: memcpy(bound + 64, id->code_digest, 32); |
| 298 | 100: 195: bound[96] = (uint8_t)(id->sm_arch & 0xff); |
| 299 | 100: 196: bound[97] = (uint8_t)((id->sm_arch >> 8) & 0xff); |
| 300 | 100: 197: bound[98] = (uint8_t)((id->sm_arch >> 16) & 0xff); |
| 301 | 100: 198: bound[99] = (uint8_t)((id->sm_arch >> 24) & 0xff); |
| 302 | -: 199: |
| 303 | 100: 200: sha256_hash(bound, sizeof(bound), id->realization_id); |
| 304 | call 0 returned 100 |
| 305 | 100: 201: return 0; |
| 306 | -: 202:} |
| 307 | -: 203: |
| 308 | -: 204:#include "omega_blackwell_codegen.h" |
| 309 | -: 205: |
| 310 | -: 206:#ifndef OMEGA_GPU_NO_POSIX |
| 311 | function oracle_omega_blackwell_codegen_matmul called 6 returned 100% blocks executed 100% |
| 312 | 6: 207:int omega_blackwell_codegen_matmul(const OmegaMatMulSpec *spec, OmegaBlackwellKernel *kernel) { |
| 313 | 6: 208: if (!spec || !kernel) return -1; |
| 314 | branch 0 taken 5 (fallthrough) |
| 315 | branch 1 taken 1 |
| 316 | branch 2 taken 1 (fallthrough) |
| 317 | branch 3 taken 4 |
| 318 | 4: 209: if (spec->precision == OMEGA_MATMUL_PRECISION_INT32) { |
| 319 | branch 0 taken 1 (fallthrough) |
| 320 | branch 1 taken 3 |
| 321 | 1: 210: return omega_blackwell_codegen_matmul_i32(spec, kernel); |
| 322 | call 0 returned 1 |
| 323 | 3: 211: } else if (spec->precision == OMEGA_MATMUL_PRECISION_FP16 || spec->precision == OMEGA_MATMUL_PRECISION_BF16) { |
| 324 | branch 0 taken 2 (fallthrough) |
| 325 | branch 1 taken 1 |
| 326 | branch 2 taken 1 (fallthrough) |
| 327 | branch 3 taken 1 |
| 328 | 2: 212: return omega_blackwell_codegen_matmul_tensor(spec, kernel); |
| 329 | call 0 returned 2 |
| 330 | -: 213: } |
| 331 | 1: 214: return -1; |
| 332 | -: 215:} |
| 333 | -: 216:#endif |
| 334 | -: 217: |
| 335 | -: 218:#endif |