Skip to content

Commit

Permalink
[OpenMP] Always emit debug messages that indicate offloading failure
Browse files Browse the repository at this point in the history
Summary:

This patch changes the libomptarget runtime to always emit debug messages that
occur before offloading failure. The goal is to provide users with information
about why their application failed in the target region rather than a single
failure message. This is only done in regions that precede offloading failure
so this should not impact runtime performance. if the debug environment
variable is set then the message is forwarded to the debug output as usual.

A new environment variable was added for future use but does nothing in this
current patch. LIBOMPTARGET_INFO will be used to report runtime information to
the user if requrested, such as grid size, SPMD usage, or data mapping. It will
take an integer indicating the level of information verbosity and a value of 0
will disable it.

Reviewers: jdoerfort

Subscribers: guansong sstefan1 yaxunl ye-luo

Tags: #OpenMP

Differential Revision: https://reviews.llvm.org/D86483
  • Loading branch information
jhuber6 committed Aug 26, 2020
1 parent 2d13693 commit 7a5a74e
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 61 deletions.
25 changes: 13 additions & 12 deletions openmp/libomptarget/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ EXTERN int omp_target_memcpy(void *dst, void *src, size_t length,
DPxPTR(src), dst_offset, src_offset, length);

if (!dst || !src || length <= 0) {
DP("Call to omp_target_memcpy with invalid arguments\n");
REPORT("Call to omp_target_memcpy with invalid arguments\n");
return OFFLOAD_FAIL;
}

if (src_device != omp_get_initial_device() && !device_is_ready(src_device)) {
DP("omp_target_memcpy returns OFFLOAD_FAIL\n");
return OFFLOAD_FAIL;
REPORT("omp_target_memcpy returns OFFLOAD_FAIL\n");
return OFFLOAD_FAIL;
}

if (dst_device != omp_get_initial_device() && !device_is_ready(dst_device)) {
DP("omp_target_memcpy returns OFFLOAD_FAIL\n");
return OFFLOAD_FAIL;
REPORT("omp_target_memcpy returns OFFLOAD_FAIL\n");
return OFFLOAD_FAIL;
}

int rc = OFFLOAD_SUCCESS;
Expand Down Expand Up @@ -207,7 +207,7 @@ EXTERN int omp_target_memcpy_rect(void *dst, void *src, size_t element_size,

if (!dst || !src || element_size < 1 || num_dims < 1 || !volume ||
!dst_offsets || !src_offsets || !dst_dimensions || !src_dimensions) {
DP("Call to omp_target_memcpy_rect with invalid arguments\n");
REPORT("Call to omp_target_memcpy_rect with invalid arguments\n");
return OFFLOAD_FAIL;
}

Expand Down Expand Up @@ -250,17 +250,17 @@ EXTERN int omp_target_associate_ptr(void *host_ptr, void *device_ptr,
DPxPTR(host_ptr), DPxPTR(device_ptr), size, device_offset, device_num);

if (!host_ptr || !device_ptr || size <= 0) {
DP("Call to omp_target_associate_ptr with invalid arguments\n");
REPORT("Call to omp_target_associate_ptr with invalid arguments\n");
return OFFLOAD_FAIL;
}

if (device_num == omp_get_initial_device()) {
DP("omp_target_associate_ptr: no association possible on the host\n");
REPORT("omp_target_associate_ptr: no association possible on the host\n");
return OFFLOAD_FAIL;
}

if (!device_is_ready(device_num)) {
DP("omp_target_associate_ptr returns OFFLOAD_FAIL\n");
REPORT("omp_target_associate_ptr returns OFFLOAD_FAIL\n");
return OFFLOAD_FAIL;
}

Expand All @@ -276,17 +276,18 @@ EXTERN int omp_target_disassociate_ptr(void *host_ptr, int device_num) {
"device_num %d\n", DPxPTR(host_ptr), device_num);

if (!host_ptr) {
DP("Call to omp_target_associate_ptr with invalid host_ptr\n");
REPORT("Call to omp_target_associate_ptr with invalid host_ptr\n");
return OFFLOAD_FAIL;
}

if (device_num == omp_get_initial_device()) {
DP("omp_target_disassociate_ptr: no association possible on the host\n");
REPORT(
"omp_target_disassociate_ptr: no association possible on the host\n");
return OFFLOAD_FAIL;
}

if (!device_is_ready(device_num)) {
DP("omp_target_disassociate_ptr returns OFFLOAD_FAIL\n");
REPORT("omp_target_disassociate_ptr returns OFFLOAD_FAIL\n");
return OFFLOAD_FAIL;
}

Expand Down
15 changes: 8 additions & 7 deletions openmp/libomptarget/src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ int DeviceTy::associatePtr(void *HstPtrBegin, void *TgtPtrBegin, int64_t Size) {
"host ptr, nothing to do\n");
return OFFLOAD_SUCCESS;
} else {
DP("Not allowed to re-associate a different device ptr+offset with the "
"same host ptr\n");
REPORT("Not allowed to re-associate a different device ptr+offset with "
"the same host ptr\n");
return OFFLOAD_FAIL;
}
}
Expand Down Expand Up @@ -103,14 +103,14 @@ int DeviceTy::disassociatePtr(void *HstPtrBegin) {
DataMapMtx.unlock();
return OFFLOAD_SUCCESS;
} else {
DP("Trying to disassociate a pointer which was not mapped via "
"omp_target_associate_ptr\n");
REPORT("Trying to disassociate a pointer which was not mapped via "
"omp_target_associate_ptr\n");
}
}

// Mapping not found
DataMapMtx.unlock();
DP("Association not found\n");
REPORT("Association not found\n");
return OFFLOAD_FAIL;
}

Expand Down Expand Up @@ -348,8 +348,9 @@ int DeviceTy::deallocTgtPtr(void *HstPtrBegin, int64_t Size, bool ForceDelete,
}
rc = OFFLOAD_SUCCESS;
} else {
DP("Section to delete (hst addr " DPxMOD ") does not exist in the allocated"
" memory\n", DPxPTR(HstPtrBegin));
REPORT("Section to delete (hst addr " DPxMOD ") does not exist in the"
" allocated memory\n",
DPxPTR(HstPtrBegin));
rc = OFFLOAD_FAIL;
}

Expand Down
6 changes: 4 additions & 2 deletions openmp/libomptarget/src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static void HandleTargetOutcome(bool success) {
break;
case tgt_mandatory:
if (!success) {
if (InfoLevel > 0)
MESSAGE0("LIBOMPTARGET_INFO is not supported yet");
FATAL_MESSAGE0(1, "failure of target construct while offloading is mandatory");
}
break;
Expand Down Expand Up @@ -303,7 +305,7 @@ EXTERN int __tgt_target_mapper(int64_t device_id, void *host_ptr,
}

if (CheckDeviceAndCtors(device_id) != OFFLOAD_SUCCESS) {
DP("Failed to get device %" PRId64 " ready\n", device_id);
REPORT("Failed to get device %" PRId64 " ready\n", device_id);
HandleTargetOutcome(false);
return OFFLOAD_FAIL;
}
Expand Down Expand Up @@ -363,7 +365,7 @@ EXTERN int __tgt_target_teams_mapper(int64_t device_id, void *host_ptr,
}

if (CheckDeviceAndCtors(device_id) != OFFLOAD_SUCCESS) {
DP("Failed to get device %" PRId64 " ready\n", device_id);
REPORT("Failed to get device %" PRId64 " ready\n", device_id);
HandleTargetOutcome(false);
return OFFLOAD_FAIL;
}
Expand Down
Loading

0 comments on commit 7a5a74e

Please sign in to comment.