* testsuite/libgomp.oacc-c-c++-common/loop-g-1.c: New.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / loop-gwv-1.c
blobf23e2f379d2ed908466ad61a658e5a6d21fc9420
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) num_workers(32) vector_length(32) copy(ary) copy(ondev)
19 #pragma acc loop gang worker vector
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 chunk_size = (N + 32*32*32 - 1) / (32*32*32);
44 int g = ix / (chunk_size * 32 * 32);
45 int w = ix / 32 % 32;
46 int v = ix % 32;
48 expected = (g << 16) | (w << 8) | v;
51 if (ary[ix] != expected)
53 exit = 1;
54 printf ("ary[%d]=%x expected %x\n", ix, ary[ix], expected);
58 return exit;