Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | d175ece | 2020-07-30 23:39:32 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [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, |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 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/CLConvolutionLayer.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h" |
| 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/DilatedConvolutionLayerDataset.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" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
Gian Marco Iodice | 84cb75d | 2018-08-21 11:57:17 +0100 | [diff] [blame] | 46 | RelativeTolerance<float> rel_tolerance_f32(0.05f); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 47 | RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2)); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
Georgios Pinitas | 51e53a3 | 2018-10-22 13:49:08 +0100 | [diff] [blame] | 48 | constexpr AbsoluteTolerance<float> abs_tolerance_qasymm8(1); /**< Relative tolerance value for comparing reference's output against implementation's output for quantized data types */ |
Gian Marco Iodice | 84cb75d | 2018-08-21 11:57:17 +0100 | [diff] [blame] | 49 | constexpr float abs_tolerance_f32 = 0.001f; /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 50 | constexpr float abs_tolerance_f16 = 0.3f; /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 51 | constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */ |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 52 | |
| 53 | /** CNN data types */ |
| 54 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 55 | { |
| 56 | DataType::F16, |
| 57 | DataType::F32, |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 58 | DataType::QASYMM8, |
| 59 | }); |
| 60 | } // namespace |
| 61 | |
| 62 | TEST_SUITE(CL) |
| 63 | TEST_SUITE(DilatedConvolutionLayer) |
| 64 | |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 65 | DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip( |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 66 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32), |
| 67 | TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32), |
| 68 | TensorInfo(TensorShape(23U, 27U, 23U, 4U), 1, DataType::F32), |
| 69 | TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32), |
| 70 | TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32) |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 71 | }), |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 72 | framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32), |
| 74 | TensorInfo(TensorShape(3U, 3U, 23U, 21U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32), |
| 76 | TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16) |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 77 | })), |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 78 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32), |
| 79 | TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32), |
| 80 | TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32), |
| 81 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32), |
| 82 | TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 83 | })), |
| 84 | framework::dataset::make("ConvInfo", { PadStrideInfo(1, 2, 1, 1), |
| 85 | PadStrideInfo(1, 2, 1, 1), |
| 86 | PadStrideInfo(1, 1, 0, 0), |
| 87 | PadStrideInfo(2, 1, 0, 0), |
| 88 | PadStrideInfo(3, 2, 1, 0) |
| 89 | })), |
| 90 | framework::dataset::make("GpuTarget", { GPUTarget::BIFROST, |
| 91 | GPUTarget::MIDGARD, |
| 92 | GPUTarget::G71, |
| 93 | GPUTarget::MIDGARD, |
| 94 | GPUTarget::BIFROST |
| 95 | })), |
| 96 | framework::dataset::make("Dilation", { Size2D(1U, 1U), |
| 97 | Size2D(1U, 1U), |
| 98 | Size2D(1U, 1U), |
| 99 | Size2D(2U, 2U), |
| 100 | Size2D(3U, 3U) |
| 101 | })), |
| 102 | |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 103 | framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::WINOGRAD, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })), |
| 104 | input_info, weights_info, output_info, conv_info, gpu_target, dilation, expected) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 105 | { |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 106 | ConvolutionMethod is_valid = CLConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(true), |
| 107 | &weights_info.clone()->set_is_resizable(true), |
| 108 | &output_info.clone()->set_is_resizable(true), conv_info, WeightsInfo(), ActivationLayerInfo(), gpu_target, dilation); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 109 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 110 | } |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 111 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 112 | TEST_SUITE_END() |
| 113 | |
| 114 | TEST_SUITE(GEMMDilatedConvolutionLayer) |
| 115 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 116 | template <typename T> |
| 117 | using CLGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>; |
| 118 | |
| 119 | TEST_SUITE(Float) |
| 120 | TEST_SUITE(FP16) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 121 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 122 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 123 | framework::dataset::make("DataType", DataType::F16)), |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 124 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 125 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 126 | { |
| 127 | // Validate output |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 128 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.0f, abs_tolerance_f16); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 129 | } |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 130 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 131 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 132 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 133 | framework::dataset::make("DataType", DataType::F16)), |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 134 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 135 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 136 | { |
| 137 | // Validate output |
Gian Marco Iodice | 84cb75d | 2018-08-21 11:57:17 +0100 | [diff] [blame] | 138 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 139 | } |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 140 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 141 | TEST_SUITE_END() |
| 142 | |
| 143 | TEST_SUITE(FP32) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 144 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 145 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 146 | framework::dataset::make("DataType", DataType::F32)), |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 147 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 148 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 149 | { |
| 150 | // Validate output |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 151 | validate(CLAccessor(_target), _reference, rel_tolerance_f32); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 152 | } |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 153 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 154 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 155 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 156 | framework::dataset::make("DataType", DataType::F32)), |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 157 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 158 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 159 | { |
| 160 | // Validate output |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 161 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 162 | } |
| 163 | TEST_SUITE_END() |
| 164 | TEST_SUITE_END() |
| 165 | |
| 166 | template <typename T> |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 167 | using CLGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>; |
| 168 | |
| 169 | TEST_SUITE(Quantized) |
| 170 | TEST_SUITE(QASYMM8) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 171 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 172 | combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 173 | framework::dataset::make("ReshapeWeights", { true })), |
| 174 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 175 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 176 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 177 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 178 | { |
| 179 | // Validate output |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 180 | validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 181 | } |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 182 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 183 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 184 | combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 185 | framework::dataset::make("ReshapeWeights", { true })), |
| 186 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 187 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 188 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })), |
| 189 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 190 | { |
| 191 | // Validate output |
Gian Marco Iodice | bcafc4d | 2018-08-17 11:02:54 +0100 | [diff] [blame] | 192 | validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 193 | } |
| 194 | TEST_SUITE_END() |
| 195 | TEST_SUITE_END() |
| 196 | |
| 197 | TEST_SUITE_END() |
| 198 | TEST_SUITE_END() |
| 199 | } // namespace validation |
| 200 | } // namespace test |
| 201 | } // namespace arm_compute |