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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/* { dg-do compile } */
/* { dg-additional-options "-foffload=disable -fdump-tree-optimized" } */
#include <stdlib.h>
static void
init (int n, double *a)
{
for (int i = 0; i < n; i++)
a[i] = (double) i;
}
static void
check (int n, double *a, double s)
{
for (int i = 0; i < n; i++)
if (a[i] != (double) i * s)
abort ();
}
typedef void (transform_fn) (int, double *, double);
static void doit (transform_fn *f, int n, double *a, double s)
{
init (n, a);
(*f) (n, a, s);
check (n, a, s);
}
/* Check various combinations for enforcing correct ordering of
construct matches. */
static void
f1 (int n, double* a, double s)
{
#pragma omp target teams
#pragma omp parallel
#pragma omp metadirective \
when (construct={target} \
: for) \
default (error at(execution) message("f1 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
static void
f2 (int n, double* a, double s)
{
#pragma omp target teams
#pragma omp parallel
#pragma omp metadirective \
when (construct={teams, parallel} \
: for) \
default (error at(execution) message("f2 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
static void
f3 (int n, double* a, double s)
{
#pragma omp target teams
#pragma omp parallel
#pragma omp metadirective \
when (construct={target, teams, parallel} \
: for) \
default (error at(execution) message("f3 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
static void
f4 (int n, double* a, double s)
{
#pragma omp target teams
#pragma omp parallel
#pragma omp metadirective \
when (construct={target, parallel} \
: for) \
default (error at(execution) message("f4 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
static void
f5 (int n, double* a, double s)
{
#pragma omp target teams
#pragma omp parallel
#pragma omp metadirective \
when (construct={target, teams} \
: for) \
default (error at(execution) message("f5 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
/* Next batch is for things where the construct doesn't match the context. */
static void
f6 (int n, double* a, double s)
{
#pragma omp target
#pragma omp teams
#pragma omp metadirective \
when (construct={parallel} \
: error at(execution) message("f6 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
static void
f7 (int n, double* a, double s)
{
#pragma omp target
#pragma omp teams
#pragma omp metadirective \
when (construct={target, parallel} \
: error at(execution) message("f7 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
static void
f8 (int n, double* a, double s)
{
#pragma omp target
#pragma omp teams
#pragma omp metadirective \
when (construct={parallel, target} \
: error at(execution) message("f8 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
/* Next test choosing the best alternative when there are multiple
matches. */
static void
f9 (int n, double* a, double s)
{
#pragma omp target teams
#pragma omp parallel
#pragma omp metadirective \
when (construct={teams, parallel} \
: error at(execution) message("f9 match incorrect 1")) \
when (construct={target, teams, parallel} \
: for) \
when (construct={target, teams} \
: error at(execution) message("f9 match incorrect 2")) \
default (error at(execution) message("f9 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
/* Note there are no tests for the matching the extended simd clause
syntax, which is only useful for "declare variant". */
#define N 10
#define S 2.0
int
main (void)
{
double a[N];
doit (f1, N, a, S);
doit (f2, N, a, S);
doit (f3, N, a, S);
doit (f4, N, a, S);
doit (f5, N, a, S);
doit (f6, N, a, S);
doit (f7, N, a, S);
doit (f8, N, a, S);
doit (f9, N, a, S);
}
/* All the error calls should be optimized away. */
/* { dg-final { scan-tree-dump-not "__builtin_GOMP_error" "optimized" } } */
|