[Openmp-commits] [openmp] r359792 - [OPENMP][NVPTX]Improve omp_get_max_threads() function.
Alexey Bataev via Openmp-commits
openmp-commits at lists.llvm.org
Thu May 2 07:52:52 PDT 2019
Author: abataev
Date: Thu May 2 07:52:52 2019
New Revision: 359792
URL: http://llvm.org/viewvc/llvm-project?rev=359792&view=rev
Log:
[OPENMP][NVPTX]Improve omp_get_max_threads() function.
Summary:
Function omp_get_max_threads() can always return 1 if current execution
mode is SPMD.
Reviewers: grokos, gtbercea, kkwli0
Subscribers: guansong, jdoerfert, caomhin, openmp-commits
Tags: #openmp
Differential Revision: https://reviews.llvm.org/D61379
Added:
openmp/trunk/libomptarget/deviceRTLs/nvptx/test/api/max_threads.c
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=359792&r1=359791&r2=359792&view=diff
==============================================================================
--- openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu (original)
+++ openmp/trunk/libomptarget/deviceRTLs/nvptx/src/libcall.cu Thu May 2 07:52:52 2019
@@ -54,14 +54,11 @@ EXTERN int omp_get_num_threads(void) {
}
EXTERN int omp_get_max_threads(void) {
- if (isRuntimeUninitialized()) {
- ASSERT0(LT_FUSSY, isSPMDMode(),
- "Expected SPMD mode only with uninitialized runtime.");
+ if (isSPMDMode())
// We're already in parallel region.
return 1; // default is 1 thread avail
- }
omptarget_nvptx_TaskDescr *currTaskDescr =
- getMyTopTaskDescriptor(isSPMDMode());
+ getMyTopTaskDescriptor(/*isSPMDExecutionMode=*/false);
int rc = 1; // default is 1 thread avail
if (!currTaskDescr->InParallelRegion()) {
// Not currently in a parallel region, return what was set.
Added: openmp/trunk/libomptarget/deviceRTLs/nvptx/test/api/max_threads.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/deviceRTLs/nvptx/test/api/max_threads.c?rev=359792&view=auto
==============================================================================
--- openmp/trunk/libomptarget/deviceRTLs/nvptx/test/api/max_threads.c (added)
+++ openmp/trunk/libomptarget/deviceRTLs/nvptx/test/api/max_threads.c Thu May 2 07:52:52 2019
@@ -0,0 +1,46 @@
+// RUN: %compile-run-and-check
+
+#include <omp.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+ int MaxThreadsL1 = -1, MaxThreadsL2 = -1;
+
+#pragma omp declare reduction(unique:int \
+ : omp_out = (omp_in == 1 ? omp_in : omp_out)) \
+ initializer(omp_priv = -1)
+
+ // Non-SPMD mode.
+#pragma omp target teams map(MaxThreadsL1, MaxThreadsL2) thread_limit(32) \
+ num_teams(1)
+ {
+ MaxThreadsL1 = omp_get_max_threads();
+#pragma omp parallel reduction(unique : MaxThreadsL2)
+ { MaxThreadsL2 = omp_get_max_threads(); }
+ }
+
+ // CHECK: Non-SPMD MaxThreadsL1 = 32
+ printf("Non-SPMD MaxThreadsL1 = %d\n", MaxThreadsL1);
+ // CHECK: Non-SPMD MaxThreadsL2 = 1
+ printf("Non-SPMD MaxThreadsL2 = %d\n", MaxThreadsL2);
+
+ // SPMD mode with full runtime
+ MaxThreadsL2 = -1;
+#pragma omp target parallel reduction(unique : MaxThreadsL2)
+ { MaxThreadsL2 = omp_get_max_threads(); }
+
+ // CHECK: SPMD with full runtime MaxThreadsL2 = 1
+ printf("SPMD with full runtime MaxThreadsL2 = %d\n", MaxThreadsL2);
+
+ // SPMD mode without runtime
+ MaxThreadsL2 = -1;
+#pragma omp target parallel for reduction(unique : MaxThreadsL2)
+ for (int I = 0; I < 2; ++I) {
+ MaxThreadsL2 = omp_get_max_threads();
+ }
+
+ // CHECK: SPMD without runtime MaxThreadsL2 = 1
+ printf("SPMD without runtime MaxThreadsL2 = %d\n", MaxThreadsL2);
+
+ return 0;
+}
More information about the Openmp-commits
mailing list