Skip to content

Commit

Permalink
[OpenMP] Add time profiling support in libomp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ggeorgakoudis committed Jan 21, 2021
1 parent 4dbdff6 commit 6b7645d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions openmp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions openmp/runtime/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions openmp/runtime/src/kmp_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions openmp/runtime/src/kmp_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 6b7645d

Please sign in to comment.