Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, 2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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_NEDIRECTCONVOLUTIONLAYER_H |
| 25 | #define ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/ActivationLayerInfo.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/IMemoryManager.h" |
| 31 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 33 | #include <memory> |
| 34 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 37 | class ITensor; |
| 38 | class ITensorInfo; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | /** Function to run the direct convolution. |
| 40 | * |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 41 | * This function calls the following: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | * |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 43 | * -# @ref cpu::CpuDirectConv2d |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | */ |
| 45 | class NEDirectConvolutionLayer : public IFunction |
| 46 | { |
| 47 | public: |
| 48 | /** Constructor */ |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 49 | NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 50 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 51 | NEDirectConvolutionLayer(const NEDirectConvolutionLayer &) = delete; |
| 52 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 53 | NEDirectConvolutionLayer &operator=(const NEDirectConvolutionLayer &) = delete; |
| 54 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 55 | NEDirectConvolutionLayer(NEDirectConvolutionLayer &&) = delete; |
| 56 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 57 | NEDirectConvolutionLayer &operator=(NEDirectConvolutionLayer &&) = delete; |
| 58 | /** Default destructor */ |
| 59 | ~NEDirectConvolutionLayer(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 60 | /** Set the input, weights, biases and output tensors. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 61 | * |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 62 | * Valid data layouts: |
| 63 | * - NHWC |
| 64 | * - NCHW |
| 65 | * |
| 66 | * Valid data type configurations: |
| 67 | * |src0 |src1 |src2 |dst | |
| 68 | * |:------|:------|:------|:------| |
| 69 | * |F16 |F16 |F16 |F16 | |
| 70 | * |F32 |F32 |F32 |F32 | |
| 71 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 72 | * @note: DirectConvolution only works in the following configurations: |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 73 | * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32 |
| 74 | * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32 |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 75 | * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32 |
| 76 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 77 | * @param[in, out] input Input tensor. Data types supported: F16/F32. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 78 | * @param[in] weights Set of kernels to convolve the input volume. |
| 79 | * Supported sizes: 1x1, 3x3 and 5x5. |
| 80 | * The 3rd dimension must be the same as the input's volume 3rd dimension. |
| 81 | * Data type supported: Same as @p input. |
Georgios Pinitas | 0223a78 | 2017-12-12 11:44:44 +0000 | [diff] [blame] | 82 | * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 83 | * @param[out] output Output tensor. |
| 84 | * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input. |
| 85 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 86 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 87 | */ |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 88 | void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 89 | /** Static function to check if given info will lead to a valid configuration of @ref NEDirectConvolutionLayer |
| 90 | * |
| 91 | * @note: DirectConvolution only works in the following configurations: |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 92 | * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32 |
| 93 | * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32 |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 94 | * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32 |
| 95 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 96 | * @param[in] input Input tensor. Data types supported: F16/F32. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 97 | * @param[in] weights Set of kernels to convolve the input volume. |
| 98 | * Supported sizes: 1x1, 3x3 and 5x5. |
| 99 | * The 3rd dimension must be the same as the input's volume 3rd dimension. |
| 100 | * Data type supported: Same as @p input. |
Georgios Pinitas | 0223a78 | 2017-12-12 11:44:44 +0000 | [diff] [blame] | 101 | * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 102 | * @param[in] output Output tensor. |
| 103 | * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input. |
| 104 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 105 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 106 | * |
| 107 | * @return a status |
| 108 | */ |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 109 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 110 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 111 | |
| 112 | // Inherited methods overridden: |
| 113 | void run() override; |
| 114 | |
| 115 | private: |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 116 | struct Impl; |
| 117 | std::shared_ptr<IMemoryManager> _memory_manager; |
| 118 | std::unique_ptr<Impl> _impl; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 119 | }; |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 120 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 121 | #endif /* ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H */ |