[llvm-branch-commits] [openmp] 6b7645d - [OpenMP] Add time profiling support in libomp

2021-01-21 Thread Giorgis Georgakoudis via llvm-branch-commits

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

[llvm-branch-commits] [openmp] 18dff28 - [OpenMP] Add doxygen generation for the runtime

2020-12-08 Thread Giorgis Georgakoudis via llvm-branch-commits

Author: Giorgis Georgakoudis
Date: 2020-12-08T16:20:45-08:00
New Revision: 18dff28958804efa6205ffaf12fce65a08211ec5

URL: 
https://github.com/llvm/llvm-project/commit/18dff28958804efa6205ffaf12fce65a08211ec5
DIFF: 
https://github.com/llvm/llvm-project/commit/18dff28958804efa6205ffaf12fce65a08211ec5.diff

LOG: [OpenMP] Add doxygen generation for the runtime

Reviewed By: jdoerfert

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

Added: 
openmp/docs/doxygen-mainpage.dox
openmp/docs/doxygen.cfg.in

Modified: 
openmp/docs/CMakeLists.txt

Removed: 




diff  --git a/openmp/docs/CMakeLists.txt b/openmp/docs/CMakeLists.txt
index 20ef78f74c9d..1e4be31a6f60 100644
--- a/openmp/docs/CMakeLists.txt
+++ b/openmp/docs/CMakeLists.txt
@@ -1,3 +1,95 @@
+
+if (DOXYGEN_FOUND)
+if (LLVM_ENABLE_DOXYGEN)
+  set(abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
+  set(abs_builddir ${CMAKE_CURRENT_BINARY_DIR})
+
+  if (HAVE_DOT)
+set(DOT ${LLVM_PATH_DOT})
+  endif()
+
+  if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
+set(enable_searchengine "YES")
+set(searchengine_url "${LLVM_DOXYGEN_SEARCHENGINE_URL}")
+set(enable_server_based_search "YES")
+set(enable_external_search "YES")
+set(extra_search_mappings "${LLVM_DOXYGEN_SEARCH_MAPPINGS}")
+  else()
+set(enable_searchengine "NO")
+set(searchengine_url "")
+set(enable_server_based_search "NO")
+set(enable_external_search "NO")
+set(extra_search_mappings "")
+  endif()
+
+  # If asked, configure doxygen for the creation of a Qt Compressed Help file.
+  if (LLVM_ENABLE_DOXYGEN_QT_HELP)
+set(OPENMP_DOXYGEN_QCH_FILENAME "org.llvm.openmp.qch" CACHE STRING
+  "Filename of the Qt Compressed help file")
+set(OPENMP_DOXYGEN_QHP_NAMESPACE "org.llvm.openmp" CACHE STRING
+  "Namespace under which the intermediate Qt Help Project file lives")
+set(OPENMP_DOXYGEN_QHP_CUST_FILTER_NAME "Clang ${OPENMP_VERSION}" CACHE 
STRING
+  "See http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-filters";)
+set(OPENMP_DOXYGEN_QHP_CUST_FILTER_ATTRS "Clang,${OPENMP_VERSION}" CACHE 
STRING
+  "See 
http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes";)
+set(openmp_doxygen_generate_qhp "YES")
+set(openmp_doxygen_qch_filename "${OPENMP_DOXYGEN_QCH_FILENAME}")
+set(openmp_doxygen_qhp_namespace "${OPENMP_DOXYGEN_QHP_NAMESPACE}")
+set(openmp_doxygen_qhelpgenerator_path 
"${LLVM_DOXYGEN_QHELPGENERATOR_PATH}")
+set(openmp_doxygen_qhp_cust_filter_name 
"${OPENMP_DOXYGEN_QHP_CUST_FILTER_NAME}")
+set(openmp_doxygen_qhp_cust_filter_attrs 
"${OPENMP_DOXYGEN_QHP_CUST_FILTER_ATTRS}")
+  else()
+set(openmp_doxygen_generate_qhp "NO")
+set(openmp_doxygen_qch_filename "")
+set(openmp_doxygen_qhp_namespace "")
+set(openmp_doxygen_qhelpgenerator_path "")
+set(openmp_doxygen_qhp_cust_filter_name "")
+set(openmp_doxygen_qhp_cust_filter_attrs "")
+  endif()
+
+  option(LLVM_DOXYGEN_SVG
+"Use svg instead of png files for doxygen graphs." OFF)
+  if (LLVM_DOXYGEN_SVG)
+set(DOT_IMAGE_FORMAT "svg")
+  else()
+set(DOT_IMAGE_FORMAT "png")
+  endif()
+
+  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen.cfg.in
+${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg @ONLY)
+
+  set(abs_top_srcdir)
+  set(abs_top_builddir)
+  set(DOT)
+  set(enable_searchengine)
+  set(searchengine_url)
+  set(enable_server_based_search)
+  set(enable_external_search)
+  set(extra_search_mappings)
+  set(openmp_doxygen_generate_qhp)
+  set(openmp_doxygen_qch_filename)
+  set(openmp_doxygen_qhp_namespace)
+  set(openmp_doxygen_qhelpgenerator_path)
+  set(openmp_doxygen_qhp_cust_filter_name)
+  set(openmp_doxygen_qhp_cust_filter_attrs)
+  set(DOT_IMAGE_FORMAT)
+
+  add_custom_target(doxygen-openmp
+COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg
+WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+COMMENT "Generating openmp doxygen documentation." VERBATIM)
+
+  if (LLVM_BUILD_DOCS)
+add_dependencies(doxygen doxygen-openmp)
+  endif()
+
+  if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
+  DESTINATION docs/html)
+  endif()
+endif()
+endif()
+
 if (LLVM_ENABLE_SPHINX)
   include(AddSphinxTarget)
   if (SPHINX_FOUND)

diff  --git a/openmp/docs/doxygen-mainpage.dox 
b/openmp/docs/doxygen-mainpage.dox
new file mode 100644
index ..ee95e3710293
--- /dev/null
+++ b/openmp/docs/doxygen-mainpage.dox
@@ -0,0 +1,5 @@
+/// \mainpage LLVM OpenMP
+///
+/// \section main_intro Introduction
+/// Welcome to the Clang/LLVM OpenMP project.
+

diff  --git a/openmp/docs/doxygen.cfg.in b/openmp/docs/doxygen.cfg.in
new file mode 100644
index ..f02c70336040
--- /dev/null
+++ b/openmp/docs/doxygen.cfg.in
@@ -0,0 +1,2294 @@
+# Doxyfile 1.8.6
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org)

