blob: 35fecf127c191c54c4436dfd6b0f3a1dfd118f10 [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);
48
49constexpr unsigned int num_elems_processed_per_iteration = 16;
50/** Input data sets **/
51const auto ElementwiseSquaredDiffU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
52 framework::dataset::make("DataType",
53 DataType::U8));
54const auto ElementwiseSquaredDiffQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
55 framework::dataset::make("DataType",
56 DataType::QASYMM8));
57const auto ElementwiseSquaredDiffS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
58 framework::dataset::make("DataType", DataType::S16));
59const auto ElementwiseSquaredDiffFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
60 framework::dataset::make("DataType", DataType::F16));
61const auto ElementwiseSquaredDiffFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
62 framework::dataset::make("DataType", DataType::F32));
63} // namespace
64
65TEST_SUITE(CL)
66TEST_SUITE(ElementwiseSquaredDiff)
67
68// *INDENT-OFF*
69// clang-format off
70DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
71 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
73 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
76 }),
77 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
79 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
81 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
82 })),
83 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
85 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
87 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
88 })),
89 framework::dataset::make("Expected", { true, true, false, false, false})),
90 input1_info, input2_info, output_info, expected)
91{
92 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);
93}
94// clang-format on
95// *INDENT-ON*
96
97template <typename T>
98using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
99
100TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000101DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000102 shape)
103{
104 // Create tensors
105 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
106 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
107 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
108
109 // Create and Configure function
110 CLElementwiseSquaredDiff add;
111 add.configure(&ref_src1, &ref_src2, &dst);
112
113 // Validate valid region
114 const ValidRegion valid_region = shape_to_valid_region(shape);
115 validate(dst.info()->valid_region(), valid_region);
116
117 // Validate padding
118 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
119 validate(ref_src1.info()->padding(), padding);
120 validate(ref_src2.info()->padding(), padding);
121 validate(dst.info()->padding(), padding);
122}
123
124FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset))
125{
126 // Validate output
127 validate(CLAccessor(_target), _reference);
128}
129TEST_SUITE_END()
130
131template <typename T>
132using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
133
134TEST_SUITE(Quantized)
135TEST_SUITE(QASYMM8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000136DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000137 shape)
138{
139 // Create tensors
140 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
141 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
142 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
143
144 // Create and Configure function
145 CLElementwiseSquaredDiff add;
146 add.configure(&ref_src1, &ref_src2, &dst);
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(), num_elems_processed_per_iteration).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, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
160 ElementwiseSquaredDiffQASYMM8Dataset),
161 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
162 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
163 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
164
165 )
166{
167 // Validate output
168 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
169}
170TEST_SUITE_END()
171TEST_SUITE_END()
172
173TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000174DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000175 shape, data_type)
176{
177 // Create tensors
178 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
179 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
180 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
181
182 // Create and Configure function
183 CLElementwiseSquaredDiff add;
184 add.configure(&ref_src1, &ref_src2, &dst);
185
186 // Validate valid region
187 const ValidRegion valid_region = shape_to_valid_region(shape);
188 validate(dst.info()->valid_region(), valid_region);
189
190 // Validate padding
191 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
192 validate(ref_src1.info()->padding(), padding);
193 validate(ref_src2.info()->padding(), padding);
194 validate(dst.info()->padding(), padding);
195}
196
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000197FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000198{
199 // Validate output
200 validate(CLAccessor(_target), _reference);
201}
202TEST_SUITE_END()
203
204TEST_SUITE(Float)
205TEST_SUITE(FP16)
206FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset))
207{
208 // Validate output
209 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
210}
211TEST_SUITE_END()
212
213TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000214DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000215 shape)
216{
217 // Create tensors
218 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
219 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
220 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
221
222 // Create and Configure function
223 CLElementwiseSquaredDiff add;
224 add.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
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000237FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000238{
239 // Validate output
240 validate(CLAccessor(_target), _reference, tolerance_fp32);
241}
giuros01164a2722018-11-20 18:34:46 +0000242template <typename T>
243using CLElementwiseSquaredDiffBroadcastFixture = ElementwiseSquaredDiffBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
244
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000245FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
giuros01164a2722018-11-20 18:34:46 +0000246 ElementwiseSquaredDiffFP32Dataset))
247{
248 // Validate output
249 validate(CLAccessor(_target), _reference, tolerance_fp32);
250}
251TEST_SUITE_END()
252TEST_SUITE_END()
253
254TEST_SUITE_END()
255TEST_SUITE_END()
256} // namespace validation
257} // namespace test
258} // namespace arm_compute