| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-additional-options "-fdump-tree-optimized" } */ |
| 3 |
/* { dg-additional-options "-DDEVICE_ARCH=x86_64 -DDEVICE_ISA=mmx -mmmx" { target { x86 && lp64 } } } */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
static void |
| 8 |
init (int n, double *a) |
| 9 |
{ |
| 10 |
for (int i = 0; i < n; i++) |
| 11 |
a[i] = (double) i; |
| 12 |
} |
| 13 |
|
| 14 |
static void |
| 15 |
check (int n, double *a, double s) |
| 16 |
{ |
| 17 |
for (int i = 0; i < n; i++) |
| 18 |
if (a[i] != (double) i * s) |
| 19 |
abort (); |
| 20 |
} |
| 21 |
|
| 22 |
typedef void (transform_fn) (int, double *, double); |
| 23 |
|
| 24 |
static void |
| 25 |
doit (transform_fn *f, int n, double *a, double s) |
| 26 |
{ |
| 27 |
init (n, a); |
| 28 |
(*f) (n, a, s); |
| 29 |
check (n, a, s); |
| 30 |
} |
| 31 |
|
| 32 |
/* Check kind=host matches (with offloading disabled). */ |
| 33 |
static void |
| 34 |
f1 (int n, double* a, double s) |
| 35 |
{ |
| 36 |
#pragma omp metadirective \ |
| 37 |
when (target_device={kind(host)} \ |
| 38 |
: parallel for) \ |
| 39 |
default (error at(execution) message("f1 match failed")) |
| 40 |
for (int i = 0; i < n; i++) |
| 41 |
a[i] = a[i] * s; |
| 42 |
} |
| 43 |
|
| 44 |
/* Check kind=nohost does not match (with offloading disabled). */ |
| 45 |
static void |
| 46 |
f2 (int n, double* a, double s) |
| 47 |
{ |
| 48 |
#pragma omp metadirective \ |
| 49 |
when (target_device={kind(nohost)} \ |
| 50 |
: error at(execution) message("f2 match failed")) \ |
| 51 |
default (parallel for) |
| 52 |
for (int i = 0; i < n; i++) |
| 53 |
a[i] = a[i] * s; |
| 54 |
} |
| 55 |
|
| 56 |
/* Check arch. Either DEVICE_ARCH is defined by command-line option, |
| 57 |
or we know it is not x86_64. */ |
| 58 |
#ifdef DEVICE_ARCH |
| 59 |
static void |
| 60 |
f3 (int n, double* a, double s) |
| 61 |
{ |
| 62 |
#pragma omp metadirective \ |
| 63 |
when (target_device={arch(DEVICE_ARCH)} \ |
| 64 |
: parallel for) \ |
| 65 |
default (error at(execution) message("f3 match failed")) |
| 66 |
for (int i = 0; i < n; i++) |
| 67 |
a[i] = a[i] * s; |
| 68 |
} |
| 69 |
#else |
| 70 |
static void |
| 71 |
f3 (int n, double* a, double s) |
| 72 |
{ |
| 73 |
#pragma omp metadirective \ |
| 74 |
when (target_device={arch("x86_64")} \ |
| 75 |
: error at(execution) message("f3 match failed")) \ |
| 76 |
default (parallel for) |
| 77 |
for (int i = 0; i < n; i++) |
| 78 |
a[i] = a[i] * s; |
| 79 |
} |
| 80 |
#endif |
| 81 |
|
| 82 |
/* Check both kind and arch together. */ |
| 83 |
#ifdef DEVICE_ARCH |
| 84 |
static void |
| 85 |
f4 (int n, double* a, double s) |
| 86 |
{ |
| 87 |
#pragma omp metadirective \ |
| 88 |
when (target_device={arch(DEVICE_ARCH), kind(host)} \ |
| 89 |
: parallel for) \ |
| 90 |
default (error at(execution) message("f4 match failed")) |
| 91 |
for (int i = 0; i < n; i++) |
| 92 |
a[i] = a[i] * s; |
| 93 |
} |
| 94 |
#else |
| 95 |
static void |
| 96 |
f4 (int n, double* a, double s) |
| 97 |
{ |
| 98 |
#pragma omp metadirective \ |
| 99 |
when (target_device={arch("x86_64"), kind(host)} \ |
| 100 |
: error at(execution) message("f4 match failed")) \ |
| 101 |
default (parallel for) |
| 102 |
for (int i = 0; i < n; i++) |
| 103 |
a[i] = a[i] * s; |
| 104 |
} |
| 105 |
#endif |
| 106 |
|
| 107 |
/* Check kind, arch, and ISA together. */ |
| 108 |
#if defined(DEVICE_ARCH) && defined(DEVICE_ISA) |
| 109 |
static void |
| 110 |
f5 (int n, double* a, double s) |
| 111 |
{ |
| 112 |
#pragma omp metadirective \ |
| 113 |
when (target_device={arch(DEVICE_ARCH), kind(host), isa(DEVICE_ISA)} \ |
| 114 |
: parallel for) \ |
| 115 |
default (error at(execution) message("f5 match failed")) |
| 116 |
for (int i = 0; i < n; i++) |
| 117 |
a[i] = a[i] * s; |
| 118 |
} |
| 119 |
#else |
| 120 |
static void |
| 121 |
f5 (int n, double* a, double s) |
| 122 |
{ |
| 123 |
#pragma omp metadirective \ |
| 124 |
when (target_device={arch("x86_64"), kind(host), isa("mmx")} \ |
| 125 |
: error at(execution) message("f5 match failed")) \ |
| 126 |
default (parallel for) |
| 127 |
for (int i = 0; i < n; i++) |
| 128 |
a[i] = a[i] * s; |
| 129 |
} |
| 130 |
#endif |
| 131 |
|
| 132 |
#define N 10 |
| 133 |
#define S 2.0 |
| 134 |
|
| 135 |
int |
| 136 |
main (void) |
| 137 |
{ |
| 138 |
double a[N]; |
| 139 |
doit (f1, N, a, S); |
| 140 |
doit (f2, N, a, S); |
| 141 |
doit (f3, N, a, S); |
| 142 |
doit (f4, N, a, S); |
| 143 |
doit (f5, N, a, S); |
| 144 |
} |
| 145 |
|
| 146 |
/* The gimplifier emits all 5 alternatives. In configurations without |
| 147 |
offloading, the dynamic selector can be completely resolved, otherwise |
| 148 |
the calls to GOMP_error must remain in the generated code pending |
| 149 |
runtime evaluation of the selectors. */ |
| 150 |
/* { dg-final { scan-tree-dump-times "GOMP_error" 5 "optimized" { target offloading_enabled } } } */ |
| 151 |
/* { dg-final { scan-tree-dump-times "GOMP_error" 0 "optimized" { target { ! offloading_enabled } } } } */ |