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 | */ |
| 24 | #ifndef __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__ |
| 25 | #define __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__ |
| 26 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/NEON/kernels/NEDepthwiseConvolutionLayer3x3Kernel.h" |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/NEON/kernels/NEDepthwiseIm2ColKernel.h" |
| 29 | #include "arm_compute/core/NEON/kernels/NEDepthwiseVectorToTensorKernel.h" |
| 30 | #include "arm_compute/core/NEON/kernels/NEDepthwiseWeightsReshapeKernel.h" |
Michalis Spyrou | b91e34c | 2017-12-20 15:50:55 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerOutputStageKernel.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h" |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 33 | #include "arm_compute/core/NEON/kernels/NEGEMMMatrixVectorMultiplyKernel.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 34 | #include "arm_compute/core/Types.h" |
| 35 | #include "arm_compute/runtime/IFunction.h" |
| 36 | #include "arm_compute/runtime/IMemoryManager.h" |
| 37 | #include "arm_compute/runtime/MemoryGroup.h" |
| 38 | #include "arm_compute/runtime/Tensor.h" |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | class ITensor; |
| 43 | |
| 44 | /** Basic function to execute a depthwise convolution for kernel size 3x3xC. This function calls the following NEON kernels: |
| 45 | * |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 46 | * -# @ref NEDepthwiseConvolutionLayer3x3 |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 47 | * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0) |
| 48 | * |
| 49 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 50 | class NEDepthwiseConvolutionLayer3x3 : public IFunction |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 51 | { |
| 52 | public: |
| 53 | /** Default constructor */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 54 | NEDepthwiseConvolutionLayer3x3(); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 55 | /** Initialize the function's source, destination, kernels and border_size. |
| 56 | * |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame^] | 57 | * @param[in, out] input Source tensor. Data type supported: QASYMM8, F32. (Written to only for border filling). |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 58 | * @param[in] weights Weights tensor. These are 3D tensors with shape [3, 3, IFM]. Data type supported: Same as @p input. |
| 59 | * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed. |
| 60 | * Data type supported: Same as @p input. |
Giorgio Arena | 82afedf | 2017-11-15 13:36:15 +0000 | [diff] [blame] | 61 | * @param[out] output Destination tensor. Data type supported: same as @p input. |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 62 | * @param[in] conv_info Padding and stride information to use for the convolution. |
| 63 | */ |
Giorgio Arena | 82afedf | 2017-11-15 13:36:15 +0000 | [diff] [blame] | 64 | void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 65 | |
| 66 | // Inherited methods overriden: |
| 67 | void run() override; |
| 68 | |
| 69 | private: |
Michalis Spyrou | b91e34c | 2017-12-20 15:50:55 +0000 | [diff] [blame] | 70 | NEDepthwiseConvolutionLayer3x3Kernel _kernel; |
| 71 | NEDirectConvolutionLayerOutputStageKernel _output_stage_kernel; |
| 72 | NEFillBorderKernel _border_handler; |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame^] | 73 | Tensor _accumulator; |
Michalis Spyrou | b91e34c | 2017-12-20 15:50:55 +0000 | [diff] [blame] | 74 | bool _has_bias; |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame^] | 75 | bool _is_quantized; |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 76 | }; |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 77 | |
Giorgio Arena | 3972528 | 2017-12-12 15:04:43 +0000 | [diff] [blame] | 78 | /** Basic function to execute a generic depthwise convolution. This function calls the following NEON kernels: |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 79 | * |
| 80 | * -# @ref NEDepthwiseIm2ColKernel |
| 81 | * -# @ref NEDepthwiseWeightsReshapeKernel |
| 82 | * -# @ref NEGEMMMatrixVectorMultiplyKernel |
| 83 | * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0) |
| 84 | * |
| 85 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 86 | class NEDepthwiseConvolutionLayer : public IFunction |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 87 | { |
| 88 | public: |
| 89 | /** Default constructor */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 90 | NEDepthwiseConvolutionLayer(); |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 91 | /** Initialize the function's source, destination, weights and convolution information. |
| 92 | * |
| 93 | * @param[in, out] input Source tensor. Data type supported: F32. (Written to only for border filling). |
| 94 | * @param[out] output Destination tensor. Data type supported: same as @p input. |
| 95 | * @param[in] weights Weights tensor. These are 3D tensors with shape [kernel_x, kernel_y, IFM]. Data type supported: Same as @p input. |
| 96 | * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed. |
| 97 | * Data type supported: Same as @p input. |
| 98 | * @param[in] conv_info Padding and stride information to use for the convolution. |
| 99 | */ |
| 100 | void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info); |
| 101 | |
| 102 | // Inherited methods overriden: |
| 103 | void run() override; |
| 104 | |
| 105 | private: |
| 106 | NEDepthwiseIm2ColKernel _im2col_kernel; |
| 107 | NEDepthwiseWeightsReshapeKernel _weights_reshape_kernel; |
| 108 | NEGEMMMatrixVectorMultiplyKernel _v2mm_kernel; |
| 109 | NEDepthwiseVectorToTensorKernel _vector_to_tensor_kernel; |
| 110 | Tensor _input_reshaped; |
| 111 | Tensor _weights_reshaped; |
| 112 | Tensor _v2mm_output; |
| 113 | }; |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 114 | } |
| 115 | #endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__ */ |