Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [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/CLWinogradInputTransformKernel.h" |
| 25 | |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/CL/CLHelpers.h" |
| 28 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/CL/CLValidate.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/CL/ICLTensor.h" |
| 31 | #include "arm_compute/core/CL/OpenCL.h" |
| 32 | #include "arm_compute/core/Error.h" |
| 33 | #include "arm_compute/core/Helpers.h" |
| 34 | #include "arm_compute/core/Types.h" |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 35 | #include "arm_compute/core/Utils.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 36 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 37 | #include "support/StringSupport.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace arm_compute; |
| 40 | |
| 41 | namespace |
| 42 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 43 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 44 | { |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 45 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16); |
| 46 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 47 | |
| 48 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 49 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 50 | const Size2D kernel_size = winograd_info.kernel_size; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 51 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd input transform only supports unit strides"); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!cl_winograd_convolution_layer_supported(output_tile_size, kernel_size, input->data_layout()), "Winograd input transform not supported"); |
| 53 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 54 | ARM_COMPUTE_UNUSED(conv_info); |
| 55 | ARM_COMPUTE_UNUSED(output_tile_size); |
| 56 | ARM_COMPUTE_UNUSED(kernel_size); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 57 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 58 | // Validate configured output |
| 59 | if(output->total_size() != 0) |
| 60 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 61 | const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 62 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 63 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 64 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 65 | } |
| 66 | |
| 67 | return Status{}; |
| 68 | } |
| 69 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 70 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 71 | { |
| 72 | ARM_COMPUTE_UNUSED(output); |
| 73 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 74 | |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 75 | bool window_changed = false; |
| 76 | Window win = calculate_max_window(*input, Steps(1, 1)); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 77 | |
| 78 | if(input->data_layout() == DataLayout::NCHW) |
| 79 | { |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 80 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 81 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 82 | const Size2D kernel_size = winograd_info.kernel_size; |
| 83 | |
| 84 | unsigned int num_elems_read_per_iteration_x = output_tile_size.width + kernel_size.width - 1; |
| 85 | unsigned int num_elems_read_per_iteration_y = output_tile_size.height + kernel_size.height - 1; |
| 86 | |
| 87 | AccessWindowRectangle input_access(input, -conv_info.pad_left(), -conv_info.pad_top(), num_elems_read_per_iteration_x, num_elems_read_per_iteration_y); |
| 88 | window_changed = update_window_and_padding(win, input_access); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 89 | } |
| 90 | else |
| 91 | { |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 92 | AccessWindowStatic input_access(input, 0, -1, input->dimension(0), input->dimension(1) + 1); |
| 93 | window_changed = update_window_and_padding(win, input_access); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 94 | } |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 95 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 96 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 97 | return std::make_pair(err, win); |
| 98 | } |
| 99 | } // namespace |
| 100 | |
| 101 | CLWinogradInputTransformKernel::CLWinogradInputTransformKernel() |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 102 | : _border_size(0), _input(nullptr), _output(nullptr), _data_layout(DataLayout::UNKNOWN), _num_tiles_x(0), _num_tiles_y(0), _step_z(1) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | |
| 106 | BorderSize CLWinogradInputTransformKernel::border_size() const |
| 107 | { |
| 108 | return _border_size; |
| 109 | } |
| 110 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 111 | void CLWinogradInputTransformKernel::configure(const ICLTensor *input, ICLTensor *output, const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 112 | { |
| 113 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 114 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), winograd_info)); |
| 115 | |
| 116 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 117 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 118 | const Size2D kernel_size = winograd_info.kernel_size; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 119 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 120 | _data_layout = input->info()->data_layout(); |
| 121 | |
| 122 | const size_t idx_w = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 123 | const size_t idx_h = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 124 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 125 | // Compute number of elements to process in the X and Y direction |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 126 | const int num_elements_x = input->info()->dimension(idx_w) - (kernel_size.width - 1) + conv_info.pad_left() + conv_info.pad_right(); |
| 127 | const int num_elements_y = input->info()->dimension(idx_h) - (kernel_size.height - 1) + conv_info.pad_top() + conv_info.pad_bottom(); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 128 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 129 | if(_data_layout == DataLayout::NCHW) |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 130 | { |
| 131 | // Check if we need to extend the right or bottom border |
| 132 | const unsigned int extra_border_right = ((num_elements_x % output_tile_size.width) == 0) ? 0u : static_cast<unsigned int>(output_tile_size.width - 1); |
| 133 | const unsigned int extra_border_bottom = ((num_elements_y % output_tile_size.height) == 0) ? 0u : static_cast<unsigned int>(output_tile_size.height - 1); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 134 | |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 135 | _border_size = BorderSize(conv_info.pad_top(), conv_info.pad_right() + extra_border_right, conv_info.pad_bottom() + extra_border_bottom, conv_info.pad_left()); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | _border_size = BorderSize(1U, 0U, 1U, 0); |
| 140 | } |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 141 | |
| 142 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
| 143 | const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(input->info()->dimension(idx_w), input->info()->dimension(idx_h)), |
| 144 | kernel_size, |
| 145 | output_tile_size, |
| 146 | conv_info); |
| 147 | |
| 148 | _input = input; |
| 149 | _output = output; |
| 150 | _num_tiles_x = num_tiles.width; |
| 151 | _num_tiles_y = num_tiles.height; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 152 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 153 | const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input->info(), winograd_info); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 154 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 155 | // Output auto initialization if not yet initialized |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 156 | auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape)); |
| 157 | |
| 158 | ARM_COMPUTE_ERROR_ON(_num_tiles_x * _num_tiles_y != static_cast<int>(output->info()->dimension(1))); |
Georgios Pinitas | ffb57a0 | 2018-10-29 18:01:52 +0000 | [diff] [blame] | 159 | const size_t total_batches = input->info()->tensor_shape().total_size_upper(3); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 160 | |
| 161 | CLBuildOptions build_opts; |
| 162 | build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(_num_tiles_x)); |
| 163 | build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left())); |
| 164 | build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top())); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 165 | build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width)); |
| 166 | build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height)); |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 167 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 168 | build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_INPUT_TRANSFORM_HORIZONTAL"); |
| 169 | build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_INPUT_TRANSFORM_VERTICAL"); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 170 | if(_data_layout == DataLayout::NHWC) |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 171 | { |
Georgios Pinitas | ffb57a0 | 2018-10-29 18:01:52 +0000 | [diff] [blame] | 172 | build_opts.add_option_if(total_batches > 1, "-DNUM_TILES_Y=" + support::cpp11::to_string(_num_tiles_y)); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 173 | build_opts.add_option("-DSRC_DIM_1=" + support::cpp11::to_string(_input->info()->dimension(1))); |
| 174 | build_opts.add_option("-DSRC_DIM_2=" + support::cpp11::to_string(_input->info()->dimension(2))); |
| 175 | } |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 176 | else |
| 177 | { |
Georgios Pinitas | ffb57a0 | 2018-10-29 18:01:52 +0000 | [diff] [blame] | 178 | build_opts.add_option_if(total_batches > 1, "-DSRC_DEPTH=" + support::cpp11::to_string(_input->info()->dimension(2))); |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 179 | } |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 180 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 181 | // Create kernel |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 182 | std::string kernel_name = "winograd_input_transform_" + output_tile_size.to_string() + "_" + kernel_size.to_string(); |
| 183 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 184 | // Get the maximum dimension from the tile size |
| 185 | const unsigned int tile_max_dim = std::max(output_tile_size.width, output_tile_size.height); |
| 186 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 187 | // Check optimized kernel if output_dims == 2x2 |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 188 | if((tile_max_dim == 2) && (_data_layout == DataLayout::NCHW)) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 189 | { |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 190 | _step_z = (_input->info()->dimension(2) % 2) != 0 ? 1 : 2; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 193 | // Append stepz and data layout |
| 194 | kernel_name += "_stepz"; |
| 195 | kernel_name += support::cpp11::to_string(_step_z); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 196 | kernel_name += "_" + lower_string(string_from_data_layout(_data_layout)); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 197 | |
| 198 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); |
| 199 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 200 | // Create window and update padding |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 201 | auto win_config = validate_and_configure_window(input->info(), output->info(), winograd_info); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 202 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 203 | ICLKernel::configure_internal(win_config.second, cl::NDRange(1, 1, 8)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 204 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 205 | _config_id = kernel_name; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 206 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 207 | _config_id += "_"; |
| 208 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 209 | _config_id += "_"; |
| 210 | _config_id += support::cpp11::to_string(input->info()->dimension(2)); |
| 211 | _config_id += "_"; |
| 212 | _config_id += support::cpp11::to_string(conv_info.pad_left()); |
| 213 | _config_id += "_"; |
| 214 | _config_id += support::cpp11::to_string(conv_info.pad_top()); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 215 | _config_id += "_"; |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 216 | _config_id += lower_string(string_from_data_layout(_data_layout)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 219 | Status CLWinogradInputTransformKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 220 | { |
| 221 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 222 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, winograd_info)); |
| 223 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), winograd_info).first); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 224 | |
| 225 | return Status{}; |
| 226 | } |
| 227 | |
| 228 | void CLWinogradInputTransformKernel::run(const Window &window, cl::CommandQueue &queue) |
| 229 | { |
| 230 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 231 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 232 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 233 | const size_t idx_w = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 234 | const size_t idx_h = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 235 | const size_t idx_c = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL); |
| 236 | const size_t total_batches = window.shape().total_size_upper(3); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 237 | |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 238 | // Collapse window |
| 239 | Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); |
| 240 | |
| 241 | Window slice = window_collapsed.first_slice_window_3D(); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 242 | slice.set(idx_w, Window::Dimension(0, _num_tiles_x, 1)); |
| 243 | slice.set(idx_h, Window::Dimension(0, _num_tiles_y, 1)); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 244 | if(_data_layout == DataLayout::NHWC) |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 245 | { |
| 246 | slice.set(idx_h, Window::Dimension(0, _num_tiles_y * total_batches, 1)); |
| 247 | } |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 248 | |
| 249 | ARM_COMPUTE_ERROR_ON(((slice[idx_c].end() - slice[idx_c].start()) % _step_z) != 0); |
| 250 | slice.set(idx_c, Window::Dimension(slice[idx_c].start(), slice[idx_c].end(), _step_z)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 251 | |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 252 | unsigned int idx = 2 * num_arguments_per_3D_tensor(); |
| 253 | _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(_input->info()->strides_in_bytes()[3])); |
| 254 | _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(_output->info()->strides_in_bytes()[3])); |
| 255 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 256 | do |
| 257 | { |
| 258 | unsigned int idx = 0; |
| 259 | add_3D_tensor_argument(idx, _input, slice); |
| 260 | add_3D_tensor_argument(idx, _output, slice); |
| 261 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 262 | enqueue(queue, *this, slice, lws_hint()); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 263 | } |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 264 | while(window_collapsed.slide_window_slice_3D(slice)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 265 | } |