blob: 42a567c234022795ea38a96102b9a843e5a79f51 [file] [log] [blame]
Giorgio Arena84e31202017-06-16 11:34:18 +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
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010025#include "AssetsLibrary.h"
Giorgio Arena84e31202017-06-16 11:34:18 +010026#include "CL/CLAccessor.h"
Giorgio Arena84e31202017-06-16 11:34:18 +010027#include "Globals.h"
28#include "PaddingCalculator.h"
Giorgio Arena84e31202017-06-16 11:34:18 +010029#include "TypePrinter.h"
30#include "Utils.h"
31#include "validation/Datasets.h"
32#include "validation/Reference.h"
33#include "validation/Validation.h"
34
35#include "arm_compute/core/Helpers.h"
36#include "arm_compute/core/Types.h"
37#include "arm_compute/runtime/CL/functions/CLIntegralImage.h"
38#include "arm_compute/runtime/Tensor.h"
39#include "arm_compute/runtime/TensorAllocator.h"
40
41#include "boost_wrapper.h"
42
43#include <random>
44#include <string>
45
46using namespace arm_compute;
47using namespace arm_compute::test;
48using namespace arm_compute::test::cl;
49using namespace arm_compute::test::validation;
50
51namespace
52{
53/** Compute CL integral image function.
54 *
55 * @param[in] shape Shape of the input and output tensors.
56 *
57 * @return Computed output tensor.
58 */
59CLTensor compute_integral_image(const TensorShape &shape)
60{
61 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010062 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
63 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U32);
Giorgio Arena84e31202017-06-16 11:34:18 +010064
65 // Create integral image configure function
66 CLIntegralImage integral_image;
67 integral_image.configure(&src, &dst);
68
69 // Allocate tensors
70 src.allocator()->allocate();
71 dst.allocator()->allocate();
72
73 BOOST_TEST(!src.info()->is_resizable());
74 BOOST_TEST(!dst.info()->is_resizable());
75
76 // Fill tensors
77 library->fill_tensor_uniform(CLAccessor(src), 0);
78
79 // Compute function
80 integral_image.run();
81
82 return dst;
83}
84} // namespace
85
86#ifndef DOXYGEN_SKIP_THIS
87BOOST_AUTO_TEST_SUITE(CL)
88BOOST_AUTO_TEST_SUITE(IntegralImage)
89
90BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
91BOOST_DATA_TEST_CASE(Configuration, SmallShapes() + LargeShapes(), shape)
92{
93 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010094 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
95 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U32);
Giorgio Arena84e31202017-06-16 11:34:18 +010096
97 BOOST_TEST(src.info()->is_resizable());
98 BOOST_TEST(dst.info()->is_resizable());
99
100 // Create integral image configure function
101 CLIntegralImage integral_image;
102 integral_image.configure(&src, &dst);
103
104 // Validate valid region
105 const ValidRegion valid_region = shape_to_valid_region(shape);
106 validate(src.info()->valid_region(), valid_region);
107 validate(dst.info()->valid_region(), valid_region);
108
109 // Validate padding
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100110 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
111 validate(src.info()->padding(), padding);
112 validate(dst.info()->padding(), padding);
Giorgio Arena84e31202017-06-16 11:34:18 +0100113}
114
115BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
116BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
117{
118 // Compute function
119 CLTensor dst = compute_integral_image(shape);
120
121 // Compute reference
122 RawTensor ref_dst = Reference::compute_reference_integral_image(shape);
123
124 // Validate output
125 validate(CLAccessor(dst), ref_dst);
126}
127
128BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
129BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(), shape)
130{
131 // Compute function
132 CLTensor dst = compute_integral_image(shape);
133
134 // Compute reference
135 RawTensor ref_dst = Reference::compute_reference_integral_image(shape);
136
137 // Validate output
138 validate(CLAccessor(dst), ref_dst);
139}
140
141BOOST_AUTO_TEST_SUITE_END()
142BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100143#endif /* DOXYGEN_SKIP_THIS */