Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 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 | */ |
| 24 | #include "arm_compute/core/CL/kernels/CLWinogradOutputTransformKernel.h" |
| 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" |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 41 | |
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 | |
Michele Di Giorgio | df2c721 | 2019-10-11 14:01:35 +0100 | [diff] [blame] | 46 | namespace arm_compute |
| 47 | { |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 48 | using namespace arm_compute::misc::shape_calculator; |
| 49 | |
| 50 | namespace |
| 51 | { |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 52 | 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] | 53 | { |
Michele Di Giorgio | df2c721 | 2019-10-11 14:01:35 +0100 | [diff] [blame] | 54 | ARM_COMPUTE_UNUSED(act_info); |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 55 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16); |
| 56 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 57 | |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 58 | ARM_COMPUTE_RETURN_ERROR_ON(output->data_layout() != winograd_info.output_data_layout); |
| 59 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 60 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 61 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 62 | const Size2D kernel_size = winograd_info.kernel_size; |
| 63 | const Size2D input_dimensions = winograd_info.input_dimensions; |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 64 | 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] | 65 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 66 | 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"); |
| 67 | 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] | 68 | |
| 69 | // 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] | 70 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
| 71 | const Size2D num_tiles = compute_winograd_convolution_tiles(input_dimensions, |
| 72 | kernel_size, |
| 73 | output_tile_size, |
| 74 | conv_info); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 75 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 76 | 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] | 77 | |
| 78 | if(bias != nullptr) |
| 79 | { |
| 80 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias); |
| 81 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0)); |
| 82 | } |
| 83 | |
| 84 | // Checks performed when output is configured |
| 85 | if(output->total_size() != 0) |
| 86 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 87 | 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] | 88 | |
| 89 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output); |
| 90 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 91 | } |
| 92 | |
| 93 | return Status{}; |
| 94 | } |
| 95 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 96 | 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] | 97 | { |
| 98 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 99 | |
| 100 | constexpr unsigned int num_elems_processed_per_iteration = 1; |
| 101 | |
| 102 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
| 103 | bool window_changed = false; |
| 104 | |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 105 | int output_static_window_end_x = 0; |
| 106 | int output_static_window_end_y = 0; |
| 107 | |
| 108 | if(output->data_layout() == DataLayout::NCHW) |
| 109 | { |
| 110 | output_static_window_end_x = ceil_to_multiple(output->dimension(0), output_tile_size.width); |
| 111 | output_static_window_end_y = ceil_to_multiple(output->dimension(1), output_tile_size.height); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | output_static_window_end_x = output->dimension(0); |
| 116 | output_static_window_end_y = std::max(ceil_to_multiple(output->dimension(1), output_tile_size.width), output->dimension(1) + 1 /* For out of bound reads towards the z axis */); |
| 117 | } |
| 118 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 119 | AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration, num_elems_processed_per_iteration); |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 120 | AccessWindowStatic output_access(output, 0, 0, output_static_window_end_x, output_static_window_end_y); |
| 121 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 122 | output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 123 | |
| 124 | if(bias != nullptr) |
| 125 | { |
| 126 | AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1)); |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 127 | window_changed = window_changed || update_window_and_padding(win, bias_access); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 128 | } |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 129 | |
| 130 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 131 | return std::make_pair(err, win); |
| 132 | } |
| 133 | } // namespace |
| 134 | |
| 135 | CLWinogradOutputTransformKernel::CLWinogradOutputTransformKernel() |
Georgios Pinitas | 7191aaa | 2019-04-03 17:01:26 +0100 | [diff] [blame] | 136 | : _input(nullptr), _bias(nullptr), _output(nullptr), _is_nhwc(false) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 137 | { |
| 138 | } |
| 139 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 140 | void CLWinogradOutputTransformKernel::configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 141 | { |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 142 | configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, winograd_info, act_info); |
| 143 | } |
| 144 | |
Manuel Bottini | 2803f70 | 2020-04-21 16:20:03 +0100 | [diff] [blame] | 145 | void CLWinogradOutputTransformKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const WinogradInfo &winograd_info, |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 146 | const ActivationLayerInfo &act_info) |
| 147 | { |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 148 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 149 | |
| 150 | // Output tensor auto initialization if not yet initialized |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 151 | auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(compute_winograd_output_transform_shape(*input->info(), winograd_info))); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 152 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 153 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (bias != nullptr ? bias->info() : nullptr), output->info(), winograd_info, act_info)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 154 | |
Georgios Pinitas | 7191aaa | 2019-04-03 17:01:26 +0100 | [diff] [blame] | 155 | _input = input; |
| 156 | _bias = bias; |
| 157 | _output = output; |
| 158 | _is_nhwc = winograd_info.output_data_layout == DataLayout::NHWC; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 159 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 160 | // Compute num_tiles_x |
| 161 | const Size2D input_dimensions = winograd_info.input_dimensions; |
| 162 | const Size2D kernel_size = winograd_info.kernel_size; |
| 163 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 164 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 165 | |
| 166 | // Compute the number of output tiles along the x and y direction of size "output_tile_size" |
| 167 | const Size2D num_tiles = compute_winograd_convolution_tiles(input_dimensions, |
| 168 | kernel_size, |
| 169 | output_tile_size, |
| 170 | conv_info); |
Georgios Pinitas | ffb57a0 | 2018-10-29 18:01:52 +0000 | [diff] [blame] | 171 | const size_t total_batches = output->info()->tensor_shape().total_size_upper(3); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 172 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 173 | // Set build options |
| 174 | CLBuildOptions build_opts; |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 175 | 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] | 176 | build_opts.add_option_if(act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(act_info.a())); |
| 177 | build_opts.add_option_if(act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(act_info.b())); |
| 178 | |
| 179 | if((output_tile_size.x() == 2) || (output_tile_size.x() == 1 && output_tile_size.y() == 2)) |
| 180 | { |
| 181 | build_opts.add_option("-DVEC_SIZE=2"); |
| 182 | } |
| 183 | else if((output_tile_size.x() == 4) || (output_tile_size.x() == 1 && output_tile_size.y() == 4)) |
| 184 | { |
| 185 | build_opts.add_option("-DVEC_SIZE=4"); |
| 186 | } |
| 187 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 188 | build_opts.add_option_if(_bias != nullptr, std::string("-DHAS_BIAS")); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 189 | build_opts.add_option("-DNUM_TILES_X=" + support::cpp11::to_string(num_tiles.width)); |
| 190 | build_opts.add_option("-DOUTPUT_TILE_W=" + support::cpp11::to_string(output_tile_size.width)); |
| 191 | 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] | 192 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); |
Georgios Pinitas | ffb57a0 | 2018-10-29 18:01:52 +0000 | [diff] [blame] | 193 | build_opts.add_option_if(total_batches > 1, "-DSRC_DEPTH=" + support::cpp11::to_string(_input->info()->dimension(2))); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 194 | build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_HORIZONTAL"); |
| 195 | build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_OUTPUT_TRANSFORM_VERTICAL"); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 196 | |
| 197 | // Create kernel |
Giorgio Arena | 3695f9a | 2018-04-23 17:41:22 +0100 | [diff] [blame] | 198 | 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)); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 199 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 200 | |
| 201 | // Configure kernel window |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 202 | auto win_config = validate_and_configure_window(input->info(), (bias != nullptr ? bias->info() : nullptr), output->info(), winograd_info.output_tile_size); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 203 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 204 | ICLKernel::configure_internal(win_config.second); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 205 | |
| 206 | // Set config_id for enabling LWS tuning |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 207 | _config_id = kernel_name; |
| 208 | _config_id += "_"; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 209 | _config_id += lower_string(string_from_data_type(input->info()->data_type())); |
| 210 | _config_id += "_"; |
| 211 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 212 | _config_id += "_"; |
| 213 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 214 | _config_id += "_"; |
| 215 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 216 | _config_id += "_"; |
| 217 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 218 | _config_id += "_"; |
| 219 | _config_id += lower_string(string_from_data_layout(winograd_info.output_data_layout)); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 222 | Status CLWinogradOutputTransformKernel::validate(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] | 223 | { |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 224 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info, act_info)); |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 225 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), (bias != nullptr ? bias->clone().get() : nullptr), output->clone().get(), winograd_info.output_tile_size).first); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 226 | |
| 227 | return Status{}; |
| 228 | } |
| 229 | |
| 230 | void CLWinogradOutputTransformKernel::run(const Window &window, cl::CommandQueue &queue) |
| 231 | { |
| 232 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 233 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window); |
| 234 | |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 235 | // Collapse window |
| 236 | Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); |
| 237 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 238 | // Get initial windows |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 239 | Window slice = window_collapsed.first_slice_window_4D(); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 240 | slice.set(Window::DimZ, Window::Dimension(0, 1, 1)); |
| 241 | |
| 242 | // Setup output slice |
| 243 | Window slice_out(slice); |
| 244 | slice_out.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 245 | slice_out.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 246 | |
| 247 | if(_bias != nullptr) |
| 248 | { |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 249 | unsigned int idx1 = 2 * num_arguments_per_4D_tensor(); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 250 | Window slice_biases; |
| 251 | slice_biases.use_tensor_dimensions(_bias->info()->tensor_shape()); |
| 252 | add_1D_tensor_argument(idx1, _bias, slice_biases); |
| 253 | } |
| 254 | |
Georgios Pinitas | 7191aaa | 2019-04-03 17:01:26 +0100 | [diff] [blame] | 255 | if(_is_nhwc) |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 256 | { |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 257 | unsigned int idx2 = 2 * num_arguments_per_4D_tensor() + ((_bias != nullptr) ? num_arguments_per_1D_tensor() : 0); |
Georgios Pinitas | c084f0d | 2018-06-11 17:43:31 +0100 | [diff] [blame] | 258 | _kernel.setArg(idx2, static_cast<int>(_output->info()->total_size() - _output->info()->strides_in_bytes().y())); |
| 259 | } |
| 260 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 261 | do |
| 262 | { |
| 263 | unsigned int idx = 0; |
Georgios Pinitas | c55beee | 2018-10-23 15:23:23 +0100 | [diff] [blame] | 264 | add_4D_tensor_argument(idx, _input, slice); |
| 265 | add_4D_tensor_argument(idx, _output, slice_out); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 266 | enqueue(queue, *this, slice, lws_hint()); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 267 | } |
| 268 | 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] | 269 | } |
Michele Di Giorgio | df2c721 | 2019-10-11 14:01:35 +0100 | [diff] [blame] | 270 | } // namespace arm_compute |