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 | { |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 41 | const float scale_255 = 1.f / 255.f; |
| 42 | |
| 43 | // *INDENT-OFF* |
| 44 | // clang-format off |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 45 | #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] | 46 | |
| 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 | |
| 77 | template <typename T> |
| 78 | using CLPixelWiseMultiplicationToF16Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, half_float::half>; |
| 79 | template <typename T> |
| 80 | using CLPixelWiseMultiplicationToF32Fixture = PixelWiseMultiplicationValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>; |
| 81 | template <typename T> |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 82 | using CLPixelWiseMultiplicationBroadcastFixture = PixelWiseMultiplicationBroadcastValidationFixture<CLTensor, CLAccessor, CLPixelWiseMultiplication, T, float>; |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 83 | |
| 84 | TEST_SUITE(CL) |
| 85 | TEST_SUITE(PixelWiseMultiplication) |
| 86 | |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 87 | // *INDENT-OFF* |
| 88 | // clang-format off |
| 89 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 90 | 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 Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 96 | }), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 97 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 98 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 99 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 100 | 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 Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 103 | })), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 104 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 105 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 106 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 107 | 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 Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 110 | })), |
Vidhya Sudhan Loganathan | 0fc2545 | 2018-06-18 14:40:56 +0100 | [diff] [blame^] | 111 | 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 Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 113 | input1_info, input2_info, output_info, scale, expected) |
| 114 | { |
Giorgio Arena | 7062382 | 2017-11-27 15:50:10 +0000 | [diff] [blame] | 115 | 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] | 116 | ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); |
| 117 | } |
| 118 | // clang-format on |
| 119 | // *INDENT-ON* |
| 120 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 121 | TEST_SUITE(F16toF16) |
| 122 | |
| 123 | TEST_SUITE(Scale255) |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 124 | 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] | 125 | TEST_SUITE_END() // Scale255 |
| 126 | |
| 127 | TEST_SUITE_END() // F16toF16 |
| 128 | |
| 129 | TEST_SUITE(F32toF32) |
| 130 | |
| 131 | TEST_SUITE(Scale255) |
John Richardson | 9c450cc | 2017-11-22 12:00:41 +0000 | [diff] [blame] | 132 | 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] | 133 | TEST_SUITE_END() // Scale255 |
| 134 | |
| 135 | TEST_SUITE_END() // F32toF32 |
| 136 | |
| 137 | TEST_SUITE_END() // PixelWiseMultiplication |
| 138 | |
| 139 | TEST_SUITE(FixedPointPixelWiseMultiplication) |
| 140 | |
Michele Di Giorgio | 6259e5f | 2018-01-17 17:29:33 +0000 | [diff] [blame] | 141 | TEST_SUITE(Broadcast) |
| 142 | PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, BroadcastFixture<float>, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) |
| 143 | TEST_SUITE_END() // Broadcast |
| 144 | |
John Richardson | dd715f2 | 2017-09-18 16:10:48 +0100 | [diff] [blame] | 145 | TEST_SUITE_END() // FixedPointPixelWiseMultiplication |
| 146 | TEST_SUITE_END() |
| 147 | } // namespace validation |
| 148 | } // namespace test |
| 149 | } // namespace arm_compute |