blob: 9323ed293462c11e7931ecbb95f2c202c4c6b93c [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));
Sanghoon Lee70f82912017-08-24 14:21:24 +010051const auto ArithmeticAdditionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
52 framework::dataset::make("DataType", DataType::F16));
53const auto ArithmeticAdditionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
54 framework::dataset::make("DataType", DataType::F32));
55} // namespace
56
57TEST_SUITE(CL)
58TEST_SUITE(ArithmeticAddition)
59
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000060// *INDENT-OFF*
61// clang-format off
62DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000063 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
64 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
65 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
66 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
67 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000068 }),
Giorgio Arena70623822017-11-27 15:50:10 +000069 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000071 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000072 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
73 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000074 })),
Giorgio Arena70623822017-11-27 15:50:10 +000075 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
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::U8),
79 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000080 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010081 framework::dataset::make("Expected", { true, true, false, false, false})),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000082 input1_info, input2_info, output_info, expected)
83{
Giorgio Arena70623822017-11-27 15:50:10 +000084 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 +000085}
86// clang-format on
87// *INDENT-ON*
88
Sanghoon Lee70f82912017-08-24 14:21:24 +010089template <typename T>
90using CLArithmeticAdditionFixture = ArithmeticAdditionValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
91
92TEST_SUITE(U8)
93DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
94 shape, policy)
95{
96 // Create tensors
97 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
98 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
99 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
100
101 // Create and Configure function
102 CLArithmeticAddition add;
103 add.configure(&ref_src1, &ref_src2, &dst, policy);
104
105 // Validate valid region
106 const ValidRegion valid_region = shape_to_valid_region(shape);
107 validate(dst.info()->valid_region(), valid_region);
108
109 // Validate padding
110 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
111 validate(ref_src1.info()->padding(), padding);
112 validate(ref_src2.info()->padding(), padding);
113 validate(dst.info()->padding(), padding);
114}
115
116FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionU8Dataset),
117 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
118{
119 // Validate output
120 validate(CLAccessor(_target), _reference);
121}
122TEST_SUITE_END()
123
124TEST_SUITE(S16)
125DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
126 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
127 shape, data_type, policy)
128{
129 // Create tensors
130 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
131 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
132 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
133
134 // Create and Configure function
135 CLArithmeticAddition add;
136 add.configure(&ref_src1, &ref_src2, &dst, policy);
137
138 // Validate valid region
139 const ValidRegion valid_region = shape_to_valid_region(shape);
140 validate(dst.info()->valid_region(), valid_region);
141
142 // Validate padding
143 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
144 validate(ref_src1.info()->padding(), padding);
145 validate(ref_src2.info()->padding(), padding);
146 validate(dst.info()->padding(), padding);
147}
148
149FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionS16Dataset),
150 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
151{
152 // Validate output
153 validate(CLAccessor(_target), _reference);
154}
155
156FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionS16Dataset),
157 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
158{
159 // Validate output
160 validate(CLAccessor(_target), _reference);
161}
162TEST_SUITE_END()
163
164template <typename T>
165using CLArithmeticAdditionFixedPointFixture = ArithmeticAdditionValidationFixedPointFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
166
Sanghoon Lee70f82912017-08-24 14:21:24 +0100167TEST_SUITE(Float)
168TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100169FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticAdditionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP16Dataset),
170 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee70f82912017-08-24 14:21:24 +0100171{
172 // Validate output
173 validate(CLAccessor(_target), _reference);
174}
175TEST_SUITE_END()
176
177TEST_SUITE(FP32)
178DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
179 shape, policy)
180{
181 // Create tensors
182 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
183 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
184 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
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(), 16).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, CLArithmeticAdditionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticAdditionFP32Dataset),
202 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
203{
204 // Validate output
205 validate(CLAccessor(_target), _reference);
206}
207
208FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticAdditionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticAdditionFP32Dataset),
209 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
210{
211 // Validate output
212 validate(CLAccessor(_target), _reference);
213}
Diego Lopez Recas0021d752017-12-18 14:42:56 +0000214
215template <typename T>
216using CLArithmeticAdditionBroadcastFixture = ArithmeticAdditionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticAddition, T>;
217
218FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
219 ArithmeticAdditionFP32Dataset),
220 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
221{
222 // Validate output
223 validate(CLAccessor(_target), _reference);
224}
225
226FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticAdditionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
227 ArithmeticAdditionFP32Dataset),
228 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
229{
230 // Validate output
231 validate(CLAccessor(_target), _reference);
232}
Sanghoon Lee70f82912017-08-24 14:21:24 +0100233TEST_SUITE_END()
234TEST_SUITE_END()
235
236TEST_SUITE_END()
237TEST_SUITE_END()
238} // namespace validation
239} // namespace test
240} // namespace arm_compute