Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 CONCLCTION 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/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 | { |
| 46 | RelativeTolerance<float> tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 47 | RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
| 48 | constexpr AbsoluteTolerance<float> tolerance_fixed(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */ |
| 49 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
| 50 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
| 51 | |
| 52 | /** CNN data types */ |
| 53 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 54 | { |
| 55 | DataType::F16, |
| 56 | DataType::F32, |
| 57 | DataType::QS8, |
| 58 | DataType::QS16, |
| 59 | DataType::QASYMM8, |
| 60 | }); |
| 61 | } // namespace |
| 62 | |
| 63 | TEST_SUITE(CL) |
| 64 | TEST_SUITE(DilatedConvolutionLayer) |
| 65 | |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 66 | DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip( |
| 67 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32, 0), |
| 68 | TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32, 0), |
| 69 | TensorInfo(TensorShape(23U, 27U, 5U, 4U), 1, DataType::F32, 0), |
| 70 | TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32, 0), |
| 71 | TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32, 0) |
| 72 | }), |
| 73 | framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32, 0), |
| 74 | TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32, 0), |
| 75 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0), |
| 76 | TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32, 0), |
| 77 | TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16, 0) |
| 78 | })), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 79 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32, 0), |
| 80 | TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32, 0), |
| 81 | TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32, 0), |
| 82 | TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32, 0), |
| 83 | TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32, 0) |
| 84 | })), |
| 85 | framework::dataset::make("ConvInfo", { PadStrideInfo(1, 2, 1, 1), |
| 86 | PadStrideInfo(1, 2, 1, 1), |
| 87 | PadStrideInfo(1, 1, 0, 0), |
| 88 | PadStrideInfo(2, 1, 0, 0), |
| 89 | PadStrideInfo(3, 2, 1, 0) |
| 90 | })), |
| 91 | framework::dataset::make("GpuTarget", { GPUTarget::BIFROST, |
| 92 | GPUTarget::MIDGARD, |
| 93 | GPUTarget::G71, |
| 94 | GPUTarget::MIDGARD, |
| 95 | GPUTarget::BIFROST |
| 96 | })), |
| 97 | framework::dataset::make("Dilation", { Size2D(1U, 1U), |
| 98 | Size2D(1U, 1U), |
| 99 | Size2D(1U, 1U), |
| 100 | Size2D(2U, 2U), |
| 101 | Size2D(3U, 3U) |
| 102 | })), |
| 103 | |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 104 | framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::WINOGRAD, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })), |
| 105 | input_info, weights_info, output_info, conv_info, gpu_target, dilation, expected) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 106 | { |
| 107 | ConvolutionMethod is_valid = CLConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(false), |
| 108 | &weights_info.clone()->set_is_resizable(false), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 109 | &output_info.clone()->set_is_resizable(false), conv_info, WeightsInfo(), ActivationLayerInfo(), gpu_target, dilation); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 110 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 111 | } |
| 112 | TEST_SUITE_END() |
| 113 | |
| 114 | TEST_SUITE(GEMMDilatedConvolutionLayer) |
| 115 | |
| 116 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDilatedConvolutionLayerDataset(), datasets::LargeDilatedConvolutionLayerDataset()), |
| 117 | CNNDataTypes), |
| 118 | input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type) |
| 119 | { |
| 120 | // Set fixed point position data type allowed |
| 121 | int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 122 | |
| 123 | auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
| 124 | |
| 125 | // Create tensors |
| 126 | CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 127 | CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 128 | CLTensor bias = create_tensor<CLTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 129 | CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 130 | |
| 131 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 132 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 133 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 134 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 135 | |
| 136 | const QuantizationInfo src_quantization_info = src.info()->quantization_info(); |
| 137 | const QuantizationInfo weights_quantization_info = weights.info()->quantization_info(); |
| 138 | |
| 139 | // Create and configure function |
| 140 | CLGEMMConvolutionLayer conv; |
| 141 | conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation); |
| 142 | |
| 143 | // Validate valid region |
| 144 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 145 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 146 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 147 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 148 | |
| 149 | validate(src.info()->valid_region(), src_valid_region); |
| 150 | validate(weights.info()->valid_region(), weights_valid_region); |
| 151 | validate(bias.info()->valid_region(), bias_valid_region); |
| 152 | validate(dst.info()->valid_region(), dst_valid_region); |
| 153 | |
| 154 | // Validate QuantizationInfo |
| 155 | ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS); |
| 156 | ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS); |
| 157 | |
| 158 | // Validate padding |
| 159 | //TODO(COMPMID-415) Need to validate padding? |
| 160 | } |
| 161 | |
| 162 | template <typename T> |
| 163 | using CLGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>; |
| 164 | |
| 165 | TEST_SUITE(Float) |
| 166 | TEST_SUITE(FP16) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 167 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 168 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 169 | framework::dataset::make("DataType", DataType::F16)), |
| 170 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 171 | { |
| 172 | // Validate output |
| 173 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 174 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 175 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 176 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 177 | framework::dataset::make("DataType", DataType::F16)), |
| 178 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 179 | { |
| 180 | // Validate output |
| 181 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 182 | } |
| 183 | TEST_SUITE_END() |
| 184 | |
| 185 | TEST_SUITE(FP32) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 186 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 187 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 188 | framework::dataset::make("DataType", DataType::F32)), |
| 189 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 190 | { |
| 191 | // Validate output |
| 192 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 193 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 194 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 195 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 196 | framework::dataset::make("DataType", DataType::F32)), |
| 197 | framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo()))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 198 | { |
| 199 | // Validate output |
| 200 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 201 | } |
| 202 | TEST_SUITE_END() |
| 203 | TEST_SUITE_END() |
| 204 | |
| 205 | template <typename T> |
| 206 | using CLGEMMDilatedConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>; |
| 207 | |
| 208 | TEST_SUITE(FixedPoint) |
| 209 | TEST_SUITE(QS8) |
| 210 | // We test for fixed point precision [4,6] |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 211 | FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMDilatedConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, |
| 212 | combine(combine(combine(combine(datasets::TinyDilatedConvolutionLayerDataset(), |
| 213 | framework::dataset::make("ReshapeWeights", { true })), |
| 214 | framework::dataset::make("DataType", |
| 215 | DataType::QS8)), |
| 216 | framework::dataset::make("FractionalBits", 4, 7)), |
| 217 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 218 | { |
| 219 | // Validate output |
| 220 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
| 221 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 222 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, |
| 223 | combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 224 | framework::dataset::make("ReshapeWeights", { true })), |
| 225 | framework::dataset::make("DataType", |
| 226 | DataType::QS8)), |
| 227 | framework::dataset::make("FractionalBits", 4, 7)), |
| 228 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 229 | { |
| 230 | // Validate output |
| 231 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
| 232 | } |
| 233 | TEST_SUITE_END() |
| 234 | |
| 235 | TEST_SUITE(QS16) |
| 236 | // Testing for fixed point position [1,14) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 237 | FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMDilatedConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, |
| 238 | combine(combine(combine(combine(datasets::TinyDilatedConvolutionLayerDataset(), |
| 239 | framework::dataset::make("ReshapeWeights", { true })), |
| 240 | framework::dataset::make("DataType", |
| 241 | DataType::QS16)), |
| 242 | framework::dataset::make("FractionalBits", 1, 14)), |
| 243 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 244 | { |
| 245 | // Validate output |
| 246 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
| 247 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 248 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, |
| 249 | combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 250 | framework::dataset::make("ReshapeWeights", { true })), |
| 251 | framework::dataset::make("DataType", |
| 252 | DataType::QS16)), |
| 253 | framework::dataset::make("FractionalBits", 1, 14)), |
| 254 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 255 | { |
| 256 | // Validate output |
| 257 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
| 258 | } |
| 259 | TEST_SUITE_END() |
| 260 | TEST_SUITE_END() |
| 261 | |
| 262 | template <typename T> |
| 263 | using CLGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>; |
| 264 | |
| 265 | TEST_SUITE(Quantized) |
| 266 | TEST_SUITE(QASYMM8) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 267 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 268 | combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(), |
| 269 | framework::dataset::make("ReshapeWeights", { true })), |
| 270 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 271 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), |
| 272 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 273 | { |
| 274 | // Validate output |
| 275 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 276 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 277 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, |
| 278 | combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(), |
| 279 | framework::dataset::make("ReshapeWeights", { true })), |
| 280 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 281 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })), |
| 282 | framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() }))) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 283 | { |
| 284 | // Validate output |
| 285 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 286 | } |
| 287 | TEST_SUITE_END() |
| 288 | TEST_SUITE_END() |
| 289 | |
| 290 | TEST_SUITE_END() |
| 291 | TEST_SUITE_END() |
| 292 | } // namespace validation |
| 293 | } // namespace test |
| 294 | } // namespace arm_compute |