| 1 |
/* Testing 'has_device_addr' clause on the target construct with template. */ |
| 2 |
|
| 3 |
#include <omp.h> |
| 4 |
|
| 5 |
template <typename T> |
| 6 |
void |
| 7 |
foo (T (&x)[]) |
| 8 |
{ |
| 9 |
#pragma omp target has_device_addr(x) |
| 10 |
for (int i = 0; i < 15; i++) |
| 11 |
x[i] = 2 * i; |
| 12 |
|
| 13 |
#pragma omp target has_device_addr(x[15:15]) |
| 14 |
for (int i = 15; i < 30; i++) |
| 15 |
x[i] = 3 * i; |
| 16 |
} |
| 17 |
|
| 18 |
int |
| 19 |
main () |
| 20 |
{ |
| 21 |
int *dp = (int*)omp_target_alloc (30*sizeof(int), 0); |
| 22 |
|
| 23 |
#pragma omp target is_device_ptr(dp) |
| 24 |
for (int i = 0; i < 30; i++) |
| 25 |
dp[i] = i; |
| 26 |
|
| 27 |
int (&x)[30] = *static_cast<int(*)[30]>(static_cast<void*>(dp)); |
| 28 |
|
| 29 |
foo <int> (x); |
| 30 |
|
| 31 |
int y[30]; |
| 32 |
for (int i = 0; i < 30; ++i) |
| 33 |
y[i] = 0; |
| 34 |
int h = omp_get_initial_device (); |
| 35 |
int t = omp_get_default_device (); |
| 36 |
omp_target_memcpy (&y, dp, 30 * sizeof(int), 0, 0, h, t); |
| 37 |
for (int i = 0; i < 15; ++i) |
| 38 |
if (y[i] != 2 * i) |
| 39 |
__builtin_abort (); |
| 40 |
for (int i = 15; i < 30; ++i) |
| 41 |
if (y[i] != 3 * i) |
| 42 |
__builtin_abort (); |
| 43 |
|
| 44 |
omp_target_free (dp, 0); |
| 45 |
|
| 46 |
return 0; |
| 47 |
} |