Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2023 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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/gpu/cl/kernels/ClWinogradInputTransformKernel.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [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" |
| 30 | #include "arm_compute/core/Error.h" |
| 31 | #include "arm_compute/core/Helpers.h" |
| 32 | #include "arm_compute/core/Types.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" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 35 | |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 36 | #include "src/core/AccessWindowStatic.h" |
| 37 | #include "src/core/CL/CLValidate.h" |
| 38 | #include "src/core/helpers/AutoConfiguration.h" |
| 39 | #include "src/core/helpers/WindowHelpers.h" |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 40 | #include "support/Cast.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 41 | #include "support/StringSupport.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 42 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 43 | namespace arm_compute |
| 44 | { |
| 45 | namespace opencl |
| 46 | { |
| 47 | namespace kernels |
| 48 | { |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 49 | namespace |
| 50 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 51 | 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] | 52 | { |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 53 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16); |
| 54 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 55 | |
| 56 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 57 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 58 | const Size2D kernel_size = winograd_info.kernel_size; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, |
| 60 | "Winograd input transform only supports unit strides"); |
| 61 | ARM_COMPUTE_RETURN_ERROR_ON_MSG( |
| 62 | !cl_winograd_convolution_layer_supported(output_tile_size, kernel_size, input->data_layout()), |
| 63 | "Winograd input transform not supported"); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 64 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_UNUSED(conv_info); |
| 66 | ARM_COMPUTE_UNUSED(output_tile_size); |
| 67 | ARM_COMPUTE_UNUSED(kernel_size); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 68 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 69 | // Validate configured output |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 70 | if (output->total_size() != 0) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 71 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 72 | const TensorShape output_shape = |
| 73 | misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 74 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 75 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 77 | } |
| 78 | |
| 79 | return Status{}; |
| 80 | } |
| 81 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | std::pair<Status, Window> |
| 83 | validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 84 | { |
| 85 | ARM_COMPUTE_UNUSED(output); |
| 86 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 87 | |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 88 | bool window_changed = false; |
| 89 | int num_elems_processed_per_iteration = 1; |
| 90 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 91 | if (input->data_layout() == DataLayout::NHWC) |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 92 | { |
| 93 | // In the case of FP16 computation, we can perform more |
| 94 | // output feature maps in a single work-item. |
| 95 | // From experiments, num_elems_processed_per_iteration = 2 looks good for fp16 to |
| 96 | // improve the performance. However, in order to make the implementation simpler, |
| 97 | // we set num_elems_processed_per_iteration = 2 only when the OFMs are multiple of 2. |
| 98 | // Note: At the moment, only Winograd Input Transform 3x3 can support N0 != 1 |
| 99 | const DataType dt = input->data_type(); |
| 100 | const size_t dim0 = input->dimension(0); |
| 101 | const size_t k_sz = winograd_info.kernel_size.area(); |
| 102 | const bool cond = dt == DataType::F16 && ((dim0 % 2) == 0); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 103 | if (cond) |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 104 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 105 | if (k_sz == 3 || k_sz == 9) |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 106 | { |
| 107 | num_elems_processed_per_iteration = 2; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 112 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 113 | if (input->data_layout() == DataLayout::NCHW) |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 114 | { |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 115 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 116 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 117 | const Size2D kernel_size = winograd_info.kernel_size; |
| 118 | |
| 119 | unsigned int num_elems_read_per_iteration_x = output_tile_size.width + kernel_size.width - 1; |
| 120 | unsigned int num_elems_read_per_iteration_y = output_tile_size.height + kernel_size.height - 1; |
| 121 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 122 | AccessWindowRectangle input_access(input, -conv_info.pad_left(), -conv_info.pad_top(), |
| 123 | num_elems_read_per_iteration_x, num_elems_read_per_iteration_y); |
Giorgio Arena | 149fdf3 | 2018-07-04 17:03:33 +0100 | [diff] [blame] | 124 | window_changed = update_window_and_padding(win, input_access); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 125 | } |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 126 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 127 | Status err = |
| 128 | (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 129 | return std::make_pair(err, win); |
| 130 | } |
| 131 | } // namespace |
| 132 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 133 | ClWinogradInputTransformKernel::ClWinogradInputTransformKernel() |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 134 | { |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 135 | _type = CLKernelType::WINOGRAD; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 138 | BorderSize ClWinogradInputTransformKernel::border_size() const |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 139 | { |
| 140 | return _border_size; |
| 141 | } |
| 142 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 143 | void ClWinogradInputTransformKernel::configure(const ClCompileContext &compile_context, |
| 144 | ITensorInfo *src, |
| 145 | ITensorInfo *dst, |
| 146 | const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 147 | { |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 148 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
| 149 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, winograd_info)); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 150 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 151 | auto padding_info = get_padding_info({src, dst}); |
SiCong Li | 04a0706 | 2020-11-17 14:09:01 +0000 | [diff] [blame] | 152 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 153 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 154 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 155 | const Size2D kernel_size = winograd_info.kernel_size; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 156 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 157 | _data_layout = src->data_layout(); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 158 | |
| 159 | const size_t idx_w = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 160 | 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] | 161 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 162 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 163 | const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(src->dimension(idx_w), src->dimension(idx_h)), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 164 | kernel_size, output_tile_size, conv_info); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 165 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 166 | _num_tiles_x = num_tiles.width; |
| 167 | _num_tiles_y = num_tiles.height; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 168 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 169 | const TensorShape output_shape = |
| 170 | misc::shape_calculator::compute_winograd_input_transform_shape(*src, winograd_info); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 171 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 172 | // Output auto initialization if not yet initialized |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 173 | auto_init_if_empty(*dst, src->clone()->set_tensor_shape(output_shape)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 174 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 175 | ARM_COMPUTE_ERROR_ON(_num_tiles_x * _num_tiles_y != static_cast<int>(dst->dimension(1))); |
| 176 | const size_t total_batches = src->tensor_shape().total_size_upper(3); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 177 | |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 178 | // Create window and update padding |
| 179 | auto win_config = validate_and_configure_window(src, dst, winograd_info); |
| 180 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 181 | IClKernel::configure_internal(win_config.second, cl::NDRange(1, 1, 8)); |
| 182 | |
| 183 | _src_width = src->dimension(idx_w); |
| 184 | _src_height = src->dimension(idx_h); |
| 185 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 186 | CLBuildOptions build_opts; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 187 | if (_data_layout == DataLayout::NHWC) |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 188 | { |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 189 | build_opts.add_option("-DNHWC"); |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 190 | build_opts.add_option("-DN0=" + support::cpp11::to_string(win_config.second.x().step())); |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 191 | build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left())); |
| 192 | build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top())); |
| 193 | build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width)); |
| 194 | build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height)); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 195 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src->data_type())); |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 196 | build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_INPUT_TRANSFORM_HORIZONTAL"); |
| 197 | build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_INPUT_TRANSFORM_VERTICAL"); |
Gian Marco Iodice | 905a3c1 | 2023-04-14 12:20:58 +0100 | [diff] [blame] | 198 | build_opts.add_option_if(total_batches > 1, "-DIS_BATCHED"); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 199 | } |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 200 | else |
| 201 | { |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 202 | build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(_num_tiles_x)); |
| 203 | build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left())); |
| 204 | build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top())); |
| 205 | build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width)); |
| 206 | build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height)); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 207 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src->data_type())); |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 208 | build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_INPUT_TRANSFORM_HORIZONTAL"); |
| 209 | build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_INPUT_TRANSFORM_VERTICAL"); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 210 | build_opts.add_option_if(total_batches > 1, "-DSRC_DEPTH=" + support::cpp11::to_string(src->dimension(2))); |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 211 | } |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 212 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 213 | // Create kernel |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 214 | std::string kernel_name = |
| 215 | "winograd_input_transform_" + output_tile_size.to_string() + "_" + kernel_size.to_string(); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 216 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 217 | // Get the maximum dimension from the tile size |
| 218 | const unsigned int tile_max_dim = std::max(output_tile_size.width, output_tile_size.height); |
| 219 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 220 | // Check optimized kernel if output_dims == 2x2 |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 221 | if ((tile_max_dim == 2) && (_data_layout == DataLayout::NCHW)) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 222 | { |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 223 | _step_z = (src->dimension(2) % 2) != 0 ? 1 : 2; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 226 | // Append stepz and data layout |
| 227 | kernel_name += "_stepz"; |
| 228 | kernel_name += support::cpp11::to_string(_step_z); |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 229 | kernel_name += "_" + lower_string(string_from_data_layout(_data_layout)); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 230 | |
ramelg01 | 2a86a30 | 2022-02-04 20:49:14 +0000 | [diff] [blame] | 231 | // A macro guard to compile ONLY the kernel of interest |
| 232 | build_opts.add_option("-D" + upper_string(kernel_name)); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 233 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 234 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 235 | _border_size = BorderSize(src->padding()); |
Giorgio Arena | 2567adf | 2020-12-14 10:50:50 +0000 | [diff] [blame] | 236 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 237 | ARM_COMPUTE_ERROR_ON((src->data_layout() == DataLayout::NHWC) && has_padding_changed(padding_info)); |
SiCong Li | 04a0706 | 2020-11-17 14:09:01 +0000 | [diff] [blame] | 238 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 239 | _config_id = kernel_name; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 240 | _config_id += support::cpp11::to_string(src->dimension(0)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 241 | _config_id += "_"; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 242 | _config_id += support::cpp11::to_string(src->dimension(1)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 243 | _config_id += "_"; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 244 | _config_id += support::cpp11::to_string(src->dimension(2)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 245 | _config_id += "_"; |
| 246 | _config_id += support::cpp11::to_string(conv_info.pad_left()); |
| 247 | _config_id += "_"; |
| 248 | _config_id += support::cpp11::to_string(conv_info.pad_top()); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 249 | _config_id += "_"; |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 250 | _config_id += lower_string(string_from_data_layout(_data_layout)); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 253 | Status ClWinogradInputTransformKernel::validate(const ITensorInfo *src, |
| 254 | const ITensorInfo *dst, |
| 255 | const WinogradInfo &winograd_info) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 256 | { |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 257 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, dst); |
| 258 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, winograd_info)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 259 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 260 | validate_and_configure_window(src->clone().get(), dst->clone().get(), winograd_info).first); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 261 | return Status{}; |
| 262 | } |
| 263 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 264 | void ClWinogradInputTransformKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 265 | { |
| 266 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 267 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 268 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 269 | auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC)); |
| 270 | auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST)); |
| 271 | |
Georgios Pinitas | 7fdcfb1 | 2020-01-09 16:45:46 +0000 | [diff] [blame] | 272 | const size_t idx_w = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 273 | const size_t idx_h = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 274 | const size_t idx_c = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL); |
| 275 | const size_t total_batches = window.shape().total_size_upper(3); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 276 | |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 277 | // Collapse window |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 278 | Window window_collapsed = window.collapse_if_possible(IClKernel::window(), Window::DimZ); |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 279 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 280 | if (_data_layout == DataLayout::NHWC) |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 281 | { |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 282 | Window slice = window_collapsed.first_slice_window_3D(); |
| 283 | slice.set(1, Window::Dimension(0, _num_tiles_x * _num_tiles_y, 1)); |
| 284 | slice.set(2, Window::Dimension(0, total_batches, 1)); |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 285 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 286 | unsigned int idx = 0; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 287 | add_4D_tensor_argument(idx, src, slice); |
| 288 | add_4D_tensor_argument(idx, dst, slice); |
ramelg01 | 2a86a30 | 2022-02-04 20:49:14 +0000 | [diff] [blame] | 289 | _kernel.setArg<cl_uint>(idx++, _src_width); |
| 290 | _kernel.setArg<cl_uint>(idx++, _src_height); |
| 291 | _kernel.setArg<cl_uint>(idx++, _num_tiles_x); |
| 292 | _kernel.setArg<cl_uint>(idx++, _num_tiles_y); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 293 | enqueue(queue, *this, slice, lws_hint()); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 294 | } |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 295 | else |
| 296 | { |
| 297 | Window slice = window_collapsed.first_slice_window_3D(); |
| 298 | slice.set(idx_w, Window::Dimension(0, _num_tiles_x, 1)); |
| 299 | slice.set(idx_h, Window::Dimension(0, _num_tiles_y, 1)); |
| 300 | |
| 301 | ARM_COMPUTE_ERROR_ON(((slice[idx_c].end() - slice[idx_c].start()) % _step_z) != 0); |
| 302 | slice.set(idx_c, Window::Dimension(slice[idx_c].start(), slice[idx_c].end(), _step_z)); |
| 303 | |
| 304 | unsigned int idx = 2 * num_arguments_per_3D_tensor(); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 305 | _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src->info()->strides_in_bytes()[3])); |
| 306 | _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(dst->info()->strides_in_bytes()[3])); |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 307 | |
| 308 | do |
| 309 | { |
| 310 | unsigned int idx = 0; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 311 | add_3D_tensor_argument(idx, src, slice); |
| 312 | add_3D_tensor_argument(idx, dst, slice); |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 313 | |
| 314 | enqueue(queue, *this, slice, lws_hint()); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 315 | } while (window_collapsed.slide_window_slice_3D(slice)); |
Gian Marco Iodice | 534b889 | 2021-04-01 16:17:16 +0100 | [diff] [blame] | 316 | } |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 317 | } |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 318 | } // namespace kernels |
| 319 | } // namespace opencl |
ramelg01 | 2a86a30 | 2022-02-04 20:49:14 +0000 | [diff] [blame] | 320 | } // namespace arm_compute |