blob: 58eca3fe0b35a0c9d58c78995223f57fa40b1836 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
giuros01164a2722018-11-20 18:34:46 +00003 *
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,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * 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/CLElementwiseOperations.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/ElementwiseOperationsFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_fp32(0.000001f);
47RelativeTolerance<float> tolerance_fp16(0.001f);
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010048AbsoluteTolerance<float> tolerance_qsymm16(1);
giuros01164a2722018-11-20 18:34:46 +000049
50constexpr unsigned int num_elems_processed_per_iteration = 16;
51/** Input data sets **/
52const auto ElementwiseSquaredDiffU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
53 framework::dataset::make("DataType",
54 DataType::U8));
55const auto ElementwiseSquaredDiffQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
56 framework::dataset::make("DataType",
57 DataType::QASYMM8));
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010058const auto ElementwiseSquaredDiffQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)),
59 framework::dataset::make("DataType",
60 DataType::QSYMM16));
giuros01164a2722018-11-20 18:34:46 +000061const auto ElementwiseSquaredDiffS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
62 framework::dataset::make("DataType", DataType::S16));
63const auto ElementwiseSquaredDiffFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
64 framework::dataset::make("DataType", DataType::F16));
65const auto ElementwiseSquaredDiffFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
66 framework::dataset::make("DataType", DataType::F32));
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000067const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
68{ ActivationLayerInfo() });
69const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
70{
71 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
72 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
73});
giuros01164a2722018-11-20 18:34:46 +000074} // namespace
75
76TEST_SUITE(CL)
77TEST_SUITE(ElementwiseSquaredDiff)
78
79// *INDENT-OFF*
80// clang-format off
81DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
82 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
84 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
87 }),
88 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
89 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
92 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
93 })),
94 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
95 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
96 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
97 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
98 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
99 })),
100 framework::dataset::make("Expected", { true, true, false, false, false})),
101 input1_info, input2_info, output_info, expected)
102{
103 ARM_COMPUTE_EXPECT(bool(CLElementwiseSquaredDiff::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
104}
105// clang-format on
106// *INDENT-ON*
107
108template <typename T>
109using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
110
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100111TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000112TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000113DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000114 shape)
115{
116 // Create tensors
117 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
118 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
119 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
120
121 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100122 CLElementwiseSquaredDiff sqdiff;
123 sqdiff.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000124
125 // Validate valid region
126 const ValidRegion valid_region = shape_to_valid_region(shape);
127 validate(dst.info()->valid_region(), valid_region);
128
129 // Validate padding
130 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
131 validate(ref_src1.info()->padding(), padding);
132 validate(ref_src2.info()->padding(), padding);
133 validate(dst.info()->padding(), padding);
134}
135
136FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset))
137{
138 // Validate output
139 validate(CLAccessor(_target), _reference);
140}
141TEST_SUITE_END()
142
giuros01164a2722018-11-20 18:34:46 +0000143TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000144DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000145 shape, data_type)
146{
147 // Create tensors
148 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
149 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
150 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
151
152 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100153 CLElementwiseSquaredDiff sqdiff;
154 sqdiff.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000155
156 // Validate valid region
157 const ValidRegion valid_region = shape_to_valid_region(shape);
158 validate(dst.info()->valid_region(), valid_region);
159
160 // Validate padding
161 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
162 validate(ref_src1.info()->padding(), padding);
163 validate(ref_src2.info()->padding(), padding);
164 validate(dst.info()->padding(), padding);
165}
166
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000167FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000168{
169 // Validate output
170 validate(CLAccessor(_target), _reference);
171}
172TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100173TEST_SUITE_END()
174
175template <typename T>
176using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
177
178TEST_SUITE(Quantized)
179TEST_SUITE(QASYMM8)
180DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
181 shape)
182{
183 // Create tensors
184 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
185 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
186 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
187
188 // Create and Configure function
189 CLElementwiseSquaredDiff sqdiff;
190 sqdiff.configure(&ref_src1, &ref_src2, &dst);
191
192 // Validate valid region
193 const ValidRegion valid_region = shape_to_valid_region(shape);
194 validate(dst.info()->valid_region(), valid_region);
195
196 // Validate padding
197 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
198 validate(ref_src1.info()->padding(), padding);
199 validate(ref_src2.info()->padding(), padding);
200 validate(dst.info()->padding(), padding);
201}
202
203FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
204 ElementwiseSquaredDiffQASYMM8Dataset),
205 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
206 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
207 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
208{
209 // Validate output
210 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
211}
212TEST_SUITE_END()
213TEST_SUITE(QSYMM16)
214DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
215 shape)
216{
217 // Create tensors
218 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
219 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
220 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
221
222 // Create and Configure function
223 CLElementwiseSquaredDiff sqdiff;
224 sqdiff.configure(&ref_src1, &ref_src2, &dst);
225
226 // Validate valid region
227 const ValidRegion valid_region = shape_to_valid_region(shape);
228 validate(dst.info()->valid_region(), valid_region);
229
230 // Validate padding
231 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
232 validate(ref_src1.info()->padding(), padding);
233 validate(ref_src2.info()->padding(), padding);
234 validate(dst.info()->padding(), padding);
235}
236
237FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
238 ElementwiseSquaredDiffQSYMM16Dataset),
239 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
240 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
241 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
242{
243 // Validate output
244 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
245}
246TEST_SUITE_END()
247TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000248
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000249template <typename T>
250using CLElementwiseSquaredDiffFloatFixture = ElementwiseSquaredDiffValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
251
giuros01164a2722018-11-20 18:34:46 +0000252TEST_SUITE(Float)
253TEST_SUITE(FP16)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000254FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset),
255 EmptyActivationFunctionsDataset))
256{
257 // Validate output
258 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
259}
260FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP16Dataset),
261 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000262{
263 // Validate output
264 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
265}
266TEST_SUITE_END()
267
268TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000269DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000270 shape)
271{
272 // Create tensors
273 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
274 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
275 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
276
277 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100278 CLElementwiseSquaredDiff sqdiff;
279 sqdiff.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000280
281 // Validate valid region
282 const ValidRegion valid_region = shape_to_valid_region(shape);
283 validate(dst.info()->valid_region(), valid_region);
284
285 // Validate padding
286 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
287 validate(ref_src1.info()->padding(), padding);
288 validate(ref_src2.info()->padding(), padding);
289 validate(dst.info()->padding(), padding);
290}
291
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000292FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset),
293 EmptyActivationFunctionsDataset))
294{
295 // Validate output
296 validate(CLAccessor(_target), _reference, tolerance_fp32);
297}
298FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP32Dataset),
299 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000300{
301 // Validate output
302 validate(CLAccessor(_target), _reference, tolerance_fp32);
303}
giuros01164a2722018-11-20 18:34:46 +0000304template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000305using CLElementwiseSquaredDiffBroadcastFloatFixture = ElementwiseSquaredDiffBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
giuros01164a2722018-11-20 18:34:46 +0000306
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000307FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(),
308 ElementwiseSquaredDiffFP32Dataset),
309 EmptyActivationFunctionsDataset))
310{
311 // Validate output
312 validate(CLAccessor(_target), _reference, tolerance_fp32);
313}
314FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
315 ElementwiseSquaredDiffFP32Dataset),
316 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000317{
318 // Validate output
319 validate(CLAccessor(_target), _reference, tolerance_fp32);
320}
321TEST_SUITE_END()
322TEST_SUITE_END()
323
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100324TEST_SUITE_END() // ElementwiseSquaredDiff
325TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000326} // namespace validation
327} // namespace test
328} // namespace arm_compute