John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 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" |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 31 | #include "tests/validation/fixtures/PixelWiseMultiplicationFixture.h" |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace validation |
| 38 | { |
| 39 | namespace |
| 40 | { |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 41 | namespace |
| 42 | { |
| 43 | const float scale_255 = 1.f / 255.f; |
Michele Di Giorgio | d8a468f | 2019-06-19 15:34:41 +0100 | [diff] [blame] | 44 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit quantized asymmetric data types */ |
| 45 | constexpr AbsoluteTolerance<float> tolerance_qsymm16(1); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit quantized symmetric data types */ |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 46 | } //namespace |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 47 | // *INDENT-OFF* |
| 48 | // clang-format off |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 49 | #define VALIDATE(TYPE, TOLERANCE) validate(CLAccessor(_target), _reference, AbsoluteTolerance<TYPE>(TOLERANCE), 0.f); |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 50 | |
| 51 | #define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, VALIDATE) \ |
| 52 | FIXTURE_DATA_TEST_CASE(TEST_NAME, CLPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ |
| 53 | combine(combine(combine(combine(combine( \ |
| 54 | datasets::SHAPES, \ |
| 55 | framework::dataset::make("DataType1", DataType::DT1)), \ |
| 56 | framework::dataset::make("DataType2", DataType::DT2)), \ |
| 57 | framework::dataset::make("Scale", std::move(SCALE))), \ |
| 58 | datasets::ConvertPolicies()), \ |
| 59 | framework::dataset::make("RoundingPolicy", RoundingPolicy::RP))) \ |
| 60 | { \ |
| 61 | VALIDATE \ |
| 62 | } |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 63 | // clang-format on |
| 64 | // *INDENT-ON* |
| 65 | } // namespace |
| 66 | |
| 67 | template <typename T> |
| 68 | using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, half_float::half>; |
| 69 | template <typename T> |
| 70 | using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>; |
| 71 | template <typename T> |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 72 | using CLPixelWiseMultiplicationBroadcastFixture = PixelWiseMultiplicationBroadcastValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 73 | |
| 74 | TEST_SUITE(CL) |
| 75 | TEST_SUITE(PixelWiseMultiplication) |
| 76 | |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 77 | // *INDENT-OFF* |
| 78 | // clang-format off |
| 79 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 80 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 82 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 83 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid scale |
| 84 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 85 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 86 | }), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 87 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 88 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 89 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 90 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 91 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 92 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 93 | })), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 94 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 95 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 96 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 97 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 98 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 99 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 100 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 101 | framework::dataset::make("Scale",{ 2.f, 2.f, 2.f, -1.f, 1.f, 1.f})), |
| 102 | framework::dataset::make("Expected", { true, true, false, false, false, false})), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 103 | input1_info, input2_info, output_info, scale, expected) |
| 104 | { |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 105 | 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 Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 106 | ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); |
| 107 | } |
| 108 | // clang-format on |
| 109 | // *INDENT-ON* |
| 110 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 111 | TEST_SUITE(F16toF16) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 112 | TEST_SUITE(Scale255) |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 113 | PIXEL_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 Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 114 | TEST_SUITE_END() // Scale255 |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 115 | TEST_SUITE_END() // F16toF16 |
| 116 | |
| 117 | TEST_SUITE(F32toF32) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 118 | TEST_SUITE(Scale255) |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 119 | PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture<float>, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 120 | TEST_SUITE_END() // Scale255 |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 121 | TEST_SUITE_END() // F32toF32 |
| 122 | |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 123 | PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, BroadcastFixture<float>, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) |
| 124 | |
| 125 | template <typename T> |
| 126 | using CLPixelWiseMultiplicationQuantizedFixture = PixelWiseMultiplicationValidationQuantizedFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, T>; |
| 127 | |
| 128 | TEST_SUITE(Quantized) |
| 129 | TEST_SUITE(QASYMM8) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame^] | 130 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 131 | combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(), |
| 132 | framework::dataset::make("DataTypeIn1", DataType::QASYMM8)), |
| 133 | framework::dataset::make("DataTypeIn2", DataType::QASYMM8)), |
| 134 | framework::dataset::make("DataTypeOut", DataType::QASYMM8)), |
| 135 | framework::dataset::make("Scale", { 1.f, 2.f })), |
| 136 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })), |
| 137 | framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)), |
| 138 | framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 139 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 140 | framework::dataset::make("OUtQInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
Michele Di Giorgio | d8a468f | 2019-06-19 15:34:41 +0100 | [diff] [blame] | 141 | { |
| 142 | // Validate output |
| 143 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 144 | } |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 145 | TEST_SUITE_END() // QASYMM8 |
| 146 | |
| 147 | TEST_SUITE(QASYMM8_SIGNED) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame^] | 148 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, |
| 149 | combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(), |
| 150 | framework::dataset::make("DataTypeIn1", DataType::QASYMM8_SIGNED)), |
| 151 | framework::dataset::make("DataTypeIn2", DataType::QASYMM8_SIGNED)), |
| 152 | framework::dataset::make("DataTypeOut", DataType::QASYMM8_SIGNED)), |
| 153 | framework::dataset::make("Scale", { 1.f, 2.f })), |
| 154 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })), |
| 155 | framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)), |
| 156 | framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 157 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 158 | framework::dataset::make("OUtQInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 159 | { |
| 160 | // Validate output |
| 161 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 162 | } |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 163 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 164 | |
Michele Di Giorgio | d8a468f | 2019-06-19 15:34:41 +0100 | [diff] [blame] | 165 | TEST_SUITE(QSYMM16) |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame^] | 166 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, |
| 167 | combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(), |
| 168 | framework::dataset::make("DataTypeIn1", DataType::QSYMM16)), |
| 169 | framework::dataset::make("DataTypeIn2", DataType::QSYMM16)), |
| 170 | framework::dataset::make("DataTypeOut", DataType::QSYMM16)), |
| 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(1.f / 32768.f, 0) })), |
| 175 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0) })), |
| 176 | framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) }))) |
Michele Di Giorgio | d8a468f | 2019-06-19 15:34:41 +0100 | [diff] [blame] | 177 | { |
| 178 | // Validate output |
| 179 | validate(CLAccessor(_target), _reference, tolerance_qsymm16); |
| 180 | } |
Michele Di Giorgio | 9428a18 | 2020-03-30 14:10:20 +0100 | [diff] [blame^] | 181 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPixelWiseMultiplicationQuantizedFixture<int16_t>, framework::DatasetMode::NIGHTLY, |
| 182 | combine(combine(combine(combine(combine(combine(combine(combine(combine(datasets::LargeShapes(), |
| 183 | framework::dataset::make("DataTypeIn1", DataType::QSYMM16)), |
| 184 | framework::dataset::make("DataTypeIn2", DataType::QSYMM16)), |
| 185 | framework::dataset::make("DataTypeOut", DataType::QSYMM16)), |
| 186 | framework::dataset::make("Scale", { 1.f, 2.f })), |
| 187 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })), |
| 188 | framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)), |
| 189 | framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0) })), |
| 190 | framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0) })), |
| 191 | framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) }))) |
Michele Di Giorgio | d8a468f | 2019-06-19 15:34:41 +0100 | [diff] [blame] | 192 | { |
| 193 | // Validate output |
| 194 | validate(CLAccessor(_target), _reference, tolerance_qsymm16); |
| 195 | } |
| 196 | TEST_SUITE_END() // QSYMM16 |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 197 | TEST_SUITE_END() // Quantized |
| 198 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 199 | TEST_SUITE_END() // PixelWiseMultiplication |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 200 | TEST_SUITE_END() // CL |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 201 | } // namespace validation |
| 202 | } // namespace test |
| 203 | } // namespace arm_compute |