#define BARRIER_COUNTER 0
#define ORDERED_COUNTER 1
-// arguments needed for L0 parallelism only.
-class omptarget_nvptx_SharedArgs {
-public:
- // All these methods must be called by the master thread only.
- INLINE void Init() {
- args = buffer;
- nArgs = MAX_SHARED_ARGS;
- }
- INLINE void DeInit() {
- // Free any memory allocated for outlined parallel function with a large
- // number of arguments.
- if (nArgs > MAX_SHARED_ARGS) {
- SafeFree(args, "new extended args");
- Init();
- }
- }
- INLINE void EnsureSize(size_t size) {
- if (size > nArgs) {
- if (nArgs > MAX_SHARED_ARGS) {
- SafeFree(args, "new extended args");
- }
- args = (void **)SafeMalloc(size * sizeof(void *), "new extended args");
- nArgs = size;
- }
- }
- // Called by all threads.
- INLINE void **GetArgs() const { return args; };
-
-private:
- // buffer of pre-allocated arguments.
- void *buffer[MAX_SHARED_ARGS];
- // pointer to arguments buffer.
- // starts off as a pointer to 'buffer' but can be dynamically allocated.
- void **args;
- // starts off as MAX_SHARED_ARGS but can increase in size.
- uint32_t nArgs;
-};
-
-extern omptarget_nvptx_SharedArgs EXTERN_SHARED(omptarget_nvptx_globalArgs);
-
// Worker slot type which is initialized with the default worker slot
// size of 4*32 bytes.
struct __kmpc_data_sharing_slot {
}
}
+/// 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.
+#define 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)
+
// Begin a data sharing context. Maintain a list of references to shared
// variables. This list of references to shared variables will be passed
// to one or more threads.
// In L0 data sharing this is called by master thread.
// In L1 data sharing this is called by active warp master thread.
EXTERN void __kmpc_begin_sharing_variables(void ***GlobalArgs, size_t nArgs) {
- omptarget_nvptx_globalArgs.EnsureSize(nArgs);
- *GlobalArgs = omptarget_nvptx_globalArgs.GetArgs();
+ if (nArgs <= NUM_SHARED_VARIABLES_IN_SHARED_MEM) {
+ SharedMemVariableSharingSpacePtr = &SharedMemVariableSharingSpace[0];
+ } else {
+ SharedMemVariableSharingSpacePtr =
+ (void **)SafeMalloc(nArgs * sizeof(void *), "new extended args");
+ }
+ *GlobalArgs = SharedMemVariableSharingSpacePtr;
}
// End a data sharing context. There is no need to have a list of refs
// In L0 data sharing this is called by master thread.
// In L1 data sharing this is called by active warp master thread.
EXTERN void __kmpc_end_sharing_variables() {
- omptarget_nvptx_globalArgs.DeInit();
+ if (SharedMemVariableSharingSpacePtr != &SharedMemVariableSharingSpace[0])
+ SafeFree(SharedMemVariableSharingSpacePtr, "new extended args");
}
// This function will return a list of references to global variables. This
// preserving the order.
// Called by all workers.
EXTERN void __kmpc_get_shared_variables(void ***GlobalArgs) {
- *GlobalArgs = omptarget_nvptx_globalArgs.GetArgs();
+ *GlobalArgs = SharedMemVariableSharingSpacePtr;
}
// This function is used to init static memory manager. This manager is used to