Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +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 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" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/datasets/LargeConvolutionLayerDataset.h" |
| 31 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 32 | #include "tests/datasets/TinyConvolutionLayerDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/framework/datasets/Datasets.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 47 | RelativeTolerance<float> tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 48 | 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 */ |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 49 | constexpr AbsoluteTolerance<float> tolerance_fixed(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */ |
| 50 | constexpr AbsoluteTolerance<float> tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 51 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 52 | |
| 53 | /** CNN data types */ |
| 54 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 55 | { |
| 56 | DataType::F16, |
| 57 | DataType::F32, |
| 58 | DataType::QS8, |
| 59 | DataType::QS16, |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 60 | DataType::QASYMM8, |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 61 | }); |
| 62 | } // namespace |
| 63 | |
| 64 | TEST_SUITE(CL) |
| 65 | TEST_SUITE(ConvolutionLayer) |
| 66 | |
| 67 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes), |
| 68 | input_shape, weights_shape, bias_shape, output_shape, info, data_type) |
| 69 | { |
| 70 | // Set fixed point position data type allowed |
| 71 | int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 72 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 73 | auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
| 74 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 75 | // Create tensors |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 76 | CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 77 | CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 78 | CLTensor bias = create_tensor<CLTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
| 79 | CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127)); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 80 | |
| 81 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 82 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 85 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 86 | const QuantizationInfo src_quantization_info = src.info()->quantization_info(); |
| 87 | const QuantizationInfo weights_quantization_info = weights.info()->quantization_info(); |
| 88 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 89 | // Create and configure function |
| 90 | CLConvolutionLayer conv; |
| 91 | conv.configure(&src, &weights, &bias, &dst, info); |
| 92 | |
| 93 | // Validate valid region |
| 94 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 95 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 96 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 97 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 98 | |
| 99 | validate(src.info()->valid_region(), src_valid_region); |
| 100 | validate(weights.info()->valid_region(), weights_valid_region); |
| 101 | validate(bias.info()->valid_region(), bias_valid_region); |
| 102 | validate(dst.info()->valid_region(), dst_valid_region); |
| 103 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 104 | // Validate QuantizationInfo |
| 105 | ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS); |
| 106 | ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS); |
| 107 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 108 | // Validate padding |
| 109 | //TODO(COMPMID-415) Need to validate padding? |
| 110 | } |
| 111 | |
| 112 | template <typename T> |
| 113 | using CLConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>; |
| 114 | |
| 115 | TEST_SUITE(Float) |
| 116 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 117 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 118 | framework::dataset::make("ReshapeWeights", { true })), |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 119 | framework::dataset::make("DataType", |
| 120 | DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 121 | { |
| 122 | // Validate output |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 123 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 124 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 125 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 126 | framework::dataset::make("ReshapeWeights", { true })), |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 127 | framework::dataset::make("DataType", |
| 128 | DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 129 | { |
| 130 | // Validate output |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 131 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 132 | } |
| 133 | TEST_SUITE_END() |
| 134 | |
| 135 | TEST_SUITE(FP32) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 136 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 137 | framework::dataset::make("ReshapeWeights", { true })), |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 138 | framework::dataset::make("DataType", |
| 139 | DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 140 | { |
| 141 | // Validate output |
| 142 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 143 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 144 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 145 | framework::dataset::make("ReshapeWeights", { true })), |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 146 | framework::dataset::make("DataType", |
| 147 | DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 148 | { |
| 149 | // Validate output |
| 150 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 151 | } |
| 152 | TEST_SUITE_END() |
| 153 | TEST_SUITE_END() |
| 154 | |
| 155 | template <typename T> |
| 156 | using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>; |
| 157 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 158 | TEST_SUITE(FixedPoint) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 159 | TEST_SUITE(QS8) |
| 160 | // We test for fixed point precision [4,6] |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 161 | FIXTURE_DATA_TEST_CASE(RunTiny, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::TinyConvolutionLayerDataset(), |
| 162 | framework::dataset::make("ReshapeWeights", { true })), |
| 163 | framework::dataset::make("DataType", |
| 164 | DataType::QS8)), |
| 165 | framework::dataset::make("FractionalBits", 4, 7))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 166 | { |
| 167 | // Validate output |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 168 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 169 | } |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 170 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 171 | framework::dataset::make("ReshapeWeights", { true })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 172 | framework::dataset::make("DataType", |
| 173 | DataType::QS8)), |
| 174 | framework::dataset::make("FractionalBits", 4, 7))) |
| 175 | { |
| 176 | // Validate output |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 177 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 178 | } |
| 179 | TEST_SUITE_END() |
| 180 | |
| 181 | TEST_SUITE(QS16) |
| 182 | // Testing for fixed point position [1,14) |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 183 | FIXTURE_DATA_TEST_CASE(RunTiny, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::TinyConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 184 | framework::dataset::make("ReshapeWeights", { true })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 185 | framework::dataset::make("DataType", |
| 186 | DataType::QS16)), |
| 187 | framework::dataset::make("FractionalBits", 1, 14))) |
| 188 | { |
| 189 | // Validate output |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 190 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 191 | } |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 192 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 193 | framework::dataset::make("ReshapeWeights", { true })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 194 | framework::dataset::make("DataType", |
| 195 | DataType::QS16)), |
| 196 | framework::dataset::make("FractionalBits", 1, 14))) |
| 197 | { |
| 198 | // Validate output |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 199 | validate(CLAccessor(_target), _reference, tolerance_fixed); |
| 200 | } |
| 201 | TEST_SUITE_END() |
| 202 | TEST_SUITE_END() |
| 203 | |
| 204 | template <typename T> |
| 205 | using CLConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>; |
| 206 | |
| 207 | TEST_SUITE(Quantized) |
| 208 | TEST_SUITE(QASYMM8) |
| 209 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 210 | framework::dataset::make("ReshapeWeights", { true })), |
| 211 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 212 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) }))) |
| 213 | { |
| 214 | // Validate output |
| 215 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 216 | } |
| 217 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 218 | framework::dataset::make("ReshapeWeights", { true })), |
| 219 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 220 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) }))) |
| 221 | { |
| 222 | // Validate output |
| 223 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 224 | } |
| 225 | TEST_SUITE_END() |
| 226 | TEST_SUITE_END() |
| 227 | |
| 228 | TEST_SUITE_END() |
| 229 | TEST_SUITE_END() |
| 230 | } // namespace validation |
| 231 | } // namespace test |
| 232 | } // namespace arm_compute |