[llvm] AMDGPU: Preliminary documentation for named barriers (PR #165502)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 29 03:15:55 PDT 2025
================
@@ -6621,6 +6668,138 @@ Multiple tags can be used at the same time to synchronize with more than one add
better code optimization, at the cost of synchronizing additional address
spaces.
+.. _amdgpu-memory-model-barriers:
+
+Hardware Barriers
++++++++++++++++++
+
+.. note::
+
+ This section is preliminary. The semantics described here are intended to be
+ formalized properly in the future.
+
+Hardware barriers synchronize execution between concurrently running waves using
+fixed function hardware. Intuitively, a set of waves are "members" of a barrier.
+Waves *signal* the barrier and later *wait* for it. Execution only proceeds past
+the *wait* once all member waves have *signaled* the barrier.
+
+Formally, barriers affect semantics in exactly two ways. First, they affect
+forward progress. Waiting on a barrier that never completes (is not signaled
+sufficiently) prevents forward progress and therefore, given the assumption of
+forward progress, is undefined behavior. Second, barrier operations can pair
+with fences to contribute *synchronizes-with* relations in the memory model.
+
+Roughly speaking:
+
+- Release fences pair with barrier signal operations that are later in program
+ order
+- Barrier wait operations pair with acquire fences that are later in program
+ order
+- If a barrier signal operation contributes to allowing a wait operation to
+ complete, then the corresponding paired fences can synchronize-with each
+ other (given compatible sync scopes and memory model relaxation annotations)
+
+Default Barriers
+################
+
+There is a default workgroup barrier and a default cluster barrier. All waves
+of a workgroup and cluster are members of the same default workgroup and
+cluster barriers, respectively.
+
+.. _amdgpu-memory-model-named-barriers:
+
+Named Barriers
+##############
+
+All named barrier operations must occur in wave-uniform control flow. All
+arguments of named barrier intrinsics must be wave-uniform.
+
+Named barriers are allocated as global variables of
+:ref:`a target extension type <amdgpu-types-named-barriers>`.
+
+Named barriers may be signaled by the intrinsics:
+
+.. code-block:: llvm
+
+ declare void @llvm.amdgcn.s.barrier.signal(i32 %barrier_hw_id)
----------------
jayfoad wrote:
Should this be `i32 %barrier_type` for consistency with other intrinsics below? (TBH I'm a bit confused about the meaning of the i32 argument, for the intrinsics that don't take a ptr argument.)
https://github.com/llvm/llvm-project/pull/165502
More information about the llvm-commits
mailing list