1 | /* |
2 | * compute_optimal_device_grid_unit_tests.hpp |
3 | * |
4 | * Created on: Oct 1, 2017 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_DATA_SRC_UTIL_TEST_COMPUTE_OPTIMAL_DEVICE_GRID_UNIT_TESTS_HPP_ |
9 | #define OPENFPM_DATA_SRC_UTIL_TEST_COMPUTE_OPTIMAL_DEVICE_GRID_UNIT_TESTS_HPP_ |
10 | |
11 | #include "util/compute_optimal_device_grid.hpp" |
12 | |
13 | BOOST_AUTO_TEST_SUITE( compute_optimal_device_grid_test ) |
14 | |
15 | BOOST_AUTO_TEST_CASE( compute_optimal_device_use_test ) |
16 | { |
17 | // Check 1D response |
18 | |
19 | size_t sz[1] = {1}; |
20 | device_grid<1> dg; |
21 | calculate_optimal_device_grid<1>(dg,sz,1,1); |
22 | |
23 | BOOST_REQUIRE_EQUAL(dg.threads.x,1ul); |
24 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
25 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
26 | |
27 | BOOST_REQUIRE_EQUAL(dg.grids.x,1ul); |
28 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
29 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
30 | |
31 | // Fill with garbage |
32 | dg.threads.x = 123; |
33 | dg.threads.y = 123; |
34 | dg.threads.z = 123; |
35 | |
36 | dg.grids.x = 123; |
37 | dg.grids.y = 123; |
38 | dg.grids.z = 123; |
39 | |
40 | calculate_optimal_device_grid<1>(dg,sz,8,4); |
41 | |
42 | BOOST_REQUIRE_EQUAL(dg.threads.x,1ul); |
43 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
44 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
45 | |
46 | BOOST_REQUIRE_EQUAL(dg.grids.x,1ul); |
47 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
48 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
49 | |
50 | sz[0] = 6; |
51 | calculate_optimal_device_grid<1>(dg,sz,8,4); |
52 | |
53 | BOOST_REQUIRE_EQUAL(dg.threads.x,6ul); |
54 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
55 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
56 | |
57 | BOOST_REQUIRE_EQUAL(dg.grids.x,1ul); |
58 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
59 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
60 | |
61 | sz[0] = 6; |
62 | |
63 | // Fill with garbage |
64 | dg.threads.x = 123; |
65 | dg.threads.y = 123; |
66 | dg.threads.z = 123; |
67 | |
68 | dg.grids.x = 123; |
69 | dg.grids.y = 123; |
70 | dg.grids.z = 123; |
71 | calculate_optimal_device_grid<1>(dg,sz,28,10); |
72 | |
73 | BOOST_REQUIRE_EQUAL(dg.threads.x,6ul); |
74 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
75 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
76 | |
77 | BOOST_REQUIRE_EQUAL(dg.grids.x,1ul); |
78 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
79 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
80 | |
81 | sz[0] = 17; |
82 | |
83 | calculate_optimal_device_grid<1>(dg,sz,28,10); |
84 | |
85 | BOOST_REQUIRE_EQUAL(dg.threads.x,17ul); |
86 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
87 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
88 | |
89 | BOOST_REQUIRE_EQUAL(dg.grids.x,1ul); |
90 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
91 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
92 | |
93 | sz[0] = 17; |
94 | |
95 | calculate_optimal_device_grid<1>(dg,sz,1,1); |
96 | |
97 | BOOST_REQUIRE_EQUAL(dg.threads.x,1ul); |
98 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
99 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
100 | |
101 | BOOST_REQUIRE_EQUAL(dg.grids.x,17ul); |
102 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
103 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
104 | |
105 | sz[0] = 17; |
106 | |
107 | // Fill with garbage |
108 | dg.threads.x = 123; |
109 | dg.threads.y = 123; |
110 | dg.threads.z = 123; |
111 | |
112 | dg.grids.x = 123; |
113 | dg.grids.y = 123; |
114 | dg.grids.z = 123; |
115 | calculate_optimal_device_grid<1>(dg,sz,5,3); |
116 | |
117 | BOOST_REQUIRE_EQUAL(dg.threads.x,1ul); |
118 | BOOST_REQUIRE_EQUAL(dg.threads.y,1ul); |
119 | BOOST_REQUIRE_EQUAL(dg.threads.z,1ul); |
120 | |
121 | BOOST_REQUIRE_EQUAL(dg.grids.x,17ul); |
122 | BOOST_REQUIRE_EQUAL(dg.grids.y,1ul); |
123 | BOOST_REQUIRE_EQUAL(dg.grids.z,1ul); |
124 | |
125 | |
126 | // 2D test |
127 | |
128 | size_t sz2[] = {64,64}; |
129 | device_grid<2> dg2; |
130 | |
131 | calculate_optimal_device_grid<2>(dg2,sz2,1536,512); |
132 | |
133 | BOOST_REQUIRE_EQUAL(dg2.threads.x,64ul); |
134 | BOOST_REQUIRE_EQUAL(dg2.threads.y,16ul); |
135 | BOOST_REQUIRE_EQUAL(dg2.threads.z,1ul); |
136 | |
137 | BOOST_REQUIRE_EQUAL(dg2.grids.x,1ul); |
138 | BOOST_REQUIRE_EQUAL(dg2.grids.y,4ul); |
139 | BOOST_REQUIRE_EQUAL(dg2.grids.z,1ul); |
140 | |
141 | // 2D test |
142 | |
143 | sz2[0] = 126; |
144 | sz2[1] = 126; |
145 | |
146 | calculate_optimal_device_grid<2>(dg2,sz2,1536,512); |
147 | |
148 | BOOST_REQUIRE_EQUAL(dg2.threads.x,18ul); |
149 | BOOST_REQUIRE_EQUAL(dg2.threads.y,18ul); |
150 | BOOST_REQUIRE_EQUAL(dg2.threads.z,1ul); |
151 | |
152 | BOOST_REQUIRE_EQUAL(dg2.grids.x,7ul); |
153 | BOOST_REQUIRE_EQUAL(dg2.grids.y,7ul); |
154 | BOOST_REQUIRE_EQUAL(dg2.grids.z,1ul); |
155 | |
156 | sz2[0] = 162; |
157 | sz2[1] = 126; |
158 | |
159 | calculate_optimal_device_grid<2>(dg2,sz2,1536,512); |
160 | |
161 | BOOST_REQUIRE_EQUAL(dg2.threads.x,162ul); |
162 | BOOST_REQUIRE_EQUAL(dg2.threads.y,6ul); |
163 | BOOST_REQUIRE_EQUAL(dg2.threads.z,1ul); |
164 | |
165 | BOOST_REQUIRE_EQUAL(dg2.grids.x,1ul); |
166 | BOOST_REQUIRE_EQUAL(dg2.grids.y,21ul); |
167 | BOOST_REQUIRE_EQUAL(dg2.grids.z,1ul); |
168 | |
169 | size_t sz3[3] = {126,126,126}; |
170 | |
171 | device_grid<3> dg3; |
172 | |
173 | calculate_optimal_device_grid<3>(dg3,sz3,1536,512); |
174 | |
175 | BOOST_REQUIRE_EQUAL(dg3.threads.x,18ul); |
176 | BOOST_REQUIRE_EQUAL(dg3.threads.y,18ul); |
177 | BOOST_REQUIRE_EQUAL(dg3.threads.z,2ul); |
178 | |
179 | BOOST_REQUIRE_EQUAL(dg3.grids.x,7ul); |
180 | BOOST_REQUIRE_EQUAL(dg3.grids.y,7ul); |
181 | BOOST_REQUIRE_EQUAL(dg3.grids.z,63ul); |
182 | } |
183 | |
184 | BOOST_AUTO_TEST_SUITE_END() |
185 | |
186 | #endif /* OPENFPM_DATA_SRC_UTIL_TEST_COMPUTE_OPTIMAL_DEVICE_GRID_UNIT_TESTS_HPP_ */ |
187 | |