Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2021 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 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPU_DIRECTCONV2D_OUTPUTSTAGE_KERNEL_H |
| 25 | #define ARM_COMPUTE_CPU_DIRECTCONV2D_OUTPUTSTAGE_KERNEL_H |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/KernelDescriptors.h" |
| 28 | #include "src/core/common/Macros.h" |
| 29 | #include "src/core/cpu/ICpuKernel.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | class ITensor; |
| 34 | namespace cpu |
| 35 | { |
| 36 | namespace kernels |
| 37 | { |
| 38 | /** Kernel to accumulate the biases, if provided, or downscale in case of quantized input. |
| 39 | * |
| 40 | * @note We assume bias to be shared |
| 41 | * @note For quantized computations (i.e. @p src of S32 type) the output data type for auto-initialization must be passed as part |
| 42 | * of the @ref DirectConvolutionLayerOutputStageKernelInfo. |
| 43 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 44 | class CpuDirectConv2dOutputStageKernel : public ICpuKernel |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 45 | { |
| 46 | public: |
| 47 | /** Default constructor */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 48 | CpuDirectConv2dOutputStageKernel() = default; |
| 49 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuDirectConv2dOutputStageKernel); |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 50 | /** Set the accumulate buffer and the biases of the kernel. |
| 51 | * |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 52 | * @param[in, out] src Input to add the bias to. If @p dst is not specified then accumulation is done in-place. |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 53 | * Data type supported: F16/F32/S32 |
| 54 | * @param[in] bias (Optional) The shared bias tensor to add. It must be 1D Tensor. Data type supported: Same as @p src |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 55 | * @param[out] dst (Optional) If the dst tensor is specified the accumulation is done out-of-place. (Defaults to nullptr) |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 56 | * Note that in-place computation is only supported for F16/F32. For S32 this must not be nullptr. |
| 57 | * Data type supported: F16/F32 or QASYMM8/QASYMM8_SIGNED if @p src is S32 |
| 58 | * @param[in] info (Optional) DirectConvolutionLayerOutputStageKernel descriptor metadata |
| 59 | */ |
| 60 | void configure(ITensorInfo *src, const ITensorInfo *bias = nullptr, ITensorInfo *dst = nullptr, |
| 61 | const DirectConvolutionLayerOutputStageKernelInfo &info = DirectConvolutionLayerOutputStageKernelInfo()); |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 62 | /** Static function to check if given info will lead to a valid configuration |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 63 | * |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 64 | * Similar to CpuDirectConv2dOutputStageKernel::configure() |
Manuel Bottini | 327225d | 2021-04-13 13:09:30 +0100 | [diff] [blame] | 65 | * |
| 66 | * @return a status |
| 67 | */ |
| 68 | static Status validate(const ITensorInfo *src, const ITensorInfo *bias = nullptr, const ITensorInfo *dst = nullptr, |
| 69 | const DirectConvolutionLayerOutputStageKernelInfo &info = DirectConvolutionLayerOutputStageKernelInfo()); |
| 70 | |
| 71 | // Inherited methods overridden: |
| 72 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
| 73 | const char *name() const override; |
| 74 | |
| 75 | private: |
| 76 | using OutputStageKernel = void(ITensor *src, const ITensor *bias, const Window &window, ITensor *dst, |
| 77 | int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift); |
| 78 | |
| 79 | OutputStageKernel *_func{ nullptr }; |
| 80 | int _result_fixedpoint_multiplier{ 0 }; |
| 81 | int _result_shift{ 0 }; |
| 82 | int _result_offset_after_shift{ 0 }; |
| 83 | }; |
| 84 | } // namespace kernels |
| 85 | } // namespace cpu |
| 86 | } // namespace arm_compute |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 87 | #endif /*ARM_COMPUTE_CPU_DIRECTCONV2D_OUTPUTSTAGE_KERNEL_H */ |