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
|
/* { dg-do compile } */
/* { dg-additional-options "-foffload=disable -fdump-tree-optimized" } */
/* { dg-additional-options "-DDEVICE_ARCH=x86_64 -DDEVICE_ISA=sse -msse" { target { x86 && lp64 } } } */
#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 kind=host matches (with offloading disabled). */
static void
f1 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={kind(host)} \
: parallel for) \
default (error at(execution) message("f1 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
/* Check kind=nohost does not match (with offloading disabled). */
static void
f2 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={kind(nohost)} \
: error at(execution) message("f2 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
/* Check arch. Either DEVICE_ARCH is defined by command-line option,
or we know it is not x86_64. */
#ifdef DEVICE_ARCH
static void
f3 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={arch(DEVICE_ARCH)} \
: parallel for) \
default (error at(execution) message("f3 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
#else
static void
f3 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={arch("x86_64")} \
: error at(execution) message("f3 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
#endif
/* Check both kind and arch together. */
#ifdef DEVICE_ARCH
static void
f4 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={arch(DEVICE_ARCH), kind(host)} \
: parallel for) \
default (error at(execution) message("f4 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
#else
static void
f4 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={arch("x86_64"), kind(host)} \
: error at(execution) message("f4 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
#endif
/* Check kind, arch, and ISA together. */
#if defined(DEVICE_ARCH) && defined(DEVICE_ISA)
static void
f5 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={arch(DEVICE_ARCH), kind(host), isa(DEVICE_ISA)} \
: parallel for) \
default (error at(execution) message("f5 match failed"))
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
#else
static void
f5 (int n, double* a, double s)
{
#pragma omp metadirective \
when (device={arch("x86_64"), kind(host), isa("sse")} \
: error at(execution) message("f5 match failed")) \
default (parallel for)
for (int i = 0; i < n; i++)
a[i] = a[i] * s;
}
#endif
#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);
}
/* All the metadirectives involving the device selector should be
fully resolved and the error calls optimized away. */
/* { dg-final { scan-tree-dump-not "__builtin_GOMP_error" "optimized" } } */
|