Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 24 | #ifndef __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONASSEMBLYDISPATCH_H__ |
| 25 | #define __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONASSEMBLYDISPATCH_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
| 29 | #include "arm_compute/runtime/IMemoryManager.h" |
| 30 | #include "arm_compute/runtime/MemoryGroup.h" |
| 31 | #include "arm_compute/runtime/Tensor.h" |
| 32 | |
| 33 | #include "arm_compute/core/NEON/kernels/assembly/NEDepthwiseConvolutionAssemblyKernelWrapper.h" |
| 34 | #include "arm_compute/core/NEON/kernels/convolution/depthwise/depthwise.hpp" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | /** Depthwise convolution assembly kernel glue */ |
| 39 | class NEDepthwiseConvolutionAssemblyDispatch : public IFunction |
| 40 | { |
| 41 | public: |
| 42 | /** Default constructor |
| 43 | * |
| 44 | * @param[in,out] memory_manager Memory manager to use |
| 45 | */ |
| 46 | NEDepthwiseConvolutionAssemblyDispatch(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 47 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 48 | NEDepthwiseConvolutionAssemblyDispatch(const NEDepthwiseConvolutionAssemblyDispatch &) = delete; |
| 49 | /** Default move constructor */ |
| 50 | NEDepthwiseConvolutionAssemblyDispatch(NEDepthwiseConvolutionAssemblyDispatch &&) = default; |
| 51 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 | NEDepthwiseConvolutionAssemblyDispatch &operator=(const NEDepthwiseConvolutionAssemblyDispatch &) = delete; |
| 53 | /** Default move assignment operator */ |
| 54 | NEDepthwiseConvolutionAssemblyDispatch &operator=(NEDepthwiseConvolutionAssemblyDispatch &&) = default; |
| 55 | /** Initialize the function's source, destination, kernels and border_size. |
| 56 | * |
| 57 | * @note Supports only NHWC format |
| 58 | * |
| 59 | * @param[in] input Source tensor. Data type supported: QASYMM8/F16/F32. (Written to only for border filling). |
| 60 | * @param[in] weights Weights tensor. These are 3D tensors with shape [3, 3, IFM]. Data type supported: Same as @p input. |
| 61 | * @param[in] bias (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed. |
| 62 | * 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] act_info (Optional) Activation layer information in case of a fused activation. |
| 67 | */ |
| 68 | void configure(const ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, |
| 69 | const PadStrideInfo &conv_info, unsigned int depth_multiplier = 1, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 70 | /** Static function to check if given info will lead to a valid configuration of @ref NEDepthwiseConvolutionAssemblyDispatch |
| 71 | * |
| 72 | * @note Supports only NHWC format |
| 73 | * |
| 74 | * @param[in] input Source tensor. Data type supported: QASYMM8/F16/F32. (Written to only for border filling). |
| 75 | * @param[in] weights Weights tensor. These are 3D tensors with shape [3, 3, IFM]. Data type supported: Same as @p input. |
| 76 | * @param[in] bias (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed. |
| 77 | * Data type supported: Same as @p input. |
| 78 | * @param[out] output Destination tensor. 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] act_info (Optional) Activation layer information in case of a fused activation. |
| 82 | * |
| 83 | * @return An error status |
| 84 | */ |
| 85 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, |
| 86 | const PadStrideInfo &conv_info, unsigned int depth_multiplier = 1, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 87 | /** Check if the optimized kernel can be used for the given kernel sizes and strides |
| 88 | * |
| 89 | * @warning Even if this return true the inputs and outputs might need to get permuted as the only layout supported is NHWC |
| 90 | * |
| 91 | * @param[in] input Input tensor info. |
| 92 | * @param[in] weights Weights tensor info. |
| 93 | * @param[in] conv_info Convolution layer metadata. |
| 94 | * @param[in] depth_multiplier (Optional) Depth multiplier to be used. |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 95 | * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1). |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 96 | * |
| 97 | * @return True if the assembly kernel could be used else false. Note that transformations of input/output could be needed. |
| 98 | */ |
Usama Arif | 881f2de | 2019-04-12 10:29:17 +0100 | [diff] [blame] | 99 | static bool is_optimized_supported(const ITensorInfo *input, const ITensorInfo *weights, PadStrideInfo conv_info, unsigned int depth_multiplier = 1, const Size2D &dilation = Size2D(1, 1)); |
Georgios Pinitas | 47d39dc | 2019-03-11 14:03:23 +0000 | [diff] [blame] | 100 | |
| 101 | // Inherited methods overridden: |
| 102 | void run() override; |
| 103 | void prepare() override; |
| 104 | |
| 105 | private: |
| 106 | MemoryGroup _memory_group; |
| 107 | const ITensor *_input; |
| 108 | const ITensor *_weights; |
| 109 | const ITensor *_bias; |
| 110 | ITensor *_output; |
| 111 | Tensor _packed_weights; |
| 112 | Tensor _workspace; |
| 113 | bool _is_prepared; |
| 114 | std::unique_ptr<depthwise::IDepthwiseConvolution> _dwc_assembly_kernel; |
| 115 | NEDepthwiseConvolutionAssemblyKernelWrapper _dwc_acl_kernel; |
| 116 | }; |
| 117 | } // namespace arm_compute |
| 118 | #endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTIONASSEMBLYDISPATCH_H__ */ |