blob: ad6ba4b618a31d6d6f087d9d5a9581a1783be0e4 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +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
25#include "Globals.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026#include "NEON/NEAccessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010027#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#include "TensorLibrary.h"
29#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/NEON/functions/NEIntegralImage.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::neon;
49using namespace arm_compute::test::validation;
50
51namespace
52{
53/** Compute Neon integral image function.
54 *
55 * @param[in] shape Shape of the input and output tensors.
56 *
57 * @return Computed output tensor.
58 */
59Tensor compute_integral_image(const TensorShape &shape)
60{
61 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010062 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
63 Tensor dst = create_tensor<Tensor>(shape, DataType::U32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064
65 // Create integral image configure function
66 NEIntegralImage 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(NEAccessor(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(NEON)
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 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
95 Tensor dst = create_tensor<Tensor>(shape, DataType::U32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096
97 BOOST_TEST(src.info()->is_resizable());
98 BOOST_TEST(dst.info()->is_resizable());
99
100 // Create integral image configure function
101 NEIntegralImage 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 src_padding = PaddingCalculator(shape.x(), 16).required_padding();
111 const PaddingSize dst_padding(1, src_padding.right, 0, 1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112
113 validate(src.info()->padding(), src_padding);
114 validate(dst.info()->padding(), dst_padding);
115}
116
117BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
118BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
119{
120 // Compute function
121 Tensor dst = compute_integral_image(shape);
122
123 // Compute reference
124 RawTensor ref_dst = Reference::compute_reference_integral_image(shape);
125
126 // Validate output
127 validate(NEAccessor(dst), ref_dst);
128}
129
130BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
131BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(), shape)
132{
133 // Compute function
134 Tensor dst = compute_integral_image(shape);
135
136 // Compute reference
137 RawTensor ref_dst = Reference::compute_reference_integral_image(shape);
138
139 // Validate output
140 validate(NEAccessor(dst), ref_dst);
141}
142
143BOOST_AUTO_TEST_SUITE_END()
144BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100145#endif /* DOXYGEN_SKIP_THIS */