blob: d34a6629666be1bf69815625b337feac0721c246 [file] [log] [blame]
Gian Marco Iodice9285adb2019-09-05 16:10:27 +01001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2019-2023 Arm Limited.
Gian Marco Iodice9285adb2019-09-05 16:10:27 +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_CLDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H
25#define ARM_COMPUTE_CLDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010026
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010027#include "arm_compute/core/KernelDescriptors.h"
SiCong Li91295492023-07-21 18:16:13 +010028#include "arm_compute/function_info/ConvolutionInfo.h"
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010029
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030#include "src/core/CL/ICLKernel.h"
31
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010032namespace arm_compute
33{
34class ICLTensor;
35
36/** Interface for the kernel to run a MxN depthwise convolution. M and N are respectively the rows and columns of the filter
37 This kernel assumes that tensor for the weights is NOT reshaped (Native version) */
38class CLDepthwiseConvolutionLayerNativeKernel : public ICLKernel
39{
40public:
41 /** Default Constructor */
42 CLDepthwiseConvolutionLayerNativeKernel();
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 CLDepthwiseConvolutionLayerNativeKernel(const CLDepthwiseConvolutionLayerNativeKernel &) = delete;
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 CLDepthwiseConvolutionLayerNativeKernel &operator=(const CLDepthwiseConvolutionLayerNativeKernel &) = delete;
47 /** Allow instances of this class to be moved */
48 CLDepthwiseConvolutionLayerNativeKernel(CLDepthwiseConvolutionLayerNativeKernel &&) = default;
49 /** Allow instances of this class to be moved */
50 CLDepthwiseConvolutionLayerNativeKernel &operator=(CLDepthwiseConvolutionLayerNativeKernel &&) = default;
Gian Marco Iodice8155c022021-04-16 15:08:59 +010051
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010052 /** Initialize the function's source, destination and parameters
53 *
Gian Marco Iodice8155c022021-04-16 15:08:59 +010054 * @param[in] compile_context The compile context to be used.
55 * @param[in] input Source tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/FP32/FP16. Data layout supported: NHWC
56 * @param[in] weights Weights tensor. A 3D tensor with dimensions [IFM, N, M].
57 * Data type supported: Same as @p input or QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when @p input is QASYMM8.
58 * @param[in] biases Biases tensor. A 1D tensor with dimensions [IFM]. Must be nullptr if not needed.
59 * Data type supported: Same as @p input, S32 when input is QASYMM8/QASYMM8_SIGNED.
60 * @param[out] output Destination tensor. Pass in nullptr or @p input for in-place operation. Data type supported: Same as @p input.
61 * @param[in] dwc_info Depthwise convolution layer info
62 * @param[in] conv_info Convolution info (padding, stride, dilation, ...)
63 * @param[in] output_multipliers (Optional) Output multipliers tensor for quantized computations. In case of per-channel quantization,
64 * the number of multipliers must be equal to the number of filters (IFM). Supported data types: S32
65 * @param[in] output_shifts (Optional) Output shifts tensor for quantized computations. In case of per-channel quantization,
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010066 * the number of multipliers must be equal to the number of filters (IFM). Supported data types: S32
SiCongLibc4e3112021-06-29 13:18:30 +010067 *
68 * @note: In-place is only supported when
69 * * data layout: NHWC
70 * * filter: 1x1
71 * * @p depth_multiplier: 1
72 * * strides: 1
73 * * dilation: 1
74 * * no padding
75 * * no change of data layout after configure
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010076 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010077 void configure(const CLCompileContext &compile_context,
78 ICLTensor *input,
79 const ICLTensor *weights,
80 const ICLTensor *biases,
81 ICLTensor *output,
82 const DWCComputeKernelInfo &dwc_info,
83 const ConvolutionInfo &conv_info,
84 const ICLTensor *output_multipliers = nullptr,
85 const ICLTensor *output_shifts = nullptr);
SiCongLibc4e3112021-06-29 13:18:30 +010086
Gian Marco Iodice8155c022021-04-16 15:08:59 +010087 /** Static function to check if given info will lead to a valid configuration of @ref CLDepthwiseConvolutionLayerNativeKernel
Manuel Bottini4c6bd512020-04-08 10:15:51 +010088 *
SiCongLibc4e3112021-06-29 13:18:30 +010089 * Similar to @ref CLDepthwiseConvolutionLayerNativeKernel::configure()
Manuel Bottini4c6bd512020-04-08 10:15:51 +010090 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010091 void configure(ICLTensor *input,
92 const ICLTensor *weights,
93 const ICLTensor *biases,
94 ICLTensor *output,
95 const DWCComputeKernelInfo &dwc_info,
96 const ConvolutionInfo &conv_info,
97 const ICLTensor *output_multipliers = nullptr,
98 const ICLTensor *output_shifts = nullptr);
SiCongLibc4e3112021-06-29 13:18:30 +010099
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100100 /** Static function to check if given info will lead to a valid configuration of @ref CLDepthwiseConvolutionLayerNativeKernel
101 *
SiCongLibc4e3112021-06-29 13:18:30 +0100102 * Similar to @ref CLDepthwiseConvolutionLayerNativeKernel::configure()
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100103 *
104 * @return a status
105 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100106 static Status validate(const ITensorInfo *input,
107 const ITensorInfo *weights,
108 const ITensorInfo *biases,
109 const ITensorInfo *output,
110 const DWCComputeKernelInfo &dwc_info,
111 const ConvolutionInfo &conv_info,
112 const ITensorInfo *output_multipliers = nullptr,
113 const ITensorInfo *output_shifts = nullptr);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100114
115 // Inherited methods overridden:
116 void run(const Window &window, cl::CommandQueue &queue) override;
117
118private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100119 const ICLTensor *_input{};
SiCongLibc4e3112021-06-29 13:18:30 +0100120 const ICLTensor *_weights{};
121 const ICLTensor *_biases{};
122 ICLTensor *_output{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100123 unsigned int _depth_multiplier{0};
SiCongLibc4e3112021-06-29 13:18:30 +0100124 const ICLTensor *_output_multipliers{};
125 const ICLTensor *_output_shifts{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100126 bool _export_input_to_cl_image{false};
127 bool _export_weights_to_cl_image{true};
128 bool _is_quantized{false};
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100129};
130} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000131#endif /*ARM_COMPUTE_CLDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H */