blob: 6f7aa94521b722cd7b6b0869c745dbfb5320dbc0 [file] [log] [blame]
Sanghoon Lee70f82912017-08-24 14:21:24 +01001/*
Diego Lopez Recas0021d752017-12-18 14:42:56 +00002 * Copyright (c) 2017-2018 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));
Sanghoon Lee70f82912017-08-24 14:21:24 +010053const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
54 framework::dataset::make("DataType", DataType::S16));
Sanghoon Lee70f82912017-08-24 14:21:24 +010055const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
56 framework::dataset::make("DataType", DataType::F16));
57const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
58 framework::dataset::make("DataType", DataType::F32));
59} // namespace
60
61TEST_SUITE(CL)
62TEST_SUITE(ArithmeticAddition)
63
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000064// *INDENT-OFF*
65// clang-format off
66DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000067 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
69 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000072 }),
Giorgio Arena70623822017-11-27 15:50:10 +000073 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000075 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000076 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
77 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000078 })),
Giorgio Arena70623822017-11-27 15:50:10 +000079 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000081 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000082 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000084 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010085 framework::dataset::make("Expected", { true, true, false, false, false})),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000086 input1_info, input2_info, output_info, expected)
87{
Giorgio Arena70623822017-11-27 15:50:10 +000088 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 +000089}
90// clang-format on
91// *INDENT-ON*
92
Sanghoon Lee70f82912017-08-24 14:21:24 +010093template <typename T>
94using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
95
96TEST_SUITE(U8)
97DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
98 shape, policy)
99{
100 // Create tensors
101 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
102 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
103 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
104
105 // Create and Configure function
106 CLArithmeticAddition add;
107 add.configure(&ref_src1, &ref_src2, &dst, policy);
108
109 // Validate valid region
110 const ValidRegion valid_region = shape_to_valid_region(shape);
111 validate(dst.info()->valid_region(), valid_region);
112
113 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100114 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee70f82912017-08-24 14:21:24 +0100115 validate(ref_src1.info()->padding(), padding);
116 validate(ref_src2.info()->padding(), padding);
117 validate(dst.info()->padding(), padding);
118}
119
120FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
121 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
122{
123 // Validate output
124 validate(CLAccessor(_target), _reference);
125}
126TEST_SUITE_END()
127
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100128template <typename T>
129using CLArithmeticAdditionQuantizedFixture = ArithmeticAdditionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
130
131TEST_SUITE(Quantized)
132TEST_SUITE(QASYMM8)
133DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
134 shape, policy)
135{
136 // Create tensors
137 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
138 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
139 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
140
141 // Create and Configure function
142 CLArithmeticAddition add;
143 add.configure(&ref_src1, &ref_src2, &dst, policy);
144
145 // Validate valid region
146 const ValidRegion valid_region = shape_to_valid_region(shape);
147 validate(dst.info()->valid_region(), valid_region);
148
149 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100150 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100151 validate(ref_src1.info()->padding(), padding);
152 validate(ref_src2.info()->padding(), padding);
153 validate(dst.info()->padding(), padding);
154}
155
Pablo Tello76259ca2018-07-12 11:14:20 +0100156FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
157 ArithmeticAdditionQASYMM8Dataset),
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100158 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Pablo Tello76259ca2018-07-12 11:14:20 +0100159 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
160 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
161 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
162
163 )
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100164{
165 // Validate output
166 validate(CLAccessor(_target), _reference);
167}
168TEST_SUITE_END()
169TEST_SUITE_END()
170
Sanghoon Lee70f82912017-08-24 14:21:24 +0100171TEST_SUITE(S16)
172DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
173 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
174 shape, data_type, policy)
175{
176 // Create tensors
177 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
178 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
179 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
180
181 // Create and Configure function
182 CLArithmeticAddition add;
183 add.configure(&ref_src1, &ref_src2, &dst, policy);
184
185 // Validate valid region
186 const ValidRegion valid_region = shape_to_valid_region(shape);
187 validate(dst.info()->valid_region(), valid_region);
188
189 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100190 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee70f82912017-08-24 14:21:24 +0100191 validate(ref_src1.info()->padding(), padding);
192 validate(ref_src2.info()->padding(), padding);
193 validate(dst.info()->padding(), padding);
194}
195
196FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
197 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
198{
199 // Validate output
200 validate(CLAccessor(_target), _reference);
201}
202
203FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
204 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
205{
206 // Validate output
207 validate(CLAccessor(_target), _reference);
208}
209TEST_SUITE_END()
210
Sanghoon Lee70f82912017-08-24 14:21:24 +0100211TEST_SUITE(Float)
212TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100213FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
214 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100215{
216 // Validate output
217 validate(CLAccessor(_target), _reference);
218}
219TEST_SUITE_END()
220
221TEST_SUITE(FP32)
222DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
223 shape, policy)
224{
225 // Create tensors
226 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
227 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
228 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
229
230 // Create and Configure function
231 CLArithmeticAddition add;
232 add.configure(&ref_src1, &ref_src2, &dst, policy);
233
234 // Validate valid region
235 const ValidRegion valid_region = shape_to_valid_region(shape);
236 validate(dst.info()->valid_region(), valid_region);
237
238 // Validate padding
Michele Di Giorgioa1422fb2018-10-24 12:20:19 +0100239 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee70f82912017-08-24 14:21:24 +0100240 validate(ref_src1.info()->padding(), padding);
241 validate(ref_src2.info()->padding(), padding);
242 validate(dst.info()->padding(), padding);
243}
244
245FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
246 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
247{
248 // Validate output
249 validate(CLAccessor(_target), _reference);
250}
251
252FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
253 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
254{
255 // Validate output
256 validate(CLAccessor(_target), _reference);
257}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000258
259template <typename T>
260using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
261
262FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
263 ArithmeticAdditionFP32Dataset),
264 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
265{
266 // Validate output
267 validate(CLAccessor(_target), _reference);
268}
269
270FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
271 ArithmeticAdditionFP32Dataset),
272 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
273{
274 // Validate output
275 validate(CLAccessor(_target), _reference);
276}
Sanghoon Lee70f82912017-08-24 14:21:24 +0100277TEST_SUITE_END()
278TEST_SUITE_END()
279
280TEST_SUITE_END()
281TEST_SUITE_END()
282} // namespace validation
283} // namespace test
284} // namespace arm_compute