blob: bdae81f1f6668ce541c5b3efea6c37d46f15f20e [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),
83 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
84 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),
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::S16),
91 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
92 })),
93 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
94 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
95 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
96 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
97 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
98 })),
99 framework::dataset::make("Expected", { true, true, false, false, false})),
100 input1_info, input2_info, output_info, expected)
101{
102 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);
103}
104// clang-format on
105// *INDENT-ON*
106
107template <typename T>
108using CLElementwiseSquaredDiffFixture = ElementwiseSquaredDiffValidationFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
109
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100110TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000111TEST_SUITE(U8)
giuros01164a2722018-11-20 18:34:46 +0000112FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseSquaredDiffU8Dataset))
113{
114 // Validate output
115 validate(CLAccessor(_target), _reference);
116}
117TEST_SUITE_END()
118
giuros01164a2722018-11-20 18:34:46 +0000119TEST_SUITE(S16)
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000120FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseSquaredDiffS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000121{
122 // Validate output
123 validate(CLAccessor(_target), _reference);
124}
125TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100126TEST_SUITE_END()
127
128template <typename T>
129using CLElementwiseSquaredDiffQuantizedFixture = ElementwiseSquaredDiffValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
130
131TEST_SUITE(Quantized)
132TEST_SUITE(QASYMM8)
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100133FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
134 ElementwiseSquaredDiffQASYMM8Dataset),
135 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
136 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
137 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
138{
139 // Validate output
140 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
141}
142TEST_SUITE_END()
143TEST_SUITE(QSYMM16)
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100144FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
145 ElementwiseSquaredDiffQSYMM16Dataset),
146 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
147 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
148 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
149{
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)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000161FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP16Dataset),
162 EmptyActivationFunctionsDataset))
163{
164 // Validate output
165 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
166}
167FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP16Dataset),
168 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000169{
170 // Validate output
171 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
172}
173TEST_SUITE_END()
174
175TEST_SUITE(FP32)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000176FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseSquaredDiffFP32Dataset),
177 EmptyActivationFunctionsDataset))
178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_fp32);
181}
182FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseSquaredDiffFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseSquaredDiffFP32Dataset),
183 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000184{
185 // Validate output
186 validate(CLAccessor(_target), _reference, tolerance_fp32);
187}
giuros01164a2722018-11-20 18:34:46 +0000188template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000189using CLElementwiseSquaredDiffBroadcastFloatFixture = ElementwiseSquaredDiffBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseSquaredDiff, T>;
giuros01164a2722018-11-20 18:34:46 +0000190
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000191FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(),
192 ElementwiseSquaredDiffFP32Dataset),
193 EmptyActivationFunctionsDataset))
194{
195 // Validate output
196 validate(CLAccessor(_target), _reference, tolerance_fp32);
197}
198FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwiseSquaredDiffBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
199 ElementwiseSquaredDiffFP32Dataset),
200 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000201{
202 // Validate output
203 validate(CLAccessor(_target), _reference, tolerance_fp32);
204}
205TEST_SUITE_END()
206TEST_SUITE_END()
207
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100208TEST_SUITE_END() // ElementwiseSquaredDiff
209TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000210} // namespace validation
211} // namespace test
212} // namespace arm_compute