Add Cooperative Groups examples - #486
Conversation
Signed-off-by: Jan Stephan <jan.stephan@amd.com>
Signed-off-by: Jan Stephan <jan.stephan@amd.com>
Signed-off-by: Jan Stephan <jan.stephan@amd.com>
Signed-off-by: Jan Stephan <jan.stephan@amd.com>
43a654b to
d6c2be3
Compare
|
@randyh62 @sourabhuday - I've added a new |
Signed-off-by: Jan Stephan <jan.stephan@amd.com>
…-examples into jstephan/cooperative-groups
|
|
|
Just need to use |
| A single block streams a 1D array through two LDS (shared memory) buffers, one tile at a time. | ||
| The async load of the next tile is issued into the second buffer while the current tile is consumed. | ||
| A split barrier separates the moment a thread has finished reading a buffer from the moment the | ||
| block guarantees that every thread is done. The kernel applies the element-wise operation | ||
| `out[i] = scale * in[i] + bias`, which is trivial to validate against a CPU reference. |
There was a problem hiding this comment.
Is there a reference to the docs that can be added here?
| run as independent work between `barrier_arrive` and `barrier_wait`. Correctness (no data races, | ||
| validated output) is the top priority. | ||
|
|
||
| This example targets the AMD/HIP (ROCm) backend, and it requires a ROCm version recent enough to ship `hip/cooperative_groups/memcpy_async.h`. |
There was a problem hiding this comment.
You could mention a specific version, or later than...
| This program showcases a double-buffered tile load pipeline built from two cooperative groups | ||
| APIs: the group-collective `cooperative_groups::memcpy_async` and the split barrier of a | ||
| `thread_block`. A split barrier decomposes an ordinary block barrier into two phases, | ||
| `barrier_arrive` and `barrier_wait`, so that independent work can run between them instead of every | ||
| thread blocking immediately. |
There was a problem hiding this comment.
| This program showcases a double-buffered tile load pipeline built from two cooperative groups | |
| APIs: the group-collective `cooperative_groups::memcpy_async` and the split barrier of a | |
| `thread_block`. A split barrier decomposes an ordinary block barrier into two phases, | |
| `barrier_arrive` and `barrier_wait`, so that independent work can run between them instead of every | |
| thread blocking immediately. | |
| This program demonstrates double-buffered tile load pipeline built with two cooperative groups | |
| APIs: | |
| * `cooperative_groups::memcpy_async` | |
| * The `thread_block` split barrier (`barrier_arrive()` / `barrier_wait()`) | |
| A split barrier decomposes an ordinary block barrier into two phases: | |
| * `barrier_arrive` | |
| * `barrier_wait` | |
| This separation allows useful independent work to execute between the two operations instead of forcing every thread to block immediately at a single barrier. |
| `cooperative_groups::memcpy_async` is an **asynchronous**, group-collective copy (typically | ||
| global <-> LDS). HIP does not expose a separate wait handle (there is no `cg::wait()`), so its | ||
| completion must be enforced by a following group barrier - either a `block.sync()` (as the official | ||
| reference test does) or, as in this example, the `barrier_wait` of a split barrier whose | ||
| `barrier_arrive` is issued *after* the copy. Ordering matters: the prefetch of the next tile is |
There was a problem hiding this comment.
| `cooperative_groups::memcpy_async` is an **asynchronous**, group-collective copy (typically | |
| global <-> LDS). HIP does not expose a separate wait handle (there is no `cg::wait()`), so its | |
| completion must be enforced by a following group barrier - either a `block.sync()` (as the official | |
| reference test does) or, as in this example, the `barrier_wait` of a split barrier whose | |
| `barrier_arrive` is issued *after* the copy. Ordering matters: the prefetch of the next tile is | |
| `cooperative_groups::memcpy_async()` is an **asynchronous**, group-collective copy operation, typically used to stage data between global memory and LDS (shared memory). HIP does not provide a separate completion handle or equivalent cg::wait() primitive, Therefore, completion of an asynchronous copy must be synchronized through a subsequent group barrier. The official reference test uses block.sync(), while this example relies on the `barrier_wait()` phase of a split barrier. | |
| Correct ordering is critical. The prefetch of the next tile is |
Motivation
In ROCm 7.14, we introduced new Cooperative Groups features. This example demonstrates how to use
memcpy_asyncand the new inclusive / exclusivescanfunctionality.Technical Details
Not supported for HIP SDK or CUDA.
Test Plan
Tested locally on gfx1100 lab machine.
Test Result
Works.
Added/Updated documentation?
Included Visual Studio files?
Submission Checklist