giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [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, |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEElementwiseOperations.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/datasets/ShapeDatasets.h" |
| 30 | #include "tests/framework/Asserts.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/framework/datasets/Datasets.h" |
| 33 | #include "tests/validation/Validation.h" |
| 34 | #include "tests/validation/fixtures/ElementwiseOperationsFixture.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | namespace |
| 43 | { |
| 44 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 45 | /** Input data sets **/ |
| 46 | const auto ElementwiseMaxQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 47 | framework::dataset::make("DataType", |
| 48 | DataType::QASYMM8)); |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 49 | const auto ElementwiseMaxQASYMM8SignedDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 50 | framework::dataset::make("DataType", |
| 51 | DataType::QASYMM8_SIGNED)); |
| 52 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 53 | /** Input data sets **/ |
| 54 | const auto ElementwiseMaxS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType", |
| 55 | DataType::S32)); |
| 56 | const auto ElementwiseMaxS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 57 | framework::dataset::make("DataType", DataType::S16)); |
| 58 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 59 | const auto ElementwiseMaxFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 60 | framework::dataset::make("DataType", DataType::F16)); |
| 61 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 62 | const auto ElementwiseMaxFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 63 | framework::dataset::make("DataType", DataType::F32)); |
| 64 | } // namespace |
| 65 | |
| 66 | TEST_SUITE(NEON) |
| 67 | TEST_SUITE(ElementwiseMax) |
| 68 | |
| 69 | template <typename T> |
| 70 | using NEElementwiseMaxFixture = ElementwiseMaxValidationFixture<Tensor, Accessor, NEElementwiseMax, T>; |
| 71 | |
| 72 | // *INDENT-OFF* |
| 73 | // clang-format off |
| 74 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 75 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 77 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 78 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 80 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), // OK |
| 81 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), // Mismatching data types |
| 82 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED,QuantizationInfo(0.1f, 2) ), // Mismatching qinfo |
| 83 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 84 | }), |
| 85 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 86 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 87 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 88 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 89 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 90 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), |
| 91 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8), |
| 92 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED,QuantizationInfo(0.4f, 5) ), // Mismatching qinfo |
| 93 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 94 | })), |
| 95 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 96 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 97 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 98 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 99 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 100 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), |
| 101 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), |
| 102 | TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED,QuantizationInfo(0.3f,4 ) ), // Mismatching qinfo |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 103 | })), |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 104 | |
| 105 | framework::dataset::make("Expected", { true, true, true, false, false, true, false, false,false})), |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 106 | input1_info, input2_info, output_info, expected) |
| 107 | { |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 108 | ARM_COMPUTE_EXPECT(bool(NEElementwiseMax::validate( |
| 109 | &input1_info.clone()->set_is_resizable(false), |
| 110 | &input2_info.clone()->set_is_resizable(false), |
| 111 | &output_info.clone()->set_is_resizable(false)) |
| 112 | ) == expected, framework::LogLevel::ERRORS); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 113 | } |
| 114 | // clang-format on |
| 115 | // *INDENT-ON* |
| 116 | |
| 117 | TEST_SUITE(S32) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 118 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMaxS32Dataset)) |
| 119 | { |
| 120 | // Validate output |
| 121 | validate(Accessor(_target), _reference); |
| 122 | } |
| 123 | TEST_SUITE_END() // S32 |
| 124 | |
| 125 | TEST_SUITE(S16) |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 126 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxS16Dataset)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 127 | { |
| 128 | // Validate output |
| 129 | validate(Accessor(_target), _reference); |
| 130 | } |
| 131 | TEST_SUITE_END() // S16 |
| 132 | |
| 133 | template <typename T> |
| 134 | using NEElementwiseMaxQuantizedFixture = ElementwiseMaxValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMax, T>; |
| 135 | |
| 136 | TEST_SUITE(Quantized) |
| 137 | TEST_SUITE(QASYMM8) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 138 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 139 | ElementwiseMaxQASYMM8Dataset), |
| 140 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 141 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 142 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(Accessor(_target), _reference, tolerance_fp32, 0.01); |
| 146 | } |
| 147 | |
| 148 | template <typename T> |
| 149 | using NEElementwiseMaxQuantizedBroadcastFixture = ElementwiseMaxQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>; |
| 150 | |
| 151 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMaxQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapesBroadcast(), |
| 152 | ElementwiseMaxQASYMM8Dataset), |
| 153 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 154 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 155 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 156 | { |
| 157 | // Validate output |
| 158 | validate(Accessor(_target), _reference); |
| 159 | } |
| 160 | TEST_SUITE_END() |
morgolock | a359805 | 2019-12-31 12:20:47 +0000 | [diff] [blame] | 161 | |
| 162 | TEST_SUITE(QASYMM8_SIGNED) |
| 163 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 164 | ElementwiseMaxQASYMM8SignedDataset), |
| 165 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 2) })), |
| 166 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 2) })), |
| 167 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 2) }))) |
| 168 | { |
| 169 | // Validate output |
| 170 | validate(Accessor(_target), _reference); |
| 171 | } |
| 172 | |
| 173 | TEST_SUITE_END() |
| 174 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 175 | TEST_SUITE_END() |
| 176 | |
| 177 | TEST_SUITE(Float) |
| 178 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 179 | TEST_SUITE(F16) |
| 180 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP16Dataset)) |
| 181 | { |
| 182 | // Validate output |
| 183 | validate(Accessor(_target), _reference); |
| 184 | } |
| 185 | TEST_SUITE_END() // F16 |
| 186 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 187 | |
| 188 | TEST_SUITE(F32) |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 189 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP32Dataset)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 190 | { |
| 191 | // Validate output |
| 192 | validate(Accessor(_target), _reference); |
| 193 | } |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 194 | template <typename T> |
| 195 | using NEElementwiseMaxBroadcastFixture = ElementwiseMaxBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>; |
| 196 | |
Michalis Spyrou | 5ce99a2 | 2019-01-25 14:17:49 +0000 | [diff] [blame] | 197 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMaxBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(), |
| 198 | ElementwiseMaxFP32Dataset)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 199 | { |
| 200 | // Validate output |
| 201 | validate(Accessor(_target), _reference); |
| 202 | } |
| 203 | TEST_SUITE_END() // F32 |
| 204 | TEST_SUITE_END() // Float |
| 205 | |
| 206 | TEST_SUITE_END() // ElementwiseMax |
| 207 | TEST_SUITE_END() // NEON |
| 208 | } // namespace validation |
| 209 | } // namespace test |
| 210 | } // namespace arm_compute |