Skip to content

Commit 2f8e712

Browse files
authored
[NFC][OpenMP] Add use_device_ptr/addr tests for when the lookup fails. (#169428)
As per OpenMP 5.1, the pointers are expected to retain their original values when a lookup fails and there is no device pointer to translate to.
1 parent 1b8626b commit 2f8e712

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
// Test that when a use_device_addr lookup fails, the
4+
// list-item retains its original address by default.
5+
//
6+
// This is necessary because we must assume that the
7+
// list-item is device-accessible, even if it was not
8+
// previously mapped.
9+
10+
// XFAIL: *
11+
12+
#include <stdio.h>
13+
int h[10];
14+
int *ph = &h[0];
15+
16+
void f1() {
17+
printf("%p\n", &h[2]); // CHECK: 0x[[#%x,ADDR:]]
18+
#pragma omp target data use_device_addr(h[2])
19+
printf("%p\n", &h[2]); // CHECK-NEXT: 0x{{0*}}[[#ADDR]]
20+
#pragma omp target data use_device_addr(ph[2])
21+
printf("%p\n", &ph[2]); // CHECK-NEXT: 0x{{0*}}[[#ADDR]]
22+
}
23+
24+
int main() { f1(); }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
// Test that when a use_device_addr lookup fails, the
4+
// list-item retains its original address by default.
5+
//
6+
// This is necessary because we must assume that the
7+
// list-item is device-accessible, even if it was not
8+
// previously mapped.
9+
10+
// XFAIL: *
11+
12+
#include <stdio.h>
13+
int x;
14+
15+
void f1() {
16+
printf("%p\n", &x); // CHECK: 0x[[#%x,ADDR:]]
17+
#pragma omp target data use_device_addr(x)
18+
printf("%p\n", &x); // CHECK-NEXT: 0x{{0*}}[[#ADDR]]
19+
}
20+
21+
int main() { f1(); }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %libomptarget-compilexx-run-and-check-generic
2+
3+
// Test that when a use_device_ptr lookup fails, the
4+
// privatized pointer retains its original value by
5+
// default.
6+
//
7+
// This is necessary because we must assume that the
8+
// pointee is device-accessible, even if it was not
9+
// previously mapped.
10+
//
11+
// OpenMP 5.1, sec 2.14.2, target data construct, p 188, l26-31:
12+
// If a list item that appears in a use_device_ptr clause ... does not point to
13+
// a mapped object, it must contain a valid device address for the target
14+
// device, and the list item references are instead converted to references to a
15+
// local device pointer that refers to this device address.
16+
//
17+
// Note: OpenMP 6.1 will have a way to change the
18+
// fallback behavior: preserve or nullify.
19+
20+
// XFAIL: *
21+
22+
#include <stdio.h>
23+
int x;
24+
int *xp = &x;
25+
26+
void f1() {
27+
printf("%p\n", xp); // CHECK: 0x[[#%x,ADDR:]]
28+
#pragma omp target data use_device_ptr(xp)
29+
printf("%p\n", xp); // CHECK-NEXT: 0x{{0*}}[[#ADDR]]
30+
}
31+
32+
int main() { f1(); }

0 commit comments

Comments
 (0)