Commit f1c821fa authored by Huber, Joseph's avatar Huber, Joseph
Browse files

[OpenMP] Add support for dynamic shared memory in new RTL

This patch adds support for using dynamic shared memory in the new
device runtime. The new function `__kmpc_get_dynamic_shared` will return a
pointer to the buffer of dynamic shared memory. Currently the amount of memory
allocated is set by an environment variable.

In the future this amount will be added to the amount used for the smart stack
which will be configured in a similar way.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D110006
parent ec02c34b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ variables is defined below.
    * ``LIBOMPTARGET_INFO=<Num>``
    * ``LIBOMPTARGET_HEAP_SIZE=<Num>``
    * ``LIBOMPTARGET_STACK_SIZE=<Num>``
    * ``LIBOMPTARGET_SHARED_MEMORY_SIZE=<Num>``

LIBOMPTARGET_DEBUG
""""""""""""""""""
@@ -338,6 +339,14 @@ allocated using ``malloc`` and ``free`` for the CUDA plugin. This is necessary
for some applications that allocate too much memory either through the user or
globalization.

LIBOMPTARGET_SHARED_MEMORY_SIZE
"""""""""""""""""""""""""""""""

This environment variable sets the amount of dynamic shared memory in bytes used 
by the kernel once it is launched. A pointer to the dynamic memory buffer can 
currently only be accessed using the ``__kmpc_get_dynamic_shared`` device 
runtime call.

.. toctree::
   :hidden:
   :maxdepth: 1
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ uint32_t getDeviceNum();
/// Return the user choosen debug level.
uint32_t getDebugLevel();

/// Return the amount of dynamic shared memory that was allocated at launch.
uint64_t getDynamicMemorySize();

bool isDebugMode(DebugLevel Level);

} // namespace config
+4 −0
Original line number Diff line number Diff line
@@ -174,6 +174,10 @@ void *__kmpc_alloc_shared(uint64_t Bytes);
/// allocated by __kmpc_alloc_shared by the same thread.
void __kmpc_free_shared(void *Ptr, uint64_t Bytes);

/// Get a pointer to the memory buffer containing dynamically allocated shared
/// memory configured at launch.
void *__kmpc_get_dynamic_shared();

/// Allocate sufficient space for \p NumArgs sequential `void*` and store the
/// allocation address in \p GlobalArgs.
///
+3 −0
Original line number Diff line number Diff line
@@ -188,6 +188,9 @@ void freeShared(void *Ptr, uint64_t Bytes, const char *Reason);
/// Alloca \p Size bytes in global memory, if possible, for \p Reason.
void *allocGlobal(uint64_t Size, const char *Reason);

/// Return a pointer to the dynamic shared memory buffer.
void *getDynamicBuffer();

/// Free \p Ptr, alloated via allocGlobal, for \p Reason.
void freeGlobal(void *Ptr, const char *Reason);

+5 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ struct DeviceEnvironmentTy {
  uint32_t DebugLevel;
  uint32_t NumDevices;
  uint32_t DeviceNum;
  uint64_t DynamicMemSize;
};

#pragma omp declare target
@@ -43,6 +44,10 @@ uint32_t config::getDeviceNum() {
  return omptarget_device_environment.DeviceNum;
}

uint64_t config::getDynamicMemorySize() {
  return omptarget_device_environment.DynamicMemSize;
}

bool config::isDebugMode(config::DebugLevel Level) {
  return config::getDebugLevel() > Level;
}
Loading