blob: ee0279df337bb4d9cb5ed8e96c3fd3b612ad088f [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Georgios Pinitasda816752021-07-02 09:22:14 +01002 * Copyright (c) 2018-2021 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
giuros01164a2722018-11-20 18:34:46 +000050/** 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));
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010057const auto ElementwiseSquaredDiffQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)),
58 framework::dataset::make("DataType",
59 DataType::QSYMM16));
Georgios Pinitasda816752021-07-02 09:22:14 +010060const auto ElementwiseSquaredDiffS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
giuros01164a2722018-11-20 18:34:46 +000061 framework::dataset::make("DataType", DataType::S16));
62const auto ElementwiseSquaredDiffFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
63 framework::dataset::make("DataType", DataType::F16));
64const auto ElementwiseSquaredDiffFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
65 framework::dataset::make("DataType", DataType::F32));
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000066const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
67{ ActivationLayerInfo() });
68const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
69{
70 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
71 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
72});
Sheri Zhanga387e272021-06-29 17:34:06 +010073const auto InPlaceDataSet = framework::dataset::make("InPlace", { false, true });
74const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false });
giuros01164a2722018-11-20 18:34:46 +000075} // namespace
76
77TEST_SUITE(CL)
78TEST_SUITE(ElementwiseSquaredDiff)
79
80// *INDENT-OFF*
81// clang-format off
82DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
83 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
giuros01164a2722018-11-20 18:34:46 +000084 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
86 }),
87 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
giuros01164a2722018-11-20 18:34:46 +000088 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
89 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
90 })),
Georgios Pinitasda816752021-07-02 09:22:14 +010091 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
giuros01164a2722018-11-20 18:34:46 +000092 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
93 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
94 })),
Georgios Pinitasda816752021-07-02 09:22:14 +010095 framework::dataset::make("Expected", { true, false, false})),
giuros01164a2722018-11-20 18:34:46 +000096 input1_info, input2_info, output_info, expected)
97{
98 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);
99}
100// clang-format on
101// *INDENT-ON*
102
103template <typename T>
104using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
105
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100106TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000107TEST_SUITE(U8)
Sheri Zhanga387e272021-06-29 17:34:06 +0100108FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset),
109 OutOfPlaceDataSet))
giuros01164a2722018-11-20 18:34:46 +0000110{
111 // Validate output
112 validate(CLAccessor(_target), _reference);
113}
114TEST_SUITE_END()
115
giuros01164a2722018-11-20 18:34:46 +0000116TEST_SUITE(S16)
Sheri Zhanga387e272021-06-29 17:34:06 +0100117FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset),
118 OutOfPlaceDataSet))
giuros01164a2722018-11-20 18:34:46 +0000119{
120 // Validate output
121 validate(CLAccessor(_target), _reference);
122}
123TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100124TEST_SUITE_END()
125
126template <typename T>
127using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
128
129TEST_SUITE(Quantized)
130TEST_SUITE(QASYMM8)
Sheri Zhanga387e272021-06-29 17:34:06 +0100131FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100132 ElementwiseSquaredDiffQASYMM8Dataset),
133 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
134 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
Sheri Zhanga387e272021-06-29 17:34:06 +0100135 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })),
136 OutOfPlaceDataSet))
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100137{
138 // Validate output
139 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
140}
141TEST_SUITE_END()
142TEST_SUITE(QSYMM16)
Sheri Zhanga387e272021-06-29 17:34:06 +0100143FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100144 ElementwiseSquaredDiffQSYMM16Dataset),
145 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
146 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
Sheri Zhanga387e272021-06-29 17:34:06 +0100147 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })),
148 OutOfPlaceDataSet))
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100149{
150 // Validate output
151 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
152}
153TEST_SUITE_END()
154TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000155
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000156template <typename T>
157using CLElementwiseSquaredDiffFloatFixture = ElementwiseSquaredDiffValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
158
giuros01164a2722018-11-20 18:34:46 +0000159TEST_SUITE(Float)
160TEST_SUITE(FP16)
Sheri Zhanga387e272021-06-29 17:34:06 +0100161FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset),
162 EmptyActivationFunctionsDataset),
163 OutOfPlaceDataSet))
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000164{
165 // Validate output
166 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
167}
Sheri Zhanga387e272021-06-29 17:34:06 +0100168FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP16Dataset),
169 ActivationFunctionsDataset),
170 OutOfPlaceDataSet))
giuros01164a2722018-11-20 18:34:46 +0000171{
172 // Validate output
173 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
174}
175TEST_SUITE_END()
176
177TEST_SUITE(FP32)
Sheri Zhanga387e272021-06-29 17:34:06 +0100178FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset),
179 EmptyActivationFunctionsDataset),
180 OutOfPlaceDataSet))
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000181{
182 // Validate output
183 validate(CLAccessor(_target), _reference, tolerance_fp32);
184}
Sheri Zhanga387e272021-06-29 17:34:06 +0100185FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP32Dataset),
186 ActivationFunctionsDataset),
187 OutOfPlaceDataSet))
giuros01164a2722018-11-20 18:34:46 +0000188{
189 // Validate output
190 validate(CLAccessor(_target), _reference, tolerance_fp32);
191}
giuros01164a2722018-11-20 18:34:46 +0000192template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000193using CLElementwiseSquaredDiffBroadcastFloatFixture = ElementwiseSquaredDiffBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
giuros01164a2722018-11-20 18:34:46 +0000194
Sheri Zhanga387e272021-06-29 17:34:06 +0100195FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapesBroadcast(),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000196 ElementwiseSquaredDiffFP32Dataset),
Sheri Zhanga387e272021-06-29 17:34:06 +0100197 EmptyActivationFunctionsDataset),
198 OutOfPlaceDataSet))
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000199{
200 // Validate output
201 validate(CLAccessor(_target), _reference, tolerance_fp32);
202}
Sheri Zhanga387e272021-06-29 17:34:06 +0100203FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapesBroadcast(),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000204 ElementwiseSquaredDiffFP32Dataset),
Sheri Zhanga387e272021-06-29 17:34:06 +0100205 ActivationFunctionsDataset),
206 OutOfPlaceDataSet))
giuros01164a2722018-11-20 18:34:46 +0000207{
208 // Validate output
209 validate(CLAccessor(_target), _reference, tolerance_fp32);
210}
211TEST_SUITE_END()
212TEST_SUITE_END()
213
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100214TEST_SUITE_END() // ElementwiseSquaredDiff
215TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000216} // namespace validation
217} // namespace test
218} // namespace arm_compute