Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021, 2023 Arm Limited. |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +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 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CL_DIRECT_CONV2D_H |
| 25 | #define ARM_COMPUTE_CL_DIRECT_CONV2D_H |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 26 | |
SiCong Li | 9129549 | 2023-07-21 18:16:13 +0100 | [diff] [blame] | 27 | #include "arm_compute/function_info/ActivationLayerInfo.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 28 | |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 29 | #include "src/gpu/cl/ClCompileContext.h" |
| 30 | #include "src/gpu/cl/IClKernel.h" |
| 31 | #include "src/gpu/cl/IClOperator.h" |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 32 | |
| 33 | #include <memory> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace opencl |
| 38 | { |
| 39 | /** Basic function to simulate a directly convolution layer. This function calls the following OpenCL kernels: |
| 40 | * |
| 41 | * -# @ref CLFillBorderKernel (executed if padding size is different from zero) |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 42 | * -# @ref opencl::ClDirectConv2d |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 43 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 44 | class ClDirectConv2d : public IClOperator |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 45 | { |
| 46 | public: |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 47 | ClDirectConv2d() = default; |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 48 | /** Set the src and dst tensors. |
| 49 | * |
| 50 | * @param[in] compile_context The compile context to be used. |
| 51 | * @param[in] src Source tensor. 3 lower dimensions represent a single src [width, height, IFM], |
| 52 | * while every optional dimension from 4 and above represent a batch of srcs. |
| 53 | * Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32. |
| 54 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p src. |
| 55 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 56 | * Data type supported: Should match @p src data type, except for src of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type. |
| 57 | * @param[out] dst Destination tensor. 3 lower dimensions represent a single dst [width, height, OFM], while the rest represent batch of dsts. |
| 58 | * Data types supported: Same as @p src. |
| 59 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 60 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 61 | * |
| 62 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 63 | void configure(const CLCompileContext &compile_context, |
| 64 | ITensorInfo *src, |
| 65 | ITensorInfo *weights, |
| 66 | ITensorInfo *biases, |
| 67 | ITensorInfo *dst, |
| 68 | const PadStrideInfo &conv_info, |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 69 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 70 | /** Static function to check if given info will lead to a valid configuration |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 71 | * |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 72 | * Similar to ClDirectConv2d::configure() |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 73 | * |
| 74 | * @return a status |
| 75 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 76 | static Status validate(const ITensorInfo *src, |
| 77 | const ITensorInfo *weights, |
| 78 | const ITensorInfo *biases, |
| 79 | const ITensorInfo *dst, |
| 80 | const PadStrideInfo &conv_info, |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 81 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 82 | |
| 83 | // Inherited method overridden |
| 84 | void run(ITensorPack &tensors) override; |
| 85 | |
| 86 | private: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 87 | std::unique_ptr<IClKernel> _direct_conv_kernel{nullptr}; |
| 88 | std::unique_ptr<IClKernel> _src_border_handler{nullptr}; |
| 89 | std::unique_ptr<IClKernel> _activation_kernel{nullptr}; |
Sheri Zhang | 1efed92 | 2021-03-10 22:43:38 +0000 | [diff] [blame] | 90 | }; |
| 91 | } // namespace opencl |
| 92 | } // namespace arm_compute |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 93 | #endif /* ARM_COMPUTE_CL_DIRECT_CONV2D_H */ |