Compute Library
 21.02
NEConvolution.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2021 Arm Limited.
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_NECONVOLUTION_H
25 #define ARM_COMPUTE_NECONVOLUTION_H
26 
27 #include "arm_compute/core/Types.h"
33 
34 #include <cstdint>
35 #include <memory>
36 
37 namespace arm_compute
38 {
39 class ITensor;
40 class NEFillBorderKernel;
41 template <unsigned int matrix_size>
43 template <unsigned int matrix_size>
45 template <unsigned int matrix_size>
47 
48 /** Basic function to execute convolution of size 3x3. This function calls the following Neon kernels:
49  *
50  * -# @ref NEFillBorderKernel (executed if border_mode == CONSTANT or border_mode == REPLICATE)
51  * -# @ref NEConvolution3x3Kernel
52  *
53  * @deprecated This function is deprecated and is intended to be removed in 21.05 release
54  *
55  */
57 {
58 public:
59  /** Constructor */
60  NEConvolution3x3() = default;
61  /** Prevent instances of this class from being copied (As this class contains pointers) */
62  NEConvolution3x3(const NEConvolution3x3 &) = delete;
63  /** Prevent instances of this class from being copied (As this class contains pointers) */
64  NEConvolution3x3 &operator=(const NEConvolution3x3 &) = delete;
65  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
67  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
69  /** Default destructor */
71  /** Initialize the function's source, destination, conv and border_mode.
72  *
73  * @param[in,out] input Source tensor. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED)
74  * @param[out] output Destination tensor, Data types supported: U8/S16.
75  * @param[in] conv Matrix_size x matrix_size S16 coefficients structured as a row-major 2D array in a linear buffer.
76  * @param[in] scale Scale of the convolution matrix. If 0 is passed, it will be set to the sum of the coefficients of the convolution or 1 if they add up to 0.
77  * @param[in] border_mode Strategy to use for borders.
78  * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
79  */
80  void configure(ITensor *input, ITensor *output, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value = 0);
81 };
82 
83 /** Basic function to execute convolution of size 5x5, 7x7, 9x9. This function calls the following Neon kernels:
84  *
85  * -# @ref NEFillBorderKernel (executed if border_mode == CONSTANT or border_mode == REPLICATE)
86  * -# @ref NEConvolutionKernel or<br/>
87  * @ref NESeparableConvolutionHorKernel and @ref NESeparableConvolutionVertKernel (if convolution matrix is separable)
88  *
89  * @deprecated This function is deprecated and is intended to be removed in 21.05 release
90  *
91  */
92 template <unsigned int matrix_size>
94 {
95 public:
96  /** Default constructor */
97  NEConvolutionSquare(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
98  /** Prevent instances of this class from being copied (As this class contains pointers) */
99  NEConvolutionSquare(const NEConvolutionSquare &) = delete;
100  /** Prevent instances of this class from being copied (As this class contains pointers) */
102  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
104  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
106  /** Default destructor */
108  /** Initialize the function's source, destination, conv and border_mode.
109  *
110  * @param[in,out] input Source tensor. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED)
111  * @param[out] output Destination tensor, Data types supported: U8 or S16.
112  * @param[in] conv matrix_size x matrix_size S16 coefficients structured as a row-major 2D array in a linear buffer.
113  * @param[in] scale Scale of the convolution matrix. If 0 is passed, it will be set to the sum of the coefficients of the convolution or 1 if they add up to 0.
114  * @param[in] border_mode Strategy to use for borders.
115  * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
116  */
117  void configure(ITensor *input, ITensor *output, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value = 0);
118 
119  // Inherited methods overridden:
120  void run() override;
121 
122 private:
123  MemoryGroup _memory_group; /**< Function memory group */
124  Tensor _tmp; /**< temporary buffer for output of horizontal pass */
125  bool _is_separable; /**< true if the convolution can be separated */
126  std::unique_ptr<NESeparableConvolutionHorKernel<matrix_size>> _kernel_hor; /**< kernel for horizontal pass of separated convolution */
127  std::unique_ptr<NESeparableConvolutionVertKernel<matrix_size>> _kernel_vert; /**< kernel for vertical pass of separated convolution */
128  std::unique_ptr<NEConvolutionKernel<matrix_size>> _kernel; /**< kernel for non-separated convolution **/
129  std::unique_ptr<NEFillBorderKernel> _border_handler; /**< kernel for border handling */
130 };
131 
132 /** Basic function to run 5x5 convolution. */
134 /** Basic function to run 7x7 convolution. */
136 /** Basic function to run 9x9 convolution. */
138 
139 /** Basic function to execute non-square convolution. This function calls the following Neon kernels:
140  *
141  * -# @ref NEFillBorderKernel (executed if border_mode == CONSTANT or border_mode == REPLICATE)
142  * -# @ref NEConvolutionRectangleKernel or<br/>
143  *
144  * @note Convolution rectangle should have dimensions of 3, 5, 7, 9
145  *
146  * @deprecated This function is deprecated and is intended to be removed in 21.05 release
147  *
148  */
150 {
151 public:
152  /** Constructor */
153  NEConvolutionRectangle() = default;
154  /** Prevent instances of this class from being copied (As this class contains pointers) */
156  /** Prevent instances of this class from being copied (As this class contains pointers) */
158  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
160  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
162  /** Default destructor */
164  /** Initialize the function's source, destination, conv and border_mode.
165  *
166  * @param[in,out] input Source tensor. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED)
167  * @param[out] output Destination tensor, Data types supported: U8 or S16.
168  * @param[in] conv Matrix_size x matrix_size S16 coefficients structured as a row-major 2D array in a linear buffer.
169  * @param[in] rows Rows of convolution kernel.
170  * @param[in] cols Columns of convolution kernel.
171  * @param[in] scale Scale of the convolution matrix. If 0 is passed, it will be set to the sum of the coefficients of the convolution or 1 if they add up to 0.
172  * @param[in] border_mode Strategy to use for borders.
173  * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
174  */
175  void configure(ITensor *input, ITensor *output, const int16_t *conv, uint32_t rows, uint32_t cols, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value = 0);
176 };
177 }
178 #endif /*ARM_COMPUTE_NECONVOLUTION_H */
BorderMode
Methods available to handle borders.
Definition: Types.h:265
NEConvolution3x3()=default
Constructor.
Kernel for the Vertical pass of a Separable Convolution.
Definition: NEConvolution.h:46
Interface for the kernel to run an arbitrary size convolution on a tensor.
Definition: NEConvolution.h:42
Base class for all functions.
Definition: IFunction.h:30
void run() override final
Run the kernels contained in the function.
~NEConvolution3x3()
Default destructor.
Kernel for the Horizontal pass of a Separable Convolution.
Definition: NEConvolution.h:44
NEConvolution3x3 & operator=(const NEConvolution3x3 &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Interface for Neon tensor.
Definition: ITensor.h:36
Basic function to execute non-square convolution.
Copyright (c) 2017-2021 Arm Limited.
Basic function to execute convolution of size 5x5, 7x7, 9x9.
Definition: NEConvolution.h:93
Basic function to execute convolution of size 3x3.
Definition: NEConvolution.h:56
Basic implementation of the tensor interface.
Definition: Tensor.h:37
void configure(ITensor *input, ITensor *output, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value=0)
Initialize the function&#39;s source, destination, conv and border_mode.
Basic interface for functions which have a single Neon kernel.