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/evidence/gpu-reconv-308/T1b-GPU-RECONV-0a1812f-observe-dropped-join/bw_warp_sim.h # 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 / evidence / gpu-reconv-308 / T1b-GPU-RECONV-0a1812f-observe-dropped-join / bw_warp_sim.h` 313 lines ยท 19167 bytes Raw Blame History 1 /* bw_warp_sim.h: host SIMT simulator for the Blackwell IR (omega #308). 2 * 3 * Models what the earlier per-thread simulators could not: a warp of 32 lanes with an 4 * active mask, divergence at predicated branches, structured reconvergence through the 5 * barrier registers (BSSY arms Bn for the lanes executing it and names the join; BSYNC 6 * parks arriving lanes until every armed lane that has not exited is there, then the 7 * warp continues as one), nested regions, and lane participation in SHFL and BAR.SYNC. 8 * 9 * A warp is a set of fragments (pc, lane mask). A predicated branch whose lanes disagree 10 * splits the fragment; the scheduler then runs one fragment at a time in a chosen order 11 * (lowest pc first or highest pc first; tests run both), which is the freedom the chip's 12 * scheduler also has. Fragments only merge at a BSYNC. Errors (all fatal, first one wins): 13 * WS_E_SHFL_SPLIT a SHFL reached by a fragment that is not the whole live warp 14 * (the chip reads inactive lanes: undefined; attention 2026-10-04) 15 * WS_E_SHFL_EXITED a SHFL on a warp some of whose lanes already exited (undefined too) 16 * WS_E_BAR_SPLIT (defined, never raised) a BAR.SYNC reached by a split warp is allowed: 17 * since Volta the CTA barrier counts arriving threads, not warps (CUDA 18 * programming guide, independent thread scheduling; INFERRED for sm_121, 19 * not chip-verified by us). The simulator parks each fragment, releases 20 * them together, counts the event in bar_split_arrivals, and leaves the 21 * fragments split: a barrier is not a reconvergence point, so a SHFL after 22 * it still fails with SHFL_SPLIT unless a BSYNC rejoined the warp. 23 * WS_E_BSYNC_UNARMED BSYNC on a barrier no BSSY armed 24 * WS_E_BSSY_REARM BSSY on a barrier still armed (lanes may still be heading to its join) 25 * WS_E_JOIN_MISMATCH BSYNC at an address other than the one the BSSY named minus one 26 * WS_E_NONMEMBER a lane reached BSYNC Bn without having executed its BSSY 27 * WS_E_STUCK lanes parked at a BSYNC that can never complete (a join was dropped, 28 * an exit jumped past it, or a target was corrupted) 29 * WS_E_NEVER_JOINED the warp finished with a barrier still armed 30 * WS_E_SELF_BRANCH, WS_E_PC, WS_E_OP, WS_E_SHIFT, WS_E_MEM, WS_E_SMEM, WS_E_FRAGS 31 * Every error names the pc. Memory: global addresses are host pointers (optionally range 32 * checked); shared memory is a per-CTA buffer poisoned at CTA start so a read of a word 33 * nobody wrote shows up in the oracle comparison. 34 * 35 * Per-lane ALU semantics are those of the two earlier simulators (tests/gpu_attention_test.c, 36 * bench/prime_race/tests/gb10_sieve_host_test.c). EX2 and RCP are exact here; the chip's 37 * are approximate. LDCU64 (memory descriptor) is not modelled. */ 38 #ifndef BW_WARP_SIM_H 39 #define BW_WARP_SIM_H 40 41 #include "omega_blackwell_codegen.h" 42 #include 43 #include 44 #include 45 #include 46 #include 47 48 #define WS_WARP 32 49 #define WS_MAX_THREADS 256 50 #define WS_MAX_WARPS (WS_MAX_THREADS / WS_WARP) 51 #define WS_MAX_FRAGS 64 52 #define WS_NBAR BW_RECONV_MAX_BAR 53 #define WS_MAX_RANGES 8 54 55 enum { 56 WS_OK = 0, WS_E_SHFL_SPLIT, WS_E_SHFL_EXITED, WS_E_BAR_SPLIT, WS_E_BSYNC_UNARMED, WS_E_BSSY_REARM, 57 WS_E_JOIN_MISMATCH, WS_E_NONMEMBER, WS_E_STUCK, WS_E_NEVER_JOINED, WS_E_SELF_BRANCH, WS_E_PC, 58 WS_E_OP, WS_E_SHIFT, WS_E_MEM, WS_E_SMEM, WS_E_FRAGS, WS_E_BAR_TIMEOUT, WS_E_STEPS 59 }; 60 static const char *ws_err_name(int e) { 61 static const char *const n[] = { "OK", "SHFL_SPLIT", "SHFL_EXITED", "BAR_SPLIT", "BSYNC_UNARMED", "BSSY_REARM", 62 "JOIN_MISMATCH", "NONMEMBER", "STUCK", "NEVER_JOINED", "SELF_BRANCH", "PC", "OP", "SHIFT", "MEM", "SMEM", 63 "FRAGS", "BAR_TIMEOUT", "STEPS" }; 64 return (e >= 0 && e < (int)(sizeof n / sizeof n[0])) ? n[e] : "?"; 65 } 66 67 typedef struct { uint32_t r[256]; uint8_t p0; } WsLane; 68 typedef struct { int pc; uint32_t mask; int parked; /* waiting at a BAR.SYNC */ } WsFrag; 69 typedef struct { int valid; int target; uint32_t members, arrived; } WsBar; 70 typedef struct { 71 WsLane lane[WS_WARP]; 72 WsFrag frag[WS_MAX_FRAGS]; 73 int nfrag; 74 WsBar bar[WS_NBAR]; 75 uint32_t exited; 76 } WsWarp; 77 typedef struct { uintptr_t lo, hi; } WsRange; 78 79 typedef struct { 80 const BlackwellIRProgram *p; 81 uint32_t cbank[256]; /* constant bank 0 words (byte offset / 4) */ 82 uint32_t threads; /* per CTA, a multiple of 32, <= WS_MAX_THREADS */ 83 uint8_t *smem; /* per-CTA shared memory buffer (poisoned at CTA start) */ 84 uint32_t smem_bytes; 85 WsRange ranges[WS_MAX_RANGES]; int nranges; /* when > 0, every global access must fall in one */ 86 int order; /* 0 = lowest pc first, 1 = highest pc first */ 87 int trace; /* print every issue of warp 0 of CTA (0,0) */ 88 /* results */ 89 int err; int err_pc; char msg[200]; 90 uint64_t warp_issues; /* fragment-instruction issues (the chip's cost unit for divergence) */ 91 uint64_t lane_issues; /* lanes active over those issues */ 92 uint64_t splits; /* branches that split a fragment */ 93 uint64_t bar_split_arrivals; /* BAR.SYNC reached by a fragment that is not the whole live warp */ 94 int max_frags, peak_bars; 95 } WsSim; 96 97 static void ws_fail(WsSim *s, int err, int pc, const char *what) { 98 if (s->err) return; 99 s->err = err; s->err_pc = pc; 100 snprintf(s->msg, sizeof s->msg, "%s at pc %d: %s", ws_err_name(err), pc, what ? what : ""); 101 } 102 103 static uint32_t ws_rd(const WsLane *l, int v, const BlackwellIRProgram *p) { if (v < 0) return 0; int ph = p->regalloc.vreg_to_phys[v]; return ph < 0 ? 0 : l->r[ph & 0xff]; } 104 static uint64_t ws_rd64(const WsLane *l, int v, const BlackwellIRProgram *p) { if (v < 0) return 0; int ph = p->regalloc.vreg_to_phys[v] & 0xff; return (uint64_t)l->r[ph] | ((uint64_t)l->r[(ph + 1) & 0xff] << 32); } 105 static void ws_wr(WsLane *l, int v, uint32_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v]; if (ph >= 0) l->r[ph & 0xff] = x; } 106 static void ws_wr64(WsLane *l, int v, uint64_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v] & 0xff; l->r[ph] = (uint32_t)x; l->r[(ph + 1) & 0xff] = (uint32_t)(x >> 32); } 107 static float ws_u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } 108 static uint32_t ws_f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } 109 static uint32_t ws_lut3(uint32_t lut, uint32_t a, uint32_t b, uint32_t c) { 110 uint32_t r = 0; 111 for (int i = 0; i < 8; i++) if (lut >> i & 1) r |= ((i & 4) ? a : ~a) & ((i & 2) ? b : ~b) & ((i & 1) ? c : ~c); 112 return r; 113 } 114 static int ws_mem_ok(WsSim *s, uint64_t a, unsigned bytes, int pc) { 115 if (s->nranges == 0) return 1; 116 for (int i = 0; i < s->nranges; i++) if (a >= s->ranges[i].lo && a + bytes <= s->ranges[i].hi) return 1; 117 ws_fail(s, WS_E_MEM, pc, "global access outside the declared buffers"); return 0; 118 } 119 static uint32_t *ws_smem(WsSim *s, uint32_t a, int pc) { 120 if ((a & 3) || a + 4 > s->smem_bytes) { ws_fail(s, WS_E_SMEM, pc, "shared access past the declared size"); return NULL; } 121 return (uint32_t *)(s->smem + a); 122 } 123 static int ws_popc(uint32_t m) { return __builtin_popcount(m); } 124 125 /* One lane, one non-control instruction. */ 126 static void ws_lane_exec(WsSim *s, WsLane *l, const BlackwellIRInsn *in, int pc, uint32_t tid, uint32_t cx, uint32_t cy) { 127 const BlackwellIRProgram *p = s->p; 128 uint32_t a = ws_rd(l, in->src1_vreg, p), b = ws_rd(l, in->src2_vreg, p), c = ws_rd(l, in->src3_vreg, p); 129 switch (in->op) { 130 case BW_IR_NOP: break; 131 case BW_IR_S2R: ws_wr(l, in->dst_vreg, in->imm == BW_SR_TID_X ? tid : in->imm == BW_SR_CTAID_X ? cx : in->imm == BW_SR_CTAID_Y ? cy : 0, p); break; 132 case BW_IR_LDC: ws_wr(l, in->dst_vreg, s->cbank[(in->imm / 4) & 0xff], p); break; 133 case BW_IR_LDC64: ws_wr64(l, in->dst_vreg, (uint64_t)s->cbank[(in->imm / 4) & 0xff] | ((uint64_t)s->cbank[(in->imm / 4 + 1) & 0xff] << 32), p); break; 134 case BW_IR_LDCU64: case BW_IR_LDCU: break; /* memory descriptor: not modelled */ 135 case BW_IR_MOV_IMM: ws_wr(l, in->dst_vreg, in->imm, p); break; 136 case BW_IR_MOV_RZ: ws_wr(l, in->dst_vreg, 0, p); break; 137 case BW_IR_IMAD: ws_wr(l, in->dst_vreg, in->src2_vreg >= 0 ? a * b + c : a * in->imm + c, p); break; 138 case BW_IR_IMAD_WIDE: ws_wr64(l, in->dst_vreg, (uint64_t)a * in->imm + ws_rd64(l, in->src3_vreg, p), p); break; 139 case BW_IR_IMAD_HI_U32: ws_wr(l, in->dst_vreg, (uint32_t)(((uint64_t)a * b) >> 32) + c, p); break; 140 case BW_IR_IADD3: ws_wr(l, in->dst_vreg, a + b, p); break; /* the encoder's IADD3 has Rc = RZ */ 141 case BW_IR_SHF_R: ws_wr(l, in->dst_vreg, a >> (in->imm & 31), p); break; 142 case BW_IR_SHF_L_U32: if (b >= 32) { ws_fail(s, WS_E_SHIFT, pc, "SHF.L.U32 amount >= 32 (not chip-verified)"); return; } ws_wr(l, in->dst_vreg, a << b, p); break; 143 case BW_IR_LOP3_AND: ws_wr(l, in->dst_vreg, a & in->imm, p); break; 144 case BW_IR_LOP3_XOR: ws_wr(l, in->dst_vreg, a ^ b, p); break; 145 case BW_IR_LOP3_LUT: ws_wr(l, in->dst_vreg, ws_lut3(in->imm & 0xff, a, b, c), p); break; 146 case BW_IR_ISETP_GE_U32: l->p0 = a >= b; break; 147 case BW_IR_LDG_E: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t x; memcpy(&x, (const void *)(uintptr_t)ad, 4); ws_wr(l, in->dst_vreg, x, p); break; } 148 case BW_IR_LDG_E_U16: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 2, pc)) return; uint16_t x; memcpy(&x, (const void *)(uintptr_t)ad, 2); ws_wr(l, in->dst_vreg, x, p); break; } 149 case BW_IR_STG_E: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; memcpy((void *)(uintptr_t)ad, &b, 4); break; } 150 case BW_IR_LDS32: { uint32_t *m = ws_smem(s, a, pc); if (!m) return; ws_wr(l, in->dst_vreg, *m, p); break; } 151 case BW_IR_STS32: { uint32_t *m = ws_smem(s, a, pc); if (!m) return; *m = b; break; } 152 case BW_IR_FADD: ws_wr(l, in->dst_vreg, ws_f2u(ws_u2f(a) + ws_u2f(b)), p); break; 153 case BW_IR_FSUB: ws_wr(l, in->dst_vreg, ws_f2u(ws_u2f(a) - ws_u2f(b)), p); break; 154 case BW_IR_FMUL: ws_wr(l, in->dst_vreg, ws_f2u(ws_u2f(a) * ws_u2f(b)), p); break; 155 case BW_IR_FFMA: ws_wr(l, in->dst_vreg, ws_f2u(fmaf(ws_u2f(a), ws_u2f(b), ws_u2f(c))), p); break; 156 case BW_IR_FMNMX_MAX: ws_wr(l, in->dst_vreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; 157 case BW_IR_FMNMX_MIN: ws_wr(l, in->dst_vreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; 158 case BW_IR_MUFU_EX2: ws_wr(l, in->dst_vreg, ws_f2u(exp2f(ws_u2f(a))), p); break; 159 case BW_IR_MUFU_RCP: ws_wr(l, in->dst_vreg, ws_f2u(1.0f / ws_u2f(a)), p); break; 160 case BW_IR_MUFU_RSQ: ws_wr(l, in->dst_vreg, ws_f2u(1.0f / sqrtf(ws_u2f(a))), p); break; 161 default: ws_fail(s, WS_E_OP, pc, "opcode not modelled"); return; 162 } 163 } 164 165 static int ws_pick(const WsSim *s, const WsWarp *w) { 166 int best = -1; 167 for (int i = 0; i < w->nfrag; i++) { 168 if (w->frag[i].mask == 0 || w->frag[i].parked) continue; 169 if (best < 0) { best = i; continue; } 170 if (s->order == 0 ? w->frag[i].pc < w->frag[best].pc : w->frag[i].pc > w->frag[best].pc) best = i; 171 } 172 return best; 173 } 174 static void ws_drop_frag(WsWarp *w, int i) { w->frag[i] = w->frag[--w->nfrag]; } 175 static int ws_add_frag(WsSim *s, WsWarp *w, int pc, uint32_t mask) { 176 if (mask == 0) return 0; 177 if (w->nfrag >= WS_MAX_FRAGS) { ws_fail(s, WS_E_FRAGS, pc, "too many fragments"); return -1; } 178 w->frag[w->nfrag].pc = pc; w->frag[w->nfrag].mask = mask; w->frag[w->nfrag].parked = 0; w->nfrag++; 179 if (w->nfrag > s->max_frags) s->max_frags = w->nfrag; 180 return 0; 181 } 182 183 /* Runs one warp until it has no runnable fragment (finished, parked at BAR.SYNC, or stuck). 184 * Returns 1 when parked at BAR.SYNC, 0 when finished, -1 on error. */ 185 static int ws_run_warp(WsSim *s, WsWarp *w, uint32_t warp, uint32_t cx, uint32_t cy, int trace) { 186 const BlackwellIRProgram *p = s->p; 187 const uint32_t live_all = 0xffffffffu; 188 for (uint64_t guard = 0;; guard++) { 189 if (s->err) return -1; 190 if (guard > 2000000000ull) { ws_fail(s, WS_E_STEPS, -1, "step budget"); return -1; } 191 int fi = ws_pick(s, w); 192 if (fi < 0) { 193 /* nothing runnable: parked at the CTA barrier, finished, or lanes waiting at a BSYNC 194 * that can never complete */ 195 for (int i = 0; i < w->nfrag; i++) if (w->frag[i].parked) return 1; 196 for (int b = 0; b < WS_NBAR; b++) if (w->bar[b].valid) { 197 if (w->bar[b].arrived) { ws_fail(s, WS_E_STUCK, w->bar[b].target - 1, "lanes parked at BSYNC, the rest never arrive"); return -1; } 198 ws_fail(s, WS_E_NEVER_JOINED, w->bar[b].target - 1, "warp finished with a barrier still armed"); return -1; 199 } 200 return 0; 201 } 202 WsFrag *f = &w->frag[fi]; 203 int pc = f->pc; 204 if (pc < 0 || (size_t)pc >= p->count) { ws_fail(s, WS_E_PC, pc, "pc outside the program"); return -1; } 205 const BlackwellIRInsn *in = &p->insns[pc]; 206 uint32_t mask = f->mask; 207 s->warp_issues++; s->lane_issues += (uint64_t)ws_popc(mask); 208 if (trace) printf("W%u pc=%d op=%d mask=%08x frags=%d\n", warp, pc, (int)in->op, mask, w->nfrag); 209 uint32_t live = live_all & ~w->exited; 210 uint32_t pmask = 0; 211 for (int L = 0; L < WS_WARP; L++) if ((mask >> L & 1) && w->lane[L].p0) pmask |= 1u << L; 212 uint32_t cond = in->predicate_p0 ? (in->predicate_not ? (mask & ~pmask) : (mask & pmask)) : mask; 213 switch (in->op) { 214 case BW_IR_EXIT: { 215 w->exited |= cond; 216 f->mask = mask & ~cond; 217 if (f->mask == 0) ws_drop_frag(w, fi); else f->pc = pc + 1; 218 break; 219 } 220 case BW_IR_BRA: { 221 int32_t delta = (int32_t)in->imm; 222 uint32_t taken = cond, fall = mask & ~cond; 223 if (taken && delta == 0) { ws_fail(s, WS_E_SELF_BRANCH, pc, "branch to itself"); return -1; } 224 if (taken && fall) s->splits++; 225 if (taken == 0) { f->pc = pc + 1; break; } 226 if (fall == 0) { f->pc = pc + delta; break; } 227 f->mask = fall; f->pc = pc + 1; 228 if (ws_add_frag(s, w, pc + delta, taken) < 0) return -1; 229 break; 230 } 231 case BW_IR_BSSY: { 232 WsBar *b = &w->bar[in->bar_reg & (WS_NBAR - 1)]; 233 if (in->bar_reg >= WS_NBAR) { ws_fail(s, WS_E_OP, pc, "barrier id"); return -1; } 234 if (b->valid) { ws_fail(s, WS_E_BSSY_REARM, pc, "BSSY on an armed barrier"); return -1; } 235 b->valid = 1; b->target = pc + (int32_t)in->imm; b->members = cond; b->arrived = 0; 236 int armed = 0; for (int k = 0; k < WS_NBAR; k++) armed += w->bar[k].valid; 237 if (armed > s->peak_bars) s->peak_bars = armed; 238 f->pc = pc + 1; 239 break; 240 } 241 case BW_IR_BSYNC: { 242 if (in->bar_reg >= WS_NBAR) { ws_fail(s, WS_E_OP, pc, "barrier id"); return -1; } 243 WsBar *b = &w->bar[in->bar_reg]; 244 if (!b->valid) { ws_fail(s, WS_E_BSYNC_UNARMED, pc, "BSYNC without a BSSY"); return -1; } 245 if (cond & ~b->members) { ws_fail(s, WS_E_NONMEMBER, pc, "a lane at BSYNC did not execute the BSSY"); return -1; } 246 b->arrived |= cond; 247 uint32_t rest = mask & ~cond; /* a predicated-off lane walks on */ 248 if (rest) { f->mask = rest; f->pc = pc + 1; } else ws_drop_frag(w, fi); 249 if (b->arrived == (b->members & ~w->exited)) { 250 if (b->target != pc + 1) { ws_fail(s, WS_E_JOIN_MISMATCH, pc, "BSSY named a different join point"); return -1; } 251 uint32_t joined = b->arrived; b->valid = 0; b->arrived = 0; b->members = 0; 252 if (ws_add_frag(s, w, pc + 1, joined) < 0) return -1; 253 } 254 break; 255 } 256 case BW_IR_SHFL_DOWN: { 257 if (w->exited) { ws_fail(s, WS_E_SHFL_EXITED, pc, "SHFL on a warp with exited lanes"); return -1; } 258 if (mask != live) { ws_fail(s, WS_E_SHFL_SPLIT, pc, "SHFL on a split warp"); return -1; } 259 uint32_t src[WS_WARP]; 260 for (int L = 0; L < WS_WARP; L++) src[L] = ws_rd(&w->lane[L], in->src1_vreg, p); 261 for (int L = 0; L < WS_WARP; L++) { int from = L + (int)(in->imm & 31); ws_wr(&w->lane[L], in->dst_vreg, from < WS_WARP ? src[from] : src[L], p); } 262 f->pc = pc + 1; 263 break; 264 } 265 case BW_IR_BAR_SYNC: { 266 if (mask != live) s->bar_split_arrivals++; 267 f->parked = 1; /* released by ws_run when every live lane of the CTA has arrived */ 268 break; 269 } 270 default: { 271 for (int L = 0; L < WS_WARP; L++) if (mask >> L & 1) { 272 ws_lane_exec(s, &w->lane[L], in, pc, warp * WS_WARP + (uint32_t)L, cx, cy); 273 if (s->err) return -1; 274 } 275 f->pc = pc + 1; 276 break; 277 } 278 } 279 } 280 } 281 282 /* Runs every CTA of the grid. Returns s->err (0 = clean). */ 283 static int ws_run(WsSim *s, uint32_t grid_x, uint32_t grid_y) { 284 s->err = 0; s->msg[0] = 0; s->warp_issues = s->lane_issues = s->splits = s->bar_split_arrivals = 0; s->max_frags = 0; s->peak_bars = 0; 285 if (!s->p || s->threads == 0 || s->threads % WS_WARP || s->threads > WS_MAX_THREADS) { ws_fail(s, WS_E_OP, -1, "bad simulator configuration"); return s->err; } 286 static WsWarp warps[WS_MAX_WARPS]; 287 uint32_t nw = s->threads / WS_WARP; 288 for (uint32_t cy = 0; cy < grid_y && !s->err; cy++) for (uint32_t cx = 0; cx < grid_x && !s->err; cx++) { 289 memset(warps, 0, sizeof(WsWarp) * nw); 290 if (s->smem && s->smem_bytes) for (uint32_t i = 0; i + 4 <= s->smem_bytes; i += 4) { uint32_t poison = 0xfeedfaceu; memcpy(s->smem + i, &poison, 4); } 291 for (uint32_t w = 0; w < nw; w++) { warps[w].nfrag = 1; warps[w].frag[0].pc = 0; warps[w].frag[0].mask = 0xffffffffu; warps[w].frag[0].parked = 0; } 292 int trace = s->trace && cx == 0 && cy == 0; 293 /* Barrier phases: every warp runs until all of its fragments are parked at BAR.SYNC or it 294 * has finished (exited lanes do not hold the barrier up: INFERRED, see WS_E_BAR_SPLIT). 295 * Then every parked fragment is released and the next phase starts. */ 296 for (int phase = 0; ; phase++) { 297 int parked = 0; 298 for (uint32_t w = 0; w < nw && !s->err; w++) { 299 if (warps[w].nfrag == 0) continue; 300 int r = ws_run_warp(s, &warps[w], w, cx, cy, trace && w == 0); 301 if (r < 0) break; 302 if (r == 1) parked++; 303 } 304 if (s->err || parked == 0) break; /* error, or every warp finished */ 305 for (uint32_t w = 0; w < nw; w++) for (int i = 0; i < warps[w].nfrag; i++) 306 if (warps[w].frag[i].parked) { warps[w].frag[i].parked = 0; warps[w].frag[i].pc++; } 307 if (phase > 100000) { ws_fail(s, WS_E_BAR_TIMEOUT, -1, "barrier phases"); break; } 308 } 309 } 310 return s->err; 311 } 312 313 #endif /* BW_WARP_SIM_H */