Gian Marco Iodice | 76335eb | 2022-11-17 11:03:39 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
Gian Marco Iodice | 76335eb | 2022-11-17 11:03:39 +0000 | [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 | */ |
| 24 | #ifndef ARM_COMPUTE_CLINDIRECTCONVOLUTIONLAYER_H |
| 25 | #define ARM_COMPUTE_CLINDIRECTCONVOLUTIONLAYER_H |
| 26 | |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/ActivationLayerInfo.h" |
Gian Marco Iodice | 76335eb | 2022-11-17 11:03:39 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/runtime/IFunction.h" |
| 30 | |
| 31 | #include <memory> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | class CLCompileContext; |
| 36 | class ICLTensor; |
| 37 | class ITensorInfo; |
| 38 | |
| 39 | /** Basic function to run the indirect convolution function |
| 40 | */ |
| 41 | class CLIndirectConvolutionLayer : public IFunction |
| 42 | { |
| 43 | public: |
| 44 | /** Constructor */ |
| 45 | CLIndirectConvolutionLayer(); |
| 46 | /** Destructor */ |
| 47 | ~CLIndirectConvolutionLayer(); |
| 48 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 49 | CLIndirectConvolutionLayer(const CLIndirectConvolutionLayer &) = delete; |
| 50 | /** Default move constructor */ |
| 51 | CLIndirectConvolutionLayer(CLIndirectConvolutionLayer &&); |
| 52 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 53 | CLIndirectConvolutionLayer &operator=(const CLIndirectConvolutionLayer &) = delete; |
| 54 | /** Default move assignment operator */ |
| 55 | CLIndirectConvolutionLayer &operator=(CLIndirectConvolutionLayer &&); |
| 56 | /** Set the input and output tensors. |
| 57 | * |
| 58 | * Valid data layouts: |
| 59 | * - NHWC |
| 60 | * |
| 61 | * Valid data type configurations: |
| 62 | * |src0 |src1 |src2 |dst | |
| 63 | * |:--------------|:--------------|:------|:--------------| |
| 64 | * |F16 |F16 |F16 |F16 | |
| 65 | * |F32 |F32 |F32 |F32 | |
| 66 | * |
| 67 | * @param[in] input Source tensor. 3 lower dimensions represent a single input, |
| 68 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 69 | * Data types supported: F16/F32. |
| 70 | * @param[in] weights Weights tensor. Weights are 4D tensor. Data type supported:Same as @p input. |
| 71 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 72 | * Data type supported: Should match @p input data type. |
| 73 | * @param[out] output Destination tensor. 3 lower dimensions represent a single output, while the rest represent batch of outputs. |
| 74 | * Data types supported: Same as @p input. |
| 75 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 76 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 77 | */ |
| 78 | void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 79 | /** Set the input and output tensors. |
| 80 | * |
| 81 | * @param[in] compile_context The compile context to be used. |
| 82 | * @param[in] input Source tensor. 3 lower dimensions represent a single input, |
| 83 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 84 | * Data types supported: F16/F32. |
| 85 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions. Data type supported:Same as @p input. |
| 86 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 87 | * Data type supported: Should match @p input data type. |
| 88 | * @param[out] output Destination tensor. 3 lower dimensions represent a single output, while the rest represent batch of outputs. |
| 89 | * Data types supported: Same as @p input. |
| 90 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 91 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 92 | */ |
| 93 | void configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, |
| 94 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 95 | /** Static function to check if given info will lead to a valid configuration of @ref CLIndirectConvolutionLayer |
| 96 | * |
| 97 | * @param[in] input Source tensor. 3 lower dimensions represent a single input, |
| 98 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 99 | * Data types supported: F16/F32. |
| 100 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions. Data type supported:Same as @p input. |
| 101 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 102 | * Data type supported: Should match @p input data type. |
| 103 | * @param[in] output Destination tensor. 3 lower dimensions represent a single output, while the rest represent batch of outputs. |
| 104 | * Data types supported: Same as @p input. |
| 105 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 106 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 107 | * |
| 108 | * @return a status |
| 109 | */ |
| 110 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 111 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 112 | |
| 113 | // Inherited methods overridden: |
| 114 | void run() override; |
| 115 | |
| 116 | private: |
| 117 | struct Impl; |
| 118 | std::unique_ptr<Impl> _impl; |
| 119 | }; |
| 120 | } |
| 121 | #endif /* ARM_COMPUTE_CLINDIRECTCONVOLUTIONLAYER_H */ |