Author: Giorgis Georgakoudis Date: 2021-01-21T09:15:14-08:00 New Revision: 6b7645dd31e5b171479fb0aa47c800e5e0d6616f
URL: https://github.com/llvm/llvm-project/commit/6b7645dd31e5b171479fb0aa47c800e5e0d6616f DIFF: https://github.com/llvm/llvm-project/commit/6b7645dd31e5b171479fb0aa47c800e5e0d6616f.diff LOG: [OpenMP] Add time profiling support in libomp Profiling has been recently implemented in libomptarget (D93055). This patch enables time profiling support for libomptarget in libomp, to support profiling of multi-threaded execution of offloaded regions. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D94855 Added: Modified: openmp/runtime/CMakeLists.txt openmp/runtime/src/CMakeLists.txt openmp/runtime/src/kmp_config.h.cmake openmp/runtime/src/kmp_runtime.cpp Removed: ################################################################################ diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt index 6d8a539f1b16..9fdd04f41646 100644 --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -34,6 +34,7 @@ if(${OPENMP_STANDALONE_BUILD}) # Should assertions be enabled? They are on by default. set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL "enable assertions?") + set(LIBOMPTARGET_PROFILING_SUPPORT FALSE) else() # Part of LLVM build # Determine the native architecture from LLVM. string(TOLOWER "${LLVM_TARGET_ARCH}" LIBOMP_NATIVE_ARCH) @@ -65,6 +66,8 @@ else() # Part of LLVM build libomp_get_architecture(LIBOMP_ARCH) endif () set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}) + # Time profiling support + set(LIBOMPTARGET_PROFILING_SUPPORT ${OPENMP_ENABLE_LIBOMPTARGET_PROFILING}) endif() # FUJITSU A64FX is a special processor because its cache line size is 256. diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt index 3a6151fd1ac3..2e927df84f5c 100644 --- a/openmp/runtime/src/CMakeLists.txt +++ b/openmp/runtime/src/CMakeLists.txt @@ -133,7 +133,18 @@ endif() # Add the OpenMP library libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS) -add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES}) +libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS) +# Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled. +if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING)) + add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES}) + # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS + target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${CMAKE_DL_LIBS}) +else() + add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED + LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${CMAKE_DL_LIBS} + LINK_COMPONENTS Support + ) +endif() set_target_properties(omp PROPERTIES PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}" @@ -166,10 +177,6 @@ if(NOT WIN32) ) endif() -# Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS -libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS) -target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${CMAKE_DL_LIBS}) - # Create *.inc before compiling any sources # objects depend on : .inc files add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc) diff --git a/openmp/runtime/src/kmp_config.h.cmake b/openmp/runtime/src/kmp_config.h.cmake index 4010a11621e0..3d682c690fc7 100644 --- a/openmp/runtime/src/kmp_config.h.cmake +++ b/openmp/runtime/src/kmp_config.h.cmake @@ -44,6 +44,8 @@ #define OMPT_DEBUG LIBOMP_OMPT_DEBUG #cmakedefine01 LIBOMP_OMPT_SUPPORT #define OMPT_SUPPORT LIBOMP_OMPT_SUPPORT +#cmakedefine01 LIBOMPTARGET_PROFILING_SUPPORT +#define OMPTARGET_PROFILING_SUPPORT LIBOMPTARGET_PROFILING_SUPPORT #cmakedefine01 LIBOMP_OMPT_OPTIONAL #define OMPT_OPTIONAL LIBOMP_OMPT_OPTIONAL #cmakedefine01 LIBOMP_USE_ADAPTIVE_LOCKS diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp index 87875a0e1bdc..bfbad559a7cb 100644 --- a/openmp/runtime/src/kmp_runtime.cpp +++ b/openmp/runtime/src/kmp_runtime.cpp @@ -32,6 +32,11 @@ #include "ompt-specific.h" #endif +#if OMPTARGET_PROFILING_SUPPORT +#include "llvm/Support/TimeProfiler.h" +static char *ProfileTraceFile = nullptr; +#endif + /* these are temporary issues to be dealt with */ #define KMP_USE_PRCTL 0 @@ -5701,6 +5706,13 @@ void __kmp_free_thread(kmp_info_t *this_th) { /* ------------------------------------------------------------------------ */ void *__kmp_launch_thread(kmp_info_t *this_thr) { +#if OMPTARGET_PROFILING_SUPPORT + ProfileTraceFile = getenv("LIBOMPTARGET_PROFILE"); + // TODO: add a configuration option for time granularity + if (ProfileTraceFile) + llvm::timeTraceProfilerInitialize(500 /* us */, "libomptarget"); +#endif + int gtid = this_thr->th.th_info.ds.ds_gtid; /* void *stack_data;*/ kmp_team_t **volatile pteam; @@ -5801,6 +5813,10 @@ void *__kmp_launch_thread(kmp_info_t *this_thr) { KA_TRACE(10, ("__kmp_launch_thread: T#%d done\n", gtid)); KMP_MB(); + +#if OMPTARGET_PROFILING_SUPPORT + llvm::timeTraceProfilerFinishThread(); +#endif return this_thr; } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits