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_streams_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_streams_test.c` 392 lines ยท 20518 bytes Raw Blame History 1 /* gpu_streams_test.c -- row C4 of docs/OMEGA.md: two independent queues and an event between them, on the GB10. 2 * 3 * --host-only codegen + encode of the two kernels (and their mutants), refusals of omega_gpu_cmdlist_wait_for 4 * --sim the kernels through the warp simulator (tests/bw_warp_sim.h): exact values, mutants caught 5 * (no flag) the chip, under the GB10 lock, AIEN_OMEGA_GPU_CHANNELS = 2 (L136 extra queue): 6 * overlap list A and list B each hold the same half-chip spin kernel (24 CTAs x 128 threads); solo A, solo B 7 * (session queue, one submit each) and the pair (A on queue 0, B on queue 1, omega_gpu_cmdlist_submit_pair), 8 * medians of REPS: PASS when pair < 0.75 (solo A + solo B), for the default barrier or first_barrier_none 9 * (both are printed). Red check: both spins in ONE list on one queue (WAIT_FOR_IDLE between them) must 10 * NOT come in under 0.75, or the measurement cannot tell overlap from order. 11 * event A: a long spin writes X. B: omega_gpu_cmdlist_wait_for(A, 0), then copy Y = X + 1. X and Y start as a 12 * signalling-NaN poison; every Y must be the spin's value + 1. Negative control: the same pair without the 13 * wait must leave at least one Y wrong (B ran while A spun), else the event is "not demonstrated" (FAIL). 14 * Every kernel comes from Omega's IR (omega_bw_em.h), encoded by our own sm_121 encoder; no CUDA. */ 15 #include "omega_gpu_cmdlist.h" 16 #include "omega_gpu_session.h" 17 #include "bw_warp_sim.h" /* brings math.h, whose fadd() would hide the emitter's */ 18 #define fadd em_fadd 19 #define ffma em_ffma 20 #include "omega_bw_em.h" 21 22 #include 23 #include 24 #include 25 26 #define THREADS 128u 27 #define CTAS 24u /* half of the GB10's 48 SMs */ 28 #define NEL (THREADS * CTAS) 29 #define UNROLL 4u /* FFMAs per loop turn: x = x * 1 + 1 */ 30 #define MAX_ITERS ((1u << 22) - 1024u) /* UNROLL * iters + tag stays below 2^24: every value exact in f32 */ 31 #define POISON 0x7fa00badu /* a signalling NaN no FFMA / FADD writes */ 32 #define REPS 5 33 34 /* argument words (constant bank 0x380) */ 35 #define A_OUT 0x380 /* spin: out u64 | copy: in u64 */ 36 #define A_ITERS 0x388 /* spin: loop turns | copy: out u64 (0x388..0x38f) */ 37 #define A_TAG 0x38c /* spin: f32 added at the end */ 38 #define A_N 0x390 /* elements */ 39 #define ARGS 5u 40 41 static int g_failed, g_checks; 42 static void check(int ok, const char *what) { 43 g_checks++; 44 if (!ok) g_failed++; 45 printf("%s: %s\n", ok ? "ok" : "FAIL", what); 46 } 47 static uint32_t f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } 48 49 /* ------------------------------------------------------------------ the kernels */ 50 51 typedef struct { int bssy, bra; } Region; 52 static Region skip_if_p0(Em *e) { Region r; r.bssy = bssy_fwd(e); r.bra = bra_if_p0_fwd(e); return r; } 53 static void region_end(Em *e, Region r) { int at = here(e); bsync(e); patch_bra(e, r.bra, at); patch_bra(e, r.bssy, at + 1); } 54 55 /* spin: out[gid] = UNROLL * iters + tag (mutant 1: one FFMA short per turn) */ 56 static int gen_spin(Em *e, int mutant) { 57 int udesc = UV64(e), pout = V64(e), a64 = V64(e), iters = V(e), tag = V(e), n = V(e), tid = V(e), cta = V(e), gid = V(e); 58 int i = V(e), one = V(e), fone = V(e), x = V(e); 59 if (e->err) return -1; 60 ldcu64(e, udesc, 0x358); 61 ldc64(e, pout, A_OUT); ldc32(e, iters, A_ITERS); ldc32(e, tag, A_TAG); ldc32(e, n, A_N); 62 s2r(e, tid, BW_SR_TID_X); s2r(e, cta, BW_SR_CTAID_X); 63 imadi(e, gid, cta, 0, THREADS, tid); 64 movi(e, one, 1); movi(e, fone, 0x3f800000u); movi(e, x, 0); movi(e, i, 0); 65 const int top = here(e); 66 loop_begin(e); 67 isetp_ge_u32(e, i, iters); 68 const int done = bra_if_p0_fwd(e); 69 for (unsigned u = 0; u < UNROLL - (mutant == 1 ? 1u : 0u); u++) ffma(e, x, x, fone, 0, fone); 70 iadd(e, i, i, one); 71 bra(e, top); 72 loop_end(e); 73 patch_bra(e, done, here(e)); 74 fadd(e, x, x, tag); 75 isetp_ge_u32(e, gid, n); 76 { Region r = skip_if_p0(e); imadw(e, a64, gid, 4u, pout); stg(e, a64, 0, x, udesc); region_end(e, r); } 77 tail(e); 78 return e->err; 79 } 80 81 /* copy: out[gid] = in[gid] + 1 (mutant 1: + 2) */ 82 static int gen_copy(Em *e, int mutant) { 83 int udesc = UV64(e), pin = V64(e), pout = V64(e), a64 = V64(e), n = V(e), tid = V(e), cta = V(e), gid = V(e), add = V(e), v = V(e); 84 if (e->err) return -1; 85 ldcu64(e, udesc, 0x358); 86 ldc64(e, pin, A_OUT); ldc64(e, pout, A_ITERS); ldc32(e, n, A_N); 87 s2r(e, tid, BW_SR_TID_X); s2r(e, cta, BW_SR_CTAID_X); 88 imadi(e, gid, cta, 0, THREADS, tid); 89 movi(e, add, mutant == 1 ? 0x40000000u : 0x3f800000u); 90 isetp_ge_u32(e, gid, n); 91 { 92 Region r = skip_if_p0(e); 93 imadw(e, a64, gid, 4u, pin); ldg32(e, v, a64, udesc, 1); 94 fadd(e, v, v, add); 95 imadw(e, a64, gid, 4u, pout); stg(e, a64, 0, v, udesc); 96 region_end(e, r); 97 } 98 tail(e); 99 return e->err; 100 } 101 102 static int codegen(int copy, int mutant, BlackwellIRProgram *prog) { 103 omega_bw_ir_init(prog); 104 Em em; memset(&em, 0, sizeof em); em.p = prog; 105 if ((copy ? gen_copy(&em, mutant) : gen_spin(&em, mutant)) != 0 || em.err || em.depth != 0) return -1; 106 return omega_bw_regalloc_solve(prog); 107 } 108 109 static void spin_args(uint32_t a[ARGS], uint64_t out, uint32_t iters, float tag) { 110 memset(a, 0, ARGS * 4u); 111 a[0] = (uint32_t)out; a[1] = (uint32_t)(out >> 32); a[2] = iters; a[3] = f2u(tag); a[4] = NEL; 112 } 113 static void copy_args(uint32_t a[ARGS], uint64_t in, uint64_t out) { 114 memset(a, 0, ARGS * 4u); 115 a[0] = (uint32_t)in; a[1] = (uint32_t)(in >> 32); a[2] = (uint32_t)out; a[3] = (uint32_t)(out >> 32); a[4] = NEL; 116 } 117 static float spin_value(uint32_t iters, float tag) { return (float)(UNROLL * iters) + tag; } 118 119 /* ------------------------------------------------------------------ host + simulator */ 120 121 static void host_only(void) { 122 char w[200]; 123 for (int copy = 0; copy < 2; copy++) 124 for (int mut = 0; mut < 2; mut++) { 125 BlackwellIRProgram *p = calloc(1, sizeof *p); 126 size_t need = 0; 127 int ok = p && codegen(copy, mut, p) == 0 && (need = omega_bw_program_code_bytes(p)) > 0; 128 void *code = ok ? calloc(1, need) : NULL; 129 OmegaBlackwellKernel kk; 130 ok = ok && code && omega_blackwell_kernel_encode_into(p, code, need, &kk) == 0 && kk.code_size == need; 131 snprintf(w, sizeof w, "codegen + encode: %s kernel%s (%zu bytes, %u registers)", copy ? "copy" : "spin", mut ? " mutant 1" : "", 132 need, ok ? kk.gpr_count : 0u); 133 check(ok, w); 134 free(code); free(p); 135 } 136 check(omega_gpu_cmdlist_wait_for(NULL, NULL, 0) == -1, "wait_for refuses missing lists"); 137 } 138 139 static int sim_run(BlackwellIRProgram *p, const uint32_t a[ARGS], WsRange *rg, int nrg, int order) { 140 static WsSim s; 141 memset(&s, 0, sizeof s); 142 s.p = p; s.threads = THREADS; s.order = order; 143 for (unsigned i = 0; i < ARGS; i++) s.cbank[0x380 / 4 + i] = a[i]; 144 memcpy(s.ranges, rg, (size_t)nrg * sizeof *rg); s.nranges = nrg; 145 if (ws_run(&s, CTAS, 1) != 0) { printf(" simulator: %s at pc %d\n", s.msg, s.err_pc); return -1; } 146 return 0; 147 } 148 149 static void sim_tier(void) { 150 char w[200]; 151 static float X[NEL], Y[NEL]; 152 WsRange rg[2] = { { (uintptr_t)X, (uintptr_t)(X + NEL) }, { (uintptr_t)Y, (uintptr_t)(Y + NEL) } }; 153 for (int mut = 0; mut < 2; mut++) { 154 BlackwellIRProgram *ps = calloc(1, sizeof *ps), *pc = calloc(1, sizeof *pc); 155 if (!ps || !pc || codegen(0, mut, ps) || codegen(1, mut, pc)) { check(0, "simulator: kernels built"); free(ps); free(pc); return; } 156 for (int order = 0; order < 2; order++) { 157 const uint32_t iters = 37u + (uint32_t)order; 158 const float tag = 5.0f + (float)order; 159 uint32_t a[ARGS]; 160 for (unsigned i = 0; i < NEL; i++) { uint32_t pz = POISON; memcpy(&X[i], &pz, 4); memcpy(&Y[i], &pz, 4); } 161 spin_args(a, (uintptr_t)X, iters, tag); 162 int rc = sim_run(ps, a, rg, 2, order); 163 copy_args(a, (uintptr_t)X, (uintptr_t)Y); 164 rc = rc || sim_run(pc, a, rg, 2, order); 165 unsigned wx = 0, wy = 0; 166 for (unsigned i = 0; i < NEL; i++) { 167 wx += f2u(X[i]) != f2u(spin_value(iters, tag)); 168 wy += f2u(Y[i]) != f2u(spin_value(iters, tag) + 1.0f); 169 } 170 if (mut == 0) snprintf(w, sizeof w, "simulator order %d: spin + copy exact on all %u elements (%u, %u wrong)", order, NEL, wx, wy); 171 else snprintf(w, sizeof w, "simulator red check order %d: mutant 1 caught (%u, %u wrong)", order, wx, wy); 172 check(mut == 0 ? rc == 0 && wx == 0 && wy == 0 : rc != 0 || (wx > 0 && wy > 0), w); 173 } 174 free(ps); free(pc); 175 } 176 } 177 178 /* ------------------------------------------------------------------ the chip */ 179 180 typedef struct { BlackwellIRProgram prog; OmegaGpuMem code; uint32_t gpr; } Kern; 181 static Kern K_spin, K_copy; 182 183 static int kern_upload(Kern *k, int copy) { 184 if (codegen(copy, 0, &k->prog) != 0) return -1; 185 size_t need = omega_bw_program_code_bytes(&k->prog); 186 if (need == 0 || omega_gpu_session_alloc_code(need, &k->code) != 0) return -1; 187 OmegaBlackwellKernel kk; 188 if (omega_blackwell_kernel_encode_into(&k->prog, k->code.cpu, need, &kk) != 0 || omega_gpu_session_sync_to_gpu(&k->code) != 0) return -1; 189 k->gpr = omega_bw_gpr_declared(kk.gpr_count); 190 if (k->gpr < 64u) k->gpr = 64u; 191 return 0; 192 } 193 194 static OmegaGpuMem g_buf; /* [OA | OB | X | Y], NEL floats each */ 195 static float *buf_at(int i) { return (float *)g_buf.cpu + (size_t)i * NEL; } 196 static uint64_t va_at(int i) { return g_buf.va + (uint64_t)i * NEL * 4u; } 197 enum { B_OA = 0, B_OB = 1, B_X = 2, B_Y = 3 }; 198 199 static void poison_all(void) { 200 uint32_t *u = g_buf.cpu; 201 for (size_t i = 0; i < 4u * NEL; i++) u[i] = POISON; 202 (void)omega_gpu_session_sync_to_gpu(&g_buf); 203 } 204 static unsigned wrong(int b, float want) { 205 (void)omega_gpu_session_sync_to_cpu(&g_buf); 206 const float *p = buf_at(b); 207 unsigned n = 0; 208 for (unsigned i = 0; i < NEL; i++) n += f2u(p[i]) != f2u(want); 209 return n; 210 } 211 212 static uint32_t g_args[8][ARGS]; /* the launches' argument words stay alive until submit */ 213 static int add_spin(OmegaGpuCmdList *cl, int slot, int out_buf, uint32_t iters, float tag) { 214 spin_args(g_args[slot], va_at(out_buf), iters, tag); 215 OmegaGpuLaunch L = { .code_va = K_spin.code.va, .gpr_count = K_spin.gpr, .threads_x = THREADS, .threads_y = 1, .grid_x = CTAS, .grid_y = 1, 216 .num_elements = NEL, .args = g_args[slot], .n_args = ARGS }; 217 return omega_gpu_cmdlist_add(cl, &L) < 0 ? -1 : 0; 218 } 219 static int add_copy(OmegaGpuCmdList *cl, int slot) { 220 copy_args(g_args[slot], va_at(B_X), va_at(B_Y)); 221 OmegaGpuLaunch L = { .code_va = K_copy.code.va, .gpr_count = K_copy.gpr, .threads_x = THREADS, .threads_y = 1, .grid_x = CTAS, .grid_y = 1, 222 .num_elements = NEL, .args = g_args[slot], .n_args = ARGS }; 223 return omega_gpu_cmdlist_add(cl, &L) < 0 ? -1 : 0; 224 } 225 226 static int cmp_u64(const void *a, const void *b) { uint64_t x = *(const uint64_t *)a, y = *(const uint64_t *)b; return x < y ? -1 : x > y; } 227 static uint64_t median(uint64_t *v, int n) { qsort(v, (size_t)n, sizeof *v, cmp_u64); return v[n / 2]; } 228 229 static OmegaGpuCmdList *g_a, *g_b, *g_ab; 230 231 /* one solo submit of a one-spin list; values checked; elapsed ns or 0 on failure */ 232 static uint64_t solo(OmegaGpuCmdList *cl, int out_buf, uint32_t iters, float tag, const OmegaGpuCmdListOpts *o) { 233 OmegaGpuCmdListStats st; 234 poison_all(); 235 if (omega_gpu_cmdlist_submit(cl, o, &st) != 0) { printf(" solo submit: %s\n", omega_gpu_session_last_error()); return 0; } 236 unsigned bad = wrong(out_buf, spin_value(iters, tag)); 237 if (bad) { printf(" solo: %u wrong values\n", bad); return 0; } 238 return st.elapsed_ns; 239 } 240 241 static int overlap(uint32_t iters, int fbn, double *ratio_out) { 242 char w[300]; 243 OmegaGpuCmdListOpts o; memset(&o, 0, sizeof o); 244 o.first_barrier_none = fbn; 245 uint64_t sa[REPS], sb[REPS], sp[REPS]; 246 for (int r = 0; r < REPS; r++) { 247 sa[r] = solo(g_a, B_OA, iters, 1.0f, &o); 248 sb[r] = solo(g_b, B_OB, iters, 2.0f, &o); 249 OmegaGpuCmdListStats s1, s2; 250 poison_all(); 251 int rc = omega_gpu_cmdlist_submit_pair(g_a, g_b, &o, &s1, &s2); 252 unsigned bad = rc ? NEL : wrong(B_OA, spin_value(iters, 1.0f)) + wrong(B_OB, spin_value(iters, 2.0f)); 253 if (rc || bad) { printf(" pair: %s, %u wrong values\n", rc ? omega_gpu_session_last_error() : "ok", bad); sp[r] = 0; } 254 else sp[r] = s1.elapsed_ns; 255 if (!sa[r] || !sb[r] || !sp[r]) { check(0, "overlap: every submit ran and every value is right"); return -1; } 256 } 257 const uint64_t ma = median(sa, REPS), mb = median(sb, REPS), mp = median(sp, REPS); 258 const double ratio = (double)mp / (double)(ma + mb); 259 *ratio_out = ratio; 260 snprintf(w, sizeof w, "overlap (%s): solo A %.3f ms, solo B %.3f ms, pair %.3f ms (medians of %d, values right): pair / (A + B) = %.3f", 261 fbn ? "first_barrier_none" : "default barrier", ma / 1e6, mb / 1e6, mp / 1e6, REPS, ratio); 262 printf("%s\n", w); 263 return 0; 264 } 265 266 static int serial_control(uint32_t iters, double *ratio_out) { 267 OmegaGpuCmdListOpts o; memset(&o, 0, sizeof o); 268 uint64_t sa[REPS], sab[REPS]; 269 for (int r = 0; r < REPS; r++) { 270 sa[r] = solo(g_a, B_OA, iters, 1.0f, &o); 271 OmegaGpuCmdListStats st; 272 poison_all(); 273 int rc = omega_gpu_cmdlist_submit(g_ab, &o, &st); 274 unsigned bad = rc ? NEL : wrong(B_OA, spin_value(iters, 1.0f)) + wrong(B_OB, spin_value(iters, 2.0f)); 275 if (!sa[r] || rc || bad) { check(0, "serial control: every submit ran and every value is right"); return -1; } 276 sab[r] = st.elapsed_ns; 277 } 278 const uint64_t ma = median(sa, REPS), mab = median(sab, REPS); 279 *ratio_out = (double)mab / (double)(2 * ma); 280 printf("serial control: solo %.3f ms, both in one list on one queue %.3f ms: ratio %.3f\n", ma / 1e6, mab / 1e6, *ratio_out); 281 return 0; 282 } 283 284 /* list A: spin into X; list B: [wait for A launch 0] copy X -> Y. Returns the count of wrong Y, or -1 on a submit failure. */ 285 static long event_run(uint32_t iters, int with_wait, int fbn) { 286 OmegaGpuCmdList *a = NULL, *b = NULL; 287 long res = -1; 288 if (omega_gpu_cmdlist_create(1, &a) || omega_gpu_cmdlist_create(1, &b)) { printf(" event: create: %s\n", omega_gpu_session_last_error()); goto out; } 289 omega_gpu_session_lock(); 290 if (add_spin(a, 4, B_X, iters, 3.0f) || (with_wait && omega_gpu_cmdlist_wait_for(b, a, 0)) || add_copy(b, 5)) { 291 omega_gpu_session_unlock(); printf(" event: add: %s\n", omega_gpu_session_last_error()); goto out; 292 } 293 OmegaGpuCmdListOpts o; memset(&o, 0, sizeof o); 294 o.first_barrier_none = fbn; 295 OmegaGpuCmdListStats s1, s2; 296 if (with_wait) { /* the refusals: a list with a wait never runs alone, nor waits on a second list */ 297 OmegaGpuCmdList *c = NULL; 298 int alone = omega_gpu_cmdlist_submit(b, &o, &s2) == -1 && strstr(omega_gpu_session_last_error(), "only in a pair") != NULL; 299 omega_gpu_session_unlock(); 300 int third = omega_gpu_cmdlist_create(1, &c) == 0; 301 omega_gpu_session_lock(); 302 third = third && add_spin(c, 6, B_OA, 1, 0.0f) == 0 && omega_gpu_cmdlist_wait_for(b, c, 0) == -1; 303 omega_gpu_session_unlock(); 304 omega_gpu_cmdlist_free(c); 305 omega_gpu_session_lock(); 306 check(alone && third, "event refusals: a list with a wait is refused alone, and cannot wait on a second list"); 307 } 308 poison_all(); 309 int rc = omega_gpu_cmdlist_submit_pair(a, b, &o, &s1, &s2); 310 if (rc) printf(" event: pair: %s\n", omega_gpu_session_last_error()); 311 else { 312 unsigned bx = wrong(B_X, spin_value(iters, 3.0f)), by = wrong(B_Y, spin_value(iters, 3.0f) + 1.0f); 313 printf(" event (%s, %s): X %u wrong, Y %u wrong of %u, pair %.3f ms\n", with_wait ? "wait" : "NO wait", fbn ? "first_barrier_none" : "default barrier", 314 bx, by, NEL, s1.elapsed_ns / 1e6); 315 res = bx ? -1 : (long)by; 316 } 317 omega_gpu_session_unlock(); 318 out: 319 omega_gpu_cmdlist_free(a); omega_gpu_cmdlist_free(b); 320 return res; 321 } 322 323 static void chip_tier(int values_only) { 324 char w[300]; 325 setenv("AIEN_OMEGA_GPU_CHANNELS", "2", 1); 326 if (omega_gpu_cmdlist_create(1, &g_a) || omega_gpu_cmdlist_create(1, &g_b) || omega_gpu_cmdlist_create(2, &g_ab)) { 327 printf("NOT_RUN: command lists: %s\n", omega_gpu_session_last_error()); exit(2); 328 } 329 omega_gpu_session_lock(); 330 if (!omega_gpu_session_open() || omega_gpu_session_alloc(4u * NEL * 4u, &g_buf) || kern_upload(&K_spin, 0) || kern_upload(&K_copy, 1)) { 331 printf("NOT_RUN: device, buffer or kernels: %s\n", omega_gpu_session_last_error()); omega_gpu_session_unlock(); exit(2); 332 } 333 OmegaGpuQueueHandle q1; 334 check(omega_gpu_session_extra_queue(1, &q1) == 0, "the second queue opens (AIEN_OMEGA_GPU_CHANNELS = 2)"); 335 336 /* calibrate: one spin of about 60 ms */ 337 uint32_t iters = 1u << 16; 338 OmegaGpuCmdListOpts o0; memset(&o0, 0, sizeof o0); 339 omega_gpu_cmdlist_reset(g_a); 340 if (add_spin(g_a, 0, B_OA, iters, 1.0f)) { check(0, "calibration list"); omega_gpu_session_unlock(); return; } 341 uint64_t t = solo(g_a, B_OA, iters, 1.0f, &o0); 342 if (!t) { check(0, "calibration spin ran with right values"); omega_gpu_session_unlock(); return; } 343 double scaled = (double)iters * 60e6 / (double)t; 344 iters = scaled > MAX_ITERS ? MAX_ITERS : (uint32_t)scaled; 345 printf("calibration: 2^16 turns took %.3f ms; using %u turns\n", t / 1e6, iters); 346 347 omega_gpu_cmdlist_reset(g_a); omega_gpu_cmdlist_reset(g_b); omega_gpu_cmdlist_reset(g_ab); 348 if (add_spin(g_a, 0, B_OA, iters, 1.0f) || add_spin(g_b, 1, B_OB, iters, 2.0f) || 349 add_spin(g_ab, 2, B_OA, iters, 1.0f) || add_spin(g_ab, 3, B_OB, iters, 2.0f)) { check(0, "timing lists"); omega_gpu_session_unlock(); return; } 350 351 if (!values_only) { 352 double r_def = 9, r_fbn = 9, r_ser = 0; 353 int ok_def = overlap(iters, 0, &r_def) == 0, ok_fbn = overlap(iters, 1, &r_fbn) == 0, ok_ser = serial_control(iters, &r_ser) == 0; 354 snprintf(w, sizeof w, "C4 overlap: two queues of the same work finish in under 0.75 of the solo sum (default %.3f, first_barrier_none %.3f)", r_def, r_fbn); 355 check((ok_def && r_def < 0.75) || (ok_fbn && r_fbn < 0.75), w); 356 snprintf(w, sizeof w, "red check: the same two spins in order on one queue do NOT pass the 0.75 bar (ratio %.3f)", r_ser); 357 check(ok_ser && r_ser >= 0.75, w); 358 } else puts("C4 overlap: NOT_RUN (values-only; timing needs an exclusive window)"); 359 omega_gpu_session_unlock(); 360 361 /* the event: positive, then the control without the wait (both barrier modes) */ 362 long pos = event_run(iters, 1, 0); 363 snprintf(w, sizeof w, "C4 event: B's copy waited for A's spin on the other queue; every Y right (%ld wrong)", pos); 364 check(pos == 0, w); 365 long neg0 = event_run(iters, 0, 0), neg1 = neg0 > 0 ? neg0 : event_run(iters, 0, 1); 366 snprintf(w, sizeof w, "negative control: without the wait B ran early and Y is wrong (default barrier %ld wrong, first_barrier_none %ld wrong)", neg0, neg1); 367 check(neg0 > 0 || neg1 > 0, w); 368 long again = event_run(iters, 1, 1); 369 snprintf(w, sizeof w, "C4 event with first_barrier_none: every Y right (%ld wrong)", again); 370 check(again == 0, w); 371 372 omega_gpu_session_lock(); 373 omega_gpu_session_free(&g_buf); omega_gpu_session_free(&K_spin.code); omega_gpu_session_free(&K_copy.code); 374 omega_gpu_session_unlock(); 375 omega_gpu_cmdlist_free(g_a); omega_gpu_cmdlist_free(g_b); omega_gpu_cmdlist_free(g_ab); 376 } 377 378 int main(int argc, char **argv) { 379 const char *tier = "chip"; 380 for (int i = 1; i < argc; i++) { 381 if (!strcmp(argv[i], "--host-only")) tier = "host"; 382 else if (!strcmp(argv[i], "--values-only")) tier = "values"; 383 else if (!strcmp(argv[i], "--sim")) tier = "sim"; 384 else { fprintf(stderr, "usage: %s [--host-only | --sim | --values-only]\n", argv[0]); return 2; } 385 } 386 if (!strcmp(tier, "host")) host_only(); 387 else if (!strcmp(tier, "sim")) { host_only(); sim_tier(); } 388 else chip_tier(!strcmp(tier, "values")); 389 if (g_failed) printf("C4 streams %s: FAIL (%d of %d)\n", tier, g_failed, g_checks); 390 else printf("C4 streams %s: PASS (%d checks)\n", tier, g_checks); 391 return g_failed ? 1 : 0; 392 }