blob: 4c19670d503e56608c82c2d0a1eb06fb15f6eb8a [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));
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));
55const 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
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2), // Mismatching fixed point
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000074 }),
Giorgio Arena70623822017-11-27 15:50:10 +000075 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000077 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000078 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
79 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
81 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000082 })),
Giorgio Arena70623822017-11-27 15:50:10 +000083 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000085 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000086 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
87 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
88 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
89 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000090 })),
Georgios Pinitas631c41a2017-12-06 11:53:03 +000091 framework::dataset::make("Expected", { true, true, false, false, false, false, true })),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000092 input1_info, input2_info, output_info, expected)
93{
Giorgio Arena70623822017-11-27 15:50:10 +000094 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 +000095}
96// clang-format on
97// *INDENT-ON*
98
Sanghoon Lee70f82912017-08-24 14:21:24 +010099template <typename T>
100using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
101
102TEST_SUITE(U8)
103DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
104 shape, policy)
105{
106 // Create tensors
107 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
108 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
109 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
110
111 // Create and Configure function
112 CLArithmeticAddition add;
113 add.configure(&ref_src1, &ref_src2, &dst, policy);
114
115 // Validate valid region
116 const ValidRegion valid_region = shape_to_valid_region(shape);
117 validate(dst.info()->valid_region(), valid_region);
118
119 // Validate padding
120 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
121 validate(ref_src1.info()->padding(), padding);
122 validate(ref_src2.info()->padding(), padding);
123 validate(dst.info()->padding(), padding);
124}
125
126FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
127 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
128{
129 // Validate output
130 validate(CLAccessor(_target), _reference);
131}
132TEST_SUITE_END()
133
134TEST_SUITE(S16)
135DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
136 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
137 shape, data_type, policy)
138{
139 // Create tensors
140 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
141 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
142 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
143
144 // Create and Configure function
145 CLArithmeticAddition add;
146 add.configure(&ref_src1, &ref_src2, &dst, policy);
147
148 // Validate valid region
149 const ValidRegion valid_region = shape_to_valid_region(shape);
150 validate(dst.info()->valid_region(), valid_region);
151
152 // Validate padding
153 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
154 validate(ref_src1.info()->padding(), padding);
155 validate(ref_src2.info()->padding(), padding);
156 validate(dst.info()->padding(), padding);
157}
158
159FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
160 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
161{
162 // Validate output
163 validate(CLAccessor(_target), _reference);
164}
165
166FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
167 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
168{
169 // Validate output
170 validate(CLAccessor(_target), _reference);
171}
172TEST_SUITE_END()
173
174template <typename T>
175using CLArithmeticAdditionFixedPointFixture = ArithmeticAdditionValidationFixedPointFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
176
177TEST_SUITE(Quantized)
178TEST_SUITE(QS8)
179FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQS8Dataset),
180 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
181 framework::dataset::make("FractionalBits", 1, 7)))
182{
183 // Validate output
184 validate(CLAccessor(_target), _reference);
185}
186
187FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticAdditionQS8Dataset),
188 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
189 framework::dataset::make("FractionalBits", 1, 7)))
190{
191 // Validate output
192 validate(CLAccessor(_target), _reference);
193}
194TEST_SUITE_END()
195
196TEST_SUITE(QS16)
197FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticAdditionQS16Dataset),
198 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
199 framework::dataset::make("FractionalBits", 1, 15)))
200{
201 // Validate output
202 validate(CLAccessor(_target), _reference);
203}
204
205FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticAdditionQS16Dataset),
206 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
207 framework::dataset::make("FractionalBits", 1, 15)))
208{
209 // Validate output
210 validate(CLAccessor(_target), _reference);
211}
212TEST_SUITE_END()
213TEST_SUITE_END()
214
215TEST_SUITE(Float)
216TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100217FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
218 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100219{
220 // Validate output
221 validate(CLAccessor(_target), _reference);
222}
223TEST_SUITE_END()
224
225TEST_SUITE(FP32)
226DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
227 shape, policy)
228{
229 // Create tensors
230 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
231 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
232 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
233
234 // Create and Configure function
235 CLArithmeticAddition add;
236 add.configure(&ref_src1, &ref_src2, &dst, policy);
237
238 // Validate valid region
239 const ValidRegion valid_region = shape_to_valid_region(shape);
240 validate(dst.info()->valid_region(), valid_region);
241
242 // Validate padding
243 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
244 validate(ref_src1.info()->padding(), padding);
245 validate(ref_src2.info()->padding(), padding);
246 validate(dst.info()->padding(), padding);
247}
248
249FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
250 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
251{
252 // Validate output
253 validate(CLAccessor(_target), _reference);
254}
255
256FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
257 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
258{
259 // Validate output
260 validate(CLAccessor(_target), _reference);
261}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000262
263template <typename T>
264using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
265
266FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
267 ArithmeticAdditionFP32Dataset),
268 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
269{
270 // Validate output
271 validate(CLAccessor(_target), _reference);
272}
273
274FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
275 ArithmeticAdditionFP32Dataset),
276 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
277{
278 // Validate output
279 validate(CLAccessor(_target), _reference);
280}
Sanghoon Lee70f82912017-08-24 14:21:24 +0100281TEST_SUITE_END()
282TEST_SUITE_END()
283
284TEST_SUITE_END()
285TEST_SUITE_END()
286} // namespace validation
287} // namespace test
288} // namespace arm_compute