]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/testsuite/libgomp.oacc-c-c++-common/loop-red-wv-1.c
[openacc] Add __builtin_goacc_parlevel_{id,size}
[thirdparty/gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / loop-red-wv-1.c
1 /* { dg-do run } */
2 /* { dg-additional-options "-O2" } */
3
4 #include <stdio.h>
5 #include <openacc.h>
6 #include <gomp-constants.h>
7
8 #define N (32*32*32+17)
9 int main ()
10 {
11 int ix;
12 int ondev = 0;
13 int t = 0, h = 0;
14
15 #pragma acc parallel num_workers(32) vector_length(32) copy(ondev)
16 {
17 #pragma acc loop worker vector reduction (+:t)
18 for (unsigned ix = 0; ix < N; ix++)
19 {
20 int val = ix;
21
22 if (acc_on_device (acc_device_not_host))
23 {
24 int g, w, v;
25
26 g = __builtin_goacc_parlevel_id (GOMP_DIM_GANG);
27 w = __builtin_goacc_parlevel_id (GOMP_DIM_WORKER);
28 v = __builtin_goacc_parlevel_id (GOMP_DIM_VECTOR);
29 val = (g << 16) | (w << 8) | v;
30 ondev = 1;
31 }
32 t += val;
33 }
34 }
35
36 for (ix = 0; ix < N; ix++)
37 {
38 int val = ix;
39 if(ondev)
40 {
41 int g = 0;
42 int w = (ix / 32) % 32;
43 int v = ix % 32;
44
45 val = (g << 16) | (w << 8) | v;
46 }
47 h += val;
48 }
49 if (t != h)
50 {
51 printf ("t=%x expected %x\n", t, h);
52 return 1;
53 }
54
55 return 0;
56 }