[Openmp-commits] [openmp] e3ee762 - [Libomptarget] Revert new variable sharing to use the old method

via Openmp-commits openmp-commits at lists.llvm.org
Tue Jul 27 15:14:11 PDT 2021


Author: Joseph Huber
Date: 2021-07-27T18:14:01-04:00
New Revision: e3ee76245ead4eebad2aec0e24c2582ffa9c7378

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

LOG: [Libomptarget] Revert new variable sharing to use the old method

The new method of sharing variables introduces a `__kmpc_alloc_shared` call
that cannot be removed in the middle end because of its non-constant argument
and unconnected free. This patch reverts this to the old method that used a
static amount of shared memory for sharing variables.

Reviewed By: jdoerfert

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

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/include/Interface.h
    openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
    openmp/libomptarget/DeviceRTL/src/State.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/include/Interface.h b/openmp/libomptarget/DeviceRTL/include/Interface.h
index 1c4c877b7662e..21ff48c30d2cc 100644
--- a/openmp/libomptarget/DeviceRTL/include/Interface.h
+++ b/openmp/libomptarget/DeviceRTL/include/Interface.h
@@ -186,7 +186,7 @@ void __kmpc_begin_sharing_variables(void ***GlobalArgs, uint64_t NumArgs);
 /// Deallocate the memory allocated by __kmpc_begin_sharing_variables.
 ///
 /// Called by the main thread after a parallel region.
-void __kmpc_end_sharing_variables(void **GlobalArgs, uint64_t NumArgs);
+void __kmpc_end_sharing_variables();
 
 /// Store the allocation address obtained via __kmpc_begin_sharing_variables in
 /// \p GlobalArgs.

diff  --git a/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp b/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
index 7b505545f92fe..367c2966f10e9 100644
--- a/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
@@ -143,8 +143,7 @@ void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
   }
 
   if (nargs)
-    memory::freeShared(GlobalArgs, nargs * sizeof(void *),
-                       "global args free shared");
+    __kmpc_end_sharing_variables();
 }
 
 __attribute__((noinline)) bool

diff  --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp
index fb472c9bbe4d2..dae262a040820 100644
--- a/openmp/libomptarget/DeviceRTL/src/State.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -497,19 +497,32 @@ __attribute__((noinline)) void __kmpc_free_shared(void *Ptr, uint64_t Bytes) {
   memory::freeShared(Ptr, Bytes, "Frontend free shared");
 }
 
+/// Allocate storage in shared memory to communicate arguments from the main
+/// thread to the workers in generic mode. If we exceed
+/// NUM_SHARED_VARIABLES_IN_SHARED_MEM we will malloc space for communication.
+constexpr uint64_t NUM_SHARED_VARIABLES_IN_SHARED_MEM = 64;
+
+[[clang::loader_uninitialized]] static void
+    *SharedMemVariableSharingSpace[NUM_SHARED_VARIABLES_IN_SHARED_MEM];
+#pragma omp allocate(SharedMemVariableSharingSpace)                            \
+    allocator(omp_pteam_mem_alloc)
 [[clang::loader_uninitialized]] static void **SharedMemVariableSharingSpacePtr;
 #pragma omp allocate(SharedMemVariableSharingSpacePtr)                         \
     allocator(omp_pteam_mem_alloc)
 
-void __kmpc_begin_sharing_variables(void ***GlobalArgs, uint64_t NumArgs) {
-  SharedMemVariableSharingSpacePtr =
-      (void **)__kmpc_alloc_shared(sizeof(void *) * NumArgs);
+void __kmpc_begin_sharing_variables(void ***GlobalArgs, uint64_t nArgs) {
+  if (nArgs <= NUM_SHARED_VARIABLES_IN_SHARED_MEM) {
+    SharedMemVariableSharingSpacePtr = &SharedMemVariableSharingSpace[0];
+  } else {
+    SharedMemVariableSharingSpacePtr = (void **)memory::allocGlobal(
+        nArgs * sizeof(void *), "new extended args");
+  }
   *GlobalArgs = SharedMemVariableSharingSpacePtr;
 }
 
-void __kmpc_end_sharing_variables(void **GlobalArgsPtr, uint64_t NumArgs) {
-  __kmpc_free_shared(SharedMemVariableSharingSpacePtr,
-                     sizeof(void *) * NumArgs);
+void __kmpc_end_sharing_variables() {
+  if (SharedMemVariableSharingSpacePtr != &SharedMemVariableSharingSpace[0])
+    memory::freeGlobal(SharedMemVariableSharingSpacePtr, "new extended args");
 }
 
 void __kmpc_get_shared_variables(void ***GlobalArgs) {


        


More information about the Openmp-commits mailing list