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