Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2023 Arm Limited. |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +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 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/utils/StringUtils.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 25 | #include "src/cpu/kernels/CpuDepthwiseConv2dNativeKernel.h" |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 26 | #include "tests/NEON/Accessor.h" |
| 27 | #include "tests/NEON/Helper.h" |
| 28 | #include "tests/framework/Macros.h" |
| 29 | #include "tests/framework/datasets/Datasets.h" |
| 30 | #include "tests/validation/Validation.h" |
| 31 | #include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h" |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace validation |
| 38 | { |
| 39 | using namespace arm_compute::misc::shape_calculator; |
| 40 | |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 41 | // Create function for CpuDepthwiseConvolutionKernel |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 42 | using CpuDepthwiseConvolutionNative = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuDepthwiseConv2dNativeKernel>; |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 43 | |
| 44 | // Fixture for NEDepthwiseConvolutionLayerKernel |
| 45 | template <typename T> |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 46 | using CpuDepthwiseConvolutionNativeFixture = DepthwiseConvolutionLayerNativeValidationFixture<Tensor, Accessor, CpuDepthwiseConvolutionNative, T>; |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 47 | |
| 48 | namespace |
| 49 | { |
| 50 | // *INDENT-OFF* |
| 51 | // clang-format off |
| 52 | RelativeTolerance<float> rel_tolerance_f32(0.001f); |
| 53 | constexpr float abs_tolerance_f32(0.0001f); |
| 54 | |
| 55 | /** Width values to test - Precommit */ |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 56 | const auto width_values_precommit = framework::dataset::make("width", { 17U } ); |
| 57 | |
| 58 | /** Width values to test - Nightly */ |
| 59 | const auto width_values_nightly = framework::dataset::make("width", { 53U, 47U } ); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 60 | |
| 61 | /** Height values to test - Precommit */ |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 62 | const auto height_values_precommit = framework::dataset::make("height", { 19U } ); |
| 63 | |
| 64 | /** Height values to test - Nightly */ |
| 65 | const auto height_values_nightly = framework::dataset::make("height", { 39U, 43U } ); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 66 | |
| 67 | /** Channel values to test - Precommit */ |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 68 | const auto channel_values_precommit = framework::dataset::make("channels", { 15U }); |
| 69 | |
| 70 | /** Channel values to test - Nightly */ |
| 71 | const auto channel_values_nightly = framework::dataset::make("channels", { 33U, 19U }); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 72 | |
| 73 | /** Batch values to test - Precommit */ |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 74 | const auto batch_values_precommit = framework::dataset::make("batch", { 1U, 2U }); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 75 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 76 | /** Batch values to test - Nightly */ |
| 77 | const auto batch_values_nightly = framework::dataset::make("batch", { 1U, 3U }); |
| 78 | |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 79 | /** Kernel size values to test - Precommit */ |
| 80 | const auto kernel_sz_values_precommit = framework::dataset::make("kernel_size", { Size2D(1U, 1U), Size2D(1U, 3U) }); |
| 81 | |
| 82 | /** Kernel size values to test - Nightly */ |
| 83 | const auto kernel_sz_values_nightly = framework::dataset::make("kernel_size", { Size2D(3U, 5U), Size2D(5U, 1U), Size2D(1U, 7U), Size2D(9U, 7U) }); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 84 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 85 | /** Depth multiplier values to test - All */ |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 86 | const auto depth_multiplier_values = framework::dataset::make("depth_multiplier", { 1U, 3U }); |
| 87 | |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 88 | /** Dilation values to test - All */ |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 89 | const auto dilation_values = framework::dataset::make("dilation", { Size2D(1U, 1U), Size2D(3U, 3U) }); |
| 90 | |
| 91 | /** Stride values to test - All */ |
| 92 | const auto stride_values = framework::dataset::make("stride", { Size2D(1U, 1U), Size2D(3U, 2U) }); |
| 93 | |
| 94 | /** Padding values to test - All */ |
| 95 | const auto padding_valid_values = framework::dataset::make("padding_valid", { true, false }); |
| 96 | |
| 97 | /** Data type values to test - All */ |
| 98 | const auto data_type_values = framework::dataset::make("data_type", { DataType::F32 }); |
| 99 | |
| 100 | /** Data layout values to test - All */ |
| 101 | const auto data_layout_values = framework::dataset::make("data_layout", { DataLayout::NHWC }); |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 102 | } // namespace |
| 103 | |
| 104 | TEST_SUITE(NEON) |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 105 | TEST_SUITE(DepthwiseConvolutionLayerNative) |
Sang-Hoon Park | e4558b5 | 2020-10-01 10:13:07 +0100 | [diff] [blame] | 106 | |
| 107 | TEST_CASE(ValidateNoPadding, framework::DatasetMode::ALL) |
| 108 | { |
| 109 | // this test case will ensure that the kernel is not adding implicit padding |
| 110 | constexpr uint32_t vector_size = 8; // Asummed vector size of the current native kernel |
| 111 | constexpr auto depth = vector_size * 2 + 1; // mis-aligned depth to force padding if exists. |
| 112 | constexpr auto data_layout = DataLayout::NHWC; |
| 113 | constexpr auto data_type = DataType::F32; |
| 114 | |
| 115 | const auto input_size = Size2D{ 100, 100 }; // random plane size of the input |
| 116 | const auto kernel_size = Size2D{ 4, 4 }; // random plane size of the kernel |
| 117 | const auto pad_stride_info = PadStrideInfo(3, 3); // random convolution information to |
| 118 | |
| 119 | TensorShape src_shape{ depth, input_size.x(), input_size.y() }; |
| 120 | TensorShape weights_shape{ depth, kernel_size.x(), kernel_size.y() }; |
| 121 | TensorShape bias_shape{ depth }; |
| 122 | |
| 123 | auto src = create_tensor<Tensor>(src_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 124 | auto weights = create_tensor<Tensor>(weights_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 125 | auto biases = create_tensor<Tensor>(bias_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 126 | auto dst = create_tensor<Tensor>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout); |
| 127 | |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 128 | cpu::kernels::CpuDepthwiseConv2dNativeKernel dwc; |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 129 | const ConvolutionInfo info{pad_stride_info, 1, ActivationLayerInfo(), Size2D(1, 1)}; |
| 130 | dwc.configure(src.info(), weights.info(), biases.info(), dst.info(), info); |
Sang-Hoon Park | e4558b5 | 2020-10-01 10:13:07 +0100 | [diff] [blame] | 131 | |
| 132 | ARM_COMPUTE_EXPECT(src.info()->padding().empty(), framework::LogLevel::ERRORS); |
| 133 | ARM_COMPUTE_EXPECT(weights.info()->padding().empty(), framework::LogLevel::ERRORS); |
| 134 | ARM_COMPUTE_EXPECT(biases.info()->padding().empty(), framework::LogLevel::ERRORS); |
| 135 | ARM_COMPUTE_EXPECT(dst.info()->padding().empty(), framework::LogLevel::ERRORS); |
| 136 | } |
| 137 | |
Dana Zlotnik | ebbae94 | 2022-02-03 12:52:15 +0200 | [diff] [blame] | 138 | TEST_SUITE(KERNEL_SELECTION) |
| 139 | DATA_TEST_CASE(KernelSelection_mul_and_add, framework::DatasetMode::ALL, |
| 140 | combine(combine(framework::dataset::make("CpuExt", std::string("NEON")), |
| 141 | framework::dataset::make("DataType", { DataType::F32, |
| 142 | DataType::F16, |
| 143 | DataType::QASYMM8_SIGNED, |
| 144 | DataType::QASYMM8, |
| 145 | DataType::QSYMM8_PER_CHANNEL |
| 146 | })), |
| 147 | framework::dataset::make("DataType_per_channel", { DataType::QASYMM8, |
| 148 | DataType::QASYMM8_SIGNED |
| 149 | })), |
| 150 | cpu_ext, data_type, data_type_per_channel) |
| 151 | { |
| 152 | using namespace cpu::kernels; |
| 153 | |
| 154 | cpuinfo::CpuIsaInfo cpu_isa{}; |
| 155 | cpu_isa.neon = (cpu_ext == "NEON"); |
| 156 | cpu_isa.fp16 = (data_type == DataType::F16); |
| 157 | |
| 158 | const auto *selected_impl = CpuDepthwiseConv2dNativeKernel::get_implementation( |
| 159 | DepthwiseConv2dNativeDataTypeISASelectorData{ data_type, data_type_per_channel,cpu_isa }, |
| 160 | cpu::KernelSelectionType::Preferred ); |
| 161 | |
| 162 | ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl); |
| 163 | |
| 164 | std::string per_channel_str = "_"; |
| 165 | if (data_type == DataType::QSYMM8_PER_CHANNEL) |
| 166 | { |
| 167 | per_channel_str = "_" + cpu_impl_dt(data_type_per_channel) + "_" ; |
| 168 | } |
| 169 | std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + per_channel_str + "deptwiseconv2dnative"; |
| 170 | std::string actual = selected_impl->name; |
| 171 | |
| 172 | ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS); |
| 173 | } |
| 174 | TEST_SUITE_END() // KERNEL_SELECTION |
| 175 | |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 176 | TEST_SUITE(Float) |
| 177 | TEST_SUITE(FP32) |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 178 | FIXTURE_DATA_TEST_CASE_NEW(RunSmall, CpuDepthwiseConvolutionNativeFixture<float>, framework::DatasetMode::ALL, |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 179 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(width_values_precommit, |
| 180 | height_values_precommit), |
| 181 | channel_values_precommit), |
| 182 | batch_values_precommit), |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 183 | kernel_sz_values_precommit), |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 184 | depth_multiplier_values), |
| 185 | dilation_values), |
| 186 | stride_values), |
| 187 | padding_valid_values), |
| 188 | data_type_values), |
| 189 | data_layout_values)) |
| 190 | { |
| 191 | // Validate output |
| 192 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 193 | } |
| 194 | |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 195 | FIXTURE_DATA_TEST_CASE_NEW(RunLarge, CpuDepthwiseConvolutionNativeFixture<float>, framework::DatasetMode::NIGHTLY, |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 196 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(width_values_nightly, |
| 197 | height_values_nightly), |
| 198 | channel_values_nightly), |
| 199 | batch_values_nightly), |
Giorgio Arena | 1720358 | 2019-08-02 16:00:41 +0100 | [diff] [blame] | 200 | kernel_sz_values_nightly), |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 201 | depth_multiplier_values), |
| 202 | dilation_values), |
| 203 | stride_values), |
| 204 | padding_valid_values), |
| 205 | data_type_values), |
| 206 | data_layout_values)) |
| 207 | { |
| 208 | // Validate output |
| 209 | validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 210 | } |
| 211 | |
| 212 | TEST_SUITE_END() // FP32 |
| 213 | TEST_SUITE_END() // Float |
Gian Marco Iodice | bd9097d | 2019-07-26 15:31:02 +0100 | [diff] [blame] | 214 | TEST_SUITE_END() // DepthwiseConvolutionLayerNative |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 215 | TEST_SUITE_END() // Neon |
Giorgio Arena | 44f5572 | 2019-07-12 14:49:49 +0100 | [diff] [blame] | 216 | } // namespace validation |
| 217 | } // namespace test |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 218 | } // namespace arm_compute |