[Openmp-commits] [openmp] [OpenMP][libomptarget] Fix potential atomics ordering bug (PR #70503)

via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 27 13:15:33 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Jan Patrick Lehr (jplehr)

<details>
<summary>Changes</summary>

This addresses a potential ordering bug in the AMDGPU plugin that may cause an assertion error at runtime, due to the Slot signal not being updated.
Original author @<!-- -->carlobertolli

---
Full diff: https://github.com/llvm/llvm-project/pull/70503.diff


1 Files Affected:

- (modified) openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp (+4-4) 


``````````diff
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
index 756c5003b0d542c..c1502d680a3170b 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -1035,14 +1035,14 @@ struct AMDGPUStreamTy {
   /// should be executed. Notice we use the post action mechanism to codify the
   /// asynchronous operation.
   static bool asyncActionCallback(hsa_signal_value_t Value, void *Args) {
-    StreamSlotTy *Slot = reinterpret_cast<StreamSlotTy *>(Args);
-    assert(Slot && "Invalid slot");
-    assert(Slot->Signal && "Invalid signal");
-
     // This thread is outside the stream mutex. Make sure the thread sees the
     // changes on the slot.
     std::atomic_thread_fence(std::memory_order_acquire);
 
+    StreamSlotTy *Slot = reinterpret_cast<StreamSlotTy *>(Args);
+    assert(Slot && "Invalid slot");
+    assert(Slot->Signal && "Invalid signal");
+
     // Peform the operation.
     if (auto Err = Slot->performAction())
       FATAL_MESSAGE(1, "Error peforming post action: %s",

``````````

</details>


https://github.com/llvm/llvm-project/pull/70503


More information about the Openmp-commits mailing list