Skip to content

Commit 7a5a74e

Browse files
committed
[OpenMP] Always emit debug messages that indicate offloading failure
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
1 parent 2d13693 commit 7a5a74e

12 files changed

+103
-61
lines changed

openmp/libomptarget/src/api.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ EXTERN int omp_target_memcpy(void *dst, void *src, size_t length,
132132
DPxPTR(src), dst_offset, src_offset, length);
133133

134134
if (!dst || !src || length <= 0) {
135-
DP("Call to omp_target_memcpy with invalid arguments\n");
135+
REPORT("Call to omp_target_memcpy with invalid arguments\n");
136136
return OFFLOAD_FAIL;
137137
}
138138

139139
if (src_device != omp_get_initial_device() && !device_is_ready(src_device)) {
140-
DP("omp_target_memcpy returns OFFLOAD_FAIL\n");
141-
return OFFLOAD_FAIL;
140+
REPORT("omp_target_memcpy returns OFFLOAD_FAIL\n");
141+
return OFFLOAD_FAIL;
142142
}
143143

144144
if (dst_device != omp_get_initial_device() && !device_is_ready(dst_device)) {
145-
DP("omp_target_memcpy returns OFFLOAD_FAIL\n");
146-
return OFFLOAD_FAIL;
145+
REPORT("omp_target_memcpy returns OFFLOAD_FAIL\n");
146+
return OFFLOAD_FAIL;
147147
}
148148

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

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

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

252252
if (!host_ptr || !device_ptr || size <= 0) {
253-
DP("Call to omp_target_associate_ptr with invalid arguments\n");
253+
REPORT("Call to omp_target_associate_ptr with invalid arguments\n");
254254
return OFFLOAD_FAIL;
255255
}
256256

257257
if (device_num == omp_get_initial_device()) {
258-
DP("omp_target_associate_ptr: no association possible on the host\n");
258+
REPORT("omp_target_associate_ptr: no association possible on the host\n");
259259
return OFFLOAD_FAIL;
260260
}
261261

262262
if (!device_is_ready(device_num)) {
263-
DP("omp_target_associate_ptr returns OFFLOAD_FAIL\n");
263+
REPORT("omp_target_associate_ptr returns OFFLOAD_FAIL\n");
264264
return OFFLOAD_FAIL;
265265
}
266266

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

278278
if (!host_ptr) {
279-
DP("Call to omp_target_associate_ptr with invalid host_ptr\n");
279+
REPORT("Call to omp_target_associate_ptr with invalid host_ptr\n");
280280
return OFFLOAD_FAIL;
281281
}
282282

283283
if (device_num == omp_get_initial_device()) {
284-
DP("omp_target_disassociate_ptr: no association possible on the host\n");
284+
REPORT(
285+
"omp_target_disassociate_ptr: no association possible on the host\n");
285286
return OFFLOAD_FAIL;
286287
}
287288

288289
if (!device_is_ready(device_num)) {
289-
DP("omp_target_disassociate_ptr returns OFFLOAD_FAIL\n");
290+
REPORT("omp_target_disassociate_ptr returns OFFLOAD_FAIL\n");
290291
return OFFLOAD_FAIL;
291292
}
292293

openmp/libomptarget/src/device.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ int DeviceTy::associatePtr(void *HstPtrBegin, void *TgtPtrBegin, int64_t Size) {
6767
"host ptr, nothing to do\n");
6868
return OFFLOAD_SUCCESS;
6969
} else {
70-
DP("Not allowed to re-associate a different device ptr+offset with the "
71-
"same host ptr\n");
70+
REPORT("Not allowed to re-associate a different device ptr+offset with "
71+
"the same host ptr\n");
7272
return OFFLOAD_FAIL;
7373
}
7474
}
@@ -103,14 +103,14 @@ int DeviceTy::disassociatePtr(void *HstPtrBegin) {
103103
DataMapMtx.unlock();
104104
return OFFLOAD_SUCCESS;
105105
} else {
106-
DP("Trying to disassociate a pointer which was not mapped via "
107-
"omp_target_associate_ptr\n");
106+
REPORT("Trying to disassociate a pointer which was not mapped via "
107+
"omp_target_associate_ptr\n");
108108
}
109109
}
110110

111111
// Mapping not found
112112
DataMapMtx.unlock();
113-
DP("Association not found\n");
113+
REPORT("Association not found\n");
114114
return OFFLOAD_FAIL;
115115
}
116116

@@ -348,8 +348,9 @@ int DeviceTy::deallocTgtPtr(void *HstPtrBegin, int64_t Size, bool ForceDelete,
348348
}
349349
rc = OFFLOAD_SUCCESS;
350350
} else {
351-
DP("Section to delete (hst addr " DPxMOD ") does not exist in the allocated"
352-
" memory\n", DPxPTR(HstPtrBegin));
351+
REPORT("Section to delete (hst addr " DPxMOD ") does not exist in the"
352+
" allocated memory\n",
353+
DPxPTR(HstPtrBegin));
353354
rc = OFFLOAD_FAIL;
354355
}
355356

openmp/libomptarget/src/interface.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static void HandleTargetOutcome(bool success) {
6262
break;
6363
case tgt_mandatory:
6464
if (!success) {
65+
if (InfoLevel > 0)
66+
MESSAGE0("LIBOMPTARGET_INFO is not supported yet");
6567
FATAL_MESSAGE0(1, "failure of target construct while offloading is mandatory");
6668
}
6769
break;
@@ -303,7 +305,7 @@ EXTERN int __tgt_target_mapper(int64_t device_id, void *host_ptr,
303305
}
304306

305307
if (CheckDeviceAndCtors(device_id) != OFFLOAD_SUCCESS) {
306-
DP("Failed to get device %" PRId64 " ready\n", device_id);
308+
REPORT("Failed to get device %" PRId64 " ready\n", device_id);
307309
HandleTargetOutcome(false);
308310
return OFFLOAD_FAIL;
309311
}
@@ -363,7 +365,7 @@ EXTERN int __tgt_target_teams_mapper(int64_t device_id, void *host_ptr,
363365
}
364366

365367
if (CheckDeviceAndCtors(device_id) != OFFLOAD_SUCCESS) {
366-
DP("Failed to get device %" PRId64 " ready\n", device_id);
368+
REPORT("Failed to get device %" PRId64 " ready\n", device_id);
367369
HandleTargetOutcome(false);
368370
return OFFLOAD_FAIL;
369371
}

0 commit comments

Comments
 (0)