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/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 */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 46 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
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 */ |
| 48 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 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. */ |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 52 | const auto data_pad_f32 = concat(concat(combine(framework::dataset::make("PadX", 0), |
| 53 | combine(framework::dataset::make("PadY", 0), |
| 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 | |
| 75 | const auto data_qs8 = combine(datasets::SmallDirectConvolutionShapes(), |
| 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. */ |
| 82 | const auto data_qs16 = combine(datasets::SmallDirectConvolutionShapes(), |
| 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 }))))))); |
| 89 | } // namespace |
| 90 | |
| 91 | TEST_SUITE(NEON) |
| 92 | TEST_SUITE(DirectConvolutionLayer) |
| 93 | |
| 94 | //TODO(COMPMID-415): Configuration tests? |
| 95 | |
| 96 | template <typename T> |
| 97 | using NEDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>; |
| 98 | |
| 99 | TEST_SUITE(Float) |
| 100 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
| 101 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 102 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(data_f32, framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 103 | { |
| 104 | // Validate output |
| 105 | validate(Accessor(_target), _reference, tolerance_fp16); |
| 106 | } |
| 107 | TEST_SUITE_END() |
| 108 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 109 | |
| 110 | TEST_SUITE(FP32) |
Georgios Pinitas | 898a806 | 2017-09-12 19:19:12 +0100 | [diff] [blame] | 111 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(data_f32, framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 112 | { |
| 113 | // Validate output |
| 114 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 115 | } |
| 116 | TEST_SUITE_END() |
| 117 | TEST_SUITE_END() |
| 118 | |
| 119 | template <typename T> |
| 120 | using NEDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>; |
| 121 | |
| 122 | TEST_SUITE(Quantized) |
| 123 | TEST_SUITE(QS8) |
| 124 | // We test for fixed point precision [4,6] |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 125 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(data_qs8, framework::dataset::make("DataType", DataType::QS8)), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 126 | framework::dataset::make("FractionalBits", 4, 7))) |
| 127 | { |
| 128 | // Validate output |
| 129 | validate(Accessor(_target), _reference, tolerance_qs); |
| 130 | } |
| 131 | TEST_SUITE_END() |
| 132 | |
| 133 | TEST_SUITE(QS16) |
| 134 | // We test for fixed point precision [4,13] |
| 135 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_qs16, framework::dataset::make("DataType", DataType::QS16)), |
| 136 | framework::dataset::make("FractionalBits", 4, 14))) |
| 137 | { |
| 138 | // Validate output |
| 139 | validate(Accessor(_target), _reference, tolerance_qs); |
| 140 | } |
| 141 | TEST_SUITE_END() |
| 142 | TEST_SUITE_END() |
| 143 | |
| 144 | TEST_SUITE_END() |
| 145 | TEST_SUITE_END() |
| 146 | } // namespace validation |
| 147 | } // namespace test |
| 148 | } // namespace arm_compute |