Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 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 | */ |
| 24 | #include "arm_compute/core/CL/kernels/CLConvolutionKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/CL/ICLKernel.h" |
| 29 | #include "arm_compute/core/CL/ICLTensor.h" |
| 30 | #include "arm_compute/core/CL/OpenCL.h" |
| 31 | #include "arm_compute/core/Error.h" |
| 32 | #include "arm_compute/core/Helpers.h" |
| 33 | #include "arm_compute/core/TensorInfo.h" |
| 34 | #include "arm_compute/core/Types.h" |
| 35 | #include "arm_compute/core/Utils.h" |
| 36 | #include "arm_compute/core/Validate.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 37 | #include "support/StringSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | |
| 39 | #include <set> |
| 40 | #include <sstream> |
| 41 | #include <string> |
| 42 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 43 | namespace arm_compute |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | constexpr unsigned int max_matrix_size = 81; |
| 48 | } // namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | |
| 50 | /****************************************************************************************\ |
| 51 | * Square Convolution * |
| 52 | \****************************************************************************************/ |
| 53 | |
| 54 | template <unsigned int matrix_size> |
| 55 | BorderSize CLConvolutionKernel<matrix_size>::border_size() const |
| 56 | { |
| 57 | return BorderSize(matrix_size / 2); |
| 58 | } |
| 59 | |
| 60 | template <unsigned int matrix_size> |
| 61 | void CLConvolutionKernel<matrix_size>::configure(const ICLTensor *input, ICLTensor *output, const int16_t *conv, uint32_t scale, bool border_undefined) |
| 62 | { |
| 63 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); |
| 64 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::S16); |
| 65 | ARM_COMPUTE_ERROR_ON(conv == nullptr); |
| 66 | |
| 67 | _input = input; |
| 68 | _output = output; |
| 69 | |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 70 | std::stringstream kernel_name; |
| 71 | CLBuildOptions build_opts; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | kernel_name << "convolution" << matrix_size << "x" << matrix_size << "_static"; |
| 73 | |
| 74 | if(scale == 0) |
| 75 | { |
| 76 | scale = calculate_matrix_scale(conv, matrix_size); |
| 77 | } |
| 78 | |
| 79 | for(unsigned int i = 0; i < matrix_size * matrix_size; i++) |
| 80 | { |
| 81 | std::stringstream mat_str; |
| 82 | mat_str << "-DMAT" << i << "=" << conv[i]; |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 83 | build_opts.add_option(mat_str.str()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 86 | build_opts.add_option("-DSCALE=" + support::cpp11::to_string(scale)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | |
| 88 | DataType data_type = data_type_for_convolution_matrix(conv, matrix_size * matrix_size); |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 89 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 90 | |
| 91 | std::stringstream out_type; |
| 92 | out_type << "-DDATA_TYPE_OUT=" << get_cl_type_from_data_type(output->info()->data_type()); |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 93 | build_opts.add_option(out_type.str()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 94 | |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 95 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name.str(), build_opts.options())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 96 | |
| 97 | // Configure kernel window |
| 98 | constexpr unsigned int num_elems_processed_per_iteration = 8; |
| 99 | constexpr unsigned int num_elems_written_per_iteration = 8; |
| 100 | constexpr unsigned int num_elems_read_per_iteration = 16; |
| 101 | constexpr unsigned int num_rows_read_per_iteration = matrix_size; |
| 102 | |
| 103 | Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size()); |
| 104 | |
| 105 | AccessWindowRectangle input_access(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration); |
| 106 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration); |
| 107 | |
| 108 | update_window_and_padding(win, input_access, output_access); |
| 109 | |
| 110 | output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size()); |
| 111 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 112 | ICLKernel::configure_internal(win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /****************************************************************************************\ |
| 116 | * Separable Convolution * |
| 117 | \****************************************************************************************/ |
| 118 | template <unsigned int matrix_size> |
| 119 | CLSeparableConvolutionHorKernel<matrix_size>::CLSeparableConvolutionHorKernel() |
| 120 | : _border_size(0) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | template <unsigned int matrix_size> |
| 125 | BorderSize CLSeparableConvolutionHorKernel<matrix_size>::border_size() const |
| 126 | { |
| 127 | return _border_size; |
| 128 | } |
| 129 | |
| 130 | template <unsigned int matrix_size> |
| 131 | void CLSeparableConvolutionHorKernel<matrix_size>::configure(const ICLTensor *input, ICLTensor *output, const int16_t *conv, bool border_undefined) |
| 132 | { |
| 133 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); |
| 134 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U16, DataType::S16, DataType::S32); |
| 135 | |
| 136 | ARM_COMPUTE_ERROR_ON((matrix_size != 5) && (matrix_size != 7) && (matrix_size != 9)); |
| 137 | |
| 138 | _input = input; |
| 139 | _output = output; |
| 140 | _border_size = BorderSize(border_undefined ? 0 : matrix_size / 2, matrix_size / 2); |
| 141 | |
| 142 | // Set build options |
| 143 | std::set<std::string> build_opts; |
| 144 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 145 | std::array<int16_t, matrix_size *matrix_size> mat = { 0 }; |
| 146 | memcpy(mat.data(), conv, matrix_size * sizeof(int16_t)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 147 | |
| 148 | for(unsigned int j = 0; j < matrix_size * matrix_size; j++) |
| 149 | { |
Moritz Pflanzer | 05da6dd | 2017-07-04 12:08:41 +0100 | [diff] [blame] | 150 | build_opts.insert("-DMAT" + support::cpp11::to_string(j) + "=" + support::cpp11::to_string(mat[j])); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | build_opts.insert("-DSCALE=0"); |
| 154 | |
| 155 | build_opts.insert("-DDATA_TYPE=" + get_cl_type_from_data_type(output->info()->data_type())); |
| 156 | |
| 157 | // Create kernel |
Gary Antcliffe | fffbdbc | 2019-05-28 11:40:21 +0100 | [diff] [blame] | 158 | const std::string kernel_name = "convolution_separable1x" + support::cpp11::to_string(matrix_size) + "_static"; |
| 159 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 160 | |
| 161 | // Configure kernel window |
| 162 | constexpr unsigned int num_elems_processed_per_iteration = 8; |
| 163 | constexpr unsigned int num_elems_read_per_iteration = 16; |
| 164 | constexpr unsigned int num_elems_written_per_iteration = 8; |
| 165 | |
| 166 | Window win = calculate_max_window_horizontal(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size()); |
| 167 | |
| 168 | AccessWindowHorizontal input_access(input->info(), -border_size().left, num_elems_read_per_iteration); |
| 169 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration); |
| 170 | |
| 171 | update_window_and_padding(win, input_access, output_access); |
| 172 | |
| 173 | output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size()); |
| 174 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 175 | ICLKernel::configure_internal(win); |
Gary Antcliffe | fffbdbc | 2019-05-28 11:40:21 +0100 | [diff] [blame] | 176 | |
| 177 | // Set config_id for enabling LWS tuning |
| 178 | _config_id = kernel_name; |
| 179 | _config_id += "_"; |
| 180 | _config_id += lower_string(string_from_data_type(input->info()->data_type())); |
| 181 | _config_id += "_"; |
| 182 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 183 | _config_id += "_"; |
| 184 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 185 | _config_id += "_"; |
| 186 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 187 | _config_id += "_"; |
| 188 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
| 189 | _config_id += "_"; |
| 190 | _config_id += support::cpp11::to_string(border_undefined); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | template <unsigned int matrix_size> |
| 194 | BorderSize CLSeparableConvolutionVertKernel<matrix_size>::border_size() const |
| 195 | { |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 196 | return BorderSize{ matrix_size / 2, 0 }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | template <unsigned int matrix_size> |
| 200 | void CLSeparableConvolutionVertKernel<matrix_size>::configure(const ICLTensor *input, ICLTensor *output, |
| 201 | const int16_t *conv, uint32_t scale, bool border_undefined, DataType data_type) |
| 202 | { |
| 203 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U16, DataType::S16, DataType::S32); |
| 204 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::S16); |
| 205 | ARM_COMPUTE_ERROR_ON((matrix_size != 5) && (matrix_size != 7) && (matrix_size != 9)); |
| 206 | ARM_COMPUTE_ERROR_ON(scale == 0); |
| 207 | |
| 208 | _input = input; |
| 209 | _output = output; |
| 210 | |
| 211 | std::set<std::string> build_opts; |
| 212 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 213 | std::array<int16_t, matrix_size *matrix_size> mat = { 0 }; |
| 214 | memcpy(mat.data() + matrix_size, conv, matrix_size * sizeof(int16_t)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 215 | |
| 216 | for(unsigned int j = 0; j < matrix_size * matrix_size; j++) |
| 217 | { |
Moritz Pflanzer | 05da6dd | 2017-07-04 12:08:41 +0100 | [diff] [blame] | 218 | build_opts.insert("-DMAT" + support::cpp11::to_string(j) + "=" + support::cpp11::to_string(mat[j])); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Moritz Pflanzer | 05da6dd | 2017-07-04 12:08:41 +0100 | [diff] [blame] | 221 | build_opts.insert("-DSCALE=" + support::cpp11::to_string(scale)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | |
| 223 | build_opts.insert("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); |
| 224 | |
| 225 | build_opts.insert("-DCOMPUTE_TYPE=" + get_cl_type_from_data_type(data_type)); |
| 226 | |
| 227 | std::stringstream out_type; |
| 228 | out_type << "-DDATA_TYPE_OUT=" << get_cl_type_from_data_type(output->info()->data_type()); |
| 229 | build_opts.insert(out_type.str()); |
| 230 | |
| 231 | // Create kernel |
Gary Antcliffe | fffbdbc | 2019-05-28 11:40:21 +0100 | [diff] [blame] | 232 | const std::string kernel_name = "convolution_separable" + support::cpp11::to_string(matrix_size) + "x1_static"; |
| 233 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 234 | |
| 235 | // Configure kernel window |
| 236 | constexpr unsigned int num_elems_processed_per_iteration = 8; |
| 237 | constexpr unsigned int num_elems_written_per_iteration = 8; |
| 238 | constexpr unsigned int num_elems_read_per_iteration = 8; |
| 239 | constexpr unsigned int num_rows_read_per_iteration = matrix_size; |
| 240 | |
| 241 | Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size()); |
| 242 | |
| 243 | AccessWindowRectangle input_access(input->info(), 0, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration); |
| 244 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration); |
| 245 | |
| 246 | update_window_and_padding(win, input_access, output_access); |
| 247 | |
| 248 | output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size()); |
| 249 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 250 | ICLKernel::configure_internal(win); |
Gary Antcliffe | fffbdbc | 2019-05-28 11:40:21 +0100 | [diff] [blame] | 251 | |
| 252 | // Set config_id for enabling LWS tuning |
| 253 | _config_id = kernel_name; |
| 254 | _config_id += "_"; |
| 255 | _config_id += lower_string(string_from_data_type(data_type)); |
| 256 | _config_id += "_"; |
| 257 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 258 | _config_id += "_"; |
| 259 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 260 | _config_id += "_"; |
| 261 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 262 | _config_id += "_"; |
| 263 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
| 264 | _config_id += "_"; |
| 265 | _config_id += support::cpp11::to_string(border_undefined); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /****************************************************************************************\ |
| 269 | * Rectangle Convolution * |
| 270 | \****************************************************************************************/ |
| 271 | |
| 272 | CLConvolutionRectangleKernel::CLConvolutionRectangleKernel() |
| 273 | : _border_size(0), _input(nullptr), _output(nullptr) |
| 274 | { |
| 275 | } |
| 276 | |
| 277 | BorderSize CLConvolutionRectangleKernel::border_size() const |
| 278 | { |
| 279 | return _border_size; |
| 280 | } |
| 281 | |
| 282 | void CLConvolutionRectangleKernel::configure(const ICLTensor *input, ICLTensor *output, const int16_t *conv, uint32_t width, uint32_t height, uint32_t scale, bool border_undefined) |
| 283 | { |
| 284 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); |
| 285 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::S16); |
| 286 | ARM_COMPUTE_ERROR_ON(nullptr == conv); |
| 287 | ARM_COMPUTE_ERROR_ON(3 != width && 5 != width && 7 != width && 9 != width); |
| 288 | ARM_COMPUTE_ERROR_ON(3 != height && 5 != height && 7 != height && 9 != height); |
| 289 | ARM_COMPUTE_ERROR_ON(0 == scale); |
| 290 | |
| 291 | _input = input; |
| 292 | _output = output; |
| 293 | _border_size = BorderSize(height / 2, width / 2); |
| 294 | |
| 295 | std::set<std::string> options; |
| 296 | |
| 297 | std::stringstream output_type; |
| 298 | output_type << "-DDATA_TYPE_OUT=" << get_cl_type_from_data_type(output->info()->data_type()); |
| 299 | options.insert(output_type.str()); |
| 300 | |
| 301 | uint32_t matrix_size = width * height; |
| 302 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 303 | std::array<int16_t, max_matrix_size> mat = { 0 }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 304 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 305 | memcpy(mat.data(), conv, matrix_size * sizeof(int16_t)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 306 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 307 | for(unsigned int j = 0; j < max_matrix_size; j++) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 308 | { |
Moritz Pflanzer | 05da6dd | 2017-07-04 12:08:41 +0100 | [diff] [blame] | 309 | options.insert("-DMAT" + support::cpp11::to_string(j) + "=" + support::cpp11::to_string(mat[j])); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Moritz Pflanzer | 05da6dd | 2017-07-04 12:08:41 +0100 | [diff] [blame] | 312 | options.insert("-DSCALE=" + support::cpp11::to_string(scale)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 313 | |
| 314 | DataType data_type = data_type_for_convolution_matrix(conv, matrix_size); |
| 315 | options.insert("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
| 316 | |
Moritz Pflanzer | 05da6dd | 2017-07-04 12:08:41 +0100 | [diff] [blame] | 317 | options.insert("-DMATRIX_WIDTH=" + support::cpp11::to_string(width)); |
| 318 | options.insert("-DMATRIX_HEIGHT=" + support::cpp11::to_string(height)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 319 | |
| 320 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("convolution_rectangle", options)); |
| 321 | |
| 322 | // Configure kernel window |
| 323 | constexpr unsigned int num_elems_processed_per_iteration = 8; |
| 324 | constexpr unsigned int num_elems_read_per_iteration = 16; |
| 325 | constexpr unsigned int num_elems_written_per_iteration = 8; |
| 326 | const unsigned int num_rows_read_per_iteration = height; |
| 327 | |
| 328 | Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size()); |
| 329 | |
| 330 | AccessWindowRectangle input_access(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration); |
| 331 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_written_per_iteration); |
| 332 | |
| 333 | update_window_and_padding(win, input_access, output_access); |
| 334 | |
| 335 | output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size()); |
| 336 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 337 | ICLKernel::configure_internal(win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void CLConvolutionRectangleKernel::run(const Window &window, cl::CommandQueue &queue) |
| 341 | { |
| 342 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 343 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 344 | |
| 345 | Window slice = window.first_slice_window_2D(); |
| 346 | |
| 347 | do |
| 348 | { |
| 349 | unsigned int idx = 0; |
| 350 | add_2D_tensor_argument(idx, _input, slice); |
| 351 | add_2D_tensor_argument(idx, _output, slice); |
Michele Di Giorgio | 6b9f388 | 2019-07-01 16:37:04 +0100 | [diff] [blame] | 352 | enqueue(queue, *this, slice, lws_hint()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 353 | } |
| 354 | while(window.slide_window_slice_2D(slice)); |
| 355 | } |
| 356 | |
| 357 | template class arm_compute::CLConvolutionKernel<3>; |
| 358 | template class arm_compute::CLConvolutionKernel<5>; |
| 359 | template class arm_compute::CLConvolutionKernel<7>; |
| 360 | template class arm_compute::CLConvolutionKernel<9>; |
| 361 | template class arm_compute::CLSeparableConvolutionVertKernel<5>; |
| 362 | template class arm_compute::CLSeparableConvolutionVertKernel<7>; |
| 363 | template class arm_compute::CLSeparableConvolutionVertKernel<9>; |
| 364 | template class arm_compute::CLSeparableConvolutionHorKernel<5>; |
| 365 | template class arm_compute::CLSeparableConvolutionHorKernel<7>; |
| 366 | template class arm_compute::CLSeparableConvolutionHorKernel<9>; |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 367 | } // namespace arm_compute |