blob: 2fc5448dc2b678cbe428b06859a1ff7ace98a7c5 [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{
46/** Input data sets **/
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000047const auto ArithmeticSubtractionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8),
48 framework::dataset::make("DataType", DataType::QASYMM8)),
49 framework::dataset::make("DataType", DataType::QASYMM8));
50
51const auto ArithmeticSubtractionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8),
52 framework::dataset::make("DataType", DataType::U8)),
53 framework::dataset::make("DataType", DataType::U8));
54
55const auto ArithmeticSubtractionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }),
56 framework::dataset::make("DataType", DataType::S16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010057 framework::dataset::make("DataType", DataType::S16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000058#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000059const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16),
60 framework::dataset::make("DataType", DataType::F16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010061 framework::dataset::make("DataType", DataType::F16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000062#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000063const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32),
64 framework::dataset::make("DataType", DataType::F32)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010065 framework::dataset::make("DataType", DataType::F32));
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000066
67const auto ArithmeticSubtractionQuantizationInfoDataset = combine(combine(framework::dataset::make("QuantizationInfoIn1", { QuantizationInfo(10, 120) }),
68 framework::dataset::make("QuantizationInfoIn2", { QuantizationInfo(20, 110) })),
69 framework::dataset::make("QuantizationInfoOut", { QuantizationInfo(15, 125) }));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010070} // namespace
71
72TEST_SUITE(NEON)
73TEST_SUITE(ArithmeticSubtraction)
74
Georgios Pinitascbf39c62018-09-10 15:07:45 +010075template <typename T>
76using NEArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>;
77
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000078// *INDENT-OFF*
79// clang-format off
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000080DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Georgios Pinitascbf39c62018-09-10 15:07:45 +010081 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000086 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::QASYMM8), // Mismatching types
87 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Invalid convert policy
Georgios Pinitascbf39c62018-09-10 15:07:45 +010088 }),
89 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
92 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
93 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000094 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
95 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
Georgios Pinitascbf39c62018-09-10 15:07:45 +010096 })),
97 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
98 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
99 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
100 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
101 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000102 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100103 })),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000104 framework::dataset::make("ConvertPolicy",{ ConvertPolicy::WRAP,
105 ConvertPolicy::SATURATE,
106 ConvertPolicy::WRAP,
107 ConvertPolicy::SATURATE,
108 ConvertPolicy::WRAP,
109 ConvertPolicy::WRAP,
110 })),
111 framework::dataset::make("Expected", { true, true, false, false, false, false, false})),
112 input1_info, input2_info, output_info, policy, expected)
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000113{
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000114 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 +0000115}
116// clang-format on
117// *INDENT-ON*
118
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100119TEST_SUITE(U8)
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000120DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100121 shape, policy)
122{
123 // Create tensors
124 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8);
125 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8);
126 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
127
128 // Create and Configure function
129 NEArithmeticSubtraction sub;
130 sub.configure(&ref_src1, &ref_src2, &dst, policy);
131
132 // Validate valid region
133 const ValidRegion valid_region = shape_to_valid_region(shape);
134 validate(dst.info()->valid_region(), valid_region);
135
136 // Validate padding
137 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
138 validate(ref_src1.info()->padding(), padding);
139 validate(ref_src2.info()->padding(), padding);
140 validate(dst.info()->padding(), padding);
141}
142
143FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset),
144 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
145{
146 // Validate output
147 validate(Accessor(_target), _reference);
148}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100149TEST_SUITE_END() // U8
Isabella Gottardib5908c22017-10-30 15:28:13 +0000150
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000151using NEArithmeticSubtractionQuantFixture = ArithmeticSubtractionQuantValidationFixture<Tensor, Accessor, NEArithmeticSubtraction>;
152
153TEST_SUITE(Quantized)
154TEST_SUITE(QASYMM8)
155DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
156 shape, policy)
157{
158 // Create tensors
159 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8);
160 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8);
161 Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8);
162
163 // Create and Configure function
164 NEArithmeticSubtraction sub;
165 sub.configure(&ref_src1, &ref_src2, &dst, policy);
166
167 // Validate valid region
168 const ValidRegion valid_region = shape_to_valid_region(shape);
169 validate(dst.info()->valid_region(), valid_region);
170
171 // Validate padding
172 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
173 validate(ref_src1.info()->padding(), padding);
174 validate(ref_src2.info()->padding(), padding);
175 validate(dst.info()->padding(), padding);
176}
177
178FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionQuantFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
179 datasets::SmallShapes(),
180 ArithmeticSubtractionQASYMM8Dataset),
181 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
182 ArithmeticSubtractionQuantizationInfoDataset))
183{
184 // Validate output
185 validate(Accessor(_target), _reference);
186}
187TEST_SUITE_END() // QASYMM8
188TEST_SUITE_END() // Quantized
189
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100190TEST_SUITE(S16)
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000191DATA_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 +0100192 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100193 shape, data_type, policy)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100194{
195 // Create tensors
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100196 Tensor ref_src1 = create_tensor<Tensor>(shape, data_type);
197 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100198 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
199
200 // Create and Configure function
201 NEArithmeticSubtraction sub;
202 sub.configure(&ref_src1, &ref_src2, &dst, policy);
203
204 // Validate valid region
205 const ValidRegion valid_region = shape_to_valid_region(shape);
206 validate(dst.info()->valid_region(), valid_region);
207
208 // Validate padding
209 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
210 validate(ref_src1.info()->padding(), padding);
211 validate(ref_src2.info()->padding(), padding);
212 validate(dst.info()->padding(), padding);
213}
214
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100215FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
216 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100217{
218 // Validate output
219 validate(Accessor(_target), _reference);
220}
221
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100222FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), 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}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100228TEST_SUITE_END() // S16
Isabella Gottardib5908c22017-10-30 15:28:13 +0000229
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100230TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000231#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100232TEST_SUITE(F16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100233FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
234 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100235{
236 // Validate output
237 validate(Accessor(_target), _reference);
238}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100239TEST_SUITE_END() // F16
240#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100241
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100242TEST_SUITE(F32)
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000243DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100244 shape, policy)
245{
246 // Create tensors
247 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32);
248 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32);
249 Tensor dst = create_tensor<Tensor>(shape, DataType::F32);
250
251 // Create and Configure function
252 NEArithmeticSubtraction sub;
253 sub.configure(&ref_src1, &ref_src2, &dst, policy);
254
255 // Validate valid region
256 const ValidRegion valid_region = shape_to_valid_region(shape);
257 validate(dst.info()->valid_region(), valid_region);
258
259 // Validate padding
260 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
261 validate(ref_src1.info()->padding(), padding);
262 validate(ref_src2.info()->padding(), padding);
263 validate(dst.info()->padding(), padding);
264}
265
266FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
267 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
268{
269 // Validate output
270 validate(Accessor(_target), _reference);
271}
272
273FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
274 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
275{
276 // Validate output
277 validate(Accessor(_target), _reference);
278}
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100279
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100280template <typename T>
281using NEArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>;
282
283FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
284 ArithmeticSubtractionFP32Dataset),
285 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
286{
287 // Validate output
288 validate(Accessor(_target), _reference);
289}
290
291FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
292 ArithmeticSubtractionFP32Dataset),
293 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
294{
295 // Validate output
296 validate(Accessor(_target), _reference);
297}
298TEST_SUITE_END() // F32
299TEST_SUITE_END() // Float
300
301TEST_SUITE_END() // ArithmeticSubtraction
302TEST_SUITE_END() // NEON
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100303} // namespace validation
304} // namespace test
305} // namespace arm_compute