Skip to content

Commit 747af24

Browse files
committed
[OpenMP] Allow more tests to run on AMDGPU
This basically works around the printf issue to increase test coverage. Differential Revision: https://reviews.llvm.org/D146838
1 parent 151b58d commit 747af24

File tree

5 files changed

+65
-30
lines changed

5 files changed

+65
-30
lines changed

openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp

Lines changed: 10 additions & 7 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 <cstdio>
74
#include <cstdlib>
85

@@ -45,17 +42,23 @@ int main() {
4542
spp[0][0].f.b[1], spp[0][0].f.b == &x[0] ? 1 : 0);
4643
// CHECK: 111 222 777 20.00000 1
4744

45+
int spp00fa = -1, spp00fca = -1, spp00fb_r = -1;
4846
__intptr_t p = reinterpret_cast<__intptr_t>(&x[0]);
49-
#pragma omp target map(tofrom : spp[0][0]) firstprivate(p)
47+
#pragma omp target map(tofrom: spp[0][0]) firstprivate(p) \
48+
map(from: spp00fa, spp00fca, spp00fb_r)
5049
{
51-
printf("%d %d %d\n", spp[0][0].f.a, spp[0][0].f.c.a,
52-
spp[0][0].f.b == reinterpret_cast<void *>(p) ? 1 : 0);
53-
// CHECK: 222 777 0
50+
spp00fa = spp[0][0].f.a;
51+
spp00fca = spp[0][0].f.c.a;
52+
spp00fb_r = spp[0][0].f.b == reinterpret_cast<void *>(p) ? 1 : 0;
53+
printf("%d %d %d\n", spp00fa, spp00fca, spp00fb_r);
54+
// XCHECK: 222 777 0
5455
spp[0][0].e = 333;
5556
spp[0][0].f.a = 444;
5657
spp[0][0].f.c.a = 555;
5758
spp[0][0].f.b[1] = 40;
5859
}
60+
printf("%d %d %d\n", spp00fa, spp00fca, spp00fb_r);
61+
// CHECK: 222 777 0
5962
printf("%d %d %d %4.5f %d\n", spp[0][0].e, spp[0][0].f.a, spp[0][0].f.c.a,
6063
spp[0][0].f.b[1], spp[0][0].f.b == &x[0] ? 1 : 0);
6164
// CHECK: 333 222 777 40.00000 1

openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp

Lines changed: 11 additions & 8 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 <cstdio>
74
#include <cstdlib>
85

@@ -42,19 +39,25 @@ int main() {
4239
spp[0][0].g == &y[0] ? 1 : 0);
4340
// CHECK: 111 222 20.00000 1 30 1
4441

42+
int spp00fa = -1, spp00fb_r = -1, spp00fg1 = -1, spp00fg_r = -1;
4543
__intptr_t p = reinterpret_cast<__intptr_t>(&x[0]),
4644
p1 = reinterpret_cast<__intptr_t>(&y[0]);
47-
#pragma omp target map(tofrom : spp[0][0]) firstprivate(p, p1)
45+
#pragma omp target map(tofrom : spp[0][0]) firstprivate(p, p1) \
46+
map(from: spp00fa, spp00fb_r, spp00fg1, spp00fg_r)
4847
{
49-
printf("%d %d %d %d\n", spp[0][0].f.a,
50-
spp[0][0].f.b == reinterpret_cast<void *>(p) ? 1 : 0, spp[0][0].g[1],
51-
spp[0][0].g == reinterpret_cast<void *>(p1) ? 1 : 0);
52-
// CHECK: 222 0 30 0
48+
spp00fa = spp[0][0].f.a;
49+
spp00fb_r = spp[0][0].f.b == reinterpret_cast<void *>(p) ? 1 : 0;
50+
spp00fg1 = spp[0][0].g[1];
51+
spp00fg_r = spp[0][0].g == reinterpret_cast<void *>(p1) ? 1 : 0;
52+
printf("%d %d %d %d\n", spp00fa, spp00fb_r, spp00fg1, spp00fg_r);
53+
// XCHECK: 222 0 30 0
5354
spp[0][0].e = 333;
5455
spp[0][0].f.a = 444;
5556
spp[0][0].f.b[1] = 40;
5657
spp[0][0].g[1] = 50;
5758
}
59+
printf("%d %d %d %d\n", spp00fa, spp00fb_r, spp00fg1, spp00fg_r);
60+
// CHECK: 222 0 30 0
5861
printf("%d %d %4.5f %d %d %d\n", spp[0][0].e, spp[0][0].f.a, spp[0][0].f.b[1],
5962
spp[0][0].f.b == &x[0] ? 1 : 0, spp[0][0].g[1],
6063
spp[0][0].g == &y[0] ? 1 : 0);

openmp/libomptarget/test/mapping/lambda_by_value.cpp

Lines changed: 17 additions & 4 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 <stdint.h>
74
#include <stdio.h>
85

@@ -11,25 +8,41 @@
118
// CHECK: tgt : [[V2]] [[PX_TGT]] 1
129
// CHECK: out : [[V2]] [[V2]] [[PX]] [[PY]]
1310

