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 | { |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 45 | const std::array<Size2D, 8> supported_input_sizes = { { Size2D(1, 3), Size2D(3, 1), Size2D(5, 5), Size2D(3, 3), Size2D(1, 5), Size2D(5, 1), Size2D(7, 1), Size2D(1, 7) } }; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 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); |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(Size2D(input_width, input_height)), "Only 1x3, 3x1, 1x5, 5x1, 7x1, 1x7, 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 | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 62 | const std::array<Size2D, 8> supported_tile_sizes = { { Size2D(2U, 2U), Size2D(4U, 4U), Size2D(1U, 6U), Size2D(6U, 1U), Size2D(4, 1), Size2D(1, 4), Size2D(2, 1), Size2D(1, 2) } }; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 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 | |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 252 | #ifndef DOXYGEN_SKIP_THIS |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 253 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 254 | void NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure( |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 255 | const ITensor *weights_hwio, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 256 | ITensor *output, |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 257 | const int matrix_stride, /** Stride across matrices in the output. */ |
| 258 | const int num_output_channels, /** Number of filters. */ |
| 259 | const int num_input_channels) /** Number of channels in each filter. */ |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 260 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 261 | _weights_hwio = weights_hwio; |
| 262 | _output = output; |
| 263 | _matrix_stride = matrix_stride; |
| 264 | _num_output_channels = num_output_channels; |
| 265 | _num_input_channels = num_input_channels; |
| 266 | |
| 267 | const int matrix_row_stride = roundup(num_output_channels, WinogradConv::N_BLOCK); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 268 | 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] | 269 | Window win; |
| 270 | auto win_last = transform.get_window(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 271 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
| 272 | INEKernel::configure(win); |
| 273 | } |
Vidhya Sudhan Loganathan | d646ae1 | 2018-11-19 15:18:20 +0000 | [diff] [blame] | 274 | #endif /* DOXYGEN_SKIP_THIS */ |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 275 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 276 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 277 | 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] | 278 | { |
| 279 | ARM_COMPUTE_UNUSED(info); |
| 280 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 281 | |
| 282 | const int matrix_row_stride = roundup(_num_output_channels, WinogradConv::N_BLOCK); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 283 | 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] | 284 | const size_t fst = window.x().start(); |
| 285 | const size_t lst = window.x().end(); |
| 286 | transform.run(fst, lst); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 289 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 290 | bool NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::is_parallelisable() const |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 291 | { |
| 292 | return false; |
| 293 | } |
| 294 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 295 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 296 | Status NEWinogradLayerTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output, |
| 297 | const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 298 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 299 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_weight_trans(input, output, winograd_info)); |
| 300 | 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] | 301 | return Status{}; |
| 302 | } |
| 303 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 304 | template class NEWinogradLayerTransformWeightsKernel<float, 2, 2, 3, 3>; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 305 | template class NEWinogradLayerTransformWeightsKernel<float, 4, 4, 3, 3>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 306 | template class NEWinogradLayerTransformWeightsKernel<float, 2, 2, 5, 5>; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 307 | template class NEWinogradLayerTransformWeightsKernel<float, 1, 6, 1, 3>; |
| 308 | template class NEWinogradLayerTransformWeightsKernel<float, 6, 1, 3, 1>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 309 | |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 310 | template class NEWinogradLayerTransformWeightsKernel<float, 1, 4, 1, 5>; |
| 311 | template class NEWinogradLayerTransformWeightsKernel<float, 4, 1, 5, 1>; |
| 312 | template class NEWinogradLayerTransformWeightsKernel<float, 1, 2, 1, 7>; |
| 313 | template class NEWinogradLayerTransformWeightsKernel<float, 2, 1, 7, 1>; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 314 | // Input transform |
| 315 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 316 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 317 | unsigned int NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_input_storage_size( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 318 | int num_batches, /* Number of batches in the input tensor. */ |
| 319 | int num_channels, /* Number of feature maps in the input tensor. */ |
| 320 | int num_rows, /* Number of rows in each feature map. */ |
| 321 | int num_cols, /* Number of columns in each feature map. */ |
| 322 | bool same_padding /* Use "SAME" padding, otherwise use "VALID". */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 323 | ) const |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 324 | { |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 325 | // Construct shapes for the input and kernel tensors. |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 326 | const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels); |
| 327 | const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 328 | const PaddingType padding = (same_padding) ? PADDING_SAME : PADDING_VALID; |
| 329 | // Return the size, converted into units of TIn |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 330 | 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] | 331 | } |
| 332 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 333 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 334 | int NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride( |
| 335 | const KernelShape &kernel_shape, const Tensor4DShape &input_shape, const PaddingType padding_type) const |
| 336 | { |
| 337 | return WinogradConv::get_input_matrix_stride(kernel_shape, input_shape, padding_type); |
| 338 | } |
| 339 | |
| 340 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 341 | NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::NEWinogradLayerTransformInputKernel() |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 342 | : _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] | 343 | { |
| 344 | } |
| 345 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 346 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 347 | void NEWinogradLayerTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 348 | const ITensor *input_nhwc, |
| 349 | const int num_batches, /* Number of batches in input tensor. */ |
| 350 | const int num_rows, /* Number of rows in input tensor. */ |
| 351 | const int num_cols, /* Number of columns in input tensor. */ |
| 352 | const int num_channels, /* Number of channels in input tensor. */ |
| 353 | const PaddingType padding, /* Padding type. */ |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 354 | ITensor *output, /* Base of output matrices. */ |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 355 | const int matrix_stride) /* Stride between output matrices. */ |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 356 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 357 | _input_nhwc = input_nhwc; |
| 358 | _num_batches = num_batches; |
| 359 | _num_rows = num_rows; |
| 360 | _num_cols = num_cols; |
| 361 | _num_channels = num_channels; |
| 362 | _padding = padding; |
| 363 | _output = output; |
| 364 | _matrix_stride = matrix_stride; |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 365 | 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] | 366 | Window win; |
| 367 | auto win_last = transform.get_window(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 368 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
| 369 | INEKernel::configure(win); |
| 370 | } |
| 371 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 372 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 373 | 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] | 374 | { |
| 375 | ARM_COMPUTE_UNUSED(info); |
| 376 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 377 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 378 | const int element_size_in_bytes = _input_nhwc->info()->element_size(); |
| 379 | const int input_col_stride = _input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes; |
| 380 | const int input_row_stride = _input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes; |
| 381 | const int input_batch_stride = _input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes; |
| 382 | const auto input_nhwc_ptr = reinterpret_cast<const T *>(_input_nhwc->buffer() + _input_nhwc->info()->offset_first_element_in_bytes()); |
| 383 | auto output_ptr = reinterpret_cast<T *>(_output->buffer() + _output->info()->offset_first_element_in_bytes()); |
| 384 | InputTransform input_transform(input_nhwc_ptr, |
Georgios Pinitas | eb84d6b | 2018-07-27 18:28:10 +0100 | [diff] [blame] | 385 | _num_batches, _num_rows, _num_cols, _num_channels, _padding, |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 386 | output_ptr, |
Georgios Pinitas | eb84d6b | 2018-07-27 18:28:10 +0100 | [diff] [blame] | 387 | _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] | 388 | |
| 389 | // 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] | 390 | const size_t fst = window.x().start(); |
| 391 | const size_t lst = window.x().end(); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 392 | input_transform.run(fst, lst); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 393 | } |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 394 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 395 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 396 | 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] | 397 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 398 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info)); |
| 399 | 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] | 400 | |
| 401 | return Status{}; |
| 402 | } |
| 403 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 404 | template class NEWinogradLayerTransformInputKernel<float, 2, 2, 3, 3>; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 405 | template class NEWinogradLayerTransformInputKernel<float, 4, 4, 3, 3>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 406 | template class NEWinogradLayerTransformInputKernel<float, 2, 2, 5, 5>; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 407 | template class NEWinogradLayerTransformInputKernel<float, 1, 6, 1, 3>; |
| 408 | template class NEWinogradLayerTransformInputKernel<float, 6, 1, 3, 1>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 409 | |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 410 | template class NEWinogradLayerTransformInputKernel<float, 1, 4, 1, 5>; |
| 411 | template class NEWinogradLayerTransformInputKernel<float, 4, 1, 5, 1>; |
| 412 | template class NEWinogradLayerTransformInputKernel<float, 1, 2, 1, 7>; |
| 413 | template class NEWinogradLayerTransformInputKernel<float, 2, 1, 7, 1>; |
| 414 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 415 | // Output transform |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 416 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 417 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 418 | unsigned int NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_storage_size( |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 419 | int num_batches, /* Number of batches in the output tensor. */ |
| 420 | int num_rows, /* Number of rows in each feature map of the input tensor. */ |
| 421 | int num_cols, /* Number of columns in each feature map of the input tensor. */ |
| 422 | int num_output_channels, /* Number of feature maps in the output tensor. */ |
| 423 | bool same_padding /* Use "SAME" padding, otherwise use "VALID". */ |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 424 | ) const |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 425 | { |
| 426 | // Construct shapes for the input and kernel tensors. |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 427 | const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1); |
| 428 | const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 429 | const PaddingType padding = (same_padding) ? PADDING_SAME : PADDING_VALID; |
| 430 | |
| 431 | // Return the size, converted into units of TOut |
| 432 | return static_cast<unsigned int>( |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 433 | WinogradConv::get_output_storage_size(kern_shape, input_shape, padding) / sizeof(T)); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 436 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 437 | NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::NEWinogradLayerTransformOutputKernel() |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 438 | : _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] | 439 | { |
| 440 | } |
| 441 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 442 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 443 | int NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride( |
| 444 | const KernelShape &kernel_shape, const Tensor4DShape &input_shape, const PaddingType padding_type) const |
| 445 | { |
| 446 | return WinogradConv::get_output_matrix_stride(kernel_shape, input_shape, padding_type); |
| 447 | } |
| 448 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 449 | Tensor4DShape NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_shape( |
| 450 | const KernelShape &kernel_shape, const Tensor4DShape &in_shape, const PaddingType padding) const |
| 451 | { |
| 452 | return WinogradConv::get_output_shape(kernel_shape, in_shape, padding); |
| 453 | } |
| 454 | |
| 455 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 456 | void NEWinogradLayerTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure( |
| 457 | const ITensor *biases, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 458 | const ITensor *output_workingspace, |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 459 | const int matrix_stride, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 460 | ITensor *output_nhwc, |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 461 | const int num_batches, |
| 462 | const int num_rows, |
| 463 | const int num_cols, |
| 464 | const int num_channels) |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 465 | { |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 466 | _biases = biases; |
| 467 | _output_workspace = output_workingspace; |
| 468 | _matrix_stride = matrix_stride; |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 469 | _matrix_row_stride = roundup(num_channels, WinogradConv::N_BLOCK); |
| 470 | _output_nhwc = output_nhwc; |
| 471 | _num_batches = num_batches; |
| 472 | _num_rows = num_rows; |
| 473 | _num_cols = num_cols; |
| 474 | _num_channels = num_channels; |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 475 | // 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] | 476 | 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] | 477 | |
| 478 | Window win; |
| 479 | auto win_last = output_transform.get_window(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 480 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 481 | _output_nhwc->info()->set_valid_region(ValidRegion(Coordinates(), _output_nhwc->info()->tensor_shape())); |
| 482 | |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 483 | INEKernel::configure(win); |
| 484 | } |
| 485 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 486 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
| 487 | 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] | 488 | { |
| 489 | ARM_COMPUTE_UNUSED(info); |
| 490 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 491 | ARM_COMPUTE_ERROR_ON_NULLPTR(_output_workspace); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 492 | ARM_COMPUTE_ERROR_ON_NULLPTR(_output_nhwc); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 493 | |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 494 | const int out_batch_stride = 0; |
| 495 | const int out_row_stride = _output_nhwc->info()->strides_in_bytes()[2] / sizeof(T); |
| 496 | const int out_col_stride = _output_nhwc->info()->strides_in_bytes()[1] / sizeof(T); |
| 497 | |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 498 | 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] | 499 | (_biases ? reinterpret_cast<T *>(_biases->buffer() + _biases->info()->offset_first_element_in_bytes()) : nullptr), |
| 500 | 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] | 501 | _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] | 502 | |
| 503 | // The code below cannot be moved to configure because biases hasn't been allocated at that point |
| 504 | const size_t fst = window.x().start(); |
| 505 | const size_t lst = window.x().end(); |
| 506 | output_transform.run(fst, lst); |
| 507 | } |
| 508 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 509 | template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols> |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 510 | 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] | 511 | const WinogradInfo &winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 512 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 513 | 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] | 514 | 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] | 515 | winograd_info) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 516 | .first); |
| 517 | |
| 518 | return Status{}; |
| 519 | } |
| 520 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 521 | template class NEWinogradLayerTransformOutputKernel<float, 2, 2, 3, 3>; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 522 | template class NEWinogradLayerTransformOutputKernel<float, 4, 4, 3, 3>; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 523 | template class NEWinogradLayerTransformOutputKernel<float, 2, 2, 5, 5>; |
Pablo Tello | bda6e4b | 2018-08-22 11:40:33 +0100 | [diff] [blame] | 524 | template class NEWinogradLayerTransformOutputKernel<float, 1, 6, 1, 3>; |
| 525 | template class NEWinogradLayerTransformOutputKernel<float, 6, 1, 3, 1>; |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 526 | |
Pablo Tello | 000d33a | 2018-09-03 16:59:20 +0100 | [diff] [blame] | 527 | template class NEWinogradLayerTransformOutputKernel<float, 1, 4, 1, 5>; |
| 528 | template class NEWinogradLayerTransformOutputKernel<float, 4, 1, 5, 1>; |
| 529 | template class NEWinogradLayerTransformOutputKernel<float, 1, 2, 1, 7>; |
| 530 | template class NEWinogradLayerTransformOutputKernel<float, 2, 1, 7, 1>; |
| 531 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 532 | } // namespace arm_compute |