aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/target-has-device-addr-8.C
blob: 2adfd30296f08a826f0683579f086ae4136ddd8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Testing 'has_device_addr' clause on the target construct with template.  */

#include <omp.h>

template <typename T>
void
foo (T (&x)[])
{
  #pragma omp target has_device_addr(x)
    for (int i = 0; i < 15; i++)
      x[i] = 2 * i;

  #pragma omp target has_device_addr(x[15:15])
    for (int i = 15; i < 30; i++)
      x[i] = 3 * i;
}

int
main ()
{
  int *dp = (int*)omp_target_alloc (30*sizeof(int), 0);

  #pragma omp target is_device_ptr(dp)
    for (int i = 0; i < 30; i++)
      dp[i] = i;

  int (&x)[30] = *static_cast<int(*)[30]>(static_cast<void*>(dp));

  foo <int> (x);

  int y[30];
  for (int i = 0; i < 30; ++i)
    y[i] = 0;
  int h = omp_get_initial_device ();
  int t = omp_get_default_device ();
  omp_target_memcpy (&y, dp, 30 * sizeof(int), 0, 0, h, t);
  for (int i = 0; i < 15; ++i)
    if (y[i] != 2 * i)
      __builtin_abort ();
  for (int i = 15; i < 30; ++i)
    if (y[i] != 3 * i)
      __builtin_abort ();

  omp_target_free (dp, 0);

  return 0;
}