giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 CONNECTION 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/NEPReluLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/ElementwiseOperationsFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 46 | |
giuros01 | d513436 | 2019-05-14 16:12:53 +0100 | [diff] [blame] | 47 | /** Input data sets **/ |
| 48 | const auto PReluLayerQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)), |
| 49 | framework::dataset::make("DataType", |
| 50 | DataType::QASYMM8)); |
| 51 | const auto PReluLayerFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 52 | framework::dataset::make("DataType", DataType::F32)); |
| 53 | |
| 54 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 55 | RelativeTolerance<float> tolerance_fp16(0.001f); |
| 56 | |
| 57 | const auto PReluLayerFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 58 | framework::dataset::make("DataType", DataType::F16)); |
| 59 | |
| 60 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 61 | |
| 62 | } // namespace |
| 63 | |
| 64 | TEST_SUITE(NEON) |
| 65 | TEST_SUITE(PReluLayer) |
| 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::QASYMM8), |
| 72 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // 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::QASYMM8), |
| 78 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 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::QASYMM8), |
| 84 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), |
| 85 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 86 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 87 | })), |
| 88 | framework::dataset::make("Expected", { true, true, false, false, false})), |
| 89 | input1_info, input2_info, output_info, expected) |
| 90 | { |
| 91 | ARM_COMPUTE_EXPECT(bool(NEPReluLayer::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 | template <typename T> |
| 97 | using NEPReluLayerFixture = PReluLayerValidationFixture<Tensor, Accessor, NEPReluLayer, T>; |
| 98 | |
| 99 | template <typename T> |
| 100 | using NEPReluLayerQuantizedFixture = PReluLayerValidationQuantizedFixture<Tensor, Accessor, NEPReluLayer, T>; |
| 101 | |
| 102 | TEST_SUITE(Quantized) |
| 103 | TEST_SUITE(QASYMM8) |
| 104 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
| 105 | shape) |
| 106 | { |
| 107 | // Create tensors |
| 108 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 109 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 110 | Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 111 | |
| 112 | // Create and Configure function |
| 113 | NEPReluLayer prelu; |
| 114 | prelu.configure(&ref_src1, &ref_src2, &dst); |
| 115 | |
| 116 | // Validate valid region |
| 117 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 118 | validate(dst.info()->valid_region(), valid_region); |
| 119 | } |
| 120 | |
| 121 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), |
| 122 | PReluLayerQASYMM8Dataset), |
| 123 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 124 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 125 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })) |
| 126 | |
| 127 | ) |
| 128 | { |
| 129 | // Validate output |
| 130 | validate(Accessor(_target), _reference, tolerance_fp32, 0.01); |
| 131 | } |
| 132 | |
| 133 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), |
| 134 | PReluLayerQASYMM8Dataset), |
| 135 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), |
| 136 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 137 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })) |
| 138 | |
| 139 | ) |
| 140 | { |
| 141 | // Validate output |
| 142 | validate(Accessor(_target), _reference, tolerance_fp32, 0.01); |
| 143 | } |
| 144 | TEST_SUITE_END() |
| 145 | TEST_SUITE_END() |
| 146 | |
| 147 | TEST_SUITE(Float) |
| 148 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 149 | TEST_SUITE(FP16) |
| 150 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP16Dataset)) |
| 151 | { |
| 152 | // Validate output |
| 153 | validate(Accessor(_target), _reference, tolerance_fp16, 0.01); |
| 154 | } |
| 155 | |
| 156 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), PReluLayerFP16Dataset)) |
| 157 | { |
| 158 | // Validate output |
| 159 | validate(Accessor(_target), _reference, tolerance_fp16, 0.01); |
| 160 | } |
| 161 | TEST_SUITE_END() // FP16 |
| 162 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 163 | |
| 164 | TEST_SUITE(FP32) |
| 165 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
| 166 | shape) |
| 167 | { |
| 168 | // Create tensors |
| 169 | Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32); |
| 170 | Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32); |
| 171 | Tensor dst = create_tensor<Tensor>(shape, DataType::F32); |
| 172 | |
| 173 | // Create and Configure function |
| 174 | NEPReluLayer prelu; |
| 175 | prelu.configure(&ref_src1, &ref_src2, &dst); |
| 176 | |
| 177 | // Validate valid region |
| 178 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 179 | validate(dst.info()->valid_region(), valid_region); |
| 180 | } |
| 181 | |
| 182 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPReluLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), PReluLayerFP32Dataset)) |
| 183 | { |
| 184 | // Validate output |
| 185 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 186 | } |
| 187 | |
| 188 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPReluLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), PReluLayerFP32Dataset)) |
| 189 | { |
| 190 | // Validate output |
| 191 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 192 | } |
| 193 | |
| 194 | template <typename T> |
| 195 | using NEPReluLayerBroadcastFixture = PReluLayerBroadcastValidationFixture<Tensor, Accessor, NEPReluLayer, T>; |
| 196 | |
| 197 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEPReluLayerBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(), |
| 198 | PReluLayerFP32Dataset)) |
| 199 | { |
| 200 | // Validate output |
| 201 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 202 | } |
| 203 | |
| 204 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEPReluLayerBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(), |
| 205 | PReluLayerFP32Dataset)) |
| 206 | { |
| 207 | // Validate output |
| 208 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 209 | } |
| 210 | TEST_SUITE_END() // FP32 |
| 211 | TEST_SUITE_END() // Float |
| 212 | |
| 213 | TEST_SUITE_END() // PReluLayer |
| 214 | TEST_SUITE_END() // NEON |
| 215 | } // namespace validation |
| 216 | } // namespace test |
| 217 | } // namespace arm_compute |