Debian Codegraph @

libgomp/testsuite/libgomp.oacc-c-c++-common/loop-red-gwv-1.c

raw
1 /* { dg-additional-options "-fopt-info-note-omp" }
2 { dg-additional-options "--param=openacc-privatization=noisy" }
3 { dg-additional-options "-foffload=-fopt-info-note-omp" }
4 { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
5 for testing/documenting aspects of that functionality. */
6
7 #include <stdio.h>
8 #include <openacc.h>
9 #include <gomp-constants.h>
10
11 #define N (32*32*32+17)
12 int main ()
13 {
14 int ix;
15 int ondev = 0;
16 int t = 0, h = 0;
17 int gangsize, workersize, vectorsize;
18
19 #define NG 32
20 #define NW 32
21 #define VL 32
22 #pragma acc parallel num_gangs(NG) num_workers(NW) vector_length(VL) \
23 copy(ondev)
24 /* { dg-note {variable 'ix' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-2 } */
25 {
26 #pragma acc loop gang worker vector reduction(+:t)
27 /* { dg-note {variable 'ix' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-1 } */
28 /* { dg-note {variable 'val' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-2 } */
29 /* { dg-note {variable 'g' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-3 } */
30 /* { dg-note {variable 'w' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-4 } */
31 /* { dg-note {variable 'v' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} "" { target *-*-* } .-5 } */
32 for (unsigned ix = 0; ix < N; ix++)
33 {
34 int val = ix;
35
36 if (acc_on_device (acc_device_not_host))
37 {
38 int g, w, v;
39
40 g = __builtin_goacc_parlevel_id (GOMP_DIM_GANG);
41 w = __builtin_goacc_parlevel_id (GOMP_DIM_WORKER);
42 v = __builtin_goacc_parlevel_id (GOMP_DIM_VECTOR);
43 val = (g << 16) | (w << 8) | v;
44 ondev = 1;
45 }
46 t += val;
47 }
48 }
49 gangsize = NG;
50 workersize = NW;
51 vectorsize = VL;
52 #ifdef ACC_DEVICE_TYPE_radeon
53 /* AMD GCN has an upper limit of 'num_workers(16)'. */
54 if (workersize > 16)
55 workersize = 16;
56 /* AMD GCN uses the autovectorizer for the vector dimension: the use
57 of a function call in vector-partitioned code in this test is not
58 currently supported. */
59 vectorsize = 1;
60 #endif
61
62 for (ix = 0; ix < N; ix++)
63 {
64 int val = ix;
65 if (ondev)
66 {
67 int chunk_size = (N + gangsize * workersize * vectorsize - 1)
68 / (gangsize * workersize * vectorsize);
69
70 int g = ix / (chunk_size * vectorsize * workersize);
71 int w = ix / vectorsize % workersize;
72 int v = ix % vectorsize;
73
74 val = (g << 16) | (w << 8) | v;
75 }
76 h += val;
77 }
78 if (t != h)
79 {
80 printf ("t=%x expected %x\n", t, h);
81 return 1;
82 }
83
84 return 0;
85 }