blob: 227ddb47436c6c3ce12f3e4fea7bc9963eb2fd23 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01001/*
Michele Di Giorgio13ec5f02020-01-02 12:11:13 +00002 * Copyright (c) 2017-2020 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEDEPTHWISECONVOLUTIONKERNEL3x3_H
25#define ARM_COMPUTE_NEDEPTHWISECONVOLUTIONKERNEL3x3_H
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
Georgios Pinitas47d39dc2019-03-11 14:03:23 +000031// Forward declarations
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010032class ITensor;
33
Georgios Pinitas4074c992018-01-30 18:13:46 +000034/** Interface for the kernel to run a 3x3 depthwise convolution on a tensor. */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000035class NEDepthwiseConvolutionLayer3x3Kernel : public INEKernel
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010036{
37public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000038 const char *name() const override
39 {
40 return "NEDepthwiseConvolutionLayer3x3Kernel";
41 }
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010042 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000043 NEDepthwiseConvolutionLayer3x3Kernel();
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010044 /** Prevent instances of this class from being copied (As this class contains pointers) */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000045 NEDepthwiseConvolutionLayer3x3Kernel(const NEDepthwiseConvolutionLayer3x3Kernel &) = delete;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010046 /** Prevent instances of this class from being copied (As this class contains pointers) */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000047 NEDepthwiseConvolutionLayer3x3Kernel &operator=(const NEDepthwiseConvolutionLayer3x3Kernel &) = delete;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010048 /** Default Move Constructor. */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000049 NEDepthwiseConvolutionLayer3x3Kernel(NEDepthwiseConvolutionLayer3x3Kernel &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000050 /** Default move assignment operator */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000051 NEDepthwiseConvolutionLayer3x3Kernel &operator=(NEDepthwiseConvolutionLayer3x3Kernel &&) = default;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010052 /** Initialize the function's source, destination, conv and border_size.
53 *
Abe Mbise7784c832018-05-31 16:48:41 +010054 * @note Supported data layouts: NCHW and NHWC
55 *
Michele Di Giorgio13ec5f02020-01-02 12:11:13 +000056 * @param[in] input Source tensor. DataType supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Abe Mbise7784c832018-05-31 16:48:41 +010057 * @param[in] weights Weights tensor. This is a 3D tensor with dimensions [3, 3, IFM] for NCHW or [IFM, 3, 3] if NHWC data layout. Data type supported: Same as @p input.
Giorgio Arena76572242018-04-04 17:44:26 +010058 * @param[out] output Destination tensor. Data type supported: Same as @p input.
59 * @param[in] conv_info Padding and stride information to use for the convolution.
60 * @param[in] depth_multiplier (Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
Usama Arif881f2de2019-04-12 10:29:17 +010061 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
62 *
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010063 */
Usama Arif881f2de2019-04-12 10:29:17 +010064 void configure(const ITensor *input, const ITensor *weights, ITensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier = 1, const Size2D &dilation = Size2D(1U, 1U));
Abe Mbise7784c832018-05-31 16:48:41 +010065 /** Static function to check if given info will lead to a valid configuration of @ref NEDepthwiseConvolutionLayer3x3Kernel
66 *
67 * @note Supported data layouts: NCHW and NHWC
68 *
Michele Di Giorgio13ec5f02020-01-02 12:11:13 +000069 * @param[in] input Source tensor info. DataType supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Usama Arif881f2de2019-04-12 10:29:17 +010070 * @param[in] weights Weights tensor info. This is a 3D tensor with dimensions [3, 3, IFM] for NCHW or [IFM, 3, 3] if NHWC data layout. Data type supported: Same as @p input.
71 * @param[in] output Destination tensor info. Data type supported: Same as @p input.
Abe Mbise7784c832018-05-31 16:48:41 +010072 * @param[in] conv_info Padding and stride information to use for the convolution.
73 * @param[in] depth_multiplier (Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
Usama Arif881f2de2019-04-12 10:29:17 +010074 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Abe Mbise7784c832018-05-31 16:48:41 +010075 *
76 * @return a status
77 */
Usama Arif881f2de2019-04-12 10:29:17 +010078 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier = 1,
79 const Size2D &dilation = Size2D(1U, 1U));
Abe Mbise7784c832018-05-31 16:48:41 +010080
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010081 // Inherited methods overridden:
82 void run(const Window &window, const ThreadInfo &info) override;
83 BorderSize border_size() const override;
84
85private:
Georgios Pinitas47d39dc2019-03-11 14:03:23 +000086 BorderSize _border_size;
87 const ITensor *_input;
88 ITensor *_output;
89 const ITensor *_weights;
90 PadStrideInfo _conv_info;
91 unsigned int _num_elems_written_per_iteration;
92 unsigned int _depth_multiplier;
Usama Arif881f2de2019-04-12 10:29:17 +010093 Size2D _dilation;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010094};
95} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000096#endif /* ARM_COMPUTE_NEDEPTHWISECONVOLUTIONKERNEL3x3_H */