blob: e9b4b16b0cdabb9bbfc0a06e87de75e3ee47252a [file] [log] [blame]
Sanghoon Lee70f82912017-08-24 14:21:24 +01001/*
Michalis Spyrou80943252019-01-10 17:19:50 +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,
Sanghoon Leea7a5b7b2017-09-14 12:11:03 +010021 * 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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
giuros01164a2722018-11-20 18:34:46 +000027#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
Sanghoon Lee70f82912017-08-24 14:21:24 +010028#include "tests/CL/CLAccessor.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{
giuros01164a2722018-11-20 18:34:46 +000046constexpr unsigned int num_elems_processed_per_iteration = 16;
Sanghoon Lee70f82912017-08-24 14:21:24 +010047/** Input data sets **/
48const auto ArithmeticAdditionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType",
49 DataType::U8));
Michele Di Giorgio4622ac12018-06-27 16:41:17 +010050const auto ArithmeticAdditionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
51 framework::dataset::make("DataType",
52 DataType::QASYMM8));
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010053const auto ArithmeticAdditionQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)),
54 framework::dataset::make("DataType",
55 DataType::QSYMM16));
Sanghoon Lee70f82912017-08-24 14:21:24 +010056const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
57 framework::dataset::make("DataType", DataType::S16));
Sanghoon Lee70f82912017-08-24 14:21:24 +010058const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
59 framework::dataset::make("DataType", DataType::F16));
60const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
61 framework::dataset::make("DataType", DataType::F32));
62} // namespace
63
64TEST_SUITE(CL)
65TEST_SUITE(ArithmeticAddition)
66
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000067// *INDENT-OFF*
68// clang-format off
69DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000070 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000075 }),
Giorgio Arena70623822017-11-27 15:50:10 +000076 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000078 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000079 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
80 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000081 })),
Giorgio Arena70623822017-11-27 15:50:10 +000082 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000084 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000085 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
86 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000087 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010088 framework::dataset::make("Expected", { true, true, false, false, false})),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000089 input1_info, input2_info, output_info, expected)
90{
Giorgio Arena70623822017-11-27 15:50:10 +000091 ARM_COMPUTE_EXPECT(bool(CLArithmeticAddition::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);
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000092}
93// clang-format on
94// *INDENT-ON*
95
Sanghoon Lee70f82912017-08-24 14:21:24 +010096template <typename T>
97using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
98
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010099TEST_SUITE(Integer)
Sanghoon Lee70f82912017-08-24 14:21:24 +0100100TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000101DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee70f82912017-08-24 14:21:24 +0100102 shape, policy)
103{
104 // Create tensors
105 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
106 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
107 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
108
109 // Create and Configure function
110 CLArithmeticAddition add;
111 add.configure(&ref_src1, &ref_src2, &dst, policy);
112
113 // Validate valid region
114 const ValidRegion valid_region = shape_to_valid_region(shape);
115 validate(dst.info()->valid_region(), valid_region);
116
117 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100118 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee70f82912017-08-24 14:21:24 +0100119 validate(ref_src1.info()->padding(), padding);
120 validate(ref_src2.info()->padding(), padding);
121 validate(dst.info()->padding(), padding);
122}
123
124FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
125 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
126{
127 // Validate output
128 validate(CLAccessor(_target), _reference);
129}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100130TEST_SUITE_END() // U8
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100131
Sanghoon Lee70f82912017-08-24 14:21:24 +0100132TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000133DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Lee70f82912017-08-24 14:21:24 +0100134 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
135 shape, data_type, policy)
136{
137 // Create tensors
138 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
139 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
140 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
141
142 // Create and Configure function
143 CLArithmeticAddition add;
144 add.configure(&ref_src1, &ref_src2, &dst, policy);
145
146 // Validate valid region
147 const ValidRegion valid_region = shape_to_valid_region(shape);
148 validate(dst.info()->valid_region(), valid_region);
149
150 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100151 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee70f82912017-08-24 14:21:24 +0100152 validate(ref_src1.info()->padding(), padding);
153 validate(ref_src2.info()->padding(), padding);
154 validate(dst.info()->padding(), padding);
155}
156
157FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
158 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
159{
160 // Validate output
161 validate(CLAccessor(_target), _reference);
162}
163
164FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
165 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
166{
167 // Validate output
168 validate(CLAccessor(_target), _reference);
169}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100170TEST_SUITE_END() // S16
171TEST_SUITE_END() // Integer
172
173template <typename T>
174using CLArithmeticAdditionQuantizedFixture = ArithmeticAdditionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
175
176TEST_SUITE(Quantized)
177TEST_SUITE(QASYMM8)
178DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
179 shape, policy)
180{
181 // Create tensors
182 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
183 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
184 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
185
186 // Create and Configure function
187 CLArithmeticAddition add;
188 add.configure(&ref_src1, &ref_src2, &dst, policy);
189
190 // Validate valid region
191 const ValidRegion valid_region = shape_to_valid_region(shape);
192 validate(dst.info()->valid_region(), valid_region);
193
194 // Validate padding
195 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
196 validate(ref_src1.info()->padding(), padding);
197 validate(ref_src2.info()->padding(), padding);
198 validate(dst.info()->padding(), padding);
199}
200
201FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
202 ArithmeticAdditionQASYMM8Dataset),
203 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
204 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
205 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
206 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
207{
208 // Validate output
209 validate(CLAccessor(_target), _reference);
210}
211TEST_SUITE_END() // QASYMM8
212TEST_SUITE(QSYMM16)
213DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
214 shape, policy)
215{
216 // Create tensors
217 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
218 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
219 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
220
221 // Create and Configure function
222 CLArithmeticAddition add;
223 add.configure(&ref_src1, &ref_src2, &dst, policy);
224
225 // Validate valid region
226 const ValidRegion valid_region = shape_to_valid_region(shape);
227 validate(dst.info()->valid_region(), valid_region);
228
229 // Validate padding
230 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
231 validate(ref_src1.info()->padding(), padding);
232 validate(ref_src2.info()->padding(), padding);
233 validate(dst.info()->padding(), padding);
234}
235
236FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
237 ArithmeticAdditionQSYMM16Dataset),
238 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
239 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
240 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
241 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
242{
243 // Validate output
244 validate(CLAccessor(_target), _reference);
245}
246TEST_SUITE_END() // QSYMM16
247TEST_SUITE_END() // Quantized
Sanghoon Lee70f82912017-08-24 14:21:24 +0100248
Sanghoon Lee70f82912017-08-24 14:21:24 +0100249TEST_SUITE(Float)
250TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100251FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
252 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100253{
254 // Validate output
255 validate(CLAccessor(_target), _reference);
256}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100257TEST_SUITE_END() // FP16
Sanghoon Lee70f82912017-08-24 14:21:24 +0100258
259TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000260DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee70f82912017-08-24 14:21:24 +0100261 shape, policy)
262{
263 // Create tensors
264 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
265 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
266 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
267
268 // Create and Configure function
269 CLArithmeticAddition add;
270 add.configure(&ref_src1, &ref_src2, &dst, policy);
271
272 // Validate valid region
273 const ValidRegion valid_region = shape_to_valid_region(shape);
274 validate(dst.info()->valid_region(), valid_region);
275
276 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100277 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee70f82912017-08-24 14:21:24 +0100278 validate(ref_src1.info()->padding(), padding);
279 validate(ref_src2.info()->padding(), padding);
280 validate(dst.info()->padding(), padding);
281}
282
283FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
284 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
285{
286 // Validate output
287 validate(CLAccessor(_target), _reference);
288}
289
290FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
291 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
292{
293 // Validate output
294 validate(CLAccessor(_target), _reference);
295}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000296
297template <typename T>
298using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
299
300FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
301 ArithmeticAdditionFP32Dataset),
302 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
303{
304 // Validate output
305 validate(CLAccessor(_target), _reference);
306}
307
308FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
309 ArithmeticAdditionFP32Dataset),
310 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
311{
312 // Validate output
313 validate(CLAccessor(_target), _reference);
314}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100315TEST_SUITE_END() // FP32
316TEST_SUITE_END() // Float
Sanghoon Lee70f82912017-08-24 14:21:24 +0100317
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100318TEST_SUITE_END() // ArithmeticAddition
319TEST_SUITE_END() // CL
Sanghoon Lee70f82912017-08-24 14:21:24 +0100320} // namespace validation
321} // namespace test
322} // namespace arm_compute