Alex Gilday | 7da29b6 | 2018-03-23 14:16: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 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/NEConvolutionLayer.h" |
| 26 | #include "arm_compute/runtime/NEON/functions/NEGEMMConvolutionLayer.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
| 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/DilatedConvolutionLayerDataset.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 47 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 48 | const AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 49 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 50 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 51 | |
| 52 | /** CNN data types */ |
| 53 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 54 | { |
| 55 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 56 | DataType::F16, |
| 57 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 58 | DataType::F32, |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 59 | DataType::QASYMM8, |
| 60 | }); |
| 61 | } // namespace |
| 62 | |
| 63 | TEST_SUITE(NEON) |
| 64 | |
| 65 | TEST_SUITE(DilatedConvolutionLayer) |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 66 | DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 67 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(8U, 8U, 2U), 1, DataType::F32, 0), |
| 68 | TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32, 0), |
| 69 | TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32, 0), |
| 70 | TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32, 0) |
| 71 | }), |
| 72 | framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0), |
| 73 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0), |
| 74 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0), |
| 75 | TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16, 0) |
| 76 | })), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 77 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(6U, 6U, 1U), 1, DataType::F32, 0), |
| 78 | TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32, 0), |
| 79 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32, 0), |
| 80 | TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32, 0) |
| 81 | })), |
| 82 | framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0), |
| 83 | PadStrideInfo(1, 1, 0, 0), |
| 84 | PadStrideInfo(2, 1, 0, 0), |
| 85 | PadStrideInfo(3, 2, 1, 0) |
| 86 | })), |
| 87 | framework::dataset::make("Dilation", { Size2D(1U, 2U), |
| 88 | Size2D(2U, 1U), |
| 89 | Size2D(2U, 2U), |
| 90 | Size2D(3U, 3U) |
| 91 | })), |
| 92 | framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })), |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 93 | input_info, weights_info, output_info, conv_info, dilation, expected) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 94 | { |
| 95 | ConvolutionMethod is_valid = NEConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false), |
| 96 | &weights_info.clone()->set_is_resizable(false), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 97 | &output_info.clone()->set_is_resizable(false), |
| 98 | conv_info, WeightsInfo(), dilation); |
| 99 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 100 | } |
| 101 | TEST_SUITE_END() |
| 102 | |
| 103 | TEST_SUITE(GEMMDilatedConvolutionLayer) |
| 104 | |
| 105 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDilatedConvolutionLayerDataset(), datasets::LargeDilatedConvolutionLayerDataset()), |
| 106 | CNNDataTypes), |
| 107 | input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type) |
| 108 | { |
| 109 | // Set fixed point position data type allowed |
| 110 | int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 111 | |
| 112 | auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
| 113 | |
| 114 | // Create tensors |
| 115 | Tensor src = create_tensor<Tensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 116 | Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 117 | Tensor bias = create_tensor<Tensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 118 | Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 119 | |
| 120 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 121 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 122 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 123 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 124 | |
| 125 | const QuantizationInfo src_quantization_info = src.info()->quantization_info(); |
| 126 | const QuantizationInfo weights_quantization_info = weights.info()->quantization_info(); |
| 127 | |
| 128 | // Create and configure function |
| 129 | NEGEMMConvolutionLayer conv; |
| 130 | conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation); |
| 131 | |
| 132 | // Validate valid region |
| 133 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 134 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 135 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 136 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 137 | |
| 138 | validate(src.info()->valid_region(), src_valid_region); |
| 139 | validate(weights.info()->valid_region(), weights_valid_region); |
| 140 | validate(bias.info()->valid_region(), bias_valid_region); |
| 141 | validate(dst.info()->valid_region(), dst_valid_region); |
| 142 | |
| 143 | // Validate QuantizationInfo |
| 144 | ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS); |
| 145 | ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS); |
| 146 | |
| 147 | // Validate padding |
| 148 | //TODO(COMPMID-415) Need to validate padding? |
| 149 | } |
| 150 | |
| 151 | template <typename T> |
| 152 | using NEGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
| 153 | |
| 154 | TEST_SUITE(Float) |
| 155 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 156 | TEST_SUITE(FP16) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 157 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 158 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 159 | framework::dataset::make("DataType", DataType::F16)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 160 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 161 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 162 | { |
| 163 | // Validate output |
| 164 | validate(Accessor(_target), _reference, tolerance_f16); |
| 165 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 166 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 167 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 168 | framework::dataset::make("DataType", DataType::F16)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 169 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 170 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 171 | { |
| 172 | // Validate output |
| 173 | validate(Accessor(_target), _reference, tolerance_f16); |
| 174 | } |
| 175 | TEST_SUITE_END() |
| 176 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 177 | |
| 178 | TEST_SUITE(FP32) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 179 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 180 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 181 | framework::dataset::make("DataType", DataType::F32)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 182 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 183 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 184 | { |
| 185 | // Validate output |
| 186 | validate(Accessor(_target), _reference, tolerance_f32); |
| 187 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 188 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 189 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 190 | framework::dataset::make("DataType", DataType::F32)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 191 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 192 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 193 | { |
| 194 | // Validate output |
| 195 | validate(Accessor(_target), _reference, tolerance_f32); |
| 196 | } |
| 197 | TEST_SUITE_END() |
| 198 | TEST_SUITE_END() |
| 199 | |
| 200 | template <typename T> |
| 201 | using NEGEMMDilatedConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>; |
| 202 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 203 | template <typename T> |
| 204 | using NEGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEGEMMConvolutionLayer, T>; |
| 205 | |
| 206 | TEST_SUITE(Quantized) |
| 207 | TEST_SUITE(QASYMM8) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 208 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 209 | combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 210 | framework::dataset::make("ReshapeWeights", { true })), |
| 211 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 212 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 213 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 214 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 215 | { |
| 216 | // Validate output |
| 217 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 218 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 219 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 220 | combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 221 | framework::dataset::make("ReshapeWeights", { true })), |
| 222 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 223 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 224 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 225 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 226 | { |
| 227 | // Validate output |
| 228 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 229 | } |
| 230 | TEST_SUITE_END() |
| 231 | TEST_SUITE_END() |
| 232 | |
| 233 | TEST_SUITE_END() |
| 234 | TEST_SUITE_END() |
| 235 | } // namespace validation |
| 236 | } // namespace test |
| 237 | } // namespace arm_compute |