namespace _OMP {
namespace config {
-enum DebugLevel : int32_t { Assertion };
+enum DebugKind : uint32_t {
+ Assertion = 1U << 0,
+ FunctionTracing = 1U << 1,
+};
/// Return the number of devices in the system, same number as returned on the
/// host by omp_get_num_devices.
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
#define PRINTF(fmt, ...) (void)fmt;
#define PRINT(str) PRINTF("%s", str)
+///}
+
+/// Enter a debugging scope for performing function traces. Enabled with
+/// FunctionTracting set in the debug kind.
+#define FunctionTracingRAII() \
+ DebugEntryRAII Entry(__LINE__, __PRETTY_FUNCTION__);
+
+/// An RAII class for handling entries to debug locations. The current location
+/// and function will be printed on entry. Nested levels increase the
+/// indentation shown in the debugging output.
+struct DebugEntryRAII {
+ DebugEntryRAII(const unsigned Line, const char *Function);
+ ~DebugEntryRAII();
+};
+
#endif
using namespace _OMP;
struct DeviceEnvironmentTy {
- uint32_t DebugLevel;
+ uint32_t DebugKind;
uint32_t NumDevices;
uint32_t DeviceNum;
uint64_t DynamicMemSize;
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() {
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
#include "Debug.h"
#include "Configuration.h"
+#include "Mapping.h"
+#include "Types.h"
using namespace _OMP;
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();
}
}
}
+/// Current indentation level for the function trace. Only accessed by thread 0.
+static uint32_t Level = 0;
+#pragma omp allocate(Level) allocator(omp_pteam_mem_alloc)
+
+DebugEntryRAII::DebugEntryRAII(const unsigned Line, const char *Function) {
+ if (config::isDebugMode(config::DebugKind::FunctionTracing) &&
+ mapping::getThreadIdInBlock() == 0) {
+
+ for (int I = 0; I < Level; ++I)
+ PRINTF("%s", " ");
+
+ PRINTF("Line %u: Thread %u Entering %s:%u\n", Line,
+ mapping::getThreadIdInBlock(), Function);
+ Level++;
+ }
+}
+
+DebugEntryRAII::~DebugEntryRAII() {
+ if (config::isDebugMode(config::DebugKind::FunctionTracing) &&
+ mapping::getThreadIdInBlock() == 0)
+ Level--;
+}
+
#pragma omp end declare target