[llvm-branch-commits] [openmp] e007b32 - [OpenMP] Add time profiling for libomptarget

2020-12-11 Thread Giorgis Georgakoudis via llvm-branch-commits

Author: Giorgis Georgakoudis
Date: 2020-12-11T18:53:37-08:00
New Revision: e007b328642946afc9e06bed9a098c7e23989900

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

LOG: [OpenMP] Add time profiling for libomptarget

Reviewed By: jdoerfert

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

Added: 


Modified: 
openmp/CMakeLists.txt
openmp/libomptarget/src/CMakeLists.txt
openmp/libomptarget/src/api.cpp
openmp/libomptarget/src/interface.cpp
openmp/libomptarget/src/private.h
openmp/libomptarget/src/rtl.cpp

Removed: 




diff  --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index 6cc36d9b7577..dc0d3a6e718a 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -82,6 +82,8 @@ endif()
 
 option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for 
offloading."
${ENABLE_LIBOMPTARGET})
+option(OPENMP_ENABLE_LIBOMPTARGET_PROFILING "Enable time profiling for 
libomptarget."
+   ${ENABLE_LIBOMPTARGET})
 if (OPENMP_ENABLE_LIBOMPTARGET)
   # Check that the library can actually be built.
   if (APPLE OR WIN32)

diff  --git a/openmp/libomptarget/src/CMakeLists.txt 
b/openmp/libomptarget/src/CMakeLists.txt
index 46f1969d14e7..586589da401d 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -21,11 +21,23 @@ set(src_files
   omptarget.cpp
 )
 
