Skip to content

Commit 5f6aa96

Browse files
committed
[OpenMP] target_data_begin: fail on device alloc fail
Without this patch, target_data_begin continues after an illegal mapping or an out-of-memory error on the device. With this patch, it terminates the runtime with an error instead. The new test exercises only illegal mappings. I didn't think of a good way to exercise out-of-memory errors from the test suite. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D78170
1 parent ba94261 commit 5f6aa96

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

openmp/libomptarget/src/omptarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ int target_data_begin(DeviceTy &Device, int32_t arg_num, void **args_base,
286286
// NULL, so getOrAlloc() returning NULL is not an error.
287287
DP("Call to getOrAllocTgtPtr returned null pointer (device failure or "
288288
"illegal mapping).\n");
289+
return OFFLOAD_FAIL;
289290
}
290291
DP("There are %" PRId64 " bytes allocated at target address " DPxMOD
291292
" - is%s new\n", data_size, DPxPTR(TgtPtrBegin),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %libomptarget-compile-aarch64-unknown-linux-gnu
2+
// RUN: %libomptarget-run-fail-aarch64-unknown-linux-gnu 2>&1 \
3+
// RUN: | %fcheck-aarch64-unknown-linux-gnu
4+
5+
// RUN: %libomptarget-compile-powerpc64-ibm-linux-gnu
6+
// RUN: %libomptarget-run-fail-powerpc64-ibm-linux-gnu 2>&1 \
7+
// RUN: | %fcheck-powerpc64-ibm-linux-gnu
8+
9+
// RUN: %libomptarget-compile-powerpc64le-ibm-linux-gnu
10+
// RUN: %libomptarget-run-fail-powerpc64le-ibm-linux-gnu 2>&1 \
11+
// RUN: | %fcheck-powerpc64le-ibm-linux-gnu
12+
13+
// RUN: %libomptarget-compile-x86_64-pc-linux-gnu
14+
// RUN: %libomptarget-run-fail-x86_64-pc-linux-gnu 2>&1 \
15+
// RUN: | %fcheck-x86_64-pc-linux-gnu
16+
17+
// CHECK: Libomptarget fatal error 1: failure of target construct while offloading is mandatory
18+
19+
int main() {
20+
int arr[4] = {0, 1, 2, 3};
21+
#pragma omp target data map(alloc: arr[0:2])
22+
#pragma omp target data map(alloc: arr[1:2])
23+
;
24+
return 0;
25+
}

0 commit comments

Comments
 (0)