[Openmp-commits] [openmp] 1684012 - [Libomptarget] Introduce new main thread ID runtime function

via Openmp-commits openmp-commits at lists.llvm.org
Wed Jul 21 18:18:39 PDT 2021


Author: Joseph Huber
Date: 2021-07-21T21:18:14-04:00
New Revision: 1684012a47f76e210612bdd44a9d57147a90c4a6

URL: https://github.com/llvm/llvm-project/commit/1684012a47f76e210612bdd44a9d57147a90c4a6
DIFF: https://github.com/llvm/llvm-project/commit/1684012a47f76e210612bdd44a9d57147a90c4a6.diff

LOG: [Libomptarget] Introduce new main thread ID runtime function

This patch introduces `__kmpc_is_generic_main_thread_id` which splits the old
comparison into its own runtime function. The purpose of this is so we can fold
this part independently, so when both this and `is_spmd_mode` are folded the
final function will be folded as well.

Reviewed By: jdoerfert

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

Added: 
    

Modified: 
    llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
    openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
    openmp/libomptarget/deviceRTLs/interface.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
index 0ef2a5ed90f4..37da4386272e 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -441,6 +441,8 @@ __OMP_RTL(__kmpc_barrier_simple_spmd, false, Void, IdentPtr, Int32)
 __OMP_RTL(__kmpc_warp_active_thread_mask, false, LanemaskTy,)
 __OMP_RTL(__kmpc_syncwarp, false, Void, LanemaskTy)
 
+__OMP_RTL(__kmpc_is_generic_main_thread_id, false, Int8, Int32)
+
 __OMP_RTL(__last, false, Void, )
 
 #undef __OMP_RTL

diff  --git a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
index 3b620de71055..ce016ceb8acd 100644
--- a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
+++ b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
@@ -162,7 +162,11 @@ EXTERN int8_t __kmpc_is_spmd_exec_mode() {
 }
 
 EXTERN int8_t __kmpc_is_generic_main_thread(kmp_int32 Tid) {
-  return !__kmpc_is_spmd_exec_mode() && GetMasterThreadID() == Tid;
+  return !__kmpc_is_spmd_exec_mode() && __kmpc_is_generic_main_thread_id(Tid);
+}
+
+NOINLINE EXTERN int8_t __kmpc_is_generic_main_thread_id(kmp_int32 Tid) {
+  return GetMasterThreadID() == Tid;
 }
 
 EXTERN bool __kmpc_kernel_parallel(void**WorkFn);

diff  --git a/openmp/libomptarget/deviceRTLs/interface.h b/openmp/libomptarget/deviceRTLs/interface.h
index e09e62996519..ade1bfe2222e 100644
--- a/openmp/libomptarget/deviceRTLs/interface.h
+++ b/openmp/libomptarget/deviceRTLs/interface.h
@@ -453,6 +453,10 @@ EXTERN int8_t __kmpc_is_spmd_exec_mode();
 /// thread in generic mode outside of a parallel region.
 EXTERN int8_t __kmpc_is_generic_main_thread(kmp_int32 Tid);
 
+/// Return true if the hardware thread id \p Tid represents the OpenMP main
+/// thread in generic mode.
+EXTERN int8_t __kmpc_is_generic_main_thread_id(kmp_int32 Tid);
+
 EXTERN void __kmpc_get_team_static_memory(int16_t isSPMDExecutionMode,
                                           const void *buf, size_t size,
                                           int16_t is_shared, const void **res);


        


More information about the Openmp-commits mailing list