[Openmp-commits] [openmp] r359892 - [OPENMP][NVPTX]Improved several standard OpenMP functions, NFC.

Alexey Bataev via Openmp-commits openmp-commits at lists.llvm.org
Fri May 3 07:47:20 PDT 2019


Author: abataev
Date: Fri May  3 07:47:20 2019
New Revision: 359892

URL: http://llvm.org/viewvc/llvm-project?rev=359892&view=rev
Log:
[OPENMP][NVPTX]Improved several standard OpenMP functions, NFC.

Summary:
Used parallelLevel[] counter to simplify and improve implementation of
the existing standard OpenMP functions. Functions are tested already in
several tests, the patch is NFC.

Reviewers: grokos, gtbercea, kkwli0

Subscribers: guansong, jdoerfert, caomhin, openmp-commits

Tags: #openmp

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

Modified:
    openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu

Modified: openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu?rev=359892&r1=359891&r2=359892&view=diff
==============================================================================
--- openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu (original)
+++ openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu Fri May  3 07:47:20 2019
@@ -53,17 +53,16 @@ EXTERN int omp_get_num_threads(void) {
 }
 
 EXTERN int omp_get_max_threads(void) {
-  if (isSPMDMode())
+  if (parallelLevel[GetWarpId()] > 0)
     // We're already in parallel region.
-    return 1;  // default is 1 thread avail
+    return 1; // default is 1 thread avail
   omptarget_nvptx_TaskDescr *currTaskDescr =
       getMyTopTaskDescriptor(/*isSPMDExecutionMode=*/false);
-  int rc = 1; // default is 1 thread avail
-  if (!currTaskDescr->InParallelRegion()) {
-    // Not currently in a parallel region, return what was set.
-    rc = currTaskDescr->NThreads();
-    ASSERT0(LT_FUSSY, rc >= 0, "bad number of threads");
-  }
+  ASSERT0(LT_FUSSY, !currTaskDescr->InParallelRegion(),
+          "Should no be in the parallel region");
+  // Not currently in a parallel region, return what was set.
+  int rc = currTaskDescr->NThreads();
+  ASSERT0(LT_FUSSY, rc >= 0, "bad number of threads");
   PRINT(LD_IO, "call omp_get_max_threads() return %d\n", rc);
   return rc;
 }
@@ -155,19 +154,19 @@ EXTERN int omp_get_active_level(void) {
 }
 
 EXTERN int omp_get_ancestor_thread_num(int level) {
-  if (isRuntimeUninitialized()) {
-    ASSERT0(LT_FUSSY, isSPMDMode(),
-            "Expected SPMD mode only with uninitialized runtime.");
+  if (isSPMDMode())
     return level == 1 ? GetThreadIdInBlock() : 0;
-  }
   int rc = -1;
-  if (level == 0) {
+  // If level is 0 or all parallel regions are not active - return 0.
+  unsigned parLevel = parallelLevel[GetWarpId()];
+  if (level == 0 || (level > 0 && parLevel < OMP_ACTIVE_PARALLEL_LEVEL &&
+                     level <= parLevel)) {
     rc = 0;
   } else if (level > 0) {
     int totLevel = omp_get_level();
     if (level <= totLevel) {
       omptarget_nvptx_TaskDescr *currTaskDescr =
-          getMyTopTaskDescriptor(isSPMDMode());
+          getMyTopTaskDescriptor(/*isSPMDExecutionMode=*/false);
       int steps = totLevel - level;
       PRINT(LD_IO, "backtrack %d steps\n", steps);
       ASSERT0(LT_FUSSY, currTaskDescr,
@@ -207,19 +206,19 @@ EXTERN int omp_get_ancestor_thread_num(i
 }
 
 EXTERN int omp_get_team_size(int level) {
-  if (isRuntimeUninitialized()) {
-    ASSERT0(LT_FUSSY, isSPMDMode(),
-            "Expected SPMD mode only with uninitialized runtime.");
+  if (isSPMDMode())
     return level == 1 ? GetNumberOfThreadsInBlock() : 1;
-  }
   int rc = -1;
-  if (level == 0) {
+  unsigned parLevel = parallelLevel[GetWarpId()];
+  // If level is 0 or all parallel regions are not active - return 1.
+  if (level == 0 || (level > 0 && parLevel < OMP_ACTIVE_PARALLEL_LEVEL &&
+                     level <= parLevel)) {
     rc = 1;
   } else if (level > 0) {
     int totLevel = omp_get_level();
     if (level <= totLevel) {
       omptarget_nvptx_TaskDescr *currTaskDescr =
-          getMyTopTaskDescriptor(isSPMDMode());
+          getMyTopTaskDescriptor(/*isSPMDExecutionMode=*/false);
       int steps = totLevel - level;
       ASSERT0(LT_FUSSY, currTaskDescr,
               "do not expect fct to be called in a non-active thread");




More information about the Openmp-commits mailing list