blob: 7a421ecf5a94c09911fe76ef6f264ace64bb6aba [file] [log] [blame]
Anthony Barbierdbdab852017-06-23 15:42:00 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "CL/CLAccessor.h"
25#include "CL/Helper.h"
26#include "Globals.h"
27#include "TensorLibrary.h"
28#include "TypePrinter.h"
29#include "Utils.h"
30#include "validation/Datasets.h"
31#include "validation/Reference.h"
32#include "validation/Validation.h"
33
34#include "arm_compute/core/Helpers.h"
35#include "arm_compute/core/Types.h"
36#include "arm_compute/runtime/CL/functions/CLDepthConvert.h"
37#include "arm_compute/runtime/Tensor.h"
38#include "arm_compute/runtime/TensorAllocator.h"
39
40#include "boost_wrapper.h"
41
42#include <random>
43#include <string>
44
45using namespace arm_compute;
46using namespace arm_compute::test;
47using namespace arm_compute::test::cl;
48using namespace arm_compute::test::validation;
49
50namespace
51{
52/** Compute CL depth convert function.
53 *
54 * @param[in] shape Shape of the input and output tensors.
55 * @param[in] dt_in Data type of input tensor.
56 * @param[in] dt_out Data type of the output tensor.
57 * @param[in] policy Conversion policy.
58 * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8.
59 *
60 * @return Computed output CLtensor.
61 */
62CLTensor compute_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift)
63{
64 // Create tensors
65 CLTensor src = create_tensor(shape, dt_in);
66 CLTensor dst = create_tensor(shape, dt_out);
67
68 // Create and configure function
69 CLDepthConvert depth_convert;
70 depth_convert.configure(&src, &dst, policy, shift);
71
72 // Allocate tensors
73 src.allocator()->allocate();
74 dst.allocator()->allocate();
75
76 BOOST_TEST(!src.info()->is_resizable());
77 BOOST_TEST(!dst.info()->is_resizable());
78
79 // Fill tensors
80 library->fill_tensor_uniform(CLAccessor(src), 0);
81
82 // Compute function
83 depth_convert.run();
84
85 return dst;
86}
87/** Configure and validate region/padding function.
88 *
89 * @param[in] shape Shape of the input and output tensors.
90 * @param[in] dt_in Data type of input tensor.
91 * @param[in] dt_out Data type of the output tensor.
92 * @param[in] policy Conversion policy.
93 * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8.
94 *
95 */
96void compute_configure_validate(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift)
97{
98 // Create tensors
99 CLTensor src = create_tensor(shape, dt_in);
100 CLTensor dst = create_tensor(shape, dt_out);
101
102 BOOST_TEST(src.info()->is_resizable());
103 BOOST_TEST(dst.info()->is_resizable());
104
105 // Create and configure function
106 CLDepthConvert depth_convert;
107 depth_convert.configure(&src, &dst, policy, shift);
108
109 // Validate valid region
110 const ValidRegion valid_region = shape_to_valid_region(shape);
111 validate(src.info()->valid_region(), valid_region);
112 validate(dst.info()->valid_region(), valid_region);
113
114 // Validate padding
115 const PaddingSize padding(0, required_padding(shape.x(), 16), 0, 0);
116 validate(src.info()->padding(), padding);
117 validate(dst.info()->padding(), padding);
118}
119} // namespace
120
121#ifndef DOXYGEN_SKIP_THIS
122BOOST_AUTO_TEST_SUITE(CL)
123BOOST_AUTO_TEST_SUITE(DepthConvert)
124
125BOOST_AUTO_TEST_SUITE(U8_to_U16)
126BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
127BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
128 * boost::unit_test::data::xrange(0, 7, 1),
129 shape, policy, shift)
130{
131 // Compute configure and validate region/padding
132 compute_configure_validate(shape, DataType::U8, DataType::U16, policy, shift);
133}
134
135BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
136BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
137 * boost::unit_test::data::xrange(0, 7, 1),
138 shape, policy, shift)
139{
140 // Compute function
141 CLTensor dst = compute_depth_convert(shape, DataType::U8, DataType::U16, policy, shift);
142
143 // Compute reference
144 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::U16, policy, shift, 0);
145
146 // Validate output
147 validate(CLAccessor(dst), ref_dst);
148}
149BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
150BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
151 * boost::unit_test::data::xrange(0, 7, 1),
152 shape, policy, shift)
153{
154 // Compute function
155 CLTensor dst = compute_depth_convert(shape, DataType::U8, DataType::U16, policy, shift);
156
157 // Compute reference
158 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::U16, policy, shift, 0);
159
160 // Validate output
161 validate(CLAccessor(dst), ref_dst);
162}
163BOOST_AUTO_TEST_SUITE_END()
164
165BOOST_AUTO_TEST_SUITE(U8_to_S16)
166BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
167BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
168 * boost::unit_test::data::xrange(0, 7, 1),
169 shape, policy, shift)
170{
171 // Compute configure and validate region/padding
172 compute_configure_validate(shape, DataType::U8, DataType::S16, policy, shift);
173}
174
175BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
176BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
177 * boost::unit_test::data::xrange(0, 7, 1),
178 shape, policy, shift)
179{
180 // Compute function
181 CLTensor dst = compute_depth_convert(shape, DataType::U8, DataType::S16, policy, shift);
182
183 // Compute reference
184 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S16, policy, shift, 0);
185
186 // Validate output
187 validate(CLAccessor(dst), ref_dst);
188}
189
190BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
191BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
192 * boost::unit_test::data::xrange(0, 7, 1),
193 shape, policy, shift)
194{
195 // Compute function
196 CLTensor dst = compute_depth_convert(shape, DataType::U8, DataType::S16, policy, shift);
197
198 // Compute reference
199 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S16, policy, shift, 0);
200
201 // Validate output
202 validate(CLAccessor(dst), ref_dst);
203}
204BOOST_AUTO_TEST_SUITE_END()
205
206BOOST_AUTO_TEST_SUITE(U8_to_S32)
207BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
208BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
209 * boost::unit_test::data::xrange(0, 7, 1),
210 shape, policy, shift)
211{
212 // Compute configure and validate region/padding
213 compute_configure_validate(shape, DataType::U8, DataType::S32, policy, shift);
214}
215
216BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
217BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
218 * boost::unit_test::data::xrange(0, 7, 1),
219 shape, policy, shift)
220{
221 // Compute function
222 CLTensor dst = compute_depth_convert(shape, DataType::U8, DataType::S32, policy, shift);
223
224 // Compute reference
225 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S32, policy, shift, 0);
226
227 // Validate output
228 validate(CLAccessor(dst), ref_dst);
229}
230
231BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
232BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
233 * boost::unit_test::data::xrange(0, 7, 1),
234 shape, policy, shift)
235{
236 // Compute function
237 CLTensor dst = compute_depth_convert(shape, DataType::U8, DataType::S32, policy, shift);
238
239 // Compute reference
240 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S32, policy, shift, 0);
241
242 // Validate output
243 validate(CLAccessor(dst), ref_dst);
244}
245BOOST_AUTO_TEST_SUITE_END()
246
247BOOST_AUTO_TEST_SUITE(U16_to_U8)
248BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
249BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
250 * boost::unit_test::data::xrange(0, 7, 1),
251 shape, policy, shift)
252{
253 // Compute configure and validate region/padding
254 compute_configure_validate(shape, DataType::U16, DataType::U8, policy, shift);
255}
256
257BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
258BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
259 * boost::unit_test::data::xrange(0, 7, 1),
260 shape, policy, shift)
261{
262 // Compute function
263 CLTensor dst = compute_depth_convert(shape, DataType::U16, DataType::U8, policy, shift);
264
265 // Compute reference
266 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U8, policy, shift, 0);
267
268 // Validate output
269 validate(CLAccessor(dst), ref_dst);
270}
271
272BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
273BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
274 * boost::unit_test::data::xrange(0, 7, 1),
275 shape, policy, shift)
276{
277 // Compute function
278 CLTensor dst = compute_depth_convert(shape, DataType::U16, DataType::U8, policy, shift);
279
280 // Compute reference
281 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U8, policy, shift, 0);
282
283 // Validate output
284 validate(CLAccessor(dst), ref_dst);
285}
286BOOST_AUTO_TEST_SUITE_END()
287
288BOOST_AUTO_TEST_SUITE(U16_to_U32)
289BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
290BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
291 * boost::unit_test::data::xrange(0, 7, 1),
292 shape, policy, shift)
293{
294 // Compute configure and validate region/padding
295 compute_configure_validate(shape, DataType::U16, DataType::U32, policy, shift);
296}
297
298BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
299BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
300 * boost::unit_test::data::xrange(0, 7, 1),
301 shape, policy, shift)
302{
303 // Compute function
304 CLTensor dst = compute_depth_convert(shape, DataType::U16, DataType::U32, policy, shift);
305
306 // Compute reference
307 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U32, policy, shift, 0);
308
309 // Validate output
310 validate(CLAccessor(dst), ref_dst);
311}
312
313BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
314BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
315 * boost::unit_test::data::xrange(0, 7, 1),
316 shape, policy, shift)
317{
318 // Compute function
319 CLTensor dst = compute_depth_convert(shape, DataType::U16, DataType::U32, policy, shift);
320
321 // Compute reference
322 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U32, policy, shift, 0);
323
324 // Validate output
325 validate(CLAccessor(dst), ref_dst);
326}
327BOOST_AUTO_TEST_SUITE_END()
328
329BOOST_AUTO_TEST_SUITE(S16_to_U8)
330BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
331BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
332 * boost::unit_test::data::xrange(0, 7, 1),
333 shape, policy, shift)
334{
335 // Compute configure and validate region/padding
336 compute_configure_validate(shape, DataType::S16, DataType::U8, policy, shift);
337}
338
339BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
340BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
341 * boost::unit_test::data::xrange(0, 7, 1),
342 shape, policy, shift)
343{
344 // Compute function
345 CLTensor dst = compute_depth_convert(shape, DataType::S16, DataType::U8, policy, shift);
346
347 // Compute reference
348 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::U8, policy, shift, 0);
349
350 // Validate output
351 validate(CLAccessor(dst), ref_dst);
352}
353
354BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
355BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
356 * boost::unit_test::data::xrange(0, 7, 1),
357 shape, policy, shift)
358{
359 // Compute function
360 CLTensor dst = compute_depth_convert(shape, DataType::S16, DataType::U8, policy, shift);
361
362 // Compute reference
363 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::U8, policy, shift, 0);
364
365 // Validate output
366 validate(CLAccessor(dst), ref_dst);
367}
368BOOST_AUTO_TEST_SUITE_END()
369
370BOOST_AUTO_TEST_SUITE(S16_to_S32)
371BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
372BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
373 * boost::unit_test::data::xrange(0, 7, 1),
374 shape, policy, shift)
375{
376 // Compute configure and validate region/padding
377 compute_configure_validate(shape, DataType::S16, DataType::S32, policy, shift);
378}
379
380BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
381BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
382 * boost::unit_test::data::xrange(0, 7, 1),
383 shape, policy, shift)
384{
385 // Compute function
386 CLTensor dst = compute_depth_convert(shape, DataType::S16, DataType::S32, policy, shift);
387
388 // Compute reference
389 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::S32, policy, shift, 0);
390
391 // Validate output
392 validate(CLAccessor(dst), ref_dst);
393}
394
395BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
396BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP })
397 * boost::unit_test::data::xrange(0, 7, 1),
398 shape, policy, shift)
399{
400 // Compute function
401 CLTensor dst = compute_depth_convert(shape, DataType::S16, DataType::S32, policy, shift);
402
403 // Compute reference
404 RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::S32, policy, shift, 0);
405
406 // Validate output
407 validate(CLAccessor(dst), ref_dst);
408}
409BOOST_AUTO_TEST_SUITE_END()
410
411BOOST_AUTO_TEST_SUITE_END()
412BOOST_AUTO_TEST_SUITE_END()
413#endif