blob: 0c2f30a98cb5682e3bca1a65ec63654fb5679e15 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01001/*
Georgios Pinitasf72f9362018-01-12 16:29:45 +00002 * Copyright (c) 2017-2018 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 */
24#ifndef __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONKERNEL3x3_H__
25#define __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONKERNEL3x3_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
Georgios Pinitas4074c992018-01-30 18:13:46 +000028#include "arm_compute/core/NEON/kernels/convolution/depthwise/depthwise.hpp"
29
30#include <memory>
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010031
32namespace arm_compute
33{
34class ITensor;
35
Georgios Pinitas4074c992018-01-30 18:13:46 +000036/** Interface for the kernel to run a 3x3 depthwise convolution on a tensor. */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000037class NEDepthwiseConvolutionLayer3x3Kernel : public INEKernel
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010038{
39public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000040 const char *name() const override
41 {
42 return "NEDepthwiseConvolutionLayer3x3Kernel";
43 }
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010044 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000045 NEDepthwiseConvolutionLayer3x3Kernel();
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(const NEDepthwiseConvolutionLayer3x3Kernel &) = delete;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010048 /** Prevent instances of this class from being copied (As this class contains pointers) */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000049 NEDepthwiseConvolutionLayer3x3Kernel &operator=(const NEDepthwiseConvolutionLayer3x3Kernel &) = delete;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010050 /** Default Move Constructor. */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000051 NEDepthwiseConvolutionLayer3x3Kernel(NEDepthwiseConvolutionLayer3x3Kernel &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000052 /** Default move assignment operator */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000053 NEDepthwiseConvolutionLayer3x3Kernel &operator=(NEDepthwiseConvolutionLayer3x3Kernel &&) = default;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010054 /** Initialize the function's source, destination, conv and border_size.
55 *
Georgios Pinitas4074c992018-01-30 18:13:46 +000056 * @param[in] input Source tensor. DataType supported: QASYMM8, F32.
57 * @param[in] weights Weights tensor. This is a 3D tensor with dimensions [3, 3, IFM]. Data type supported: Same as @p input.
58 * @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] data_layout (Optional) Data layout of the input and weights tensor
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010061 */
Georgios Pinitas4074c992018-01-30 18:13:46 +000062 void configure(const ITensor *input, const ITensor *weights, ITensor *output, const PadStrideInfo &conv_info, DataLayout data_layout = DataLayout::NCHW);
63 /** Static method that checks if optimized execution is supported for the given parameters
64 *
65 * @param[in] input_shape Input shape
66 * @param[in] conv_info Padding and stride information to use for the convolution.
67 * @param[in] dt Data type of the input and weights
68 * @param[in] data_layout (Optional) Data layout of the input and weights tensor
69 *
70 * @return True if the optimized kernels can be executed else false
71 */
72 static bool is_optimized_execution_possible(TensorShape input_shape, PadStrideInfo conv_info, DataType dt, DataLayout data_layout = DataLayout::NCHW);
73 /** Generates the convolver object */
74 void generate_convolver();
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010075
76 // Inherited methods overridden:
77 void run(const Window &window, const ThreadInfo &info) override;
78 BorderSize border_size() const override;
79
80private:
Georgios Pinitas4074c992018-01-30 18:13:46 +000081 void configure_generic();
82 void configure_optimized();
83 void run_generic(const Window &window, const ThreadInfo &info);
84 void run_optimized(const Window &window, const ThreadInfo &info);
Georgios Pinitasbe0ae932018-03-13 13:08:12 +000085 /** Creates an optimized backend convolver object
86 *
87 * @note Convolver of strides 1,2 and convolution size of 3 is currently supported
88 *
89 * @param[in] conv_info Padding and stride information to use for the convolution
90 * @param[in] w Weights tensor
91 * @param[in] in Input tensor
92 * @param[in] out Output tensor
93 * @param[in] setup_strides (Optional) Boolean to enable setting the strides of the tensors
94 * in the convolver in case of padding. Defaults to false
95 *
96 * @return A convolver object or nullptr if the configuration is not supported
97 */
98 std::unique_ptr<depthwise::IDepthwiseConvolution> create_convolver_object(PadStrideInfo conv_info,
99 const ITensor *w,
100 const ITensor *in,
101 ITensor *out,
102 bool setup_strides = false);
Georgios Pinitas4074c992018-01-30 18:13:46 +0000103
104private:
105 BorderSize _border_size;
106 const ITensor *_input;
107 ITensor *_output;
108 const ITensor *_weights;
109 PadStrideInfo _conv_info;
110 std::unique_ptr<depthwise::IDepthwiseConvolution> _convolver;
111 unsigned int _num_elems_written_per_iteration;
112 bool _run_optimized;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100113};
114} // namespace arm_compute
Anthony Barbiere8a49832018-01-18 10:04:05 +0000115#endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONKERNEL3x3_H__ */