Skip to content

Commit e1c7a46

Browse files
committedMay 4, 2018
[OpenMP] Use LIBOMPTARGET_DEVICE_RTL_DEBUG env var to control debug messages on the device side
Summary: Enable the device side debug messages at compile time, use env var to control at runtime. To achieve this, an environment data block is passed to the device lib when it is loaded. By default, the message is off, to enable it, a user need to set LIBOMPDEVICE_DEBUG=1. Reviewers: grokos Reviewed By: grokos Subscribers: openmp-commits Tags: #openmp Differential Revision: https://reviews.llvm.org/D46210 llvm-svn: 331550
1 parent 8e4958e commit e1c7a46

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed
 

‎openmp/libomptarget/deviceRTLs/nvptx/src/debug.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@
163163

164164
#define PRINT0(_flag, _str) \
165165
{ \
166-
if (DON(_flag)) { \
166+
if (omptarget_device_environment.debug_level && DON(_flag)) { \
167167
printf("<b %2d, t %4d, w %2d, l %2d>: " _str, blockIdx.x, threadIdx.x, \
168168
threadIdx.x / WARPSIZE, threadIdx.x & 0x1F); \
169169
} \
170170
}
171171

172172
#define PRINT(_flag, _str, _args...) \
173173
{ \
174-
if (DON(_flag)) { \
174+
if (omptarget_device_environment.debug_level && DON(_flag)) { \
175175
printf("<b %2d, t %4d, w %2d, l %2d>: " _str, blockIdx.x, threadIdx.x, \
176176
threadIdx.x / WARPSIZE, threadIdx.x & 0x1F, _args); \
177177
} \

‎openmp/libomptarget/deviceRTLs/nvptx/src/omp_data.cu

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
#include "omptarget-nvptx.h"
1515

16+
////////////////////////////////////////////////////////////////////////////////
17+
// global device envrionment
18+
////////////////////////////////////////////////////////////////////////////////
19+
20+
__device__ omptarget_device_environmentTy omptarget_device_environment;
21+
1622
////////////////////////////////////////////////////////////////////////////////
1723
// global data holding OpenMP state information
1824
////////////////////////////////////////////////////////////////////////////////

‎openmp/libomptarget/deviceRTLs/nvptx/src/omptarget-nvptx.h

+13
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,19 @@ class omptarget_nvptx_ThreadPrivateContext {
379379
uint64_t SourceQueue;
380380
};
381381

382+
/// Device envrionment data
383+
struct omptarget_device_environmentTy {
384+
int32_t debug_level;
385+
};
386+
387+
////////////////////////////////////////////////////////////////////////////////
388+
// global device envrionment
389+
////////////////////////////////////////////////////////////////////////////////
390+
391+
extern __device__ omptarget_device_environmentTy omptarget_device_environment;
392+
393+
////////////////////////////////////////////////////////////////////////////////
394+
382395
////////////////////////////////////////////////////////////////////////////////
383396
// global data tables
384397
////////////////////////////////////////////////////////////////////////////////

‎openmp/libomptarget/plugins/cuda/src/rtl.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ struct KernelTy {
8080
: Func(_Func), ExecutionMode(_ExecutionMode) {}
8181
};
8282

83+
/// Device envrionment data
84+
/// Manually sync with the deviceRTL side for now, move to a dedicated header file later.
85+
struct omptarget_device_environmentTy {
86+
int32_t debug_level;
87+
};
88+
8389
/// List that contains all the kernels.
8490
/// FIXME: we may need this to be per device and per library.
8591
std::list<KernelTy> KernelsList;
@@ -486,6 +492,48 @@ __tgt_target_table *__tgt_rtl_load_binary(int32_t device_id,
486492
DeviceInfo.addOffloadEntry(device_id, entry);
487493
}
488494

495+
// send device environment data to the device
496+
{
497+
omptarget_device_environmentTy device_env;
498+
499+
device_env.debug_level = 0;
500+
501+
#ifdef OMPTARGET_DEBUG
502+
if (char *envStr = getenv("LIBOMPTARGET_DEVICE_RTL_DEBUG")) {
503+
device_env.debug_level = std::stoi(envStr);
504+
}
505+
#endif
506+
507+
const char * device_env_Name="omptarget_device_environment";
508+
CUdeviceptr device_env_Ptr;
509+
size_t cusize;
510+
511+
err = cuModuleGetGlobal(&device_env_Ptr, &cusize, cumod, device_env_Name);
512+
513+
if (err == CUDA_SUCCESS) {
514+
if ((size_t)cusize != sizeof(device_env)) {
515+
DP("Global device_environment '%s' - size mismatch (%zu != %zu)\n",
516+
device_env_Name, cusize, sizeof(int32_t));
517+
CUDA_ERR_STRING(err);
518+
return NULL;
519+
}
520+
521+
err = cuMemcpyHtoD(device_env_Ptr, &device_env, cusize);
522+
if (err != CUDA_SUCCESS) {
523+
DP("Error when copying data from host to device. Pointers: "
524+
"host = " DPxMOD ", device = " DPxMOD ", size = %zu\n",
525+
DPxPTR(&device_env), DPxPTR(device_env_Ptr), cusize);
526+
CUDA_ERR_STRING(err);
527+
return NULL;
528+
}
529+
530+
DP("Sending global device environment data %zu bytes\n", (size_t)cusize);
531+
} else {
532+
DP("Finding global device environment '%s' - symbol missing.\n", device_env_Name);
533+
DP("Continue, considering this is a device RTL which does not accept envrionment setting.\n");
534+
}
535+
}
536+
489537
return DeviceInfo.getOffloadEntriesTable(device_id);
490538
}
491539

0 commit comments

Comments
 (0)
Please sign in to comment.