Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 1 | /* |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +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, |
| 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" |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 25 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
| 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/DepthwiseConvolutionLayerDataset.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/DepthwiseConvolutionLayerFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 44 | using namespace arm_compute::misc::shape_calculator; |
| 45 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 46 | namespace |
| 47 | { |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 48 | constexpr RelativeTolerance<float> tolerance_f32(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 49 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for DataType::QASYMM8 */ |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 50 | |
| 51 | const auto depth_multipliers = framework::dataset::make("DepthMultiplier", { 1, 2, 3 }); |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 52 | } // namespace |
| 53 | |
| 54 | TEST_SUITE(NEON) |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 55 | TEST_SUITE(DepthwiseConvLayer) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 56 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 57 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), |
| 58 | datasets::LargeDepthwiseConvolutionLayerDataset3x3()), |
| 59 | depth_multipliers), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 60 | framework::dataset::make("DataType", DataType::F32)), |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 61 | input_shape, kernel_size, info, depth_multiplier, data_type) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 62 | { |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 63 | // Get shapes |
| 64 | TensorShape weights_shape(kernel_size.width, kernel_size.height); |
| 65 | |
| 66 | const TensorInfo in_info(input_shape, 1, data_type); |
| 67 | const TensorInfo we_info(weights_shape, 1, data_type); |
| 68 | const TensorShape output_shape = compute_depthwise_convolution_shape(in_info, we_info, info, depth_multiplier); |
| 69 | |
| 70 | weights_shape.set(2, output_shape.z()); |
| 71 | |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 72 | // Create tensors |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 73 | Tensor src = create_tensor<Tensor>(input_shape, data_type); |
| 74 | Tensor dst = create_tensor<Tensor>(output_shape, data_type); |
| 75 | Tensor weights = create_tensor<Tensor>(weights_shape, data_type); |
| 76 | const TensorShape bias_shape(weights_shape[2]); |
| 77 | Tensor bias = create_tensor<Tensor>(bias_shape, data_type); |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 78 | |
| 79 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 80 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 81 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 82 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | |
| 84 | // Create and configure function |
| 85 | NEDepthwiseConvolutionLayer3x3 depthwise_layer; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 86 | depthwise_layer.configure(&src, &weights, &bias, &dst, info, depth_multiplier); |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 87 | |
| 88 | // Validate valid region |
| 89 | const ValidRegion input_valid_region = shape_to_valid_region(input_shape); |
| 90 | const ValidRegion output_valid_region = shape_to_valid_region(output_shape); |
| 91 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 92 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 93 | |
| 94 | validate(src.info()->valid_region(), input_valid_region); |
| 95 | validate(dst.info()->valid_region(), output_valid_region); |
| 96 | validate(weights.info()->valid_region(), weights_valid_region); |
| 97 | validate(bias.info()->valid_region(), bias_valid_region); |
| 98 | |
| 99 | // Validate padding |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 100 | bool is_optimized_run = NEDepthwiseConvolutionLayer3x3Kernel::is_optimized_execution_possible(input_shape, info, data_type, depth_multiplier, DataLayout::NCHW); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 101 | const int step_non_opt_dwc = 16 >> info.stride().first; |
| 102 | const int step_bias_add = 16 / src.info()->element_size(); |
| 103 | const int step = is_optimized_run ? step_bias_add : std::max(step_non_opt_dwc, step_bias_add); |
| 104 | const PaddingSize padding = PaddingCalculator(output_shape.x(), step).required_padding(); |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 105 | validate(dst.info()->padding(), padding); |
| 106 | } |
| 107 | |
| 108 | TEST_SUITE(Float) |
| 109 | TEST_SUITE(F32) |
| 110 | TEST_SUITE(Generic) |
| 111 | template <typename T> |
| 112 | using NEDepthwiseConvolutionLayerFixture = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 113 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(), |
| 114 | depth_multipliers), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 115 | framework::dataset::make("DataType", |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 116 | DataType::F32)), |
| 117 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 118 | { |
| 119 | validate(Accessor(_target), _reference, tolerance_f32); |
| 120 | } |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 121 | FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset(), |
| 122 | depth_multipliers), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 123 | framework::dataset::make("DataType", |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 124 | DataType::F32)), |
| 125 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 126 | { |
| 127 | validate(Accessor(_target), _reference, tolerance_f32); |
| 128 | } |
| 129 | TEST_SUITE_END() |
| 130 | |
| 131 | TEST_SUITE(W3x3) |
| 132 | template <typename T> |
| 133 | using NEDepthwiseConvolutionLayerFixture3x3 = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 134 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), |
| 135 | depth_multipliers), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 136 | framework::dataset::make("DataType", |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 137 | DataType::F32)), |
| 138 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 139 | { |
| 140 | validate(Accessor(_target), _reference, tolerance_f32); |
| 141 | } |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 142 | FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(), |
| 143 | depth_multipliers), |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 144 | framework::dataset::make("DataType", |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 145 | DataType::F32)), |
| 146 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 147 | { |
| 148 | validate(Accessor(_target), _reference, tolerance_f32); |
| 149 | } |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 150 | FIXTURE_DATA_TEST_CASE(RunOptimized, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::OptimizedDepthwiseConvolutionLayerDataset3x3(), |
| 151 | framework::dataset::make("DepthMultiplier", 1)), |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 152 | framework::dataset::make("DataType", |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 153 | DataType::F32)), |
| 154 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 155 | { |
| 156 | validate(Accessor(_target), _reference, tolerance_f32); |
| 157 | } |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 158 | TEST_SUITE_END() |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 159 | TEST_SUITE_END() |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 160 | |
| 161 | TEST_SUITE_END() |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 162 | |
| 163 | template <typename T> |
| 164 | using NEDepthwiseConvolutionLayerQuantizedFixture3x3 = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 165 | template <typename T> |
| 166 | using NEDepthwiseConvolutionLayerQuantizedFixture = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>; |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 167 | |
| 168 | TEST_SUITE(Quantized) |
| 169 | TEST_SUITE(QASYMM8) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 170 | TEST_SUITE(Generic) |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 171 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 172 | combine(combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(), |
| 173 | depth_multipliers), |
| 174 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 175 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })), |
| 176 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 177 | { |
| 178 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 179 | } |
| 180 | TEST_SUITE_END() |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 181 | TEST_SUITE(W3x3) |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 182 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::PRECOMMIT, |
| 183 | combine(combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), depth_multipliers), |
| 184 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 185 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })), |
| 186 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 187 | { |
| 188 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 189 | } |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 190 | FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::NIGHTLY, |
| 191 | combine(combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(), |
| 192 | depth_multipliers), |
| 193 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 194 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })), |
| 195 | framework::dataset::make("DataLayout", DataLayout::NCHW))) |
Anthony Barbier | f45d5a9 | 2018-01-24 16:23:15 +0000 | [diff] [blame] | 196 | { |
| 197 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 198 | } |
| 199 | TEST_SUITE_END() |
| 200 | TEST_SUITE_END() |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 201 | TEST_SUITE_END() |
| 202 | |
| 203 | TEST_SUITE_END() |
| 204 | TEST_SUITE_END() |
| 205 | } // namespace validation |
| 206 | } // namespace test |
| 207 | } // namespace arm_compute |