[Openmp-commits] [openmp] 32dc480 - [OpenMP][DeviceRTL] Fix an issue that thread array might be corrupted

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Thu Oct 6 13:13:40 PDT 2022


Author: Shilei Tian
Date: 2022-10-06T16:13:33-04:00
New Revision: 32dc48094b0c7074617a2b237927128ef148db6d

URL: https://github.com/llvm/llvm-project/commit/32dc48094b0c7074617a2b237927128ef148db6d
DIFF: https://github.com/llvm/llvm-project/commit/32dc48094b0c7074617a2b237927128ef148db6d.diff

LOG: [OpenMP][DeviceRTL] Fix an issue that thread array might be corrupted

The shared memory stack in the device runtime assumes no intervined uses.
D135037 breaks the assumption, potentially causing the shared stack corruption.
This patch moves the thread array to heap memory. Since it is already the slow
path, it doesn't matter that much anyway.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D135391

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/src/State.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp
index fc0c734f53aa..9e00c1fea7a7 100644
--- a/openmp/libomptarget/DeviceRTL/src/State.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -263,11 +263,11 @@ void state::enterDataEnvironment(IdentTy *Ident) {
   if (!atomic::load(ThreadStatesBitsPtr, atomic::seq_cst)) {
     uint32_t Bytes = sizeof(ThreadStates[0]) * mapping::getBlockSize();
     void *ThreadStatesPtr =
-        memory::allocShared(Bytes, "Thread state array allocation");
+        memory::allocGlobal(Bytes, "Thread state array allocation");
     if (!atomic::cas(ThreadStatesBitsPtr, uintptr_t(0),
                      reinterpret_cast<uintptr_t>(ThreadStatesPtr),
                      atomic::seq_cst, atomic::seq_cst))
-      memory::freeShared(ThreadStatesPtr, Bytes,
+      memory::freeGlobal(ThreadStatesPtr, Bytes,
                          "Thread state array allocated multiple times");
     ASSERT(atomic::load(ThreadStatesBitsPtr, atomic::seq_cst) &&
            "Expected valid thread states bit!");


        


More information about the Openmp-commits mailing list