Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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/CLPoolingLayerKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
| 27 | #include "arm_compute/core/CL/CLHelpers.h" |
| 28 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/CL/ICLKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/CL/ICLTensor.h" |
| 31 | #include "arm_compute/core/CL/OpenCL.h" |
| 32 | #include "arm_compute/core/Helpers.h" |
| 33 | #include "arm_compute/core/TensorInfo.h" |
| 34 | #include "arm_compute/core/Utils.h" |
| 35 | #include "arm_compute/core/Validate.h" |
| 36 | #include "arm_compute/core/Window.h" |
| 37 | |
| 38 | #include <set> |
| 39 | #include <string> |
| 40 | #include <tuple> |
| 41 | |
| 42 | using namespace arm_compute; |
| 43 | |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 44 | namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | { |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 46 | // Internal window config info |
| 47 | using CLPoolingConfig = std::pair<unsigned int, BorderSize>; //num_elems_processed_per_iteration, border_size |
| 48 | |
| 49 | void auto_init(const ITensorInfo *input, ITensorInfo *output, unsigned int pooled_w, unsigned int pooled_h) |
| 50 | { |
| 51 | TensorShape output_shape{ input->tensor_shape() }; |
| 52 | output_shape.set(0, pooled_w); |
| 53 | output_shape.set(1, pooled_h); |
| 54 | |
Giorgio Arena | b8ab997 | 2017-11-29 15:09:39 +0000 | [diff] [blame] | 55 | auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 58 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info) |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 59 | { |
| 60 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 61 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32); |
| 62 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((is_data_type_quantized_asymmetric(input->data_type()) && pool_info.pool_type() == PoolingType::L2), |
| 63 | "Unsupported combination of parameters!"); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 64 | |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 65 | const bool is_global_pooling = pool_info.is_global_pooling(); |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 66 | const unsigned int pool_size_x = is_global_pooling ? input->tensor_shape().x() : pool_info.pool_size().width; |
| 67 | const unsigned int pool_size_y = is_global_pooling ? input->tensor_shape().y() : pool_info.pool_size().height; |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 68 | |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 69 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_global_pooling && ((pool_info.pad_stride_info().pad().first >= pool_size_x) || (pool_info.pad_stride_info().pad().second >= pool_size_y)), |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 70 | "Invalid pool size and pool pad combination!"); |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 71 | |
| 72 | // Checks performed when output is configured |
| 73 | if(output->total_size() != 0) |
| 74 | { |
| 75 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); |
| 77 | |
| 78 | unsigned int pooled_w = 0; |
| 79 | unsigned int pooled_h = 0; |
| 80 | std::tie(pooled_w, pooled_h) = scaled_dimensions(input->dimension(0), |
| 81 | input->dimension(1), |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 82 | pool_size_x, |
| 83 | pool_size_y, |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 84 | pool_info.pad_stride_info()); |
Georgios Pinitas | 4c2dd54 | 2017-11-13 12:58:41 +0000 | [diff] [blame] | 85 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((output->dimension(0) != pooled_w) || (output->dimension(1) != pooled_h), |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 86 | "Invalid output pooling dimensions!"); |
| 87 | } |
| 88 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 89 | return Status{}; |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 92 | std::tuple<Status, Window, CLPoolingConfig> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, const PoolingLayerInfo &pool_info) |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 93 | { |
| 94 | int pool_pad_x = 0; |
| 95 | int pool_pad_y = 0; |
| 96 | int pool_stride_x = 0; |
| 97 | int pool_stride_y = 0; |
| 98 | unsigned int pooled_w = 0; |
| 99 | unsigned int pooled_h = 0; |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 100 | int pool_size_x = pool_info.is_global_pooling() ? input->dimension(0) : pool_info.pool_size().width; |
| 101 | int pool_size_y = pool_info.is_global_pooling() ? input->dimension(1) : pool_info.pool_size().height; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 102 | const PadStrideInfo pad_stride_info = pool_info.pad_stride_info(); |
| 103 | std::tie(pool_pad_x, pool_pad_y) = pad_stride_info.pad(); |
| 104 | std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.stride(); |
| 105 | |
| 106 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 107 | |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 108 | // Check output dimensions |
| 109 | std::tie(pooled_w, pooled_h) = scaled_dimensions(input->dimension(0), |
| 110 | input->dimension(1), |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 111 | pool_size_x, |
| 112 | pool_size_y, |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 113 | pad_stride_info); |
| 114 | |
| 115 | auto_init(input, output, pooled_w, pooled_h); |
| 116 | |
| 117 | BorderSize border_size = BorderSize(pool_pad_y, pool_pad_x); |
| 118 | const DataType data_type = input->data_type(); |
| 119 | |
| 120 | const int input_width = input->dimension(0); |
| 121 | const int input_height = input->dimension(1); |
| 122 | |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 123 | // Change the number of elements processed per iteration |
| 124 | // for pooling 3x3 with stride less equal than 3 |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 125 | const bool can_optimize = (pool_size_x == 3) && (pool_size_y == 3) && (pool_stride_x <= 3) && !is_data_type_quantized(data_type); |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 126 | const unsigned int num_elems_processed_per_iteration = can_optimize ? 4 : 1; |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 127 | const int num_elems_read_per_iteration = (num_elems_processed_per_iteration - 1) * pool_stride_x + pool_size_x; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 128 | |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 129 | // Number of iterations in X dimension |
| 130 | const int num_iterations_x = (pooled_w + num_elems_processed_per_iteration - 1) / num_elems_processed_per_iteration; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 131 | |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 132 | // Upper limit for the number of right/bottom border elements that are accessed |
| 133 | const int upper_bound_w = ((num_iterations_x - 1) * num_elems_processed_per_iteration * pool_stride_x - pool_pad_x + num_elems_read_per_iteration) - input_width; |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 134 | const int upper_bound_h = ((pooled_h - 1) * pool_stride_y - pool_pad_y + pool_size_y) - input_height; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 135 | |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 136 | border_size.right = std::max(upper_bound_w, pool_pad_x); |
| 137 | border_size.bottom = std::max(upper_bound_h, pool_pad_y); |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 138 | |
| 139 | Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); |
| 140 | |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 141 | AccessWindowRectangle input_access(input, -pool_pad_x, -pool_pad_y, num_elems_read_per_iteration, pool_size_y, |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 142 | pool_stride_x * num_elems_processed_per_iteration, pool_stride_y); |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 143 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 144 | bool window_changed = update_window_and_padding(win, input_access, output_access); |
| 145 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 146 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 147 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 148 | return std::make_tuple(err, win, CLPoolingConfig(num_elems_processed_per_iteration, border_size)); |
| 149 | } |
| 150 | } // namespace |
| 151 | |
| 152 | CLPoolingLayerKernel::CLPoolingLayerKernel() |
| 153 | : _input(nullptr), _output(nullptr), _pool_info(), _border_size(0), _num_elems_processed_per_iteration(1) |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | BorderSize CLPoolingLayerKernel::border_size() const |
| 158 | { |
| 159 | return _border_size; |
| 160 | } |
| 161 | |
| 162 | void CLPoolingLayerKernel::configure(const ICLTensor *input, ICLTensor *output, const PoolingLayerInfo &pool_info) |
| 163 | { |
| 164 | int pool_pad_x = 0; |
| 165 | int pool_pad_y = 0; |
| 166 | int pool_stride_x = 0; |
| 167 | int pool_stride_y = 0; |
| 168 | unsigned int pooled_w = 0; |
| 169 | unsigned int pooled_h = 0; |
| 170 | const PoolingType pool_type = pool_info.pool_type(); |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 171 | const int pool_size_x = pool_info.is_global_pooling() ? input->info()->dimension(0) : pool_info.pool_size().width; |
| 172 | const int pool_size_y = pool_info.is_global_pooling() ? input->info()->dimension(1) : pool_info.pool_size().height; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 173 | const PadStrideInfo pad_stride_info = pool_info.pad_stride_info(); |
| 174 | const bool exclude_padding = pool_info.exclude_padding(); |
| 175 | std::tie(pool_pad_x, pool_pad_y) = pad_stride_info.pad(); |
| 176 | std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.stride(); |
| 177 | |
| 178 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 179 | |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 180 | // Check output dimensions |
| 181 | std::tie(pooled_w, pooled_h) = scaled_dimensions(input->info()->dimension(0), |
| 182 | input->info()->dimension(1), |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 183 | pool_size_x, |
| 184 | pool_size_y, |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 185 | pad_stride_info); |
| 186 | |
| 187 | auto_init(input->info(), output->info(), pooled_w, pooled_h); |
| 188 | |
Giorgio Arena | f6a43c5 | 2017-12-01 12:16:25 +0000 | [diff] [blame] | 189 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), pool_info)); |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 190 | |
| 191 | // Set instance variables |
| 192 | _input = input; |
| 193 | _output = output; |
| 194 | _pool_info = pool_info; |
| 195 | |
| 196 | const GPUTarget gpu_target = get_arch_from_target(get_target()); |
| 197 | const DataType data_type = input->info()->data_type(); |
| 198 | |
| 199 | // Set build options |
| 200 | CLBuildOptions build_opts; |
| 201 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
| 202 | build_opts.add_option("-DPOOL_" + string_from_pooling_type(pool_type)); |
| 203 | build_opts.add_option_if(is_data_type_fixed_point(data_type), |
| 204 | "-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position())); |
| 205 | build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(pool_stride_x)); |
| 206 | if(pool_type != PoolingType::MAX) |
| 207 | { |
| 208 | build_opts.add_option_if(exclude_padding, "-DEXCLUDE_PADDING"); |
| 209 | build_opts.add_option("-DMAX_WIDTH=" + support::cpp11::to_string(input->info()->dimension(0) + (exclude_padding ? 0 : pool_pad_x))); |
| 210 | build_opts.add_option("-DMAX_HEIGHT=" + support::cpp11::to_string(input->info()->dimension(1) + (exclude_padding ? 0 : pool_pad_y))); |
| 211 | build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(pool_stride_y)); |
| 212 | build_opts.add_option("-DPAD_X=" + support::cpp11::to_string(pool_pad_x)); |
| 213 | build_opts.add_option("-DPAD_Y=" + support::cpp11::to_string(pool_pad_y)); |
| 214 | } |
| 215 | |
| 216 | // Create kernel |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 217 | if((pool_size_x == 3) && (pool_size_y == 3) && !is_data_type_quantized_asymmetric(data_type)) |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 218 | { |
| 219 | // Check if we have pool3x3 with stride_x less equal than 3. In these cases, run an optimized OpenCL kernel where |
| 220 | // each thread computes 4 output elements |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 221 | const bool is_pool3x3_stride_le3 = (pool_size_x == 3) && (pool_size_y == 3) && (pool_stride_x <= 3) && !is_data_type_fixed_point(data_type); |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 222 | |
| 223 | std::string kernel_name = ((is_pool3x3_stride_le3) ? "pooling_layer_optimized_" : "pooling_layer_") |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 224 | + support::cpp11::to_string(pool_size_x); |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 225 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); |
| 226 | } |
| 227 | else // Run general case |
| 228 | { |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 229 | build_opts.add_option("-DPOOL_SIZE_X=" + support::cpp11::to_string(pool_size_x)); |
| 230 | build_opts.add_option("-DPOOL_SIZE_Y=" + support::cpp11::to_string(pool_size_y)); |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 231 | build_opts.add_option_if(data_type == DataType::F16, "-DFP16"); |
| 232 | |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame^] | 233 | std::string kernel_name = is_data_type_quantized_asymmetric(data_type) ? "pooling_layer_MxN_quantized" : "pooling_layer_MxN"; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 234 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); |
| 235 | } |
| 236 | |
| 237 | // Configure kernel window |
| 238 | auto win_config = validate_and_configure_window(input->info(), output->info(), pool_info); |
| 239 | |
| 240 | ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); |
| 241 | |
| 242 | // Configure the local work size (hint) from the first two dimensions of the global work size. |
| 243 | // On Bifrost, this works for up to 35x35xC filters, for which the pooling_layer_3_optimized |
| 244 | // kernel is launched with gws=(9, 33, C). In any case, the hint will be ignored if it is |
| 245 | // invalid (e.g. exceeds the maximum workgroup size that the kernel can be launched with). |
| 246 | if(gpu_target == GPUTarget::BIFROST) |
| 247 | { |
| 248 | cl::NDRange gws = ICLKernel::gws_from_window(std::get<1>(win_config)); |
| 249 | _lws_hint = cl::NDRange(gws[0], gws[1], 1); |
| 250 | } |
| 251 | |
| 252 | ICLKernel::configure(std::get<1>(win_config)); |
| 253 | |
| 254 | CLPoolingConfig pooling_config = std::get<2>(win_config); |
| 255 | _num_elems_processed_per_iteration = pooling_config.first; |
| 256 | _border_size = pooling_config.second; |
| 257 | |
| 258 | // Set config_id for enabling LWS tuning |
| 259 | _config_id = "pooling_layer_"; |
| 260 | _config_id += lower_string(string_from_data_type(data_type)); |
| 261 | _config_id += "_"; |
| 262 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 263 | _config_id += "_"; |
| 264 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
| 265 | } |
| 266 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 267 | Status CLPoolingLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info) |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 268 | { |
| 269 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, pool_info)); |
| 270 | ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get(), pool_info))); |
| 271 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 272 | return Status{}; |
Giorgio Arena | 9f26b3e | 2017-11-28 14:35:00 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 275 | void CLPoolingLayerKernel::run(const Window &window, cl::CommandQueue &queue) |
| 276 | { |
| 277 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 278 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 279 | |
| 280 | unsigned int pool_pad_x, pool_pad_y, pool_stride_x, pool_stride_y = 0; |
| 281 | std::tie(pool_pad_x, pool_pad_y) = _pool_info.pad_stride_info().pad(); |
| 282 | std::tie(pool_stride_x, pool_stride_y) = _pool_info.pad_stride_info().stride(); |
| 283 | |
steniu01 | f70256b | 2017-07-13 14:03:35 +0100 | [diff] [blame] | 284 | Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); |
| 285 | Window slice = window_collapsed.first_slice_window_3D(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 286 | |
| 287 | do |
| 288 | { |
| 289 | // Upsample input by pool size |
| 290 | Window in_slice(slice); |
Diego Lopez Recas | 61ef5bf | 2017-12-11 12:36:55 +0000 | [diff] [blame] | 291 | in_slice.set(Window::DimX, Window::Dimension(in_slice.x().start() - pool_pad_x, |
| 292 | (in_slice.x().end() - pool_pad_x) * pool_stride_x, |
| 293 | pool_stride_x * _num_elems_processed_per_iteration)); |
| 294 | in_slice.set(Window::DimY, Window::Dimension(in_slice.y().start() - pool_pad_y, |
| 295 | (in_slice.y().end() - pool_pad_y) * pool_stride_y, |
| 296 | pool_stride_y)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 297 | |
| 298 | // Set inputs |
| 299 | unsigned int idx = 0; |
| 300 | add_3D_tensor_argument(idx, _input, in_slice); |
| 301 | add_3D_tensor_argument(idx, _output, slice); |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 302 | enqueue(queue, *this, slice, _lws_hint); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 303 | } |
steniu01 | f70256b | 2017-07-13 14:03:35 +0100 | [diff] [blame] | 304 | while(window_collapsed.slide_window_slice_3D(slice)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 305 | } |