blob: e327769397ea11df0147bf24585f94c716f45d34 [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"
27#include "arm_compute/runtime/CL/functions/CLArithmeticAddition.h"
28#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{
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));
Michele Di Giorgio4622ac12018-06-27 16:41:17 +010049const auto ArithmeticAdditionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
50 framework::dataset::make("DataType",
51 DataType::QASYMM8));
Sanghoon Lee70f82912017-08-24 14:21:24 +010052const auto ArithmeticAdditionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
53 framework::dataset::make("DataType", DataType::S16));
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));
56const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
57 framework::dataset::make("DataType", DataType::F32));
58} // namespace
59
60TEST_SUITE(CL)
61TEST_SUITE(ArithmeticAddition)
62
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000063// *INDENT-OFF*
64// clang-format off
65DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000066 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
67 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
68 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
69 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000071 }),
Giorgio Arena70623822017-11-27 15:50:10 +000072 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000074 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000075 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
76 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000077 })),
Giorgio Arena70623822017-11-27 15:50:10 +000078 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000080 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000081 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000083 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010084 framework::dataset::make("Expected", { true, true, false, false, false})),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000085 input1_info, input2_info, output_info, expected)
86{
Giorgio Arena70623822017-11-27 15:50:10 +000087 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 +000088}
89// clang-format on
90// *INDENT-ON*
91
Sanghoon Lee70f82912017-08-24 14:21:24 +010092template <typename T>
93using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
94
95TEST_SUITE(U8)
96DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
97 shape, policy)
98{
99 // Create tensors
100 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
101 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
102 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
103
104 // Create and Configure function
105 CLArithmeticAddition add;
106 add.configure(&ref_src1, &ref_src2, &dst, policy);
107
108 // Validate valid region
109 const ValidRegion valid_region = shape_to_valid_region(shape);
110 validate(dst.info()->valid_region(), valid_region);
111
112 // Validate padding
113 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
114 validate(ref_src1.info()->padding(), padding);
115 validate(ref_src2.info()->padding(), padding);
116 validate(dst.info()->padding(), padding);
117}
118
119FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
120 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
121{
122 // Validate output
123 validate(CLAccessor(_target), _reference);
124}
125TEST_SUITE_END()
126
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100127template <typename T>
128using CLArithmeticAdditionQuantizedFixture = ArithmeticAdditionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
129
130TEST_SUITE(Quantized)
131TEST_SUITE(QASYMM8)
132DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
133 shape, policy)
134{
135 // Create tensors
136 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
137 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
138 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
139
140 // Create and Configure function
141 CLArithmeticAddition add;
142 add.configure(&ref_src1, &ref_src2, &dst, policy);
143
144 // Validate valid region
145 const ValidRegion valid_region = shape_to_valid_region(shape);
146 validate(dst.info()->valid_region(), valid_region);
147
148 // Validate padding
149 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
150 validate(ref_src1.info()->padding(), padding);
151 validate(ref_src2.info()->padding(), padding);
152 validate(dst.info()->padding(), padding);
153}
154
Pablo Tello76259ca2018-07-12 11:14:20 +0100155FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
156 ArithmeticAdditionQASYMM8Dataset),
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100157 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Pablo Tello76259ca2018-07-12 11:14:20 +0100158 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
159 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
160 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
161
162 )
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100163{
164 // Validate output
165 validate(CLAccessor(_target), _reference);
166}
167TEST_SUITE_END()
168TEST_SUITE_END()
169
Sanghoon Lee70f82912017-08-24 14:21:24 +0100170TEST_SUITE(S16)
171DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
172 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
173 shape, data_type, policy)
174{
175 // Create tensors
176 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
177 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
178 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
179
180 // Create and Configure function
181 CLArithmeticAddition add;
182 add.configure(&ref_src1, &ref_src2, &dst, policy);
183
184 // Validate valid region
185 const ValidRegion valid_region = shape_to_valid_region(shape);
186 validate(dst.info()->valid_region(), valid_region);
187
188 // Validate padding
189 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
190 validate(ref_src1.info()->padding(), padding);
191 validate(ref_src2.info()->padding(), padding);
192 validate(dst.info()->padding(), padding);
193}
194
195FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
196 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
197{
198 // Validate output
199 validate(CLAccessor(_target), _reference);
200}
201
202FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
203 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
204{
205 // Validate output
206 validate(CLAccessor(_target), _reference);
207}
208TEST_SUITE_END()
209
Sanghoon Lee70f82912017-08-24 14:21:24 +0100210TEST_SUITE(Float)
211TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100212FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
213 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100214{
215 // Validate output
216 validate(CLAccessor(_target), _reference);
217}
218TEST_SUITE_END()
219
220TEST_SUITE(FP32)
221DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
222 shape, policy)
223{
224 // Create tensors
225 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
226 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
227 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
228
229 // Create and Configure function
230 CLArithmeticAddition add;
231 add.configure(&ref_src1, &ref_src2, &dst, policy);
232
233 // Validate valid region
234 const ValidRegion valid_region = shape_to_valid_region(shape);
235 validate(dst.info()->valid_region(), valid_region);
236
237 // Validate padding
238 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
239 validate(ref_src1.info()->padding(), padding);
240 validate(ref_src2.info()->padding(), padding);
241 validate(dst.info()->padding(), padding);
242}
243
244FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
245 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
246{
247 // Validate output
248 validate(CLAccessor(_target), _reference);
249}
250
251FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
252 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
253{
254 // Validate output
255 validate(CLAccessor(_target), _reference);
256}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000257
258template <typename T>
259using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
260
261FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
262 ArithmeticAdditionFP32Dataset),
263 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
264{
265 // Validate output
266 validate(CLAccessor(_target), _reference);
267}
268
269FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
270 ArithmeticAdditionFP32Dataset),
271 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
272{
273 // Validate output
274 validate(CLAccessor(_target), _reference);
275}
Sanghoon Lee70f82912017-08-24 14:21:24 +0100276TEST_SUITE_END()
277TEST_SUITE_END()
278
279TEST_SUITE_END()
280TEST_SUITE_END()
281} // namespace validation
282} // namespace test
283} // namespace arm_compute