diff --git a/openmp/libomptarget/deviceRTLs/common/omptarget.h b/openmp/libomptarget/deviceRTLs/common/omptarget.h --- a/openmp/libomptarget/deviceRTLs/common/omptarget.h +++ b/openmp/libomptarget/deviceRTLs/common/omptarget.h @@ -74,6 +74,19 @@ extern DEVICE SHARED omptarget_nvptx_SharedArgs omptarget_nvptx_globalArgs; +// The slot used for data sharing by the master and worker threads. We use a +// complete (default size version and an incomplete one so that we allow sizes +// greater than the default). Is standard layout. +struct __kmpc_data_sharing_slot { + __kmpc_data_sharing_slot *Next; + __kmpc_data_sharing_slot *Prev; + void *PrevSlotStackPtr; + void *DataEnd; + DEVICE char *Data() { + return reinterpret_cast(this) + sizeof(__kmpc_data_sharing_slot); + } +}; + // Data structure to keep in shared memory that traces the current slot, stack, // and frame pointer as well as the active threads that didn't exit the current // environment. @@ -86,19 +99,13 @@ // Additional worker slot type which is initialized with the default worker slot // size of 4*32 bytes. struct __kmpc_data_sharing_worker_slot_static { - __kmpc_data_sharing_slot *Next; - __kmpc_data_sharing_slot *Prev; - void *PrevSlotStackPtr; - void *DataEnd; + __kmpc_data_sharing_slot b; char Data[DS_Worker_Warp_Slot_Size]; }; // Additional master slot type which is initialized with the default master slot // size of 4 bytes. struct __kmpc_data_sharing_master_slot_static { - __kmpc_data_sharing_slot *Next; - __kmpc_data_sharing_slot *Prev; - void *PrevSlotStackPtr; - void *DataEnd; + __kmpc_data_sharing_slot b; char Data[DS_Slot_Size]; }; extern DEVICE SHARED DataSharingStateTy DataSharingState; @@ -209,40 +216,40 @@ // initialize it with a smaller slot. if (IsMasterThread) { // Do not initialize this slot again if it has already been initalized. - if (master_rootS[0].DataEnd == &master_rootS[0].Data[0] + DS_Slot_Size) + if (master_rootS[0].b.DataEnd == master_rootS[0].b.Data() + DS_Slot_Size) return 0; // Initialize the pointer to the end of the slot given the size of the // data section. DataEnd is non-inclusive. - master_rootS[0].DataEnd = &master_rootS[0].Data[0] + DS_Slot_Size; + master_rootS[0].b.DataEnd = master_rootS[0].b.Data() + DS_Slot_Size; // We currently do not have a next slot. - master_rootS[0].Next = 0; - master_rootS[0].Prev = 0; - master_rootS[0].PrevSlotStackPtr = 0; + master_rootS[0].b.Next = 0; + master_rootS[0].b.Prev = 0; + master_rootS[0].b.PrevSlotStackPtr = 0; return (__kmpc_data_sharing_slot *)&master_rootS[0]; } // Do not initialize this slot again if it has already been initalized. - if (worker_rootS[wid].DataEnd == - &worker_rootS[wid].Data[0] + DS_Worker_Warp_Slot_Size) + if (worker_rootS[wid].b.DataEnd == + worker_rootS[wid].b.Data() + DS_Worker_Warp_Slot_Size) return 0; // Initialize the pointer to the end of the slot given the size of the data // section. DataEnd is non-inclusive. - worker_rootS[wid].DataEnd = - &worker_rootS[wid].Data[0] + DS_Worker_Warp_Slot_Size; + worker_rootS[wid].b.DataEnd = + worker_rootS[wid].b.Data() + DS_Worker_Warp_Slot_Size; // We currently do not have a next slot. - worker_rootS[wid].Next = 0; - worker_rootS[wid].Prev = 0; - worker_rootS[wid].PrevSlotStackPtr = 0; - return (__kmpc_data_sharing_slot *)&worker_rootS[wid]; + worker_rootS[wid].b.Next = 0; + worker_rootS[wid].b.Prev = 0; + worker_rootS[wid].b.PrevSlotStackPtr = 0; + return &worker_rootS[wid].b; } INLINE __kmpc_data_sharing_slot *GetPreallocatedSlotAddr(int wid) { - worker_rootS[wid].DataEnd = - &worker_rootS[wid].Data[0] + DS_Worker_Warp_Slot_Size; + worker_rootS[wid].b.DataEnd = + worker_rootS[wid].b.Data() + DS_Worker_Warp_Slot_Size; // We currently do not have a next slot. - worker_rootS[wid].Next = 0; - worker_rootS[wid].Prev = 0; - worker_rootS[wid].PrevSlotStackPtr = 0; - return (__kmpc_data_sharing_slot *)&worker_rootS[wid]; + worker_rootS[wid].b.Next = 0; + worker_rootS[wid].b.Prev = 0; + worker_rootS[wid].b.PrevSlotStackPtr = 0; + return &worker_rootS[wid].b; } private: diff --git a/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu b/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu --- a/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu @@ -29,7 +29,7 @@ for (int WID = 0; WID < WARPSIZE; WID++) { __kmpc_data_sharing_slot *RootS = teamDescr->GetPreallocatedSlotAddr(WID); DataSharingState.SlotPtr[WID] = RootS; - DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0]; + DataSharingState.StackPtr[WID] = (void *)RootS->Data(); } } @@ -108,16 +108,16 @@ NewSlot->Next = 0; NewSlot->Prev = SlotP; NewSlot->PrevSlotStackPtr = StackP; - NewSlot->DataEnd = &NewSlot->Data[0] + NewSize; + NewSlot->DataEnd = NewSlot->Data() + NewSize; // Make previous slot point to the newly allocated slot. SlotP->Next = NewSlot; // The current slot becomes the new slot. SlotP = NewSlot; // The stack pointer always points to the next free stack frame. - StackP = &NewSlot->Data[0] + PushSize; + StackP = NewSlot->Data() + PushSize; // The frame pointer always points to the beginning of the frame. - FrameP = DataSharingState.FramePtr[WID] = &NewSlot->Data[0]; + FrameP = DataSharingState.FramePtr[WID] = NewSlot->Data(); } else { // Add the data chunk to the current slot. The frame pointer is set to // point to the start of the new frame held in StackP. @@ -190,7 +190,7 @@ // If the current slot is empty, we need to free the slot after the // pop. - bool SlotEmpty = (StackP == &SlotP->Data[0]); + bool SlotEmpty = (StackP == SlotP->Data()); if (SlotEmpty && SlotP->Prev) { // Before removing the slot we need to reset StackP. diff --git a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu --- a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu @@ -141,7 +141,7 @@ __kmpc_data_sharing_slot *RootS = currTeamDescr.RootS( WID, WID == WARPSIZE - 1); DataSharingState.SlotPtr[WID] = RootS; - DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0]; + DataSharingState.StackPtr[WID] = (void *)RootS->Data(); } } diff --git a/openmp/libomptarget/deviceRTLs/interface.h b/openmp/libomptarget/deviceRTLs/interface.h --- a/openmp/libomptarget/deviceRTLs/interface.h +++ b/openmp/libomptarget/deviceRTLs/interface.h @@ -438,17 +438,6 @@ EXTERN void __kmpc_end_sharing_variables(); EXTERN void __kmpc_get_shared_variables(void ***GlobalArgs); -// The slot used for data sharing by the master and worker threads. We use a -// complete (default size version and an incomplete one so that we allow sizes -// greater than the default). -struct __kmpc_data_sharing_slot { - __kmpc_data_sharing_slot *Next; - __kmpc_data_sharing_slot *Prev; - void *PrevSlotStackPtr; - void *DataEnd; - char Data[]; -}; - // SPMD execution mode interrogation function. EXTERN int8_t __kmpc_is_spmd_exec_mode();