blob: 256d93f7f54a9008cb64c96d729607d48af18928 [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"
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));
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
155FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQASYMM8Dataset),
156 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
157 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
158{
159 // Validate output
160 validate(CLAccessor(_target), _reference);
161}
162TEST_SUITE_END()
163TEST_SUITE_END()
164
Sanghoon Lee70f82912017-08-24 14:21:24 +0100165TEST_SUITE(S16)
166DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
167 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
168 shape, data_type, policy)
169{
170 // Create tensors
171 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
172 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
173 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
174
175 // Create and Configure function
176 CLArithmeticAddition add;
177 add.configure(&ref_src1, &ref_src2, &dst, policy);
178
179 // Validate valid region
180 const ValidRegion valid_region = shape_to_valid_region(shape);
181 validate(dst.info()->valid_region(), valid_region);
182
183 // Validate padding
184 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
185 validate(ref_src1.info()->padding(), padding);
186 validate(ref_src2.info()->padding(), padding);
187 validate(dst.info()->padding(), padding);
188}
189
190FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
191 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
192{
193 // Validate output
194 validate(CLAccessor(_target), _reference);
195}
196
197FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
198 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
199{
200 // Validate output
201 validate(CLAccessor(_target), _reference);
202}
203TEST_SUITE_END()
204
Sanghoon Lee70f82912017-08-24 14:21:24 +0100205TEST_SUITE(Float)
206TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100207FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
208 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100209{
210 // Validate output
211 validate(CLAccessor(_target), _reference);
212}
213TEST_SUITE_END()
214
215TEST_SUITE(FP32)
216DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
217 shape, policy)
218{
219 // Create tensors
220 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
221 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
222 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
223
224 // Create and Configure function
225 CLArithmeticAddition add;
226 add.configure(&ref_src1, &ref_src2, &dst, policy);
227
228 // Validate valid region
229 const ValidRegion valid_region = shape_to_valid_region(shape);
230 validate(dst.info()->valid_region(), valid_region);
231
232 // Validate padding
233 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
234 validate(ref_src1.info()->padding(), padding);
235 validate(ref_src2.info()->padding(), padding);
236 validate(dst.info()->padding(), padding);
237}
238
239FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
240 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
241{
242 // Validate output
243 validate(CLAccessor(_target), _reference);
244}
245
246FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
247 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
248{
249 // Validate output
250 validate(CLAccessor(_target), _reference);
251}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000252
253template <typename T>
254using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
255
256FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
257 ArithmeticAdditionFP32Dataset),
258 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
259{
260 // Validate output
261 validate(CLAccessor(_target), _reference);
262}
263
264FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
265 ArithmeticAdditionFP32Dataset),
266 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
267{
268 // Validate output
269 validate(CLAccessor(_target), _reference);
270}
Sanghoon Lee70f82912017-08-24 14:21:24 +0100271TEST_SUITE_END()
272TEST_SUITE_END()
273
274TEST_SUITE_END()
275TEST_SUITE_END()
276} // namespace validation
277} // namespace test
278} // namespace arm_compute