Skip to content

Commit

Permalink
[OpenMP][NFC] Move DebugKind to make it reusable from the host
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoerfert committed Oct 21, 2023
1 parent 499fb1b commit 1cea309
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
9 changes: 2 additions & 7 deletions openmp/libomptarget/DeviceRTL/include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
#ifndef OMPTARGET_CONFIGURATION_H
#define OMPTARGET_CONFIGURATION_H

#include "Environment.h"
#include "Types.h"

namespace ompx {
namespace config {

enum DebugKind : uint32_t {
Assertion = 1U << 0,
FunctionTracing = 1U << 1,
CommonIssues = 1U << 2,
};

/// Return the number of devices in the system, same number as returned on the
/// host by omp_get_num_devices.
uint32_t getNumDevices();
Expand All @@ -50,7 +45,7 @@ uint64_t getIndirectCallTableSize();
uint64_t getHardwareParallelism();

/// Return if debugging is enabled for the given debug kind.
bool isDebugMode(DebugKind Level);
bool isDebugMode(DeviceDebugKind Level);

/// Indicates if this kernel may require thread-specific states, or if it was
/// explicitly disabled by the user.
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/DeviceRTL/include/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void __assert_fail_internal(const char *expr, const char *msg, const char *file,

#define ASSERT(expr, msg) \
{ \
if (config::isDebugMode(config::DebugKind::Assertion) && !(expr)) \
if (config::isDebugMode(DeviceDebugKind::Assertion) && !(expr)) \
__assert_fail_internal(#expr, msg, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
else \
Expand Down
7 changes: 3 additions & 4 deletions openmp/libomptarget/DeviceRTL/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//

#include "Configuration.h"
#include "Environment.h"
#include "State.h"
#include "Types.h"

Expand All @@ -32,7 +31,7 @@ using namespace ompx;
CONSTANT(__omp_rtl_device_environment);

uint32_t config::getDebugKind() {
return __omp_rtl_debug_kind & __omp_rtl_device_environment.DebugKind;
return __omp_rtl_debug_kind & __omp_rtl_device_environment.DeviceDebugKind;
}

uint32_t config::getNumDevices() {
Expand Down Expand Up @@ -64,8 +63,8 @@ uint64_t config::getIndirectCallTableSize() {
return __omp_rtl_device_environment.IndirectCallTableSize;
}

bool config::isDebugMode(config::DebugKind Kind) {
return config::getDebugKind() & Kind;
bool config::isDebugMode(DeviceDebugKind Kind) {
return config::getDebugKind() & uint32_t(Kind);
}

bool config::mayUseThreadStates() { return !__omp_rtl_assume_no_thread_state; }
Expand Down
4 changes: 2 additions & 2 deletions openmp/libomptarget/DeviceRTL/src/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
return Ptr;
}

if (config::isDebugMode(config::DebugKind::CommonIssues))
if (config::isDebugMode(DeviceDebugKind::CommonIssues))
PRINT("Shared memory stack full, fallback to dynamic allocation of global "
"memory will negatively impact performance.\n");
void *GlobalMemory = memory::allocGlobal(
Expand Down Expand Up @@ -172,7 +172,7 @@ void memory::freeShared(void *Ptr, uint64_t Bytes, const char *Reason) {

void *memory::allocGlobal(uint64_t Bytes, const char *Reason) {
void *Ptr = malloc(Bytes);
if (config::isDebugMode(config::DebugKind::CommonIssues) && Ptr == nullptr)
if (config::isDebugMode(DeviceDebugKind::CommonIssues) && Ptr == nullptr)
PRINT("nullptr returned by malloc!\n");
return Ptr;
}
Expand Down
9 changes: 8 additions & 1 deletion openmp/libomptarget/include/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ using IdentTy = ident_t;

#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"

enum class DeviceDebugKind : uint32_t {
Assertion = 1U << 0,
FunctionTracing = 1U << 1,
CommonIssues = 1U << 2,
AllocationTracker = 1U << 3,
};

struct DeviceEnvironmentTy {
uint32_t DebugKind;
uint32_t DeviceDebugKind;
uint32_t NumDevices;
uint32_t DeviceNum;
uint32_t DynamicMemSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "PluginInterface.h"
#include "Debug.h"
#include "Environment.h"
#include "GlobalHandler.h"
#include "JIT.h"
#include "elf_common.h"
Expand Down Expand Up @@ -687,7 +688,7 @@ Error GenericDeviceTy::setupDeviceEnvironment(GenericPluginTy &Plugin,
return CallTablePairOrErr.takeError();

DeviceEnvironmentTy DeviceEnvironment;
DeviceEnvironment.DebugKind = OMPX_DebugKind;
DeviceEnvironment.DeviceDebugKind = OMPX_DebugKind;
DeviceEnvironment.NumDevices = Plugin.getNumDevices();
// TODO: The device ID used here is not the real device ID used by OpenMP.
DeviceEnvironment.DeviceNum = DeviceId;
Expand Down

0 comments on commit 1cea309

Please sign in to comment.