[Openmp-commits] [openmp] r328146 - [OpenMP][libomptarget] Fix master warp check

Gheorghe-Teodor Bercea via Openmp-commits openmp-commits at lists.llvm.org
Wed Mar 21 13:51:17 PDT 2018


Author: gbercea
Date: Wed Mar 21 13:51:16 2018
New Revision: 328146

URL: http://llvm.org/viewvc/llvm-project?rev=328146&view=rev
Log:
[OpenMP][libomptarget] Fix master warp check

Summary: The check for the master warp must take into consideration the actual number of warps: the master warp is equal to the last active warp not necessarily WARPSIZE - 1.

Reviewers: grokos, carlo.bertolli, ABataev, caomhin

Reviewed By: grokos

Subscribers: guansong, openmp-commits

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

Modified:
    openmp/trunk/libomptarget/deviceRTLs/nvptx/src/data_sharing.cu
    openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.cu
    openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.h

Modified: openmp/trunk/libomptarget/deviceRTLs/nvptx/src/data_sharing.cu
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/deviceRTLs/nvptx/src/data_sharing.cu?rev=328146&r1=328145&r2=328146&view=diff
==============================================================================
--- openmp/trunk/libomptarget/deviceRTLs/nvptx/src/data_sharing.cu (original)
+++ openmp/trunk/libomptarget/deviceRTLs/nvptx/src/data_sharing.cu Wed Mar 21 13:51:16 2018
@@ -88,7 +88,7 @@ __kmpc_initialize_data_sharing_environme
 
   omptarget_nvptx_TeamDescr *teamDescr =
       &omptarget_nvptx_threadPrivateContext->TeamContext();
-  __kmpc_data_sharing_slot *RootS = teamDescr->RootS(WID);
+  __kmpc_data_sharing_slot *RootS = teamDescr->RootS(WID, IsMasterThread());
 
   DataSharingState.SlotPtr[WID] = RootS;
   DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0];
@@ -337,17 +337,27 @@ EXTERN void __kmpc_data_sharing_init_sta
   // This function initializes the stack pointer with the pointer to the
   // statically allocated shared memory slots. The size of a shared memory
   // slot is pre-determined to be 256 bytes.
-  unsigned WID = getWarpId();
-  omptarget_nvptx_TeamDescr *teamDescr =
-      &omptarget_nvptx_threadPrivateContext->TeamContext();
-  __kmpc_data_sharing_slot *RootS = teamDescr->RootS(WID);
 
-  DataSharingState.SlotPtr[WID] = RootS;
-  DataSharingState.TailPtr[WID] = RootS;
-  DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0];
+  // Initialize the data sharing structures. This section should only be
+  // executed by the warp active master threads.
+  if (IsWarpMasterActiveThread()) {
+    unsigned WID = getWarpId();
+    omptarget_nvptx_TeamDescr *teamDescr =
+        &omptarget_nvptx_threadPrivateContext->TeamContext();
+    __kmpc_data_sharing_slot *RootS = teamDescr->RootS(WID, IsMasterThread());
+
+    DataSharingState.SlotPtr[WID] = RootS;
+    DataSharingState.TailPtr[WID] = RootS;
+    DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0];
+  }
 
-  // We initialize the list of references to arguments here.
-  omptarget_nvptx_globalArgs.Init();
+  // Currently we only support the sharing of variables between master and
+  // workers. The list of references to shared variables exists only for
+  // the master thread.
+  if (IsMasterThread()) {
+    // Initialize the list of references to arguments.
+    omptarget_nvptx_globalArgs.Init();
+  }
 }
 
 // Called at the time of the kernel initialization. This is used to initilize

Modified: openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.cu
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.cu?rev=328146&r1=328145&r2=328146&view=diff
==============================================================================
--- openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.cu (original)
+++ openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.cu Wed Mar 21 13:51:16 2018
@@ -168,7 +168,8 @@ EXTERN void __kmpc_spmd_kernel_init(int
   if (RequiresDataSharing && threadId % WARPSIZE == 0) {
     // Warp master innitializes data sharing environment.
     unsigned WID = threadId / WARPSIZE;
-    __kmpc_data_sharing_slot *RootS = currTeamDescr.RootS(WID);
+    __kmpc_data_sharing_slot *RootS = currTeamDescr.RootS(
+        WID, WID == WARPSIZE - 1);
     DataSharingState.SlotPtr[WID] = RootS;
     DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0];
   }

Modified: openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.h?rev=328146&r1=328145&r2=328146&view=diff
==============================================================================
--- openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.h (original)
+++ openmp/trunk/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.h Wed Mar 21 13:51:16 2018
@@ -259,10 +259,10 @@ public:
   // init
   INLINE void InitTeamDescr();
 
-  INLINE __kmpc_data_sharing_slot *RootS(int wid) {
+  INLINE __kmpc_data_sharing_slot *RootS(int wid, bool IsMasterThread) {
     // If this is invoked by the master thread of the master warp then intialize
     // it with a smaller slot.
-    if (wid == WARPSIZE - 1) {
+    if (IsMasterThread) {
       // 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;




More information about the Openmp-commits mailing list