aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/goacc/template.C
blob: f7a717bf7ed03e67257d1451b6f26ee665f291dc (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// This error is temporary.  Remove when support is added for these clauses
// in the middle end.  Also remove the comments from the reduction test
// after the FE learns that reduction variables may appear in data clauses too.
// { dg-prune-output "sorry, unimplemented" }

#pragma acc routine
template <typename T> T
accDouble(int val)
{
  return val * 2;
}

template<typename T> T
oacc_parallel_copy (T a)
{
  T b = 0;
  char w = 1;
  int x = 2;
  float y = 3;
  double z = 4;

#pragma acc parallel num_gangs (a) num_workers (a) vector_length (a) default (none) copyout (b) copyin (a)
  {
    b = a;
  }

#pragma acc parallel num_gangs (a) copy (w, x, y, z)
  {
    w = accDouble<char>(w);
    x = accDouble<int>(x);
    y = accDouble<float>(y);
    z = accDouble<double>(z);
  }

#pragma acc parallel num_gangs (a) if (1)
  {
#pragma acc loop auto tile (a, 3)
  for (int i = 0; i < a; i++)
    for (int j = 0; j < 5; j++)
      b = a;

#pragma acc loop seq
  for (int i = 0; i < a; i++)
    b = a;
  }

  T c;

#pragma acc parallel num_workers (10)
  {
#pragma acc atomic capture
    c = b++;

#pragma atomic update
    c++;

#pragma acc atomic read
    b = a;

#pragma acc atomic write
    b = a;
  }

//#pragma acc parallel reduction (+:c)
//  {
//    c = 1;
//  }

#pragma acc data if (1) copy (b)
  {
    #pragma acc parallel
    {
      b = a;
    }
  }

#pragma acc enter data copyin (b)
#pragma acc parallel present (b)
    {
      b = a;
    }

#pragma acc update host (b)
#pragma acc update self (b)
#pragma acc update device (b)
#pragma acc exit data delete (b)

  return b;
}

template<typename T> T
oacc_kernels_copy (T a)
{
  T b = 0;
  T c = 0;
  char w = 1;
  int x = 2;
  float y = 3;
  double z = 4;

#pragma acc kernels copy (w, x, y, z)
  {
    w = accDouble<char>(w);
    x = accDouble<int>(x);
    y = accDouble<float>(y);
    z = accDouble<double>(z);
  }

#pragma acc kernels copyout (b) copyin (a)
  b = a;

//#pragma acc kernels loop reduction (+:c)
//  for (int i = 0; i < 10; i++)
//    {
//      c = 1;
//    }

#pragma acc data if (1) copy (b)
  {
    #pragma acc kernels
    {
      b = a;
    }
  }

#pragma acc enter data copyin (b)
#pragma acc kernels present (b)
    {
      b = a;
    }
  return b;
}

int
main ()
{
  int b = oacc_parallel_copy<int> (5);
  int c = oacc_kernels_copy<int> (5);

  return b + c;
}