2015-11-18 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / routine-gwv-1.c
blob5980747f137f854378c99abe18d7668686f6723a
1 /* { dg-do run } */
2 /* { dg-additional-options "-O2" */
4 #include <stdio.h>
6 #define N (32*32*32+17)
8 #pragma acc routine gang
9 void __attribute__ ((noinline)) gang (int ary[N])
11 #pragma acc loop gang worker vector
12 for (unsigned ix = 0; ix < N; ix++)
14 if (__builtin_acc_on_device (5))
16 int g = 0, w = 0, v = 0;
18 __asm__ volatile ("mov.u32 %0,%%ctaid.x;" : "=r" (g));
19 __asm__ volatile ("mov.u32 %0,%%tid.y;" : "=r" (w));
20 __asm__ volatile ("mov.u32 %0,%%tid.x;" : "=r" (v));
21 ary[ix] = (g << 16) | (w << 8) | v;
23 else
24 ary[ix] = ix;
28 int main ()
30 int ary[N];
31 int ix;
32 int exit = 0;
33 int ondev = 0;
35 for (ix = 0; ix < N;ix++)
36 ary[ix] = -1;
38 #pragma acc parallel num_gangs(32) num_workers(32) vector_length(32) copy(ary) copy(ondev)
40 ondev = __builtin_acc_on_device (5);
41 gang (ary);
44 for (ix = 0; ix < N; ix++)
46 int expected = ix;
47 if(ondev)
49 int chunk_size = (N + 32*32*32 - 1) / (32*32*32);
51 int g = ix / (chunk_size * 32 * 32);
52 int w = ix / 32 % 32;
53 int v = ix % 32;
55 expected = (g << 16) | (w << 8) | v;
58 if (ary[ix] != expected)
60 exit = 1;
61 printf ("ary[%d]=%x expected %x\n", ix, ary[ix], expected);
65 return exit;