blob: a0205f1ea62649bb02e79785c05ed4bbf49f988d [file] [log] [blame]
Giorgio Arena44f55722019-07-12 14:49:49 +01001/*
2 * Copyright (c) 2019 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 */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010024#ifndef __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H__
25#define __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H__
Giorgio Arena44f55722019-07-12 14:49:49 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
Giorgio Arenad93e2632019-10-15 11:09:33 +010029#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
30#include <arm_neon.h>
31#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
32
Giorgio Arena44f55722019-07-12 14:49:49 +010033namespace arm_compute
34{
35// Forward declarations
36class ITensor;
37
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010038/** Interface for the kernel to run a depthwise convolution native on a tensor. */
39class NEDepthwiseConvolutionLayerNativeKernel : public INEKernel
Giorgio Arena44f55722019-07-12 14:49:49 +010040{
41public:
42 const char *name() const override
43 {
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010044 return "NEDepthwiseConvolutionLayerNativeKernel";
Giorgio Arena44f55722019-07-12 14:49:49 +010045 }
46 /** Default constructor */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010047 NEDepthwiseConvolutionLayerNativeKernel();
Giorgio Arena44f55722019-07-12 14:49:49 +010048 /** Prevent instances of this class from being copied (As this class contains pointers) */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010049 NEDepthwiseConvolutionLayerNativeKernel(const NEDepthwiseConvolutionLayerNativeKernel &) = delete;
Giorgio Arena44f55722019-07-12 14:49:49 +010050 /** Prevent instances of this class from being copied (As this class contains pointers) */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010051 NEDepthwiseConvolutionLayerNativeKernel &operator=(const NEDepthwiseConvolutionLayerNativeKernel &) = delete;
Giorgio Arena44f55722019-07-12 14:49:49 +010052 /** Default Move Constructor. */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010053 NEDepthwiseConvolutionLayerNativeKernel(NEDepthwiseConvolutionLayerNativeKernel &&) = default;
Giorgio Arena44f55722019-07-12 14:49:49 +010054 /** Default move assignment operator */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010055 NEDepthwiseConvolutionLayerNativeKernel &operator=(NEDepthwiseConvolutionLayerNativeKernel &&) = default;
Giorgio Arena44f55722019-07-12 14:49:49 +010056 /** Initialize the function's source, destination and parameters.
57 *
58 * @note Supported data layouts: NHWC
59 *
Giorgio Arenad93e2632019-10-15 11:09:33 +010060 * @param[in] input Source tensor. DataType supported: QASYMM8/F16/F32.
Giorgio Arena44f55722019-07-12 14:49:49 +010061 * @param[in] weights Weights tensor. This is a 3D tensor with dimensions [IFM, W, H]. Data type supported: Same as @p input.
62 * @param[in] biases Biases tensor. A 1D tensor with dimensions [IFM]. Must be nullptr if not needed. Data type supported: Same as @p input.
63 * @param[out] output Destination tensor. Data type supported: Same as @p input.
64 * @param[in] conv_info Padding and stride information to use for the convolution.
65 * @param[in] depth_multiplier (Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
66 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
67 *
68 */
69 void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier = 1,
70 const Size2D &dilation = Size2D(1U, 1U));
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010071 /** Static function to check if given info will lead to a valid configuration of @ref NEDepthwiseConvolutionLayerNativeKernel
Giorgio Arena44f55722019-07-12 14:49:49 +010072 *
73 * @note Supported data layouts: NHWC
74 *
Giorgio Arenad93e2632019-10-15 11:09:33 +010075 * @param[in] input Source tensor info. DataType supported: QASYMM8/F16/F32.
Giorgio Arena44f55722019-07-12 14:49:49 +010076 * @param[in] weights Weights tensor info. This is a 3D tensor with dimensions [IFM, W, H]. Data type supported: Same as @p input.
77 * @param[in] biases Biases tensor info. A 1D tensor with dimensions [IFM]. Must be nullptr if not needed. Data type supported: Same as @p input.
78 * @param[in] output Destination tensor info. Data type supported: Same as @p input.
79 * @param[in] conv_info Padding and stride information to use for the convolution.
80 * @param[in] depth_multiplier (Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
81 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
82 *
83 * @return a status
84 */
85 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier = 1,
86 const Size2D &dilation = Size2D(1U, 1U));
87
88 // Inherited methods overridden:
89 void run(const Window &window, const ThreadInfo &info) override;
90 BorderSize border_size() const override;
91
92private:
Giorgio Arenad93e2632019-10-15 11:09:33 +010093 template < typename T, typename TW, int S, bool has_biases, bool is_per_channel, typename std::enable_if < std::is_same<T, float>::value
94#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
95 || std::is_same<T, float16_t>::value
96#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
97 ,
98 int >::type = 0 >
99 void run_depthwise(const Window &window);
100
101 template <typename T, typename TW, int S, bool has_biases, bool is_per_channel, typename std::enable_if<std::is_same<T, uint8_t>::value, int>::type = 0>
Giorgio Arena44f55722019-07-12 14:49:49 +0100102 void run_depthwise(const Window &window);
103
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100104 /** Common signature for all the specialised depthwise convolution native functions
Giorgio Arena44f55722019-07-12 14:49:49 +0100105 *
106 * @param[in] window Region on which to execute the kernel.
107 */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100108 using DepthwiseFunctionPtr = void (NEDepthwiseConvolutionLayerNativeKernel::*)(const Window &window);
Giorgio Arena44f55722019-07-12 14:49:49 +0100109
110 DepthwiseFunctionPtr _func;
111 BorderSize _border_size;
112 const ITensor *_input;
113 const ITensor *_weights;
114 const ITensor *_biases;
115 ITensor *_output;
116 PadStrideInfo _conv_info;
117 unsigned int _depth_multiplier;
118 Size2D _dilation;
Giorgio Arenad93e2632019-10-15 11:09:33 +0100119 std::vector<int> _output_multiplier;
120 std::vector<int> _output_shift;
Giorgio Arena44f55722019-07-12 14:49:49 +0100121};
122} // namespace arm_compute
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100123#endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H__ */