Skip to content

Commit

Permalink
AMDGPU: Add description for new atomicrmw metadata (llvm#85052)
Browse files Browse the repository at this point in the history
Add a spec for yet-to-be-implemented metadata to allow the backend to
fully handle atomicrmw lowering. This is the base of an alternative
to llvm#69229, which inverts the direction to be correct by default, and
extends to cover the peer device case.
  • Loading branch information
arsenm authored and aaryanshukla committed Jul 14, 2024
1 parent 27fcbb5 commit d87e085
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
78 changes: 78 additions & 0 deletions llvm/docs/AMDGPUUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,84 @@ arguments.

%val = load i32, ptr %in, align 4, !amdgpu.last.use !{}

'``amdgpu.no.remote.memory``' Metadata
---------------------------------------------

Asserts a memory operation does not access bytes in host memory, or
remote connected peer device memory (the address must be device
local). This is intended for use with :ref:`atomicrmw <i_atomicrmw>`
and other atomic instructions. This is required to emit a native
hardware instruction for some :ref:`system scope
<amdgpu-memory-scopes>` atomic operations on some subtargets. For most
integer atomic operations, this is a sufficient restriction to emit a
native atomic instruction.

An :ref:`atomicrmw <i_atomicrmw>` without metadata will be treated
conservatively as required to preserve the operation behavior in all
cases. This will typically be used in conjunction with
:ref:`\!amdgpu.no.fine.grained.memory<amdgpu_no_fine_grained_memory>`.


.. code-block:: llvm

; Indicates the atomic does not access fine-grained memory, or
; remote device memory.
%old0 = atomicrmw sub ptr %ptr0, i32 1 acquire, !amdgpu.no.fine.grained.memory !0, !amdgpu.no.remote.memory !0

; Indicates the atomic does not access peer device memory.
%old2 = atomicrmw sub ptr %ptr2, i32 1 acquire, !amdgpu.no.remote.memory !0

!0 = !{}

.. _amdgpu_no_fine_grained_memory:

'``amdgpu.no.fine.grained.memory``' Metadata
-------------------------------------------------

Asserts a memory access does not access bytes allocated in
fine-grained allocated memory. This is intended for use with
:ref:`atomicrmw <i_atomicrmw>` and other atomic instructions. This is
required to emit a native hardware instruction for some :ref:`system
scope <amdgpu-memory-scopes>` atomic operations on some subtargets. An
:ref:`atomicrmw <i_atomicrmw>` without metadata will be treated
conservatively as required to preserve the operation behavior in all
cases. This will typically be used in conjunction with
:ref:`\!amdgpu.no.remote.memory.access<amdgpu_no_remote_memory_access>`.

.. code-block:: llvm

; Indicates the access does not access fine-grained memory, or
; remote device memory.
%old0 = atomicrmw sub ptr %ptr0, i32 1 acquire, !amdgpu.no.fine.grained.memory !0, !amdgpu.no.remote.memory.access !0

; Indicates the access does not access fine-grained memory
%old2 = atomicrmw sub ptr %ptr2, i32 1 acquire, !amdgpu.no.fine.grained.memory !0

!0 = !{}

.. _amdgpu_no_remote_memory_access:

'``amdgpu.ignore.denormal.mode``' Metadata
------------------------------------------

For use with :ref:`atomicrmw <i_atomicrmw>` floating-point
operations. Indicates the handling of denormal inputs and results is
insignificant and may be inconsistent with the expected floating-point
mode. This is necessary to emit a native atomic instruction on some
targets for some address spaces where float denormals are
unconditionally flushed. This is typically used in conjunction with
:ref:`\!amdgpu.no.remote.memory.access<amdgpu_no_remote_memory_access>`
and
:ref:`\!amdgpu.no.fine.grained.memory<amdgpu_no_fine_grained_memory>`


.. code-block:: llvm

%res0 = atomicrmw fadd ptr addrspace(1) %ptr, float %value seq_cst, align 4, !amdgpu.ignore.denormal.mode !0
%res1 = atomicrmw fadd ptr addrspace(1) %ptr, float %value seq_cst, align 4, !amdgpu.ignore.denormal.mode !0, !amdgpu.no.fine.grained.memory !0, !amdgpu.no.remote.memory.access !0

!0 = !{}


LLVM IR Attributes
==================
Expand Down
2 changes: 2 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Changes to the AMDGPU Backend
-----------------------------

* Implemented the ``llvm.get.fpenv`` and ``llvm.set.fpenv`` intrinsics.
* Added ``!amdgpu.no.fine.grained.memory`` and
``!amdgpu.no.remote.memory`` metadata to control atomic behavior.

* Implemented :ref:`llvm.get.rounding <int_get_rounding>` and :ref:`llvm.set.rounding <int_set_rounding>`

Expand Down

0 comments on commit d87e085

Please sign in to comment.