[Openmp-commits] [openmp] r310841 - [OpenMP] libomptarget: move debugging dumps under control of env var LIBOMPTARGET_DEBUG

Sergey Dmitriev via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 14 08:10:00 PDT 2017


Author: sdmitriev
Date: Mon Aug 14 08:09:59 2017
New Revision: 310841

URL: http://llvm.org/viewvc/llvm-project?rev=310841&view=rev
Log:
[OpenMP] libomptarget: move debugging dumps under control of env var LIBOMPTARGET_DEBUG

Disable default debugging dumps for libomptarget and plugins and move dumps
under control of environment variable LIBOMPTARGET_DEBUG=<integer>. Dumps
are enabled when LIBOMPTARGET_DEBUG is set to a positive integer value.

Debugging dumps are available only in debug build; release build does not
support it.

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

Added:
    openmp/trunk/libomptarget/test/env/
    openmp/trunk/libomptarget/test/env/omp_target_debug.c   (with props)
Modified:
    openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp
    openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
    openmp/trunk/libomptarget/src/omptarget.cpp
    openmp/trunk/libomptarget/test/CMakeLists.txt
    openmp/trunk/libomptarget/test/lit.cfg
    openmp/trunk/libomptarget/test/lit.site.cfg.in

Modified: openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp?rev=310841&r1=310840&r2=310841&view=diff
==============================================================================
--- openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp (original)
+++ openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp Mon Aug 14 08:09:59 2017
@@ -25,9 +25,20 @@
 #define TARGET_NAME CUDA
 #endif
 
+#ifdef OMPTARGET_DEBUG
+static int DebugLevel = 0;
+
 #define GETNAME2(name) #name
 #define GETNAME(name) GETNAME2(name)
-#define DP(...) DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__)
+#define DP(...) \
+  do { \
+    if (DebugLevel > 0) { \
+      DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__); \
+    } \
+  } while (false)
+#else // OMPTARGET_DEBUG
+#define DP(...) {}
+#endif // OMPTARGET_DEBUG
 
 #include "../../common/elf_common.c"
 
@@ -157,6 +168,12 @@ public:
   }
 
   RTLDeviceInfoTy() {
+#ifdef OMPTARGET_DEBUG
+    if (char *envStr = getenv("LIBOMPTARGET_DEBUG")) {
+      DebugLevel = std::stoi(envStr);
+    }
+#endif // OMPTARGET_DEBUG
+
     DP("Start initializing CUDA\n");
 
     CUresult err = cuInit(0);

Modified: openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp?rev=310841&r1=310840&r2=310841&view=diff
==============================================================================
--- openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp (original)
+++ openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp Mon Aug 14 08:09:59 2017
@@ -20,6 +20,7 @@
 #include <gelf.h>
 #include <link.h>
 #include <list>
+#include <string>
 #include <vector>
 
 #include "omptargetplugin.h"
@@ -32,9 +33,20 @@
 #define TARGET_ELF_ID 0
 #endif
 
+#ifdef OMPTARGET_DEBUG
+static int DebugLevel = 0;
+
 #define GETNAME2(name) #name
 #define GETNAME(name) GETNAME2(name)
-#define DP(...) DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__)
+#define DP(...) \
+  do { \
+    if (DebugLevel > 0) { \
+      DEBUGP("Target " GETNAME(TARGET_NAME) " RTL", __VA_ARGS__); \
+    } \
+  } while (false)
+#else // OMPTARGET_DEBUG
+#define DP(...) {}
+#endif // OMPTARGET_DEBUG
 
 #include "../../common/elf_common.c"
 
@@ -94,7 +106,15 @@ public:
     return &E.Table;
   }
 