-# Build libomptarget library with libdl dependency.
-add_library(omptarget SHARED ${src_files})
-target_link_libraries(omptarget
-  ${CMAKE_DL_LIBS}
-  "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
+# Build libomptarget library with libdl dependency. Add LLVMSupport
+# dependency if building in-tree with profiling enabled.
+if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING))
+  add_library(omptarget SHARED ${src_files})
+  target_link_libraries(omptarget
+${CMAKE_DL_LIBS}
+"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
+else()
+  set(LLVM_LINK_COMPONENTS
+Support
+)
+  add_llvm_library(omptarget SHARED ${src_files}
+  LINK_LIBS ${CMAKE_DL_LIBS}
+  "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
+  )
+  target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED)
+endif()
 
 # Install libomptarget under the lib destination folder.
 install(TARGETS omptarget LIBRARY COMPONENT omptarget

diff  --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/api.cpp
index cd5cb0c98c63..58f7cec2fdd6 100644
--- a/openmp/libomptarget/src/api.cpp
+++ b/openmp/libomptarget/src/api.cpp
@@ -19,6 +19,7 @@
 #include 
 
 EXTERN int omp_get_num_devices(void) {
+  TIMESCOPE();
   PM->RTLsMtx.lock();
   size_t DevicesSize = PM->Devices.size();
   PM->RTLsMtx.unlock();
@@ -29,12 +30,14 @@ EXTERN int omp_get_num_devices(void) {
 }
 
 EXTERN int omp_get_initial_device(void) {
+  TIMESCOPE();
   int hostDevice = omp_get_num_devices();
   DP("Call to omp_get_initial_device returning %d\n", hostDevice);
   return hostDevice;
 }
 
 EXTERN void *omp_target_alloc(size_t size, int device_num) {
+  TIMESCOPE();
   DP("Call to omp_target_alloc for device %d requesting %zu bytes\n",
   device_num, size);
 
@@ -62,6 +65,7 @@ EXTERN void *omp_target_alloc(size_t size, int device_num) {
 }
 
 EXTERN void omp_target_free(void *device_ptr, int device_num) {
+  TIMESCOPE();
   DP("Call to omp_target_free for device %d and address " DPxMOD "\n",
   device_num, DPxPTR(device_ptr));
 
@@ -86,6 +90,7 @@ EXTERN void omp_target_free(void *device_ptr, int device_num) 
{
 }
 
 EXTERN int omp_target_is_present(void *ptr, int device_num) {
+  TIMESCOPE();
   DP("Call to omp_target_is_present for device %d and address " DPxMOD "\n",
   device_num, DPxPTR(ptr));
 
@@ -125,6 +130,7 @@ EXTERN int omp_target_is_present(void *ptr, int device_num) 
{
 
 EXTERN int omp_target_memcpy(void *dst, void *src, size_t length,
 size_t dst_offset, size_t src_offset, int dst_device, int src_device) {
+  TIMESCOPE();
   DP("Call to omp_target_memcpy, dst device %d, src device %d, "
   "dst addr " DPxMOD ", src addr " DPxMOD ", dst offset %zu, "
   "src offset %zu, length %zu\n", dst_device, src_device, DPxPTR(dst),
@@ -190,6 +196,7 @@ EXTERN int omp_target_memcpy_rect(void *dst, void *src, 
size_t element_size,
 int num_dims, const size_t *volume, const size_t *dst_offsets,
 const size_t *src_offsets, const size_t *dst_dimensions,
 const size_t *src_dimensions, int dst_device, int src_device) {
+  TIMESCOPE();
   DP("Call to omp_target_memcpy_rect, dst device %d, src device %d, "
   "dst addr " DPxMOD ", src addr " DPxMOD ", dst offsets " DPxMOD ", "
   "src offsets " DPxMOD ", dst dims " DPxMOD ", src dims " DPxMOD ", "
@@ -244,6 +251,7 @@ EXTERN int omp_target_memcpy