Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +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/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 30 | #include "tests/datasets/DirectConvolutionLayerDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/datasets/ShapeDatasets.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/DirectConvolutionLayerFixture.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 | { |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 46 | // COMPMID-517 Invesitgate the mismatch to see whether it is a real bug |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 47 | RelativeTolerance<half> tolerance_fp16(half(0.2)); /**< Tolerance for floating point tests */ |
| 48 | RelativeTolerance<float> tolerance_fp32(0.02f); /**< Tolerance for floating point tests */ |
| 49 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 50 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 51 | constexpr AbsoluteTolerance<int8_t> tolerance_qs8(0); /**< Tolerance for fixed point tests */ |
| 52 | constexpr AbsoluteTolerance<int16_t> tolerance_qs16(0); /**< Tolerance for fixed point tests */ |
| 53 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance for quantized tests */ |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 54 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 55 | /** Direct convolution data set. */ |
| 56 | const auto data = combine(datasets::SmallDirectConvolutionShapes(), |
| 57 | combine(framework::dataset::make("StrideX", 1, 3), |
| 58 | combine(framework::dataset::make("StrideY", 1, 3), |
| 59 | combine(concat(combine(framework::dataset::make("PadX", 0), |
| 60 | combine(framework::dataset::make("PadY", 0), |
| 61 | framework::dataset::make("KernelSize", 1))), |
| 62 | combine(framework::dataset::make("PadX", 0, 2), |
| 63 | combine(framework::dataset::make("PadY", 0, 2), |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 64 | framework::dataset::make("KernelSize", { 3, 5 })))), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 65 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame^] | 66 | const auto data_fixed_point = combine(datasets::TinyDirectConvolutionShapes(), |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 67 | combine(framework::dataset::make("StrideX", 1, 3), |
| 68 | combine(framework::dataset::make("StrideY", 1, 3), |
| 69 | combine(concat(combine(framework::dataset::make("PadX", 0), |
| 70 | combine(framework::dataset::make("PadY", 0), |
| 71 | framework::dataset::make("KernelSize", 1))), |
| 72 | combine(framework::dataset::make("PadX", 0, 2), |
| 73 | combine(framework::dataset::make("PadY", 0, 2), |
| 74 | framework::dataset::make("KernelSize", { 3 })))), |
| 75 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 76 | } // namespace |
| 77 | |
| 78 | TEST_SUITE(CL) |
| 79 | TEST_SUITE(DirectConvolutionLayer) |
| 80 | |
| 81 | //TODO(COMPMID-415): Configuration tests? |
| 82 | |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 83 | // *INDENT-OFF* |
| 84 | // clang-format off |
| 85 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 86 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type input/weights |
| 87 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching input feature maps |
| 88 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Unsupported kernel width |
| 89 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Non-rectangular weights dimensions |
| 90 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid weights dimensions |
| 91 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid stride |
| 92 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid biases size |
| 93 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid biases dimensions |
| 94 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid output size |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 95 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Window shrink |
| 96 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32, 0), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 97 | }), |
| 98 | framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F16, 0), |
| 99 | TensorInfo(TensorShape(3U, 3U, 3U, 4U), 1, DataType::F32, 0), |
| 100 | TensorInfo(TensorShape(9U, 9U, 2U, 4U), 1, DataType::F32, 0), |
| 101 | TensorInfo(TensorShape(5U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 102 | TensorInfo(TensorShape(3U, 3U, 2U, 4U, 3U), 1, DataType::F32, 0), |
| 103 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 104 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 105 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 106 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
| 107 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0), |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 108 | TensorInfo(TensorShape(1U, 1U, 2U, 4U), 1, DataType::F32, 0), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 109 | })), |
| 110 | framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 111 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 112 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 113 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 114 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 115 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 116 | TensorInfo(TensorShape(3U), 1, DataType::F32, 0), |
| 117 | TensorInfo(TensorShape(4U, 2U), 1, DataType::F32, 0), |
| 118 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
| 119 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 120 | TensorInfo(TensorShape(4U), 1, DataType::F32, 0), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 121 | })), |
| 122 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 123 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 124 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 125 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 126 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 127 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 128 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 129 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
| 130 | TensorInfo(TensorShape(26U, 11U, 4U), 1, DataType::F32, 0), |
| 131 | TensorInfo(TensorShape(25U, 11U, 4U), 1, DataType::F32, 0), |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 132 | TensorInfo(TensorShape(32U, 16U, 4U), 1, DataType::F32, 0), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 133 | })), |
| 134 | framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 0, 0), |
| 135 | PadStrideInfo(1, 1, 0, 0), |
| 136 | PadStrideInfo(1, 1, 0, 0), |
| 137 | PadStrideInfo(1, 1, 0, 0), |
| 138 | PadStrideInfo(1, 1, 0, 0), |
| 139 | PadStrideInfo(3, 3, 0, 0), |
| 140 | PadStrideInfo(1, 1, 0, 0), |
| 141 | PadStrideInfo(1, 1, 0, 0), |
| 142 | PadStrideInfo(1, 1, 0, 0), |
| 143 | PadStrideInfo(1, 1, 0, 0), |
Giorgio Arena | 5948634 | 2017-12-01 10:42:47 +0000 | [diff] [blame] | 144 | PadStrideInfo(1, 1, 0, 0), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 145 | })), |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 146 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, false, false, true })), |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 147 | input_info, weights_info, biases_info, output_info, conv_info, expected) |
| 148 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 149 | bool is_valid = bool(CLDirectConvolutionLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &biases_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), conv_info)); |
| 150 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
Georgios Pinitas | 30902ed | 2017-11-14 15:32:57 +0000 | [diff] [blame] | 151 | } |
| 152 | // clang-format on |
| 153 | // *INDENT-ON* |
| 154 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 155 | template <typename T> |
| 156 | using CLDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 157 | template <typename T> |
| 158 | using CLDirectConvolutionValidationWithTensorShapesFixture = DirectConvolutionValidationWithTensorShapesFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 159 | |
| 160 | TEST_SUITE(Float) |
| 161 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 162 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixture<half>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 163 | { |
| 164 | // Validate output |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 165 | validate(CLAccessor(_target), _reference, tolerance_fp16, tolerance_num); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 166 | } |
| 167 | TEST_SUITE_END() |
| 168 | |
| 169 | TEST_SUITE(FP32) |
| 170 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F32))) |
| 171 | { |
| 172 | // Validate output |
| 173 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 174 | } |
| 175 | TEST_SUITE_END() |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 176 | |
| 177 | TEST_SUITE(FP32_CustomDataset) |
| 178 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionValidationWithTensorShapesFixture<float>, framework::DatasetMode::ALL, combine(datasets::DirectConvolutionLayerDataset(), |
| 179 | framework::dataset::make("DataType", DataType::F32))) |
| 180 | { |
| 181 | // Validate output |
| 182 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 183 | } |
| 184 | TEST_SUITE_END() |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 185 | TEST_SUITE_END() |
| 186 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 187 | template <typename T> |
| 188 | using CLDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
| 189 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 190 | TEST_SUITE(FixedPoint) |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 191 | TEST_SUITE(QS8) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 192 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(data_fixed_point, framework::dataset::make("DataType", DataType::QS8)), |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 193 | framework::dataset::make("FractionalBits", 2, 7))) |
| 194 | { |
| 195 | // Validate output |
| 196 | validate(CLAccessor(_target), _reference, tolerance_qs8); |
| 197 | } |
| 198 | TEST_SUITE_END() |
| 199 | |
| 200 | TEST_SUITE(QS16) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 201 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_fixed_point, framework::dataset::make("DataType", DataType::QS16)), |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 202 | framework::dataset::make("FractionalBits", 2, 15))) |
| 203 | { |
| 204 | // Validate output |
| 205 | validate(CLAccessor(_target), _reference, tolerance_qs16); |
| 206 | } |
| 207 | TEST_SUITE_END() |
| 208 | TEST_SUITE_END() |
| 209 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 210 | template <typename T> |
| 211 | using CLDirectConvolutionLayerQuantizedFixture = DirectConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 212 | template <typename T> |
| 213 | using CLDirectConvolutionValidationWithTensorShapesQuantizedFixture = DirectConvolutionValidationWithTensorShapesQuantizedFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 214 | |
| 215 | TEST_SUITE(Quantized) |
| 216 | TEST_SUITE(QASYMM8) |
| 217 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(data, framework::dataset::make("DataType", DataType::QASYMM8)), |
Georgios Pinitas | 6fdfaa8 | 2017-11-29 14:27:24 +0000 | [diff] [blame] | 218 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 10) }))) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 219 | { |
| 220 | // Validate output |
| 221 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 222 | } |
| 223 | TEST_SUITE_END() |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 224 | |
| 225 | TEST_SUITE(QASYMM8_CustomDataset) |
| 226 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionValidationWithTensorShapesQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(datasets::DirectConvolutionLayerDataset(), |
| 227 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 228 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255, 127) }))) |
| 229 | { |
| 230 | // Validate output |
| 231 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 232 | } |
| 233 | TEST_SUITE_END() |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 234 | TEST_SUITE_END() |
| 235 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 236 | TEST_SUITE_END() |
| 237 | TEST_SUITE_END() |
| 238 | } // namespace validation |
| 239 | } // namespace test |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame^] | 240 | } // namespace arm_compute |