John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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; |
| 44 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 45 | } //namespace |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 46 | // *INDENT-OFF* |
| 47 | // clang-format off |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 48 | #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] | 49 | |
| 50 | #define PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, SHAPES, DT1, DT2, SCALE, RP, VALIDATE) \ |
| 51 | FIXTURE_DATA_TEST_CASE(TEST_NAME, CLPixelWiseMultiplication##FIXTURE, framework::DatasetMode::MODE, \ |
| 52 | combine(combine(combine(combine(combine( \ |
| 53 | datasets::SHAPES, \ |
| 54 | framework::dataset::make("DataType1", DataType::DT1)), \ |
| 55 | framework::dataset::make("DataType2", DataType::DT2)), \ |
| 56 | framework::dataset::make("Scale", std::move(SCALE))), \ |
| 57 | datasets::ConvertPolicies()), \ |
| 58 | framework::dataset::make("RoundingPolicy", RoundingPolicy::RP))) \ |
| 59 | { \ |
| 60 | VALIDATE \ |
| 61 | } |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 62 | // clang-format on |
| 63 | // *INDENT-ON* |
| 64 | } // namespace |
| 65 | |
| 66 | template <typename T> |
| 67 | using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, half_float::half>; |
| 68 | template <typename T> |
| 69 | using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>; |
| 70 | template <typename T> |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 71 | using CLPixelWiseMultiplicationBroadcastFixture = PixelWiseMultiplicationBroadcastValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 72 | |
| 73 | TEST_SUITE(CL) |
| 74 | TEST_SUITE(PixelWiseMultiplication) |
| 75 | |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 76 | // *INDENT-OFF* |
| 77 | // clang-format off |
| 78 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 79 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 80 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 81 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid scale |
| 83 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 84 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 85 | }), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 86 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 87 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 88 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 89 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 90 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 91 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 92 | })), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 93 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 94 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 95 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 96 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 97 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 98 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 99 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame] | 100 | framework::dataset::make("Scale",{ 2.f, 2.f, 2.f, -1.f, 1.f, 1.f})), |
| 101 | framework::dataset::make("Expected", { true, true, false, false, false, false})), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 102 | input1_info, input2_info, output_info, scale, expected) |
| 103 | { |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 104 | 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] | 105 | ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); |
| 106 | } |
| 107 | // clang-format on |
| 108 | // *INDENT-ON* |
| 109 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 110 | TEST_SUITE(F16toF16) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 111 | TEST_SUITE(Scale255) |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 112 | 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] | 113 | TEST_SUITE_END() // Scale255 |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 114 | TEST_SUITE_END() // F16toF16 |
| 115 | |
| 116 | TEST_SUITE(F32toF32) |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 117 | TEST_SUITE(Scale255) |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 118 | 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] | 119 | TEST_SUITE_END() // Scale255 |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 120 | TEST_SUITE_END() // F32toF32 |
| 121 | |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 122 | PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, BroadcastFixture<float>, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) |
| 123 | |
| 124 | template <typename T> |
| 125 | using CLPixelWiseMultiplicationQuantizedFixture = PixelWiseMultiplicationValidationQuantizedFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, T>; |
| 126 | |
| 127 | TEST_SUITE(Quantized) |
| 128 | TEST_SUITE(QASYMM8) |
| 129 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(), |
| 130 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 131 | framework::dataset::make("Scale", { 1.f, 2.f })), |
| 132 | framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), |
| 133 | framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)), |
| 134 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 135 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 136 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 137 | { |
| 138 | // Validate output |
| 139 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 140 | } |
| 141 | TEST_SUITE_END() // QASYMM8 |
| 142 | TEST_SUITE_END() // Quantized |
| 143 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 144 | TEST_SUITE_END() // PixelWiseMultiplication |
Georgios Pinitas | bf28a3c | 2018-09-18 14:34:48 +0100 | [diff] [blame] | 145 | TEST_SUITE_END() // CL |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 146 | } // namespace validation |
| 147 | } // namespace test |
| 148 | } // namespace arm_compute |