blob: 35c29638a5b2a4b720dcc8b3d4c3b27f849b7832 [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"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025#include "NEON/NEAccessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010026#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#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/NEON/functions/NEArithmeticSubtraction.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::neon;
48using namespace arm_compute::test::validation;
49
50namespace
51{
52/** Compute Neon arithmetic subtraction function.
53 *
54 * @param[in] shape Shape of the input and output tensors.
55 * @param[in] dt_in0 Data type of first input tensor.
56 * @param[in] dt_in1 Data type of second input tensor.
57 * @param[in] dt_out Data type of the output tensor.
58 * @param[in] policy Overflow policy of the operation.
59 *
60 * @return Computed output tensor.
61 */
62Tensor compute_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy policy)
63{
64 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010065 Tensor src1 = create_tensor<Tensor>(shape, dt_in0);
66 Tensor src2 = create_tensor<Tensor>(shape, dt_in1);
67 Tensor dst = create_tensor<Tensor>(shape, dt_out);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068
69 // Create and configure function
70 NEArithmeticSubtraction sub;
71 sub.configure(&src1, &src2, &dst, policy);
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 sub.run();
88
89 return dst;
90}
91
92void validate_configuration(const Tensor &src1, const Tensor &src2, Tensor &dst, TensorShape shape, ConvertPolicy policy)
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 NEArithmeticSubtraction sub;
100 sub.configure(&src1, &src2, &dst, policy);
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 Pflanzer2509fba2017-06-23 14:15:03 +0100109 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
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(ArithmeticSubtraction)
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()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
123 shape, policy)
124{
125 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +0100126 Tensor src1 = create_tensor<Tensor>(shape, DataType::U8);
127 Tensor src2 = create_tensor<Tensor>(shape, DataType::U8);
128 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100129
130 validate_configuration(src1, src2, dst, shape, policy);
131}
132BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
133BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
134 shape, policy)
135{
136 // Compute function
137 Tensor dst = compute_arithmetic_subtraction(shape, DataType::U8, DataType::U8, DataType::U8, policy);
138
139 // Compute reference
140 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, DataType::U8, DataType::U8, DataType::U8, policy);
141
142 // Validate output
143 validate(NEAccessor(dst), ref_dst);
144}
145BOOST_AUTO_TEST_SUITE_END()
146
147BOOST_AUTO_TEST_SUITE(S16)
148BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
149BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
150 shape, dt, policy)
151{
152 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +0100153 Tensor src1 = create_tensor<Tensor>(shape, dt);
154 Tensor src2 = create_tensor<Tensor>(shape, DataType::S16);
155 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156
157 validate_configuration(src1, src2, dst, shape, policy);
158}
159BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
160BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
161 shape, dt, policy)
162{
163 // Compute function
164 Tensor dst = compute_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
165
166 // Compute reference
167 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
168
169 // Validate output
170 validate(NEAccessor(dst), ref_dst);
171}
172BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
173BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
174 shape, dt, policy)
175{
176 // Compute function
177 Tensor dst = compute_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
178
179 // Compute reference
180 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
181
182 // Validate output
183 validate(NEAccessor(dst), ref_dst);
184}
185BOOST_AUTO_TEST_SUITE_END()
186
187BOOST_AUTO_TEST_SUITE(F32)
188BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
189BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
190 shape, policy)
191{
192 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +0100193 Tensor src1 = create_tensor<Tensor>(shape, DataType::F32);
194 Tensor src2 = create_tensor<Tensor>(shape, DataType::F32);
195 Tensor dst = create_tensor<Tensor>(shape, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100196
197 validate_configuration(src1, src2, dst, shape, policy);
198}
199BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
200BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
201{
202 // Compute function
203 Tensor dst = compute_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, ConvertPolicy::WRAP);
204
205 // Compute reference
206 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, ConvertPolicy::WRAP);
207
208 // Validate output
209 validate(NEAccessor(dst), ref_dst);
210}
211BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
212BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
213 shape, policy)
214{
215 // Compute function
216 Tensor dst = compute_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, policy);
217
218 // Compute reference
219 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, policy);
220
221 // Validate output
222 validate(NEAccessor(dst), ref_dst);
223}
224BOOST_AUTO_TEST_SUITE_END()
225
226BOOST_AUTO_TEST_SUITE_END()
227BOOST_AUTO_TEST_SUITE_END()
228#endif