Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +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 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEDepthwiseConvolutionLayer3x3Kernel.h" |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 25 | #include "arm_compute/core/NEON/kernels/detail/NEDirectConvolutionDetail.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/AccessWindowStatic.h" |
Georgios Pinitas | 8f5802f | 2019-02-22 11:08:32 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/CPP/Validate.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Coordinates.h" |
| 30 | #include "arm_compute/core/Error.h" |
| 31 | #include "arm_compute/core/Helpers.h" |
| 32 | #include "arm_compute/core/ITensor.h" |
| 33 | #include "arm_compute/core/NEON/INEKernel.h" |
| 34 | #include "arm_compute/core/TensorInfo.h" |
| 35 | #include "arm_compute/core/TensorShape.h" |
| 36 | #include "arm_compute/core/Types.h" |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 37 | #include "arm_compute/core/Utils.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 38 | #include "arm_compute/core/Validate.h" |
| 39 | #include "arm_compute/core/Window.h" |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 40 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 41 | |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 42 | namespace arm_compute |
| 43 | { |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 44 | namespace |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 45 | { |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 46 | template <typename T1, typename T2, unsigned int stridex> |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 47 | class convolver_3x3 |
| 48 | { |
| 49 | public: |
| 50 | static void convolve(const Window &window, unsigned int num_elems_written_per_iteration, |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 51 | const ITensor *input, const ITensor *weights, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 52 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 53 | const int input_offset = -input->info()->quantization_info().uniform().offset; |
| 54 | const int weights_offset = -weights->info()->quantization_info().uniform().offset; |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 55 | |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 56 | const int input_stride_x = input->info()->strides_in_bytes().x(); |
| 57 | const int input_stride_y = input->info()->strides_in_bytes().y(); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 58 | const int input_stride_z = input->info()->strides_in_bytes().z(); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 59 | const int input_stride_w = input->info()->strides_in_bytes()[3]; |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 60 | const int output_stride_y = output->info()->strides_in_bytes().y(); |
| 61 | const int kernel_stride_y = weights->info()->strides_in_bytes().y(); |
| 62 | const int kernel_stride_z = weights->info()->strides_in_bytes().z(); |
| 63 | const int output_w = output->info()->dimension(0); |
| 64 | const int output_h = output->info()->dimension(1); |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 65 | const int delta_input = detail::get_input_num_elems_processed(num_elems_written_per_iteration, stridex); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 66 | const unsigned int conv_stride_y = std::get<1>(conv_info.stride()); |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 67 | const unsigned int conv_pad_x = conv_info.pad_left(); |
| 68 | const unsigned int conv_pad_y = conv_info.pad_top(); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 69 | |
| 70 | // setup output window for the iterator |
| 71 | Window window_out = window; |
| 72 | window_out.set(Window::DimX, Window::Dimension(0, output->info()->dimension(Window::DimX), output->info()->dimension(Window::DimX))); |
| 73 | window_out.set(Window::DimY, Window::Dimension(0, output->info()->dimension(Window::DimY), output->info()->dimension(Window::DimY))); |
| 74 | |
| 75 | // setup input window for the iterator |
| 76 | Window window_in = window; |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 77 | // Iteration of input is taken care of in execute_window_loop |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 78 | window_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 79 | window_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 80 | window_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 81 | |
| 82 | Window window_k = calculate_max_window(*weights->info(), Steps(1u)); |
| 83 | |
| 84 | Iterator in(input, window_in); |
| 85 | Iterator out(output, window_out); |
| 86 | Iterator w(weights, window_k); |
| 87 | |
| 88 | const uint8_t *weights_ptr = w.ptr(); |
| 89 | |
| 90 | execute_window_loop(window_out, [&](const Coordinates & id) |
| 91 | { |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 92 | int ih = 0; |
| 93 | int oh = 0; |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 94 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 95 | const uint8_t *input_ptr = in.ptr() - conv_pad_x * input_stride_x - conv_pad_y * input_stride_y + (id.z() / depth_multiplier) * input_stride_z + input_stride_w * id[3]; |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 96 | const uint8_t *ptr_weights_base = weights_ptr + id.z() * kernel_stride_z; |
| 97 | |
| 98 | const auto ptr_weights_r0 = reinterpret_cast<const T1 *>(ptr_weights_base); |
| 99 | const auto ptr_weights_r1 = reinterpret_cast<const T1 *>(ptr_weights_base + kernel_stride_y); |
| 100 | const auto ptr_weights_r2 = reinterpret_cast<const T1 *>(ptr_weights_base + kernel_stride_y * 2); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 101 | const auto vw_r0 = detail::load_matrix_row(ptr_weights_r0, weights_offset); |
| 102 | const auto vw_r1 = detail::load_matrix_row(ptr_weights_r1, weights_offset); |
| 103 | const auto vw_r2 = detail::load_matrix_row(ptr_weights_r2, weights_offset); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 104 | |
| 105 | for(ih = 0, oh = 0; oh < output_h; ++oh, ih += conv_stride_y) |
| 106 | { |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 107 | auto in_top = reinterpret_cast<const T1 *>(input_ptr + (ih + 0) * input_stride_y); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 108 | auto in_mid = reinterpret_cast<const T1 *>(input_ptr + (ih + dilation.y()) * input_stride_y); |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 109 | auto in_low = reinterpret_cast<const T1 *>(input_ptr + (ih + 2 * dilation.y()) * input_stride_y); // uint8/int8 |
| 110 | auto p_out = reinterpret_cast<T2 *>(out.ptr() + oh * output_stride_y); // int32 |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 111 | |
| 112 | for(int ow = 0; ow < output_w; ow += num_elems_written_per_iteration, |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 113 | in_top += delta_input, in_mid += delta_input, in_low += delta_input, |
| 114 | p_out += num_elems_written_per_iteration) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 115 | { |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 116 | if(dilation == Size2D(1U, 1U)) |
| 117 | { |
Georgios Pinitas | a26e166 | 2020-03-04 15:31:25 +0000 | [diff] [blame] | 118 | detail::convolve_3x3<false>(in_top, in_mid, in_low, p_out, vw_r0, vw_r1, vw_r2, stridex, input_offset); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 122 | auto vres = detail::convolve_3x3_dilation(in_top, in_mid, in_low, vw_r0, vw_r1, vw_r2, dilation.x(), stridex, input_offset); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 123 | detail::store_results<stridex>(p_out, vres); |
| 124 | } |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | }, |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 128 | out); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 129 | } |
| 130 | }; |
| 131 | |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 132 | template <typename T1, typename T2> |
| 133 | inline void convolve_3x3(const Window &window, unsigned int num_elems_written_per_iteration, |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 134 | const ITensor *input, const ITensor *weights, ITensor *output, |
| 135 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation) |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 136 | { |
| 137 | const unsigned int conv_stride_x = std::get<0>(conv_info.stride()); |
| 138 | switch(conv_stride_x) |
| 139 | { |
| 140 | case 1: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 141 | convolver_3x3<T1, T2, 1>::convolve(window, num_elems_written_per_iteration, input, weights, output, conv_info, depth_multiplier, dilation); |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 142 | break; |
| 143 | case 2: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 144 | convolver_3x3<T1, T2, 2>::convolve(window, num_elems_written_per_iteration, input, weights, output, conv_info, depth_multiplier, dilation); |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 145 | break; |
| 146 | case 3: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 147 | convolver_3x3<T1, T2, 3>::convolve(window, num_elems_written_per_iteration, input, weights, output, conv_info, depth_multiplier, dilation); |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 148 | break; |
| 149 | default: |
| 150 | ARM_COMPUTE_ERROR("Not implemented"); |
| 151 | } |
| 152 | } |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 153 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 154 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation) |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 155 | { |
Georgios Pinitas | 8f5802f | 2019-02-22 11:08:32 +0000 | [diff] [blame] | 156 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 157 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::F16, DataType::F32); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 158 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 159 | |
Giorgio Arena | 66cbafb | 2018-08-23 14:51:00 +0100 | [diff] [blame] | 160 | const DataLayout data_layout = input->data_layout(); |
| 161 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 162 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 163 | |
| 164 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(width_idx) != 3 || weights->dimension(height_idx) != 3); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 165 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.stride().first < 1 || conv_info.stride().first > 3); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 166 | |
| 167 | if(output->total_size() != 0) |
| 168 | { |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 169 | const TensorShape output_shape = misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier, dilation); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 170 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 171 | |
Georgios Pinitas | 20c246a | 2018-09-12 16:45:53 +0100 | [diff] [blame] | 172 | if(is_data_type_quantized_asymmetric(input->data_type())) |
| 173 | { |
| 174 | ARM_COMPUTE_RETURN_ERROR_ON(output->data_type() != DataType::S32); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 179 | } |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | return Status{}; |
| 183 | } |
| 184 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 185 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 186 | const Size2D &dilation) |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 187 | { |
| 188 | Window win; |
| 189 | bool window_changed = false; |
| 190 | |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 191 | // Get convolved dimensions |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 192 | const TensorShape output_shape = misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier, dilation); |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 193 | const DataType output_dt = is_data_type_quantized_asymmetric(input->data_type()) ? DataType::S32 : input->data_type(); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 194 | |
| 195 | // Output auto inizialitation if not yet initialized |
Pablo Tello | a28aebc | 2019-06-03 14:59:48 +0100 | [diff] [blame] | 196 | auto_init_if_empty(*output, input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape).set_data_type(output_dt).set_quantization_info(output->quantization_info())); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 197 | |
| 198 | // Configure kernel window (generic) |
| 199 | const unsigned int conv_stride_x = conv_info.stride().first; |
| 200 | const unsigned int conv_stride_y = conv_info.stride().second; |
| 201 | const unsigned int conv_pad_top = conv_info.pad_top(); |
| 202 | const unsigned int conv_pad_left = conv_info.pad_left(); |
| 203 | |
| 204 | unsigned int num_elems_written_per_iteration = 16 >> conv_stride_x; |
| 205 | unsigned int num_elems_read_per_iteration = 0; |
| 206 | |
| 207 | switch(input->data_type()) |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 208 | { |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 209 | case DataType::QASYMM8: |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 210 | case DataType::QASYMM8_SIGNED: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 211 | num_elems_read_per_iteration = 16 + 15 * (dilation.x() - 1); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 212 | break; |
Georgios Pinitas | 20c246a | 2018-09-12 16:45:53 +0100 | [diff] [blame] | 213 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 214 | case DataType::F16: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 215 | num_elems_written_per_iteration = 32 >> conv_stride_x; |
| 216 | num_elems_read_per_iteration = 24 + 23 * (dilation.x() - 1); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 217 | break; |
Georgios Pinitas | 20c246a | 2018-09-12 16:45:53 +0100 | [diff] [blame] | 218 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 219 | case DataType::F32: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 220 | num_elems_read_per_iteration = 12 + 11 * (dilation.x() - 1); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 221 | break; |
| 222 | default: |
| 223 | ARM_COMPUTE_ERROR("Data type not supported."); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 226 | // Configure kernel window |
| 227 | win = calculate_max_window(*output, Steps(num_elems_written_per_iteration)); |
| 228 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 229 | AccessWindowRectangle input_access(input, -conv_pad_left, -conv_pad_top, num_elems_read_per_iteration, 3 + 2 * (dilation.y() - 1), conv_stride_x, conv_stride_y); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 230 | AccessWindowStatic weights_access(weights, 0, 0, 3, 3); |
| 231 | AccessWindowHorizontal output_access(output, 0, num_elems_written_per_iteration); |
| 232 | |
| 233 | window_changed = update_window_and_padding(win, input_access, weights_access, output_access); |
| 234 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 235 | |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 236 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 237 | return std::make_pair(err, win); |
| 238 | } |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 239 | } // namespace |
| 240 | |
| 241 | NEDepthwiseConvolutionLayer3x3Kernel::NEDepthwiseConvolutionLayer3x3Kernel() |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 242 | : _border_size(0), _input(), _output(), _weights(), _conv_info(), _num_elems_written_per_iteration(0), _depth_multiplier(1), _dilation() |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 243 | { |
| 244 | } |
| 245 | |
| 246 | BorderSize NEDepthwiseConvolutionLayer3x3Kernel::border_size() const |
| 247 | { |
| 248 | return _border_size; |
| 249 | } |
| 250 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 251 | void NEDepthwiseConvolutionLayer3x3Kernel::configure(const ITensor *input, const ITensor *weights, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 252 | const Size2D &dilation) |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 253 | { |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 254 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 255 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), weights->info(), output->info(), conv_info, depth_multiplier, dilation)); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 256 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 257 | _input = input; |
| 258 | _output = output; |
| 259 | _weights = weights; |
| 260 | _conv_info = conv_info; |
| 261 | _depth_multiplier = depth_multiplier; |
| 262 | switch(input->info()->data_type()) |
| 263 | { |
| 264 | case DataType::QASYMM8: |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 265 | case DataType::QASYMM8_SIGNED: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 266 | case DataType::F32: |
| 267 | _num_elems_written_per_iteration = 16 >> _conv_info.stride().first; |
| 268 | break; |
| 269 | case DataType::F16: |
| 270 | _num_elems_written_per_iteration = 32 >> _conv_info.stride().first; |
| 271 | break; |
| 272 | default: |
| 273 | ARM_COMPUTE_ERROR("Data type not supported."); |
| 274 | } |
| 275 | _border_size = BorderSize(_conv_info.pad_top(), _conv_info.pad_right(), _conv_info.pad_bottom(), _conv_info.pad_left()); |
| 276 | _dilation = dilation; |
| 277 | auto win_config = validate_and_configure_window(_input->info(), _weights->info(), _output->info(), _conv_info, _depth_multiplier, dilation); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 278 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 279 | INEKernel::configure(win_config.second); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 282 | Status NEDepthwiseConvolutionLayer3x3Kernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, |
| 283 | const Size2D &dilation) |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 284 | { |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 285 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, output, conv_info, depth_multiplier, dilation)); |
| 286 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), output->clone().get(), conv_info, depth_multiplier, dilation).first); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 287 | return Status{}; |
| 288 | } |
| 289 | |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 290 | void NEDepthwiseConvolutionLayer3x3Kernel::run(const Window &window, const ThreadInfo &info) |
| 291 | { |
| 292 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 293 | ARM_COMPUTE_UNUSED(info); |
| 294 | |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 295 | ARM_COMPUTE_UNUSED(info); |
| 296 | |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 297 | switch(_input->info()->data_type()) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 298 | { |
Georgios Pinitas | 20c246a | 2018-09-12 16:45:53 +0100 | [diff] [blame] | 299 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 300 | case DataType::F16: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 301 | convolve_3x3<float16_t, float16_t>(window, _num_elems_written_per_iteration, _input, _weights, _output, _conv_info, _depth_multiplier, _dilation); |
Georgios Pinitas | 20c246a | 2018-09-12 16:45:53 +0100 | [diff] [blame] | 302 | break; |
| 303 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 304 | case DataType::F32: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 305 | convolve_3x3<float, float>(window, _num_elems_written_per_iteration, _input, _weights, _output, _conv_info, _depth_multiplier, _dilation); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 306 | break; |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 307 | case DataType::QASYMM8: |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 308 | convolve_3x3<uint8_t, int32_t>(window, _num_elems_written_per_iteration, _input, _weights, _output, _conv_info, _depth_multiplier, _dilation); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 309 | break; |
Michele Di Giorgio | 13ec5f0 | 2020-01-02 12:11:13 +0000 | [diff] [blame] | 310 | case DataType::QASYMM8_SIGNED: |
| 311 | convolve_3x3<int8_t, int32_t>(window, _num_elems_written_per_iteration, _input, _weights, _output, _conv_info, _depth_multiplier, _dilation); |
| 312 | break; |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 313 | default: |
| 314 | ARM_COMPUTE_ERROR("Not implemented"); |
| 315 | } |
| 316 | } |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 317 | } // namespace arm_compute |