blob: 6f4cce3cdeda6b234fba63e75a07811bf32d5645 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sheri Zhang1e3ab422021-03-16 17:35:08 +00002 * Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H
25#define ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/Types.h"
Michalis Spyrou6eb73452020-07-02 17:39:25 +010028#include "arm_compute/runtime/IFunction.h"
Sheri Zhang1e3ab422021-03-16 17:35:08 +000029
30#include <memory>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
32namespace arm_compute
33{
34class ITensor;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010035class ITensorInfo;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036
Sheri Zhang1e3ab422021-03-16 17:35:08 +000037/** Basic function to run @ref cpu::CpuPixelWiseMultiplication */
Michalis Spyrou6eb73452020-07-02 17:39:25 +010038class NEPixelWiseMultiplication : public IFunction
39{
40public:
41 /** Default Constructor */
42 NEPixelWiseMultiplication();
43 /** Default Destructor */
44 ~NEPixelWiseMultiplication();
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 NEPixelWiseMultiplication(const NEPixelWiseMultiplication &) = delete;
47 /** Default move constructor */
Sheri Zhang1e3ab422021-03-16 17:35:08 +000048 NEPixelWiseMultiplication(NEPixelWiseMultiplication &&) = default;
Michalis Spyrou6eb73452020-07-02 17:39:25 +010049 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NEPixelWiseMultiplication &operator=(const NEPixelWiseMultiplication &) = delete;
51 /** Default move assignment operator */
Sheri Zhang1e3ab422021-03-16 17:35:08 +000052 NEPixelWiseMultiplication &operator=(NEPixelWiseMultiplication &&) = default;
Michalis Spyrou6eb73452020-07-02 17:39:25 +010053 /** Initialise the kernel's inputs, output and convertion policy.
54 *
55 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
56 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
57 *
SiCong Libb88f892020-08-28 11:18:47 +010058 * @param[in, out] input1 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
Michalis Spyrou6eb73452020-07-02 17:39:25 +010059 * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
SiCong Libb88f892020-08-28 11:18:47 +010060 * @param[in, out] input2 An input tensor. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), QASYMM8_SIGNED (only if @p input1 is QASYMM8_SIGNED), S16, S32, QSYMM16 (only if @p input1 is QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
Michalis Spyrou6eb73452020-07-02 17:39:25 +010061 * This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
62 * @param[out] output Output tensor. Data types supported:
63 * - U8, only if both inputs are U8.
64 * - QASYMM8, only if both inputs are QASYMM8.
65 * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED.
66 * - S16.
67 * - QSYMM16, only if both inputs are QSYMM16.
SiCong Libb88f892020-08-28 11:18:47 +010068 * - S32, only if both inputs are S32 or both are QSYMM16.
Michalis Spyrou6eb73452020-07-02 17:39:25 +010069 * - F16, only if @p input1 is F16.
70 * - F32, only if both inputs are F32.
71 * @param[in] scale Scale to apply after multiplication.
72 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
SiCong Libb88f892020-08-28 11:18:47 +010073 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
74 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Michalis Spyrou6eb73452020-07-02 17:39:25 +010075 * @param[in] rounding_policy Rounding policy.
76 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
77 */
78 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy,
79 const ActivationLayerInfo &act_info = ActivationLayerInfo());
80 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplication
81 *
82 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
83 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
84 *
SiCong Libb88f892020-08-28 11:18:47 +010085 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
86 * @param[in] input2 An input tensor info. Data types supported: U8, QASYMM8 (only if @p input1 is QASYMM8), QASYMM8_SIGNED (only if @p input1 is QASYMM8_SIGNED), S16, S32, QSYMM16 (only if both inputs are QSYMM16), F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
Michalis Spyrou6eb73452020-07-02 17:39:25 +010087 * @param[in] output Output tensor info. Data types supported:
88 * - U8, only if both inputs are U8.
89 * - QASYMM8, only if both inputs are QASYMM8.
90 * - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED.
91 * - S16.
92 * - QSYMM16, only if both inputs are QSYMM16.
SiCong Libb88f892020-08-28 11:18:47 +010093 * - S32, only if both inputs are S32 or both are QSYMM16.
Michalis Spyrou6eb73452020-07-02 17:39:25 +010094 * - F16, only if @p input1 is F16.
95 * - F32, only if both inputs are F32.
96 * @param[in] scale Scale to apply after multiplication.
97 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
SiCong Libb88f892020-08-28 11:18:47 +010098 * If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255
99 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100100 * @param[in] rounding_policy Rounding policy.
101 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
102 *
103 * @return a status
104 */
105 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy,
106 const ActivationLayerInfo &act_info = ActivationLayerInfo());
107
108 // Inherited methods overridden:
109 void run() override;
110
111private:
112 struct Impl;
113 std::unique_ptr<Impl> _impl;
114};
115
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000116/** Basic function to run @ref cpu::CpuComplexPixelWiseMultiplication. */
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100117class NEComplexPixelWiseMultiplication : public IFunction
118{
119public:
120 /** Default Constructor */
121 NEComplexPixelWiseMultiplication();
122 /** Default Destructor */
123 ~NEComplexPixelWiseMultiplication();
124 /** Prevent instances of this class from being copied (As this class contains pointers) */
125 NEComplexPixelWiseMultiplication(const NEComplexPixelWiseMultiplication &) = delete;
126 /** Default move constructor */
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000127 NEComplexPixelWiseMultiplication(NEComplexPixelWiseMultiplication &&) = default;
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100128 /** Prevent instances of this class from being copied (As this class contains pointers) */
129 NEComplexPixelWiseMultiplication &operator=(const NEComplexPixelWiseMultiplication &) = delete;
130 /** Default move assignment operator */
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000131 NEComplexPixelWiseMultiplication &operator=(NEComplexPixelWiseMultiplication &&) = default;
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100132 /** Initialise the kernel's inputs, output.
133 *
134 * @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
135 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
136 * @param[in, out] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
137 * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0.
138 * @param[out] output The output tensor. Data types supported: same as @p input1. Number of channels: same as @p input1.
139 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
140 */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000141 void configure(ITensor *input1, ITensor *input2, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
giuros01154bc1c2019-03-26 17:44:40 +0000142 /** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplication
143 *
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000144 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor).
145 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
146 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
147 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported.
giuros01154bc1c2019-03-26 17:44:40 +0000148 */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000149 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michalis Spyrou6eb73452020-07-02 17:39:25 +0100150
151 // Inherited methods overridden:
152 void run() override;
153
154private:
155 struct Impl;
156 std::unique_ptr<Impl> _impl;
giuros01154bc1c2019-03-26 17:44:40 +0000157};
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000158} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000159#endif /*ARM_COMPUTE_NEPIXELWISEMULTIPLICATION_H */