Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +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/NEConvolutionLayer.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEWinogradLayer.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/datasets/LargeConvolutionLayerDataset.h" |
| 32 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 33 | #include "tests/datasets/TinyConvolutionLayerDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 39 | #include "tests/validation/fixtures/WinogradLayerFixture.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | namespace |
| 48 | { |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 49 | const AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 50 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 51 | const AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 52 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 53 | const AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */ |
| 54 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 55 | |
| 56 | /** CNN data types */ |
| 57 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 58 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 59 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 60 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 61 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 62 | DataType::F32, |
| 63 | DataType::QS8, |
| 64 | DataType::QS16, |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 65 | DataType::QASYMM8, |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 66 | }); |
| 67 | } // namespace |
| 68 | |
| 69 | TEST_SUITE(NEON) |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 70 | |
| 71 | #if defined(__aarch64__) |
| 72 | TEST_SUITE(WinogradLayer) |
| 73 | template <typename T> |
| 74 | using NEWinogradLayerFixture = WinogradLayerValidationFixture<Tensor, Accessor, NEWinogradLayer, T>; |
| 75 | |
| 76 | TEST_SUITE(FP32) |
| 77 | FIXTURE_DATA_TEST_CASE(RunSmall, NEWinogradLayerFixture<float>, framework::DatasetMode::PRECOMMIT, datasets::SmallWinogradLayerDataset()) |
| 78 | { |
| 79 | // Validate output |
| 80 | validate(Accessor(_target), _reference, tolerance_f32); |
| 81 | } |
| 82 | |
| 83 | TEST_SUITE_END() |
| 84 | TEST_SUITE_END() |
| 85 | #endif /* __aarch64__ */ |
| 86 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 87 | TEST_SUITE(ConvolutionLayer) |
| 88 | |
| 89 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes), |
| 90 | input_shape, weights_shape, bias_shape, output_shape, info, data_type) |
| 91 | { |
| 92 | // Set fixed point position data type allowed |
| 93 | int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 94 | |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 95 | auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
| 96 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 97 | // Create tensors |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 98 | Tensor src = create_tensor<Tensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 99 | Tensor weights = create_tensor<Tensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 100 | Tensor bias = create_tensor<Tensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 101 | Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 102 | |
| 103 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 104 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 105 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 106 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 107 | |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 108 | const QuantizationInfo src_quantization_info = src.info()->quantization_info(); |
| 109 | const QuantizationInfo weights_quantization_info = weights.info()->quantization_info(); |
| 110 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 111 | // Create and configure function |
| 112 | NEConvolutionLayer conv; |
| 113 | conv.configure(&src, &weights, &bias, &dst, info); |
| 114 | |
| 115 | // Validate valid region |
| 116 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 117 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 118 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 119 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 120 | |
| 121 | validate(src.info()->valid_region(), src_valid_region); |
| 122 | validate(weights.info()->valid_region(), weights_valid_region); |
| 123 | validate(bias.info()->valid_region(), bias_valid_region); |
| 124 | validate(dst.info()->valid_region(), dst_valid_region); |
| 125 | |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 126 | // Validate QuantizationInfo |
| 127 | ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS); |
| 128 | ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS); |
| 129 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 130 | // Validate padding |
| 131 | //TODO(COMPMID-415) Need to validate padding? |
| 132 | } |
| 133 | |
| 134 | template <typename T> |
| 135 | using NEConvolutionLayerFixture = ConvolutionValidationFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
| 136 | |
| 137 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 138 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 139 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 140 | FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 141 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 142 | framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 143 | { |
| 144 | // Validate output |
| 145 | validate(Accessor(_target), _reference, tolerance_f16); |
| 146 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 147 | FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 148 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 149 | framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 150 | { |
| 151 | // Validate output |
| 152 | validate(Accessor(_target), _reference, tolerance_f16); |
| 153 | } |
| 154 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 155 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 156 | |
| 157 | TEST_SUITE(FP32) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 158 | FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 159 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 160 | framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 161 | { |
| 162 | // Validate output |
| 163 | validate(Accessor(_target), _reference, tolerance_f32); |
| 164 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 165 | FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 166 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 167 | framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 168 | { |
| 169 | // Validate output |
| 170 | validate(Accessor(_target), _reference, tolerance_f32); |
| 171 | } |
| 172 | TEST_SUITE_END() |
| 173 | TEST_SUITE_END() |
| 174 | |
| 175 | template <typename T> |
| 176 | using NEConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
| 177 | |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 178 | TEST_SUITE(FixedPoint) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 179 | TEST_SUITE(QS8) |
| 180 | // We test for fixed point precision [4,6] |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 181 | FIXTURE_DATA_TEST_CASE(RunTiny, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::TinyConvolutionLayerDataset(), |
| 182 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 183 | framework::dataset::make("DataType", DataType::QS8)), |
| 184 | framework::dataset::make("FractionalBits", 4, 7))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 185 | { |
| 186 | // Validate output |
| 187 | validate(Accessor(_target), _reference, tolerance_q); |
| 188 | } |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 189 | FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Georgios Pinitas | ce54b56 | 2017-09-14 17:21:51 +0100 | [diff] [blame] | 190 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 191 | framework::dataset::make("DataType", DataType::QS8)), |
| 192 | framework::dataset::make("FractionalBits", 4, 7))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 193 | { |
| 194 | // Validate output |
| 195 | validate(Accessor(_target), _reference, tolerance_q); |
| 196 | } |
| 197 | TEST_SUITE_END() |
| 198 | |
| 199 | TEST_SUITE(QS16) |
| 200 | // Testing for fixed point position [1,14) |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 201 | FIXTURE_DATA_TEST_CASE(RunTiny, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::TinyConvolutionLayerDataset(), |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 202 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 203 | framework::dataset::make("DataType", DataType::QS16)), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 204 | framework::dataset::make("FractionalBits", 1, 14))) |
| 205 | { |
| 206 | // Validate output |
| 207 | validate(Accessor(_target), _reference, tolerance_q); |
| 208 | } |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 209 | FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 210 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 211 | framework::dataset::make("DataType", DataType::QS16)), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 212 | framework::dataset::make("FractionalBits", 1, 14))) |
| 213 | { |
| 214 | // Validate output |
| 215 | validate(Accessor(_target), _reference, tolerance_q); |
| 216 | } |
| 217 | TEST_SUITE_END() |
| 218 | TEST_SUITE_END() |
| 219 | |
Isabella Gottardi | e6630e4 | 2018-01-18 15:50:39 +0000 | [diff] [blame] | 220 | template <typename T> |
| 221 | using NEConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<Tensor, Accessor, NEConvolutionLayer, T>; |
| 222 | |
| 223 | TEST_SUITE(Quantized) |
| 224 | TEST_SUITE(QASYMM8) |
| 225 | FIXTURE_DATA_TEST_CASE(RunSmall, NEConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 226 | framework::dataset::make("ReshapeWeights", { true })), |
| 227 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 228 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) }))) |
| 229 | { |
| 230 | // Validate output |
| 231 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 232 | } |
| 233 | FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 234 | framework::dataset::make("ReshapeWeights", { true })), |
| 235 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 236 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) }))) |
| 237 | { |
| 238 | // Validate output |
| 239 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 240 | } |
| 241 | TEST_SUITE_END() |
| 242 | TEST_SUITE_END() |
| 243 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 244 | TEST_SUITE_END() |
| 245 | TEST_SUITE_END() |
| 246 | } // namespace validation |
| 247 | } // namespace test |
| 248 | } // namespace arm_compute |