blob: 650738c0f6f779641672c8a42df25112931e80e3 [file] [log] [blame]
Sanghoon Lee72898fe2017-09-01 11:42:16 +01001/*
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +00002 * Copyright (c) 2017-2019 ARM Limited.
Sanghoon Lee72898fe2017-09-01 11:42:16 +01003 *
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,
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +000021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Sanghoon Lee72898fe2017-09-01 11:42:16 +010022 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/NEON/functions/NEArithmeticSubtraction.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ConvertPolicyDataset.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
Georgios Pinitascbf39c62018-09-10 15:07:45 +010036#include "tests/validation/fixtures/ArithmeticOperationsFixture.h"
Sanghoon Lee72898fe2017-09-01 11:42:16 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Manuel Bottini8d04fa02019-03-08 14:00:40 +000046
47#ifdef __aarch64__
48constexpr AbsoluteTolerance<float> tolerance_qasymm8(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
49#else //__aarch64__
50constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
51#endif //__aarch64__
52
Sanghoon Lee72898fe2017-09-01 11:42:16 +010053/** Input data sets **/
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000054const auto ArithmeticSubtractionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8),
55 framework::dataset::make("DataType", DataType::QASYMM8)),
56 framework::dataset::make("DataType", DataType::QASYMM8));
57
58const auto ArithmeticSubtractionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8),
59 framework::dataset::make("DataType", DataType::U8)),
60 framework::dataset::make("DataType", DataType::U8));
61
62const auto ArithmeticSubtractionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }),
63 framework::dataset::make("DataType", DataType::S16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010064 framework::dataset::make("DataType", DataType::S16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000065#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000066const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16),
67 framework::dataset::make("DataType", DataType::F16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010068 framework::dataset::make("DataType", DataType::F16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000069#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000070const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32),
71 framework::dataset::make("DataType", DataType::F32)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010072 framework::dataset::make("DataType", DataType::F32));
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000073
74const auto ArithmeticSubtractionQuantizationInfoDataset = combine(combine(framework::dataset::make("QuantizationInfoIn1", { QuantizationInfo(10, 120) }),
75 framework::dataset::make("QuantizationInfoIn2", { QuantizationInfo(20, 110) })),
76 framework::dataset::make("QuantizationInfoOut", { QuantizationInfo(15, 125) }));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010077} // namespace
78
79TEST_SUITE(NEON)
80TEST_SUITE(ArithmeticSubtraction)
81
Georgios Pinitascbf39c62018-09-10 15:07:45 +010082template <typename T>
83using NEArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>;
84
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000085// *INDENT-OFF*
86// clang-format off
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000087DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Georgios Pinitascbf39c62018-09-10 15:07:45 +010088 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
89 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
91 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
92 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000093 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::QASYMM8), // Mismatching types
94 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Invalid convert policy
Georgios Pinitascbf39c62018-09-10 15:07:45 +010095 }),
96 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
97 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
98 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
99 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
100 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000101 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
102 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100103 })),
104 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
105 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
106 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
107 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
108 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000109 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100110 })),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000111 framework::dataset::make("ConvertPolicy",{ ConvertPolicy::WRAP,
112 ConvertPolicy::SATURATE,
113 ConvertPolicy::WRAP,
114 ConvertPolicy::SATURATE,
115 ConvertPolicy::WRAP,
116 ConvertPolicy::WRAP,
117 })),
118 framework::dataset::make("Expected", { true, true, false, false, false, false, false})),
119 input1_info, input2_info, output_info, policy, expected)
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000120{
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000121 ARM_COMPUTE_EXPECT(bool(NEArithmeticSubtraction::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), policy)) == expected, framework::LogLevel::ERRORS);
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000122}
123// clang-format on
124// *INDENT-ON*
125
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100126TEST_SUITE(U8)
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000127DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100128 shape, policy)
129{
130 // Create tensors
131 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8);
132 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8);
133 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
134
135 // Create and Configure function
136 NEArithmeticSubtraction sub;
137 sub.configure(&ref_src1, &ref_src2, &dst, policy);
138
139 // Validate valid region
140 const ValidRegion valid_region = shape_to_valid_region(shape);
141 validate(dst.info()->valid_region(), valid_region);
142
143 // Validate padding
144 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
145 validate(ref_src1.info()->padding(), padding);
146 validate(ref_src2.info()->padding(), padding);
147 validate(dst.info()->padding(), padding);
148}
149
150FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset),
151 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
152{
153 // Validate output
154 validate(Accessor(_target), _reference);
155}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100156TEST_SUITE_END() // U8
Isabella Gottardib5908c22017-10-30 15:28:13 +0000157
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000158using NEArithmeticSubtractionQuantFixture = ArithmeticSubtractionQuantValidationFixture<Tensor, Accessor, NEArithmeticSubtraction>;
159
160TEST_SUITE(Quantized)
161TEST_SUITE(QASYMM8)
162DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
163 shape, policy)
164{
165 // Create tensors
166 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8);
167 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8);
168 Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8);
169
170 // Create and Configure function
171 NEArithmeticSubtraction sub;
172 sub.configure(&ref_src1, &ref_src2, &dst, policy);
173
174 // Validate valid region
175 const ValidRegion valid_region = shape_to_valid_region(shape);
176 validate(dst.info()->valid_region(), valid_region);
177
178 // Validate padding
179 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
180 validate(ref_src1.info()->padding(), padding);
181 validate(ref_src2.info()->padding(), padding);
182 validate(dst.info()->padding(), padding);
183}
184
185FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionQuantFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
186 datasets::SmallShapes(),
187 ArithmeticSubtractionQASYMM8Dataset),
188 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
189 ArithmeticSubtractionQuantizationInfoDataset))
190{
191 // Validate output
Manuel Bottini8d04fa02019-03-08 14:00:40 +0000192 validate(Accessor(_target), _reference, tolerance_qasymm8);
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000193}
194TEST_SUITE_END() // QASYMM8
195TEST_SUITE_END() // Quantized
196
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100197TEST_SUITE(S16)
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000198DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100199 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100200 shape, data_type, policy)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100201{
202 // Create tensors
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100203 Tensor ref_src1 = create_tensor<Tensor>(shape, data_type);
204 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100205 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
206
207 // Create and Configure function
208 NEArithmeticSubtraction sub;
209 sub.configure(&ref_src1, &ref_src2, &dst, policy);
210
211 // Validate valid region
212 const ValidRegion valid_region = shape_to_valid_region(shape);
213 validate(dst.info()->valid_region(), valid_region);
214
215 // Validate padding
216 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
217 validate(ref_src1.info()->padding(), padding);
218 validate(ref_src2.info()->padding(), padding);
219 validate(dst.info()->padding(), padding);
220}
221
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100222FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
223 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100224{
225 // Validate output
226 validate(Accessor(_target), _reference);
227}
228
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100229FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset),
230 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100231{
232 // Validate output
233 validate(Accessor(_target), _reference);
234}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100235TEST_SUITE_END() // S16
Isabella Gottardib5908c22017-10-30 15:28:13 +0000236
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100237TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000238#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100239TEST_SUITE(F16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100240FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
241 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100242{
243 // Validate output
244 validate(Accessor(_target), _reference);
245}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100246TEST_SUITE_END() // F16
247#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100248
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100249TEST_SUITE(F32)
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000250DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100251 shape, policy)
252{
253 // Create tensors
254 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32);
255 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32);
256 Tensor dst = create_tensor<Tensor>(shape, DataType::F32);
257
258 // Create and Configure function
259 NEArithmeticSubtraction sub;
260 sub.configure(&ref_src1, &ref_src2, &dst, policy);
261
262 // Validate valid region
263 const ValidRegion valid_region = shape_to_valid_region(shape);
264 validate(dst.info()->valid_region(), valid_region);
265
266 // Validate padding
267 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
268 validate(ref_src1.info()->padding(), padding);
269 validate(ref_src2.info()->padding(), padding);
270 validate(dst.info()->padding(), padding);
271}
272
273FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
274 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
275{
276 // Validate output
277 validate(Accessor(_target), _reference);
278}
279
280FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
281 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
282{
283 // Validate output
284 validate(Accessor(_target), _reference);
285}
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100286
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100287template <typename T>
288using NEArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>;
289
290FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
291 ArithmeticSubtractionFP32Dataset),
292 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
293{
294 // Validate output
295 validate(Accessor(_target), _reference);
296}
297
298FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
299 ArithmeticSubtractionFP32Dataset),
300 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
301{
302 // Validate output
303 validate(Accessor(_target), _reference);
304}
305TEST_SUITE_END() // F32
306TEST_SUITE_END() // Float
307
308TEST_SUITE_END() // ArithmeticSubtraction
309TEST_SUITE_END() // NEON
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100310} // namespace validation
311} // namespace test
312} // namespace arm_compute