Skip to content

Commit 1cea309

Browse files
committed
[OpenMP][NFC] Move DebugKind to make it reusable from the host
1 parent 499fb1b commit 1cea309

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

openmp/libomptarget/DeviceRTL/include/Configuration.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
#ifndef OMPTARGET_CONFIGURATION_H
1414
#define OMPTARGET_CONFIGURATION_H
1515

16+
#include "Environment.h"
1617
#include "Types.h"
1718

1819
namespace ompx {
1920
namespace config {
2021

21-
enum DebugKind : uint32_t {
22-
Assertion = 1U << 0,
23-
FunctionTracing = 1U << 1,
24-
CommonIssues = 1U << 2,
25-
};
26-
2722
/// Return the number of devices in the system, same number as returned on the
2823
/// host by omp_get_num_devices.
2924
uint32_t getNumDevices();
@@ -50,7 +45,7 @@ uint64_t getIndirectCallTableSize();
5045
uint64_t getHardwareParallelism();
5146

5247
/// Return if debugging is enabled for the given debug kind.
53-
bool isDebugMode(DebugKind Level);
48+
bool isDebugMode(DeviceDebugKind Level);
5449

5550
/// Indicates if this kernel may require thread-specific states, or if it was
5651
/// explicitly disabled by the user.

openmp/libomptarget/DeviceRTL/include/Debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void __assert_fail_internal(const char *expr, const char *msg, const char *file,
2828

2929
#define ASSERT(expr, msg) \
3030
{ \
31-
if (config::isDebugMode(config::DebugKind::Assertion) && !(expr)) \
31+
if (config::isDebugMode(DeviceDebugKind::Assertion) && !(expr)) \
3232
__assert_fail_internal(#expr, msg, __FILE__, __LINE__, \
3333
__PRETTY_FUNCTION__); \
3434
else \

openmp/libomptarget/DeviceRTL/src/Configuration.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "Configuration.h"
15-
#include "Environment.h"
1615
#include "State.h"
1716
#include "Types.h"
1817

@@ -32,7 +31,7 @@ using namespace ompx;
3231
CONSTANT(__omp_rtl_device_environment);
3332

3433
uint32_t config::getDebugKind() {
35-
return __omp_rtl_debug_kind & __omp_rtl_device_environment.DebugKind;
34+
return __omp_rtl_debug_kind & __omp_rtl_device_environment.DeviceDebugKind;
3635
}
3736

3837
uint32_t config::getNumDevices() {
@@ -64,8 +63,8 @@ uint64_t config::getIndirectCallTableSize() {
6463
return __omp_rtl_device_environment.IndirectCallTableSize;
6564
}
6665

67-
bool config::isDebugMode(config::DebugKind Kind) {
68-
return config::getDebugKind() & Kind;
66+
bool config::isDebugMode(DeviceDebugKind Kind) {
67+
return config::getDebugKind() & uint32_t(Kind);
6968
}
7069

7170
bool config::mayUseThreadStates() { return !__omp_rtl_assume_no_thread_state; }

openmp/libomptarget/DeviceRTL/src/State.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
137137
return Ptr;
138138
}
139139

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

173173
void *memory::allocGlobal(uint64_t Bytes, const char *Reason) {
174174
void *Ptr = malloc(Bytes);
175-
if (config::isDebugMode(config::DebugKind::CommonIssues) && Ptr == nullptr)
175+
if (config::isDebugMode(DeviceDebugKind::CommonIssues) && Ptr == nullptr)
176176
PRINT("nullptr returned by malloc!\n");
177177
return Ptr;
178178
}

openmp/libomptarget/include/Environment.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ using IdentTy = ident_t;
2525

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

28+
enum class DeviceDebugKind : uint32_t {
29+
Assertion = 1U << 0,
30+
FunctionTracing = 1U << 1,
31+
CommonIssues = 1U << 2,
32+
AllocationTracker = 1U << 3,
33+
};
34+
2835
struct DeviceEnvironmentTy {
29-
uint32_t DebugKind;
36+
uint32_t DeviceDebugKind;
3037
uint32_t NumDevices;
3138
uint32_t DeviceNum;
3239
uint32_t DynamicMemSize;

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "PluginInterface.h"
1212
#include "Debug.h"
13+
#include "Environment.h"
1314
#include "GlobalHandler.h"
1415
#include "JIT.h"
1516
#include "elf_common.h"
@@ -687,7 +688,7 @@ Error GenericDeviceTy::setupDeviceEnvironment(GenericPluginTy &Plugin,
687688
return CallTablePairOrErr.takeError();
688689

689690
DeviceEnvironmentTy DeviceEnvironment;
690-
DeviceEnvironment.DebugKind = OMPX_DebugKind;
691+
DeviceEnvironment.DeviceDebugKind = OMPX_DebugKind;
691692
DeviceEnvironment.NumDevices = Plugin.getNumDevices();
692693
// TODO: The device ID used here is not the real device ID used by OpenMP.
693694
DeviceEnvironment.DeviceNum = DeviceId;

0 commit comments

Comments
 (0)