2015-11-18 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / routine-v-1.c
blob29e0f9017a51009ad9fa2156e1b65a99a07b5790
1 /* { dg-do run } */
2 /* { dg-additional-options "-O2" */
4 #include <stdio.h>
6 #define N (32*32*32+17)
8 #pragma acc routine vector
9 void __attribute__ ((noinline)) vector (int ary[N])
11 #pragma acc loop 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 vector_length(32) copy(ary) copy(ondev)
40 ondev = __builtin_acc_on_device (5);
41 vector (ary);
44 for (ix = 0; ix < N; ix++)
46 int expected = ix;
47 if(ondev)
49 int g = 0;
50 int w = 0;
51 int v = ix % 32;
53 expected = (g << 16) | (w << 8) | v;
56 if (ary[ix] != expected)
58 exit = 1;
59 printf ("ary[%d]=%x expected %x\n", ix, ary[ix], expected);
63 return exit;