diff options
author | Sergey Dmitriev <serguei.n.dmitriev@intel.com> | 2017-08-14 15:09:59 +0000 |
---|---|---|
committer | Sergey Dmitriev <serguei.n.dmitriev@intel.com> | 2017-08-14 15:09:59 +0000 |
commit | b305d26b57623a54ddd0ce3f534f416b67c9abed (patch) | |
tree | 2b3e90e415d2e8672554282459df75fd82499da5 /openmp | |
parent | 3c595a6b2c58a23c42a6270bddca8ae99108b5be (diff) | |
download | bcm5719-llvm-b305d26b57623a54ddd0ce3f534f416b67c9abed.tar.gz bcm5719-llvm-b305d26b57623a54ddd0ce3f534f416b67c9abed.zip |
[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
llvm-svn: 310841
Diffstat (limited to 'openmp')
-rw-r--r-- | openmp/libomptarget/plugins/cuda/src/rtl.cpp | 19 | ||||
-rw-r--r-- | openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp | 24 | ||||
-rw-r--r-- | openmp/libomptarget/src/omptarget.cpp | 20 | ||||
-rw-r--r-- | openmp/libomptarget/test/CMakeLists.txt | 6 | ||||
-rw-r--r-- | openmp/libomptarget/test/env/omp_target_debug.c | 20 | ||||
-rw-r--r-- | openmp/libomptarget/test/lit.cfg | 29 | ||||
-rw-r--r-- | openmp/libomptarget/test/lit.site.cfg.in | 1 |
7 files changed, 112 insertions, 7 deletions
diff --git a/openmp/libomptarget/plugins/cuda/src/rtl.cpp b/openmp/libomptarget/plugins/cuda/src/rtl.cpp index 9981cf2f650..7f39ebce6a5 100644 --- a/openmp/libomptarget/plugins/cuda/src/rtl.cpp +++ b/openmp/libomptarget/plugins/cuda/src/rtl.cpp @@ -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); diff --git a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp index f6a69df0839..558388dbce6 100644 --- a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp +++ b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp @@ -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 diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp index 8edc3f7db22..95e0e1ee2ba 100644 --- a/openmp/libomptarget/src/omptarget.cpp +++ b/openmp/libomptarget/src/omptarget.cpp @@ -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")) { diff --git a/openmp/libomptarget/test/CMakeLists.txt b/openmp/libomptarget/test/CMakeLists.txt index 29814df2e6d..f22fcee413e 100644 --- a/openmp/libomptarget/test/CMakeLists.txt +++ b/openmp/libomptarget/test/CMakeLists.txt @@ -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) diff --git a/openmp/libomptarget/test/env/omp_target_debug.c b/openmp/libomptarget/test/env/omp_target_debug.c new file mode 100644 index 00000000000..ce84c9842f6 --- /dev/null +++ b/openmp/libomptarget/test/env/omp_target_debug.c @@ -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 + diff --git a/openmp/libomptarget/test/lit.cfg b/openmp/libomptarget/test/lit.cfg index 88b20e967fc..f7e533b1049 100644 --- a/openmp/libomptarget/test/lit.cfg +++ b/openmp/libomptarget/test/lit.cfg @@ -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.libomptarget_all_targets: " | " + 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.libomptarget_all_targets: 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, \ diff --git a/openmp/libomptarget/test/lit.site.cfg.in b/openmp/libomptarget/test/lit.site.cfg.in index ae649a99e7e..a448e27964b 100644 --- a/openmp/libomptarget/test/lit.site.cfg.in +++ b/openmp/libomptarget/test/lit.site.cfg.in @@ -14,6 +14,7 @@ config.operating_system = "@CMAKE_SYSTEM_NAME@" 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") |