[Openmp-commits] [PATCH] D135391: [OpenMP][DeviceRTL] Fix an issue that thread array might be corrupted

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Oct 6 12:57:51 PDT 2022


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, jhuber6.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

The shared memory stack in the device runtime assumes no intervined uses.
D135037 <https://reviews.llvm.org/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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135391

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


Index: openmp/libomptarget/DeviceRTL/src/State.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/State.cpp
+++ openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -263,11 +263,11 @@
   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::allocGlogal(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!");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135391.465839.patch
Type: text/x-patch
Size: 1013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20221006/30fd2074/attachment.bin>


More information about the Openmp-commits mailing list