| 1 |
/* { dg-additional-options "-fdump-tree-gimple" } */ |
| 2 |
|
| 3 |
// Do diagnostic check / dump check only; |
| 4 |
// Note: this test should work as run-test as well. |
| 5 |
|
| 6 |
#if 0 |
| 7 |
#include <omp.h> |
| 8 |
#else |
| 9 |
#ifdef __cplusplus |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
extern int omp_get_default_device (); |
| 13 |
extern int omp_get_num_devices (); |
| 14 |
#ifdef __cplusplus |
| 15 |
} |
| 16 |
#endif |
| 17 |
#endif |
| 18 |
|
| 19 |
|
| 20 |
void f(int *x, int *y); |
| 21 |
#pragma omp declare variant(f) adjust_args(need_device_ptr: x, y) match(construct={dispatch}) |
| 22 |
void g(int *x, int *y); |
| 23 |
|
| 24 |
void |
| 25 |
sub (int *a, int *b) |
| 26 |
{ |
| 27 |
// The has_device_addr is a bit questionable as the caller is not actually |
| 28 |
// passing a device address - but we cannot pass one because of the |
| 29 |
// following: |
| 30 |
// |
| 31 |
// As for 'b' need_device_ptr has been specified and 'b' is not |
| 32 |
// in the semantic requirement set 'is_device_ptr' (and only in 'has_device_addr') |
| 33 |
// "the argument is converted in the same manner that a use_device_ptr clause |
| 34 |
// on a target_data construct converts its pointer" |
| 35 |
#pragma omp dispatch is_device_ptr(a), has_device_addr(b) /* { dg-warning "'has_device_addr' for 'b' does not imply 'is_device_ptr' required for 'need_device_ptr' \\\[-Wopenmp\\\]" } */ |
| 36 |
g(a, b); |
| 37 |
} |
| 38 |
|
| 39 |
void |
| 40 |
f(int *from, int *to) |
| 41 |
{ |
| 42 |
static int cnt = 0; |
| 43 |
cnt++; |
| 44 |
if (cnt >= 3) |
| 45 |
{ |
| 46 |
if (omp_get_default_device () != -1 |
| 47 |
&& omp_get_default_device () < omp_get_num_devices ()) |
| 48 |
{ |
| 49 |
// On offload device but not mapped |
| 50 |
if (from != (void *)0L) // Not mapped |
| 51 |
__builtin_abort (); |
| 52 |
} |
| 53 |
else if (from[0] != 5) |
| 54 |
__builtin_abort (); |
| 55 |
return; |
| 56 |
} |
| 57 |
#pragma omp target is_device_ptr(from, to) |
| 58 |
{ |
| 59 |
to[0] = from[0] * 10; |
| 60 |
to[1] = from[1] * 10; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
int |
| 65 |
main () |
| 66 |
{ |
| 67 |
int A[2], B[2] = {123, 456}, C[1] = {5}; |
| 68 |
int *p = A; |
| 69 |
#pragma omp target enter data map(A, B) |
| 70 |
|
| 71 |
/* Note: We don't add 'use_device_addr(B)' here; |
| 72 |
if we do, it will fail with an illegal memory access (why?). */ |
| 73 |
#pragma omp target data use_device_ptr(p) |
| 74 |
{ |
| 75 |
sub(p, B); |
| 76 |
sub(C, B); /* C is not mapped -> 'from' ptr == NULL */ |
| 77 |
} |
| 78 |
|
| 79 |
#pragma omp target exit data map(A, B) |
| 80 |
} |
| 81 |
|
| 82 |
// { dg-final { scan-tree-dump-times "#pragma omp dispatch has_device_addr\\(b\\) is_device_ptr\\(a\\)" 1 "gimple" } } |
| 83 |
// { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 1 "gimple" } } |
| 84 |
// { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(b" 1 "gimple" } } |
| 85 |
// { dg-final { scan-tree-dump-times "f \\(a, D\\.\[0-9\]+\\);" 1 "gimple" } } |