[Openmp-commits] [openmp] 24a36ce - [OpenMP][Offloading] Replace all calls to `isSPMDMode` with `__kmpc_is_spmd_exec_mode`
Shilei Tian via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jun 30 12:40:03 PDT 2021
Author: Shilei Tian
Date: 2021-06-30T15:39:57-04:00
New Revision: 24a36ce58b773332dbb28df87270251686c9430d
URL: https://github.com/llvm/llvm-project/commit/24a36ce58b773332dbb28df87270251686c9430d
DIFF: https://github.com/llvm/llvm-project/commit/24a36ce58b773332dbb28df87270251686c9430d.diff
LOG: [OpenMP][Offloading] Replace all calls to `isSPMDMode` with `__kmpc_is_spmd_exec_mode`
In our ongoing work, we are using `AbstractAttributor` to deduct execution model
of device functions, and potententially remove unnecessary function calls to
`__kmpc_is_spmd_exec_mode`. In current device runtime, we have mixed use of
`isSPMDMode` and `__kmpc_is_spmd_exec_mode`, but in fact in `__kmpc_is_spmd_exec_mode`
it simply calls `isSPMDMode`. Since all functions starting with `__kmpc` is C
function, which doesn't have things like name mangling. It is more optimization
friendly. In this patch, we simply replaced all calls to `isSPMDMode` with
`__kmpc_is_spmd_exec_mode` to pave the way for the optimization.
Reviewed By: JonChesterfield
Differential Revision: https://reviews.llvm.org/D105211
Added:
Modified:
openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
openmp/libomptarget/deviceRTLs/common/src/libcall.cu
openmp/libomptarget/deviceRTLs/common/src/loop.cu
openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
openmp/libomptarget/deviceRTLs/common/src/support.cu
openmp/libomptarget/deviceRTLs/common/support.h
Removed:
################################################################################
diff --git a/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu b/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
index 367fc608c2994..3b95ca88aad27 100644
--- a/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
+++ b/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
@@ -66,7 +66,7 @@ static void *__kmpc_alloc_for_warp(AllocTy Alloc, unsigned Bytes,
EXTERN void *__kmpc_alloc_shared(size_t Bytes) {
Bytes = Bytes + (Bytes % MinBytes);
- if (IsMasterThread(isSPMDMode())) {
+ if (IsMasterThread(__kmpc_is_spmd_exec_mode())) {
// Main thread alone, use shared memory if space is available.
if (MainSharedStack.Usage[0] + Bytes <= MainSharedStack.MaxSize) {
void *Ptr = &MainSharedStack.Data[MainSharedStack.Usage[0]];
diff --git a/openmp/libomptarget/deviceRTLs/common/src/libcall.cu b/openmp/libomptarget/deviceRTLs/common/src/libcall.cu
index c1cfe3e7d6d72..ae0590284d06d 100644
--- a/openmp/libomptarget/deviceRTLs/common/src/libcall.cu
+++ b/openmp/libomptarget/deviceRTLs/common/src/libcall.cu
@@ -29,7 +29,7 @@ EXTERN double omp_get_wtime(void) {
EXTERN void omp_set_num_threads(int num) {
// Ignore it for SPMD mode.
- if (isSPMDMode())
+ if (__kmpc_is_spmd_exec_mode())
return;
ASSERT0(LT_FUSSY, isRuntimeInitialized(), "Expected initialized runtime.");
PRINT(LD_IO, "call omp_set_num_threads(num %d)\n", num);
@@ -41,7 +41,7 @@ EXTERN void omp_set_num_threads(int num) {
}
EXTERN int omp_get_num_threads(void) {
- int rc = GetNumberOfOmpThreads(isSPMDMode());
+ int rc = GetNumberOfOmpThreads(__kmpc_is_spmd_exec_mode());
PRINT(LD_IO, "call omp_get_num_threads() return %d\n", rc);
return rc;
}
@@ -60,7 +60,7 @@ EXTERN int omp_get_max_threads(void) {
}
EXTERN int omp_get_thread_limit(void) {
- if (isSPMDMode())
+ if (__kmpc_is_spmd_exec_mode())
return GetNumberOfThreadsInBlock();
int rc = threadLimit;
PRINT(LD_IO, "call omp_get_thread_limit() return %d\n", rc);
@@ -68,7 +68,7 @@ EXTERN int omp_get_thread_limit(void) {
}
EXTERN int omp_get_thread_num() {
- bool isSPMDExecutionMode = isSPMDMode();
+ bool isSPMDExecutionMode = __kmpc_is_spmd_exec_mode();
int tid = GetLogicalThreadIdInBlock(isSPMDExecutionMode);
int rc = GetOmpThreadId(tid, isSPMDExecutionMode);
PRINT(LD_IO, "call omp_get_thread_num() returns %d\n", rc);
@@ -76,7 +76,7 @@ EXTERN int omp_get_thread_num() {
}
EXTERN int omp_get_num_procs(void) {
- int rc = GetNumberOfProcsInDevice(isSPMDMode());
+ int rc = GetNumberOfProcsInDevice(__kmpc_is_spmd_exec_mode());
PRINT(LD_IO, "call omp_get_num_procs() returns %d\n", rc);
return rc;
}
@@ -143,7 +143,7 @@ EXTERN int omp_get_active_level(void) {
}
EXTERN int omp_get_ancestor_thread_num(int level) {
- if (isSPMDMode())
+ if (__kmpc_is_spmd_exec_mode())
return level == 1 ? GetThreadIdInBlock() : 0;
int rc = -1;
// If level is 0 or all parallel regions are not active - return 0.
@@ -197,7 +197,7 @@ EXTERN int omp_get_ancestor_thread_num(int level) {
}
EXTERN int omp_get_team_size(int level) {
- if (isSPMDMode())
+ if (__kmpc_is_spmd_exec_mode())
return level == 1 ? GetNumberOfThreadsInBlock() : 1;
int rc = -1;
unsigned parLevel = parallelLevel[GetWarpId()];
@@ -217,13 +217,13 @@ EXTERN int omp_get_team_size(int level) {
EXTERN void omp_get_schedule(omp_sched_t *kind, int *modifier) {
if (isRuntimeUninitialized()) {
- ASSERT0(LT_FUSSY, isSPMDMode(),
+ ASSERT0(LT_FUSSY, __kmpc_is_spmd_exec_mode(),
"Expected SPMD mode only with uninitialized runtime.");
*kind = omp_sched_static;
*modifier = 1;
} else {
omptarget_nvptx_TaskDescr *currTaskDescr =
- getMyTopTaskDescriptor(isSPMDMode());
+ getMyTopTaskDescriptor(__kmpc_is_spmd_exec_mode());
*kind = currTaskDescr->GetRuntimeSched();
*modifier = currTaskDescr->RuntimeChunkSize();
}
@@ -235,13 +235,13 @@ EXTERN void omp_set_schedule(omp_sched_t kind, int modifier) {
PRINT(LD_IO, "call omp_set_schedule(sched %d, modif %d)\n", (int)kind,
modifier);
if (isRuntimeUninitialized()) {
- ASSERT0(LT_FUSSY, isSPMDMode(),
+ ASSERT0(LT_FUSSY, __kmpc_is_spmd_exec_mode(),
"Expected SPMD mode only with uninitialized runtime.");
return;
}
if (kind >= omp_sched_static && kind < omp_sched_auto) {
omptarget_nvptx_TaskDescr *currTaskDescr =
- getMyTopTaskDescriptor(isSPMDMode());
+ getMyTopTaskDescriptor(__kmpc_is_spmd_exec_mode());
currTaskDescr->SetRuntimeSched(kind);
currTaskDescr->RuntimeChunkSize() = modifier;
PRINT(LD_IOD, "omp_set_schedule did set sched %d & modif %" PRIu64 "\n",
diff --git a/openmp/libomptarget/deviceRTLs/common/src/loop.cu b/openmp/libomptarget/deviceRTLs/common/src/loop.cu
index b1fce8e3d0c62..04447be28db11 100644
--- a/openmp/libomptarget/deviceRTLs/common/src/loop.cu
+++ b/openmp/libomptarget/deviceRTLs/common/src/loop.cu
@@ -508,7 +508,7 @@ public:
PRINT(LD_LOOP,
"Got sched: active %d, total %d: lb %lld, ub %lld, stride = %lld, "
"last %d\n",
- (int)GetNumberOfOmpThreads(isSPMDMode()),
+ (int)GetNumberOfOmpThreads(__kmpc_is_spmd_exec_mode()),
(int)GetNumberOfWorkersInTeam(), (long long)*plower,
(long long)*pupper, (long long)*pstride, (int)*plast);
return DISPATCH_NOTFINISHED;
diff --git a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
index 1c53131d17144..c117c7e00bf28 100644
--- a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
+++ b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
@@ -65,7 +65,7 @@ EXTERN void __kmpc_kernel_init(int ThreadLimit, int16_t RequiresOMPRuntime) {
nThreads = GetNumberOfThreadsInBlock();
threadLimit = ThreadLimit;
- if (!isSPMDMode())
+ if (!__kmpc_is_spmd_exec_mode())
omptarget_nvptx_globalArgs.Init();
__kmpc_data_sharing_init_stack();
@@ -162,8 +162,7 @@ EXTERN void __kmpc_spmd_kernel_deinit_v2(int16_t RequiresOMPRuntime) {
// Return true if the current target region is executed in SPMD mode.
EXTERN int8_t __kmpc_is_spmd_exec_mode() {
- PRINT0(LD_IO | LD_PAR, "call to __kmpc_is_spmd_exec_mode\n");
- return isSPMDMode();
+ return (execution_param & ModeMask) == Spmd;
}
#pragma omp end declare target
diff --git a/openmp/libomptarget/deviceRTLs/common/src/support.cu b/openmp/libomptarget/deviceRTLs/common/src/support.cu
index df7ad675572e3..0977e2867e6e1 100644
--- a/openmp/libomptarget/deviceRTLs/common/src/support.cu
+++ b/openmp/libomptarget/deviceRTLs/common/src/support.cu
@@ -26,8 +26,6 @@ void setExecutionParameters(ExecutionMode EMode, RuntimeMode RMode) {
bool isGenericMode() { return (execution_param & ModeMask) == Generic; }
-bool isSPMDMode() { return (execution_param & ModeMask) == Spmd; }
-
bool isRuntimeUninitialized() {
return (execution_param & RuntimeMask) == RuntimeUninitialized;
}
@@ -42,7 +40,7 @@ bool isRuntimeInitialized() {
bool checkSPMDMode(kmp_Ident *loc) {
if (!loc)
- return isSPMDMode();
+ return __kmpc_is_spmd_exec_mode();
// If SPMD is true then we are not in the UNDEFINED state so
// we can return immediately.
@@ -55,7 +53,7 @@ bool checkSPMDMode(kmp_Ident *loc) {
return false;
// We are in underfined state.
- return isSPMDMode();
+ return __kmpc_is_spmd_exec_mode();
}
bool checkGenericMode(kmp_Ident *loc) { return !checkSPMDMode(loc); }
diff --git a/openmp/libomptarget/deviceRTLs/common/support.h b/openmp/libomptarget/deviceRTLs/common/support.h
index af20362fbf871..4e9ce39b30403 100644
--- a/openmp/libomptarget/deviceRTLs/common/support.h
+++ b/openmp/libomptarget/deviceRTLs/common/support.h
@@ -33,7 +33,6 @@ enum RuntimeMode {
void setExecutionParameters(ExecutionMode EMode, RuntimeMode RMode);
bool isGenericMode();
-bool isSPMDMode();
bool isRuntimeUninitialized();
bool isRuntimeInitialized();
More information about the Openmp-commits
mailing list