blob: f466332e3cd8841ee5d7447473af51107fee9eec [file] [log] [blame]
John Richardsondd715f22017-09-18 16:10:48 +01001/*
Giorgio Arenaada6cbc2021-04-16 17:03:39 +01002 * Copyright (c) 2017-2021 Arm Limited.
John Richardsondd715f22017-09-18 16:10:48 +01003 *
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/runtime/CL/functions/CLPixelWiseMultiplication.h"
25#include "tests/CL/CLAccessor.h"
26#include "tests/PaddingCalculator.h"
27#include "tests/datasets/ConvertPolicyDataset.h"
28#include "tests/datasets/ShapeDatasets.h"
29#include "tests/framework/Macros.h"
30#include "tests/validation/Validation.h"
John Richardsondd715f22017-09-18 16:10:48 +010031#include "tests/validation/fixtures/PixelWiseMultiplicationFixture.h"
32
33namespace arm_compute
34{
35namespace test
36{
37namespace validation
38{
39namespace
40{
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +010041namespace
42{
43const float scale_255 = 1.f / 255.f;
Michele Di Giorgiod8a468f2019-06-19 15:34:41 +010044constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit quantized asymmetric data types */
45constexpr AbsoluteTolerance<float> tolerance_qsymm16(1); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit quantized symmetric data types */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000046const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
47{ ActivationLayerInfo() });
48const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
49{
50 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
51 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
52});
Sang-Hoon Park95a6f722020-06-19 15:31:29 +010053// Since in-place computation on CL-side hasn't been intended to be implemented, they are not tested.
54// However, this dataset is required for the shared fixture and it would make extension easier when
55// CL-side also starts supporting in-place computation.
56const auto InPlaceDataSet = framework::dataset::make("InPlace", { false });
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +010057} //namespace
John Richardsondd715f22017-09-18 16:10:48 +010058// *INDENT-OFF*
59// clang-format off
John Richardson9c450cc2017-11-22 12:00:41 +000060#define VALIDATE(TYPE, TOLERANCE) validate(CLAccessor(_target), _reference, AbsoluteTolerance<TYPE>(TOLERANCE), 0.f);
John Richardsondd715f22017-09-18 16:10:48 +010061
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000062#define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, ACT, VALIDATE) \
John Richardsondd715f22017-09-18 16:10:48 +010063 FIXTURE_DATA_TEST_CASE(TEST_NAME, CLPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \
Sang-Hoon Park95a6f722020-06-19 15:31:29 +010064 combine(combine(combine(combine(combine(combine(combine( \
John Richardsondd715f22017-09-18 16:10:48 +010065 datasets::SHAPES, \
66 framework::dataset::make("DataType1", DataType::DT1)), \
67 framework::dataset::make("DataType2", DataType::DT2)), \
68 framework::dataset::make("Scale", std::move(SCALE))), \
69 datasets::ConvertPolicies()), \
Sang-Hoon Park95a6f722020-06-19 15:31:29 +010070 framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), ACT), \
71 InPlaceDataSet)) \
John Richardsondd715f22017-09-18 16:10:48 +010072 { \
73 VALIDATE \
74 }
John Richardsondd715f22017-09-18 16:10:48 +010075// clang-format on
76// *INDENT-ON*
77} // namespace
78
79template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000080using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFloatFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, half_float::half>;
John Richardsondd715f22017-09-18 16:10:48 +010081template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000082using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFloatFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>;
John Richardsondd715f22017-09-18 16:10:48 +010083template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000084using CLPixelWiseMultiplicationBroadcastFixture = PixelWiseMultiplicationBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>;
John Richardsondd715f22017-09-18 16:10:48 +010085
86TEST_SUITE(CL)
87TEST_SUITE(PixelWiseMultiplication)
88
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000089// *INDENT-OFF*
90// clang-format off
91DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000092 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
93 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000094 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid scale
95 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
96 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000097 }),
Giorgio Arena70623822017-11-27 15:50:10 +000098 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
99 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +0000100 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
101 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
102 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000103 })),
Giorgio Arena70623822017-11-27 15:50:10 +0000104 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
105 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +0000106 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
107 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
108 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000109 })),
Giorgio Arenaada6cbc2021-04-16 17:03:39 +0100110 framework::dataset::make("Scale",{ 2.f, 2.f, -1.f, 1.f, 1.f})),
111 framework::dataset::make("Expected", { true, true, false, false, false})),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000112 input1_info, input2_info, output_info, scale, expected)
113{
Giorgio Arena70623822017-11-27 15:50:10 +0000114 bool has_error = bool(CLPixelWiseMultiplication::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), scale, ConvertPolicy::WRAP, RoundingPolicy::TO_ZERO));
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000115 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
116}
117// clang-format on
118// *INDENT-ON*
119
John Richardsondd715f22017-09-18 16:10:48 +0100120TEST_SUITE(F16toF16)
John Richardsondd715f22017-09-18 16:10:48 +0100121TEST_SUITE(Scale255)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000122PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF16Fixture<half_float::half>, PRECOMMIT, SmallShapes(), F16, F16, scale_255, TO_NEAREST_UP, EmptyActivationFunctionsDataset,
123 VALIDATE(float, 1.f))
124PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunWithActivation, ToF16Fixture<half_float::half>, ALL, TinyShapes(), F16, F16, scale_255, TO_NEAREST_UP, ActivationFunctionsDataset, VALIDATE(float,
125 1.f))
John Richardsondd715f22017-09-18 16:10:48 +0100126TEST_SUITE_END() // Scale255
John Richardsondd715f22017-09-18 16:10:48 +0100127TEST_SUITE_END() // F16toF16
128
129TEST_SUITE(F32toF32)
John Richardsondd715f22017-09-18 16:10:48 +0100130TEST_SUITE(Scale255)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000131PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture<float>, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, EmptyActivationFunctionsDataset, VALIDATE(float, 1.f))
132PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunWithActivation, ToF32Fixture<float>, ALL, TinyShapes(), F32, F32, scale_255, TO_NEAREST_UP, ActivationFunctionsDataset, VALIDATE(float, 1.f))
John Richardsondd715f22017-09-18 16:10:48 +0100133TEST_SUITE_END() // Scale255
John Richardsondd715f22017-09-18 16:10:48 +0100134TEST_SUITE_END() // F32toF32
135
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000136PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, BroadcastFixture<float>, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, EmptyActivationFunctionsDataset,
137 VALIDATE(float, 1.f))
138PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunWithActivationSmallBroadcast, BroadcastFixture<float>, ALL, TinyShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, ActivationFunctionsDataset,
139 VALIDATE(float, 1.f))
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100140
141template <typename T>
Michele Di Giorgio7a0212a2020-04-14 16:08:32 +0100142using CLPixelWiseMultiplicationQuantizedFixture = PixelWiseMultiplicationValidationQuantizedFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, T>;
143using CLPixelWiseMultiplicationQSYMM16ToS32Fxture = PixelWiseMultiplicationValidationQuantizedFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, int16_t, int16_t, int32_t>;
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100144
145TEST_SUITE(Quantized)
146TEST_SUITE(QASYMM8)
Michele Di Giorgio9428a182020-03-30 14:10:20 +0100147FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
Sang-Hoon Park95a6f722020-06-19 15:31:29 +0100148 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(),
149 framework::dataset::make("DataTypeIn1", DataType::QASYMM8)),
150 framework::dataset::make("DataTypeIn2", DataType::QASYMM8)),
151 framework::dataset::make("DataTypeOut", DataType::QASYMM8)),
152 framework::dataset::make("Scale", { 1.f, 2.f })),
153 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
154 framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)),
155 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
156 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
157 framework::dataset::make("OUtQInfo", { QuantizationInfo(1.f / 255.f, 5) })),
158 InPlaceDataSet))
Michele Di Giorgiod8a468f2019-06-19 15:34:41 +0100159{
160 // Validate output
161 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
162}
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000163TEST_SUITE_END() // QASYMM8
164
165TEST_SUITE(QASYMM8_SIGNED)
Michele Di Giorgio9428a182020-03-30 14:10:20 +0100166FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT,
Sang-Hoon Park95a6f722020-06-19 15:31:29 +0100167 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(),
168 framework::dataset::make("DataTypeIn1", DataType::QASYMM8_SIGNED)),
169 framework::dataset::make("DataTypeIn2", DataType::QASYMM8_SIGNED)),
170 framework::dataset::make("DataTypeOut", DataType::QASYMM8_SIGNED)),
171 framework::dataset::make("Scale", { 1.f, 2.f })),
172 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
173 framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)),
174 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
175 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
176 framework::dataset::make("OUtQInfo", { QuantizationInfo(1.f / 255.f, 5) })),
177 InPlaceDataSet))
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
181}
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000182TEST_SUITE_END() // QASYMM8_SIGNED
183
Michele Di Giorgiod8a468f2019-06-19 15:34:41 +0100184TEST_SUITE(QSYMM16)
Michele Di Giorgio9428a182020-03-30 14:10:20 +0100185FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT,
Sang-Hoon Park95a6f722020-06-19 15:31:29 +0100186 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(),
187 framework::dataset::make("DataTypeIn1", DataType::QSYMM16)),
188 framework::dataset::make("DataTypeIn2", DataType::QSYMM16)),
189 framework::dataset::make("DataTypeOut", DataType::QSYMM16)),
190 framework::dataset::make("Scale", { 1.f, 2.f })),
191 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
192 framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)),
193 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0) })),
194 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0) })),
195 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })),
196 InPlaceDataSet))
Michele Di Giorgiod8a468f2019-06-19 15:34:41 +0100197{
198 // Validate output
199 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
200}
Michele Di Giorgio9428a182020-03-30 14:10:20 +0100201FIXTURE_DATA_TEST_CASE(RunLarge, CLPixelWiseMultiplicationQuantizedFixture<int16_t>, framework::DatasetMode::NIGHTLY,
Sang-Hoon Park95a6f722020-06-19 15:31:29 +0100202 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeShapes(),
203 framework::dataset::make("DataTypeIn1", DataType::QSYMM16)),
204 framework::dataset::make("DataTypeIn2", DataType::QSYMM16)),
205 framework::dataset::make("DataTypeOut", DataType::QSYMM16)),
206 framework::dataset::make("Scale", { 1.f, 2.f })),
207 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
208 framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)),
209 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0) })),
210 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0) })),
211 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })),
212 InPlaceDataSet))
Michele Di Giorgiod8a468f2019-06-19 15:34:41 +0100213{
214 // Validate output
215 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
216}
217TEST_SUITE_END() // QSYMM16
Michele Di Giorgio7a0212a2020-04-14 16:08:32 +0100218TEST_SUITE(QSYMM16ToS32)
219FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQSYMM16ToS32Fxture, framework::DatasetMode::ALL,
Sang-Hoon Park95a6f722020-06-19 15:31:29 +0100220 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(),
221 framework::dataset::make("DataTypeIn1", DataType::QSYMM16)),
222 framework::dataset::make("DataTypeIn2", DataType::QSYMM16)),
223 framework::dataset::make("DataTypeOut", DataType::S32)),
224 framework::dataset::make("Scale", { 1.f })),
225 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
226 framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)),
227 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0) })),
228 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0) })),
229 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f, 0) })),
230 InPlaceDataSet))
Michele Di Giorgio7a0212a2020-04-14 16:08:32 +0100231{
232 // Validate output
233 validate(CLAccessor(_target), _reference, tolerance_qsymm16);
234}
235TEST_SUITE_END() // QSYMM16ToS32
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100236TEST_SUITE_END() // Quantized
237
John Richardsondd715f22017-09-18 16:10:48 +0100238TEST_SUITE_END() // PixelWiseMultiplication
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100239TEST_SUITE_END() // CL
John Richardsondd715f22017-09-18 16:10:48 +0100240} // namespace validation
241} // namespace test
242} // namespace arm_compute