blob: 62bc5d41c9e4b966a6ee7b8226b66863631e70dc [file] [log] [blame]
Manuel Bottini327225d2021-04-13 13:09:30 +01001/*
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 Bottinib4bb6a02021-05-24 16:01:32 +010024#ifndef ARM_COMPUTE_CPU_DIRECTCONV2D_OUTPUTSTAGE_KERNEL_H
25#define ARM_COMPUTE_CPU_DIRECTCONV2D_OUTPUTSTAGE_KERNEL_H
Manuel Bottini327225d2021-04-13 13:09:30 +010026
27#include "arm_compute/core/KernelDescriptors.h"
28#include "src/core/common/Macros.h"
29#include "src/core/cpu/ICpuKernel.h"
30
31namespace arm_compute
32{
33class ITensor;
34namespace cpu
35{
36namespace 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 Bottinib4bb6a02021-05-24 16:01:32 +010044class CpuDirectConv2dOutputStageKernel : public ICpuKernel
Manuel Bottini327225d2021-04-13 13:09:30 +010045{
46public:
47 /** Default constructor */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010048 CpuDirectConv2dOutputStageKernel() = default;
49 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuDirectConv2dOutputStageKernel);
Manuel Bottini327225d2021-04-13 13:09:30 +010050 /** Set the accumulate buffer and the biases of the kernel.
51 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010052 * @param[in, out] src Input to add the bias to. If @p dst is not specified then accumulation is done in-place.
Manuel Bottini327225d2021-04-13 13:09:30 +010053 * 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 Bottinib4bb6a02021-05-24 16:01:32 +010055 * @param[out] dst (Optional) If the dst tensor is specified the accumulation is done out-of-place. (Defaults to nullptr)
Manuel Bottini327225d2021-04-13 13:09:30 +010056 * 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 Bottinib4bb6a02021-05-24 16:01:32 +010062 /** Static function to check if given info will lead to a valid configuration
Manuel Bottini327225d2021-04-13 13:09:30 +010063 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010064 * Similar to CpuDirectConv2dOutputStageKernel::configure()
Manuel Bottini327225d2021-04-13 13:09:30 +010065 *
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
75private:
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 Bottinib4bb6a02021-05-24 16:01:32 +010087#endif /*ARM_COMPUTE_CPU_DIRECTCONV2D_OUTPUTSTAGE_KERNEL_H */