Phase Tracking

Barriers reuse across iterations by flipping phase 0 ↔ 1

phase = 0
Iter 0
phase = 1
Iter 1
phase = 0
Iter 2
phase = 1
Iter 3
phase = 0
Iter 4
phase = 1
Iter 5
phase = 0
Iter 6
phase = 1
Iter 7

How It Works

Each barrier has a phase bit (0 or 1). After all expected arrivals, the barrier flips its phase and resets — ready for the next iteration. No reinitialization needed.
1
Producer arrives at barrier (phase 0)
2
Consumer calls try_wait(phase=0) — unblocks
3
Barrier flips to phase 1, phase ^= 1

Why Phase Tracking?

In a pipelined kernel, barriers are reused every iteration of the K-loop. Phase tracking solves the problem of "did this barrier fire for iteration i or iteration i-1?"
phase_tma = 0
for k in range(K):
  try_wait(tma_bar, phase_tma)
  phase_tma ^= 1  # flip