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/runtime/NEON/functions/NEWinogradConvolutionLayer.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 25 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Error.h" |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/NEON/kernels/NEWinogradConvolutionLayerKernel.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Utils.h" |
| 29 | #include "arm_compute/core/Validate.h" |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Validate.h" |
| 31 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 32 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/NEON/functions/NEGEMMAssemblyDispatch.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 34 | #include "support/ToolchainSupport.h" |
| 35 | |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 36 | #include "arm_compute/core/NEON/kernels/convolution/winograd/winograd_gemm.hpp" |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 37 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 40 | namespace |
| 41 | { |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 42 | inline Tensor4DShape internal_get_input_shape(const arm_compute::ITensor *input) |
| 43 | { |
| 44 | const DataLayout data_layout = input->info()->data_layout(); |
| 45 | const int in_width = input->info()->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH)); |
| 46 | const int in_height = input->info()->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT)); |
| 47 | const int in_channels = input->info()->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL)); |
| 48 | const int in_batches = input->info()->dimension(3); |
| 49 | |
| 50 | return Tensor4DShape({ in_batches, in_height, in_width, in_channels }); |
| 51 | } |
| 52 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 53 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info) |
| 54 | { |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 55 | const DataLayout data_layout = input->data_layout(); |
| 56 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 57 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 58 | |
| 59 | ARM_COMPUTE_UNUSED(output); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 60 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32); |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 61 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 62 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != 3 && weights->dimension(height_idx) != 5, "Only 3 and 5 kernels are supported"); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 63 | ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4); |
| 64 | |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd layer only supports unit strides."); |
| 66 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 67 | if(biases != nullptr) |
| 68 | { |
| 69 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, biases); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 71 | } |
| 72 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 73 | return Status{}; |
| 74 | } |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 75 | |
| 76 | Size2D winograd_output_tile(const Size2D &input_dims, const Size2D &kernel_dims) |
| 77 | { |
| 78 | Size2D output_tile = Size2D{}; |
| 79 | |
| 80 | if(kernel_dims == Size2D(3U, 3U)) |
| 81 | { |
| 82 | output_tile = (input_dims.width <= 4 && input_dims.height <= 4) ? Size2D(2U, 2U) : Size2D(4U, 4U); |
| 83 | } |
| 84 | else if(kernel_dims == Size2D(5U, 5U)) |
| 85 | { |
| 86 | output_tile = Size2D(2U, 2U); |
| 87 | } |
| 88 | |
| 89 | return output_tile; |
| 90 | } |
| 91 | |
| 92 | bool check_support_fast_math(const Size2D &output_tile, const Size2D &kernel_size) |
| 93 | { |
| 94 | // Check if we want to configure a Winograd configuration which requires fast math |
| 95 | using WinogradConfiguration = std::pair<std::pair<int, int>, std::pair<int, int>>; |
| 96 | |
| 97 | std::vector<WinogradConfiguration> fast_math_winograd = |
| 98 | { |
| 99 | WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(5, 5)), |
| 100 | WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(5, 5)) |
| 101 | }; |
| 102 | |
| 103 | auto p = std::make_pair(std::pair<int, int>(output_tile.width, output_tile.height), |
| 104 | std::pair<int, int>(kernel_size.width, kernel_size.height)); |
| 105 | |
| 106 | return std::find(fast_math_winograd.begin(), fast_math_winograd.end(), p) != fast_math_winograd.end(); |
| 107 | } |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 108 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 109 | } //namespace |
| 110 | |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 111 | NEWinogradConvolutionLayer::NEWinogradConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager) |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 112 | : _memory_group(memory_manager), _asm_glue(memory_manager), _transform_input_kernel(nullptr), _transform_output_kernel(nullptr), _transform_weights_kernel(nullptr), _activationlayer_function(), |
| 113 | _permute_input(), _permute_weights(), _permute_output(), _input_workspace(), _output_workspace(), _kernel_storage(), _input_nhwc(), _output_nhwc(), _weights_hwio(), _input(), _weights(), _output(), |
| 114 | _is_prepared(false), _is_activationlayer_enabled(false) |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 115 | { |
| 116 | } /* arm_compute */ |
| 117 | |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 118 | void NEWinogradConvolutionLayer::configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, |
| 119 | bool enable_fast_math) |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 120 | { |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 121 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
Andrew Mundy | 4d9379a | 2018-03-15 16:47:03 +0000 | [diff] [blame] | 122 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), conv_info)); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 123 | |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 124 | // Get indices for the width and height |
| 125 | const DataLayout data_layout = input->info()->data_layout(); |
| 126 | const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 127 | const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 128 | const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 129 | |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 130 | const Size2D input_dims = Size2D(input->info()->dimension(width_idx), input->info()->dimension(height_idx)); |
| 131 | const Size2D kernel_size = Size2D(weights->info()->dimension(width_idx), weights->info()->dimension(height_idx)); |
| 132 | const Size2D output_tile = winograd_output_tile(input_dims, kernel_size); |
| 133 | |
| 134 | // Check if the Winograd configuration requires fast math |
| 135 | if(!enable_fast_math) |
| 136 | { |
| 137 | ARM_COMPUTE_ERROR_ON_MSG(check_support_fast_math(output_tile, kernel_size), "This Winograd configuration requires enable_fast_math=true"); |
| 138 | } |
| 139 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 140 | _weights = weights; |
| 141 | _input = input; |
| 142 | _output = output; |
| 143 | _is_prepared = false; |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 144 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 145 | std::unique_ptr<INEWinogradLayerTransformInputKernel<float>> transform_input_kernel; |
| 146 | std::unique_ptr<INEWinogradLayerTransformWeightsKernel<float>> transform_weights_kernel; |
| 147 | std::unique_ptr<INEWinogradLayerTransformOutputKernel<float>> transform_output_kernel; |
| 148 | |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 149 | int n_gemms = 0; |
| 150 | int N_BLOCK = 0; // Size of block used by GEMM. |
Michalis Spyrou | 2b3129e | 2018-04-25 18:10:13 +0100 | [diff] [blame] | 151 | |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 152 | switch(kernel_size.width) |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 153 | { |
| 154 | case 3: |
| 155 | { |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 156 | if(input->info()->dimension(width_idx) > 4 && input->info()->dimension(height_idx) > 4) |
| 157 | { |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 158 | using config = NEWinogradLayerConfiguration<float, float, 4, 4, 3, 3>; |
| 159 | transform_input_kernel = support::cpp14::make_unique<config::TransformInputKernel>(); |
| 160 | transform_weights_kernel = support::cpp14::make_unique<config::TransformWeightsKernel>(); |
| 161 | transform_output_kernel = support::cpp14::make_unique<config::TransformOutputKernel>(); |
| 162 | n_gemms = config::WinogradBase::N_GEMMS; |
| 163 | N_BLOCK = config::WinogradConv::N_BLOCK; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 164 | } |
| 165 | else |
| 166 | { |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 167 | using config = NEWinogradLayerConfiguration<float, float, 2, 2, 3, 3>; |
| 168 | transform_input_kernel = support::cpp14::make_unique<config::TransformInputKernel>(); |
| 169 | transform_weights_kernel = support::cpp14::make_unique<config::TransformWeightsKernel>(); |
| 170 | transform_output_kernel = support::cpp14::make_unique<config::TransformOutputKernel>(); |
| 171 | n_gemms = config::WinogradBase::N_GEMMS; |
| 172 | N_BLOCK = config::WinogradConv::N_BLOCK; |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 173 | } |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 174 | break; |
| 175 | } |
| 176 | case 5: |
| 177 | { |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 178 | using config = NEWinogradLayerConfiguration<float, float, 2, 2, 5, 5>; |
| 179 | transform_input_kernel = support::cpp14::make_unique<config::TransformInputKernel>(); |
| 180 | transform_weights_kernel = support::cpp14::make_unique<config::TransformWeightsKernel>(); |
| 181 | transform_output_kernel = support::cpp14::make_unique<config::TransformOutputKernel>(); |
| 182 | n_gemms = config::WinogradBase::N_GEMMS; |
| 183 | N_BLOCK = config::WinogradConv::N_BLOCK; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 184 | break; |
| 185 | } |
| 186 | default: |
| 187 | { |
| 188 | ARM_COMPUTE_ERROR("Not supported."); |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | |
Pablo Tello | 679463a | 2018-02-06 11:47:59 +0000 | [diff] [blame] | 193 | const PaddingType use_padding_type = (conv_info.pad_left() != 0u) ? PADDING_SAME : PADDING_VALID; |
| 194 | const bool use_same_padding = use_padding_type == PADDING_SAME; |
| 195 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 196 | // Get convolved dimensions |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 197 | const int in_channels = input->info()->dimension(channel_idx); |
| 198 | const int out_channels = output->info()->dimension(channel_idx); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 199 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 200 | const Tensor4DShape in_shape(internal_get_input_shape(input)); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 201 | const DataType data_type = input->info()->data_type(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 202 | const size_t data_type_size = input->info()->element_size(); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 203 | // Get the memory required to instantiate a new Winograd operator. |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 204 | constexpr size_t storage_alignment = 64; |
| 205 | |
| 206 | // Kernel Storage |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 207 | const size_t kernel_storage_size = transform_weights_kernel->get_weight_storage_size(out_channels, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 208 | in_channels) |
| 209 | * data_type_size |
| 210 | + storage_alignment - 1; /* FIXME: remove alignment after COMPMID-1088 */ |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 211 | |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 212 | // Input storage |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 213 | const size_t input_storage_size = transform_input_kernel->get_input_storage_size(in_shape.n_batches, in_shape.n_channels, in_shape.n_rows, in_shape.n_cols, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 214 | use_same_padding) |
| 215 | * data_type_size |
| 216 | + storage_alignment - 1; /* FIXME: remove alignment after COMPMID-1088 */ |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 217 | |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 218 | // Output storage |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 219 | const size_t output_storage_size = transform_output_kernel->get_output_storage_size(in_shape.n_batches, in_shape.n_rows, in_shape.n_cols, out_channels, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 220 | use_same_padding) |
| 221 | * data_type_size |
| 222 | + storage_alignment - 1; /* FIXME: remove alignment after COMPMID-1088 */ |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 223 | ; |
| 224 | const KernelShape kernel_shape({ out_channels, static_cast<int>(kernel_size.height), static_cast<int>(kernel_size.width), in_channels }); |
| 225 | const int kernel_matrix_stride = transform_weights_kernel->get_matrix_stride(kernel_shape); |
| 226 | |
| 227 | const int output_matrix_stride = transform_output_kernel->get_matrix_stride(kernel_shape, in_shape, use_padding_type); |
| 228 | const auto output_shape(transform_output_kernel->get_output_shape(kernel_shape, in_shape, use_padding_type)); |
| 229 | |
| 230 | const int input_matrix_stride = transform_input_kernel->get_matrix_stride(kernel_shape, in_shape, use_padding_type); |
| 231 | |
| 232 | // Configure GEMM |
| 233 | const int tile_rows = iceildiv(output_shape.n_rows, output_tile.height); |
| 234 | const int tile_cols = iceildiv(output_shape.n_cols, output_tile.width); |
| 235 | const int m = in_shape.n_batches * tile_rows * tile_cols; |
| 236 | const int k = in_shape.n_channels; |
| 237 | const int n = out_channels; |
| 238 | const int kernel_matrix_row_stride = roundup(out_channels, N_BLOCK); |
| 239 | const int output_matrix_row_stride = kernel_matrix_row_stride; |
| 240 | |
| 241 | TensorShape a_shape(k, m, 1, n_gemms); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 242 | Strides a_strides(data_type_size); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 243 | a_strides.set(1, a_strides[0] * k); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 244 | //a_strides.set(2, data_type_size * input_matrix_stride / n_gemms); FIXME: This is the real batch size, but RSH's code crashes if it's not 0. |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 245 | a_strides.set(2, 0); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 246 | a_strides.set(3, data_type_size * input_matrix_stride); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 247 | |
| 248 | TensorShape b_shape(n, k, n_gemms); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 249 | Strides b_strides(data_type_size); |
| 250 | b_strides.set(1, data_type_size * kernel_matrix_row_stride); |
| 251 | b_strides.set(2, data_type_size * kernel_matrix_stride); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 252 | |
| 253 | TensorShape d_shape(n, m, 1, n_gemms); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 254 | Strides d_strides(data_type_size); |
| 255 | d_strides.set(1, data_type_size * output_matrix_row_stride); |
| 256 | //d_strides.set(2, data_type_size * output_matrix_stride / n_gemms); FIXME: This is the real batch size, but RSH's code crashes if it's not 0. |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 257 | d_strides.set(2, 0); |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 258 | d_strides.set(3, data_type_size * output_matrix_stride); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 259 | |
| 260 | TensorInfo a_info, b_info, d_info; |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 261 | a_info.init(a_shape, 1, data_type, a_strides, 0, input_storage_size); |
| 262 | b_info.init(b_shape, 1, data_type, b_strides, 0, kernel_storage_size); |
| 263 | d_info.init(d_shape, 1, data_type, d_strides, 0, output_storage_size); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 264 | |
| 265 | _input_workspace.allocator()->init(a_info, storage_alignment); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 266 | _kernel_storage.allocator()->init(b_info, storage_alignment); |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 267 | _output_workspace.allocator()->init(d_info, storage_alignment); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 268 | |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 269 | // configure and allocate dst tensor to be used to convert from winograd domain to spatial domain when calling to reshape_output() |
| 270 | TensorInfo info(TensorShape(_output->info()->dimension(2), _output->info()->dimension(0), |
| 271 | _output->info()->dimension(1), _output->info()->dimension(3)), |
| 272 | 1, _output->info()->data_type()); |
| 273 | _output_nhwc.allocator()->init(info); |
Pablo Tello | 02541fb | 2017-12-15 09:48:59 +0000 | [diff] [blame] | 274 | |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 275 | // Configure the InputTransform |
Anthony Barbier | 20394d5 | 2018-08-02 11:29:09 +0100 | [diff] [blame^] | 276 | _memory_group.manage(&_input_workspace); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 277 | if(data_layout == DataLayout::NCHW) |
| 278 | { |
| 279 | // configure the kernel to transform the input tensor from NCHW -> NHWC |
| 280 | _permute_input.configure(input, &_input_nhwc, PermutationVector(2U, 0U, 1U)); |
| 281 | _input_nhwc.allocator()->allocate(); |
| 282 | transform_input_kernel->configure(&_input_nhwc, in_shape.n_batches, in_shape.n_rows, in_shape.n_cols, in_shape.n_channels, use_padding_type, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 283 | &_input_workspace, input_matrix_stride); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 284 | } |
| 285 | else |
| 286 | { |
| 287 | transform_input_kernel->configure(_input, in_shape.n_batches, in_shape.n_rows, in_shape.n_cols, in_shape.n_channels, use_padding_type, |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 288 | &_input_workspace, input_matrix_stride); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 289 | } |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 290 | |
| 291 | // Configure WeightsTransform |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 292 | if(data_layout == DataLayout::NCHW) |
| 293 | { |
| 294 | // Re-order a weight tensor from [Output feature map x Input feature map x Height x Width] to [Height x Width x Input feature map x Output feature map] |
| 295 | _permute_weights.configure(weights, &_weights_hwio, PermutationVector(3U, 2U, 0U, 1U)); |
| 296 | |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 297 | transform_weights_kernel->configure(&_weights_hwio, &_kernel_storage, kernel_matrix_stride, out_channels, in_channels); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 298 | } |
| 299 | else |
| 300 | { |
| 301 | // Re-order a weight tensor from [Output feature map x Input feature map x Height x Width] to [Height x Width x Input feature map x Output feature map] |
| 302 | _permute_weights.configure(weights, &_weights_hwio, PermutationVector(3U, 0U, 1U, 2U)); |
| 303 | |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 304 | transform_weights_kernel->configure(&_weights_hwio, &_kernel_storage, kernel_matrix_stride, out_channels, in_channels); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 305 | } |
| 306 | _weights_hwio.allocator()->allocate(); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 307 | |
| 308 | // Configure OutputTransform |
| 309 | //The biases tensor has not been allocated at this point in time, the output transform will add the biases to the final result in the run() method |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 310 | |
Anthony Barbier | 20394d5 | 2018-08-02 11:29:09 +0100 | [diff] [blame^] | 311 | _memory_group.manage(&_output_workspace); |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 312 | if(data_layout == DataLayout::NCHW) |
| 313 | { |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 314 | transform_output_kernel->configure(biases, &_output_workspace, |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 315 | output_matrix_stride, &_output_nhwc, |
| 316 | in_shape.n_batches, output_shape.n_rows, output_shape.n_cols, out_channels); |
| 317 | } |
| 318 | else |
| 319 | { |
Anthony Barbier | e155337 | 2018-07-16 18:53:52 +0100 | [diff] [blame] | 320 | transform_output_kernel->configure(biases, &_output_workspace, |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 321 | output_matrix_stride, _output, |
| 322 | in_shape.n_batches, output_shape.n_rows, output_shape.n_cols, out_channels); |
| 323 | } |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 324 | |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 325 | _asm_glue.configure(&_input_workspace, &_kernel_storage, &_output_workspace, 1.0f, 0.f, false); |
Anthony Barbier | 20394d5 | 2018-08-02 11:29:09 +0100 | [diff] [blame^] | 326 | _input_workspace.allocator()->allocate(); |
| 327 | _kernel_storage.allocator()->allocate(); |
| 328 | _output_workspace.allocator()->allocate(); |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 329 | |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 330 | // Reorder the convoluted output to ACL's ordering NCHW |
| 331 | _permute_output.configure(&_output_nhwc, _output, PermutationVector(1U, 2U, 0U)); |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 332 | |
Anthony Barbier | 20394d5 | 2018-08-02 11:29:09 +0100 | [diff] [blame^] | 333 | _output_nhwc.allocator()->allocate(); |
| 334 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 335 | _transform_input_kernel = std::move(transform_input_kernel); |
| 336 | _transform_weights_kernel = std::move(transform_weights_kernel); |
| 337 | _transform_output_kernel = std::move(transform_output_kernel); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 338 | |
| 339 | //Configure Activation Layer |
| 340 | _is_activationlayer_enabled = act_info.enabled(); |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 341 | if(_is_activationlayer_enabled) |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 342 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 343 | _activationlayer_function.configure(_output, nullptr, act_info); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 344 | } |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 347 | void NEWinogradConvolutionLayer::run() |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 348 | { |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 349 | const DataLayout data_layout = _input->info()->data_layout(); |
| 350 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 351 | prepare(); |
| 352 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 353 | _memory_group.acquire(); |
Pablo Tello | 679463a | 2018-02-06 11:47:59 +0000 | [diff] [blame] | 354 | |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 355 | if(data_layout == DataLayout::NCHW) |
| 356 | { |
| 357 | //Bring channels to the front as Winograd code expects the tensor to be in the format NHWC |
| 358 | _permute_input.run(); |
| 359 | } |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 360 | // Transform input tensor to the winograd domain |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 361 | NEScheduler::get().schedule(_transform_input_kernel.get(), Window::DimX); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 362 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 363 | //Run 16 GEMMs in multiple threads, each kernel runs one or more GEMMs |
Anthony Barbier | 578225e | 2018-07-16 18:00:11 +0100 | [diff] [blame] | 364 | _asm_glue.run(); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 365 | |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 366 | // Transform output tensor to the spatial domain |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 367 | NEScheduler::get().schedule(_transform_output_kernel.get(), Window::DimX); |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 368 | |
Pablo Tello | 7df2786 | 2018-05-30 11:44:26 +0100 | [diff] [blame] | 369 | if(data_layout == DataLayout::NCHW) |
| 370 | { |
| 371 | // Reorder the convoluted output to ACL's ordering NCHW |
| 372 | _permute_output.run(); |
| 373 | } |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 374 | |
| 375 | if(_is_activationlayer_enabled) |
| 376 | { |
| 377 | _activationlayer_function.run(); |
| 378 | } |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 379 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 380 | _memory_group.release(); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 381 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 382 | |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 383 | Status NEWinogradConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 384 | const ActivationLayerInfo &act_info, bool enable_fast_math) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 385 | { |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 386 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 387 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info)); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 388 | |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 389 | // Get indices for the width and height |
| 390 | const size_t idx_width = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH); |
| 391 | const size_t idx_height = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT); |
| 392 | |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 393 | // Input shape, kernel size and output tile |
| 394 | const Size2D input_dims = Size2D(input->dimension(idx_width), input->dimension(idx_height)); |
| 395 | const Size2D kernel_size = Size2D(weights->dimension(idx_width), weights->dimension(idx_height)); |
| 396 | const Size2D output_tile = winograd_output_tile(input_dims, kernel_size); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 397 | |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 398 | // Check if the Winograd configuration requires fast math |
| 399 | if(!enable_fast_math) |
| 400 | { |
| 401 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(check_support_fast_math(output_tile, kernel_size), "This Winograd configuration requires enable_fast_math=true"); |
| 402 | } |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 403 | |
| 404 | const WinogradInfo winograd_info = WinogradInfo(output_tile, |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 405 | kernel_size, |
| 406 | input_dims, |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 407 | conv_info, |
| 408 | input->data_layout()); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 409 | |
| 410 | // Validate input transform |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 411 | const TensorShape input0_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] | 412 | const TensorInfo input0 = input->clone()->set_tensor_shape(input0_shape); |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 413 | |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 414 | switch(weights->dimension(idx_width)) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 415 | { |
| 416 | case 3: |
| 417 | { |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 418 | if(input_dims.width > 4 && input_dims.height > 4) |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 419 | { |
| 420 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformInputKernel<float, 4, 4, 3, 3>::validate(input, &input0, winograd_info))); |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformInputKernel<float, 2, 2, 3, 3>::validate(input, &input0, winograd_info))); |
| 425 | } |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 426 | break; |
| 427 | } |
| 428 | case 5: |
| 429 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 430 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformInputKernel<float, 2, 2, 5, 5>::validate(input, &input0, winograd_info))); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 431 | break; |
| 432 | } |
| 433 | default: |
| 434 | { |
| 435 | ARM_COMPUTE_RETURN_ERROR_MSG("Only 3x3 and 5x5 kernels supported."); |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | // Validate filter transform |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 440 | const TensorShape input1_shape = misc::shape_calculator::compute_winograd_filter_transform_shape(*weights, winograd_info); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 441 | const TensorInfo input1 = weights->clone()->set_tensor_shape(input1_shape); |
| 442 | |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 443 | switch(weights->dimension(idx_width)) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 444 | { |
| 445 | case 3: |
| 446 | { |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 447 | if(input_dims.width > 4 && input_dims.height > 4) |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 448 | { |
| 449 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformWeightsKernel<float, 4, 4, 3, 3>::validate(weights, &input1, winograd_info))); |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformWeightsKernel<float, 2, 2, 3, 3>::validate(weights, &input1, winograd_info))); |
| 454 | } |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 455 | break; |
| 456 | } |
| 457 | case 5: |
| 458 | { |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 459 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformWeightsKernel<float, 2, 2, 5, 5>::validate(weights, &input1, winograd_info))); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 460 | break; |
| 461 | } |
| 462 | default: |
| 463 | { |
| 464 | ARM_COMPUTE_RETURN_ERROR_MSG("Only 3x3 and 5x5 kernels supported."); |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | // Validate batched matrix multiply |
| 469 | TensorShape batched_mm_output_shape = input0.tensor_shape(); |
| 470 | batched_mm_output_shape[0] = input1.tensor_shape()[0]; |
| 471 | const TensorInfo batched_mm_output = input0.clone()->set_tensor_shape(batched_mm_output_shape); |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 472 | switch(weights->dimension(idx_width)) |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 473 | { |
| 474 | case 3: |
| 475 | { |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 476 | if(input_dims.width > 4 && input_dims.height > 4) |
Vidhya Sudhan Loganathan | cb0010b | 2018-05-11 16:23:53 +0100 | [diff] [blame] | 477 | { |
| 478 | // Validate output transform |
| 479 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformOutputKernel<float, 4, 4, 3, 3>::validate(&batched_mm_output, biases, output, winograd_info))); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | // Validate output transform |
| 484 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformOutputKernel<float, 2, 2, 3, 3>::validate(&batched_mm_output, biases, output, winograd_info))); |
| 485 | } |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 486 | break; |
| 487 | } |
| 488 | case 5: |
| 489 | { |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 490 | // Validate output transform |
Vidhya Sudhan Loganathan | 84ce1f9 | 2018-04-25 13:00:09 +0100 | [diff] [blame] | 491 | ARM_COMPUTE_RETURN_ON_ERROR((NEWinogradLayerTransformOutputKernel<float, 2, 2, 5, 5>::validate(&batched_mm_output, biases, output, winograd_info))); |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 492 | break; |
| 493 | } |
| 494 | default: |
| 495 | { |
| 496 | ARM_COMPUTE_RETURN_ERROR_MSG("Only 3x3 and 5x5 kernels supported."); |
| 497 | break; |
| 498 | } |
| 499 | } |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 500 | // Validate Activation Layer |
| 501 | if(act_info.enabled()) |
| 502 | { |
| 503 | NEActivationLayer::validate(output, nullptr, act_info); |
| 504 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 505 | return Status{}; |
| 506 | } |
| 507 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 508 | void NEWinogradConvolutionLayer::prepare() |
| 509 | { |
| 510 | if(!_is_prepared) |
| 511 | { |
| 512 | // Permute weights |
| 513 | _permute_weights.run(); |
| 514 | _weights->mark_as_unused(); |
| 515 | |
| 516 | // Transform weights |
| 517 | NEScheduler::get().schedule(_transform_weights_kernel.get(), Window::DimX); |
| 518 | _weights_hwio.allocator()->free(); |
| 519 | |
| 520 | _is_prepared = true; |
| 521 | } |
| 522 | } |
| 523 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 524 | } // namespace arm_compute |