blob: 0a4ab6627baa3f405af7bbd9efcf76ca09a418e1 [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
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));
giuros01164a2722018-11-20 18:34:46 +000060const auto ElementwiseSquaredDiffS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
61 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});
giuros01164a2722018-11-20 18:34:46 +000073} // namespace
74
75TEST_SUITE(CL)
76TEST_SUITE(ElementwiseSquaredDiff)
77
78// *INDENT-OFF*
79// clang-format off
80DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
81 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
giuros01164a2722018-11-20 18:34:46 +000083 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
85 }),
86 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
87 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 })),
91 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
92 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
giuros01164a2722018-11-20 18:34:46 +000093 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
94 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
95 })),
Manuel Bottinied2a8ed2020-10-07 17:17:16 +010096 framework::dataset::make("Expected", { true, true, false, false})),
giuros01164a2722018-11-20 18:34:46 +000097 input1_info, input2_info, output_info, expected)
98{
99 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);
100}
101// clang-format on
102// *INDENT-ON*
103
104template <typename T>
105using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
106
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100107TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000108TEST_SUITE(U8)
giuros01164a2722018-11-20 18:34:46 +0000109FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset))
110{
111 // Validate output
112 validate(CLAccessor(_target), _reference);
113}
114TEST_SUITE_END()
115
giuros01164a2722018-11-20 18:34:46 +0000116TEST_SUITE(S16)
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000117FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000118{
119 // Validate output
120 validate(CLAccessor(_target), _reference);
121}
122TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100123TEST_SUITE_END()
124
125template <typename T>
126using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
127
128TEST_SUITE(Quantized)
129TEST_SUITE(QASYMM8)
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100130FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
131 ElementwiseSquaredDiffQASYMM8Dataset),
132 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
133 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
134 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
135{
136 // Validate output
137 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
138}
139TEST_SUITE_END()
140TEST_SUITE(QSYMM16)
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100141FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
142 ElementwiseSquaredDiffQSYMM16Dataset),
143 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
144 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
145 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
146{
147 // Validate output
148 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
149}
150TEST_SUITE_END()
151TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000152
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000153template <typename T>
154using CLElementwiseSquaredDiffFloatFixture = ElementwiseSquaredDiffValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
155
giuros01164a2722018-11-20 18:34:46 +0000156TEST_SUITE(Float)
157TEST_SUITE(FP16)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000158FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset),
159 EmptyActivationFunctionsDataset))
160{
161 // Validate output
162 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
163}
164FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP16Dataset),
165 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000166{
167 // Validate output
168 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
169}
170TEST_SUITE_END()
171
172TEST_SUITE(FP32)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000173FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset),
174 EmptyActivationFunctionsDataset))
175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_fp32);
178}
179FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP32Dataset),
180 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000181{
182 // Validate output
183 validate(CLAccessor(_target), _reference, tolerance_fp32);
184}
giuros01164a2722018-11-20 18:34:46 +0000185template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000186using CLElementwiseSquaredDiffBroadcastFloatFixture = ElementwiseSquaredDiffBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
giuros01164a2722018-11-20 18:34:46 +0000187
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000188FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(),
189 ElementwiseSquaredDiffFP32Dataset),
190 EmptyActivationFunctionsDataset))
191{
192 // Validate output
193 validate(CLAccessor(_target), _reference, tolerance_fp32);
194}
195FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
196 ElementwiseSquaredDiffFP32Dataset),
197 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000198{
199 // Validate output
200 validate(CLAccessor(_target), _reference, tolerance_fp32);
201}
202TEST_SUITE_END()
203TEST_SUITE_END()
204
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100205TEST_SUITE_END() // ElementwiseSquaredDiff
206TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000207} // namespace validation
208} // namespace test
209} // namespace arm_compute