1 /* { dg-do run } */
2
3 /* Ignore vector_length warnings for offloaded (nvptx) targets. */
4 /* { dg-additional-options "-foffload=-w" } */
5
6 /* Integer reductions. */
7
8 #include <stdlib.h>
9 #include "reduction.h"
10
11 const int ng = 8;
12 const int nw = 4;
13 const int vl = 32;
14
15 static void
test_reductions(void)16 test_reductions (void)
17 {
18 const int n = 10;
19 int i;
20 int array[n];
21
22 for (i = 0; i < n; i++)
23 array[i] = i+1;
24
25 /* Gang reductions. */
26 check_reduction_op (int, +, 0, array[i], num_gangs (ng), gang);
27 check_reduction_op (int, *, 1, array[i], num_gangs (ng), gang);
28 check_reduction_op (int, &, -1, array[i], num_gangs (ng), gang);
29 check_reduction_op (int, |, 0, array[i], num_gangs (ng), gang);
30 check_reduction_op (int, ^, 0, array[i], num_gangs (ng), gang);
31
32 /* Worker reductions. */
33 check_reduction_op (int, +, 0, array[i], num_workers (nw), worker);
34 check_reduction_op (int, *, 1, array[i], num_workers (nw), worker);
35 check_reduction_op (int, &, -1, array[i], num_workers (nw), worker);
36 check_reduction_op (int, |, 0, array[i], num_workers (nw), worker);
37 check_reduction_op (int, ^, 0, array[i], num_workers (nw), worker);
38
39 /* Vector reductions. */
40 check_reduction_op (int, +, 0, array[i], vector_length (vl), vector);
41 check_reduction_op (int, *, 1, array[i], vector_length (vl), vector);
42 check_reduction_op (int, &, -1, array[i], vector_length (vl), vector);
43 check_reduction_op (int, |, 0, array[i], vector_length (vl), vector);
44 check_reduction_op (int, ^, 0, array[i], vector_length (vl), vector);
45
46 /* Combined reductions. */
47 check_reduction_op (int, +, 0, array[i], num_gangs (ng) num_workers (nw)
48 vector_length (vl), gang worker vector);
49 check_reduction_op (int, *, 1, array[i], num_gangs (ng) num_workers (nw)
50 vector_length (vl), gang worker vector);
51 check_reduction_op (int, &, -1, array[i], num_gangs (ng) num_workers (nw)
52 vector_length (vl), gang worker vector);
53 check_reduction_op (int, |, 0, array[i], num_gangs (ng) num_workers (nw)
54 vector_length (vl), gang worker vector);
55 check_reduction_op (int, ^, 0, array[i], num_gangs (ng) num_workers (nw)
56 vector_length (vl), gang worker vector);
57 }
58
59 static void
test_reductions_bool(void)60 test_reductions_bool (void)
61 {
62 const int n = 1000;
63 int i;
64 int array[n];
65 int cmp_val;
66
67 for (i = 0; i < n; i++)
68 array[i] = i;
69
70 cmp_val = 5;
71
72 /* Gang reductions. */
73 check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng),
74 gang);
75 check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng),
76 gang);
77
78 /* Worker reductions. */
79 check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_workers (nw),
80 worker);
81 check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_workers (nw),
82 worker);
83
84 /* Vector reductions. */
85 check_reduction_op (int, &&, 1, (cmp_val > array[i]), vector_length (vl),
86 vector);
87 check_reduction_op (int, ||, 0, (cmp_val > array[i]), vector_length (vl),
88 vector);
89
90 /* Combined reductions. */
91 check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng)
92 num_workers (nw) vector_length (vl), gang worker vector);
93 check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng)
94 num_workers (nw) vector_length (vl), gang worker vector);
95 }
96
97 static void
test_reductions_minmax(void)98 test_reductions_minmax (void)
99 {
100 const int n = 1000;
101 int i;
102 int array[n];
103
104 for (i = 0; i < n; i++)
105 array[i] = i;
106
107 /* Gang reductions. */
108 check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng), gang);
109 check_reduction_macro (int, max, -1, array[i], num_gangs (ng), gang);
110
111 /* Worker reductions. */
112 check_reduction_macro (int, min, n + 1, array[i], num_workers (nw), worker);
113 check_reduction_macro (int, max, -1, array[i], num_workers (nw), worker);
114
115 /* Vector reductions. */
116 check_reduction_macro (int, min, n + 1, array[i], vector_length (vl),
117 vector);
118 check_reduction_macro (int, max, -1, array[i], vector_length (vl), vector);
119
120 /* Combined reductions. */
121 check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng)
122 num_workers (nw) vector_length (vl), gang worker
123 vector);
124 check_reduction_macro (int, max, -1, array[i], num_gangs (ng)
125 num_workers (nw) vector_length (vl), gang worker
126 vector);
127 }
128
129 int
main(void)130 main (void)
131 {
132 test_reductions ();
133 test_reductions_bool ();
134 test_reductions_minmax ();
135 return 0;
136 }
137