-  RTLDeviceInfoTy(int32_t num_devices) { FuncGblEntries.resize(num_devices); }
+  RTLDeviceInfoTy(int32_t num_devices) {
+#ifdef OMPTARGET_DEBUG
+    if (char *envStr = getenv("LIBOMPTARGET_DEBUG")) {
+      DebugLevel = std::stoi(envStr);
+    }
+#endif // OMPTARGET_DEBUG
+
+    FuncGblEntries.resize(num_devices);
+  }
 
   ~RTLDeviceInfoTy() {
     // Close dynamic libraries

Modified: openmp/trunk/libomptarget/src/omptarget.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/src/omptarget.cpp?rev=310841&r1=310840&r2=310841&view=diff
==============================================================================
--- openmp/trunk/libomptarget/src/omptarget.cpp (original)
+++ openmp/trunk/libomptarget/src/omptarget.cpp Mon Aug 14 08:09:59 2017
@@ -27,7 +27,19 @@
 // Header file global to this project
 #include "omptarget.h"
 
-#define DP(...) DEBUGP("Libomptarget", __VA_ARGS__)
+#ifdef OMPTARGET_DEBUG
+static int DebugLevel = 0;
+
+#define DP(...) \
+  do { \
+    if (DebugLevel > 0) { \
+      DEBUGP("Libomptarget", __VA_ARGS__); \
+    } \
+  } while (false)
+#else // OMPTARGET_DEBUG
+#define DP(...) {}
+#endif // OMPTARGET_DEBUG
+
 #define INF_REF_CNT (LONG_MAX>>1) // leave room for additions/subtractions
 #define CONSIDERED_INF(x) (x > (INF_REF_CNT>>1))
 
@@ -281,6 +293,12 @@ public:
 };
 
 void RTLsTy::LoadRTLs() {
+#ifdef OMPTARGET_DEBUG
+  if (char *envStr = getenv("LIBOMPTARGET_DEBUG")) {
+    DebugLevel = std::stoi(envStr);
+  }
+#endif // OMPTARGET_DEBUG
+
   // Parse environment variable OMP_TARGET_OFFLOAD (if set)
   char *envStr = getenv("OMP_TARGET_OFFLOAD");
   if (envStr && !strcmp(envStr, "DISABLED")) {

Modified: openmp/trunk/libomptarget/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/test/CMakeLists.txt?rev=310841&r1=310840&r2=310841&view=diff
==============================================================================
--- openmp/trunk/libomptarget/test/CMakeLists.txt (original)
+++ openmp/trunk/libomptarget/test/CMakeLists.txt Mon Aug 14 08:09:59 2017
@@ -10,6 +10,12 @@ endif()
 set(LIBOMPTARGET_TEST_CFLAGS "" CACHE STRING
   "Extra compiler flags to send to the test compiler")
 
+if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug)
+  set(LIBOMPTARGET_DEBUG True)
+else()
+  set(LIBOMPTARGET_DEBUG False)
+endif()
+
 if(${LIBOMPTARGET_STANDALONE_BUILD})
   # Make sure we can use the console pool for recent cmake and ninja > 1.5
   if(CMAKE_VERSION VERSION_LESS 3.1.20141117)

Added: openmp/trunk/libomptarget/test/env/omp_target_debug.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/test/env/omp_target_debug.c?rev=310841&view=auto
==============================================================================
--- openmp/trunk/libomptarget/test/env/omp_target_debug.c (added)
+++ openmp/trunk/libomptarget/test/env/omp_target_debug.c Mon Aug 14 08:09:59 2017
@@ -0,0 +1,20 @@
+// RUN: %libomptarget-compile-aarch64-unknown-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-aarch64-unknown-linux-gnu 2>&1 | %fcheck-aarch64-unknown-linux-gnu -allow-empty -check-prefix=DEBUG
+// RUN: %libomptarget-compile-aarch64-unknown-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-aarch64-unknown-linux-gnu 2>&1 | %fcheck-aarch64-unknown-linux-gnu -allow-empty -check-prefix=NDEBUG
+// RUN: %libomptarget-compile-powerpc64-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-powerpc64-ibm-linux-gnu 2>&1 | %fcheck-powerpc64-ibm-linux-gnu -allow-empty -check-prefix=DEBUG
+// RUN: %libomptarget-compile-powerpc64-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-powerpc64-ibm-linux-gnu 2>&1 | %fcheck-powerpc64-ibm-linux-gnu -allow-empty -check-prefix=NDEBUG
+// RUN: %libomptarget-compile-powerpc64le-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-powerpc64le-ibm-linux-gnu 2>&1 | %fcheck-powerpc64le-ibm-linux-gnu -allow-empty -check-prefix=DEBUG
+// RUN: %libomptarget-compile-powerpc64le-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-powerpc64le-ibm-linux-gnu 2>&1 | %fcheck-powerpc64le-ibm-linux-gnu -allow-empty -check-prefix=NDEBUG
+// RUN: %libomptarget-compile-x86_64-pc-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-x86_64-pc-linux-gnu 2>&1 | %fcheck-x86_64-pc-linux-gnu -allow-empty -check-prefix=DEBUG
+// RUN: %libomptarget-compile-x86_64-pc-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-x86_64-pc-linux-gnu 2>&1 | %fcheck-x86_64-pc-linux-gnu -allow-empty -check-prefix=NDEBUG
+// REQUIRES: libomptarget-debug
+
+int main(void) {
+#pragma omp target
+  {}
+  return 0;
+}
+
+// DEBUG: Libomptarget
+// NDEBUG-NOT: Libomptarget
+// NDEBUG-NOT: Target
+

Propchange: openmp/trunk/libomptarget/test/env/omp_target_debug.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openmp/trunk/libomptarget/test/env/omp_target_debug.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: openmp/trunk/libomptarget/test/env/omp_target_debug.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: openmp/trunk/libomptarget/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/test/lit.cfg?rev=310841&r1=310840&r2=310841&view=diff
==============================================================================
--- openmp/trunk/libomptarget/test/lit.cfg (original)
+++ openmp/trunk/libomptarget/test/lit.cfg Mon Aug 14 08:09:59 2017
@@ -42,6 +42,9 @@ if config.omp_host_rtl_directory:
 
 config.test_cflags = config.test_cflags + " " + config.test_extra_cflags
 
+if config.libomptarget_debug:
+  config.available_features.add('libomptarget-debug')
+
 # Setup environment to find dynamic library at runtime
 if config.operating_system == 'Windows':
     append_dynamic_library_path('PATH', config.library_dir, ";")
@@ -77,12 +80,23 @@ for libomptarget_target in config.libomp
             " | " + config.libomptarget_filecheck + " %s"))
         config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
             libomptarget_target, \
