Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, 2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/gpu/cl/kernels/ClIm2ColKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/CL/ICLTensor.h" |
| 29 | #include "arm_compute/core/CL/OpenCL.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Helpers.h" |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/TensorInfo.h" |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/Validate.h" |
| 33 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 34 | #include "arm_compute/core/utils/StringUtils.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 35 | #include "src/core/AccessWindowStatic.h" |
| 36 | #include "src/core/CL/CLValidate.h" |
| 37 | #include "src/core/helpers/AutoConfiguration.h" |
| 38 | #include "src/core/helpers/WindowHelpers.h" |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 39 | #include "support/Cast.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 40 | #include "support/StringSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | |
| 42 | #include <cmath> |
| 43 | #include <tuple> |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 44 | #include <utility> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 46 | namespace arm_compute |
| 47 | { |
| 48 | using namespace misc::shape_calculator; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 49 | namespace opencl |
| 50 | { |
| 51 | namespace kernels |
| 52 | { |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 53 | namespace |
| 54 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 55 | struct Im2ColConfiguration |
| 56 | { |
| 57 | std::string kernel_name{}; |
| 58 | std::set<std::string> build_options{}; |
| 59 | unsigned int num_elems_processed_per_iteration{}; |
| 60 | bool is_padding_required_nchw{}; |
| 61 | }; |
| 62 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 63 | Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 64 | unsigned int num_groups) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 65 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 66 | const unsigned int channel_idx = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::CHANNEL); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 67 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 68 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(src); |
| 69 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::F16, DataType::F32); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON(is_data_type_quantized(src->data_type()) && has_bias); |
| 71 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(dst); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 72 | ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1)); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON(src->data_layout() == DataLayout::UNKNOWN); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 74 | ARM_COMPUTE_RETURN_ERROR_ON(num_groups == 0); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 75 | ARM_COMPUTE_RETURN_ERROR_ON(src->data_layout() == DataLayout::NHWC && num_groups > 1); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON((src->dimension(channel_idx) % num_groups) != 0); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 77 | |
SiCong Li | f650ea5 | 2020-08-05 15:04:00 +0100 | [diff] [blame] | 78 | // Since there's no implicit padding added, check the total input spatial dimensions (with conv paddings) are big enough for the kernel dimensions |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 79 | const unsigned int width_idx = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::WIDTH); |
| 80 | const unsigned int height_idx = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::HEIGHT); |
| 81 | const unsigned total_width = src->dimension(width_idx) + conv_info.pad_left() + conv_info.pad_right(); |
| 82 | const unsigned total_height = src->dimension(height_idx) + conv_info.pad_top() + conv_info.pad_bottom(); |
SiCong Li | f650ea5 | 2020-08-05 15:04:00 +0100 | [diff] [blame] | 83 | ARM_COMPUTE_RETURN_ERROR_ON((total_width < kernel_dims.width) || (total_height < kernel_dims.height)); |
| 84 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 85 | if(dst->total_size() > 0) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 86 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 87 | const TensorInfo tensor_info_output = dst->clone()->set_tensor_shape(compute_im2col_conv_shape(src, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups)); |
| 88 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(dst, &tensor_info_output); |
| 89 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst); |
| 90 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(src, dst); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return Status{}; |
| 94 | } |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 95 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 96 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *src, ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 97 | unsigned int num_elems_processed_per_iteration, bool is_padding_required_nchw, unsigned int num_groups) |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 98 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 99 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 100 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 101 | // Output tensor auto initialization if not yet initialized |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 102 | TensorShape expected_output_shape = compute_im2col_conv_shape(src, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 103 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 104 | auto_init_if_empty(*dst, src->clone()->set_tensor_shape(expected_output_shape)); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 105 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 106 | const DataLayout data_layout = src->data_layout(); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 107 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 108 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 109 | const unsigned int input_width = src->dimension(width_idx); |
| 110 | const unsigned int input_height = src->dimension(height_idx); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 111 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 112 | // Configure the execute window based on the selected optimal OpenCL kernel |
| 113 | bool window_changed = false; |
| 114 | Window win; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 115 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 116 | if(data_layout == DataLayout::NHWC) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 117 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 118 | win = calculate_max_window(*src, Steps(num_elems_processed_per_iteration)); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
| 122 | if(is_padding_required_nchw) |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 123 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 124 | const BorderSize border(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left()); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 125 | win = calculate_max_window(*src, |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 126 | Steps(num_elems_processed_per_iteration * conv_info.stride().first, conv_info.stride().second)); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 127 | AccessWindowStatic input_access(src, |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 128 | -border.left, |
| 129 | -border.top, |
| 130 | ceil_to_multiple(input_width + border.right, kernel_dims.width * num_elems_processed_per_iteration), |
| 131 | input_height + border.bottom); |
| 132 | window_changed = window_changed || update_window_and_padding(win, input_access); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 133 | } |
| 134 | else |
| 135 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 136 | // For the generic case, CLIm2ColKernel doesn't need padding (we do not read out-of-bounds elements) so |
| 137 | // update_window_and_padding() can be skipped |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 138 | win = calculate_max_window(*src, Steps()); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 139 | } |
| 140 | } |
Michalis Spyrou | 702dc0c | 2021-03-19 15:06:07 +0000 | [diff] [blame] | 141 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 142 | // set the Z dimension's step same size as the whole dimension so that one can't split across the Z dimension |
| 143 | win.set_dimension_step(Window::DimZ, win[Window::DimZ].end() - win[Window::DimZ].start()); |
| 144 | |
| 145 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 146 | return std::make_pair(err, win); |
| 147 | } |
| 148 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 149 | Im2ColConfiguration configure_opencl_kernel(const ITensorInfo *src, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, unsigned int num_groups) |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 150 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 151 | const DataLayout data_layout = src->data_layout(); |
| 152 | const DataType data_type = src->data_type(); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 153 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 154 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 155 | const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 156 | const unsigned int input_width = src->dimension(width_idx); |
| 157 | const unsigned int input_height = src->dimension(height_idx); |
| 158 | const unsigned int input_channel = src->dimension(channel_idx); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 159 | |
| 160 | const std::pair<unsigned int, unsigned int> convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation); |
| 161 | |
| 162 | // Im2Col configuration |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 163 | std::string kernel_name = "im2col_generic_"; |
| 164 | CLBuildOptions build_opts; |
| 165 | unsigned int num_elems_processed_per_iteration = 1; |
| 166 | bool is_padding_required_nchw = false; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 167 | const UniformQuantizationInfo qinfo = src->quantization_info().uniform(); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 168 | |
| 169 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 170 | build_opts.add_option("-DELEMENT_SIZE=" + support::cpp11::to_string(src->element_size())); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 171 | build_opts.add_option("-DKERNEL_WIDTH=" + support::cpp11::to_string(kernel_dims.width)); |
| 172 | build_opts.add_option("-DKERNEL_HEIGHT=" + support::cpp11::to_string(kernel_dims.height)); |
| 173 | build_opts.add_option("-DCONVOLVED_WIDTH=" + support::cpp11::to_string(convolved_dims.first)); |
| 174 | build_opts.add_option("-DCONVOLVED_HEIGHT=" + support::cpp11::to_string(convolved_dims.second)); |
| 175 | build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.stride().first)); |
| 176 | build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.stride().second)); |
| 177 | build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left())); |
| 178 | build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top())); |
| 179 | build_opts.add_option("-DPAD_RIGHT=" + support::cpp11::to_string(conv_info.pad_right())); |
| 180 | build_opts.add_option("-DPAD_BOTTOM=" + support::cpp11::to_string(conv_info.pad_bottom())); |
| 181 | build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input_width)); |
| 182 | build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(input_height)); |
| 183 | build_opts.add_option("-DSRC_DEPTH=" + support::cpp11::to_string(input_channel)); |
| 184 | build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(dilation.x())); |
| 185 | build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(dilation.y())); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 186 | build_opts.add_option_if(num_groups > 1, "-DNUM_GROUPS=" + support::cpp11::to_string(num_groups)); |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 187 | build_opts.add_option_if_else(is_data_type_quantized(data_type), "-DPAD_VALUE=" + support::cpp11::to_string(qinfo.offset), "-DPAD_VALUE=0"); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 188 | build_opts.add_option_if(has_bias, "-DHAS_BIAS"); |
| 189 | |
| 190 | if(data_layout == DataLayout::NHWC) |
| 191 | { |
SiCong Li | f650ea5 | 2020-08-05 15:04:00 +0100 | [diff] [blame] | 192 | num_elems_processed_per_iteration = std::min(2U, input_channel); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 193 | is_padding_required_nchw = false; |
| 194 | |
Gian Marco Iodice | bf9731e | 2018-12-12 10:18:04 +0000 | [diff] [blame] | 195 | // Only the 3x3 and 9x9 cases are optimized for NHWC |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 196 | if(kernel_dims == Size2D(3U, 3U)) |
| 197 | { |
| 198 | kernel_name = "im2col3x3_"; |
Giorgio Arena | e330fb4 | 2021-11-15 17:03:22 +0000 | [diff] [blame] | 199 | build_opts.add_option("-DIM2COL_3X3"); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 200 | } |
Gian Marco Iodice | bf9731e | 2018-12-12 10:18:04 +0000 | [diff] [blame] | 201 | else if(kernel_dims == Size2D(9U, 9U)) |
| 202 | { |
| 203 | kernel_name = "im2col9x9_"; |
Giorgio Arena | e330fb4 | 2021-11-15 17:03:22 +0000 | [diff] [blame] | 204 | build_opts.add_option("-DIM2COL_9X9"); |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | build_opts.add_option("-DIM2COL_GENERIC"); |
Gian Marco Iodice | bf9731e | 2018-12-12 10:18:04 +0000 | [diff] [blame] | 209 | } |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 210 | |
SiCong Li | f650ea5 | 2020-08-05 15:04:00 +0100 | [diff] [blame] | 211 | // Get boundary vector (the first/last vector with potentially a partial vector size) size |
| 212 | // If input_channel is a multiple of num_elems_processed_per_iteration, the boundary vec size is the (full) vector size |
| 213 | // otherwise, the boundary vec size is the (partial) remainder vector size |
| 214 | const unsigned int vec_size = num_elems_processed_per_iteration; |
| 215 | const unsigned int partial_vec_size = input_channel % vec_size; |
| 216 | const unsigned int boundary_vec_size = vec_size - ((vec_size - partial_vec_size) % vec_size); |
| 217 | build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vec_size)); |
| 218 | build_opts.add_option("-DBOUNDARY_VECTOR_SIZE=" + support::cpp11::to_string(boundary_vec_size)); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 219 | } |
| 220 | else |
| 221 | { |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 222 | if(dilation == Size2D(1U, 1U)) |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 223 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 224 | const bool squared_im2col = kernel_dims.width == kernel_dims.height; |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 225 | if(squared_im2col) |
Anthony Barbier | fcd52fb | 2017-11-28 10:31:43 +0000 | [diff] [blame] | 226 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 227 | // Check if we can run an optimized im2col for NCHW |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 228 | switch(kernel_dims.width) |
| 229 | { |
| 230 | case 1: |
| 231 | // Optimized im2col1x1 if stride_x = 1 and conv_info.has_padding() = false |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 232 | if(conv_info.stride().first == 1 && !conv_info.has_padding()) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 233 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 234 | kernel_name = "im2col1x1_stridex1_"; |
| 235 | num_elems_processed_per_iteration = 4; |
| 236 | is_padding_required_nchw = true; |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 237 | } |
| 238 | break; |
| 239 | case 3: |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 240 | kernel_name = "im2col3x3_"; |
| 241 | num_elems_processed_per_iteration = 1; |
| 242 | is_padding_required_nchw = true; |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 243 | break; |
| 244 | case 5: |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 245 | kernel_name = "im2col5x5_"; |
| 246 | num_elems_processed_per_iteration = 1; |
| 247 | is_padding_required_nchw = true; |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 248 | break; |
| 249 | case 11: |
| 250 | // Optimized im2col11x11 if pad_x = pad_y = 0 |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 251 | if(!conv_info.has_padding()) |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 252 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 253 | kernel_name = "im2col11x11_padx0_pady0_"; |
| 254 | num_elems_processed_per_iteration = 1; |
| 255 | is_padding_required_nchw = true; |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 256 | } |
| 257 | break; |
| 258 | default: |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 259 | kernel_name = "im2col_generic_"; |
| 260 | num_elems_processed_per_iteration = 1; |
| 261 | is_padding_required_nchw = false; |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 262 | break; |
| 263 | } |
Anthony Barbier | fcd52fb | 2017-11-28 10:31:43 +0000 | [diff] [blame] | 264 | } |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 265 | else if(kernel_dims.width > 1 && !conv_info.has_padding()) |
| 266 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 267 | kernel_name = "im2col_generic_padx0_pady0_"; |
| 268 | num_elems_processed_per_iteration = 1; |
| 269 | is_padding_required_nchw = false; |
Anthony Barbier | fcd52fb | 2017-11-28 10:31:43 +0000 | [diff] [blame] | 270 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 271 | // Optimized im2col is performed using one or more vector operations with the specified vector size |
| 272 | // and a remainder. For example, for 5x5 convolutions, im2col is performed using vectors of size 4 |
| 273 | // and scalars; for 7x7 convolutions, using vectors of size 4 and vectors of size 3. |
| 274 | // Using the vector size of 4 is always safe since OpenCL supports vectors of size 2 and 3. |
| 275 | // Using the vector size of 8, however, may be faster. |
| 276 | // For 2x2 convolutions, use vectors of size 2. (For 3x3 convolutions, im2col_kernel3x3_padx0_pady0 |
| 277 | // is used instead.) |
| 278 | const size_t vector_size = std::min(static_cast<size_t>(4), kernel_dims.width); |
| 279 | const size_t width_mod_vector_size = kernel_dims.width % vector_size; |
| 280 | build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vector_size)); |
| 281 | build_opts.add_option("-DWIDTH_MOD_VECTOR_SIZE=" + support::cpp11::to_string(width_mod_vector_size)); |
Anthony Barbier | fcd52fb | 2017-11-28 10:31:43 +0000 | [diff] [blame] | 282 | } |
Anthony Barbier | fcd52fb | 2017-11-28 10:31:43 +0000 | [diff] [blame] | 283 | } |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 286 | // Append the data layout to the kernel_name |
| 287 | kernel_name += lower_string(string_from_data_layout(data_layout)); |
| 288 | |
| 289 | Im2ColConfiguration im2col_config; |
| 290 | im2col_config.kernel_name = kernel_name; |
| 291 | im2col_config.build_options = build_opts.options(); |
| 292 | im2col_config.num_elems_processed_per_iteration = num_elems_processed_per_iteration; |
| 293 | im2col_config.is_padding_required_nchw = is_padding_required_nchw; |
| 294 | |
| 295 | return im2col_config; |
| 296 | } |
| 297 | } // namespace |
| 298 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 299 | ClIm2ColKernel::ClIm2ColKernel() |
| 300 | : _data_layout(DataLayout::UNKNOWN), _convolved_dims(), _num_elems_processed_per_iteration(1), _kernel_dims(), _conv_info(), _num_groups() |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 301 | { |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 302 | _type = CLKernelType::ELEMENTWISE; |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 305 | void ClIm2ColKernel::configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 306 | const Size2D &dilation, |
| 307 | unsigned int num_groups) |
| 308 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 309 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
| 310 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, kernel_dims, conv_info, has_bias, dilation, num_groups)); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 311 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 312 | auto padding_info = get_padding_info({ src, dst }); |
| 313 | _data_layout = src->data_layout(); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 314 | |
| 315 | const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 316 | const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 317 | const unsigned int input_width = src->dimension(width_idx); |
| 318 | const unsigned int input_height = src->dimension(height_idx); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 319 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 320 | // Select and configure the optimal OpenCL kernel to run. |
| 321 | // This function returns the OpenCL kernel's name, the arguments to pass at compile time, the number of elements processed per iteration |
| 322 | // and the padding requirement flag |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 323 | Im2ColConfiguration im2col_config = configure_opencl_kernel(src, kernel_dims, conv_info, has_bias, dilation, num_groups); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 324 | |
| 325 | // Create kernel |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 326 | _kernel = create_kernel(compile_context, im2col_config.kernel_name, im2col_config.build_options); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 327 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 328 | _convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation); |
| 329 | _num_elems_processed_per_iteration = im2col_config.num_elems_processed_per_iteration; |
| 330 | _kernel_dims = kernel_dims; // Only needed by the Tuner |
| 331 | _conv_info = conv_info; // Only needed by the Tuner |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 332 | _num_groups = num_groups; |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 333 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 334 | // Configure kernel window |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 335 | auto win_config = validate_and_configure_window(src, dst, kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration, |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 336 | im2col_config.is_padding_required_nchw, num_groups); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 337 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 338 | IClKernel::configure_internal(win_config.second); |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 339 | |
| 340 | // Set config_id for enabling LWS tuning |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 341 | _config_id = im2col_config.kernel_name; |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 342 | _config_id += "_"; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 343 | _config_id += lower_string(string_from_data_type(src->data_type())); |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 344 | _config_id += "_"; |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 345 | _config_id += support::cpp11::to_string(num_groups); |
| 346 | _config_id += "_"; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 347 | _config_id += support::cpp11::to_string(dst->dimension(0)); |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 348 | _config_id += "_"; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 349 | _config_id += support::cpp11::to_string(dst->dimension(1)); |
Giorgio Arena | 00b93f5 | 2018-06-28 17:18:50 +0100 | [diff] [blame] | 350 | _config_id += "_"; |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 351 | _config_id += lower_string(string_from_data_layout(_data_layout)); |
SiCong Li | 04a0706 | 2020-11-17 14:09:01 +0000 | [diff] [blame] | 352 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 353 | ARM_COMPUTE_ERROR_ON(src->data_layout() == DataLayout::NHWC && has_padding_changed(padding_info)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 356 | Status ClIm2ColKernel::validate(const ITensorInfo *src, const ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 357 | unsigned int num_groups) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 358 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 359 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, kernel_dims, conv_info, has_bias, dilation, num_groups)); |
| 360 | Im2ColConfiguration im2col_config = configure_opencl_kernel(src, kernel_dims, conv_info, has_bias, dilation, num_groups); |
| 361 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), dst->clone().get(), kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration, |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 362 | im2col_config.is_padding_required_nchw, num_groups) |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 363 | .first); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 364 | return Status{}; |
| 365 | } |
| 366 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 367 | void ClIm2ColKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 368 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 369 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 370 | ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(IClKernel::window(), window); |
| 371 | ARM_COMPUTE_ERROR_ON(tensors.empty()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 372 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 373 | // Get initial windows |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 374 | // Collapse in order to have (SRC_DEPTH * BATCH_SIZE) on the 3rd dimension |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 375 | Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 376 | window_collapsed.set_dimension_step(Window::DimZ, 1); |
| 377 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 378 | auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC)); |
| 379 | auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST)); |
| 380 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
| 381 | |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 382 | Window window_output; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 383 | window_output.use_tensor_dimensions(dst->info()->tensor_shape()); |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 384 | |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 385 | const Window first_slice_3d = window_collapsed.first_slice_window_3D(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 386 | |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 387 | Window slice = first_slice_3d; |
| 388 | Window slice_in = first_slice_3d; |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 389 | Window slice_out = window_output.first_slice_window_2D(); |
Pablo Tello | 4a626a7 | 2018-04-04 10:01:14 +0100 | [diff] [blame] | 390 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 391 | if(_data_layout == DataLayout::NHWC) |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 392 | { |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 393 | const Window tmp_win = window.collapse_if_possible(ICLKernel::window(), 3); |
| 394 | const int num_batches = tmp_win[3].end(); |
| 395 | |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 396 | slice.set(1, Window::Dimension(0, static_cast<int>(dst->info()->tensor_shape()[1]), 1)); |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 397 | slice.set(2, Window::Dimension(0, static_cast<int>(num_batches), 1)); |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | slice.set(0, Window::Dimension(0, static_cast<int>(ceil_to_multiple(_convolved_dims.first, _num_elems_processed_per_iteration)), _num_elems_processed_per_iteration)); |
| 402 | slice.set(1, Window::Dimension(0, static_cast<int>(_convolved_dims.second), 1)); |
| 403 | // Note: In case of NCHW the 3rd dimension is already set collapsing the input window |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 404 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 405 | |
| 406 | // Setup input slice |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 407 | // The dimensions of the input are increased within the OpenCL kernel |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 408 | slice_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 409 | slice_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 410 | slice_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 411 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 412 | // Setup output slice |
| 413 | // The dimensions of the output are increased within the OpenCL kernel |
| 414 | slice_out.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 415 | slice_out.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 416 | |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 417 | unsigned int idx = num_arguments_per_3D_tensor() + (_num_groups == 1 ? num_arguments_per_2D_tensor() : num_arguments_per_3D_tensor()); |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 418 | _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src->info()->strides_in_bytes()[3])); |
| 419 | _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(dst->info()->strides_in_bytes()[((_num_groups == 1) ? 2 : 3)])); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 420 | do |
| 421 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 422 | unsigned int idx = 0; |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 423 | add_3D_tensor_argument(idx, src, slice_in); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 424 | if(_num_groups == 1) |
| 425 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 426 | add_2D_tensor_argument(idx, dst, slice_out); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 427 | } |
| 428 | else |
| 429 | { |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 430 | add_3D_tensor_argument(idx, dst, slice_out); |
Giorgio Arena | 0f17039 | 2018-07-18 16:13:12 +0100 | [diff] [blame] | 431 | } |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 432 | enqueue(queue, *this, slice, lws_hint()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 433 | } |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 434 | while(window_collapsed.slide_window_slice_3D(slice) && window_output.slide_window_slice_2D(slice_out) && window_collapsed.slide_window_slice_3D(slice_in)); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 435 | } |
Manuel Bottini | d844c08 | 2021-07-14 12:58:54 +0100 | [diff] [blame] | 436 | } // namespace kernels |
| 437 | } // namespace opencl |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 438 | } // namespace arm_compute |