blob: 21a8c4b79f8804c805e7601b07f2c87841005325 [file] [log] [blame]
Sanghoon Lee70f82912017-08-24 14:21:24 +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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * 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"
36#include "tests/validation/fixtures/ArithmeticAdditionFixture.h"
Sanghoon Lee70f82912017-08-24 14:21:24 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Input data sets **/
47const auto ArithmeticAdditionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType",
48 DataType::U8));
49const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
50 framework::dataset::make("DataType", DataType::S16));
51const auto ArithmeticAdditionQS8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QS8), framework::dataset::make("DataType", DataType::QS8)),
52 framework::dataset::make("DataType", DataType::QS8));
53const auto ArithmeticAdditionQS16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QS16), framework::dataset::make("DataType", DataType::QS16)),
54 framework::dataset::make("DataType", DataType::QS16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000055#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Sanghoon Lee70f82912017-08-24 14:21:24 +010056const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
57 framework::dataset::make("DataType", DataType::F16));
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000058#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee70f82912017-08-24 14:21:24 +010059const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
60 framework::dataset::make("DataType", DataType::F32));
61} // 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),
74 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2), // Mismatching fixed point
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
79 }),
80 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
81 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
84 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
87 })),
88 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
89 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
92 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
93 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
94 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
95 })),
96 framework::dataset::make("Expected", { false, false, true, true, true, true, false })),
97 input1_info, input2_info, output_info, expected)
98{
99 ARM_COMPUTE_EXPECT(bool(NEArithmeticAddition::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), ConvertPolicy::WRAP)) == expected, framework::LogLevel::ERRORS);
100}
101// clang-format on
102// *INDENT-ON*
103
Sanghoon Lee70f82912017-08-24 14:21:24 +0100104TEST_SUITE(U8)
105DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
106 shape, policy)
107{
108 // Create tensors
109 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::U8);
110 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::U8);
111 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
112
113 // Create and Configure function
114 NEArithmeticAddition add;
115 add.configure(&ref_src1, &ref_src2, &dst, policy);
116
117 // Validate valid region
118 const ValidRegion valid_region = shape_to_valid_region(shape);
119 validate(dst.info()->valid_region(), valid_region);
120
121 // Validate padding
122 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
123 validate(ref_src1.info()->padding(), padding);
124 validate(ref_src2.info()->padding(), padding);
125 validate(dst.info()->padding(), padding);
126}
127
128FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
129 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
130{
131 // Validate output
132 validate(Accessor(_target), _reference);
133}
134TEST_SUITE_END()
135
136TEST_SUITE(S16)
137DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
138 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
139 shape, data_type, policy)
140{
141 // Create tensors
142 Tensor ref_src1 = create_tensor<Tensor>(shape, data_type);
143 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16);
144 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
145
146 // Create and Configure function
147 NEArithmeticAddition add;
148 add.configure(&ref_src1, &ref_src2, &dst, policy);
149
150 // Validate valid region
151 const ValidRegion valid_region = shape_to_valid_region(shape);
152 validate(dst.info()->valid_region(), valid_region);
153
154 // Validate padding
155 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
156 validate(ref_src1.info()->padding(), padding);
157 validate(ref_src2.info()->padding(), padding);
158 validate(dst.info()->padding(), padding);
159}
160
161FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
162 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
163{
164 // Validate output
165 validate(Accessor(_target), _reference);
166}
167
168FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
169 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
170{
171 // Validate output
172 validate(Accessor(_target), _reference);
173}
174TEST_SUITE_END()
175
176template <typename T>
177using NEArithmeticAdditionFixedPointFixture = ArithmeticAdditionValidationFixedPointFixture<Tensor, Accessor, NEArithmeticAddition, T>;
178
179TEST_SUITE(Quantized)
180TEST_SUITE(QS8)
181FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQS8Dataset),
182 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
183 framework::dataset::make("FractionalBits", 1, 7)))
184{
185 // Validate output
186 validate(Accessor(_target), _reference);
187}
188
189FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticAdditionQS8Dataset),
190 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
191 framework::dataset::make("FractionalBits", 1, 7)))
192{
193 // Validate output
194 validate(Accessor(_target), _reference);
195}
196TEST_SUITE_END()
197
198TEST_SUITE(QS16)
199FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQS16Dataset),
200 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
201 framework::dataset::make("FractionalBits", 1, 15)))
202{
203 // Validate output
204 validate(Accessor(_target), _reference);
205}
206
207FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticAdditionQS16Dataset),
208 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
209 framework::dataset::make("FractionalBits", 1, 15)))
210{
211 // Validate output
212 validate(Accessor(_target), _reference);
213}
214TEST_SUITE_END()
215TEST_SUITE_END()
216
217TEST_SUITE(Float)
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000218#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Sanghoon Lee70f82912017-08-24 14:21:24 +0100219TEST_SUITE(F16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100220FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
221 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100222{
223 // Validate output
224 validate(Accessor(_target), _reference);
225}
226TEST_SUITE_END()
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000227#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Sanghoon Lee70f82912017-08-24 14:21:24 +0100228
229TEST_SUITE(F32)
230DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
231 shape, policy)
232{
233 // Create tensors
234 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32);
235 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32);
236 Tensor dst = create_tensor<Tensor>(shape, DataType::F32);
237
238 // Create and Configure function
239 NEArithmeticAddition add;
240 add.configure(&ref_src1, &ref_src2, &dst, policy);
241
242 // Validate valid region
243 const ValidRegion valid_region = shape_to_valid_region(shape);
244 validate(dst.info()->valid_region(), valid_region);
245
246 // Validate padding
247 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
248 validate(ref_src1.info()->padding(), padding);
249 validate(ref_src2.info()->padding(), padding);
250 validate(dst.info()->padding(), padding);
251}
252
253FIXTURE_DATA_TEST_CASE(RunSmall, NEArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
254 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
255{
256 // Validate output
257 validate(Accessor(_target), _reference);
258}
259
260FIXTURE_DATA_TEST_CASE(RunLarge, NEArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
261 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
262{
263 // Validate output
264 validate(Accessor(_target), _reference);
265}
266TEST_SUITE_END()
267TEST_SUITE_END()
268
269TEST_SUITE_END()
270TEST_SUITE_END()
271} // namespace validation
272} // namespace test
273} // namespace arm_compute