blob: 3ea176cc31835d1ea318bbb62230b96be1fe2061 [file] [log] [blame]
Sheri Zhang1e3ab422021-03-16 17:35:08 +00001/*
2 * Copyright (c) 2016-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 */
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010024#ifndef ARM_COMPUTE_CPU_MUL_KERNEL_H
25#define ARM_COMPUTE_CPU_MUL_KERNEL_H
Sheri Zhang1e3ab422021-03-16 17:35:08 +000026
27#include "src/core/common/Macros.h"
28#include "src/core/cpu/ICpuKernel.h"
29
30namespace arm_compute
31{
32namespace cpu
33{
34namespace kernels
35{
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010036/** Interface for the kernel to perform multiplication between two tensors */
37class CpuMulKernel : public ICpuKernel
Sheri Zhang1e3ab422021-03-16 17:35:08 +000038{
39public:
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010040 CpuMulKernel() = default;
41 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuMulKernel);
Sheri Zhang1e3ab422021-03-16 17:35:08 +000042 /** Initialise the kernel's input, dst and border mode.
43 *
44 * Valid configurations (Src1,Src2) -> Dst :
45 *
46 * Support: Broadcast? Scale=1/255?
47 * - (U8,U8) -> U8, S16 N Y
48 * - (U8,S16) -> S16 N Y
49 * - (S16,U8) -> S16 N Y
50 * - (S16,S16) -> S16 N Y
51 * - (S32,S32) -> S32 Y N
52 * - (F16,F16) -> F16 N Y
53 * - (F32,F32) -> F32 Y Y
54 * - (QASYMM8,QASYMM8) -> QASYMM8 Y Y
55 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED Y Y
56 * - (QSYMM16,QSYMM16) -> QSYMM16, S32 N Y
57 *
58 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
59 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
60 *
61 * @param[in] src1 First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
62 * @param[in] src2 Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
63 * @param[out] dst Dst tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
64 * @param[in] scale Scale to apply after multiplication.
65 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
66 * If both @p src1, @p src2 and @p dst are of datatype S32, scale cannot be 1/255
67 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
68 * @param[in] rounding_policy Rounding policy.
69 */
70 void configure(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010071 /** Static function to check if given info will lead to a valid configuration
Sheri Zhang1e3ab422021-03-16 17:35:08 +000072 *
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010073 * Similar to @ref CpuMulKernel::configure()
Sheri Zhang1e3ab422021-03-16 17:35:08 +000074 *
75 * @return a status
76 */
77 static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
78
79 // Inherited methods overridden
80 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
81 const char *name() const override;
82
83private:
84 /** Common signature for all the specialised multiplication functions with integer scaling factor
85 *
86 * @param[in] src1 Src1 tensor object.
87 * @param[in] src2 Src2 tensor object.
88 * @param[out] dst Dst tensor object.
89 * @param[in] window Region on which to execute the kernel
90 * @param[in] scale Integer scale factor.
91 */
92 using MulFunctionInt = void(const ITensor *src1, const ITensor *src2, ITensor *dst, const Window &window, int scale);
93 /** Common signature for all the specialised multiplication functions with float scaling factor
94 *
95 * @param[in] src1 Src1 tensor object.
96 * @param[in] src2 Src2 tensor object.
97 * @param[out] dst Dst tensor object.
98 * @param[in] window Region on which to execute the kernel
99 * @param[in] scale Float scale factor.
100 */
101 using MulFunctionFloat = void(const ITensor *src1, const ITensor *src2, ITensor *dst, const Window &window, float scale);
102 /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor
103 *
104 * @param[in] src1 Src1 tensor object.
105 * @param[in] src2 Src2 tensor object.
106 * @param[out] dst Dst tensor object.
107 * @param[in] window Region on which to execute the kernel
108 * @param[in] scale Float scale factor.
109 *
110 */
111 using MulFunctionQuantized = void(const ITensor *src1, const ITensor *src2, ITensor *dst, const Window &window, float scale);
112
113 MulFunctionFloat *_func_float{ nullptr };
114 MulFunctionInt *_func_int{ nullptr };
115 MulFunctionQuantized *_func_quantized{ nullptr };
116 float _scale{ 0 };
117 int _scale_exponent{ 0 };
118};
119
120/** Interface for the complex pixelwise multiplication kernel. */
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100121class CpuComplexMulKernel : public ICpuKernel
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000122{
123public:
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100124 CpuComplexMulKernel() = default;
125 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuComplexMulKernel);
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000126 /** Initialise the kernel's src, dst and border mode.
127 *
128 * @param[in] src1 An src tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
129 * @param[in] src2 An src tensor. Data types supported: same as @p src1. Number of channels supported: same as @p src1.
130 * @param[out] dst The dst tensor, Data types supported: same as @p src1. Number of channels supported: same as @p src1.
131 */
132 void configure(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst);
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100133 /** Static function to check if given info will lead to a valid configuration
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000134 *
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100135 * Similar to @ref CpuComplexMulKernel::configure()
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000136 *
137 * @return a status
138 */
139 static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst);
140
141 // Inherited methods overridden:
142 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
143 const char *name() const override;
144};
145} // namespace kernels
146} // namespace cpu
147} // namespace arm_compute
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100148#endif /* ARM_COMPUTE_CPU_MUL_KERNEL_H */