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

Jan Patrick Lehr via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 27 13:14:01 PDT 2023


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

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

>From a86a259a1cab4610b439203fd3bdcc7a8cb8fa35 Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Fri, 27 Oct 2023 16:08:57 -0400
Subject: [PATCH] [OpenMP][libomptarget] Fix potential atomics ordering bug

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
---
 openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

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",



More information about the Openmp-commits mailing list