| 1 |
/* |
| 2 |
* Copyright (c) 2016-2021, 2023-2024 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 |
*/ |
| 24 |
#ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEPIXELWISEMULTIPLICATION_H |
| 25 |
#define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEPIXELWISEMULTIPLICATION_H |
| 26 |
|
| 27 |
#include "arm_compute/core/Rounding.h" |
| 28 |
#include "arm_compute/core/Types.h" |
| 29 |
#include "arm_compute/function_info/ActivationLayerInfo.h" |
| 30 |
#include "arm_compute/runtime/IFunction.h" |
| 31 |
|
| 32 |
#include <memory> |
| 33 |
|
| 34 |
namespace arm_compute |
| 35 |
{ |
| 36 |
class ITensor; |
| 37 |
class ITensorInfo; |
| 38 |
|
| 39 |
/** Basic function to run cpu::CpuMul */ |
| 40 |
class NEPixelWiseMultiplication : public IFunction |
| 41 |
{ |
| 42 |
public: |
| 43 |
/** Default Constructor */ |
| 44 |
NEPixelWiseMultiplication(); |
| 45 |
/** Default Destructor */ |
| 46 |
~NEPixelWiseMultiplication(); |
| 47 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 48 |
NEPixelWiseMultiplication(const NEPixelWiseMultiplication &) = delete; |
| 49 |
/** Default move constructor */ |
| 50 |
NEPixelWiseMultiplication(NEPixelWiseMultiplication &&) = default; |
| 51 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 |
NEPixelWiseMultiplication &operator=(const NEPixelWiseMultiplication &) = delete; |
| 53 |
/** Default move assignment operator */ |
| 54 |
NEPixelWiseMultiplication &operator=(NEPixelWiseMultiplication &&) = default; |
| 55 |
/** Initialise the kernel's inputs, output and convertion policy. |
| 56 |
* |
| 57 |
* Valid data layouts: |
| 58 |
* - All |
| 59 |
* |
| 60 |
* Valid data type configurations: |
| 61 |
* |src0 |src1 |dst | |
| 62 |
* |:--------------|:--------------|:--------------| |
| 63 |
* |QASYMM8 |QASYMM8 |QASYMM8 | |
| 64 |
* |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED | |
| 65 |
* |QSYMM16 |QSYMM16 |QASYMM16 | |
| 66 |
* |QSYMM16 |QSYMM16 |S32 | |
| 67 |
* |U8 |U8 |U8 | |
| 68 |
* |U8 |U8 |S16 | |
| 69 |
* |U8 |S16 |S16 | |
| 70 |
* |S16 |U8 |S16 | |
| 71 |
* |S16 |S16 |S16 | |
| 72 |
* |S32 |S32 |S32 | |
| 73 |
* |F16 |F16 |F16 | |
| 74 |
* |F32 |F32 |F32 | |
| 75 |
* |
| 76 |
* @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. |
| 77 |
* For all other scale values only round to zero (implemented as round towards minus infinity) is supported. |
| 78 |
* |
| 79 |
* @param[in, out] input1 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32 |
| 80 |
* This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 81 |
* @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). |
| 82 |
* This input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 83 |
* @param[out] output Output tensor. Data types supported: |
| 84 |
* - U8, only if both inputs are U8. |
| 85 |
* - QASYMM8, only if both inputs are QASYMM8. |
| 86 |
* - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED. |
| 87 |
* - S16. |
| 88 |
* - QSYMM16, only if both inputs are QSYMM16. |
| 89 |
* - S32, only if both inputs are S32 or both are QSYMM16. |
| 90 |
* - F16, only if @p input1 is F16. |
| 91 |
* - F32, only if both inputs are F32. |
| 92 |
* @param[in] scale Scale to apply after multiplication. |
| 93 |
* Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. |
| 94 |
* If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255 |
| 95 |
* @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype |
| 96 |
* @param[in] rounding_policy Rounding policy. |
| 97 |
* @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 98 |
*/ |
| 99 |
void configure(const ITensor *input1, |
| 100 |
const ITensor *input2, |
| 101 |
ITensor *output, |
| 102 |
float scale, |
| 103 |
ConvertPolicy overflow_policy, |
| 104 |
RoundingPolicy rounding_policy, |
| 105 |
const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 106 |
/** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplication |
| 107 |
* |
| 108 |
* @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. |
| 109 |
* For all other scale values only round to zero (implemented as round towards minus infinity) is supported. |
| 110 |
* |
| 111 |
* @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32 |
| 112 |
* @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). |
| 113 |
* @param[in] output Output tensor info. Data types supported: |
| 114 |
* - U8, only if both inputs are U8. |
| 115 |
* - QASYMM8, only if both inputs are QASYMM8. |
| 116 |
* - QASYMM8_SIGNED, only if @p input1 is QASYMM8_SIGNED. |
| 117 |
* - S16. |
| 118 |
* - QSYMM16, only if both inputs are QSYMM16. |
| 119 |
* - S32, only if both inputs are S32 or both are QSYMM16. |
| 120 |
* - F16, only if @p input1 is F16. |
| 121 |
* - F32, only if both inputs are F32. |
| 122 |
* @param[in] scale Scale to apply after multiplication. |
| 123 |
* Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. |
| 124 |
* If both @p input1, @p input2 and @p output are of datatype S32, scale cannot be 1/255 |
| 125 |
* @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype |
| 126 |
* @param[in] rounding_policy Rounding policy. |
| 127 |
* @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 128 |
* |
| 129 |
* @return a status |
| 130 |
*/ |
| 131 |
static Status validate(const ITensorInfo *input1, |
| 132 |
const ITensorInfo *input2, |
| 133 |
const ITensorInfo *output, |
| 134 |
float scale, |
| 135 |
ConvertPolicy overflow_policy, |
| 136 |
RoundingPolicy rounding_policy, |
| 137 |
const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 138 |
|
| 139 |
// Inherited methods overridden: |
| 140 |
void run() override; |
| 141 |
|
| 142 |
private: |
| 143 |
struct Impl; |
| 144 |
std::unique_ptr<Impl> _impl; |
| 145 |
}; |
| 146 |
|
| 147 |
/** Basic function to run cpu::CpuComplexMul. */ |
| 148 |
class NEComplexPixelWiseMultiplication : public IFunction |
| 149 |
{ |
| 150 |
public: |
| 151 |
/** Default Constructor */ |
| 152 |
NEComplexPixelWiseMultiplication(); |
| 153 |
/** Default Destructor */ |
| 154 |
~NEComplexPixelWiseMultiplication(); |
| 155 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 156 |
NEComplexPixelWiseMultiplication(const NEComplexPixelWiseMultiplication &) = delete; |
| 157 |
/** Default move constructor */ |
| 158 |
NEComplexPixelWiseMultiplication(NEComplexPixelWiseMultiplication &&) = default; |
| 159 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 160 |
NEComplexPixelWiseMultiplication &operator=(const NEComplexPixelWiseMultiplication &) = delete; |
| 161 |
/** Default move assignment operator */ |
| 162 |
NEComplexPixelWiseMultiplication &operator=(NEComplexPixelWiseMultiplication &&) = default; |
| 163 |
/** Initialise the kernel's inputs, output. |
| 164 |
* |
| 165 |
* @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor). |
| 166 |
* The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 167 |
* @param[in, out] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1. |
| 168 |
* The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. |
| 169 |
* @param[out] output The output tensor. Data types supported: same as @p input1. Number of channels: same as @p input1. |
| 170 |
* @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 171 |
*/ |
| 172 |
void configure(ITensor *input1, |
| 173 |
ITensor *input2, |
| 174 |
ITensor *output, |
| 175 |
const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 176 |
/** Static function to check if given info will lead to a valid configuration of @ref NEComplexPixelWiseMultiplication |
| 177 |
* |
| 178 |
* @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2 (complex tensor). |
| 179 |
* @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1. |
| 180 |
* @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1. |
| 181 |
* @param[in] act_info (Optional) Activation layer information in case of a fused activation. Currently not supported. |
| 182 |
*/ |
| 183 |
static Status validate(const ITensorInfo *input1, |
| 184 |
const ITensorInfo *input2, |
| 185 |
const ITensorInfo *output, |
| 186 |
const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
| 187 |
|
| 188 |
// Inherited methods overridden: |
| 189 |
void run() override; |
| 190 |
|
| 191 |
private: |
| 192 |
struct Impl; |
| 193 |
std::unique_ptr<Impl> _impl; |
| 194 |
}; |
| 195 |
} // namespace arm_compute |
| 196 |
#endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEPIXELWISEMULTIPLICATION_H |