giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 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 | { |
Michele Di Giorgio | bc0e1c9 | 2020-04-29 17:25:20 +0100 | [diff] [blame] | 44 | constexpr RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 45 | constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 46 | /** Input data sets **/ |
| 47 | const auto ElementwiseMinQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 48 | framework::dataset::make("DataType", |
| 49 | DataType::QASYMM8)); |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 50 | |
| 51 | const auto ElementwiseMaxQASYMM8SignedDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), |
| 52 | framework::dataset::make("DataType", |
| 53 | DataType::QASYMM8_SIGNED)); |
| 54 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 55 | const auto ElementwiseMinS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType", |
| 56 | DataType::S32)); |
| 57 | const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 58 | framework::dataset::make("DataType", DataType::S16)); |
| 59 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 60 | const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 61 | framework::dataset::make("DataType", DataType::F16)); |
| 62 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 63 | const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 64 | framework::dataset::make("DataType", DataType::F32)); |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 65 | const auto InPlaceDataSet = framework::dataset::make("InPlace", { false, true }); |
| 66 | const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false }); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 67 | } // namespace |
| 68 | |
| 69 | TEST_SUITE(NEON) |
| 70 | TEST_SUITE(ElementwiseMin) |
| 71 | |
| 72 | template <typename T> |
| 73 | using NEElementwiseMinFixture = ElementwiseMinValidationFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 74 | |
| 75 | // *INDENT-OFF* |
| 76 | // clang-format off |
| 77 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 78 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 80 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination |
| 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 83 | TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), // Ok |
| 84 | TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), // Mismatching types, cannot mix QASYMM8_SIGNED with QASYMM8 |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 85 | }), |
| 86 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 87 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 88 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 89 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 90 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 91 | TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), |
| 92 | TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8), |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 93 | })), |
| 94 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 95 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 96 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 97 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 98 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 99 | TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), |
| 100 | TensorInfo(TensorShape(4U, 4U, 2U), 1, DataType::QASYMM8_SIGNED), |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 101 | })), |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 102 | framework::dataset::make("Expected", { true, true, true, false, |
Michele Di Giorgio | bc0e1c9 | 2020-04-29 17:25:20 +0100 | [diff] [blame] | 103 | false,true,false})), |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 104 | input1_info, input2_info, output_info, expected) |
| 105 | { |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 106 | ARM_COMPUTE_EXPECT(bool(NEElementwiseMin::validate( |
| 107 | &input1_info.clone()->set_is_resizable(false), |
| 108 | &input2_info.clone()->set_is_resizable(false), |
| 109 | &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 110 | } |
| 111 | // clang-format on |
| 112 | // *INDENT-ON* |
| 113 | |
| 114 | TEST_SUITE(S32) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 115 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ElementwiseMinS32Dataset), |
| 116 | InPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 117 | { |
| 118 | // Validate output |
| 119 | validate(Accessor(_target), _reference); |
| 120 | } |
| 121 | TEST_SUITE_END() // S32 |
| 122 | |
| 123 | TEST_SUITE(S16) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 124 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMinS16Dataset), |
| 125 | InPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 126 | { |
| 127 | // Validate output |
| 128 | validate(Accessor(_target), _reference); |
| 129 | } |
| 130 | TEST_SUITE_END() // S16 |
| 131 | |
| 132 | template <typename T> |
| 133 | using NEElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 134 | |
| 135 | TEST_SUITE(Quantized) |
| 136 | TEST_SUITE(QASYMM8) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 137 | template <typename T> |
| 138 | using NEElementwiseMinQuantizedBroadcastFixture = ElementwiseMinQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 139 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 140 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMinQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 141 | combine(combine(combine(combine(combine(datasets::SmallShapesBroadcast(), |
| 142 | ElementwiseMinQASYMM8Dataset), |
| 143 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 144 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 145 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })), |
| 146 | OutOfPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 147 | { |
| 148 | // Validate output |
| 149 | validate(Accessor(_target), _reference); |
| 150 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 151 | FIXTURE_DATA_TEST_CASE(RunTinyBroadcastInPlace, NEElementwiseMinQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 152 | combine(combine(combine(combine(combine(datasets::TinyShapesBroadcastInplace(), |
| 153 | ElementwiseMinQASYMM8Dataset), |
| 154 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 20) })), |
| 155 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 20) })), |
| 156 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 20) })), |
| 157 | InPlaceDataSet)) |
| 158 | { |
| 159 | // Validate output |
| 160 | validate(Accessor(_target), _reference); |
| 161 | } |
| 162 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(), |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 163 | ElementwiseMinQASYMM8Dataset), |
| 164 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 165 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 166 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })), |
| 167 | OutOfPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 168 | { |
| 169 | // Validate output |
| 170 | validate(Accessor(_target), _reference, tolerance_fp32, 0.01); |
| 171 | } |
| 172 | TEST_SUITE_END() |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 173 | |
| 174 | TEST_SUITE(QASYMM8_SIGNED) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 175 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(), |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 176 | ElementwiseMaxQASYMM8SignedDataset), |
Michele Di Giorgio | bc0e1c9 | 2020-04-29 17:25:20 +0100 | [diff] [blame] | 177 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 20) })), |
| 178 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f, 0) })), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 179 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f, -27) })), |
| 180 | OutOfPlaceDataSet)) |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 181 | { |
| 182 | // Validate output |
Michele Di Giorgio | bc0e1c9 | 2020-04-29 17:25:20 +0100 | [diff] [blame] | 183 | validate(Accessor(_target), _reference, tolerance_qasymm8_signed); |
morgolock | 781d727 | 2020-01-10 10:11:14 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | TEST_SUITE_END() |
| 187 | |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 188 | TEST_SUITE_END() |
| 189 | |
| 190 | TEST_SUITE(Float) |
| 191 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 192 | TEST_SUITE(F16) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 193 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset), |
| 194 | InPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 195 | { |
| 196 | // Validate output |
| 197 | validate(Accessor(_target), _reference); |
| 198 | } |
| 199 | TEST_SUITE_END() // F16 |
| 200 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 201 | |
| 202 | TEST_SUITE(F32) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 203 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset), |
| 204 | InPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 205 | { |
| 206 | // Validate output |
| 207 | validate(Accessor(_target), _reference); |
| 208 | } |
| 209 | |
| 210 | template <typename T> |
| 211 | using NEElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 212 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 213 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMinBroadcastFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(), |
| 214 | ElementwiseMinFP32Dataset), |
| 215 | OutOfPlaceDataSet)) |
| 216 | { |
| 217 | // Validate output |
| 218 | validate(Accessor(_target), _reference); |
| 219 | } |
| 220 | FIXTURE_DATA_TEST_CASE(RunTinyBroadcastInPlace, NEElementwiseMinBroadcastFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcastInplace(), |
| 221 | ElementwiseMinFP32Dataset), |
| 222 | InPlaceDataSet)) |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 223 | { |
| 224 | // Validate output |
| 225 | validate(Accessor(_target), _reference); |
| 226 | } |
| 227 | TEST_SUITE_END() // F32 |
| 228 | TEST_SUITE_END() // Float |
| 229 | |
| 230 | TEST_SUITE_END() // ElementwiseMin |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 231 | TEST_SUITE_END() // Neon |
giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 232 | } // namespace validation |
| 233 | } // namespace test |
| 234 | } // namespace arm_compute |