Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | f1aeab9 | 2023-05-30 13:35:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021, 2023 Arm Limited. |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 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 ARM_COMPUTE_CL_ELEMENTWISE_OPERATIONS_H |
| 25 | #define ARM_COMPUTE_CL_ELEMENTWISE_OPERATIONS_H |
| 26 | |
SiCong Li | 9129549 | 2023-07-21 18:16:13 +0100 | [diff] [blame] | 27 | #include "arm_compute/function_info/ActivationLayerInfo.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 28 | |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 29 | #include "src/gpu/cl/ClCompileContext.h" |
| 30 | #include "src/gpu/cl/IClOperator.h" |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace opencl |
| 35 | { |
| 36 | /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for division |
| 37 | * |
| 38 | * @note The tensor data type for the inputs must be F16/F32. |
| 39 | * @note The function performs an arithmetic division between two tensors. |
| 40 | */ |
| 41 | class ClElementwiseDivision : public IClOperator |
| 42 | { |
| 43 | public: |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 44 | /** Configure function for a given list of arguments. |
| 45 | * |
| 46 | * @param[in] compile_context The compile context to be used. |
| 47 | * @param[in] src1 First source tensor info. Data types supported: F16/F32. |
| 48 | * @param[in] src2 Second source tensor info. same as @p src1. |
| 49 | * @param[out] dst Destination tensor info. Data types supported: same as @p src1. |
| 50 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 51 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 52 | void configure(const ClCompileContext &compile_context, |
| 53 | ITensorInfo *src1, |
| 54 | ITensorInfo *src2, |
| 55 | ITensorInfo *dst, |
| 56 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 57 | /** Static function to check if given info will lead to a valid configuration |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 58 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 59 | * Similar to @ref ClElementwiseDivision::configure() |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 60 | * |
| 61 | * @return a status |
| 62 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 63 | static Status validate(const ITensorInfo *src1, |
| 64 | const ITensorInfo *src2, |
| 65 | const ITensorInfo *dst, |
| 66 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for max |
| 70 | * |
| 71 | * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32. |
| 72 | * @note The function performs a max operation between two tensors. |
| 73 | */ |
| 74 | class ClElementwiseMax : public IClOperator |
| 75 | { |
| 76 | public: |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 77 | /** Configure function for a given list of arguments. |
| 78 | * |
| 79 | * @param[in] compile_context The compile context to be used. |
| 80 | * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32. |
| 81 | * @param[in] src2 Second source tensor info. Data types supported: same as @p src1. |
| 82 | * @param[out] dst Destination tensor info. Data types supported: same as @p src1. |
| 83 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 84 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 85 | void configure(const ClCompileContext &compile_context, |
| 86 | ITensorInfo *src1, |
| 87 | ITensorInfo *src2, |
| 88 | ITensorInfo *dst, |
| 89 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 90 | /** Static function to check if given info will lead to a valid configuration |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 91 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 92 | * Similar to @ref ClElementwiseMax::configure() |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 93 | * |
| 94 | * @return a status |
| 95 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 96 | static Status validate(const ITensorInfo *src1, |
| 97 | const ITensorInfo *src2, |
| 98 | const ITensorInfo *dst, |
| 99 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for min |
| 103 | * |
| 104 | * @note The tensor data type for the inputs must be U8/QASYMM8/S16/QSYMM16/S32/U32/F16/F32. |
| 105 | * @note The function performs a max operation between two tensors. |
| 106 | */ |
| 107 | class ClElementwiseMin : public IClOperator |
| 108 | { |
| 109 | public: |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 110 | /** Configure function for a given list of arguments. |
| 111 | * |
| 112 | * @param[in] compile_context The compile context to be used. |
| 113 | * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/S32/U32/F16/F32. |
| 114 | * @param[in] src2 Second source tensor info. Data types supported: same as @p src1. |
| 115 | * @param[out] dst Destination tensor info. Data types supported: same as @p src1. |
| 116 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 117 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 118 | void configure(const ClCompileContext &compile_context, |
| 119 | ITensorInfo *src1, |
| 120 | ITensorInfo *src2, |
| 121 | ITensorInfo *dst, |
| 122 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 123 | /** Static function to check if given info will lead to a valid configuration |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 124 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 125 | * Similar to @ref ClElementwiseMin::configure() |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 126 | * |
| 127 | * @return a status |
| 128 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 129 | static Status validate(const ITensorInfo *src1, |
| 130 | const ITensorInfo *src2, |
| 131 | const ITensorInfo *dst, |
| 132 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for squared difference |
| 136 | * |
| 137 | * @note The tensor data type for the inputs must be QASYMM8/U8/S16/QSYMM16/F16/F32. |
| 138 | * @note The function performs a squared different operation between two tensors (i.e., out[i] = (in1[i] - in2[i])^2 |
| 139 | */ |
| 140 | class ClElementwiseSquaredDiff : public IClOperator |
| 141 | { |
| 142 | public: |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 143 | /** Configure function for a given list of arguments. |
| 144 | * |
| 145 | * @param[in] compile_context The compile context to be used. |
| 146 | * @param[in] src1 First source tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. |
| 147 | * @param[in] src2 Second source tensor info. Data types supported: same as @p src1. |
| 148 | * @param[out] dst Destination tensor info. Data types supported: same as @p src1. |
| 149 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 150 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 151 | void configure(const ClCompileContext &compile_context, |
| 152 | ITensorInfo *src1, |
| 153 | ITensorInfo *src2, |
| 154 | ITensorInfo *dst, |
| 155 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 156 | /** Static function to check if given info will lead to a valid configuration |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 157 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 158 | * Similar to @ref ClElementwiseSquaredDiff::configure() |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 159 | * |
| 160 | * @return a status |
| 161 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 162 | static Status validate(const ITensorInfo *src1, |
| 163 | const ITensorInfo *src2, |
| 164 | const ITensorInfo *dst, |
| 165 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | /** Basic function to run @ref opencl::kernels::ClArithmeticKernel for power |
| 169 | * |
| 170 | * @note The tensor data type for the inputs must be F16/F32. |
| 171 | * @note The function performs an elementwise power of in1 to in2 (i.e., out[i] = in1[i] ^ in2[i]) |
| 172 | */ |
| 173 | class ClElementwisePower : public IClOperator |
| 174 | { |
| 175 | public: |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 176 | /** Configure function for a given list of arguments. |
| 177 | * |
| 178 | * @param[in] compile_context The compile context to be used. |
| 179 | * @param[in] src1 First source tensor info. Data types supported: F16/F32. |
| 180 | * @param[in] src2 Second source tensor info. Data types supported: F16/F32. |
| 181 | * @param[out] dst Destination tensor info. Data types supported:F16/F32. |
| 182 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
| 183 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 184 | void configure(const ClCompileContext &compile_context, |
| 185 | ITensorInfo *src1, |
| 186 | ITensorInfo *src2, |
| 187 | ITensorInfo *dst, |
| 188 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 189 | /** Static function to check if given info will lead to a valid configuration |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 190 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 191 | * Similar to @ref ClElementwisePower::configure() |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 192 | * |
| 193 | * @return a status |
| 194 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 195 | static Status validate(const ITensorInfo *src1, |
| 196 | const ITensorInfo *src2, |
| 197 | const ITensorInfo *dst, |
| 198 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Michele Di Giorgio | 237be03 | 2021-01-25 15:44:02 +0000 | [diff] [blame] | 199 | }; |
| 200 | } // namespace opencl |
| 201 | } // namespace arm_compute |
| 202 | #endif /* ARM_COMPUTE_CL_ELEMENTWISE_OPERATIONS_H */ |