diff --git a/openmp/libomptarget/DeviceRTL/include/Configuration.h b/openmp/libomptarget/DeviceRTL/include/Configuration.h --- a/openmp/libomptarget/DeviceRTL/include/Configuration.h +++ b/openmp/libomptarget/DeviceRTL/include/Configuration.h @@ -18,7 +18,10 @@ namespace _OMP { namespace config { -enum DebugLevel : int32_t { Assertion }; +enum DebugKind : uint32_t { + Assertion = 1 << 0, + FunctionTracing = 1 << 1, +}; /// Return the number of devices in the system, same number as returned on the /// host by omp_get_num_devices. @@ -29,12 +32,12 @@ uint32_t getDeviceNum(); /// Return the user choosen debug level. -uint32_t getDebugLevel(); +uint32_t getDebugKind(); /// Return the amount of dynamic shared memory that was allocated at launch. uint64_t getDynamicMemorySize(); -bool isDebugMode(DebugLevel Level); +bool isDebugMode(DebugKind Level); } // namespace config } // namespace _OMP diff --git a/openmp/libomptarget/DeviceRTL/include/Debug.h b/openmp/libomptarget/DeviceRTL/include/Debug.h --- a/openmp/libomptarget/DeviceRTL/include/Debug.h +++ b/openmp/libomptarget/DeviceRTL/include/Debug.h @@ -37,4 +37,11 @@ ///} +#define ENTER DebugEntryRAII Entry(__FILE__, __LINE__, __PRETTY_FUNCTION__); + +struct DebugEntryRAII { + DebugEntryRAII(const char *File, const unsigned Line, const char *Function); + ~DebugEntryRAII(); +}; + #endif diff --git a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp --- a/openmp/libomptarget/DeviceRTL/src/Configuration.cpp +++ b/openmp/libomptarget/DeviceRTL/src/Configuration.cpp @@ -18,7 +18,7 @@ using namespace _OMP; struct DeviceEnvironmentTy { - uint32_t DebugLevel; + uint32_t DebugKind; uint32_t NumDevices; uint32_t DeviceNum; uint64_t DynamicMemSize; @@ -32,8 +32,8 @@ DeviceEnvironmentTy CONSTANT(omptarget_device_environment) __attribute__((used)); -uint32_t config::getDebugLevel() { - return __omp_rtl_debug_kind & omptarget_device_environment.DebugLevel; +uint32_t config::getDebugKind() { + return __omp_rtl_debug_kind & omptarget_device_environment.DebugKind; } uint32_t config::getNumDevices() { @@ -48,8 +48,8 @@ return omptarget_device_environment.DynamicMemSize; } -bool config::isDebugMode(config::DebugLevel Level) { - return config::getDebugLevel() > Level; +bool config::isDebugMode(config::DebugKind Kind) { + return config::getDebugKind() & Kind; } #pragma omp end declare target diff --git a/openmp/libomptarget/DeviceRTL/src/Debug.cpp b/openmp/libomptarget/DeviceRTL/src/Debug.cpp --- a/openmp/libomptarget/DeviceRTL/src/Debug.cpp +++ b/openmp/libomptarget/DeviceRTL/src/Debug.cpp @@ -12,6 +12,7 @@ #include "Debug.h" #include "Configuration.h" +#include "Mapping.h" using namespace _OMP; @@ -19,7 +20,7 @@ extern "C" { void __assert_assume(bool cond, const char *exp, const char *file, int line) { - if (!cond && config::isDebugMode(config::DebugLevel::Assertion)) { + if (!cond && config::isDebugMode(config::DebugKind::Assertion)) { PRINTF("ASSERTION failed: %s at %s, line %d\n", exp, file, line); __builtin_trap(); } @@ -47,4 +48,29 @@ #pragma omp end declare variant ///} +namespace { +/// Current indentation level for the function trace. Only accessed by thread 0. +uint32_t Level = 0; +} // namespace + +DebugEntryRAII::DebugEntryRAII(const char *File, const unsigned Line, + const char *Function) { + if (mapping::getThreadIdInBlock() == 0 && + config::isDebugMode(config::DebugKind::FunctionTracing)) { + + for (int I = 0; I < Level; ++I) + PRINTF("%s", " "); + + PRINTF("%s:%u: Thread %u Entering %s:\n", File, Line, + mapping::getThreadIdInBlock(), Function); + Level++; + } +} + +DebugEntryRAII::~DebugEntryRAII() { + if (mapping::getThreadIdInBlock() == 0 && + config::isDebugMode(config::DebugKind::FunctionTracing)) + Level--; +} + #pragma omp end declare target