blob: 79e30c1754847502f37069f8b1d973d68d4537ab [file] [log] [blame]
John Richardsondd715f22017-09-18 16:10:48 +01001/*
2 * Copyright (c) 2017 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/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"
31#include "tests/validation/fixtures/FixedPointPixelWiseMultiplicationFixture.h"
32#include "tests/validation/fixtures/PixelWiseMultiplicationFixture.h"
33
34namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
40namespace
41{
42const float scale_unity = 1.f;
43const float scale_255 = 1.f / 255.f;
44
45// *INDENT-OFF*
46// clang-format off
47#define WRAP_VALIDATE(TYPE, TOLERANCE) validate_wrap(CLAccessor(_target), _reference, AbsoluteTolerance<TYPE>(TOLERANCE), 0.f);
48
49#define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, VALIDATE) \
50 FIXTURE_DATA_TEST_CASE(TEST_NAME, CLPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \
51 combine(combine(combine(combine(combine( \
52 datasets::SHAPES, \
53 framework::dataset::make("DataType1", DataType::DT1)), \
54 framework::dataset::make("DataType2", DataType::DT2)), \
55 framework::dataset::make("Scale", std::move(SCALE))), \
56 datasets::ConvertPolicies()), \
57 framework::dataset::make("RoundingPolicy", RoundingPolicy::RP))) \
58 { \
59 VALIDATE \
60 }
61
62#define FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, FPP_START, FPP_END) \
63 FIXTURE_DATA_TEST_CASE(TEST_NAME, CLFixedPointPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \
64 combine(combine(combine(combine(combine(combine( \
65 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()), \
70 framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), \
71 framework::dataset::make("FixedPointPosition", FPP_START, FPP_END))) \
72 { \
73 validate(CLAccessor(_target), _reference); \
74 }
75// clang-format on
76// *INDENT-ON*
77} // namespace
78
79template <typename T>
80using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, half_float::half>;
81template <typename T>
82using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>;
83template <typename T>
84using CLPixelWiseMultiplicationToQS8Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, qint8_t>;
85template <typename T>
86using CLPixelWiseMultiplicationToQS16Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, qint16_t>;
87template <typename T>
88using CLFixedPointPixelWiseMultiplicationFixture = FixedPointPixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T>;
89
90TEST_SUITE(CL)
91TEST_SUITE(PixelWiseMultiplication)
92
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000093// *INDENT-OFF*
94// clang-format off
95DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000096 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
97 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
98 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
99 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid scale
100 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
101 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
102 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2), // Mismatching data type
103 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2), // Mismatching fixed point
104 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2), // Invalid scale
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000105 }),
Giorgio Arena70623822017-11-27 15:50:10 +0000106 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
107 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000108 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +0000109 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
110 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
111 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
112 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS16, 2),
113 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
114 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000115 })),
Giorgio Arena70623822017-11-27 15:50:10 +0000116 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
117 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000118 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +0000119 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
120 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
121 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
122 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
123 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
124 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000125 })),
Giorgio Arena70623822017-11-27 15:50:10 +0000126 framework::dataset::make("Scale",{ 2.f, 2.f, 2.f, -1.f, 1.f, 1.f, 1.f, 1.f, 3.f})),
127 framework::dataset::make("Expected", { false, false, true, true, true, true, true, true, true })),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000128 input1_info, input2_info, output_info, scale, expected)
129{
Giorgio Arena70623822017-11-27 15:50:10 +0000130 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 +0000131 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
132}
133// clang-format on
134// *INDENT-ON*
135
John Richardsondd715f22017-09-18 16:10:48 +0100136TEST_SUITE(F16toF16)
137
138TEST_SUITE(Scale255)
139PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF16Fixture<half_float::half>, PRECOMMIT, SmallShapes(), F16, F16, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f))
140TEST_SUITE_END() // Scale255
141
142TEST_SUITE_END() // F16toF16
143
144TEST_SUITE(F32toF32)
145
146TEST_SUITE(Scale255)
147PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture<float>, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, WRAP_VALIDATE(float, 1.f))
148TEST_SUITE_END() // Scale255
149
150TEST_SUITE_END() // F32toF32
151
152TEST_SUITE_END() // PixelWiseMultiplication
153
154TEST_SUITE(FixedPointPixelWiseMultiplication)
155
156TEST_SUITE(QS8)
157
158TEST_SUITE(ScaleUnity)
159FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture<qint8_t>, PRECOMMIT, SmallShapes(), QS8, QS8, scale_unity, TO_ZERO, 1, 7)
160TEST_SUITE_END() // ScaleUnity
161
162TEST_SUITE_END() // QS8
163
164TEST_SUITE(QS16)
165
166TEST_SUITE(ScaleUnity)
167FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, Fixture<qint16_t>, PRECOMMIT, SmallShapes(), QS16, QS16, scale_unity, TO_ZERO, 1, 15)
168TEST_SUITE_END() // ScaleUnity
169
170TEST_SUITE_END() // QS16
171
172TEST_SUITE_END() // FixedPointPixelWiseMultiplication
173TEST_SUITE_END()
174} // namespace validation
175} // namespace test
176} // namespace arm_compute