Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [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 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/ITensor.h" |
| 28 | #include "arm_compute/core/PixelValue.h" |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
| 32 | #include "support/ToolchainSupport.h" |
| 33 | |
| 34 | using namespace arm_compute; |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 35 | using namespace arm_compute::misc; |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 36 | using namespace arm_compute::misc::shape_calculator; |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 37 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 38 | NEDepthwiseConvolutionLayer3x3::NEDepthwiseConvolutionLayer3x3() |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 39 | : _dwc_kernel(), _output_stage_kernel(), _border_handler(), _permute_input(), _permute_weights(), _permute_output(), _accumulator(), _permuted_input(), _permuted_weights(), _permuted_output(), |
| 40 | _has_bias(false), _is_quantized(false), _is_optimized(false), _are_weights_reshaped(false), _is_nchw(true), _is_first_run(true), _permute(false) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 44 | void NEDepthwiseConvolutionLayer3x3::configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 45 | { |
Georgios Pinitas | 20c246a | 2018-09-12 16:45:53 +0100 | [diff] [blame] | 46 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Georgios Pinitas | 1250a5a | 2018-01-02 13:27:37 +0000 | [diff] [blame] | 47 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 48 | |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 49 | PixelValue zero_value(0.f); |
| 50 | |
| 51 | _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 52 | _has_bias = biases != nullptr; |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 53 | _is_optimized = NEDepthwiseConvolutionLayer3x3Kernel::is_optimized_execution_possible(input->info()->tensor_shape(), |
| 54 | conv_info, |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 55 | input->info()->data_type(), |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 56 | depth_multiplier, |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 57 | input->info()->data_layout()); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 58 | _are_weights_reshaped = false; |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 59 | _is_nchw = input->info()->data_layout() == DataLayout::NCHW; |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 60 | _permute = _is_optimized == _is_nchw; |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 61 | |
Georgios Pinitas | a799ce0 | 2018-09-12 20:11:34 +0100 | [diff] [blame] | 62 | // Initialize the intermediate accumulator tensor in case of quantized input |
| 63 | if(_is_quantized) |
| 64 | { |
| 65 | TensorShape accum_shape = output->info()->tensor_shape(); |
| 66 | DataLayout accum_layout = output->info()->data_layout(); |
| 67 | if(!_is_optimized && !_is_nchw) |
| 68 | { |
| 69 | permute(accum_shape, PermutationVector(1U, 2U, 0U)); |
| 70 | accum_layout = DataLayout::NCHW; |
| 71 | } |
| 72 | |
| 73 | _accumulator.allocator()->init(TensorInfo(accum_shape, 1, DataType::S32, input->info()->quantization_info())); |
| 74 | _accumulator.info()->set_data_layout(accum_layout); |
| 75 | zero_value = PixelValue(static_cast<uint32_t>(input->info()->quantization_info().offset)); |
| 76 | } |
| 77 | |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 78 | if(_is_optimized) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 79 | { |
Georgios Pinitas | a799ce0 | 2018-09-12 20:11:34 +0100 | [diff] [blame] | 80 | ITensor *optimized_output = (_is_quantized) ? &_accumulator : output; |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 81 | if(_is_nchw) |
| 82 | { |
| 83 | // Configure the function to transform the input tensor from NCHW -> NHWC |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 84 | _permute_input.configure(input, &_permuted_input, PermutationVector(2U, 0U, 1U)); |
| 85 | _permuted_input.info()->set_data_layout(DataLayout::NHWC); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 86 | |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 87 | // Configure the function to transform the weights tensor from IHW -> HWI |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 88 | _permute_weights.configure(weights, &_permuted_weights, PermutationVector(2U, 0U, 1U)); |
| 89 | _permuted_weights.info()->set_data_layout(DataLayout::NHWC); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 90 | |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 91 | // Configure optimized depthwise |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 92 | _dwc_kernel.configure(&_permuted_input, &_permuted_weights, &_permuted_output, conv_info, depth_multiplier, DataLayout::NHWC); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 93 | |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 94 | // Configure the function to transform the convoluted output to ACL's native ordering format NCHW |
Georgios Pinitas | a799ce0 | 2018-09-12 20:11:34 +0100 | [diff] [blame] | 95 | _permuted_output.info()->set_data_layout(DataLayout::NHWC); |
| 96 | _permute_output.configure(&_permuted_output, optimized_output, PermutationVector(1U, 2U, 0U)); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 97 | |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 98 | // Allocate tensors |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 99 | _permuted_input.allocator()->allocate(); |
| 100 | _permuted_weights.allocator()->allocate(); |
| 101 | _permuted_output.allocator()->allocate(); |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 102 | } |
| 103 | else |
| 104 | { |
Georgios Pinitas | a799ce0 | 2018-09-12 20:11:34 +0100 | [diff] [blame] | 105 | _dwc_kernel.configure(input, weights, optimized_output, conv_info, depth_multiplier, DataLayout::NHWC); |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 106 | } |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 107 | } |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 108 | else |
| 109 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 110 | if(!_is_nchw) |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 111 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 112 | // Configure the function to transform the input tensor from NHWC -> NCHW |
| 113 | _permute_input.configure(input, &_permuted_input, PermutationVector(1U, 2U, 0U)); |
| 114 | _permuted_input.info()->set_data_layout(DataLayout::NCHW); |
Georgios Pinitas | 9be0c5a | 2018-02-19 12:46:29 +0000 | [diff] [blame] | 115 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 116 | // Configure the function to transform the weights tensor from HWI -> IHW |
| 117 | _permute_weights.configure(weights, &_permuted_weights, PermutationVector(1U, 2U, 0U)); |
| 118 | _permuted_weights.info()->set_data_layout(DataLayout::NCHW); |
| 119 | |
| 120 | // Configure optimized depthwise |
| 121 | _dwc_kernel.configure(&_permuted_input, &_permuted_weights, (_is_quantized) ? &_accumulator : &_permuted_output, conv_info, depth_multiplier); |
| 122 | |
| 123 | // Configure border handler |
| 124 | _border_handler.configure(&_permuted_input, _dwc_kernel.border_size(), BorderMode::CONSTANT, zero_value); |
| 125 | |
| 126 | // Allocate tensors |
| 127 | _permuted_input.allocator()->allocate(); |
| 128 | _permuted_weights.allocator()->allocate(); |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 129 | } |
| 130 | else |
| 131 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 132 | // Configure depthwise convolution kernel |
| 133 | _dwc_kernel.configure(input, weights, (_is_quantized) ? &_accumulator : output, conv_info, depth_multiplier); |
| 134 | |
| 135 | // Configure border handler |
| 136 | _border_handler.configure(input, _dwc_kernel.border_size(), BorderMode::CONSTANT, zero_value); |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 137 | } |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 138 | } |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 139 | |
| 140 | // Configure biases accumulation |
| 141 | if(_is_quantized) |
| 142 | { |
| 143 | const QuantizationInfo output_quant_info = (output->info()->total_size() == 0) ? input->info()->quantization_info() : output->info()->quantization_info(); |
| 144 | |
| 145 | float multiplier = input->info()->quantization_info().scale * weights->info()->quantization_info().scale / output_quant_info.scale; |
| 146 | int output_multiplier, output_shift; |
| 147 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
Georgios Pinitas | a799ce0 | 2018-09-12 20:11:34 +0100 | [diff] [blame] | 148 | _output_stage_kernel.configure(&_accumulator, biases, (_is_nchw || _is_optimized) ? output : &_permuted_output, output_multiplier, output_shift, output_quant_info.offset); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 149 | _accumulator.allocator()->allocate(); |
| 150 | } |
| 151 | else if(_has_bias) |
| 152 | { |
| 153 | _output_stage_kernel.configure((_is_nchw || _is_optimized) ? output : &_permuted_output, biases); |
| 154 | } |
| 155 | |
| 156 | if(!_is_optimized && !_is_nchw) |
| 157 | { |
| 158 | // Configure the function to transform the convoluted output to NHWC |
| 159 | _permute_output.configure(&_permuted_output, output, PermutationVector(2U, 0U, 1U)); |
| 160 | _permuted_output.allocator()->allocate(); |
| 161 | } |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 164 | Status NEDepthwiseConvolutionLayer3x3::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 165 | unsigned int depth_multiplier) |
| 166 | { |
| 167 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 168 | ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() == DataLayout::UNKNOWN); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 169 | |
Giorgio Arena | 66cbafb | 2018-08-23 14:51:00 +0100 | [diff] [blame] | 170 | if(biases != nullptr) |
| 171 | { |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 172 | const unsigned int channel_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL); |
Giorgio Arena | 66cbafb | 2018-08-23 14:51:00 +0100 | [diff] [blame] | 173 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 174 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(channel_idx)); |
Giorgio Arena | 66cbafb | 2018-08-23 14:51:00 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 177 | const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); |
| 178 | TensorInfo accumulator = TensorInfo(output->clone()->set_is_resizable(true).reset_padding().set_data_type(DataType::S32)); |
| 179 | |
| 180 | ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseConvolutionLayer3x3Kernel::validate(input, weights, is_quantized ? &accumulator : output, conv_info, depth_multiplier)); |
| 181 | |
| 182 | if(is_quantized) |
| 183 | { |
| 184 | ARM_COMPUTE_RETURN_ON_ERROR(NEDirectConvolutionLayerOutputStageKernel::validate(&accumulator, biases, output)); |
| 185 | } |
| 186 | |
| 187 | return Status{}; |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 190 | void NEDepthwiseConvolutionLayer3x3::run() |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 191 | { |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 192 | if(_is_first_run && _is_optimized) |
| 193 | { |
| 194 | _is_first_run = false; |
| 195 | // Create convolver (deferred) |
| 196 | _dwc_kernel.generate_convolver(); |
| 197 | } |
| 198 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 199 | // Permute weights |
| 200 | if(_permute) |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 201 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 202 | if(!_are_weights_reshaped) |
| 203 | { |
| 204 | _are_weights_reshaped = true; |
| 205 | _permute_weights.run(); |
| 206 | } |
| 207 | |
| 208 | _permute_input.run(); |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Handle input |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 212 | if(!_is_optimized) |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 213 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 214 | // Fill border |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 215 | NEScheduler::get().schedule(&_border_handler, Window::DimX); |
| 216 | } |
| 217 | |
| 218 | // Execute depthwise convolution |
| 219 | NEScheduler::get().schedule(&_dwc_kernel, Window::DimX); |
| 220 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 221 | // Permute output |
Giorgio Arena | 1ed1fc6 | 2018-03-26 16:20:05 +0100 | [diff] [blame] | 222 | if(_is_optimized && _is_nchw) |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 223 | { |
| 224 | _permute_output.run(); |
| 225 | } |
| 226 | |
| 227 | // Add biases |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame] | 228 | if(_has_bias || _is_quantized) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 229 | { |
Michalis Spyrou | b91e34c | 2017-12-20 15:50:55 +0000 | [diff] [blame] | 230 | NEScheduler::get().schedule(&_output_stage_kernel, Window::DimX); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 231 | } |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 232 | |
| 233 | // Permute output |
| 234 | if(!_is_optimized && !_is_nchw) |
| 235 | { |
| 236 | _permute_output.run(); |
| 237 | } |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 240 | NEDepthwiseConvolutionLayer::NEDepthwiseConvolutionLayer() |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 241 | : _im2col_kernel(), _weights_reshape_kernel(), _v2mm_kernel(), _vector_to_tensor_kernel(), _output_stage_kernel(), _v2mm_input_fill_border(), _v2mm_weights_fill_border(), _permute_input(), |
| 242 | _permute_weights(), _permute_output(), _input_reshaped(), _weights_reshaped(), _v2mm_output(), _output_reshaped(), _permuted_input(), _permuted_weights(), _permuted_output(), _is_prepared(false), |
| 243 | _is_quantized(false), _is_nhwc(false), _original_weights(nullptr) |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 244 | { |
| 245 | } |
| 246 | |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 247 | void NEDepthwiseConvolutionLayer::configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier) |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 248 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 249 | const unsigned int channel_idx = get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::CHANNEL); |
| 250 | ARM_COMPUTE_UNUSED(channel_idx); |
| 251 | |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 252 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F32); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 253 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 254 | ARM_COMPUTE_ERROR_ON((input->info()->dimension(channel_idx) * depth_multiplier) != weights->info()->dimension(channel_idx)); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 255 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 256 | _is_nhwc = input->info()->data_layout() == DataLayout::NHWC; |
| 257 | |
| 258 | ITensor *input_to_use = input; |
| 259 | const ITensor *weights_to_use = weights; |
| 260 | ITensor *output_to_use = output; |
| 261 | |
| 262 | if(_is_nhwc) |
| 263 | { |
| 264 | _permute_input.configure(input, &_permuted_input, PermutationVector(1U, 2U, 0U)); |
| 265 | _permuted_input.info()->set_data_layout(DataLayout::NCHW); |
| 266 | input_to_use = &_permuted_input; |
| 267 | |
| 268 | _permute_weights.configure(weights, &_permuted_weights, PermutationVector(1U, 2U, 0U)); |
| 269 | _permuted_weights.info()->set_data_layout(DataLayout::NCHW); |
| 270 | weights_to_use = &_permuted_weights; |
| 271 | } |
| 272 | |
| 273 | const size_t weights_w = weights_to_use->info()->dimension(0); |
| 274 | const size_t weights_h = weights_to_use->info()->dimension(1); |
| 275 | const size_t weights_z = weights_to_use->info()->dimension(2); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 276 | |
Georgios Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 277 | _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 278 | _is_prepared = false; |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 279 | _original_weights = weights_to_use; |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 280 | |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 281 | // Should bias be appended ? |
| 282 | bool append_bias = (biases != nullptr) && !_is_quantized; |
| 283 | |
| 284 | // Calculate output shape |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 285 | TensorShape output_shape = shape_calculator::compute_depthwise_convolution_shape(*input->info(), *weights->info(), conv_info, depth_multiplier); |
| 286 | |
| 287 | // Output auto inizialitation if not yet initialized |
| 288 | auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape)); |
| 289 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 290 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 291 | if(_is_nhwc) |
| 292 | { |
| 293 | permute(output_shape, PermutationVector(1U, 2U, 0U)); |
| 294 | _permuted_output.allocator()->init(output->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape)); |
| 295 | _permuted_output.info()->set_data_layout(DataLayout::NCHW); |
| 296 | output_to_use = &_permuted_output; |
| 297 | } |
| 298 | |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 299 | // Output width and height |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 300 | const unsigned int conv_w = output_shape.x(); |
| 301 | const unsigned int conv_h = output_shape.y(); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 302 | |
| 303 | // Set up intermediate tensors |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 304 | const size_t patch_size = weights_w * weights_h + (append_bias ? 1 : 0); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 305 | const size_t conv_size = conv_w * conv_h; |
| 306 | |
| 307 | // Im2Col configuration |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 308 | TensorShape shape_im2col = input_to_use->info()->tensor_shape(); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 309 | shape_im2col.set(0, patch_size); |
| 310 | shape_im2col.set(1, conv_size); |
| 311 | shape_im2col.set(2, weights_z); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 312 | _input_reshaped.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_im2col).set_data_layout(DataLayout::NCHW)); |
| 313 | _im2col_kernel.configure(input_to_use, &_input_reshaped, Size2D(weights_w, weights_h), conv_info, append_bias, depth_multiplier); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 314 | |
| 315 | // Weights reshape configuration |
| 316 | const TensorShape shape_weights_reshape(patch_size, weights_z); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 317 | _weights_reshaped.allocator()->init(weights->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_weights_reshape).set_data_layout(DataLayout::NCHW)); |
| 318 | _weights_reshape_kernel.configure(weights_to_use, &_weights_reshaped, append_bias ? biases : nullptr); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 319 | |
| 320 | // GEMV configuration |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 321 | DataType v2mm_dt = (input->info()->data_type() == DataType::QASYMM8) ? DataType::S32 : input->info()->data_type(); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 322 | TensorShape shape_v2mm_out = input_to_use->info()->tensor_shape(); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 323 | shape_v2mm_out.set(0, conv_size * weights_z); |
| 324 | shape_v2mm_out.set(1, 1); |
| 325 | shape_v2mm_out.set(2, 1); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 326 | _v2mm_output.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_data_type(v2mm_dt).set_tensor_shape(shape_v2mm_out).set_data_layout(DataLayout::NCHW)); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 327 | _v2mm_kernel.configure(&_input_reshaped, &_weights_reshaped, &_v2mm_output); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 328 | _output_reshaped.allocator()->init(_v2mm_output.info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape)); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 329 | _vector_to_tensor_kernel.configure(&_v2mm_output, (_is_quantized) ? &_output_reshaped : output_to_use, conv_w, conv_h); |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 330 | |
| 331 | // Output staged configuration |
| 332 | if(_is_quantized) |
| 333 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 334 | const QuantizationInfo output_quant_info = output->info()->quantization_info(); |
Georgios Pinitas | 9be0c5a | 2018-02-19 12:46:29 +0000 | [diff] [blame] | 335 | |
| 336 | float multiplier = input->info()->quantization_info().scale * weights->info()->quantization_info().scale / output_quant_info.scale; |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 337 | int output_multiplier, output_shift; |
| 338 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 339 | _output_stage_kernel.configure(&_output_reshaped, biases, output_to_use, output_multiplier, output_shift, output_quant_info.offset); |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 340 | _output_reshaped.allocator()->allocate(); |
| 341 | } |
| 342 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 343 | if(_is_nhwc) |
| 344 | { |
| 345 | _permute_output.configure(&_permuted_output, output, PermutationVector(2U, 0U, 1U)); |
| 346 | |
| 347 | _permuted_input.allocator()->allocate(); |
| 348 | _permuted_weights.allocator()->allocate(); |
| 349 | _permuted_output.allocator()->allocate(); |
| 350 | } |
| 351 | |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 352 | // Fill borders on inputs |
Anthony Barbier | fb8dda2 | 2018-01-30 09:27:05 +0000 | [diff] [blame] | 353 | PixelValue zero_in(static_cast<int32_t>(0)); |
| 354 | PixelValue zero_w(static_cast<int32_t>(0)); |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 355 | if(_is_quantized) |
| 356 | { |
| 357 | zero_in = PixelValue(static_cast<int32_t>(input->info()->quantization_info().offset)); |
| 358 | zero_w = PixelValue(static_cast<int32_t>(weights->info()->quantization_info().offset)); |
| 359 | } |
| 360 | BorderSize border_size = _v2mm_kernel.border_size(); |
| 361 | _v2mm_input_fill_border.configure(&_input_reshaped, border_size, BorderMode::CONSTANT, zero_in); |
| 362 | |
| 363 | border_size.bottom = 0; |
| 364 | _v2mm_weights_fill_border.configure(&_weights_reshaped, border_size, BorderMode::CONSTANT, zero_w); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 365 | |
| 366 | // Allocate intermediate tensors |
| 367 | _input_reshaped.allocator()->allocate(); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 368 | _v2mm_output.allocator()->allocate(); |
| 369 | } |
| 370 | |
Georgios Pinitas | 1049020 | 2018-08-17 17:16:06 +0100 | [diff] [blame] | 371 | Status NEDepthwiseConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 372 | unsigned int depth_multiplier) |
| 373 | { |
| 374 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 375 | ARM_COMPUTE_RETURN_ERROR_ON(input->data_layout() == DataLayout::UNKNOWN); |
| 376 | |
| 377 | const unsigned int width_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH); |
| 378 | const unsigned int height_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 379 | |
Georgios Pinitas | 1049020 | 2018-08-17 17:16:06 +0100 | [diff] [blame] | 380 | // Clone output to use auto init |
| 381 | auto output_clone = output->clone(); |
| 382 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 383 | const ITensorInfo *input_to_use = input; |
| 384 | const ITensorInfo *weights_to_use = weights; |
Georgios Pinitas | 1049020 | 2018-08-17 17:16:06 +0100 | [diff] [blame] | 385 | const ITensorInfo *output_to_use = output_clone.get(); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 386 | |
| 387 | TensorShape permuted_input_shape = input->tensor_shape(); |
| 388 | TensorShape permuted_weights_shape = weights->tensor_shape(); |
| 389 | TensorInfo permuted_input; |
| 390 | TensorInfo permuted_weights; |
| 391 | |
| 392 | if(input->data_layout() == DataLayout::NHWC) |
| 393 | { |
| 394 | permute(permuted_input_shape, PermutationVector(1U, 2U, 0U)); |
| 395 | permute(permuted_weights_shape, PermutationVector(1U, 2U, 0U)); |
| 396 | |
| 397 | permuted_input = TensorInfo(input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_input_shape).set_data_layout(DataLayout::NCHW)); |
| 398 | permuted_weights = TensorInfo(weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(permuted_weights_shape).set_data_layout(DataLayout::NCHW)); |
| 399 | |
| 400 | input_to_use = &permuted_input; |
| 401 | weights_to_use = &permuted_weights; |
| 402 | } |
| 403 | |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 404 | const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); |
| 405 | const bool append_bias = (biases != nullptr) && !is_quantized; |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 406 | TensorShape output_shape = shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier); |
| 407 | const size_t weights_w = weights_to_use->dimension(0); |
| 408 | const size_t weights_h = weights_to_use->dimension(1); |
| 409 | const size_t weights_z = weights_to_use->dimension(2); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 410 | const unsigned int conv_w = output_shape[width_idx]; |
| 411 | const unsigned int conv_h = output_shape[height_idx]; |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 412 | const size_t patch_size = weights_w * weights_h + (append_bias ? 1 : 0); |
| 413 | const size_t conv_size = conv_w * conv_h; |
| 414 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 415 | // Output auto inizialitation if not yet initialized |
Georgios Pinitas | 1049020 | 2018-08-17 17:16:06 +0100 | [diff] [blame] | 416 | auto_init_if_empty(*output_clone, input->clone()->set_tensor_shape(output_shape)); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 417 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 418 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 419 | TensorInfo permuted_output; |
| 420 | if(input->data_layout() == DataLayout::NHWC) |
| 421 | { |
| 422 | permute(output_shape, PermutationVector(1U, 2U, 0U)); |
Georgios Pinitas | 1049020 | 2018-08-17 17:16:06 +0100 | [diff] [blame] | 423 | permuted_output = TensorInfo(output_clone->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_shape).set_data_layout(DataLayout::NCHW)); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 424 | output_to_use = &permuted_output; |
| 425 | } |
| 426 | |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 427 | // Im2Col configuration |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 428 | TensorShape shape_im2col = input_to_use->tensor_shape(); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 429 | shape_im2col.set(0, patch_size); |
| 430 | shape_im2col.set(1, conv_size); |
| 431 | shape_im2col.set(2, weights_z); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 432 | TensorInfo input_reshaped(input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_im2col).set_data_layout(DataLayout::NCHW)); |
| 433 | ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseIm2ColKernel::validate(input_to_use, &input_reshaped, Size2D(weights_w, weights_h), conv_info, append_bias, depth_multiplier)); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 434 | |
| 435 | // Weights reshape configuration |
| 436 | const TensorShape shape_weights_reshape(patch_size, weights_z); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 437 | TensorInfo weights_reshaped(weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_weights_reshape).set_data_layout(DataLayout::NCHW)); |
| 438 | ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseWeightsReshapeKernel::validate(weights_to_use, &weights_reshaped, append_bias ? biases : nullptr)); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 439 | |
| 440 | // GEMV configuration |
| 441 | DataType v2mm_dt = (input->data_type() == DataType::QASYMM8) ? DataType::S32 : input->data_type(); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 442 | TensorShape shape_v2mm_out = input_to_use->tensor_shape(); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 443 | shape_v2mm_out.set(0, conv_size * weights_z); |
| 444 | shape_v2mm_out.set(1, 1); |
| 445 | shape_v2mm_out.set(2, 1); |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 446 | TensorInfo v2mm_output(input->clone()->set_is_resizable(true).reset_padding().set_data_type(v2mm_dt).set_tensor_shape(shape_v2mm_out).set_data_layout(DataLayout::NCHW)); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 447 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMMatrixVectorMultiplyKernel::validate(&input_reshaped, &weights_reshaped, &v2mm_output)); |
| 448 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 449 | TensorInfo output_reshaped(v2mm_output.clone()->set_is_resizable(true).reset_padding().set_tensor_shape(output_to_use->tensor_shape())); |
| 450 | ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseVectorToTensorKernel::validate(&v2mm_output, (is_quantized) ? &output_reshaped : output_to_use, conv_w, conv_h)); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 451 | |
| 452 | if(is_quantized) |
| 453 | { |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 454 | ARM_COMPUTE_RETURN_ON_ERROR(NEDirectConvolutionLayerOutputStageKernel::validate(&output_reshaped, biases, output_to_use)); |
Abe Mbise | 7784c83 | 2018-05-31 16:48:41 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | return Status{}; |
| 458 | } |
| 459 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 460 | void NEDepthwiseConvolutionLayer::run() |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 461 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 462 | prepare(); |
Georgios Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 463 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 464 | if(_is_nhwc) |
| 465 | { |
| 466 | _permute_input.run(); |
| 467 | } |
| 468 | |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 469 | NEScheduler::get().schedule(&_im2col_kernel, Window::DimX); |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 470 | NEScheduler::get().schedule(&_v2mm_input_fill_border, Window::DimX); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 471 | NEScheduler::get().schedule(&_v2mm_kernel, Window::DimX); |
| 472 | NEScheduler::get().schedule(&_vector_to_tensor_kernel, Window::DimX); |
Georgios Pinitas | d05dce4 | 2018-01-22 16:29:17 +0000 | [diff] [blame] | 473 | if(_is_quantized) |
| 474 | { |
| 475 | NEScheduler::get().schedule(&_output_stage_kernel, Window::DimX); |
| 476 | } |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 477 | |
| 478 | if(_is_nhwc) |
| 479 | { |
| 480 | _permute_output.run(); |
| 481 | } |
Anthony Barbier | fb8dda2 | 2018-01-30 09:27:05 +0000 | [diff] [blame] | 482 | } |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 483 | |
| 484 | void NEDepthwiseConvolutionLayer::prepare() |
| 485 | { |
| 486 | if(!_is_prepared) |
| 487 | { |
| 488 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
| 489 | |
Giorgio Arena | 26b2216 | 2018-08-13 15:49:49 +0100 | [diff] [blame] | 490 | if(_is_nhwc) |
| 491 | { |
| 492 | _permute_weights.run(); |
| 493 | } |
| 494 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 495 | // Run reshape and mark original weights as unused |
| 496 | _weights_reshaped.allocator()->allocate(); |
| 497 | NEScheduler::get().schedule(&_weights_reshape_kernel, Window::DimX); |
| 498 | NEScheduler::get().schedule(&_v2mm_weights_fill_border, Window::DimX); |
| 499 | _original_weights->mark_as_unused(); |
| 500 | |
| 501 | _is_prepared = true; |
| 502 | } |
| 503 | } |