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 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" |
| 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" |
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 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 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_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */ |
| 49 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 50 | |
| 51 | /** CNN data types */ |
| 52 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 53 | { |
| 54 | DataType::F16, |
| 55 | DataType::F32, |
| 56 | DataType::QS8, |
| 57 | DataType::QS16, |
| 58 | }); |
| 59 | } // namespace |
| 60 | |
| 61 | TEST_SUITE(CL) |
| 62 | TEST_SUITE(ConvolutionLayer) |
| 63 | |
| 64 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes), |
| 65 | input_shape, weights_shape, bias_shape, output_shape, info, data_type) |
| 66 | { |
| 67 | // Set fixed point position data type allowed |
| 68 | int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 69 | |
| 70 | // Create tensors |
| 71 | CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, fixed_point_position); |
| 72 | CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, fixed_point_position); |
| 73 | CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type, 1, fixed_point_position); |
| 74 | CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position); |
| 75 | |
| 76 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 77 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 78 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 79 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 80 | |
| 81 | // Create and configure function |
| 82 | CLConvolutionLayer conv; |
| 83 | conv.configure(&src, &weights, &bias, &dst, info); |
| 84 | |
| 85 | // Validate valid region |
| 86 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 87 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 88 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 89 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 90 | |
| 91 | validate(src.info()->valid_region(), src_valid_region); |
| 92 | validate(weights.info()->valid_region(), weights_valid_region); |
| 93 | validate(bias.info()->valid_region(), bias_valid_region); |
| 94 | validate(dst.info()->valid_region(), dst_valid_region); |
| 95 | |
| 96 | // Validate padding |
| 97 | //TODO(COMPMID-415) Need to validate padding? |
| 98 | } |
| 99 | |
| 100 | template <typename T> |
| 101 | using CLConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>; |
| 102 | |
| 103 | TEST_SUITE(Float) |
| 104 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 105 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 106 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 107 | framework::dataset::make("DataType", |
| 108 | DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 109 | { |
| 110 | // Validate output |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 111 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 112 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 113 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 114 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 115 | framework::dataset::make("DataType", |
| 116 | DataType::F16))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 117 | { |
| 118 | // Validate output |
steniu01 | 3e05e4e | 2017-08-25 17:18:01 +0100 | [diff] [blame] | 119 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 120 | } |
| 121 | TEST_SUITE_END() |
| 122 | |
| 123 | TEST_SUITE(FP32) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 124 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 125 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 126 | framework::dataset::make("DataType", |
| 127 | DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 128 | { |
| 129 | // Validate output |
| 130 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 131 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 132 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 133 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 134 | framework::dataset::make("DataType", |
| 135 | DataType::F32))) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 136 | { |
| 137 | // Validate output |
| 138 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 139 | } |
| 140 | TEST_SUITE_END() |
| 141 | TEST_SUITE_END() |
| 142 | |
| 143 | template <typename T> |
| 144 | using CLConvolutionLayerFixedPointFixture = ConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLConvolutionLayer, T>; |
| 145 | |
| 146 | TEST_SUITE(Quantized) |
| 147 | TEST_SUITE(QS8) |
| 148 | // We test for fixed point precision [4,6] |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 149 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 150 | framework::dataset::make("ReshapeWeights", { true, false })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 151 | framework::dataset::make("DataType", |
| 152 | DataType::QS8)), |
| 153 | framework::dataset::make("FractionalBits", 4, 7))) |
| 154 | { |
| 155 | // Validate output |
| 156 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 157 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 158 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 159 | framework::dataset::make("ReshapeWeights", { true, false })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 160 | framework::dataset::make("DataType", |
| 161 | DataType::QS8)), |
| 162 | framework::dataset::make("FractionalBits", 4, 7))) |
| 163 | { |
| 164 | // Validate output |
| 165 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 166 | } |
| 167 | TEST_SUITE_END() |
| 168 | |
| 169 | TEST_SUITE(QS16) |
| 170 | // Testing for fixed point position [1,14) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 171 | FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
| 172 | framework::dataset::make("ReshapeWeights", { true, false })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 173 | framework::dataset::make("DataType", |
| 174 | DataType::QS16)), |
| 175 | framework::dataset::make("FractionalBits", 1, 14))) |
| 176 | { |
| 177 | // Validate output |
| 178 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 179 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 180 | FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(), |
| 181 | framework::dataset::make("ReshapeWeights", { true, false })), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 182 | framework::dataset::make("DataType", |
| 183 | DataType::QS16)), |
| 184 | framework::dataset::make("FractionalBits", 1, 14))) |
| 185 | { |
| 186 | // Validate output |
| 187 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 188 | } |
| 189 | TEST_SUITE_END() |
| 190 | TEST_SUITE_END() |
| 191 | |
| 192 | TEST_SUITE_END() |
| 193 | TEST_SUITE_END() |
| 194 | } // namespace validation |
| 195 | } // namespace test |
| 196 | } // namespace arm_compute |