-            "%clangxx-" + libomptarget_target + " %s -o %t-" + \
-            libomptarget_target + " && %t-" + libomptarget_target))
+            "%libomptarget-compilexx-" + libomptarget_target + " && " + \
+            "%libomptarget-run-" + libomptarget_target))
         config.substitutions.append(("%libomptarget-compile-and-run-" + \
             libomptarget_target, \
+            "%libomptarget-compile-" + libomptarget_target + " && " + \
+            "%libomptarget-run-" + libomptarget_target))
+        config.substitutions.append(("%libomptarget-compilexx-" + \
+            libomptarget_target, \
+            "%clangxx-" + libomptarget_target + " %s -o %t-" + \
+            libomptarget_target))
+        config.substitutions.append(("%libomptarget-compile-" + \
+            libomptarget_target, \
             "%clang-" + libomptarget_target + " %s -o %t-" + \
-            libomptarget_target + " && %t-" + libomptarget_target))
+            libomptarget_target))
+        config.substitutions.append(("%libomptarget-run-" + \
+            libomptarget_target, \
+            "%t-" + libomptarget_target))
         config.substitutions.append(("%clangxx-" + libomptarget_target, \
             "%clangxx %cflags -fopenmp-targets=" + libomptarget_target))
         config.substitutions.append(("%clang-" + libomptarget_target, \
@@ -102,6 +116,15 @@ for libomptarget_target in config.libomp
         config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
             libomptarget_target, \
             "echo ignored-command"))
+        config.substitutions.append(("%libomptarget-compilexx-" + \
+            libomptarget_target, \
+            "echo ignored-command"))
+        config.substitutions.append(("%libomptarget-compile-" + \
+            libomptarget_target, \
+            "echo ignored-command"))
+        config.substitutions.append(("%libomptarget-run-" + \
+            libomptarget_target, \
+            "echo ignored-command"))
         config.substitutions.append(("%clang-" + libomptarget_target, \
             "echo ignored-command"))
         config.substitutions.append(("%clangxx-" + libomptarget_target, \

Modified: openmp/trunk/libomptarget/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/libomptarget/test/lit.site.cfg.in?rev=310841&r1=310840&r2=310841&view=diff
==============================================================================
--- openmp/trunk/libomptarget/test/lit.site.cfg.in (original)
+++ openmp/trunk/libomptarget/test/lit.site.cfg.in Mon Aug 14 08:09:59 2017
@@ -14,6 +14,7 @@ config.operating_system = "@CMAKE_SYSTEM
 config.libomptarget_all_targets = "@LIBOMPTARGET_ALL_TARGETS@".split()
 config.libomptarget_system_targets = "@LIBOMPTARGET_SYSTEM_TARGETS@".split()
 config.libomptarget_filecheck = "@LIBOMPTARGET_FILECHECK_EXECUTABLE@"
+config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBOMPTARGET_BASE_DIR@/test/lit.cfg")




More information about the Openmp-commits mailing list