blob: 22f9eac7cd28d6fe006823cbe79f9ecae1f6cd20 [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#include "Globals.h"
25#include "NEON/Helper.h"
26#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/NEAbsoluteDifference.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 absolute difference function.
54 *
55 * @param[in] shape Shape of the input and output tensors.
56 * @param[in] dt_in0 Data type of first input tensor.
57 * @param[in] dt_in1 Data type of second input tensor.
58 * @param[in] dt_out Data type of the output tensor.
59 *
60 * @return Computed output tensor.
61 */
62Tensor compute_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out)
63{
64 // Create tensors
65 Tensor src1 = create_tensor(shape, dt_in0);
66 Tensor src2 = create_tensor(shape, dt_in1);
67 Tensor dst = create_tensor(shape, dt_out);
68
69 // Create and configure function
70 NEAbsoluteDifference abs_d;
71 abs_d.configure(&src1, &src2, &dst);
72
73 // Allocate tensors
74 src1.allocator()->allocate();
75 src2.allocator()->allocate();
76 dst.allocator()->allocate();
77
78 BOOST_TEST(!src1.info()->is_resizable());
79 BOOST_TEST(!src2.info()->is_resizable());
80 BOOST_TEST(!dst.info()->is_resizable());
81
82 // Fill tensors
83 library->fill_tensor_uniform(NEAccessor(src1), 0);
84 library->fill_tensor_uniform(NEAccessor(src2), 1);
85
86 // Compute function
87 abs_d.run();
88
89 return dst;
90}
91
92void validate_configuration(const Tensor &src1, const Tensor &src2, Tensor &dst, TensorShape shape)
93{
94 BOOST_TEST(src1.info()->is_resizable());
95 BOOST_TEST(src2.info()->is_resizable());
96 BOOST_TEST(dst.info()->is_resizable());
97
98 // Create and configure function
99 NEAbsoluteDifference abs_d;
100 abs_d.configure(&src1, &src2, &dst);
101
102 // Validate valid region
103 const ValidRegion valid_region = shape_to_valid_region(shape);
104 validate(src1.info()->valid_region(), valid_region);
105 validate(src2.info()->valid_region(), valid_region);
106 validate(dst.info()->valid_region(), valid_region);
107
108 // Validate padding
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100109 const PaddingSize padding(0, PaddingCalculator(shape.x(), 16).required_padding(), 0, 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110 validate(src1.info()->padding(), padding);
111 validate(src2.info()->padding(), padding);
112 validate(dst.info()->padding(), padding);
113}
114} // namespace
115
116#ifndef DOXYGEN_SKIP_THIS
117BOOST_AUTO_TEST_SUITE(NEON)
118BOOST_AUTO_TEST_SUITE(AbsoluteDifference)
119
120BOOST_AUTO_TEST_SUITE(U8)
121BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
122BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()),
123 shape)
124{
125 // Create tensors
126 Tensor src1 = create_tensor(shape, DataType::U8);
127 Tensor src2 = create_tensor(shape, DataType::U8);
128 Tensor dst = create_tensor(shape, DataType::U8);
129
130 validate_configuration(src1, src2, dst, shape);
131}
132BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
133BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(),
134 shape)
135{
136 // Compute function
137 Tensor dst = compute_absolute_difference(shape, DataType::U8, DataType::U8, DataType::U8);
138
139 // Compute reference
140 RawTensor ref_dst = Reference::compute_reference_absolute_difference(shape, DataType::U8, DataType::U8, DataType::U8);
141
142 // Validate output
143 validate(NEAccessor(dst), ref_dst);
144}
145BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
146BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(),
147 shape)
148{
149 // Compute function
150 Tensor dst = compute_absolute_difference(shape, DataType::U8, DataType::U8, DataType::U8);
151
152 // Compute reference
153 RawTensor ref_dst = Reference::compute_reference_absolute_difference(shape, DataType::U8, DataType::U8, DataType::U8);
154
155 // Validate output
156 validate(NEAccessor(dst), ref_dst);
157}
158BOOST_AUTO_TEST_SUITE_END()
159
160BOOST_AUTO_TEST_SUITE(S16)
161BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
162BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ DataType::U8, DataType::S16 }),
163 shape, dt)
164{
165 // Create tensors
166 Tensor src1 = create_tensor(shape, dt);
167 Tensor src2 = create_tensor(shape, DataType::S16);
168 Tensor dst = create_tensor(shape, DataType::S16);
169
170 validate_configuration(src1, src2, dst, shape);
171}
172BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
173BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }),
174 shape, dt)
175{
176 // Compute function
177 Tensor dst = compute_absolute_difference(shape, dt, DataType::S16, DataType::S16);
178
179 // Compute reference
180 RawTensor ref_dst = Reference::compute_reference_absolute_difference(shape, dt, DataType::S16, DataType::S16);
181
182 // Validate output
183 validate(NEAccessor(dst), ref_dst);
184}
185BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
186BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }),
187 shape, dt)
188{
189 // Compute function
190 Tensor dst = compute_absolute_difference(shape, dt, DataType::S16, DataType::S16);
191
192 // Compute reference
193 RawTensor ref_dst = Reference::compute_reference_absolute_difference(shape, dt, DataType::S16, DataType::S16);
194
195 // Validate output
196 validate(NEAccessor(dst), ref_dst);
197}
198BOOST_AUTO_TEST_SUITE_END()
199
200BOOST_AUTO_TEST_SUITE_END()
201BOOST_AUTO_TEST_SUITE_END()
202#endif