blob: c00f95b88553602e9a8e623238e8702cae808d3b [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
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)
101DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
102 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)
136DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
137 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)
174DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
175 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
197FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset))
198{
199 // Validate output
200 validate(CLAccessor(_target), _reference);
201}
202
203FIXTURE_DATA_TEST_CASE(RunLarge, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseSquaredDiffS16Dataset))
204{
205 // Validate output
206 validate(CLAccessor(_target), _reference);
207}
208TEST_SUITE_END()
209
210TEST_SUITE(Float)
211TEST_SUITE(FP16)
212FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset))
213{
214 // Validate output
215 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
216}
217TEST_SUITE_END()
218
219TEST_SUITE(FP32)
220DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
221 shape)
222{
223 // Create tensors
224 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
225 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
226 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
227
228 // Create and Configure function
229 CLElementwiseSquaredDiff add;
230 add.configure(&ref_src1, &ref_src2, &dst);
231
232 // Validate valid region
233 const ValidRegion valid_region = shape_to_valid_region(shape);
234 validate(dst.info()->valid_region(), valid_region);
235
236 // Validate padding
237 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
238 validate(ref_src1.info()->padding(), padding);
239 validate(ref_src2.info()->padding(), padding);
240 validate(dst.info()->padding(), padding);
241}
242
243FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset))
244{
245 // Validate output
246 validate(CLAccessor(_target), _reference, tolerance_fp32);
247}
248
249FIXTURE_DATA_TEST_CASE(RunLarge, CLElementwiseSquaredDiffFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseSquaredDiffFP32Dataset))
250{
251 // Validate output
252 validate(CLAccessor(_target), _reference, tolerance_fp32);
253}
254
255template <typename T>
256using CLElementwiseSquaredDiffBroadcastFixture = ElementwiseSquaredDiffBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
257
258FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapesBroadcast(),
259 ElementwiseSquaredDiffFP32Dataset))
260{
261 // Validate output
262 validate(CLAccessor(_target), _reference, tolerance_fp32);
263}
264
265FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLElementwiseSquaredDiffBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(),
266 ElementwiseSquaredDiffFP32Dataset))
267{
268 // Validate output
269 validate(CLAccessor(_target), _reference, tolerance_fp32);
270}
271TEST_SUITE_END()
272TEST_SUITE_END()
273
274TEST_SUITE_END()
275TEST_SUITE_END()
276} // namespace validation
277} // namespace test
278} // namespace arm_compute