Skip to content

Commit de9edf4

Browse files
committed
[OpenMP] Avoid zero size copies to the device
This unblocks one of the XFAIL tests for AMD, though we need to work around the missing printf still. Differential Revision: https://reviews.llvm.org/D146592
1 parent ebcc6db commit de9edf4

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

openmp/libomptarget/src/device.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ TargetPointerResultTy DeviceTy::getTargetPointer(
321321

322322
// If the target pointer is valid, and we need to transfer data, issue the
323323
// data transfer.
324-
if (TargetPointer && !IsHostPtr && HasFlagTo && (IsNew || HasFlagAlways)) {
324+
if (TargetPointer && !IsHostPtr && HasFlagTo && (IsNew || HasFlagAlways) &&
325+
Size != 0) {
325326
// Lock the entry before releasing the mapping table lock such that another
326327
// thread that could issue data movement will get the right result.
327328
std::lock_guard<decltype(*Entry)> LG(*Entry);

openmp/libomptarget/src/omptarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ int targetDataEnd(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
10281028
// Move data back to the host
10291029
const bool HasAlways = ArgTypes[I] & OMP_TGT_MAPTYPE_ALWAYS;
10301030
const bool HasFrom = ArgTypes[I] & OMP_TGT_MAPTYPE_FROM;
1031-
if (HasFrom && (HasAlways || IsLast) && !IsHostPtr) {
1031+
if (HasFrom && (HasAlways || IsLast) && !IsHostPtr && DataSize != 0) {
10321032
DP("Moving %" PRId64 " bytes (tgt:" DPxMOD ") -> (hst:" DPxMOD ")\n",
10331033
DataSize, DPxPTR(TgtPtrBegin), DPxPTR(HstPtrBegin));
10341034

openmp/libomptarget/test/mapping/data_member_ref.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// RUN: %libomptarget-compilexx-run-and-check-generic
22

3-
// Wrong results on amdgpu
4-
// XFAIL: amdgcn-amd-amdhsa
5-
63
#include <stdio.h>
74

85
struct View {
@@ -26,42 +23,55 @@ int main() {
2623
int Data = 123456;
2724
V1.Data = &Data;
2825
Foo<ViewPtr> Baz(V1);
26+
int D1, D2;
2927

3028
// CHECK: Host 123456.
3129
printf("Host %d.\n", Bar.VRef.Data);
32-
#pragma omp target map(Bar.VRef)
30+
#pragma omp target map(Bar.VRef) map(from : D1, D2)
3331
{
3432
// CHECK: Device 123456.
35-
printf("Device %d.\n", Bar.VRef.Data);
33+
D1 = Bar.VRef.Data;
34+
printf("Device %d.\n", D1);
3635
V.Data = 654321;
3736
// CHECK: Device 654321.
38-
printf("Device %d.\n", Bar.VRef.Data);
37+
D2 = Bar.VRef.Data;
38+
printf("Device %d.\n", D2);
3939
}
40+
printf("Device %d.\n", D1);
41+
printf("Device %d.\n", D2);
4042
// CHECK: Host 654321 654321.
4143
printf("Host %d %d.\n", Bar.VRef.Data, V.Data);
4244
V.Data = 123456;
4345
// CHECK: Host 123456.
4446
printf("Host %d.\n", Bar.VRef.Data);
45-
#pragma omp target map(Bar) map(Bar.VRef)
47+
#pragma omp target map(Bar) map(Bar.VRef) map(from : D1, D2)
4648
{
4749
// CHECK: Device 123456.
48-
printf("Device %d.\n", Bar.VRef.Data);
50+
D1 = Bar.VRef.Data;
51+
printf("Device %d.\n", D1);
4952
V.Data = 654321;
5053
// CHECK: Device 654321.
51-
printf("Device %d.\n", Bar.VRef.Data);
54+
D2 = Bar.VRef.Data;
55+
printf("Device %d.\n", D2);
5256
}
57+
printf("Device %d.\n", D1);
58+
printf("Device %d.\n", D2);
5359
// CHECK: Host 654321 654321.
5460
printf("Host %d %d.\n", Bar.VRef.Data, V.Data);
5561
// CHECK: Host 123456.
5662
printf("Host %d.\n", *Baz.VRef.Data);
57-
#pragma omp target map(*Baz.VRef.Data)
63+
#pragma omp target map(*Baz.VRef.Data) map(from : D1, D2)
5864
{
5965
// CHECK: Device 123456.
60-
printf("Device %d.\n", *Baz.VRef.Data);
66+
D1 = *Baz.VRef.Data;
67+
printf("Device %d.\n", D1);
6168
*V1.Data = 654321;
6269
// CHECK: Device 654321.
63-
printf("Device %d.\n", *Baz.VRef.Data);
70+
D2 = *Baz.VRef.Data;
71+
printf("Device %d.\n", D2);
6472
}
73+
printf("Device %d.\n", D1);
74+
printf("Device %d.\n", D2);
6575
// CHECK: Host 654321 654321 654321.
6676
printf("Host %d %d %d.\n", *Baz.VRef.Data, *V1.Data, Data);
6777
return 0;

0 commit comments

Comments
 (0)