| 1 |
#include <stdio.h> |
| 2 |
#include <openacc.h> |
| 3 |
#include <gomp-constants.h> |
| 4 |
|
| 5 |
#define N (32*32*32+17) |
| 6 |
|
| 7 |
#pragma acc routine gang |
| 8 |
void __attribute__ ((noinline)) gang (int ary[N]) |
| 9 |
{ |
| 10 |
#pragma acc loop gang worker vector |
| 11 |
for (unsigned ix = 0; ix < N; ix++) |
| 12 |
{ |
| 13 |
if (acc_on_device (acc_device_not_host)) |
| 14 |
{ |
| 15 |
int g, w, v; |
| 16 |
|
| 17 |
g = __builtin_goacc_parlevel_id (GOMP_DIM_GANG); |
| 18 |
w = __builtin_goacc_parlevel_id (GOMP_DIM_WORKER); |
| 19 |
v = __builtin_goacc_parlevel_id (GOMP_DIM_VECTOR); |
| 20 |
ary[ix] = (g << 16) | (w << 8) | v; |
| 21 |
} |
| 22 |
else |
| 23 |
ary[ix] = ix; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
int main () |
| 28 |
{ |
| 29 |
int ary[N]; |
| 30 |
int ix; |
| 31 |
int exit = 0; |
| 32 |
int ondev = 0; |
| 33 |
int gangsize, workersize, vectorsize; |
| 34 |
|
| 35 |
for (ix = 0; ix < N;ix++) |
| 36 |
ary[ix] = -1; |
| 37 |
|
| 38 |
#define NG 32 |
| 39 |
#define NW 32 |
| 40 |
#define VL 32 |
| 41 |
#pragma acc parallel num_gangs(NG) num_workers(NW) vector_length(VL) \ |
| 42 |
copy(ary) copy(ondev) |
| 43 |
{ |
| 44 |
ondev = acc_on_device (acc_device_not_host); |
| 45 |
gang (ary); |
| 46 |
} |
| 47 |
gangsize = NG; |
| 48 |
workersize = NW; |
| 49 |
vectorsize = VL; |
| 50 |
#ifdef ACC_DEVICE_TYPE_radeon |
| 51 |
/* AMD GCN has an upper limit of 'num_workers(16)'. */ |
| 52 |
if (workersize > 16) |
| 53 |
workersize = 16; |
| 54 |
/* AMD GCN uses the autovectorizer for the vector dimension: the use |
| 55 |
of a function call in vector-partitioned code in this test is not |
| 56 |
currently supported. */ |
| 57 |
vectorsize = 1; |
| 58 |
#endif |
| 59 |
|
| 60 |
for (ix = 0; ix < N; ix++) |
| 61 |
{ |
| 62 |
int expected = ix; |
| 63 |
if(ondev) |
| 64 |
{ |
| 65 |
int chunk_size = (N + gangsize * workersize * vectorsize - 1) |
| 66 |
/ (gangsize * workersize * vectorsize); |
| 67 |
|
| 68 |
int g = ix / (chunk_size * vectorsize * workersize); |
| 69 |
int w = (ix / vectorsize) % workersize; |
| 70 |
int v = ix % vectorsize; |
| 71 |
|
| 72 |
expected = (g << 16) | (w << 8) | v; |
| 73 |
} |
| 74 |
|
| 75 |
if (ary[ix] != expected) |
| 76 |
{ |
| 77 |
exit = 1; |
| 78 |
printf ("ary[%d]=%x expected %x\n", ix, ary[ix], expected); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
return exit; |
| 83 |
} |