blob: edc150109ece9e1b6eef145ffe5199ff6e6a31f4 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2018-2019 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));
67} // namespace
68
69TEST_SUITE(CL)
70TEST_SUITE(ElementwiseSquaredDiff)
71
72// *INDENT-OFF*
73// clang-format off
74DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
75 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
77 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
80 }),
81 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
85 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
86 })),
87 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
88 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
89 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
92 })),
93 framework::dataset::make("Expected", { true, true, false, false, false})),
94 input1_info, input2_info, output_info, expected)
95{
96 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);
97}
98// clang-format on
99// *INDENT-ON*
100
101template <typename T>
102using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
103
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100104TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000105TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000106DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000107 shape)
108{
109 // Create tensors
110 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
111 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
112 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
113
114 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100115 CLElementwiseSquaredDiff sqdiff;
116 sqdiff.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000117
118 // Validate valid region
119 const ValidRegion valid_region = shape_to_valid_region(shape);
120 validate(dst.info()->valid_region(), valid_region);
121
122 // Validate padding
123 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
124 validate(ref_src1.info()->padding(), padding);
125 validate(ref_src2.info()->padding(), padding);
126 validate(dst.info()->padding(), padding);
127}
128
129FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset))
130{
131 // Validate output
132 validate(CLAccessor(_target), _reference);
133}
134TEST_SUITE_END()
135
giuros01164a2722018-11-20 18:34:46 +0000136TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000137DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000138 shape, data_type)
139{
140 // Create tensors
141 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
142 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
143 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
144
145 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100146 CLElementwiseSquaredDiff sqdiff;
147 sqdiff.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000148
149 // Validate valid region
150 const ValidRegion valid_region = shape_to_valid_region(shape);
151 validate(dst.info()->valid_region(), valid_region);
152
153 // Validate padding
154 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
155 validate(ref_src1.info()->padding(), padding);
156 validate(ref_src2.info()->padding(), padding);
157 validate(dst.info()->padding(), padding);
158}
159
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000160FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000161{
162 // Validate output
163 validate(CLAccessor(_target), _reference);
164}
165TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100166TEST_SUITE_END()
167
168template <typename T>
169using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
170
171TEST_SUITE(Quantized)
172TEST_SUITE(QASYMM8)
173DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
174 shape)
175{
176 // Create tensors
177 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
178 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
179 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
180
181 // Create and Configure function
182 CLElementwiseSquaredDiff sqdiff;
183 sqdiff.configure(&ref_src1, &ref_src2, &dst);
184
185 // Validate valid region
186 const ValidRegion valid_region = shape_to_valid_region(shape);
187 validate(dst.info()->valid_region(), valid_region);
188
189 // Validate padding
190 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
191 validate(ref_src1.info()->padding(), padding);
192 validate(ref_src2.info()->padding(), padding);
193 validate(dst.info()->padding(), padding);
194}
195
196FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
197 ElementwiseSquaredDiffQASYMM8Dataset),
198 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
199 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
200 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
201{
202 // Validate output
203 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
204}
205TEST_SUITE_END()
206TEST_SUITE(QSYMM16)
207DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
208 shape)
209{
210 // Create tensors
211 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
212 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
213 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
214
215 // Create and Configure function
216 CLElementwiseSquaredDiff sqdiff;
217 sqdiff.configure(&ref_src1, &ref_src2, &dst);
218
219 // Validate valid region
220 const ValidRegion valid_region = shape_to_valid_region(shape);
221 validate(dst.info()->valid_region(), valid_region);
222
223 // Validate padding
224 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
225 validate(ref_src1.info()->padding(), padding);
226 validate(ref_src2.info()->padding(), padding);
227 validate(dst.info()->padding(), padding);
228}
229
230FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
231 ElementwiseSquaredDiffQSYMM16Dataset),
232 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
233 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
234 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
235{
236 // Validate output
237 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
238}
239TEST_SUITE_END()
240TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000241
242TEST_SUITE(Float)
243TEST_SUITE(FP16)
244FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset))
245{
246 // Validate output
247 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
248}
249TEST_SUITE_END()
250
251TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000252DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000253 shape)
254{
255 // Create tensors
256 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
257 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
258 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
259
260 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100261 CLElementwiseSquaredDiff sqdiff;
262 sqdiff.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000263
264 // Validate valid region
265 const ValidRegion valid_region = shape_to_valid_region(shape);
266 validate(dst.info()->valid_region(), valid_region);
267
268 // Validate padding
269 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
270 validate(ref_src1.info()->padding(), padding);
271 validate(ref_src2.info()->padding(), padding);
272 validate(dst.info()->padding(), padding);
273}
274
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000275FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000276{
277 // Validate output
278 validate(CLAccessor(_target), _reference, tolerance_fp32);
279}
giuros01164a2722018-11-20 18:34:46 +0000280template <typename T>
281using CLElementwiseSquaredDiffBroadcastFixture = ElementwiseSquaredDiffBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
282
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000283FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
giuros01164a2722018-11-20 18:34:46 +0000284 ElementwiseSquaredDiffFP32Dataset))
285{
286 // Validate output
287 validate(CLAccessor(_target), _reference, tolerance_fp32);
288}
289TEST_SUITE_END()
290TEST_SUITE_END()
291
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100292TEST_SUITE_END() // ElementwiseSquaredDiff
293TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000294} // namespace validation
295} // namespace test
296} // namespace arm_compute