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" |
| 36 | #include "tests/validation/half.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 | constexpr AbsoluteTolerance<float> tolerance_qs(1.f); /**< Tolerance for fixed point tests */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 47 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 48 | constexpr AbsoluteTolerance<float> tolerance_fp16(0.01f); /**< Tolerance for half precision floating point tests */ |
| 49 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 50 | constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 51 | |
| 52 | /** Direct convolution data set. */ |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 53 | const auto data_pad_f32 = concat(concat(combine(framework::dataset::make("PadX", 0), |
| 54 | combine(framework::dataset::make("PadY", 0), |
| 55 | framework::dataset::make("KernelSize", 1))), |
| 56 | combine(framework::dataset::make("PadX", 0, 2), |
| 57 | combine(framework::dataset::make("PadY", 0, 2), |
| 58 | framework::dataset::make("KernelSize", 3)))), |
| 59 | combine(framework::dataset::make("PadX", 0, 3), |
| 60 | combine(framework::dataset::make("PadY", 0, 3), |
| 61 | framework::dataset::make("KernelSize", 5)))); |
| 62 | |
| 63 | const auto data_pad_qs8 = concat(combine(framework::dataset::make("PadX", 0), |
| 64 | combine(framework::dataset::make("PadY", 0), |
| 65 | framework::dataset::make("KernelSize", 1))), |
| 66 | combine(framework::dataset::make("PadX", 0, 2), |
| 67 | combine(framework::dataset::make("PadY", 0, 2), |
| 68 | framework::dataset::make("KernelSize", 3)))); |
| 69 | |
| 70 | const auto data_f32 = combine(datasets::SmallDirectConvolutionShapes(), |
| 71 | combine(framework::dataset::make("StrideX", 1, 3), |
| 72 | combine(framework::dataset::make("StrideY", 1, 3), |
| 73 | combine(data_pad_f32, |
| 74 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
| 75 | |
| 76 | const auto data_qs8 = combine(datasets::SmallDirectConvolutionShapes(), |
| 77 | combine(framework::dataset::make("StrideX", 1, 3), |
| 78 | combine(framework::dataset::make("StrideY", 1, 3), |
| 79 | combine(data_pad_qs8, |
| 80 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 81 | |
| 82 | /** Direct convolution QS16 data set. */ |
| 83 | const auto data_qs16 = combine(datasets::SmallDirectConvolutionShapes(), |
| 84 | combine(framework::dataset::make("StrideX", 1, 3), |
| 85 | combine(framework::dataset::make("StrideY", 1, 3), |
| 86 | combine(framework::dataset::make("PadX", 0), |
| 87 | combine(framework::dataset::make("PadY", 0), |
| 88 | combine(framework::dataset::make("KernelSize", 1), |
| 89 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))))); |
| 90 | } // namespace |
| 91 | |
| 92 | TEST_SUITE(NEON) |
| 93 | TEST_SUITE(DirectConvolutionLayer) |
| 94 | |
| 95 | //TODO(COMPMID-415): Configuration tests? |
| 96 | |
| 97 | template <typename T> |
| 98 | using NEDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>; |
| 99 | |
| 100 | TEST_SUITE(Float) |
| 101 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
| 102 | TEST_SUITE(FP16) |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 103 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixture<half_float::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] | 104 | { |
| 105 | // Validate output |
| 106 | validate(Accessor(_target), _reference, tolerance_fp16); |
| 107 | } |
| 108 | TEST_SUITE_END() |
| 109 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 110 | |
| 111 | TEST_SUITE(FP32) |
Georgios Pinitas | 898a806 | 2017-09-12 19:19:12 +0100 | [diff] [blame^] | 112 | 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] | 113 | { |
| 114 | // Validate output |
| 115 | validate(Accessor(_target), _reference, tolerance_fp32); |
| 116 | } |
| 117 | TEST_SUITE_END() |
| 118 | TEST_SUITE_END() |
| 119 | |
| 120 | template <typename T> |
| 121 | using NEDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<Tensor, Accessor, NEDirectConvolutionLayer, T>; |
| 122 | |
| 123 | TEST_SUITE(Quantized) |
| 124 | TEST_SUITE(QS8) |
| 125 | // We test for fixed point precision [4,6] |
Pablo Tello | 06da39d | 2017-08-10 15:10:40 +0100 | [diff] [blame] | 126 | 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] | 127 | framework::dataset::make("FractionalBits", 4, 7))) |
| 128 | { |
| 129 | // Validate output |
| 130 | validate(Accessor(_target), _reference, tolerance_qs); |
| 131 | } |
| 132 | TEST_SUITE_END() |
| 133 | |
| 134 | TEST_SUITE(QS16) |
| 135 | // We test for fixed point precision [4,13] |
| 136 | FIXTURE_DATA_TEST_CASE(Run, NEDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_qs16, framework::dataset::make("DataType", DataType::QS16)), |
| 137 | framework::dataset::make("FractionalBits", 4, 14))) |
| 138 | { |
| 139 | // Validate output |
| 140 | validate(Accessor(_target), _reference, tolerance_qs); |
| 141 | } |
| 142 | TEST_SUITE_END() |
| 143 | TEST_SUITE_END() |
| 144 | |
| 145 | TEST_SUITE_END() |
| 146 | TEST_SUITE_END() |
| 147 | } // namespace validation |
| 148 | } // namespace test |
| 149 | } // namespace arm_compute |