11+
#pragma omp begin declare target
12+
int a = -1, *c;
13+
long b = -1;
14+
const long *d;
15+
int e = -1, *f, g = -1;
16+
#pragma omp end declare target
17+
1418
int main() {
1519
int x[10];
1620
long y[8];
1721
x[1] = 111;
1822
y[1] = 222;
1923

2024
auto lambda = [&x, y]() {
25+
a = x[1];
26+
b = y[1];
27+
c = &x[0];
28+
d = &y[0];
2129
printf("lambda: %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
2230
x[1] = y[1];
2331
};
24-
2532
printf("before: %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
2633

2734
intptr_t xp = (intptr_t)&x[0];
2835
#pragma omp target firstprivate(xp)
2936
{
3037
lambda();
38+
e = x[1];
39+
f = &x[0];
40+
g = (&x[0] != (int *)xp);
3141
printf("tgt : %d %p %d\n", x[1], &x[0], (&x[0] != (int *)xp));
3242
}
43+
#pragma omp target update from(a, b, c, d, e, f, g)
44+
printf("lambda: %d %ld %p %p\n", a, b, c, d);
45+
printf("tgt : %d %p %d\n", e, f, g);
3346
printf("out : %d %ld %p %p\n", x[1], y[1], &x[0], &y[0]);
3447

3548
return 0;

openmp/libomptarget/test/mapping/ompx_hold/struct.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
// RUN: %libomptarget-compile-generic -fopenmp-extensions
22
// RUN: %libomptarget-run-generic | %fcheck-generic -strict-whitespace
33

4-
// Wrong results on amdgpu
5-
// XFAIL: amdgcn-amd-amdhsa
6-
74
#include <omp.h>
85
#include <stdio.h>
96

7+
#pragma omp begin declare target
8+
char *N1, *N2;
9+
int V1, V2;
10+
#pragma omp declare target
11+
1012
#define CHECK_PRESENCE(Var1, Var2, Var3) \
1113
printf(" presence of %s, %s, %s: %d, %d, %d\n", #Var1, #Var2, #Var3, \
1214
omp_target_is_present(&(Var1), omp_get_default_device()), \
1315
omp_target_is_present(&(Var2), omp_get_default_device()), \
1416
omp_target_is_present(&(Var3), omp_get_default_device()))
1517

18+
#define CHECK_VALUES_HELPER(N1, N2, Var1, Var2) \
19+
printf(" values of %s, %s: %d, %d\n", N1, N2, (Var1), (Var2))
20+
21+
#define CHECK_VALUES_DELAYED(Var1, Var2) \
22+
N1 = #Var1; \
23+
N2 = #Var2; \
24+
V1 = (Var1); \
25+
V2 = (Var2);
26+
27+
#define CHECK_DELAYED_VALUS() \
28+
_Pragma("omp target update from(N1, N2, V1, V2)") \
29+
CHECK_VALUES_HELPER(N1, N2, V1, V2)
30+
1631
#define CHECK_VALUES(Var1, Var2) \
17-
printf(" values of %s, %s: %d, %d\n", #Var1, #Var2, (Var1), (Var2))
32+
CHECK_VALUES_HELPER(#Var1, #Var2, (Var1), (Var2))
1833

1934
int main() {
2035
struct S {
@@ -132,8 +147,9 @@ int main() {
132147
#pragma omp target map(to : s.i, s.j)
133148
{ // No transfer here even though parent's DynRefCount=1.
134149
// CHECK-NEXT: values of s.i, s.j: 21, 31
135-
CHECK_VALUES(s.i, s.j);
150+
CHECK_VALUES_DELAYED(s.i, s.j);
136151
}
152+
CHECK_DELAYED_VALUS();
137153
}
138154
// CHECK-NEXT: presence of s, s.i, s.j: 0, 0, 0
139155
// CHECK-NEXT: values of s.i, s.j: 21, 31
@@ -162,8 +178,9 @@ int main() {
162178
#pragma omp target map(ompx_hold, to : s.i, s.j)
163179
{ // No transfer here even though parent's HoldRefCount=1.
164180
// CHECK-NEXT: values of s.i, s.j: 21, 31
165-
CHECK_VALUES(s.i, s.j);
181+
CHECK_VALUES_DELAYED(s.i, s.j);
166182
}
183+
CHECK_DELAYED_VALUS();
167184
}
168185
// CHECK-NEXT: presence of s, s.i, s.j: 0, 0, 0
169186
// CHECK-NEXT: values of s.i, s.j: 21, 31

openmp/libomptarget/test/offloading/host_as_target.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
// RUN: %libomptarget-compile-run-and-check-generic
99

10-
// amdgpu does not have a working printf definition
11-
// XFAIL: amdgcn-amd-amdhsa
12-
1310
#include <omp.h>
1411
#include <stdio.h>
1512

1613
static void check(char *X, int Dev) {
1714
printf(" host X = %c\n", *X);
18-
#pragma omp target device(Dev)
19-
printf("device X = %c\n", *X);
15+
char DV = -1;
16+
#pragma omp target device(Dev) map(from : DV)
17+
DV = *X;
18+
printf("device X = %c\n", DV);
2019
}
2120

2221
#define CHECK_DATA() check(&X, DevDefault)

0 commit comments

Comments
 (0)