* testsuite/libgomp.oacc-c-c++-common/loop-g-1.c: New.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / loop-g-2.c
blobc01c6fa66a6615833e509695563fa377fece72a3
1 /* { dg-do run } */
2 /* { dg-additional-options "-O2" */
4 #include <stdio.h>
6 #define N (32*32*32+17)
7 int main ()
9 int ary[N];
10 int ix;
11 int exit = 0;
12 int ondev = 0;
14 for (ix = 0; ix < N;ix++)
15 ary[ix] = -1;
17 #pragma acc parallel num_gangs(32) vector_length(32) copy(ary) copy(ondev)
19 #pragma acc loop gang (static:1)
20 for (unsigned ix = 0; ix < N; ix++)
22 if (__builtin_acc_on_device (5))
24 int g = 0, w = 0, v = 0;
26 __asm__ volatile ("mov.u32 %0,%%ctaid.x;" : "=r" (g));
27 __asm__ volatile ("mov.u32 %0,%%tid.y;" : "=r" (w));
28 __asm__ volatile ("mov.u32 %0,%%tid.x;" : "=r" (v));
29 ary[ix] = (g << 16) | (w << 8) | v;
30 ondev = 1;
32 else
33 ary[ix] = ix;
37 for (ix = 0; ix < N; ix++)
39 int expected = ix;
40 if(ondev)
42 int g = ix % 32;
43 int w = 0;
44 int v = 0;
46 expected = (g << 16) | (w << 8) | v;
49 if (ary[ix] != expected)
51 exit = 1;
52 printf ("ary[%d]=%x expected %x\n", ix, ary[ix], expected);
56 return exit;