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