Index: openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp =================================================================== --- openmp/trunk/libomptarget/plugins/cuda/src/rtl.cpp +++ openmp/trunk/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 @@ } 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); Index: openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp =================================================================== --- openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp +++ openmp/trunk/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #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 @@ 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 Index: openmp/trunk/libomptarget/src/omptarget.cpp =================================================================== --- openmp/trunk/libomptarget/src/omptarget.cpp +++ openmp/trunk/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 @@ }; 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")) { Index: openmp/trunk/libomptarget/test/CMakeLists.txt =================================================================== --- openmp/trunk/libomptarget/test/CMakeLists.txt +++ openmp/trunk/libomptarget/test/CMakeLists.txt @@ -10,6 +10,12 @@ 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) Index: openmp/trunk/libomptarget/test/env/omp_target_debug.c =================================================================== --- openmp/trunk/libomptarget/test/env/omp_target_debug.c +++ openmp/trunk/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 + Index: openmp/trunk/libomptarget/test/lit.cfg =================================================================== --- openmp/trunk/libomptarget/test/lit.cfg +++ openmp/trunk/libomptarget/test/lit.cfg @@ -42,6 +42,9 @@ 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 @@ " | " + 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 @@ 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, \ Index: openmp/trunk/libomptarget/test/lit.site.cfg.in =================================================================== --- openmp/trunk/libomptarget/test/lit.site.cfg.in +++ openmp/trunk/libomptarget/test/lit.site.cfg.in @@ -14,6 +14,7 @@ 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")