blob: ade473abff03239c6d6962a5bea79de633f1bdf4 [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/NEArithmeticSubtraction.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 arithmetic subtraction 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 * @param[in] policy Overflow policy of the operation.
60 *
61 * @return Computed output tensor.
62 */
63Tensor compute_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy policy)
64{
65 // Create tensors
66 Tensor src1 = create_tensor(shape, dt_in0);
67 Tensor src2 = create_tensor(shape, dt_in1);
68 Tensor dst = create_tensor(shape, dt_out);
69
70 // Create and configure function
71 NEArithmeticSubtraction sub;
72 sub.configure(&src1, &src2, &dst, policy);
73
74 // Allocate tensors
75 src1.allocator()->allocate();
76 src2.allocator()->allocate();
77 dst.allocator()->allocate();
78
79 BOOST_TEST(!src1.info()->is_resizable());
80 BOOST_TEST(!src2.info()->is_resizable());
81 BOOST_TEST(!dst.info()->is_resizable());
82
83 // Fill tensors
84 library->fill_tensor_uniform(NEAccessor(src1), 0);
85 library->fill_tensor_uniform(NEAccessor(src2), 1);
86
87 // Compute function
88 sub.run();
89
90 return dst;
91}
92
93void validate_configuration(const Tensor &src1, const Tensor &src2, Tensor &dst, TensorShape shape, ConvertPolicy policy)
94{
95 BOOST_TEST(src1.info()->is_resizable());
96 BOOST_TEST(src2.info()->is_resizable());
97 BOOST_TEST(dst.info()->is_resizable());
98
99 // Create and configure function
100 NEArithmeticSubtraction sub;
101 sub.configure(&src1, &src2, &dst, policy);
102
103 // Validate valid region
104 const ValidRegion valid_region = shape_to_valid_region(shape);
105 validate(src1.info()->valid_region(), valid_region);
106 validate(src2.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();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100111 validate(src1.info()->padding(), padding);
112 validate(src2.info()->padding(), padding);
113 validate(dst.info()->padding(), padding);
114}
115} // namespace
116
117#ifndef DOXYGEN_SKIP_THIS
118BOOST_AUTO_TEST_SUITE(NEON)
119BOOST_AUTO_TEST_SUITE(ArithmeticSubtraction)
120
121BOOST_AUTO_TEST_SUITE(U8)
122BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
123BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
124 shape, policy)
125{
126 // Create tensors
127 Tensor src1 = create_tensor(shape, DataType::U8);
128 Tensor src2 = create_tensor(shape, DataType::U8);
129 Tensor dst = create_tensor(shape, DataType::U8);
130
131 validate_configuration(src1, src2, dst, shape, policy);
132}
133BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
134BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
135 shape, policy)
136{
137 // Compute function
138 Tensor dst = compute_arithmetic_subtraction(shape, DataType::U8, DataType::U8, DataType::U8, policy);
139
140 // Compute reference
141 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, DataType::U8, DataType::U8, DataType::U8, policy);
142
143 // Validate output
144 validate(NEAccessor(dst), ref_dst);
145}
146BOOST_AUTO_TEST_SUITE_END()
147
148BOOST_AUTO_TEST_SUITE(S16)
149BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
150BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
151 shape, dt, policy)
152{
153 // Create tensors
154 Tensor src1 = create_tensor(shape, dt);
155 Tensor src2 = create_tensor(shape, DataType::S16);
156 Tensor dst = create_tensor(shape, DataType::S16);
157
158 validate_configuration(src1, src2, dst, shape, policy);
159}
160BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
161BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
162 shape, dt, policy)
163{
164 // Compute function
165 Tensor dst = compute_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
166
167 // Compute reference
168 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
169
170 // Validate output
171 validate(NEAccessor(dst), ref_dst);
172}
173BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
174BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
175 shape, dt, policy)
176{
177 // Compute function
178 Tensor dst = compute_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
179
180 // Compute reference
181 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, dt, DataType::S16, DataType::S16, policy);
182
183 // Validate output
184 validate(NEAccessor(dst), ref_dst);
185}
186BOOST_AUTO_TEST_SUITE_END()
187
188BOOST_AUTO_TEST_SUITE(F32)
189BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
190BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
191 shape, policy)
192{
193 // Create tensors
194 Tensor src1 = create_tensor(shape, DataType::F32);
195 Tensor src2 = create_tensor(shape, DataType::F32);
196 Tensor dst = create_tensor(shape, DataType::F32);
197
198 validate_configuration(src1, src2, dst, shape, policy);
199}
200BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
201BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
202{
203 // Compute function
204 Tensor dst = compute_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, ConvertPolicy::WRAP);
205
206 // Compute reference
207 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, ConvertPolicy::WRAP);
208
209 // Validate output
210 validate(NEAccessor(dst), ref_dst);
211}
212BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
213BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE, ConvertPolicy::WRAP }),
214 shape, policy)
215{
216 // Compute function
217 Tensor dst = compute_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, policy);
218
219 // Compute reference
220 RawTensor ref_dst = Reference::compute_reference_arithmetic_subtraction(shape, DataType::F32, DataType::F32, DataType::F32, policy);
221
222 // Validate output
223 validate(NEAccessor(dst), ref_dst);
224}
225BOOST_AUTO_TEST_SUITE_END()
226
227BOOST_AUTO_TEST_SUITE_END()
228BOOST_AUTO_TEST_SUITE_END()
229#endif