Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [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, |
| 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/NEDirectConvolutionLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 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/DirectConvolutionLayerFixture.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 45 | constexpr AbsoluteTolerance<float> tolerance_qs(1.f); /**< Tolerance for fixed point tests */ |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 46 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 47 | constexpr AbsoluteTolerance<float> tolerance_fp16(0.01f); /**< Tolerance for half precision floating point tests */ |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 48 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 49 | constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 50 | |
| 51 | /** Direct convolution data set. */ |
Georgios Pinitas | 1599787 | 2018-02-19 13:58:22 +0000 | [diff] [blame] | 52 | const auto data_pad_f32 = concat(concat(combine(framework::dataset::make("PadX", 0, 1), |
| 53 | combine(framework::dataset::make("PadY", 0, 1), |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 54 | framework::dataset::make("KernelSize", 1))), |
| 55 | combine(framework::dataset::make("PadX", 0, 2), |
| 56 | combine(framework::dataset::make("PadY", 0, 2), |
| 57 | framework::dataset::make("KernelSize", 3)))), |
| 58 | combine(framework::dataset::make("PadX", 0, 3), |
| 59 | combine(framework::dataset::make("PadY", 0, 3), |
| 60 | framework::dataset::make("KernelSize", 5)))); |
| 61 | |
| 62 | const auto data_pad_qs8 = concat(combine(framework::dataset::make("PadX", 0), |
| 63 | combine(framework::dataset::make("PadY", 0), |
| 64 | framework::dataset::make("KernelSize", 1))), |
| 65 | combine(framework::dataset::make("PadX", 0, 2), |
| 66 | combine(framework::dataset::make("PadY", 0, 2), |
| 67 | framework::dataset::make("KernelSize", 3)))); |
| 68 | |
| 69 | const auto data_f32 = combine(datasets::SmallDirectConvolutionShapes(), |
| 70 | combine(framework::dataset::make("StrideX", 1, 3), |
| 71 | combine(framework::dataset::make("StrideY", 1, 3), |
| 72 | combine(data_pad_f32, |
| 73 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
| 74 | |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 75 | const auto data_qs8 = combine(datasets::TinyDirectConvolutionShapes(), |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 76 | combine(framework::dataset::make("StrideX", 1, 3), |
| 77 | combine(framework::dataset::make("StrideY", 1, 3), |
| 78 | combine(data_pad_qs8, |
| 79 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 80 | |
| 81 | /** Direct convolution QS16 data set. */ |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 82 | const auto data_qs16 = combine(datasets::TinyDirectConvolutionShapes(), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 83 | combine(framework::dataset::make("StrideX", 1, 3), |
| 84 | combine(framework::dataset::make("StrideY", 1, 3), |
| 85 | combine(framework::dataset::make("PadX", 0), |
| 86 | combine(framework::dataset::make("PadY", 0), |
| 87 | combine(framework::dataset::make("KernelSize", 1), |
| 88 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))))); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 89 | /** Activation function Dataset*/ |
| 90 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 91 | { |
| 92 | ActivationLayerInfo(), |
| 93 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 94 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f), |
| 95 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f) |
| 96 | }); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 97 | } // namespace |
| 98 | |
| 99 | TEST_SUITE(NEON) |
| 100 | TEST_SUITE(DirectConvolutionLayer) |
| 101 | |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 102 | // *INDENT-OFF* |
| 103 | // clang-format off |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 104 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip( |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 105 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type input/weights |
| 106 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching input feature maps |
| 107 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Unsupported kernel width |
| 108 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Non-rectangular weights dimensions |
| 109 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid weights dimensions |
| 110 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid stride |
| 111 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid biases size |
| 112 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid biases dimensions |
| 113 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid output size |
| 114 | }), |
| 115 | framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F16, 0), |
| 116 | TensorInfo(TensorShape(3U, 3U, 3U, 4U), 1, DataType::F32, 0), |
| 117 | TensorInfo(TensorShape(9U, 9U, 2U, 4U), 1, DataType::F32, 0), |
| 118 | TensorInfo(TensorShape(5U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 119 | TensorInfo(TensorShape(3U, 3U, 2U, 4U, 3U), 1, DataType::F32, 0), |
| 120 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 121 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 122 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 123 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 124 | })), |
| 125 | framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 126 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 127 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 128 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 129 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 130 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 131 | TensorInfo(TensorShape(3U), 1, DataType::F32, 0), |
| 132 | TensorInfo(TensorShape(4U, 2U), 1, DataType::F32, 0), |
| 133 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 134 | })), |
| 135 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 136 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 137 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 138 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 139 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 140 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 141 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 142 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 143 | TensorInfo(TensorShape(26U, 11U, 4U), 1, DataType::F32, 0), |
| 144 | })), |
| 145 | framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0), |
| 146 | PadStrideInfo(1, 1, 0, 0), |
| 147 | PadStrideInfo(1, 1, 0, 0), |
| 148 | PadStrideInfo(1, 1, 0, 0), |
| 149 | PadStrideInfo(1, 1, 0, 0), |
| 150 | PadStrideInfo(3, 3, 0, 0), |
| 151 | PadStrideInfo(1, 1, 0, 0), |
| 152 | PadStrideInfo(1, 1, 0, 0), |
| 153 | PadStrideInfo(1, 1, 0, 0), |
| 154 | })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 155 | framework::dataset::make("ActivationInfo", |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 156 | { |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 157 | ActivationLayerInfo(), |
| 158 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU) |
| 159 | })), |
| 160 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false })), |
| 161 | input_info, weights_info, biases_info, output_info, conv_info, act_info, expected) |
| 162 | { |
| 163 | bool is_valid = bool(NEDirectConvolutionLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &biases_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), conv_info, act_info)); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 164 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 165 | } |
| 166 | // clang-format on |
| 167 | // *INDENT-ON* |
| 168 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 169 | //TODO(COMPMID-415): Configuration tests? |
| 170 | |
| 171 | template <typename T> |
| 172 | using NEDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>; |
| 173 | |
| 174 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 175 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 176 | TEST_SUITE(FP16) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 177 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(data_f32, framework::dataset::make("DataType", DataType::F16)), |
| 178 | ActivationFunctionsDataset)) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 179 | { |
| 180 | // Validate output |
| 181 | validate(Accessor(_target), _reference, tolerance_fp16); |
| 182 | } |
| 183 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 184 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 185 | |
| 186 | TEST_SUITE(FP32) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 187 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(data_f32, framework::dataset::make("DataType", DataType::F32)), |
| 188 | ActivationFunctionsDataset)) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 189 | { |
| 190 | // Validate output |
| 191 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 192 | } |
| 193 | TEST_SUITE_END() |
| 194 | TEST_SUITE_END() |
| 195 | |
| 196 | template <typename T> |
| 197 | using NEDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>; |
| 198 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 199 | const auto QuantizedActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 200 | { |
| 201 | ActivationLayerInfo(), |
| 202 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 203 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.f) |
| 204 | }); |
| 205 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 206 | TEST_SUITE(Quantized) |
| 207 | TEST_SUITE(QS8) |
| 208 | // We test for fixed point precision [4,6] |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 209 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(data_qs8, framework::dataset::make("DataType", DataType::QS8)), |
| 210 | framework::dataset::make("FractionalBits", 4, 7)), |
| 211 | QuantizedActivationFunctionsDataset)) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 212 | { |
| 213 | // Validate output |
| 214 | validate(Accessor(_target), _reference, tolerance_qs); |
| 215 | } |
| 216 | TEST_SUITE_END() |
| 217 | |
| 218 | TEST_SUITE(QS16) |
| 219 | // We test for fixed point precision [4,13] |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame^] | 220 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(data_qs16, framework::dataset::make("DataType", DataType::QS16)), |
| 221 | framework::dataset::make("FractionalBits", 4, 14)), |
| 222 | QuantizedActivationFunctionsDataset)) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 223 | { |
| 224 | // Validate output |
| 225 | validate(Accessor(_target), _reference, tolerance_qs); |
| 226 | } |
| 227 | TEST_SUITE_END() |
| 228 | TEST_SUITE_END() |
| 229 | |
| 230 | TEST_SUITE_END() |
| 231 | TEST_SUITE_END() |
| 232 | } // namespace validation |
| 233 | } // namespace test |
| 234 | } // namespace arm_compute |