Skip to content

Commit 987072b

Browse files
abhinavgabaaokblast
authored andcommitted
[NFC][OpenMP] Add small class-member use_device_ptr/addr unit tests. (llvm#164039)
Two of the tests are currently asserting, and two are emitting unexpected results. The asserting tests will be fixed using the ATTACH-style codegen from llvm#153683. The other two involve `use_device_addr` on byrefs, and need more follow-up codegen changes, that have been noted in a FIXME comment.
1 parent 1952c85 commit 987072b

8 files changed

+300
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
#include <omp.h>
4+
#include <stdio.h>
5+
6+
int x = 0;
7+
int *y = &x;
8+
int z = 0;
9+
10+
struct ST {
11+
int n = 111;
12+
int *a = &x;
13+
int *&b = y;
14+
int c = 0;
15+
int &d = z;
16+
int m = 0;
17+
18+
void f7() {
19+
#pragma omp target data map(to : c)
20+
{
21+
void *mapped_ptr = omp_get_mapped_ptr(&c, omp_get_default_device());
22+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
23+
#pragma omp target data use_device_addr(c)
24+
{
25+
printf("%d\n", &c == mapped_ptr); // CHECK: 1
26+
}
27+
}
28+
}
29+
};
30+
31+
int main() {
32+
ST s;
33+
s.f7();
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
#include <omp.h>
4+
#include <stdio.h>
5+
6+
int x = 0;
7+
int *y = &x;
8+
int z = 0;
9+
10+
struct ST {
11+
int n = 111;
12+
int *a = &x;
13+
int *&b = y;
14+
int c = 0;
15+
int &d = z;
16+
int m = 0;
17+
18+
void f8() {
19+
#pragma omp target enter data map(to : d)
20+
{
21+
void *mapped_ptr = omp_get_mapped_ptr(&d, omp_get_default_device());
22+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
23+
#pragma omp target data use_device_addr(d)
24+
{
25+
printf("%d\n", &d == mapped_ptr); // CHECK: 1
26+
}
27+
}
28+
}
29+
};
30+
31+
int main() {
32+
ST s;
33+
s.f8();
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
#include <omp.h>
4+
#include <stdio.h>
5+
6+
int x = 0;
7+
int *y = &x;
8+
int z = 0;
9+
10+
struct ST {
11+
int n = 111;
12+
int *a = &x;
13+
int *&b = y;
14+
int c = 0;
15+
int &d = z;
16+
int m = 0;
17+
18+
void f6() {
19+
uintptr_t offset = (uintptr_t)&d - n;
20+
#pragma omp target data map(to : m, d)
21+
{
22+
void *mapped_ptr = omp_get_mapped_ptr(&d, omp_get_default_device());
23+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
24+
#pragma omp target data map(m, d) use_device_addr(d)
25+
{
26+
// FIXME: Clang is mapping class member references using:
27+
// &this[0], &ref_ptee(this[0].d), 4, PTR_AND_OBJ
28+
// but a load from `this[0]` cannot be used to compute the offset
29+
// in the runtime, because for example in this case, it would mean
30+
// that the base address of the pointee is a load from `n`, i.e. 111.
31+
// clang should be emitting the following instead:
32+
// &ref_ptr(this[0].d), &ref_ptee(this[0].d), 4, PTR_AND_OBJ
33+
// And eventually, the following that's compatible with the
34+
// ref/attach modifiers:
35+
// &ref_ptee(this[0].[d])), &ref_ptee(this[0].d), TO | FROM
36+
// &ref_ptr(this[0].d), &ref_ptee(this[0].d), 4, ATTACH
37+
// EXPECTED: 1 0
38+
// CHECK: 0 1
39+
printf("%d %d\n", &d == mapped_ptr,
40+
(uintptr_t)&d == (uintptr_t)mapped_ptr - offset);
41+
}
42+
}
43+
}
44+
};
45+
46+
int main() {
47+
ST s;
48+
s.f6();
49+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
#include <omp.h>
4+
#include <stdio.h>
5+
6+
int x = 0;
7+
int *y = &x;
8+
int z = 0;
9+
10+
struct ST {
11+
int n = 111;
12+
int *a = &x;
13+
int *&b = y;
14+
int c = 0;
15+
int &d = z;
16+
int m = 0;
17+
18+
void f5() {
19+
uintptr_t offset = (uintptr_t)&c - (uintptr_t)this;
20+
#pragma omp target data map(to : m, c)
21+
{
22+
void *mapped_ptr = omp_get_mapped_ptr(&c, omp_get_default_device());
23+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
24+
#pragma omp target data map(m, c) use_device_addr(c)
25+
{
26+
// FIXME: RT is currently doing the translation for "&this[0]" instead
27+
// of &this->c, for a map like:
28+
// this, &this->c, ..., RETURN_PARAM
29+
// We either need to fix RT, or emit a separate entry for such
30+
// use_device_addr, even if there is a matching map entry already.
31+
// EXPECTED: 1 0
32+
// CHECK: 0 1
33+
printf("%d %d\n", &c == mapped_ptr,
34+
(uintptr_t)&c == (uintptr_t)mapped_ptr - offset);
35+
}
36+
}
37+
}
38+
};
39+
40+
int main() {
41+
ST s;
42+
s.f5();
43+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
#include <omp.h>
4+
#include <stdio.h>
5+
6+
int x = 0;
7+
int *y = &x;
8+
int z = 0;
9+
10+
struct ST {
11+
int n = 111;
12+
int *a = &x;
13+
int *&b = y;
14+
int c = 0;
15+
int &d = z;
16+
int m = 0;
17+
18+
void f3() {
19+
#pragma omp target data map(to : a[0])
20+
{
21+
void *mapped_ptr = omp_get_mapped_ptr(a, omp_get_default_device());
22+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
23+
#pragma omp target data use_device_ptr(a)
24+
{
25+
printf("%d\n", a == mapped_ptr); // CHECK: 1
26+
}
27+
}
28+
}
29+
};
30+
31+
int main() {
32+
ST s;
33+
s.f3();
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
#include <omp.h>
4+
#include <stdio.h>
5+
6+
int x = 0;
7+
int *y = &x;
8+
int z = 0;
9+
10+
struct ST {
11+
int n = 111;
12+
int *a = &x;
13+
int *&b = y;
14+
int c = 0;
15+
int &d = z;
16+
int m = 0;
17+
18+
void f4() {
19+
#pragma omp target data map(to : b[0])
20+
{
21+
void *mapped_ptr = omp_get_mapped_ptr(b, omp_get_default_device());
22+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
23+
#pragma omp target data use_device_ptr(b)
24+
{
25+
printf("%d\n", b == mapped_ptr); // CHECK: 1
26+
}
27+
}
28+
}
29+
};
30+
31+
int main() {
32+
ST s;
33+
s.f4();
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
// XFAIL: *
4+
5+
#include <omp.h>
6+
#include <stdio.h>
7+
8+
int x = 0;
9+
int *y = &x;
10+
int z = 0;
11+
12+
struct ST {
13+
int n = 111;
14+
int *a = &x;
15+
int *&b = y;
16+
int c = 0;
17+
int &d = z;
18+
int m = 0;
19+
20+
void f2() {
21+
#pragma omp target data map(to : b[0])
22+
{
23+
void *mapped_ptr = omp_get_mapped_ptr(b, omp_get_default_device());
24+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
25+
#pragma omp target data map(b[0], m) use_device_ptr(b)
26+
{
27+
printf("%d\n", b == mapped_ptr); // CHECK: 1
28+
}
29+
}
30+
}
31+
};
32+
33+
int main() {
34+
ST s;
35+
s.f2();
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
// XFAIL: *
4+
5+
#include <omp.h>
6+
#include <stdio.h>
7+
8+
int x = 0;
9+
int *y = &x;
10+
int z = 0;
11+
12+
struct ST {
13+
int n = 111;
14+
int *a = &x;
15+
int *&b = y;
16+
int c = 0;
17+
int &d = z;
18+
int m = 0;
19+
20+
void f1() {
21+
#pragma omp target data map(to : a[0])
22+
{
23+
void *mapped_ptr = omp_get_mapped_ptr(a, omp_get_default_device());
24+
printf("%d\n", mapped_ptr != NULL); // CHECK: 1
25+
#pragma omp target data map(a[0], m) use_device_ptr(a)
26+
{
27+
printf("%d\n", a == mapped_ptr); // CHECK: 1
28+
}
29+
}
30+
}
31+
};
32+
33+
int main() {
34+
ST s;
35+
s.f1();
36+
}

0 commit comments

Comments
 (0)