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 / evidence / FB1-CUT4B-0396844 / gpu_matmul_api_test.c
| 1 | /* gpu_matmul_api_test: FB-1 cut 1 / 1b gate for omega_gpu_matmul_api. |
| 2 | * |
| 3 | * ./gpu_matmul_api_test --host-only argument and limit refusals, codegen only, no chip |
| 4 | * ./gpu_matmul_api_test --out receipt.json chip sweep over shapes, JSON receipt |
| 5 | * ./gpu_matmul_api_test --timing --out r.json resident GEMV timing (median of 100 calls) + parity |
| 6 | * ./gpu_matmul_api_test --mutant --out r.json wrong kernel (last K step dropped) must FAIL parity; |
| 7 | * exit 0 when every shape caught it ("mutant killed") |
| 8 | * ./gpu_matmul_api_test --cta-budget N ... run with a different CTA budget (I42 experiment) |
| 9 | * |
| 10 | * Shapes come from OMEGA_GPU_MATMUL_SHAPES ("m,k,n;m,k,n;..."), default below. |
| 11 | * Pass rule per shape: rc OK, parity verified by the API oracle, end-to-end error < 1e-5 relative to |
| 12 | * the accumulation scale (bf16 inputs against a double reference; only accumulation order and the |
| 13 | * chip's f32 accumulator differ), second call hits the kernel cache and agrees bit for bit. |
| 14 | */ |
| 15 | #include "omega_gpu_matmul_api.h" |
| 16 | #include "omega_blackwell_codegen.h" |
| 17 | #include "omega_blackwell_matmul.h" |
| 18 | #include <inttypes.h> |
| 19 | #include <math.h> |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <time.h> |
| 24 | |
| 25 | /* round a float to bf16 and back, as the API does on the way in */ |
| 26 | static float bf16r(float f) { uint16_t h = omega_fp32_to_bf16(f); uint32_t u = (uint32_t)h << 16; float o; memcpy(&o, &u, 4); return o; } |
| 27 | |
| 28 | static int g_checks, g_failed; |
| 29 | #define CHECK(cond, ...) do { g_checks++; if (!(cond)) { g_failed++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0) |
| 30 | |
| 31 | /* cut-1 list unchanged, then the cut-1b Llama shapes (hidden 2048, ffn 8192, vocab 128256) */ |
| 32 | static const char *DEFAULT_SHAPES = |
| 33 | "16,16,16;32,32,32;64,64,64;128,128,128;256,256,256;512,512,512;" |
| 34 | "1,1024,1024;1,256,1024;16,1024,256;8,1024,8;" |
| 35 | "1024,16,128;192,16,192;512,16,64;256,16,256;128,16,512;" |
| 36 | "1,2048,8192;1,8192,2048;1,2048,128256"; |
| 37 | static const char *MUTANT_SHAPES = "16,32,16;1,2048,8192;64,64,64;1,1024,1024"; |
| 38 | static const char *TIMING_SHAPES = "1,2048,8192;1,8192,2048"; |
| 39 | |
| 40 | static uint32_t lcg(uint32_t *s) { *s = *s * 1664525u + 1013904223u; return *s; } |
| 41 | static double now_ms(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec * 1e3 + t.tv_nsec / 1e6; } |
| 42 | |
| 43 | static void fill(float *a, size_t n, uint32_t *seed) { for (size_t i = 0; i < n; i++) a[i] = ((float)(lcg(seed) % 2001) - 1000.0f) / 1000.0f; } |
| 44 | |
| 45 | /* end-to-end: full-K product on the host from the same bf16-rounded inputs, in double; error relative |
| 46 | * to the accumulation scale (sum of |terms|), not to a result that may cancel to near zero */ |
| 47 | static double e2e_max_rel(uint32_t m, uint32_t k, uint32_t n, const float *a, const float *b, const float *c, size_t *bad) { |
| 48 | double worst = 0.0; size_t nbad = 0; |
| 49 | for (size_t i = 0; i < m; i++) for (size_t j = 0; j < n; j++) { |
| 50 | double acc = 0.0, scale = 0.0; |
| 51 | for (size_t t = 0; t < k; t++) { double p = (double)bf16r(a[i * k + t]) * (double)bf16r(b[t * n + j]); acc += p; scale += fabs(p); } |
| 52 | double rel = fabs(acc - (double)c[i * n + j]) / (scale > 1e-6 ? scale : 1e-6); |
| 53 | if (rel > worst) worst = rel; |
| 54 | if (rel >= 1e-5) nbad++; |
| 55 | } |
| 56 | if (bad) *bad = nbad; |
| 57 | return worst; |
| 58 | } |
| 59 | |
| 60 | static void host_only(void) { |
| 61 | float a[16 * 16] = {0}, b[16 * 16] = {0}, c[16 * 16] = {0}; |
| 62 | OmegaGpuMatmulInfo info; |
| 63 | CHECK(omega_gpu_matmul_f32(0, 16, 16, a, b, c, &info) == OMEGA_GPU_MATMUL_BAD_ARGS, "m=0 refused"); |
| 64 | CHECK(omega_gpu_matmul_f32(16, 16, 16, NULL, b, c, &info) == OMEGA_GPU_MATMUL_BAD_ARGS, "NULL a refused"); |
| 65 | CHECK(omega_gpu_matmul_f32(OMEGA_BW_MATMUL_MAX_M + 1, 16, 16, a, b, c, &info) == OMEGA_GPU_MATMUL_TOO_LARGE, "m over limit refused"); |
| 66 | CHECK(omega_gpu_matmul_bf16(16, OMEGA_BW_MATMUL_MAX_K + 1, 16, (uint16_t *)a, (uint16_t *)b, c, NULL) == OMEGA_GPU_MATMUL_TOO_LARGE, "k over limit refused (NULL info ok)"); |
| 67 | CHECK(omega_gpu_matmul_bf16(16, 16, OMEGA_BW_MATMUL_MAX_N + 1, (uint16_t *)a, (uint16_t *)b, c, NULL) == OMEGA_GPU_MATMUL_TOO_LARGE, "n over limit refused"); |
| 68 | CHECK(OMEGA_BW_MATMUL_MAX_N >= 128256 && OMEGA_BW_MATMUL_MAX_K >= 8192 && OMEGA_BW_MATMUL_MAX_M >= 2048, "limits cover Llama shapes (vocab 128256, ffn 8192)"); |
| 69 | OmegaGpuTensor *t = NULL; |
| 70 | CHECK(omega_gpu_tensor_upload_f32(0, 16, a, &t) == OMEGA_GPU_MATMUL_BAD_ARGS && t == NULL, "tensor k=0 refused"); |
| 71 | CHECK(omega_gpu_tensor_upload_f32(16, 16, NULL, &t) == OMEGA_GPU_MATMUL_BAD_ARGS, "tensor NULL refused"); |
| 72 | CHECK(omega_gpu_matmul_resident_f32(16, a, NULL, c, &info) == OMEGA_GPU_MATMUL_BAD_ARGS, "resident NULL tensor refused"); |
| 73 | CHECK(strcmp(omega_gpu_matmul_rc_name(OMEGA_GPU_MATMUL_PARITY_FAIL), "PARITY_FAIL") == 0, "rc name"); |
| 74 | CHECK(omega_gpu_matmul_cta_budget() == OMEGA_GPU_MATMUL_MAX_CTAS, "default CTA budget"); |
| 75 | CHECK(omega_gpu_matmul_is_blocked() == 0, "not blocked at start"); |
| 76 | |
| 77 | /* codegen only: the looped kernel must accept every padded Llama shape without touching the chip */ |
| 78 | struct { uint32_t k, n, gx; } ok[] = { {16, 8, 1}, {2048, 8192, 64}, {8192, 2048, 64}, {2048, 128256, 64}, {1024, 1024, 1}, {16384, 262144, 64} }; |
| 79 | for (size_t i = 0; i < sizeof ok / sizeof ok[0]; i++) { |
| 80 | OmegaMatMulSpec spec; OmegaBlackwellKernel kernel; memset(&kernel, 0, sizeof kernel); |
| 81 | int rc = omega_matmul_spec_init(&spec, 16, ok[i].k, ok[i].n, OMEGA_MATMUL_PRECISION_BF16) == 0 && |
| 82 | omega_blackwell_codegen_matmul_tensor_loop(&spec, ok[i].gx, 0, &kernel) == 0 && kernel.code_size > 0; |
| 83 | CHECK(rc, "loop kernel K=%u N=%u gx=%u generated", ok[i].k, ok[i].n, ok[i].gx); |
| 84 | CHECK(kernel.gpr_count <= 64, "loop kernel K=%u N=%u fits 64 registers (got %u)", ok[i].k, ok[i].n, kernel.gpr_count); |
| 85 | /* the mutant kernel is a different program */ |
| 86 | OmegaBlackwellKernel mut; memset(&mut, 0, sizeof mut); |
| 87 | if (omega_blackwell_codegen_matmul_tensor_loop(&spec, ok[i].gx, 1, &mut) == 0) { |
| 88 | CHECK(memcmp(mut.code_digest, kernel.code_digest, 32) != 0, "mutant kernel differs K=%u N=%u", ok[i].k, ok[i].n); |
| 89 | omega_blackwell_kernel_free(&mut); |
| 90 | } else CHECK(ok[i].k == 16, "mutant refused only for K=16 (K=%u)", ok[i].k); |
| 91 | omega_blackwell_kernel_free(&kernel); |
| 92 | } |
| 93 | OmegaMatMulSpec spec; OmegaBlackwellKernel kernel; memset(&kernel, 0, sizeof kernel); |
| 94 | CHECK(omega_matmul_spec_init(&spec, 16, 24, 16, OMEGA_MATMUL_PRECISION_BF16) == 0 && omega_blackwell_codegen_matmul_tensor_loop(&spec, 1, 0, &kernel) != 0, "K not multiple of 16 refused by codegen (the API pads)"); |
| 95 | CHECK(omega_matmul_spec_init(&spec, 16, 16, 16, OMEGA_MATMUL_PRECISION_BF16) == 0 && omega_blackwell_codegen_matmul_tensor_loop(&spec, 3, 0, &kernel) != 0, "grid_x beyond the column tiles refused"); |
| 96 | /* the single-tile kernel of cut 1 still generates (other gates use it) */ |
| 97 | memset(&kernel, 0, sizeof kernel); |
| 98 | CHECK(omega_matmul_spec_init(&spec, 16, 16, 8, OMEGA_MATMUL_PRECISION_BF16) == 0 && omega_blackwell_codegen_matmul(&spec, &kernel) == 0 && kernel.code_size > 0, "16x16x8 single-tile kernel generated"); |
| 99 | omega_blackwell_kernel_free(&kernel); |
| 100 | omega_gpu_matmul_cache_clear(); |
| 101 | } |
| 102 | |
| 103 | static int chip_sweep(const char *shapes, const char *out_path, int mutant) { |
| 104 | FILE *out = out_path ? fopen(out_path, "w") : NULL; |
| 105 | if (out_path && !out) { printf("cannot open %s\n", out_path); return 2; } |
| 106 | if (out) fprintf(out, "{\"schema\":\"OMEGA_GPU_MATMUL_API_SWEEP_V2\",\"mutant\":%s,\"cta_budget\":%u,\"shapes\":[", mutant ? "true" : "false", omega_gpu_matmul_cta_budget()); |
| 107 | char *copy = strdup(shapes); |
| 108 | char *save = NULL; |
| 109 | int first = 1; |
| 110 | for (char *tok = strtok_r(copy, ";", &save); tok; tok = strtok_r(NULL, ";", &save)) { |
| 111 | unsigned m, k, n; |
| 112 | if (sscanf(tok, "%u,%u,%u", &m, &k, &n) != 3) { printf("bad shape %s\n", tok); continue; } |
| 113 | size_t na = (size_t)m * k, nb = (size_t)k * n, nc = (size_t)m * n; |
| 114 | float *a = malloc(na * sizeof *a), *b = malloc(nb * sizeof *b), *c = malloc(nc * sizeof *c), *c2 = malloc(nc * sizeof *c2); |
| 115 | if (!a || !b || !c || !c2) { printf("out of host memory for %s\n", tok); free(a); free(b); free(c); free(c2); continue; } |
| 116 | uint32_t seed = 0x5eed0000u ^ (m << 20) ^ (k << 10) ^ n; |
| 117 | fill(a, na, &seed); fill(b, nb, &seed); |
| 118 | for (size_t i = 0; i < nc; i++) c[i] = -12345.0f; |
| 119 | OmegaGpuMatmulInfo info, info2; |
| 120 | double t0 = now_ms(); |
| 121 | int rc = omega_gpu_matmul_f32(m, k, n, a, b, c, &info); |
| 122 | double wall_ms = now_ms() - t0; |
| 123 | /* second call on the same shape must hit the kernel cache and agree */ |
| 124 | int rc2 = omega_gpu_matmul_f32(m, k, n, a, b, c2, &info2); |
| 125 | size_t repeat_mismatch = 0; |
| 126 | for (size_t i = 0; i < nc; i++) if (c[i] != c2[i]) repeat_mismatch++; |
| 127 | size_t e2e_bad = 0; |
| 128 | double e2e = (rc == OMEGA_GPU_MATMUL_OK || rc == OMEGA_GPU_MATMUL_PARITY_FAIL) ? e2e_max_rel(m, k, n, a, b, c, &e2e_bad) : 0.0; |
| 129 | int pass = rc == OMEGA_GPU_MATMUL_OK && info.parity_verified && e2e < 1e-5 |
| 130 | && rc2 == OMEGA_GPU_MATMUL_OK && info2.kernel_cache_hit && repeat_mismatch == 0; |
| 131 | if (mutant) { |
| 132 | /* the wrong kernel must be caught: PARITY_FAIL from the API oracle and a visible e2e error */ |
| 133 | int caught = rc == OMEGA_GPU_MATMUL_PARITY_FAIL && !info.parity_verified && e2e >= 1e-5; |
| 134 | CHECK(caught, "mutant shape %ux%ux%u NOT caught: rc=%s parity=%d e2e_rel=%g", m, k, n, omega_gpu_matmul_rc_name(rc), info.parity_verified, e2e); |
| 135 | pass = caught; |
| 136 | } else { |
| 137 | CHECK(pass, "shape %ux%ux%u rc=%s parity=%d max_rel=%g e2e_rel=%g rc2=%s hit=%d repeat_mismatch=%zu", |
| 138 | m, k, n, omega_gpu_matmul_rc_name(rc), info.parity_verified, info.max_rel_err, e2e, |
| 139 | omega_gpu_matmul_rc_name(rc2), info2.kernel_cache_hit, repeat_mismatch); |
| 140 | } |
| 141 | printf("%s %ux%ux%u rc=%s chip_ns=%" PRIu64 " call_ms=%.3f wall_ms=%.1f max_abs=%g max_rel=%g mismatches=%zu e2e_rel=%g e2e_bad=%zu grid=%ux%u calls=%u rows_per_call=%u cache_hit2=%d err=\"%s\"\n", |
| 142 | pass ? (mutant ? "KILLED" : "PASS") : (mutant ? "SURVIVED" : "FAIL"), m, k, n, omega_gpu_matmul_rc_name(rc), info.elapsed_ns, info.call_ns / 1e6, wall_ms, |
| 143 | info.max_abs_err, info.max_rel_err, info.mismatch_count, e2e, e2e_bad, info.grid_x, info.grid_y, info.chip_calls, info.rows_per_call, info2.kernel_cache_hit, rc == OMEGA_GPU_MATMUL_CHIP_FAIL ? omega_gpu_matmul_last_error() : ""); |
| 144 | if (out) { |
| 145 | fprintf(out, "%s{\"m\":%u,\"k\":%u,\"n\":%u,\"rc\":\"%s\",\"pass\":%s,\"chip_elapsed_ns\":%" PRIu64 |
| 146 | ",\"call_ms\":%.3f,\"wall_ms\":%.3f,\"max_abs_err\":%g,\"max_rel_err\":%g,\"mismatch_count\":%zu," |
| 147 | "\"parity_verified\":%s,\"completion_marker\":%u,\"repeat_rc\":\"%s\",\"repeat_cache_hit\":%s," |
| 148 | "\"repeat_mismatch\":%zu,\"e2e_max_rel\":%g,\"e2e_bad\":%zu,\"grid_x\":%u,\"grid_y\":%u,\"chip_calls\":%u,\"rows_per_call\":%u,\"padded_m\":%u,\"padded_k\":%u,\"padded_n\":%u,\"target_chip\":\"%s\",\"sm_architecture\":%u}", |
| 149 | first ? "" : ",", m, k, n, omega_gpu_matmul_rc_name(rc), pass ? "true" : "false", |
| 150 | info.elapsed_ns, info.call_ns / 1e6, wall_ms, info.max_abs_err, info.max_rel_err, info.mismatch_count, |
| 151 | info.parity_verified ? "true" : "false", info.completion_marker, |
| 152 | omega_gpu_matmul_rc_name(rc2), info2.kernel_cache_hit ? "true" : "false", |
| 153 | repeat_mismatch, e2e, e2e_bad, info.grid_x, info.grid_y, info.chip_calls, info.rows_per_call, info.padded_m, info.padded_k, info.padded_n, info.target_chip, info.sm_architecture); |
| 154 | first = 0; |
| 155 | } |
| 156 | free(a); free(b); free(c); free(c2); |
| 157 | if (omega_gpu_matmul_is_blocked()) { printf("device latched after an uncertain completion; stopping the sweep\n"); break; } |
| 158 | } |
| 159 | free(copy); |
| 160 | if (out) { |
| 161 | fprintf(out, "],\"blocked\":%s,\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", omega_gpu_matmul_is_blocked() ? "true" : "false", g_checks, g_failed, |
| 162 | g_failed == 0 ? (mutant ? "OMEGA_GPU_MATMUL_MUTANT_KILLED" : "OMEGA_GPU_MATMUL_API_PASS") : (mutant ? "OMEGA_GPU_MATMUL_MUTANT_SURVIVED" : "OMEGA_GPU_MATMUL_API_FAIL")); |
| 163 | fclose(out); |
| 164 | } |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int cmp_double(const void *x, const void *y) { double a = *(const double *)x, b = *(const double *)y; return a < b ? -1 : a > b; } |
| 169 | |
| 170 | /* Resident path: upload B once, then 100 calls; median wall time per call must be under 5 ms. |
| 171 | * Parity: first and last result against the double reference (0 elements at or beyond 1e-5). */ |
| 172 | static int timing(const char *shapes, const char *out_path) { |
| 173 | FILE *out = out_path ? fopen(out_path, "w") : NULL; |
| 174 | if (out_path && !out) { printf("cannot open %s\n", out_path); return 2; } |
| 175 | if (out) fprintf(out, "{\"schema\":\"OMEGA_GPU_MATMUL_API_TIMING_V1\",\"cta_budget\":%u,\"calls\":100,\"shapes\":[", omega_gpu_matmul_cta_budget()); |
| 176 | char *copy = strdup(shapes); char *save = NULL; int first = 1; |
| 177 | for (char *tok = strtok_r(copy, ";", &save); tok; tok = strtok_r(NULL, ";", &save)) { |
| 178 | unsigned m, k, n; |
| 179 | if (sscanf(tok, "%u,%u,%u", &m, &k, &n) != 3) { printf("bad shape %s\n", tok); continue; } |
| 180 | size_t na = (size_t)m * k, nb = (size_t)k * n, nc = (size_t)m * n; |
| 181 | float *a = malloc(na * sizeof *a), *b = malloc(nb * sizeof *b), *c = malloc(nc * sizeof *c), *c_first = malloc(nc * sizeof *c_first); |
| 182 | uint16_t *ah = malloc(na * sizeof *ah); |
| 183 | if (!a || !b || !c || !c_first || !ah) { printf("out of host memory\n"); return 2; } |
| 184 | uint32_t seed = 0x7111e000u ^ (m << 20) ^ (k << 10) ^ n; |
| 185 | fill(a, na, &seed); fill(b, nb, &seed); |
| 186 | for (size_t i = 0; i < na; i++) ah[i] = omega_fp32_to_bf16(a[i]); |
| 187 | OmegaGpuTensor *t = NULL; |
| 188 | double tu0 = now_ms(); |
| 189 | int urc = omega_gpu_tensor_upload_f32(k, n, b, &t); |
| 190 | double upload_ms = now_ms() - tu0; |
| 191 | CHECK(urc == OMEGA_GPU_MATMUL_OK, "upload %ux%u rc=%s", k, n, omega_gpu_matmul_rc_name(urc)); |
| 192 | double samples[100]; int ok_calls = 0; OmegaGpuMatmulInfo info; memset(&info, 0, sizeof info); |
| 193 | uint64_t chip_ns_sum = 0; size_t repeat_mismatch = 0; |
| 194 | if (urc == OMEGA_GPU_MATMUL_OK) { |
| 195 | for (int i = 0; i < 100; i++) { |
| 196 | for (size_t j = 0; j < nc; j++) c[j] = -12345.0f; |
| 197 | double t0 = now_ms(); |
| 198 | int rc = omega_gpu_matmul_resident_bf16(m, ah, t, c, &info); |
| 199 | samples[i] = now_ms() - t0; |
| 200 | if (rc == OMEGA_GPU_MATMUL_OK) ok_calls++; |
| 201 | chip_ns_sum += info.elapsed_ns; |
| 202 | if (i == 0) memcpy(c_first, c, nc * sizeof *c); |
| 203 | else for (size_t j = 0; j < nc; j++) if (c[j] != c_first[j]) repeat_mismatch++; |
| 204 | if (omega_gpu_matmul_is_blocked()) break; |
| 205 | } |
| 206 | } |
| 207 | qsort(samples, 100, sizeof samples[0], cmp_double); |
| 208 | double median = samples[50], p90 = samples[90], mn = samples[0], mx = samples[99]; |
| 209 | size_t bad_first = 0, bad_last = 0; |
| 210 | double e2e_first = e2e_max_rel(m, k, n, a, b, c_first, &bad_first); |
| 211 | double e2e_last = e2e_max_rel(m, k, n, a, b, c, &bad_last); |
| 212 | int pass = ok_calls == 100 && bad_first == 0 && bad_last == 0 && repeat_mismatch == 0 && median < 5.0; |
| 213 | CHECK(pass, "timing %ux%ux%u ok_calls=%d median_ms=%.3f e2e_first=%g e2e_last=%g bad=%zu/%zu repeat_mismatch=%zu", |
| 214 | m, k, n, ok_calls, median, e2e_first, e2e_last, bad_first, bad_last, repeat_mismatch); |
| 215 | printf("%s timing %ux%ux%u upload_ms=%.1f ok_calls=%d median_ms=%.3f p90_ms=%.3f min_ms=%.3f max_ms=%.3f chip_ns_mean=%" PRIu64 " grid=%ux%u e2e_first=%g e2e_last=%g repeat_mismatch=%zu\n", |
| 216 | pass ? "PASS" : "FAIL", m, k, n, upload_ms, ok_calls, median, p90, mn, mx, ok_calls ? chip_ns_sum / (uint64_t)ok_calls : 0, info.grid_x, info.grid_y, e2e_first, e2e_last, repeat_mismatch); |
| 217 | if (out) { |
| 218 | fprintf(out, "%s{\"m\":%u,\"k\":%u,\"n\":%u,\"pass\":%s,\"upload_ms\":%.3f,\"ok_calls\":%d,\"median_ms\":%.4f,\"p90_ms\":%.4f,\"min_ms\":%.4f,\"max_ms\":%.4f," |
| 219 | "\"chip_ns_mean\":%" PRIu64 ",\"grid_x\":%u,\"grid_y\":%u,\"e2e_first\":%g,\"e2e_last\":%g,\"e2e_bad_first\":%zu,\"e2e_bad_last\":%zu,\"repeat_mismatch\":%zu}", |
| 220 | first ? "" : ",", m, k, n, pass ? "true" : "false", upload_ms, ok_calls, median, p90, mn, mx, |
| 221 | ok_calls ? chip_ns_sum / (uint64_t)ok_calls : 0, info.grid_x, info.grid_y, e2e_first, e2e_last, bad_first, bad_last, repeat_mismatch); |
| 222 | first = 0; |
| 223 | } |
| 224 | omega_gpu_tensor_free(t); |
| 225 | free(a); free(b); free(c); free(c_first); free(ah); |
| 226 | if (omega_gpu_matmul_is_blocked()) break; |
| 227 | } |
| 228 | free(copy); |
| 229 | if (out) { |
| 230 | fprintf(out, "],\"blocked\":%s,\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", omega_gpu_matmul_is_blocked() ? "true" : "false", g_checks, g_failed, |
| 231 | g_failed == 0 ? "OMEGA_GPU_MATMUL_TIMING_PASS" : "OMEGA_GPU_MATMUL_TIMING_FAIL"); |
| 232 | fclose(out); |
| 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | int main(int argc, char **argv) { |
| 238 | const char *out_path = NULL; |
| 239 | int host = 0, mutant = 0, do_timing = 0; |
| 240 | for (int i = 1; i < argc; i++) { |
| 241 | if (strcmp(argv[i], "--host-only") == 0) host = 1; |
| 242 | else if (strcmp(argv[i], "--mutant") == 0) mutant = 1; |
| 243 | else if (strcmp(argv[i], "--timing") == 0) do_timing = 1; |
| 244 | else if (strcmp(argv[i], "--cta-budget") == 0 && i + 1 < argc) omega_gpu_matmul_set_cta_budget((uint32_t)strtoul(argv[++i], NULL, 10)); |
| 245 | else if (strcmp(argv[i], "--out") == 0 && i + 1 < argc) out_path = argv[++i]; |
| 246 | } |
| 247 | const char *shapes = getenv("OMEGA_GPU_MATMUL_SHAPES"); |
| 248 | if (shapes && !*shapes) shapes = NULL; |
| 249 | int rc = 0; |
| 250 | if (host) host_only(); |
| 251 | else if (do_timing) rc = timing(shapes ? shapes : TIMING_SHAPES, out_path); |
| 252 | else if (mutant) { omega_gpu_matmul_test_set_mutant(1); rc = chip_sweep(shapes ? shapes : MUTANT_SHAPES, out_path, 1); omega_gpu_matmul_test_set_mutant(0); } |
| 253 | else rc = chip_sweep(shapes ? shapes : DEFAULT_SHAPES, out_path, 0); |
| 254 | if (!omega_gpu_matmul_is_blocked()) omega_gpu_device_close(); |
| 255 | if (rc) return 2; |
| 256 | printf("%s: %d checks, %d failed%s\n", g_failed ? "FAIL" : "PASS", g_checks, g_failed, mutant ? (g_failed ? " (mutant SURVIVED)" : " (mutant killed)") : ""); |
| 257 | return g_failed ? 1 : 0; |
| 258 | } |