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/omega-mv/blob/main/tests/gpu_scan_test.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / gpu_scan_test.c` 379 lines ยท 19417 bytes Raw Blame History 1 /* gpu_scan_test.c -- row C3 of docs/OMEGA.md: reductions and prefix sums of any length, bit-exact against the 2 * frozen-order host reference (src/omega_gpu_scan.h). 3 * 4 * --host-only no device: refusals, every kernel through our codegen and encoder, the references checked against 5 * exact integer sums and against the E1 reduction reference (omega_reduce_reference) 6 * --sim the real kernels through the warp simulator (tests/bw_warp_sim.h), both scheduling orders, lengths 7 * that cross every tile, CTA and grid-stride edge; the three mutants must be caught 8 * (no flag) the GB10: every n from 1 to 2048, then 2^k - 1, 2^k, 2^k + 1 up to 2^28, then random lengths; 9 * bit-exact (a NaN result must be a NaN); the three mutants must be caught. 10 * --max-log2 K stops the power-of-two ladder at 2^K (default 28). 11 * Last line: "C3 scan : PASS ( checks)" or "... FAIL ( of )". */ 12 #include "omega_gpu_scan.h" 13 #include "omega_gpu_session.h" 14 #include "omega_numeric_reduce.h" 15 #include "bw_warp_sim.h" 16 17 #include 18 #include 19 #include 20 #include 21 22 static int g_checks, g_failed; 23 static void check(int ok, const char *what) { 24 g_checks++; 25 if (!ok) { g_failed++; printf("FAIL: %s\n", what); } 26 } 27 28 static uint32_t f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } 29 static float u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } 30 static int is_nan(uint32_t u) { return (u & 0x7f800000u) == 0x7f800000u && (u & 0x007fffffu); } 31 static int same(float a, float b) { uint32_t x = f2u(a), y = f2u(b); return x == y || (is_nan(x) && is_nan(y)); } 32 33 static uint64_t g_rng = 0x9e3779b97f4a7c15ull; 34 static uint32_t rnd(void) { g_rng = g_rng * 6364136223846793005ull + 1442695040888963407ull; return (uint32_t)(g_rng >> 33); } 35 36 /* inputs: 0 small integers (every sum exact), 1 mixed magnitudes and signed zeros, 2 mixed plus NaN and infinities */ 37 static void fill(float *x, size_t n, int kind, uint64_t seed) { 38 g_rng = seed * 0x2545f4914f6cdd1dull + 1; 39 for (size_t i = 0; i < n; i++) { 40 if (kind == 0) { x[i] = (float)((int)(rnd() % 2001u) - 1000); continue; } 41 float m = (float)((rnd() & 0x7fffffu) | 1u) * (rnd() & 1 ? -1.0f : 1.0f); 42 int e = (int)(rnd() % 41u) - 20 - 23; 43 x[i] = m * u2f((uint32_t)(127 + e) << 23); 44 if (i % 97u == 5u) x[i] = 0.0f; 45 if (i % 131u == 7u) x[i] = -0.0f; 46 if (kind == 2 && i % 53u == 11u) x[i] = u2f(0x7fc00000u | (rnd() & 0xffffu)); 47 if (kind == 2 && i == n / 3) x[i] = u2f(0x7f800000u); 48 if (kind == 2 && i == n / 2 && n > 4) x[i] = u2f(0xff800000u); 49 } 50 } 51 52 static const char *op_name(OmegaGpuRedOp op) { return op == OMEGA_GPU_RED_SUM ? "sum" : op == OMEGA_GPU_RED_MAX ? "max" : "min"; } 53 54 /* ------------------------------------------------------------------ host only */ 55 56 static int fake_fail(void *ctx, OmegaScanKind k, const uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS], uint32_t g) { 57 (void)ctx; (void)k; (void)a; (void)g; return -1; 58 } 59 60 static void host_only(void) { 61 char w[200]; 62 float x[4] = { 1, 2, 3, 4 }, o; 63 check(omega_gpu_reduce(OMEGA_GPU_RED_SUM, x, 0, &o, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "reduce n = 0 refused"); 64 check(omega_gpu_reduce(OMEGA_GPU_RED_SUM, NULL, 4, &o, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "reduce NULL input refused"); 65 check(omega_gpu_reduce((OmegaGpuRedOp)7, x, 4, &o, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "reduce unknown op refused"); 66 check(omega_gpu_reduce(OMEGA_GPU_RED_SUM, x, OMEGA_GPU_SCAN_MAX_N + 1, &o, NULL) == OMEGA_GPU_SCAN_TOO_LARGE, "reduce 2^28 + 1 refused"); 67 check(omega_gpu_prefix_sum(x, 0, x, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "prefix n = 0 refused"); 68 check(omega_gpu_prefix_sum(x, OMEGA_GPU_SCAN_MAX_N + 1, x, NULL) == OMEGA_GPU_SCAN_TOO_LARGE, "prefix 2^28 + 1 refused"); 69 uint64_t r; 70 check(omega_gpu_scan_drive_reduce(OMEGA_GPU_RED_SUM, 100, 0, 0, &r, fake_fail, NULL, NULL) == OMEGA_GPU_SCAN_CHIP_FAIL, "a failed launch is reported (reduce)"); 71 check(omega_gpu_scan_drive_prefix(100, 0, 0, 0, fake_fail, NULL, NULL) == OMEGA_GPU_SCAN_CHIP_FAIL, "a failed launch is reported (prefix)"); 72 73 for (int mut = 0; mut <= 3; mut++) 74 for (int k = 0; k < OMEGA_SCAN_K_COUNT; k++) { 75 BlackwellIRProgram *p = calloc(1, sizeof *p); 76 OmegaScanSpec s = { (OmegaScanKind)k, mut }; 77 int rc = omega_gpu_scan_codegen(&s, p); 78 size_t bytes = rc == 0 ? omega_bw_program_code_bytes(p) : 0; 79 uint8_t *code = bytes ? malloc(bytes) : NULL; 80 OmegaBlackwellKernel kk; memset(&kk, 0, sizeof kk); 81 int enc = code ? omega_blackwell_kernel_encode_into(p, code, bytes, &kk) : -1; 82 snprintf(w, sizeof w, "kernel %d mutant %d through codegen and encoder (%zu bytes, %u gprs)", k, mut, bytes, (unsigned)kk.gpr_count); 83 check(rc == 0 && enc == 0 && kk.code_size == bytes, w); 84 if (mut == 0 && rc == 0) printf("kernel %d: %u insns, %zu bytes, %u gprs\n", k, (unsigned)p->count, bytes, (unsigned)kk.gpr_count); 85 free(code); free(p); 86 } 87 88 /* the references against exact sums: integers in [-1000, 1000], n <= 16384, every partial sum below 2^24 */ 89 static float a[16384], y[16384]; 90 const size_t ns[] = { 1, 2, 31, 32, 33, 63, 64, 65, 1023, 1024, 1025, 1057, 16384 }; 91 for (size_t t = 0; t < sizeof ns / sizeof ns[0]; t++) { 92 size_t n = ns[t]; 93 fill(a, n, 0, n); 94 double s = 0, mx = -1e9, mn = 1e9; 95 for (size_t i = 0; i < n; i++) { s += a[i]; if (a[i] > mx) mx = a[i]; if (a[i] < mn) mn = a[i]; } 96 float rs, rmx, rmn; 97 int ok = omega_gpu_reduce_reference(OMEGA_GPU_RED_SUM, a, n, &rs) == 0 && omega_gpu_reduce_reference(OMEGA_GPU_RED_MAX, a, n, &rmx) == 0 && 98 omega_gpu_reduce_reference(OMEGA_GPU_RED_MIN, a, n, &rmn) == 0; 99 snprintf(w, sizeof w, "reference sum/max/min exact at n = %zu", n); 100 check(ok && rs == (float)s && rmx == (float)mx && rmn == (float)mn, w); 101 ok = omega_gpu_prefix_sum_reference(a, n, y) == 0; 102 double run = 0; size_t bad = 0; 103 for (size_t i = 0; i < n; i++) { run += a[i]; bad += y[i] != (float)run; } 104 snprintf(w, sizeof w, "reference prefix sum exact at n = %zu (%zu wrong)", n, bad); 105 check(ok && bad == 0, w); 106 } 107 108 /* the reduction reference is the E1 order: equal bit for bit to omega_reduce_reference on any input */ 109 static float b[300000]; 110 const size_t ms[] = { 1, 2, 17, 32, 33, 100, 1000, 1024, 1025, 4097, 32768, 32769, 299999 }; 111 for (int kind = 1; kind <= 2; kind++) 112 for (size_t t = 0; t < sizeof ms / sizeof ms[0]; t++) 113 for (int op = 0; op < 3; op++) { 114 size_t n = ms[t]; 115 fill(b, n, kind, n * 3 + (size_t)op); 116 float mine, e1; 117 int ok = omega_gpu_reduce_reference((OmegaGpuRedOp)op, b, n, &mine) == 0 && omega_reduce_reference((OmegaReduceOp)op, b, n, &e1) == 0; 118 snprintf(w, sizeof w, "reference %s equals the E1 reference, inputs %d, n = %zu (%08x vs %08x)", op_name(op), kind, n, f2u(mine), f2u(e1)); 119 check(ok && same(mine, e1), w); 120 } 121 122 /* the frozen order is a real order: summing left to right gives a different answer on mixed inputs */ 123 fill(b, 4097, 1, 99); 124 float tree, seq = -0.0f; 125 for (size_t i = 0; i < 4097; i++) seq += b[i]; 126 omega_gpu_reduce_reference(OMEGA_GPU_RED_SUM, b, 4097, &tree); 127 check(f2u(tree) != f2u(seq), "the frozen tree differs from a left-to-right sum (the order is pinned, not luck)"); 128 } 129 130 /* ------------------------------------------------------------------ the simulator */ 131 132 typedef struct { 133 BlackwellIRProgram *prog[OMEGA_SCAN_K_COUNT]; 134 int order; 135 WsRange ranges[3]; 136 char err[260]; 137 } SimCtx; 138 139 static int sim_launch(void *ctx, OmegaScanKind k, const uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS], uint32_t grid_x) { 140 SimCtx *c = ctx; 141 static WsSim s; 142 memset(&s, 0, sizeof s); 143 s.p = c->prog[k]; s.threads = OMEGA_GPU_SCAN_THREADS; s.order = c->order; 144 for (unsigned i = 0; i < OMEGA_GPU_SCAN_ARGS_WORDS; i++) s.cbank[0x380 / 4 + i] = a[i]; 145 memcpy(s.ranges, c->ranges, sizeof c->ranges); s.nranges = 3; 146 if (ws_run(&s, grid_x, 1) != 0) { snprintf(c->err, sizeof c->err, "kernel %d: %s at pc %d", (int)k, s.msg, s.err_pc); return -1; } 147 return 0; 148 } 149 150 static int sim_build(SimCtx *c, int mutant) { 151 for (int k = 0; k < OMEGA_SCAN_K_COUNT; k++) { 152 c->prog[k] = calloc(1, sizeof *c->prog[k]); 153 OmegaScanSpec s = { (OmegaScanKind)k, mutant }; 154 if (!c->prog[k] || omega_gpu_scan_codegen(&s, c->prog[k]) != 0) return -1; 155 } 156 return 0; 157 } 158 static void sim_free(SimCtx *c) { for (int k = 0; k < OMEGA_SCAN_K_COUNT; k++) free(c->prog[k]); } 159 160 #define POISON 0x7fa00badu 161 static void poison(float *p, size_t n) { for (size_t i = 0; i < n; i++) memcpy(&p[i], &(uint32_t){ POISON }, 4); } 162 163 /* one reduction through the simulator; 0 when it ran, the result in *out */ 164 static int sim_reduce(SimCtx *c, OmegaGpuRedOp op, const float *x, size_t n, float *out) { 165 size_t sw = omega_gpu_scan_reduce_scratch_words(n); 166 float *scr = malloc(sw * 4u); 167 poison(scr, sw); 168 c->ranges[0] = (WsRange){ (uintptr_t)x, (uintptr_t)(x + n) }; 169 c->ranges[1] = (WsRange){ (uintptr_t)scr, (uintptr_t)(scr + sw) }; 170 c->ranges[2] = c->ranges[1]; 171 uint64_t res = 0; 172 int rc = omega_gpu_scan_drive_reduce(op, n, (uintptr_t)x, (uintptr_t)scr, &res, sim_launch, c, NULL); 173 if (rc == 0) { memcpy(out, (const void *)(uintptr_t)res, 4); if (f2u(*out) == POISON) rc = -9; } 174 free(scr); 175 return rc; 176 } 177 178 static int sim_prefix(SimCtx *c, const float *x, size_t n, float *y) { 179 size_t sw = omega_gpu_scan_prefix_scratch_words(n); 180 float *scr = malloc(sw * 4u); 181 poison(scr, sw); poison(y, n); 182 c->ranges[0] = (WsRange){ (uintptr_t)x, (uintptr_t)(x + n) }; 183 c->ranges[1] = (WsRange){ (uintptr_t)y, (uintptr_t)(y + n) }; 184 c->ranges[2] = (WsRange){ (uintptr_t)scr, (uintptr_t)(scr + sw) }; 185 int rc = omega_gpu_scan_drive_prefix(n, (uintptr_t)x, (uintptr_t)y, (uintptr_t)scr, sim_launch, c, NULL); 186 for (size_t i = 0; rc == 0 && i < n; i++) if (f2u(y[i]) == POISON) rc = -9; 187 free(scr); 188 return rc; 189 } 190 191 static size_t diff(const float *a, const float *b, size_t n, size_t *first) { 192 size_t d = 0; 193 for (size_t i = 0; i < n; i++) if (!same(a[i], b[i])) { if (!d) *first = i; d++; } 194 return d; 195 } 196 197 static void sim_tier(void) { 198 char w[600]; 199 static size_t ns[200]; size_t nn = 0; 200 for (size_t n = 1; n <= 70; n++) ns[nn++] = n; 201 const size_t more[] = { 255, 256, 257, 1000, 1023, 1024, 1025, 2047, 2048, 2049, 32767, 32768, 32769, 40000, 270000 }; 202 for (size_t i = 0; i < sizeof more / sizeof more[0]; i++) ns[nn++] = more[i]; 203 float *x = malloc(270000 * 4u), *y = malloc(270000 * 4u), *ref = malloc(270000 * 4u); 204 SimCtx c; memset(&c, 0, sizeof c); 205 check(sim_build(&c, 0) == 0, "simulator: all kernels built"); 206 for (int order = 0; order <= 1; order++) { 207 c.order = order; 208 size_t bad_red = 0, bad_pre = 0, runs = 0; 209 for (size_t t = 0; t < nn; t++) { 210 size_t n = ns[t]; 211 if (order == 1 && n > 40000) continue; 212 int kind = (int)(t % 3); 213 fill(x, n, kind, n * 7 + (size_t)order); 214 for (int op = 0; op < 3; op++) { 215 float got, want; 216 omega_gpu_reduce_reference((OmegaGpuRedOp)op, x, n, &want); 217 int rc = sim_reduce(&c, (OmegaGpuRedOp)op, x, n, &got); 218 runs++; 219 if (rc != 0 || !same(got, want)) { 220 bad_red++; 221 snprintf(w, sizeof w, "sim order %d %s n = %zu: rc %d got %08x want %08x %s", order, op_name(op), n, rc, f2u(got), f2u(want), c.err); 222 check(0, w); 223 } 224 } 225 omega_gpu_prefix_sum_reference(x, n, ref); 226 int rc = sim_prefix(&c, x, n, y); 227 size_t first = 0, d = rc == 0 ? diff(y, ref, n, &first) : n; 228 runs++; 229 if (rc != 0 || d) { 230 bad_pre++; 231 snprintf(w, sizeof w, "sim order %d prefix n = %zu: rc %d, %zu wrong, first at %zu (%08x vs %08x) %s", order, n, rc, d, first, 232 f2u(y[first]), f2u(ref[first]), c.err); 233 check(0, w); 234 } 235 } 236 snprintf(w, sizeof w, "simulator order %d: %zu runs, reductions wrong %zu, prefix sums wrong %zu", order, runs, bad_red, bad_pre); 237 check(bad_red == 0 && bad_pre == 0, w); 238 printf("%s\n", w); 239 } 240 sim_free(&c); 241 242 /* red checks: each mutant must change a result the real kernels get right */ 243 for (int mut = 1; mut <= 3; mut++) { 244 SimCtx m; memset(&m, 0, sizeof m); 245 int built = sim_build(&m, mut) == 0, caught = 0; 246 const size_t n = 1000; 247 fill(x, n, 1, 4242); 248 if (built && mut == 1) { 249 for (int op = 0; op < 3 && !caught; op++) { 250 float got = 0, want; omega_gpu_reduce_reference((OmegaGpuRedOp)op, x, n, &want); 251 caught = sim_reduce(&m, (OmegaGpuRedOp)op, x, n, &got) != 0 || !same(got, want); 252 } 253 } else if (built) { 254 omega_gpu_prefix_sum_reference(x, n, ref); 255 size_t first; 256 caught = sim_prefix(&m, x, n, y) != 0 || diff(y, ref, n, &first) != 0; 257 } 258 snprintf(w, sizeof w, "simulator red check: mutant %d is caught", mut); 259 check(built && caught, w); 260 sim_free(&m); 261 } 262 free(x); free(y); free(ref); 263 } 264 265 /* ------------------------------------------------------------------ the chip */ 266 267 static size_t mem_available(void) { 268 FILE *f = fopen("/proc/meminfo", "r"); 269 char line[256]; size_t kb = 0; 270 while (f && fgets(line, sizeof line, f)) if (sscanf(line, "MemAvailable: %zu kB", &kb) == 1) break; 271 if (f) fclose(f); 272 return kb * 1024u; 273 } 274 275 static float *g_x, *g_y, *g_ref; 276 277 static void chip_one(size_t n, int kind, int verbose) { 278 char w[600]; 279 fill(g_x, n, kind, n * 11 + (size_t)kind); 280 for (int op = 0; op < 3; op++) { 281 float got = 0, want; OmegaGpuScanInfo info; 282 omega_gpu_reduce_reference((OmegaGpuRedOp)op, g_x, n, &want); 283 int rc = omega_gpu_reduce((OmegaGpuRedOp)op, g_x, n, &got, &info); 284 int ok = rc == 0 && same(got, want); 285 if (!ok || verbose) { 286 snprintf(w, sizeof w, "chip %s n = %zu inputs %d: %s, got %08x want %08x, %u launches, kernels %.3f ms%s%s", op_name(op), n, kind, 287 omega_gpu_scan_rc_name(rc), f2u(got), f2u(want), info.launches, info.elapsed_ns / 1e6, rc ? ": " : "", 288 rc ? omega_gpu_session_last_error() : ""); 289 if (ok) { g_checks++; printf("ok: %s\n", w); } else check(0, w); 290 } else g_checks++; 291 } 292 OmegaGpuScanInfo info; 293 omega_gpu_prefix_sum_reference(g_x, n, g_ref); 294 int rc = omega_gpu_prefix_sum(g_x, n, g_y, &info); 295 size_t first = 0, d = rc == 0 ? diff(g_y, g_ref, n, &first) : n; 296 if (rc || d || verbose) { 297 snprintf(w, sizeof w, "chip prefix n = %zu inputs %d: %s, %zu wrong (first at %zu), %u launches, kernels %.3f ms%s%s", n, kind, 298 omega_gpu_scan_rc_name(rc), d, first, info.launches, info.elapsed_ns / 1e6, rc ? ": " : "", rc ? omega_gpu_session_last_error() : ""); 299 if (!rc && !d) { g_checks++; printf("ok: %s\n", w); } else check(0, w); 300 } else g_checks++; 301 } 302 303 static void chip_tier(unsigned max_log2) { 304 char w[200]; 305 size_t cap = (size_t)1 << max_log2; 306 if (cap > OMEGA_GPU_SCAN_MAX_N) cap = OMEGA_GPU_SCAN_MAX_N; 307 /* host: input, output, reference (3 x 4n); device buffer: in + out + scratch (~ 8n); plus 8 GiB for everyone else */ 308 size_t need = cap * 4u * 5u + ((size_t)8 << 30), have = mem_available(); 309 if (have < need) { 310 printf("NOT_RUN: MemAvailable %zu MiB < %zu MiB needed for n up to %zu\n", have >> 20, need >> 20, cap); 311 exit(2); 312 } 313 g_x = malloc(cap * 4u); g_y = malloc(cap * 4u); g_ref = malloc(cap * 4u); 314 if (!g_x || !g_y || !g_ref) { printf("NOT_RUN: host allocation\n"); exit(2); } 315 316 int before = g_failed; 317 for (size_t n = 1; n <= 2048; n++) chip_one(n, (int)(n % 3), 0); 318 printf("every n from 1 to 2048 (sum, max, min, prefix): %s\n", g_failed == before ? "PASS" : "FAIL"); 319 before = g_failed; 320 for (unsigned k = 11; k <= max_log2 && k <= 28; k++) { 321 size_t p = (size_t)1 << k; 322 chip_one(p - 1, 1, 0); 323 chip_one(p, 2, k >= 20); 324 if (p + 1 <= cap) chip_one(p + 1, 1, 0); 325 } 326 printf("2^k - 1, 2^k, 2^k + 1 up to 2^%u: %s\n", max_log2, g_failed == before ? "PASS" : "FAIL"); 327 before = g_failed; 328 g_rng = 0xc3c3c3c3ull; 329 for (int i = 0; i < 64; i++) { 330 size_t n = 2049 + (((size_t)rnd() << 16) ^ rnd()) % (cap > (1u << 24) ? (1u << 24) : cap - 2048); 331 chip_one(n, i % 3, 0); 332 } 333 printf("64 random lengths: %s\n", g_failed == before ? "PASS" : "FAIL"); 334 335 for (int mut = 1; mut <= 3; mut++) { 336 omega_gpu_scan_test_set_mutant(mut); 337 const size_t n = 1000; 338 fill(g_x, n, 1, 4242); 339 int caught = 0; 340 if (mut == 1) { 341 for (int op = 0; op < 3 && !caught; op++) { 342 float got = 0, want; omega_gpu_reduce_reference((OmegaGpuRedOp)op, g_x, n, &want); 343 caught = omega_gpu_reduce((OmegaGpuRedOp)op, g_x, n, &got, NULL) != 0 || !same(got, want); 344 } 345 } else { 346 size_t first; 347 omega_gpu_prefix_sum_reference(g_x, n, g_ref); 348 caught = omega_gpu_prefix_sum(g_x, n, g_y, NULL) != 0 || diff(g_y, g_ref, n, &first) != 0; 349 } 350 snprintf(w, sizeof w, "chip red check: mutant %d is caught", mut); 351 check(caught, w); 352 } 353 omega_gpu_scan_test_set_mutant(0); 354 fill(g_x, 1000, 1, 4242); 355 omega_gpu_prefix_sum_reference(g_x, 1000, g_ref); 356 size_t first; 357 check(omega_gpu_prefix_sum(g_x, 1000, g_y, NULL) == 0 && diff(g_y, g_ref, 1000, &first) == 0, "the real kernels are right again after the red checks"); 358 omega_gpu_session_close(); /* the kernels go with the device (close hook); the next call builds them on a new one */ 359 check(omega_gpu_prefix_sum(g_x, 1000, g_y, NULL) == 0 && diff(g_y, g_ref, 1000, &first) == 0, "after the device closed and opened again the kernels are rebuilt and right"); 360 free(g_x); free(g_y); free(g_ref); 361 } 362 363 int main(int argc, char **argv) { 364 const char *tier = "chip"; 365 unsigned max_log2 = 28; 366 for (int i = 1; i < argc; i++) { 367 if (!strcmp(argv[i], "--host-only")) tier = "host"; 368 else if (!strcmp(argv[i], "--sim")) tier = "sim"; 369 else if (!strcmp(argv[i], "--max-log2") && i + 1 < argc) max_log2 = (unsigned)atoi(argv[++i]); 370 else { fprintf(stderr, "usage: %s [--host-only | --sim] [--max-log2 K]\n", argv[0]); return 2; } 371 } 372 if (max_log2 < 11 || max_log2 > 28) { fprintf(stderr, "--max-log2 must be 11..28\n"); return 2; } 373 if (!strcmp(tier, "host")) host_only(); 374 else if (!strcmp(tier, "sim")) { host_only(); sim_tier(); } 375 else chip_tier(max_log2); 376 if (g_failed) printf("C3 scan %s: FAIL (%d of %d)\n", tier, g_failed, g_checks); 377 else printf("C3 scan %s: PASS (%d checks)\n", tier, g_checks); 378 return g_failed ? 1 : 0; 379 }