blob: 99b084f6bc2cfe5e7e7c98adf8d982e59fb7f20b [file] [log] [blame]
John Richardsondd715f22017-09-18 16:10:48 +01001/*
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +00002 * Copyright (c) 2017-2018 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{
John Richardsondd715f22017-09-18 16:10:48 +010041const float scale_255 = 1.f / 255.f;
42
43// *INDENT-OFF*
44// clang-format off
John Richardson9c450cc2017-11-22 12:00:41 +000045#define VALIDATE(TYPE, TOLERANCE) validate(CLAccessor(_target), _reference, AbsoluteTolerance<TYPE>(TOLERANCE), 0.f);
John Richardsondd715f22017-09-18 16:10:48 +010046
47#define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, VALIDATE) \
48 FIXTURE_DATA_TEST_CASE(TEST_NAME, CLPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \
49 combine(combine(combine(combine(combine( \
50 datasets::SHAPES, \
51 framework::dataset::make("DataType1", DataType::DT1)), \
52 framework::dataset::make("DataType2", DataType::DT2)), \
53 framework::dataset::make("Scale", std::move(SCALE))), \
54 datasets::ConvertPolicies()), \
55 framework::dataset::make("RoundingPolicy", RoundingPolicy::RP))) \
56 { \
57 VALIDATE \
58 }
59
60#define FP_PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, FPP_START, FPP_END) \
61 FIXTURE_DATA_TEST_CASE(TEST_NAME, CLFixedPointPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \
62 combine(combine(combine(combine(combine(combine( \
63 datasets::SHAPES, \
64 framework::dataset::make("DataType1", DataType::DT1)), \
65 framework::dataset::make("DataType2", DataType::DT2)), \
66 framework::dataset::make("Scale", std::move(SCALE))), \
67 datasets::ConvertPolicies()), \
68 framework::dataset::make("RoundingPolicy", RoundingPolicy::RP)), \
69 framework::dataset::make("FixedPointPosition", FPP_START, FPP_END))) \
70 { \
71 validate(CLAccessor(_target), _reference); \
72 }
73// clang-format on
74// *INDENT-ON*
75} // namespace
76
77template <typename T>
78using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, half_float::half>;
79template <typename T>
80using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>;
81template <typename T>
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +000082using CLPixelWiseMultiplicationBroadcastFixture = PixelWiseMultiplicationBroadcastValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>;
John Richardsondd715f22017-09-18 16:10:48 +010083
84TEST_SUITE(CL)
85TEST_SUITE(PixelWiseMultiplication)
86
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000087// *INDENT-OFF*
88// clang-format off
89DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000090 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
92 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
93 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid scale
94 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
95 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000096 }),
Giorgio Arena70623822017-11-27 15:50:10 +000097 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
98 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000099 TensorInfo(TensorShape(27U, 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),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000106 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +0000107 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
108 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
109 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000110 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +0100111 framework::dataset::make("Scale",{ 2.f, 2.f, 2.f, -1.f, 1.f, 1.f})),
112 framework::dataset::make("Expected", { true, true, false, false, false, false})),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000113 input1_info, input2_info, output_info, scale, expected)
114{
Giorgio Arena70623822017-11-27 15:50:10 +0000115 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 +0000116 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
117}
118// clang-format on
119// *INDENT-ON*
120
John Richardsondd715f22017-09-18 16:10:48 +0100121TEST_SUITE(F16toF16)
122
123TEST_SUITE(Scale255)
John Richardson9c450cc2017-11-22 12:00:41 +0000124PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF16Fixture<half_float::half>, PRECOMMIT, SmallShapes(), F16, F16, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f))
John Richardsondd715f22017-09-18 16:10:48 +0100125TEST_SUITE_END() // Scale255
126
127TEST_SUITE_END() // F16toF16
128
129TEST_SUITE(F32toF32)
130
131TEST_SUITE(Scale255)
John Richardson9c450cc2017-11-22 12:00:41 +0000132PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture<float>, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f))
John Richardsondd715f22017-09-18 16:10:48 +0100133TEST_SUITE_END() // Scale255
134
135TEST_SUITE_END() // F32toF32
136
137TEST_SUITE_END() // PixelWiseMultiplication
138
139TEST_SUITE(FixedPointPixelWiseMultiplication)
140
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +0000141TEST_SUITE(Broadcast)
142PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, BroadcastFixture<float>, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f))
143TEST_SUITE_END() // Broadcast
144
John Richardsondd715f22017-09-18 16:10:48 +0100145TEST_SUITE_END() // FixedPointPixelWiseMultiplication
146TEST_SUITE_END()
147} // namespace validation
148} // namespace test
149} // namespace arm_compute