blob: e5c2c5fd8350f3dc1b2dce86a807a96a951579df [file] [log] [blame]
Sanghoon Lee72898fe2017-09-01 11:42:16 +01001/*
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +00002 * Copyright (c) 2017-2020 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#ifdef __aarch64__
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +000047constexpr AbsoluteTolerance<float> tolerance_qasymm8(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
48#else //__aarch64__
Manuel Bottini8d04fa02019-03-08 14:00:40 +000049constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +000050#endif //__aarch64__
51constexpr AbsoluteTolerance<int16_t> tolerance_qsymm16(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
Manuel Bottini8d04fa02019-03-08 14:00:40 +000052
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
Michalis Spyrou6f58b372019-12-04 12:00:36 +000058const auto ArithmeticSubtractionQASYMM8SIGNEDDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED),
59 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
60 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED));
61
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +000062const auto ArithmeticSubtractionQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16),
63 framework::dataset::make("DataType", DataType::QSYMM16)),
64 framework::dataset::make("DataType", DataType::QSYMM16));
65
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000066const auto ArithmeticSubtractionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8),
67 framework::dataset::make("DataType", DataType::U8)),
68 framework::dataset::make("DataType", DataType::U8));
69
70const auto ArithmeticSubtractionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }),
71 framework::dataset::make("DataType", DataType::S16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010072 framework::dataset::make("DataType", DataType::S16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000073#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000074const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16),
75 framework::dataset::make("DataType", DataType::F16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010076 framework::dataset::make("DataType", DataType::F16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000077#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000078const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32),
79 framework::dataset::make("DataType", DataType::F32)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010080 framework::dataset::make("DataType", DataType::F32));
Manuel Bottini6a2b6e82019-02-25 13:50:11 +000081
82const auto ArithmeticSubtractionQuantizationInfoDataset = combine(combine(framework::dataset::make("QuantizationInfoIn1", { QuantizationInfo(10, 120) }),
83 framework::dataset::make("QuantizationInfoIn2", { QuantizationInfo(20, 110) })),
84 framework::dataset::make("QuantizationInfoOut", { QuantizationInfo(15, 125) }));
Michalis Spyrou6f58b372019-12-04 12:00:36 +000085const auto ArithmeticSubtractionQuantizationInfoSignedDataset = combine(combine(framework::dataset::make("QuantizationInfoIn1", { QuantizationInfo(0.5f, 10) }),
86 framework::dataset::make("QuantizationInfoIn2", { QuantizationInfo(0.5f, 20) })),
87 framework::dataset::make("QuantizationInfoOut", { QuantizationInfo(0.5f, 50) }));
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +000088const auto ArithmeticSubtractionQuantizationInfoSymmetric = combine(combine(framework::dataset::make("QuantizationInfoIn1", { QuantizationInfo(0.3f, 0) }),
89 framework::dataset::make("QuantizationInfoIn2", { QuantizationInfo(0.7f, 0) })),
90 framework::dataset::make("QuantizationInfoOut", { QuantizationInfo(0.2f, 0) }));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010091} // namespace
92
93TEST_SUITE(NEON)
94TEST_SUITE(ArithmeticSubtraction)
95
Georgios Pinitascbf39c62018-09-10 15:07:45 +010096template <typename T>
97using NEArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>;
98
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000099// *INDENT-OFF*
100// clang-format off
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000101DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100102 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
103 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
104 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
105 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
106 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000107 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::QASYMM8), // Mismatching types
108 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Invalid convert policy
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100109 }),
110 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
111 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
112 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
113 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
114 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000115 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
116 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100117 })),
118 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
119 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
120 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
121 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
122 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000123 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100124 })),
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000125 framework::dataset::make("ConvertPolicy",{ ConvertPolicy::WRAP,
126 ConvertPolicy::SATURATE,
127 ConvertPolicy::WRAP,
128 ConvertPolicy::SATURATE,
129 ConvertPolicy::WRAP,
130 ConvertPolicy::WRAP,
131 })),
132 framework::dataset::make("Expected", { true, true, false, false, false, false, false})),
133 input1_info, input2_info, output_info, policy, expected)
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +0000134{
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000135 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 +0000136}
137// clang-format on
138// *INDENT-ON*
139
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100140TEST_SUITE(U8)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100141FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset),
142 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
143{
144 // Validate output
145 validate(Accessor(_target), _reference);
146}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100147TEST_SUITE_END() // U8
Isabella Gottardib5908c22017-10-30 15:28:13 +0000148
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +0000149using NEArithmeticSubtractionQASYMM8Fixture = ArithmeticSubtractionValidationQuantizedFixture<Tensor, Accessor, NEArithmeticSubtraction, uint8_t>;
150using NEArithmeticSubtractionQASYMM8SignedFixture = ArithmeticSubtractionValidationQuantizedFixture<Tensor, Accessor, NEArithmeticSubtraction, int8_t>;
151using NEArithmeticSubtractionQSYMM16Fixture = ArithmeticSubtractionValidationQuantizedFixture<Tensor, Accessor, NEArithmeticSubtraction, int16_t>;
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000152
153TEST_SUITE(Quantized)
154TEST_SUITE(QASYMM8)
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +0000155FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionQASYMM8Fixture, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ArithmeticSubtractionQASYMM8Dataset),
156 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
157 ArithmeticSubtractionQuantizationInfoDataset))
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000158{
159 // Validate output
Manuel Bottini8d04fa02019-03-08 14:00:40 +0000160 validate(Accessor(_target), _reference, tolerance_qasymm8);
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000161}
162TEST_SUITE_END() // QASYMM8
Michalis Spyrou6f58b372019-12-04 12:00:36 +0000163
164TEST_SUITE(QASYMM8_SIGNED)
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +0000165FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionQASYMM8SignedFixture, framework::DatasetMode::ALL, combine(combine(combine(
166 datasets::SmallShapes(),
167 ArithmeticSubtractionQASYMM8SIGNEDDataset),
168 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
169 ArithmeticSubtractionQuantizationInfoSignedDataset))
Michalis Spyrou6f58b372019-12-04 12:00:36 +0000170{
171 // Validate output
172 validate(Accessor(_target), _reference, tolerance_qasymm8);
173}
174TEST_SUITE_END() // QASYMM8_SIGNED
Michele Di Giorgio9f2403f2020-03-27 10:23:44 +0000175
176TEST_SUITE(QSYMM16)
177FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionQSYMM16Fixture, framework::DatasetMode::ALL, combine(combine(combine(
178 datasets::SmallShapes(),
179 ArithmeticSubtractionQSYMM16Dataset),
180 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
181 ArithmeticSubtractionQuantizationInfoSymmetric))
182{
183 // Validate output
184 validate(Accessor(_target), _reference, tolerance_qsymm16);
185}
186TEST_SUITE_END() // QSYMM16
Manuel Bottini6a2b6e82019-02-25 13:50:11 +0000187TEST_SUITE_END() // Quantized
188
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100189TEST_SUITE(S16)
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100190FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
191 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100192{
193 // Validate output
194 validate(Accessor(_target), _reference);
195}
196
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100197FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset),
198 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100199{
200 // Validate output
201 validate(Accessor(_target), _reference);
202}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100203TEST_SUITE_END() // S16
Isabella Gottardib5908c22017-10-30 15:28:13 +0000204
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100205TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000206#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100207TEST_SUITE(F16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100208FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
209 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100210{
211 // Validate output
212 validate(Accessor(_target), _reference);
213}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100214TEST_SUITE_END() // F16
215#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100216
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100217TEST_SUITE(F32)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100218FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
219 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
220{
221 // Validate output
222 validate(Accessor(_target), _reference);
223}
224
225FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
226 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
227{
228 // Validate output
229 validate(Accessor(_target), _reference);
230}
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100231
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100232template <typename T>
233using NEArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticSubtraction, T>;
234
235FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
236 ArithmeticSubtractionFP32Dataset),
237 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
238{
239 // Validate output
240 validate(Accessor(_target), _reference);
241}
242
243FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
244 ArithmeticSubtractionFP32Dataset),
245 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
246{
247 // Validate output
248 validate(Accessor(_target), _reference);
249}
250TEST_SUITE_END() // F32
251TEST_SUITE_END() // Float
252
253TEST_SUITE_END() // ArithmeticSubtraction
254TEST_SUITE_END() // NEON
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100255} // namespace validation
256} // namespace test
257} // namespace arm_compute