You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d06790e
Browse filesBrowse the repository at this point in the historyBrowse files
Puzzle 29's double-buffered stencil now uses mbarrier the way the PTX
contract specifies, and its page teaches that pattern, so readers no
longer learn a wait that only works by coincidence.
MODULAR_ORIG_COMMIT_REV_ID: f725593c5c03eb6936c7acc3f841162428ab6237
Copy file name to clipboardExpand all lines: book/src/puzzle_29/memory_barrier.md
+31-20Lines changed: 31 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ NVIDIA-only.
25
25
> -**Precise control**: [`mbarrier_init()`](https://max.modular.com/api/mojo/max/gpu/sync/sync/mbarrier_init) sets up reusable barrier objects with specific thread counts
> -**Flexible waiting**: [`mbarrier_test_wait()`](https://max.modular.com/api/mojo/max/gpu/sync/sync/mbarrier_test_wait) polls a completion state without blocking, so you decide what a thread does while waiting
28
-
> -**Reusable objects**: Same barrier can be reinitialized and reused across multiple iterations
28
+
> -**Reusable objects**: Once every thread arrives, a barrier advances to its next phase on its own, so the same object serves every iteration without being reinitialized
29
29
> -**Multiple barriers**: Different barrier objects for different synchronization points (initialization, iteration, finalization)
30
30
> -**Hardware primitive**: Maps directly to the NVIDIA `mbarrier` instructions rather than to a single block-wide barrier
31
31
> -**Memory semantics**: Explicit control over memory visibility and ordering guarantees
@@ -38,7 +38,7 @@ NVIDIA-only.
38
38
>
39
39
> -**Buffer role alternation**: An arrival count scoped to the threads that wrote the buffer about to be read
40
40
> -**Iteration boundaries**: Separate barrier objects for initialization, the iteration loop, and finalization
41
-
> -**State management**: `mbarrier_arrive()` returns a state token, so arrival can be tracked and not merely awaited
41
+
> -**State management**: `mbarrier_arrive()` returns a token for the barrier's current phase, so arrival can be tracked and not merely awaited
42
42
> -**Composability**: The same primitive tracks `cp.async` and TMA transfer completion on newer hardware
43
43
>
44
44
> This puzzle demonstrates **synchronization patterns** used in real-world GPU
@@ -194,7 +194,9 @@ when memory operations complete, essential for complex memory access patterns.
194
194
loop
195
195
-**Buffer swap safety**: Prevents reading from buffer while others still
196
196
writing
197
-
-**Barrier reinitialization**: Reset barrier state between iterations
197
+
-**Phase tracking**: Each thread waits on the token its own `mbarrier_arrive()`
198
+
returned; the barrier moves to its next phase by itself, so it is never
199
+
reinitialized inside the loop
198
200
199
201
**Output phase:**
200
202
@@ -240,19 +242,23 @@ when memory operations complete, essential for complex memory access patterns.
0 commit comments