Skip to content

Commit d2147b1

Browse files
committed
[OpenMP] Fix always,from and delete for data absent at exit
Without this patch, there's a runtime error for those map types at exit from an "omp target data" or at "omp target exit data", but the spec says the list item should be ignored. This patch tests that fix in data_absent_at_exit.c, and it also improves other testing for data that is not fully present at exit. Reviewed By: grokos, RaviNarayanaswamy Differential Revision: https://reviews.llvm.org/D96999
1 parent 82492f2 commit d2147b1

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
lines changed

openmp/libomptarget/src/omptarget.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,13 @@ int targetDataEnd(ident_t *loc, DeviceTy &Device, int32_t ArgNum,
545545
DP("Mapping does not exist (%s)\n",
546546
(HasPresentModifier ? "'present' map type modifier" : "ignored"));
547547
if (HasPresentModifier) {
548+
// OpenMP 5.1, sec. 2.21.7.1 "map Clause", p. 350 L10-13:
549+
// "If a map clause appears on a target, target data, target enter data
550+
// or target exit data construct with a present map-type-modifier then
551+
// on entry to the region if the corresponding list item does not appear
552+
// in the device data environment then an error occurs and the program
553+
// terminates."
554+
//
548555
// This should be an error upon entering an "omp target exit data". It
549556
// should not be an error upon exiting an "omp target data" or "omp
550557
// target". For "omp target data", Clang thus doesn't include present
@@ -564,6 +571,14 @@ int targetDataEnd(ident_t *loc, DeviceTy &Device, int32_t ArgNum,
564571
DataSize, DPxPTR(TgtPtrBegin), (IsLast ? "" : " not"));
565572
}
566573

574+
// OpenMP 5.1, sec. 2.21.7.1 "map Clause", p. 351 L14-16:
575+
// "If the map clause appears on a target, target data, or target exit data
576+
// construct and a corresponding list item of the original list item is not
577+
// present in the device data environment on exit from the region then the
578+
// list item is ignored."
579+
if (!TgtPtrBegin)
580+
continue;
581+
567582
bool DelEntry = IsLast || ForceDelete;
568583

569584
if ((ArgTypes[I] & OMP_TGT_MAPTYPE_MEMBER_OF) &&
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu
2+
// RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu
3+
// RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu
4+
// RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
5+
// RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda
6+
7+
#include <stdio.h>
8+
9+
// OpenMP 5.1, sec. 2.21.7.1 "map Clause", p. 351 L14-16:
10+
// "If the map clause appears on a target, target data, or target exit data
11+
// construct and a corresponding list item of the original list item is not
12+
// present in the device data environment on exit from the region then the
13+
// list item is ignored."
14+
15+
int main(void) {
16+
int f = 5, r = 6, d = 7, af = 8;
17+
18+
// Check exit from omp target data.
19+
// CHECK: f = 5, af = 8
20+
#pragma omp target data map(from: f) map(always, from: af)
21+
{
22+
#pragma omp target exit data map(delete: f, af)
23+
}
24+
printf("f = %d, af = %d\n", f, af);
25+
26+
// Check omp target exit data.
27+
// CHECK: f = 5, r = 6, d = 7, af = 8
28+
#pragma omp target exit data map(from: f) map(release: r) map(delete: d) \
29+
map(always, from: af)
30+
printf("f = %d, r = %d, d = %d, af = %d\n", f, r, d, af);
31+
32+
return 0;
33+
}

openmp/libomptarget/test/mapping/present/target_exit_data.c renamed to openmp/libomptarget/test/mapping/present/target_exit_data_delete.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ int main() {
2323
fprintf(stderr, "addr=%p, size=%ld\n", &i, sizeof i);
2424

2525
// CHECK-NOT: Libomptarget
26-
#pragma omp target enter data map(alloc: i)
27-
#pragma omp target exit data map(present, release: i)
26+
#pragma omp target enter data map(alloc: i)
27+
#pragma omp target exit data map(present, delete: i)
2828

29-
// CHECK: i is present
30-
fprintf(stderr, "i is present\n");
29+
// CHECK: i was present
30+
fprintf(stderr, "i was present\n");
3131

3232
// CHECK: Libomptarget message: device mapping required by 'present' map type modifier does not exist for host address 0x{{0*}}[[#HOST_ADDR]] ([[#SIZE]] bytes)
3333
// CHECK: Libomptarget fatal error 1: failure of target construct while offloading is mandatory
34-
#pragma omp target exit data map(present, release: i)
34+
#pragma omp target exit data map(present, delete: i)
3535

36-
// CHECK-NOT: i is present
37-
fprintf(stderr, "i is present\n");
36+
// CHECK-NOT: i was present
37+
fprintf(stderr, "i was present\n");
3838

3939
return 0;
4040
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %libomptarget-compile-aarch64-unknown-linux-gnu -fopenmp-version=51
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 -fopenmp-version=51
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 -fopenmp-version=51
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 -fopenmp-version=51
14+
// RUN: %libomptarget-run-fail-x86_64-pc-linux-gnu 2>&1 \
15+
// RUN: | %fcheck-x86_64-pc-linux-gnu
16+
17+
#include <stdio.h>
18+
19+
int main() {
20+
int i;
21+
22+
// CHECK: addr=0x[[#%x,HOST_ADDR:]], size=[[#%u,SIZE:]]
23+
fprintf(stderr, "addr=%p, size=%ld\n", &i, sizeof i);
24+
25+
// CHECK-NOT: Libomptarget
26+
#pragma omp target enter data map(alloc: i)
27+
#pragma omp target exit data map(present, release: i)
28+
29+
// CHECK: i was present
30+
fprintf(stderr, "i was present\n");
31+
32+
// CHECK: Libomptarget message: device mapping required by 'present' map type modifier does not exist for host address 0x{{0*}}[[#HOST_ADDR]] ([[#SIZE]] bytes)
33+
// CHECK: Libomptarget fatal error 1: failure of target construct while offloading is mandatory
34+
#pragma omp target exit data map(present, release: i)
35+
36+
// CHECK-NOT: i was present
37+
fprintf(stderr, "i was present\n");
38+
39+
return 0;
40+
}

openmp/libomptarget/test/mapping/target_data_array_extension_at_exit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
// RUN: %libomptarget-compile-x86_64-pc-linux-gnu \
2121
// RUN: -fopenmp-version=51 -DEXTENDS=BEFORE
22-
// XUN: %libomptarget-run-x86_64-pc-linux-gnu 2>&1 \
23-
// XUN: | %fcheck-x86_64-pc-linux-gnu
22+
// RUN: %libomptarget-run-x86_64-pc-linux-gnu 2>&1 \
23+
// RUN: | %fcheck-x86_64-pc-linux-gnu
2424

2525
// --------------------------------------------------
2626
// Check extends after

0 commit comments

Comments
 (0)