Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 1 | /* |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +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 | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEWinogradConvolutionLayerKernel.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 25 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/IAccessWindow.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/ITensor.h" |
| 31 | #include "arm_compute/core/TensorInfo.h" |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/Validate.h" |
| 33 | #include "arm_compute/core/Window.h" |
| 34 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Pablo Tello | 3d4968a | 2017-12-04 15:03:35 +0000 | [diff] [blame] | 35 | #include "support/ToolchainSupport.h" |
| 36 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 37 | namespace arm_compute |
| 38 | { |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 39 | //Batched Gemms |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 40 | |
| 41 | namespace |
| 42 | { |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 43 | inline bool is_kernel_size_supported(Size2D size) |
| 44 | { |
| 45 | const std::array<Size2D, 4> supported_input_sizes = { { Size2D(1, 3), Size2D(3, 1), Size2D(5, 5), Size2D(3, 3) } }; |
| 46 | return std::end(supported_input_sizes) != std::find(std::begin(supported_input_sizes), std::end(supported_input_sizes), size); |
| 47 | } |
| 48 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 49 | Status validate_arguments_winograd_weight_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 50 | { |
| 51 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); |
| 52 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 53 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); |
| 54 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 55 | const size_t idx_width = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH); |
| 56 | const size_t idx_height = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT); |
| 57 | const auto input_width = input->dimension(idx_width); |
| 58 | const auto input_height = input->dimension(idx_height); |
| 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(Size2D(input_width, input_height)), "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported"); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 60 | ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > 4); |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 61 | const Size2D &output_tile = winograd_info.output_tile_size; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 62 | const std::array<Size2D, 4> supported_tile_sizes = { { Size2D(2U, 2U), Size2D(4U, 4U), Size2D(1U, 6U), Size2D(6U, 1U) } }; |
| 63 | ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_tile_sizes) == std::find(std::begin(supported_tile_sizes), std::end(supported_tile_sizes), output_tile)); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 64 | |
| 65 | // Checks performed when output is configured |
| 66 | if(output->total_size() != 0) |
| 67 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 68 | const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info)); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 69 | |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output); |
| 71 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 72 | } |
| 73 | |
| 74 | return Status{}; |
| 75 | } |
| 76 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 77 | std::pair<Status, Window> validate_and_configure_window_winograd_weight_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 78 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 79 | const Size2D kernel_dims = winograd_info.kernel_size; |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 80 | // Output tensor auto inizialitation if not yet initialized |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 81 | auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info))); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 82 | |
| 83 | unsigned int num_elems_processed_per_iteration_x = kernel_dims.width; |
| 84 | unsigned int num_elems_processed_per_iteration_y = kernel_dims.height; |
| 85 | |
| 86 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y)); |
| 87 | bool window_changed = false; |
| 88 | |
| 89 | AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y); |
| 90 | AccessWindowStatic output_access(output, 0, 0, output->dimension(0), output->dimension(1)); |
| 91 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 92 | output_access.set_valid_region(win, ValidRegion(Coordinates(0, 0), output->tensor_shape())); |
| 93 | |
| 94 | Window win_collapsed = win.collapse(win, Window::DimZ); |
| 95 | |
| 96 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 97 | |
| 98 | return std::make_pair(err, win_collapsed); |
| 99 | } |
| 100 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 101 | Status validate_arguments_winograd_input_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 102 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 103 | const Size2D &kernel_dims = winograd_info.kernel_size; |
| 104 | const PadStrideInfo &conv_info = winograd_info.convolution_info; |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 105 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); |
| 106 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 107 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); |
| 108 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd input transform only supports unit strides"); |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 109 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(Size2D(kernel_dims.width, kernel_dims.height)), |
| 110 | "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported"); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 111 | |
| 112 | // Validate configured output |
| 113 | if(output->total_size() != 0) |
| 114 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 115 | const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 116 | |
| 117 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 118 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 119 | } |
| 120 | |
| 121 | return Status{}; |
| 122 | } |
| 123 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 124 | std::pair<Status, Window> validate_and_configure_window_winograd_input_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 125 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 126 | const PadStrideInfo conv_info = winograd_info.convolution_info; |
| 127 | const Size2D output_tile_size = winograd_info.output_tile_size; |
| 128 | const Size2D kernel_dims = winograd_info.kernel_size; |
| 129 | const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 130 | // Output auto inizialitation if not yet initialized |
| 131 | auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape)); |
| 132 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 133 | unsigned int num_elems_read_per_iteration_x = (output_tile_size.width + kernel_dims.width - 1); |
| 134 | unsigned int num_elems_read_per_iteration_y = (output_tile_size.height + kernel_dims.height - 1); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 135 | |
| 136 | Window win = calculate_max_window(*input, Steps(1, 1)); |
| 137 | |
| 138 | AccessWindowRectangle input_access(input, -conv_info.pad_left(), -conv_info.pad_top(), num_elems_read_per_iteration_x, num_elems_read_per_iteration_y); |
| 139 | |
| 140 | bool window_changed = update_window_and_padding(win, input_access); |
| 141 | |
| 142 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 143 | return std::make_pair(err, win); |
| 144 | } |
| 145 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 146 | Status validate_arguments_winograd_output_trans(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 147 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 148 | const PadStrideInfo &conv_info = winograd_info.convolution_info; |
| 149 | const Size2D kernel_dims = winograd_info.kernel_size; |
| 150 | |
| 151 | // Number of tiles along the X and Y direction |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 152 | const unsigned int num_tiles_x = std::ceil((winograd_info.input_dimensions.x() - (kernel_dims.width - 1) + conv_info.pad_left() + conv_info.pad_right()) / static_cast<float> |
| 153 | (winograd_info.output_tile_size.width)); |
| 154 | const unsigned int num_tiles_y = std::ceil((winograd_info.input_dimensions.y() - (kernel_dims.height - 1) + conv_info.pad_top() + conv_info.pad_bottom()) / static_cast<float> |
| 155 | (winograd_info.output_tile_size.height)); |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 156 | const Size2D num_tiles = Size2D(num_tiles_x, num_tiles_y); |
| 157 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 158 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input); |
| 159 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 160 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); |
| 161 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != num_tiles.area()); |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 162 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(Size2D(kernel_dims.width, kernel_dims.height)), |
| 163 | "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported"); |
| 164 | |
| 165 | const std::array<unsigned int, 3> supported_gemm_sizes = { { 8U, 16U, 36U } }; |
| 166 | ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_gemm_sizes) == std::find(std::begin(supported_gemm_sizes), std::end(supported_gemm_sizes), input->dimension(2))); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 167 | ARM_COMPUTE_UNUSED(kernel_dims); |
| 168 | if(bias != nullptr) |
| 169 | { |
| 170 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias); |
| 171 | ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0)); |
| 172 | ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() != size_t(1)); |
| 173 | } |
| 174 | |
| 175 | // Checks performed when output is configured |
| 176 | if(output->total_size() != 0) |
| 177 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 178 | const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info)); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 179 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output); |
| 180 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 181 | } |
| 182 | return Status{}; |
| 183 | } |
| 184 | |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 185 | std::pair<Status, Window> validate_and_configure_window_winograd_output_trans(ITensorInfo *input, ITensorInfo *bias, ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 186 | { |
| 187 | // Output tensor auto initialization if not yet initialized |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 188 | auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info))); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 189 | |
| 190 | constexpr unsigned int num_elems_processed_per_iteration = 1; |
| 191 | |
| 192 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
| 193 | bool window_changed = false; |
| 194 | |
| 195 | AccessWindowRectangle input_access(input, 0, 0, num_elems_processed_per_iteration, num_elems_processed_per_iteration); |
| 196 | AccessWindowStatic output_access(output, 0, 0, ceil_to_multiple(output->dimension(0), 2), ceil_to_multiple(output->dimension(1), 2)); |
| 197 | |
| 198 | if(bias != nullptr) |
| 199 | { |
| 200 | AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1)); |
| 201 | window_changed = update_window_and_padding(win, input_access, bias_access, output_access); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 206 | } |
| 207 | output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); |
| 208 | |
| 209 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 210 | return std::make_pair(err, win); |
| 211 | } |
| 212 | } // namespace |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 213 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 214 | template <typename T> |
| 215 | Status INEWinogradLayerTransformWeightsKernel<T>::validate(const ITensorInfo *input, const ITensorInfo *weights) |
| 216 | { |
| 217 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); |
| 218 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 219 | const DataLayout data_layout = input->data_layout(); |
| 220 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 221 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 222 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(Size2D(weights->dimension(width_idx), weights->dimension(height_idx))), |
| 223 | "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported"); |
| 224 | ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4); |
| 225 | return Status{}; |
| 226 | } |
| 227 | |
| 228 | template class INEWinogradLayerTransformWeightsKernel<float>; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 229 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 230 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 231 | unsigned int NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_weight_storage_size(int num_output_channels, int num_input_channels) const |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 232 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 233 | const KernelShape shape(num_output_channels, KernelRows, KernelCols, num_input_channels); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 234 | return static_cast<unsigned int>( |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 235 | // WinogradConv returns the size in bytes, we divide by `sizeof(T)` to express that in units of T |
| 236 | WinogradConv::get_kernel_storage_size(shape) / sizeof(T)); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 239 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 240 | NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::NEWinogradLayerTransformWeightsKernel() |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 241 | : _weights_hwio(nullptr), _output(nullptr), _matrix_stride(0), _num_output_channels(0), _num_input_channels(0) |
| 242 | |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 243 | { |
| 244 | } |
| 245 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 246 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 247 | int NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(const KernelShape &kernel_shape) const |
| 248 | { |
| 249 | return WinogradConv::get_kernel_matrix_stride(kernel_shape); |
| 250 | } |
| 251 | |
| 252 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 253 | void NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure( |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 254 | const ITensor *weights_hwio, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 255 | ITensor *output, |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 256 | const int matrix_stride, /** Stride across matrices in the output. */ |
| 257 | const int num_output_channels, /** Number of filters. */ |
| 258 | const int num_input_channels) /** Number of channels in each filter. */ |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 259 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 260 | _weights_hwio = weights_hwio; |
| 261 | _output = output; |
| 262 | _matrix_stride = matrix_stride; |
| 263 | _num_output_channels = num_output_channels; |
| 264 | _num_input_channels = num_input_channels; |
| 265 | |
| 266 | const int matrix_row_stride = roundup(num_output_channels, WinogradConv::N_BLOCK); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 267 | WeightsTransform transform(nullptr, nullptr, matrix_stride, matrix_row_stride, num_output_channels, num_input_channels); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 268 | Window win; |
| 269 | auto win_last = transform.get_window(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 270 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
| 271 | INEKernel::configure(win); |
| 272 | } |
| 273 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 274 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 275 | void NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run(const Window &window, const ThreadInfo &info) |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 276 | { |
| 277 | ARM_COMPUTE_UNUSED(info); |
| 278 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 279 | |
| 280 | const int matrix_row_stride = roundup(_num_output_channels, WinogradConv::N_BLOCK); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 281 | WeightsTransform transform(reinterpret_cast<T *>(_weights_hwio->buffer()), reinterpret_cast<T *>(_output->buffer()), _matrix_stride, matrix_row_stride, _num_output_channels, _num_input_channels); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 282 | const size_t fst = window.x().start(); |
| 283 | const size_t lst = window.x().end(); |
| 284 | transform.run(fst, lst); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 287 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 288 | bool NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::is_parallelisable() const |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 289 | { |
| 290 | return false; |
| 291 | } |
| 292 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 293 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 294 | Status NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output, |
| 295 | const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 296 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 297 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_weight_trans(input, output, winograd_info)); |
| 298 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_weight_trans(input->clone().get(), output->clone().get(), winograd_info).first); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 299 | return Status{}; |
| 300 | } |
| 301 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 302 | template class NEWinogradLayerTransformWeightsKernel<float, 2, 2, 3, 3>; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 303 | template class NEWinogradLayerTransformWeightsKernel<float, 4, 4, 3, 3>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 304 | template class NEWinogradLayerTransformWeightsKernel<float, 2, 2, 5, 5>; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 305 | template class NEWinogradLayerTransformWeightsKernel<float, 1, 6, 1, 3>; |
| 306 | template class NEWinogradLayerTransformWeightsKernel<float, 6, 1, 3, 1>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 307 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 308 | // Input transform |
| 309 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 310 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 311 | unsigned int NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_input_storage_size( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 312 | int num_batches, /* Number of batches in the input tensor. */ |
| 313 | int num_channels, /* Number of feature maps in the input tensor. */ |
| 314 | int num_rows, /* Number of rows in each feature map. */ |
| 315 | int num_cols, /* Number of columns in each feature map. */ |
| 316 | bool same_padding /* Use "SAME" padding, otherwise use "VALID". */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 317 | ) const |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 318 | { |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 319 | // Construct shapes for the input and kernel tensors. |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 320 | const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels); |
| 321 | const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 322 | const PaddingType padding = (same_padding) ? PADDING_SAME : PADDING_VALID; |
| 323 | // Return the size, converted into units of TIn |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 324 | return static_cast<unsigned int>(WinogradConv::get_input_storage_size(kern_shape, input_shape, padding) / sizeof(T)); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 327 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 328 | int NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride( |
| 329 | const KernelShape &kernel_shape, const Tensor4DShape &input_shape, const PaddingType padding_type) const |
| 330 | { |
| 331 | return WinogradConv::get_input_matrix_stride(kernel_shape, input_shape, padding_type); |
| 332 | } |
| 333 | |
| 334 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 335 | NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::NEWinogradLayerTransformInputKernel() |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 336 | : _input_nhwc(), _num_batches(0), _num_rows(0), _num_cols(0), _num_channels(0), _padding(), _output(nullptr), _matrix_stride(0) |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 337 | { |
| 338 | } |
| 339 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 340 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 341 | void NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 342 | const ITensor *input_nhwc, |
| 343 | const int num_batches, /* Number of batches in input tensor. */ |
| 344 | const int num_rows, /* Number of rows in input tensor. */ |
| 345 | const int num_cols, /* Number of columns in input tensor. */ |
| 346 | const int num_channels, /* Number of channels in input tensor. */ |
| 347 | const PaddingType padding, /* Padding type. */ |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 348 | ITensor *output, /* Base of output matrices. */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 349 | const int matrix_stride) /* Stride between output matrices. */ |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 350 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 351 | _input_nhwc = input_nhwc; |
| 352 | _num_batches = num_batches; |
| 353 | _num_rows = num_rows; |
| 354 | _num_cols = num_cols; |
| 355 | _num_channels = num_channels; |
| 356 | _padding = padding; |
| 357 | _output = output; |
| 358 | _matrix_stride = matrix_stride; |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 359 | InputTransform transform(nullptr, num_batches, num_rows, num_cols, num_channels, padding, nullptr, matrix_stride, num_channels); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 360 | Window win; |
| 361 | auto win_last = transform.get_window(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 362 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
| 363 | INEKernel::configure(win); |
| 364 | } |
| 365 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 366 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 367 | void NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run(const Window &window, const ThreadInfo &info) |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 368 | { |
| 369 | ARM_COMPUTE_UNUSED(info); |
| 370 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 371 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 372 | const int element_size_in_bytes = _input_nhwc->info()->element_size(); |
| 373 | const int input_col_stride = _input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes; |
| 374 | const int input_row_stride = _input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes; |
| 375 | const int input_batch_stride = _input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes; |
| 376 | const auto input_nhwc_ptr = reinterpret_cast<const T *>(_input_nhwc->buffer() + _input_nhwc->info()->offset_first_element_in_bytes()); |
| 377 | auto output_ptr = reinterpret_cast<T *>(_output->buffer() + _output->info()->offset_first_element_in_bytes()); |
| 378 | InputTransform input_transform(input_nhwc_ptr, |
Georgios Pinitas | eb84d6b | 2018-07-27 18:28:10 +0100 | [diff] [blame] | 379 | _num_batches, _num_rows, _num_cols, _num_channels, _padding, |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 380 | output_ptr, |
Georgios Pinitas | eb84d6b | 2018-07-27 18:28:10 +0100 | [diff] [blame] | 381 | _matrix_stride, _num_channels, input_batch_stride, input_row_stride, input_col_stride); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 382 | |
| 383 | // The code below cannot be moved to configure because biases hasn't been allocated at that point |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 384 | const size_t fst = window.x().start(); |
| 385 | const size_t lst = window.x().end(); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 386 | input_transform.run(fst, lst); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 387 | } |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 388 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 389 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 390 | Status NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 391 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 392 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info)); |
| 393 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_input_trans(input->clone().get(), output->clone().get(), winograd_info).first); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 394 | |
| 395 | return Status{}; |
| 396 | } |
| 397 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 398 | template class NEWinogradLayerTransformInputKernel<float, 2, 2, 3, 3>; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 399 | template class NEWinogradLayerTransformInputKernel<float, 4, 4, 3, 3>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 400 | template class NEWinogradLayerTransformInputKernel<float, 2, 2, 5, 5>; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 401 | template class NEWinogradLayerTransformInputKernel<float, 1, 6, 1, 3>; |
| 402 | template class NEWinogradLayerTransformInputKernel<float, 6, 1, 3, 1>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 403 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 404 | // Output transform |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 405 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 406 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 407 | unsigned int NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_storage_size( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 408 | int num_batches, /* Number of batches in the output tensor. */ |
| 409 | int num_rows, /* Number of rows in each feature map of the input tensor. */ |
| 410 | int num_cols, /* Number of columns in each feature map of the input tensor. */ |
| 411 | int num_output_channels, /* Number of feature maps in the output tensor. */ |
| 412 | bool same_padding /* Use "SAME" padding, otherwise use "VALID". */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 413 | ) const |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 414 | { |
| 415 | // Construct shapes for the input and kernel tensors. |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 416 | const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1); |
| 417 | const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 418 | const PaddingType padding = (same_padding) ? PADDING_SAME : PADDING_VALID; |
| 419 | |
| 420 | // Return the size, converted into units of TOut |
| 421 | return static_cast<unsigned int>( |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 422 | WinogradConv::get_output_storage_size(kern_shape, input_shape, padding) / sizeof(T)); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 425 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 426 | NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::NEWinogradLayerTransformOutputKernel() |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 427 | : _biases(nullptr), _output_workspace(nullptr), _matrix_stride(0), _matrix_row_stride(0), _output_nhwc(nullptr), _num_batches(0), _num_rows(0), _num_cols(0), _num_channels(0) |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 428 | { |
| 429 | } |
| 430 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 431 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 432 | int NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride( |
| 433 | const KernelShape &kernel_shape, const Tensor4DShape &input_shape, const PaddingType padding_type) const |
| 434 | { |
| 435 | return WinogradConv::get_output_matrix_stride(kernel_shape, input_shape, padding_type); |
| 436 | } |
| 437 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 438 | Tensor4DShape NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_shape( |
| 439 | const KernelShape &kernel_shape, const Tensor4DShape &in_shape, const PaddingType padding) const |
| 440 | { |
| 441 | return WinogradConv::get_output_shape(kernel_shape, in_shape, padding); |
| 442 | } |
| 443 | |
| 444 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 445 | void NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure( |
| 446 | const ITensor *biases, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 447 | const ITensor *output_workingspace, |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 448 | const int matrix_stride, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 449 | ITensor *output_nhwc, |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 450 | const int num_batches, |
| 451 | const int num_rows, |
| 452 | const int num_cols, |
| 453 | const int num_channels) |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 454 | { |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 455 | _biases = biases; |
| 456 | _output_workspace = output_workingspace; |
| 457 | _matrix_stride = matrix_stride; |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 458 | _matrix_row_stride = roundup(num_channels, WinogradConv::N_BLOCK); |
| 459 | _output_nhwc = output_nhwc; |
| 460 | _num_batches = num_batches; |
| 461 | _num_rows = num_rows; |
| 462 | _num_cols = num_cols; |
| 463 | _num_channels = num_channels; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 464 | // We don't have the biases buffer at this stage as it hasn't been allocated, we pass in nullptr OutputTransform is only used here to compute the window |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 465 | OutputTransform output_transform(nullptr, _matrix_stride, _matrix_row_stride, nullptr, nullptr, _num_batches, _num_rows, _num_cols, _num_channels); |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 466 | |
| 467 | Window win; |
| 468 | auto win_last = output_transform.get_window(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 469 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 470 | _output_nhwc->info()->set_valid_region(ValidRegion(Coordinates(), _output_nhwc->info()->tensor_shape())); |
| 471 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 472 | INEKernel::configure(win); |
| 473 | } |
| 474 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 475 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 476 | void NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run(const Window &window, const ThreadInfo &info) |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 477 | { |
| 478 | ARM_COMPUTE_UNUSED(info); |
| 479 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 480 | ARM_COMPUTE_ERROR_ON_NULLPTR(_output_workspace); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 481 | ARM_COMPUTE_ERROR_ON_NULLPTR(_output_nhwc); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 482 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 483 | const int out_batch_stride = 0; |
| 484 | const int out_row_stride = _output_nhwc->info()->strides_in_bytes()[2] / sizeof(T); |
| 485 | const int out_col_stride = _output_nhwc->info()->strides_in_bytes()[1] / sizeof(T); |
| 486 | |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 487 | OutputTransform output_transform(reinterpret_cast<T *>(_output_workspace->buffer()), _matrix_stride, _matrix_row_stride, |
Georgios Pinitas | eb84d6b | 2018-07-27 18:28:10 +0100 | [diff] [blame] | 488 | (_biases ? reinterpret_cast<T *>(_biases->buffer() + _biases->info()->offset_first_element_in_bytes()) : nullptr), |
| 489 | reinterpret_cast<T *>(_output_nhwc->buffer() + _output_nhwc->info()->offset_first_element_in_bytes()), |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 490 | _num_batches, _num_rows, _num_cols, _num_channels, out_batch_stride, out_row_stride, out_col_stride); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 491 | |
| 492 | // The code below cannot be moved to configure because biases hasn't been allocated at that point |
| 493 | const size_t fst = window.x().start(); |
| 494 | const size_t lst = window.x().end(); |
| 495 | output_transform.run(fst, lst); |
| 496 | } |
| 497 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 498 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 499 | Status NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 500 | const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 501 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 502 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_output_trans(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info)); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 503 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_output_trans(input->clone().get(), (bias != nullptr ? bias->clone().get() : nullptr), output->clone().get(), |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 504 | winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 505 | .first); |
| 506 | |
| 507 | return Status{}; |
| 508 | } |
| 509 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 510 | template class NEWinogradLayerTransformOutputKernel<float, 2, 2, 3, 3>; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 511 | template class NEWinogradLayerTransformOutputKernel<float, 4, 4, 3, 3>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 512 | template class NEWinogradLayerTransformOutputKernel<float, 2, 2, 5, 5>; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame^] | 513 | template class NEWinogradLayerTransformOutputKernel<float, 1, 6, 1, 3>; |
| 514 | template class NEWinogradLayerTransformOutputKernel<float, 6, 1, 3, 1>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 515 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 516 | } // namespace arm_compute |