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