Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 1 | /* |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2022 Arm Limited. |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +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/ClWinogradOutputTransformKernel.h" |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 25 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLHelpers.h" |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/CL/ICLTensor.h" |
| 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/IAccessWindow.h" |
| 31 | #include "arm_compute/core/TensorInfo.h" |
| 32 | #include "arm_compute/core/Types.h" |
| 33 | #include "arm_compute/core/Utils.h" |
| 34 | #include "arm_compute/core/Validate.h" |
| 35 | #include "arm_compute/core/Window.h" |
| 36 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 37 | #include "src/core/AccessWindowStatic.h" |
| 38 | #include "src/core/CL/CLValidate.h" |
| 39 | #include "src/core/helpers/AutoConfiguration.h" |
| 40 | #include "src/core/helpers/WindowHelpers.h" |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 41 | #include "support/Cast.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 42 | #include "support/StringSupport.h" |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 43 | |
| 44 | #include <cmath> |
| 45 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 46 | using namespace arm_compute::misc::shape_calculator; |
| 47 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 48 | namespace arm_compute |
| 49 | { |
| 50 | namespace opencl |
| 51 | { |
| 52 | namespace kernels |
| 53 | { |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 54 | namespace |
| 55 | { |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 56 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 57 | { |
Michele Di Giorgio | df2c721 | 2019-10-11 14:01:35 +0100 | [diff] [blame] | 58 | ARM_COMPUTE_UNUSED(act_info); |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16); |
| 60 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 61 | |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 62 | ARM_COMPUTE_RETURN_ERROR_ON(output->data_layout() != winograd_info.output_data_layout); |
| 63 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 64 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 65 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 66 | const Size2D kernel_size = winograd_info.kernel_size; |
| 67 | const Size2D input_dimensions = winograd_info.input_dimensions; |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 68 | const unsigned int num_channels = (winograd_info.kernel_size.width + winograd_info.output_tile_size.width - 1) * (winograd_info.kernel_size.height + winograd_info.output_tile_size.height - 1); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 69 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 70 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!cl_winograd_convolution_layer_supported(output_tile_size, kernel_size, winograd_info.output_data_layout), "Winograd output transform not supported"); |
| 71 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->dimension(2) != num_channels, "Wrong number of channels"); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 72 | |
| 73 | // Compute number of elements to process in the X and Y direction |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 74 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
| 75 | const Size2D num_tiles = compute_winograd_convolution_tiles(input_dimensions, |
| 76 | kernel_size, |
| 77 | output_tile_size, |
| 78 | conv_info); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 79 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 80 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != static_cast<unsigned int>((num_tiles.area()))); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 81 | |
| 82 | if(bias != nullptr) |
| 83 | { |
| 84 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias); |
| 85 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0)); |
| 86 | } |
| 87 | |
| 88 | // Checks performed when output is configured |
| 89 | if(output->total_size() != 0) |
| 90 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 91 | const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(compute_winograd_output_transform_shape(*input, winograd_info)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 92 | |
| 93 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output); |
| 94 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 95 | } |
| 96 | |
| 97 | return Status{}; |
| 98 | } |
| 99 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 100 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *bias, ITensorInfo *output, const Size2D &output_tile_size) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 101 | { |
| 102 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Gian Marco Iodice | 5f91041 | 2020-10-20 09:14:45 +0100 | [diff] [blame] | 103 | ARM_COMPUTE_UNUSED(bias); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 104 | |
| 105 | constexpr unsigned int num_elems_processed_per_iteration = 1; |
| 106 | |
| 107 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
| 108 | bool window_changed = false; |
| 109 | |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 110 | if(output->data_layout() == DataLayout::NCHW) |
| 111 | { |
Gian Marco Iodice | 5f91041 | 2020-10-20 09:14:45 +0100 | [diff] [blame] | 112 | const int output_static_window_end_x = ceil_to_multiple(output->dimension(0), output_tile_size.width); |
| 113 | const int output_static_window_end_y = ceil_to_multiple(output->dimension(1), output_tile_size.height); |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 114 | |
Gian Marco Iodice | 5f91041 | 2020-10-20 09:14:45 +0100 | [diff] [blame] | 115 | AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration, num_elems_processed_per_iteration); |
| 116 | AccessWindowStatic output_access(output, 0, 0, output_static_window_end_x, output_static_window_end_y); |
| 117 | window_changed = update_window_and_padding(win, input_access, output_access); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 118 | } |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 119 | |
| 120 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 121 | return std::make_pair(err, win); |
| 122 | } |
| 123 | } // namespace |
| 124 | |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 125 | ClWinogradOutputTransformKernel::ClWinogradOutputTransformKernel() |
| 126 | { |
| 127 | _type = CLKernelType::WINOGRAD; |
| 128 | } |
| 129 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 130 | void ClWinogradOutputTransformKernel::configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *bias, ITensorInfo *dst, const WinogradInfo &winograd_info, |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 131 | const ActivationLayerInfo &act_info) |
| 132 | { |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 133 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 134 | |
| 135 | // Output tensor auto initialization if not yet initialized |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 136 | auto_init_if_empty(*dst, src->clone()->set_tensor_shape(compute_winograd_output_transform_shape(*src, winograd_info))); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 137 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 138 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, bias, dst, winograd_info, act_info)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 139 | |
Gian Marco Iodice | a8903c8 | 2021-03-24 14:48:22 +0000 | [diff] [blame] | 140 | // Configure kernel window |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 141 | auto win_config = validate_and_configure_window(src, bias, dst, winograd_info.output_tile_size); |
Gian Marco Iodice | a8903c8 | 2021-03-24 14:48:22 +0000 | [diff] [blame] | 142 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 143 | IClKernel::configure_internal(win_config.second); |
Gian Marco Iodice | a8903c8 | 2021-03-24 14:48:22 +0000 | [diff] [blame] | 144 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 145 | auto padding_info = get_padding_info({ src, bias, dst }); |
Gian Marco Iodice | 5f91041 | 2020-10-20 09:14:45 +0100 | [diff] [blame] | 146 | |
Georgios Pinitas | 7191aaa | 2019-04-03 17:01:26 +0100 | [diff] [blame] | 147 | _is_nhwc = winograd_info.output_data_layout == DataLayout::NHWC; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 148 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 149 | // Compute num_tiles_x |
| 150 | const Size2D input_dimensions = winograd_info.input_dimensions; |
| 151 | const Size2D kernel_size = winograd_info.kernel_size; |
| 152 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 153 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
Gian Marco Iodice | 5f91041 | 2020-10-20 09:14:45 +0100 | [diff] [blame] | 154 | const int idx_width = get_data_layout_dimension_index(winograd_info.output_data_layout, DataLayoutDimension::WIDTH); |
| 155 | const int idx_height = get_data_layout_dimension_index(winograd_info.output_data_layout, DataLayoutDimension::HEIGHT); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 156 | |
| 157 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
| 158 | const Size2D num_tiles = compute_winograd_convolution_tiles(input_dimensions, |
| 159 | kernel_size, |
| 160 | output_tile_size, |
| 161 | conv_info); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 162 | const size_t total_batches = dst->tensor_shape().total_size_upper(3); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 163 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 164 | // Set build options |
| 165 | CLBuildOptions build_opts; |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 166 | build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_info.activation()))); |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 167 | build_opts.add_option_if(act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(act_info.a())); |
| 168 | build_opts.add_option_if(act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(act_info.b())); |
| 169 | |
| 170 | if((output_tile_size.x() == 2) || (output_tile_size.x() == 1 && output_tile_size.y() == 2)) |
| 171 | { |
| 172 | build_opts.add_option("-DVEC_SIZE=2"); |
| 173 | } |
| 174 | else if((output_tile_size.x() == 4) || (output_tile_size.x() == 1 && output_tile_size.y() == 4)) |
| 175 | { |
| 176 | build_opts.add_option("-DVEC_SIZE=4"); |
| 177 | } |
| 178 | |
Gian Marco Iodice | d8804fd | 2022-06-28 16:55:19 +0100 | [diff] [blame] | 179 | _num_tiles_x = num_tiles.width; |
| 180 | |
Gunes Bayir | cc03419 | 2022-08-10 15:58:51 +0100 | [diff] [blame] | 181 | // Conditions of -cl-fast-relaxed-math causing accuracy issues can be traced from COMPMID-5324 |
| 182 | const GPUTarget gpu_target = get_target(); |
| 183 | const auto act_function = act_info.activation(); |
| 184 | const auto src_data_type = src->data_type(); |
| 185 | |
| 186 | if((gpu_target != GPUTarget::G71 && (gpu_target & GPUTarget::GPU_ARCH_MASK) == GPUTarget::BIFROST) |
| 187 | && (act_function == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU || act_function == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) |
| 188 | && (src_data_type == DataType::F32 || src_data_type == DataType::F16)) |
| 189 | { |
| 190 | // -cl-fast-relaxed-math also sets -cl-finite-math-only and -cl-unsafe-math-optimizations |
| 191 | // to disable -cl-finite-math-only, we only include -cl-unsafe-math-optimizations |
| 192 | build_opts.add_option("-cl-unsafe-math-optimizations"); |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | build_opts.add_option("-cl-fast-relaxed-math"); |
| 197 | } |
| 198 | |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 199 | if(_is_nhwc) |
| 200 | { |
| 201 | build_opts.add_option_if(bias != nullptr, std::string("-DHAS_BIAS")); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 202 | build_opts.add_option("-DN0=" + support::cpp11::to_string(win_config.second.x().step())); |
| 203 | build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width)); |
| 204 | build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height)); |
Gunes Bayir | cc03419 | 2022-08-10 15:58:51 +0100 | [diff] [blame] | 205 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src_data_type)); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 206 | build_opts.add_option_if(total_batches > 1, "-DSRC_DEPTH=" + support::cpp11::to_string(src->dimension(2))); |
| 207 | build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_HORIZONTAL"); |
| 208 | build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_VERTICAL"); |
Gian Marco Iodice | 0c68704 | 2022-06-14 15:13:16 +0100 | [diff] [blame] | 209 | build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(_num_tiles_x)); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 210 | } |
| 211 | else |
| 212 | { |
| 213 | build_opts.add_option_if(bias != nullptr, std::string("-DHAS_BIAS")); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 214 | build_opts.add_option("-DN0=" + support::cpp11::to_string(win_config.second.x().step())); |
| 215 | build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(num_tiles.width)); |
| 216 | build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width)); |
| 217 | build_opts.add_option("-DOUTPUT_TILE_H=" + support::cpp11::to_string(output_tile_size.height)); |
Gunes Bayir | cc03419 | 2022-08-10 15:58:51 +0100 | [diff] [blame] | 218 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src_data_type)); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 219 | build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(src->dimension(1))); |
| 220 | build_opts.add_option("-DDST_WIDTH=" + support::cpp11::to_string(dst->dimension(idx_width))); |
| 221 | build_opts.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(dst->dimension(idx_height))); |
| 222 | build_opts.add_option_if(total_batches > 1, "-DSRC_DEPTH=" + support::cpp11::to_string(src->dimension(2))); |
| 223 | build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_HORIZONTAL"); |
| 224 | build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_VERTICAL"); |
| 225 | } |
| 226 | |
| 227 | // Storing tensor dimensions to be sent later as kernel arguments |
Gunes Bayir | cc03419 | 2022-08-10 15:58:51 +0100 | [diff] [blame] | 228 | _src_height = src->dimension(1); |
| 229 | _dst_width = dst->dimension(idx_width); |
| 230 | _dst_height = dst->dimension(idx_height); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 231 | |
| 232 | // Create kernel |
Giorgio Arena | 3695f9a | 2018-04-23 17:41:22 +0100 | [diff] [blame] | 233 | std::string kernel_name = "winograd_output_transform_" + output_tile_size.to_string() + "_" + kernel_size.to_string() + "_" + lower_string(string_from_data_layout(winograd_info.output_data_layout)); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 234 | |
| 235 | // A macro guard to compile ONLY the kernel of interest |
| 236 | build_opts.add_option("-D" + upper_string(kernel_name)); |
| 237 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 238 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 239 | // Set config_id for enabling LWS tuning |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 240 | _config_id = kernel_name; |
| 241 | _config_id += "_"; |
Gunes Bayir | cc03419 | 2022-08-10 15:58:51 +0100 | [diff] [blame] | 242 | _config_id += lower_string(string_from_data_type(src_data_type)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +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(0)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 245 | _config_id += "_"; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 246 | _config_id += support::cpp11::to_string(src->dimension(1)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 247 | _config_id += "_"; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 248 | _config_id += support::cpp11::to_string(dst->dimension(0)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 249 | _config_id += "_"; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 250 | _config_id += support::cpp11::to_string(dst->dimension(1)); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 251 | _config_id += "_"; |
| 252 | _config_id += lower_string(string_from_data_layout(winograd_info.output_data_layout)); |
Gian Marco Iodice | 5f91041 | 2020-10-20 09:14:45 +0100 | [diff] [blame] | 253 | |
| 254 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info) && _is_nhwc); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 257 | Status ClWinogradOutputTransformKernel::validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 258 | { |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 259 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, (bias != nullptr ? bias->clone().get() : nullptr), dst, winograd_info, act_info)); |
| 260 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), (bias != nullptr ? bias->clone().get() : nullptr), dst->clone().get(), winograd_info.output_tile_size).first); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 261 | return Status{}; |
| 262 | } |
| 263 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 264 | void ClWinogradOutputTransformKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 265 | { |
| 266 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 267 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IClKernel::window(), window); |
| 268 | |
| 269 | auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0)); |
| 270 | auto bias = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1)); |
| 271 | auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 272 | |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 273 | // Collapse window |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 274 | Window window_collapsed = window.collapse_if_possible(IClKernel::window(), Window::DimZ); |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 275 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 276 | // Get initial windows |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 277 | Window slice = window_collapsed.first_slice_window_4D(); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 278 | slice.set(Window::DimZ, Window::Dimension(0, 1, 1)); |
| 279 | |
| 280 | // Setup output slice |
| 281 | Window slice_out(slice); |
| 282 | slice_out.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 283 | slice_out.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 284 | |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 285 | if(bias != nullptr) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 286 | { |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 287 | unsigned int idx1 = 2 * num_arguments_per_4D_tensor(); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 288 | Window slice_biases; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 289 | slice_biases.use_tensor_dimensions(bias->info()->tensor_shape()); |
| 290 | add_1D_tensor_argument(idx1, bias, slice_biases); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Georgios Pinitas | 7191aaa | 2019-04-03 17:01:26 +0100 | [diff] [blame] | 293 | if(_is_nhwc) |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 294 | { |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 295 | unsigned int idx2 = 2 * num_arguments_per_4D_tensor() + ((bias != nullptr) ? num_arguments_per_1D_tensor() : 0); |
ramelg01 | bb6877a | 2022-02-08 09:38:17 +0000 | [diff] [blame] | 296 | _kernel.setArg(idx2++, static_cast<int>(dst->info()->total_size() - dst->info()->strides_in_bytes().y())); |
| 297 | _kernel.setArg<cl_int>(idx2++, _src_height); |
| 298 | _kernel.setArg<cl_int>(idx2++, _dst_width); |
| 299 | _kernel.setArg<cl_int>(idx2++, _dst_height); |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 302 | do |
| 303 | { |
| 304 | unsigned int idx = 0; |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 305 | add_4D_tensor_argument(idx, src, slice); |
| 306 | add_4D_tensor_argument(idx, dst, slice_out); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 307 | enqueue(queue, *this, slice, lws_hint()); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 308 | } |
| 309 | while(window.slide_window_slice_3D(slice) && window.slide_window_slice_3D(slice_out)); |
Gian Marco Iodice | e52a300 | 2018-04-11 15:59:10 +0100 | [diff] [blame] | 310 | } |
Manuel Bottini | c6f4ec3 | 2021-05-18 18:41:56 +0100 | [diff] [blame] | 311 | } // namespace kernels |
| 312 | } // namespace opencl |
Michele Di Giorgio | df2c721 | 2019-10-11 14:01:35 +0100 | [diff] [blame] | 313 | } // namespace arm_compute |