giuros01 | 92fd943 | 2018-12-03 17:30:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 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 ElementwiseMinQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 47 | framework::dataset::make("DataType", |
| 48 | DataType::QASYMM8)); |
| 49 | const auto ElementwiseMinS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType", |
| 50 | DataType::S32)); |
| 51 | const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)), |
| 52 | framework::dataset::make("DataType", DataType::S16)); |
| 53 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 54 | const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 55 | framework::dataset::make("DataType", DataType::F16)); |
| 56 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 57 | const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 58 | framework::dataset::make("DataType", DataType::F32)); |
| 59 | } // namespace |
| 60 | |
| 61 | TEST_SUITE(NEON) |
| 62 | TEST_SUITE(ElementwiseMin) |
| 63 | |
| 64 | template <typename T> |
| 65 | using NEElementwiseMinFixture = ElementwiseMinValidationFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 66 | |
| 67 | // *INDENT-OFF* |
| 68 | // clang-format off |
| 69 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 70 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 71 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 72 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination |
| 74 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 75 | }), |
| 76 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 77 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 78 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 80 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 81 | })), |
| 82 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 83 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 84 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32), |
| 85 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), |
| 86 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 87 | })), |
| 88 | framework::dataset::make("Expected", { true, true, true, false, false})), |
| 89 | input1_info, input2_info, output_info, expected) |
| 90 | { |
| 91 | ARM_COMPUTE_EXPECT(bool(NEElementwiseMin::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); |
| 92 | } |
| 93 | // clang-format on |
| 94 | // *INDENT-ON* |
| 95 | |
| 96 | TEST_SUITE(S32) |
| 97 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), |
| 98 | shape) |
| 99 | { |
| 100 | // Create tensors |
| 101 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::S32); |
| 102 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S32); |
| 103 | Tensor dst = create_tensor<Tensor>(shape, DataType::S32); |
| 104 | |
| 105 | // Create and Configure function |
| 106 | NEElementwiseMin add; |
| 107 | add.configure(&ref_src1, &ref_src2, &dst); |
| 108 | |
| 109 | // Validate valid region |
| 110 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 111 | validate(dst.info()->valid_region(), valid_region); |
| 112 | } |
| 113 | |
| 114 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinS32Dataset)) |
| 115 | { |
| 116 | // Validate output |
| 117 | validate(Accessor(_target), _reference); |
| 118 | } |
| 119 | TEST_SUITE_END() // S32 |
| 120 | |
| 121 | TEST_SUITE(S16) |
| 122 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::S16 })), |
| 123 | shape, data_type) |
| 124 | { |
| 125 | // Create tensors |
| 126 | Tensor ref_src1 = create_tensor<Tensor>(shape, data_type); |
| 127 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16); |
| 128 | Tensor dst = create_tensor<Tensor>(shape, DataType::S16); |
| 129 | |
| 130 | // Create and Configure function |
| 131 | NEElementwiseMin add; |
| 132 | add.configure(&ref_src1, &ref_src2, &dst); |
| 133 | |
| 134 | // Validate valid region |
| 135 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 136 | validate(dst.info()->valid_region(), valid_region); |
| 137 | } |
| 138 | |
| 139 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset)) |
| 140 | { |
| 141 | // Validate output |
| 142 | validate(Accessor(_target), _reference); |
| 143 | } |
| 144 | |
| 145 | FIXTURE_DATA_TEST_CASE(RunLarge, NEElementwiseMinFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseMinS16Dataset)) |
| 146 | { |
| 147 | // Validate output |
| 148 | validate(Accessor(_target), _reference); |
| 149 | } |
| 150 | TEST_SUITE_END() // S16 |
| 151 | |
| 152 | template <typename T> |
| 153 | using NEElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 154 | |
| 155 | TEST_SUITE(Quantized) |
| 156 | TEST_SUITE(QASYMM8) |
| 157 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), |
| 158 | shape) |
| 159 | { |
| 160 | // Create tensors |
| 161 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 162 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 163 | Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 164 | |
| 165 | // Create and Configure function |
| 166 | NEElementwiseMin add; |
| 167 | add.configure(&ref_src1, &ref_src2, &dst); |
| 168 | |
| 169 | // Validate valid region |
| 170 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 171 | validate(dst.info()->valid_region(), valid_region); |
| 172 | } |
| 173 | |
| 174 | template <typename T> |
| 175 | using NEElementwiseMinQuantizedBroadcastFixture = ElementwiseMinQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 176 | |
| 177 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMinQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapesBroadcast(), |
| 178 | ElementwiseMinQASYMM8Dataset), |
| 179 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 180 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 181 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))) |
| 182 | { |
| 183 | // Validate output |
| 184 | validate(Accessor(_target), _reference); |
| 185 | } |
| 186 | |
| 187 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 188 | ElementwiseMinQASYMM8Dataset), |
| 189 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 190 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 191 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })) |
| 192 | |
| 193 | ) |
| 194 | { |
| 195 | // Validate output |
| 196 | validate(Accessor(_target), _reference, tolerance_fp32, 0.01); |
| 197 | } |
| 198 | TEST_SUITE_END() |
| 199 | TEST_SUITE_END() |
| 200 | |
| 201 | TEST_SUITE(Float) |
| 202 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 203 | TEST_SUITE(F16) |
| 204 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset)) |
| 205 | { |
| 206 | // Validate output |
| 207 | validate(Accessor(_target), _reference); |
| 208 | } |
| 209 | TEST_SUITE_END() // F16 |
| 210 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 211 | |
| 212 | TEST_SUITE(F32) |
| 213 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), |
| 214 | shape) |
| 215 | { |
| 216 | // Create tensors |
| 217 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 218 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 219 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
| 220 | |
| 221 | // Create and Configure function |
| 222 | NEElementwiseMin add; |
| 223 | add.configure(&ref_src1, &ref_src2, &dst); |
| 224 | |
| 225 | // Validate valid region |
| 226 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 227 | validate(dst.info()->valid_region(), valid_region); |
| 228 | } |
| 229 | |
| 230 | FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMinFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset)) |
| 231 | { |
| 232 | // Validate output |
| 233 | validate(Accessor(_target), _reference); |
| 234 | } |
| 235 | |
| 236 | FIXTURE_DATA_TEST_CASE(RunLarge, NEElementwiseMinFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseMinFP32Dataset)) |
| 237 | { |
| 238 | // Validate output |
| 239 | validate(Accessor(_target), _reference); |
| 240 | } |
| 241 | |
| 242 | template <typename T> |
| 243 | using NEElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMin, T>; |
| 244 | |
| 245 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMinBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapesBroadcast(), |
| 246 | ElementwiseMinFP32Dataset)) |
| 247 | { |
| 248 | // Validate output |
| 249 | validate(Accessor(_target), _reference); |
| 250 | } |
| 251 | |
| 252 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEElementwiseMinBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(), |
| 253 | ElementwiseMinFP32Dataset)) |
| 254 | { |
| 255 | // Validate output |
| 256 | validate(Accessor(_target), _reference); |
| 257 | } |
| 258 | TEST_SUITE_END() // F32 |
| 259 | TEST_SUITE_END() // Float |
| 260 | |
| 261 | TEST_SUITE_END() // ElementwiseMin |
| 262 | TEST_SUITE_END() // NEON |
| 263 | } // namespace validation |
| 264 | } // namespace test |
| 265 | } // namespace arm_compute |