blob: 3b54ed62c719e541e095f6bf6daf61299f7147b6 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01001/*
Georgios Pinitasf72f9362018-01-12 16:29:45 +00002 * Copyright (c) 2017-2018 ARM Limited.
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01003 *
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 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000024#include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010025
26#include "arm_compute/core/Helpers.h"
27#include "arm_compute/core/ITensor.h"
28#include "arm_compute/core/PixelValue.h"
Georgios Pinitasd05dce42018-01-22 16:29:17 +000029#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Georgios Pinitasf72f9362018-01-12 16:29:45 +000030#include "arm_compute/core/utils/quantization/AsymmHelpers.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010031#include "arm_compute/runtime/NEON/NEScheduler.h"
32#include "support/ToolchainSupport.h"
33
34using namespace arm_compute;
Georgios Pinitasd05dce42018-01-22 16:29:17 +000035using namespace arm_compute::misc;
Georgios Pinitas4074c992018-01-30 18:13:46 +000036using namespace arm_compute::misc::shape_calculator;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010037
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000038NEDepthwiseConvolutionLayer3x3::NEDepthwiseConvolutionLayer3x3()
Georgios Pinitas4074c992018-01-30 18:13:46 +000039 : _dwc_kernel(), _output_stage_kernel(), _border_handler(), _permute_input(), _permute_weights(), _permute_output(), _accumulator(), _input_nhwc(), _weights_hwio(), _output_nhwc(), _has_bias(false),
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010040 _is_quantized(false), _is_optimized(false), _are_weights_reshaped(false), _is_nchw(true), _is_first_run(true)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010041{
42}
43
Giorgio Arena76572242018-04-04 17:44:26 +010044void NEDepthwiseConvolutionLayer3x3::configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010045{
Georgios Pinitasf72f9362018-01-12 16:29:45 +000046 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F32);
Georgios Pinitas1250a5a2018-01-02 13:27:37 +000047 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010048
Georgios Pinitasf72f9362018-01-12 16:29:45 +000049 PixelValue zero_value(0.f);
50
51 _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type());
52 _has_bias = biases != nullptr;
Georgios Pinitas4074c992018-01-30 18:13:46 +000053 _is_optimized = NEDepthwiseConvolutionLayer3x3Kernel::is_optimized_execution_possible(input->info()->tensor_shape(),
54 conv_info,
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010055 input->info()->data_type(),
Giorgio Arena76572242018-04-04 17:44:26 +010056 depth_multiplier,
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010057 input->info()->data_layout());
Georgios Pinitas4074c992018-01-30 18:13:46 +000058 _are_weights_reshaped = false;
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010059 _is_nchw = input->info()->data_layout() == DataLayout::NCHW;
60
61 ARM_COMPUTE_ERROR_ON(!_is_optimized && !_is_nchw);
Georgios Pinitasf72f9362018-01-12 16:29:45 +000062
Georgios Pinitas4074c992018-01-30 18:13:46 +000063 if(_is_optimized)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010064 {
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010065 if(_is_nchw)
66 {
67 // Configure the function to transform the input tensor from NCHW -> NHWC
68 _permute_input.configure(input, &_input_nhwc, PermutationVector(2U, 0U, 1U));
Georgios Pinitas4074c992018-01-30 18:13:46 +000069
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010070 // Configure the function to transform the weights tensor from IHW -> HWI
71 _permute_weights.configure(weights, &_weights_hwio, PermutationVector(2U, 0U, 1U));
Georgios Pinitas4074c992018-01-30 18:13:46 +000072
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010073 // Configure optimized depthwise
Giorgio Arena76572242018-04-04 17:44:26 +010074 _dwc_kernel.configure(&_input_nhwc, &_weights_hwio, &_output_nhwc, conv_info, depth_multiplier, DataLayout::NHWC);
Georgios Pinitas4074c992018-01-30 18:13:46 +000075
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010076 // Configure the function to transform the convoluted output to ACL's native ordering format NCHW
77 _permute_output.configure(&_output_nhwc, output, PermutationVector(1U, 2U, 0U));
Georgios Pinitas4074c992018-01-30 18:13:46 +000078
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010079 // Allocate tensors
80 _input_nhwc.allocator()->allocate();
81 _weights_hwio.allocator()->allocate();
82 _output_nhwc.allocator()->allocate();
83 }
84 else
85 {
Giorgio Arena76572242018-04-04 17:44:26 +010086 _dwc_kernel.configure(input, weights, output, conv_info, depth_multiplier, DataLayout::NHWC);
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010087 }
Georgios Pinitasf72f9362018-01-12 16:29:45 +000088 }
Georgios Pinitas4074c992018-01-30 18:13:46 +000089 else
90 {
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010091 // Allocate the intermediate accumulator tensor in case of quantized input
Georgios Pinitas4074c992018-01-30 18:13:46 +000092 if(_is_quantized)
93 {
94 _accumulator.allocator()->init(TensorInfo(output->info()->tensor_shape(), 1, DataType::S32));
95 _accumulator.info()->set_quantization_info(input->info()->quantization_info());
96 zero_value = PixelValue(static_cast<uint32_t>(input->info()->quantization_info().offset));
97 }
Georgios Pinitasf72f9362018-01-12 16:29:45 +000098
Georgios Pinitas4074c992018-01-30 18:13:46 +000099 // Configure depthwise convolution kernel
Giorgio Arena76572242018-04-04 17:44:26 +0100100 _dwc_kernel.configure(input, weights, (_is_quantized) ? &_accumulator : output, conv_info, depth_multiplier);
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000101
Georgios Pinitas4074c992018-01-30 18:13:46 +0000102 // Configure border handler
103 _border_handler.configure(input, _dwc_kernel.border_size(), BorderMode::CONSTANT, zero_value);
104 }
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000105
106 // Configure biases accumulation
107 if(_has_bias || _is_quantized)
108 {
109 if(_is_quantized)
110 {
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +0000111 const QuantizationInfo output_quant_info = (output->info()->total_size() == 0) ? input->info()->quantization_info() : output->info()->quantization_info();
112
113 float multiplier = input->info()->quantization_info().scale * weights->info()->quantization_info().scale / output_quant_info.scale;
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000114 int output_multiplier, output_shift;
115 quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift);
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +0000116 _output_stage_kernel.configure(&_accumulator, biases, output, output_multiplier, output_shift, output_quant_info.offset);
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000117 _accumulator.allocator()->allocate();
118 }
119 else
120 {
121 _output_stage_kernel.configure(output, biases);
122 }
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100123 }
124}
125
Abe Mbise7784c832018-05-31 16:48:41 +0100126Status NEDepthwiseConvolutionLayer3x3::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
127 unsigned int depth_multiplier)
128{
129 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output);
130 ARM_COMPUTE_UNUSED(biases);
131 ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() != DataLayout::NCHW && input->data_layout() != DataLayout::NHWC);
132
133 return NEDepthwiseConvolutionLayer3x3Kernel::validate(input, weights, output, conv_info, depth_multiplier);
134}
135
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000136void NEDepthwiseConvolutionLayer3x3::run()
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100137{
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100138 if(_is_first_run && _is_optimized)
139 {
140 _is_first_run = false;
141 // Create convolver (deferred)
142 _dwc_kernel.generate_convolver();
143 }
144
Georgios Pinitas4074c992018-01-30 18:13:46 +0000145 // Permute weights in HWIO format if the optimized kernel will be executedd
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100146 if(!_are_weights_reshaped && _is_optimized && _is_nchw)
Georgios Pinitas4074c992018-01-30 18:13:46 +0000147 {
148 _are_weights_reshaped = true;
149 _permute_weights.run();
150 }
151
152 // Handle input
153 if(_is_optimized)
154 {
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100155 if(_is_nchw)
156 {
157 // Permute input to NHWC format execution
158 _permute_input.run();
159 }
Georgios Pinitas4074c992018-01-30 18:13:46 +0000160 }
161 else
162 {
163 // Fill border in NCHW format execution
164 NEScheduler::get().schedule(&_border_handler, Window::DimX);
165 }
166
167 // Execute depthwise convolution
168 NEScheduler::get().schedule(&_dwc_kernel, Window::DimX);
169
170 // Permute output to ACL's native NCHW format in case of NHWC execution
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100171 if(_is_optimized && _is_nchw)
Georgios Pinitas4074c992018-01-30 18:13:46 +0000172 {
173 _permute_output.run();
174 }
175
176 // Add biases
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000177 if(_has_bias || _is_quantized)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100178 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000179 NEScheduler::get().schedule(&_output_stage_kernel, Window::DimX);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100180 }
Michalis Spyroub7b31532017-11-23 12:10:21 +0000181}
182
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000183NEDepthwiseConvolutionLayer::NEDepthwiseConvolutionLayer()
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000184 : _im2col_kernel(), _weights_reshape_kernel(), _v2mm_kernel(), _vector_to_tensor_kernel(), _output_stage_kernel(), _v2mm_input_fill_border(), _v2mm_weights_fill_border(), _input_reshaped(),
Georgios Pinitas72219332018-06-05 14:56:06 +0100185 _weights_reshaped(), _v2mm_output(), _output_reshaped(), _is_prepared(false), _is_quantized(false), _original_weights(nullptr)
Michalis Spyroub7b31532017-11-23 12:10:21 +0000186{
187}
188
Giorgio Arena76572242018-04-04 17:44:26 +0100189void NEDepthwiseConvolutionLayer::configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier)
Michalis Spyroub7b31532017-11-23 12:10:21 +0000190{
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000191 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F32);
Michalis Spyroub7b31532017-11-23 12:10:21 +0000192 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
Giorgio Arena76572242018-04-04 17:44:26 +0100193 ARM_COMPUTE_ERROR_ON((input->info()->dimension(2) * depth_multiplier) != weights->info()->dimension(2));
Michalis Spyroub7b31532017-11-23 12:10:21 +0000194
195 const size_t weights_w = weights->info()->dimension(0);
196 const size_t weights_h = weights->info()->dimension(1);
197 const size_t weights_z = weights->info()->dimension(2);
198
Georgios Pinitas1562be32018-03-08 19:09:19 +0000199 _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type());
Georgios Pinitas72219332018-06-05 14:56:06 +0100200 _is_prepared = false;
Georgios Pinitas1562be32018-03-08 19:09:19 +0000201 _original_weights = weights;
Michalis Spyroub7b31532017-11-23 12:10:21 +0000202
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000203 // Should bias be appended ?
204 bool append_bias = (biases != nullptr) && !_is_quantized;
205
206 // Calculate output shape
Giorgio Arena76572242018-04-04 17:44:26 +0100207 TensorShape output_shape = shape_calculator::compute_depthwise_convolution_shape(*input->info(), *weights->info(), conv_info, depth_multiplier);
208
209 // Output auto inizialitation if not yet initialized
210 auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
211 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000212
213 // Output width and height
Giorgio Arena76572242018-04-04 17:44:26 +0100214 const unsigned int conv_w = output_shape.x();
215 const unsigned int conv_h = output_shape.y();
Michalis Spyroub7b31532017-11-23 12:10:21 +0000216
217 // Set up intermediate tensors
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000218 const size_t patch_size = weights_w * weights_h + (append_bias ? 1 : 0);
Michalis Spyroub7b31532017-11-23 12:10:21 +0000219 const size_t conv_size = conv_w * conv_h;
220
221 // Im2Col configuration
222 TensorShape shape_im2col = input->info()->tensor_shape();
223 shape_im2col.set(0, patch_size);
224 shape_im2col.set(1, conv_size);
225 shape_im2col.set(2, weights_z);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000226 _input_reshaped.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_im2col));
Giorgio Arena76572242018-04-04 17:44:26 +0100227 _im2col_kernel.configure(input, &_input_reshaped, Size2D(weights_w, weights_h), conv_info, append_bias, depth_multiplier);
Michalis Spyroub7b31532017-11-23 12:10:21 +0000228
229 // Weights reshape configuration
230 const TensorShape shape_weights_reshape(patch_size, weights_z);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000231 _weights_reshaped.allocator()->init(weights->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_weights_reshape));
232 _weights_reshape_kernel.configure(weights, &_weights_reshaped, append_bias ? biases : nullptr);
Michalis Spyroub7b31532017-11-23 12:10:21 +0000233
234 // GEMV configuration
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000235 DataType v2mm_dt = (input->info()->data_type() == DataType::QASYMM8) ? DataType::S32 : input->info()->data_type();
Michalis Spyroub7b31532017-11-23 12:10:21 +0000236 TensorShape shape_v2mm_out = input->info()->tensor_shape();
237 shape_v2mm_out.set(0, conv_size * weights_z);
238 shape_v2mm_out.set(1, 1);
239 shape_v2mm_out.set(2, 1);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000240 _v2mm_output.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_data_type(v2mm_dt).set_tensor_shape(shape_v2mm_out));
Michalis Spyroub7b31532017-11-23 12:10:21 +0000241 _v2mm_kernel.configure(&_input_reshaped, &_weights_reshaped, &_v2mm_output);
Giorgio Arena76572242018-04-04 17:44:26 +0100242 _output_reshaped.allocator()->init(_v2mm_output.info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape));
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000243 _vector_to_tensor_kernel.configure(&_v2mm_output, (_is_quantized) ? &_output_reshaped : output, conv_w, conv_h);
244
245 // Output staged configuration
246 if(_is_quantized)
247 {
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +0000248 const QuantizationInfo output_quant_info = (output->info()->total_size() == 0) ? input->info()->quantization_info() : output->info()->quantization_info();
249
250 float multiplier = input->info()->quantization_info().scale * weights->info()->quantization_info().scale / output_quant_info.scale;
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000251 int output_multiplier, output_shift;
252 quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift);
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +0000253 _output_stage_kernel.configure(&_output_reshaped, biases, output, output_multiplier, output_shift, output_quant_info.offset);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000254 _output_reshaped.allocator()->allocate();
255 }
256
257 // Fill borders on inputs
Anthony Barbierfb8dda22018-01-30 09:27:05 +0000258 PixelValue zero_in(static_cast<int32_t>(0));
259 PixelValue zero_w(static_cast<int32_t>(0));
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000260 if(_is_quantized)
261 {
262 zero_in = PixelValue(static_cast<int32_t>(input->info()->quantization_info().offset));
263 zero_w = PixelValue(static_cast<int32_t>(weights->info()->quantization_info().offset));
264 }
265 BorderSize border_size = _v2mm_kernel.border_size();
266 _v2mm_input_fill_border.configure(&_input_reshaped, border_size, BorderMode::CONSTANT, zero_in);
267
268 border_size.bottom = 0;
269 _v2mm_weights_fill_border.configure(&_weights_reshaped, border_size, BorderMode::CONSTANT, zero_w);
Michalis Spyroub7b31532017-11-23 12:10:21 +0000270
271 // Allocate intermediate tensors
272 _input_reshaped.allocator()->allocate();
Michalis Spyroub7b31532017-11-23 12:10:21 +0000273 _v2mm_output.allocator()->allocate();
274}
275
Abe Mbise7784c832018-05-31 16:48:41 +0100276Status NEDepthwiseConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
277 unsigned int depth_multiplier)
278{
279 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output);
280 ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() != DataLayout::NCHW && input->data_layout() != DataLayout::NHWC);
281
282 const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type());
283 const bool append_bias = (biases != nullptr) && !is_quantized;
284 const TensorShape output_shape = shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier);
285 const size_t weights_w = weights->dimension(0);
286 const size_t weights_h = weights->dimension(1);
287 const size_t weights_z = weights->dimension(2);
288 const unsigned int conv_w = output_shape.x();
289 const unsigned int conv_h = output_shape.y();
290 const size_t patch_size = weights_w * weights_h + (append_bias ? 1 : 0);
291 const size_t conv_size = conv_w * conv_h;
292
293 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape);
294
295 // Im2Col configuration
296 TensorShape shape_im2col = input->tensor_shape();
297 shape_im2col.set(0, patch_size);
298 shape_im2col.set(1, conv_size);
299 shape_im2col.set(2, weights_z);
300 TensorInfo input_reshaped(input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_im2col));
301 ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseIm2ColKernel::validate(input, &input_reshaped, Size2D(weights_w, weights_h), conv_info, append_bias, depth_multiplier));
302
303 // Weights reshape configuration
304 const TensorShape shape_weights_reshape(patch_size, weights_z);
305 TensorInfo weights_reshaped(weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_weights_reshape));
306 ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseWeightsReshapeKernel::validate(weights, &weights_reshaped, append_bias ? biases : nullptr));
307
308 // GEMV configuration
309 DataType v2mm_dt = (input->data_type() == DataType::QASYMM8) ? DataType::S32 : input->data_type();
310 TensorShape shape_v2mm_out = input->tensor_shape();
311 shape_v2mm_out.set(0, conv_size * weights_z);
312 shape_v2mm_out.set(1, 1);
313 shape_v2mm_out.set(2, 1);
314 TensorInfo v2mm_output(input->clone()->set_is_resizable(true).reset_padding().set_data_type(v2mm_dt).set_tensor_shape(shape_v2mm_out));
315 ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMMatrixVectorMultiplyKernel::validate(&input_reshaped, &weights_reshaped, &v2mm_output));
316
317 TensorInfo output_reshaped(v2mm_output.clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape));
318 ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseVectorToTensorKernel::validate(&v2mm_output, (is_quantized) ? &output_reshaped : output, conv_w, conv_h));
319
320 if(is_quantized)
321 {
322 ARM_COMPUTE_RETURN_ON_ERROR(NEDirectConvolutionLayerOutputStageKernel::validate(&output_reshaped, biases, output));
323 }
324
325 return Status{};
326}
327
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000328void NEDepthwiseConvolutionLayer::run()
Michalis Spyroub7b31532017-11-23 12:10:21 +0000329{
Georgios Pinitas72219332018-06-05 14:56:06 +0100330 prepare();
Georgios Pinitas1562be32018-03-08 19:09:19 +0000331
Michalis Spyroub7b31532017-11-23 12:10:21 +0000332 NEScheduler::get().schedule(&_im2col_kernel, Window::DimX);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000333 NEScheduler::get().schedule(&_v2mm_input_fill_border, Window::DimX);
Michalis Spyroub7b31532017-11-23 12:10:21 +0000334 NEScheduler::get().schedule(&_v2mm_kernel, Window::DimX);
335 NEScheduler::get().schedule(&_vector_to_tensor_kernel, Window::DimX);
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000336 if(_is_quantized)
337 {
338 NEScheduler::get().schedule(&_output_stage_kernel, Window::DimX);
339 }
Anthony Barbierfb8dda22018-01-30 09:27:05 +0000340}
Georgios Pinitas72219332018-06-05 14:56:06 +0100341
342void NEDepthwiseConvolutionLayer::prepare()
343{
344 if(!_is_prepared)
345 {
346 ARM_COMPUTE_ERROR_ON(!_original_weights->is_used());
347
348 // Run reshape and mark original weights as unused
349 _weights_reshaped.allocator()->allocate();
350 NEScheduler::get().schedule(&_weights_reshape_kernel, Window::DimX);
351 NEScheduler::get().schedule(&_v2mm_weights_fill_border, Window::DimX);
352 _original_weights->mark_as_unused();
353
354 _is_prepared = true;
355 }
356}