blob: 3c734f68ec20c1850dc495af1bdc1873d83b37de [file] [log] [blame]
Sanghoon Lee70f82912017-08-24 14:21:24 +01001/*
Georgios Pinitas5a594532018-12-03 14:30:05 +00002 * Copyright (c) 2017-2019 ARM Limited.
Sanghoon Lee70f82912017-08-24 14:21:24 +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,
Georgios Pinitas5a594532018-12-03 14:30:05 +000021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Sanghoon Lee70f82912017-08-24 14:21:24 +010022 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/NEON/functions/NEArithmeticAddition.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 Lee70f82912017-08-24 14:21:24 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Georgios Pinitasa84faff2018-12-05 18:17:24 +000046constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
47
Sanghoon Lee70f82912017-08-24 14:21:24 +010048/** Input data sets **/
49const auto ArithmeticAdditionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType",
50 DataType::U8));
51const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
52 framework::dataset::make("DataType", DataType::S16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000053#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Sanghoon Lee70f82912017-08-24 14:21:24 +010054const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
55 framework::dataset::make("DataType", DataType::F16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000056#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee70f82912017-08-24 14:21:24 +010057const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
58 framework::dataset::make("DataType", DataType::F32));
Georgios Pinitasa84faff2018-12-05 18:17:24 +000059const auto ArithmeticAdditionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
60 framework::dataset::make("DataType", DataType::QASYMM8));
Sanghoon Lee70f82912017-08-24 14:21:24 +010061} // namespace
62
63TEST_SUITE(NEON)
64TEST_SUITE(ArithmeticAddition)
65
66template <typename T>
67using NEArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<Tensor, Accessor, NEArithmeticAddition, T>;
68
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000069// *INDENT-OFF*
70// clang-format off
71DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
72 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitas5a594532018-12-03 14:30:05 +000074 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Unsupported broadcast
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),// Mismatching shapes
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000077 }),
78 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitas5a594532018-12-03 14:30:05 +000080 TensorInfo(TensorShape(1U, 13U, 2U), 1, DataType::S16),
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000081 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
82 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000083 })),
84 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitas5a594532018-12-03 14:30:05 +000086 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S16),
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000087 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
88 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000089 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010090 framework::dataset::make("Expected", { true, true, false, false, false})),
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000091 input1_info, input2_info, output_info, expected)
92{
Georgios Pinitas5a594532018-12-03 14:30:05 +000093 Status s = NEArithmeticAddition::validate(&input1_info.clone()->set_is_resizable(false),
94 &input2_info.clone()->set_is_resizable(false),
95 &output_info.clone()->set_is_resizable(false),
96 ConvertPolicy::WRAP);
97 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
Ioan-Cristian Szabo397d58a2017-11-30 15:19:11 +000098}
99// clang-format on
100// *INDENT-ON*
101
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000102TEST_SUITE(Integer)
Sanghoon Lee70f82912017-08-24 14:21:24 +0100103TEST_SUITE(U8)
104DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
105 shape, policy)
106{
107 // Create tensors
108 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8);
109 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8);
110 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
111
112 // Create and Configure function
113 NEArithmeticAddition add;
114 add.configure(&ref_src1, &ref_src2, &dst, policy);
115
116 // Validate valid region
117 const ValidRegion valid_region = shape_to_valid_region(shape);
118 validate(dst.info()->valid_region(), valid_region);
119
120 // Validate padding
Georgios Pinitas5a594532018-12-03 14:30:05 +0000121 validate(ref_src1.info()->padding(), PaddingSize());
122 validate(ref_src2.info()->padding(), PaddingSize());
123 validate(dst.info()->padding(), PaddingSize());
Sanghoon Lee70f82912017-08-24 14:21:24 +0100124}
125
126FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
127 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
128{
129 // Validate output
130 validate(Accessor(_target), _reference);
131}
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000132TEST_SUITE_END() // U8
Sanghoon Lee70f82912017-08-24 14:21:24 +0100133
134TEST_SUITE(S16)
135DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
136 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
137 shape, data_type, policy)
138{
139 // Create tensors
140 Tensor ref_src1 = create_tensor<Tensor>(shape, data_type);
141 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16);
142 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
143
144 // Create and Configure function
145 NEArithmeticAddition add;
146 add.configure(&ref_src1, &ref_src2, &dst, policy);
147
148 // Validate valid region
149 const ValidRegion valid_region = shape_to_valid_region(shape);
150 validate(dst.info()->valid_region(), valid_region);
151
152 // Validate padding
Georgios Pinitas5a594532018-12-03 14:30:05 +0000153 validate(ref_src1.info()->padding(), PaddingSize());
154 validate(ref_src2.info()->padding(), PaddingSize());
155 validate(dst.info()->padding(), PaddingSize());
Sanghoon Lee70f82912017-08-24 14:21:24 +0100156}
157
158FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
159 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
160{
161 // Validate output
162 validate(Accessor(_target), _reference);
163}
164
165FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
166 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
167{
168 // Validate output
169 validate(Accessor(_target), _reference);
170}
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000171TEST_SUITE_END() // S16
172TEST_SUITE_END() // Integer
Sanghoon Lee70f82912017-08-24 14:21:24 +0100173
Sanghoon Lee70f82912017-08-24 14:21:24 +0100174TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000175#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Sanghoon Lee70f82912017-08-24 14:21:24 +0100176TEST_SUITE(F16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100177FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
178 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100179{
180 // Validate output
181 validate(Accessor(_target), _reference);
182}
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000183TEST_SUITE_END() // F16
184#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee70f82912017-08-24 14:21:24 +0100185
186TEST_SUITE(F32)
187DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
188 shape, policy)
189{
190 // Create tensors
191 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32);
192 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32);
193 Tensor dst = create_tensor<Tensor>(shape, DataType::F32);
194
195 // Create and Configure function
196 NEArithmeticAddition add;
197 add.configure(&ref_src1, &ref_src2, &dst, policy);
198
199 // Validate valid region
200 const ValidRegion valid_region = shape_to_valid_region(shape);
201 validate(dst.info()->valid_region(), valid_region);
202
203 // Validate padding
Georgios Pinitas5a594532018-12-03 14:30:05 +0000204 validate(ref_src1.info()->padding(), PaddingSize());
205 validate(ref_src2.info()->padding(), PaddingSize());
206 validate(dst.info()->padding(), PaddingSize());
Sanghoon Lee70f82912017-08-24 14:21:24 +0100207}
208
209FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
210 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
211{
212 // Validate output
213 validate(Accessor(_target), _reference);
214}
215
216FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
217 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
218{
219 // Validate output
220 validate(Accessor(_target), _reference);
221}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000222
223template <typename T>
224using NEArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<Tensor, Accessor, NEArithmeticAddition, T>;
225
226FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
227 ArithmeticAdditionFP32Dataset),
228 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
229{
230 // Validate output
231 validate(Accessor(_target), _reference);
232}
233
234FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
235 ArithmeticAdditionFP32Dataset),
236 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
237{
238 // Validate output
239 validate(Accessor(_target), _reference);
240}
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000241TEST_SUITE_END() // F32
242TEST_SUITE_END() // Float
Sanghoon Lee70f82912017-08-24 14:21:24 +0100243
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000244template <typename T>
245using NEArithmeticAdditionQuantizedFixture = ArithmeticAdditionValidationQuantizedFixture<Tensor, Accessor, NEArithmeticAddition, T>;
246
247TEST_SUITE(Quantized)
248TEST_SUITE(QASYMM8)
249DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
250 shape, policy)
251{
252 // Create tensors
253 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8);
254 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8);
255 Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8);
256
257 // Create and Configure function
258 NEArithmeticAddition add;
259 add.configure(&ref_src1, &ref_src2, &dst, policy);
260
261 // Validate valid region
262 const ValidRegion valid_region = shape_to_valid_region(shape);
263 validate(dst.info()->valid_region(), valid_region);
264
265 // Validate padding
Georgios Pinitas5a594532018-12-03 14:30:05 +0000266 validate(ref_src1.info()->padding(), PaddingSize());
267 validate(ref_src2.info()->padding(), PaddingSize());
268 validate(dst.info()->padding(), PaddingSize());
Georgios Pinitasa84faff2018-12-05 18:17:24 +0000269}
270
271FIXTURE_DATA_TEST_CASE(RunSmall,
272 NEArithmeticAdditionQuantizedFixture<uint8_t>,
273 framework::DatasetMode::PRECOMMIT,
274 combine(combine(combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQASYMM8Dataset),
275 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
276 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
277 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
278 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })))
279{
280 // Validate output
281 validate(Accessor(_target), _reference, tolerance_qasymm8);
282}
283TEST_SUITE_END() // QASYMM8
284TEST_SUITE_END() // Quantized
285
286TEST_SUITE_END() // ArithmeticAddition
287TEST_SUITE_END() // NEON
Sanghoon Lee70f82912017-08-24 14:21:24 +0100288} // namespace validation
289} // namespace test
290} // namespace arm_compute