Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 1 | /* |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H |
| 25 | #define ARM_COMPUTE_CLDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 26 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 27 | #include "src/core/CL/ICLKernel.h" |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 28 | |
| 29 | #include "arm_compute/core/KernelDescriptors.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | class ICLTensor; |
| 34 | |
| 35 | /** Interface for the kernel to run a MxN depthwise convolution. M and N are respectively the rows and columns of the filter |
| 36 | This kernel assumes that tensor for the weights is NOT reshaped (Native version) */ |
| 37 | class CLDepthwiseConvolutionLayerNativeKernel : public ICLKernel |
| 38 | { |
| 39 | public: |
| 40 | /** Default Constructor */ |
| 41 | CLDepthwiseConvolutionLayerNativeKernel(); |
| 42 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 43 | CLDepthwiseConvolutionLayerNativeKernel(const CLDepthwiseConvolutionLayerNativeKernel &) = delete; |
| 44 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 45 | CLDepthwiseConvolutionLayerNativeKernel &operator=(const CLDepthwiseConvolutionLayerNativeKernel &) = delete; |
| 46 | /** Allow instances of this class to be moved */ |
| 47 | CLDepthwiseConvolutionLayerNativeKernel(CLDepthwiseConvolutionLayerNativeKernel &&) = default; |
| 48 | /** Allow instances of this class to be moved */ |
| 49 | CLDepthwiseConvolutionLayerNativeKernel &operator=(CLDepthwiseConvolutionLayerNativeKernel &&) = default; |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 50 | |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 51 | /** Initialize the function's source, destination and parameters |
| 52 | * |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 53 | * @param[in] compile_context The compile context to be used. |
| 54 | * @param[in] input Source tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/FP32/FP16. Data layout supported: NHWC |
| 55 | * @param[in] weights Weights tensor. A 3D tensor with dimensions [IFM, N, M]. |
| 56 | * Data type supported: Same as @p input or QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when @p input is QASYMM8. |
| 57 | * @param[in] biases Biases tensor. A 1D tensor with dimensions [IFM]. Must be nullptr if not needed. |
| 58 | * Data type supported: Same as @p input, S32 when input is QASYMM8/QASYMM8_SIGNED. |
| 59 | * @param[out] output Destination tensor. Pass in nullptr or @p input for in-place operation. Data type supported: Same as @p input. |
| 60 | * @param[in] dwc_info Depthwise convolution layer info |
| 61 | * @param[in] conv_info Convolution info (padding, stride, dilation, ...) |
| 62 | * @param[in] output_multipliers (Optional) Output multipliers tensor for quantized computations. In case of per-channel quantization, |
| 63 | * the number of multipliers must be equal to the number of filters (IFM). Supported data types: S32 |
| 64 | * @param[in] output_shifts (Optional) Output shifts tensor for quantized computations. In case of per-channel quantization, |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 65 | * the number of multipliers must be equal to the number of filters (IFM). Supported data types: S32 |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 66 | * |
| 67 | * @note: In-place is only supported when |
| 68 | * * data layout: NHWC |
| 69 | * * filter: 1x1 |
| 70 | * * @p depth_multiplier: 1 |
| 71 | * * strides: 1 |
| 72 | * * dilation: 1 |
| 73 | * * no padding |
| 74 | * * no change of data layout after configure |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 75 | */ |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 76 | void configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const DWCComputeKernelInfo &dwc_info, |
| 77 | const ConvolutionInfo &conv_info, const ICLTensor *output_multipliers = nullptr, const ICLTensor *output_shifts = nullptr); |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 78 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 79 | /** Static function to check if given info will lead to a valid configuration of @ref CLDepthwiseConvolutionLayerNativeKernel |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 80 | * |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 81 | * Similar to @ref CLDepthwiseConvolutionLayerNativeKernel::configure() |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 82 | */ |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 83 | void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const DWCComputeKernelInfo &dwc_info, |
| 84 | const ConvolutionInfo &conv_info, const ICLTensor *output_multipliers = nullptr, const ICLTensor *output_shifts = nullptr); |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 85 | |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 86 | /** Static function to check if given info will lead to a valid configuration of @ref CLDepthwiseConvolutionLayerNativeKernel |
| 87 | * |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 88 | * Similar to @ref CLDepthwiseConvolutionLayerNativeKernel::configure() |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 89 | * |
| 90 | * @return a status |
| 91 | */ |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 92 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const DWCComputeKernelInfo &dwc_info, |
| 93 | const ConvolutionInfo &conv_info, const ITensorInfo *output_multipliers = nullptr, const ITensorInfo *output_shifts = nullptr); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 94 | |
| 95 | // Inherited methods overridden: |
| 96 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 97 | |
| 98 | private: |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 99 | const ICLTensor *_input {}; |
| 100 | const ICLTensor *_weights{}; |
| 101 | const ICLTensor *_biases{}; |
| 102 | ICLTensor *_output{}; |
| 103 | unsigned int _depth_multiplier{ 0 }; |
| 104 | const ICLTensor *_output_multipliers{}; |
| 105 | const ICLTensor *_output_shifts{}; |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 106 | bool _export_to_cl_image { true }; |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 107 | bool _is_quantized{ false }; |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 108 | }; |
| 109 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 110 | #endif /*ARM_COMPUTE_CLDEPTHWISECONVOLUTIONLAYERNATIVEKERNEL_H */ |