George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2023 Arm Limited. |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/kernels/CpuElementwiseUnaryKernel.h" |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 25 | |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/ITensor.h" |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Utils.h" |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/Validate.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 31 | |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 32 | #include "src/core/common/Registrars.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 33 | #include "src/core/CPP/Validate.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 34 | #include "src/core/helpers/AutoConfiguration.h" |
| 35 | #include "src/core/helpers/WindowHelpers.h" |
Dana Zlotnik | d5c496d | 2021-11-28 14:46:12 +0200 | [diff] [blame] | 36 | #include "src/cpu/kernels/elementwise_unary/list.h" |
Michalis Spyrou | e6bcb5b | 2019-06-07 11:47:16 +0100 | [diff] [blame] | 37 | #include "support/ToolchainSupport.h" |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 38 | |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 39 | namespace arm_compute |
| 40 | { |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 41 | namespace cpu |
| 42 | { |
| 43 | namespace kernels |
| 44 | { |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 45 | namespace |
| 46 | { |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 47 | #ifdef __aarch64__ |
| 48 | |
| 49 | std::unique_ptr<uint8_t[]> q8_prepare_lut(ElementWiseUnary op, const ITensorInfo *src, const ITensorInfo *dst) |
| 50 | { |
| 51 | ARM_COMPUTE_ERROR_ON(src->data_type() != dst->data_type()); |
| 52 | ARM_COMPUTE_ERROR_ON(!is_data_type_quantized(src->data_type())); |
| 53 | ARM_COMPUTE_ERROR_ON(src->element_size() != 1); |
| 54 | |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 55 | auto lut = std::unique_ptr<uint8_t[]>(new uint8_t[256]); |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 56 | const auto is_signed = src->data_type() == DataType::QASYMM8_SIGNED; |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 57 | const auto src_qi = src->quantization_info().uniform(); |
| 58 | const auto dst_qi = dst->quantization_info().uniform(); |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 59 | |
| 60 | const auto dst_min_fp = (((is_signed) ? -128 : 0) - dst_qi.offset) * dst_qi.scale; |
| 61 | const auto dst_max_fp = (((is_signed) ? 127 : 255) - dst_qi.offset) * dst_qi.scale; |
| 62 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 63 | for (int i = 0; i < 256; ++i) |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 64 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 65 | const auto in = |
| 66 | (is_signed) ? dequantize_qasymm8_signed(static_cast<int8_t>(i), src_qi) : dequantize_qasymm8(i, src_qi); |
| 67 | float result = 0; |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 68 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 69 | switch (op) |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 70 | { |
| 71 | case ElementWiseUnary::RSQRT: |
| 72 | result = 1 / sqrt(in); |
| 73 | break; |
| 74 | |
| 75 | case ElementWiseUnary::EXP: |
| 76 | result = std::exp(in); |
| 77 | break; |
| 78 | |
| 79 | case ElementWiseUnary::NEG: |
| 80 | result = -in; |
| 81 | break; |
| 82 | |
| 83 | case ElementWiseUnary::LOG: |
| 84 | result = std::log(in); |
| 85 | break; |
| 86 | |
| 87 | case ElementWiseUnary::ABS: |
| 88 | result = std::abs(in); |
| 89 | break; |
| 90 | |
| 91 | case ElementWiseUnary::ROUND: |
| 92 | result = support::cpp11::nearbyint(in); |
| 93 | break; |
| 94 | |
| 95 | case ElementWiseUnary::SIN: |
| 96 | result = std::sin(in); |
| 97 | break; |
| 98 | |
| 99 | default: |
| 100 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 101 | } |
| 102 | |
| 103 | result = utility::clamp(result, dst_min_fp, dst_max_fp); |
| 104 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 105 | const auto out = (is_signed) ? static_cast<uint8_t>(quantize_qasymm8_signed(result, dst_qi)) |
| 106 | : quantize_qasymm8(result, dst_qi); |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 107 | lut[i] = out; |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return lut; |
| 111 | } |
| 112 | |
| 113 | #endif // __aarch64__ |
| 114 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 115 | static const std::vector<CpuElementwiseUnaryKernel::ElementwiseUnaryKernel> available_kernels = { |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 116 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 117 | "sve_fp32_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 118 | [](const DataTypeISASelectorData &data) { return (data.dt == DataType::F32 && data.isa.sve); }, |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 119 | REGISTER_FP32_SVE(sve_fp32_elementwise_unary), |
| 120 | nullptr, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 121 | }, |
| 122 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 123 | "sve_fp16_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 124 | [](const DataTypeISASelectorData &data) { return (data.dt == DataType::F16 && data.isa.sve && data.isa.fp16); }, |
Dana Zlotnik | d5c496d | 2021-11-28 14:46:12 +0200 | [diff] [blame] | 125 | REGISTER_FP16_SVE(sve_fp16_elementwise_unary), |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 126 | nullptr, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 127 | }, |
| 128 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 129 | "sve_s32_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 130 | [](const DataTypeISASelectorData &data) { return (data.dt == DataType::S32 && data.isa.sve); }, |
Dana Zlotnik | d5c496d | 2021-11-28 14:46:12 +0200 | [diff] [blame] | 131 | REGISTER_INTEGER_SVE(sve_s32_elementwise_unary), |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 132 | nullptr, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 133 | }, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 134 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 135 | "neon_fp32_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 136 | [](const DataTypeISASelectorData &data) { return data.dt == DataType::F32; }, |
Dana Zlotnik | d5c496d | 2021-11-28 14:46:12 +0200 | [diff] [blame] | 137 | REGISTER_FP32_NEON(neon_fp32_elementwise_unary), |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 138 | nullptr, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 139 | }, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 140 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 141 | "neon_fp16_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 142 | [](const DataTypeISASelectorData &data) { return data.dt == DataType::F16 && data.isa.fp16; }, |
Dana Zlotnik | 8d8208c | 2022-01-24 09:13:55 +0200 | [diff] [blame] | 143 | REGISTER_FP16_NEON(neon_fp16_elementwise_unary), |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 144 | nullptr, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 145 | }, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 146 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 147 | "neon_s32_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 148 | [](const DataTypeISASelectorData &data) { return data.dt == DataType::S32; }, |
Dana Zlotnik | d5c496d | 2021-11-28 14:46:12 +0200 | [diff] [blame] | 149 | REGISTER_INTEGER_NEON(neon_s32_elementwise_unary), |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 150 | nullptr, |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 151 | }, |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 152 | #ifdef __aarch64__ |
| 153 | { |
SiCong Li | c0463a2 | 2023-05-17 13:46:13 +0100 | [diff] [blame] | 154 | "sve2_q8_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 155 | [](const DataTypeISASelectorData &data) |
| 156 | { return (data.dt == DataType::QASYMM8 || data.dt == DataType::QASYMM8_SIGNED) && data.isa.sve2; }, |
SiCong Li | c0463a2 | 2023-05-17 13:46:13 +0100 | [diff] [blame] | 157 | REGISTER_QASYMM8_SVE2(sve2_q8_elementwise_unary), |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 158 | &q8_prepare_lut, |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 159 | }, |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 160 | { |
| 161 | "neon_q8_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 162 | [](const DataTypeISASelectorData &data) |
| 163 | { return data.dt == DataType::QASYMM8 || data.dt == DataType::QASYMM8_SIGNED; }, |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 164 | REGISTER_QASYMM8_NEON(neon_q8_elementwise_unary), |
| 165 | &q8_prepare_lut, |
| 166 | }, |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 167 | #else // __aarch64__ |
| 168 | { |
| 169 | "neon_qasymm8_signed_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 170 | [](const DataTypeISASelectorData &data) { return data.dt == DataType::QASYMM8_SIGNED; }, |
Ramy Elgammal | b84df20 | 2023-04-12 17:31:10 +0100 | [diff] [blame] | 171 | REGISTER_QASYMM8_SIGNED_NEON(neon_qasymm8_signed_elementwise_unary), |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 172 | nullptr, |
| 173 | }, |
| 174 | { |
| 175 | "neon_qasymm8_elementwise_unary", |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 176 | [](const DataTypeISASelectorData &data) { return data.dt == DataType::QASYMM8; }, |
Ramy Elgammal | 8b7f42a | 2023-03-31 16:16:15 +0100 | [diff] [blame] | 177 | REGISTER_QASYMM8_NEON(neon_qasymm8_elementwise_unary), |
| 178 | nullptr, |
| 179 | }, |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 180 | #endif // __aarch64__ |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 183 | } // namespace |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 184 | |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 185 | void CpuElementwiseUnaryKernel::configure(ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst) |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 186 | { |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 187 | ARM_COMPUTE_ERROR_THROW_ON(validate(op, src, dst)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 188 | const auto uk = CpuElementwiseUnaryKernel::get_implementation( |
| 189 | DataTypeISASelectorData{src.data_type(), CPUInfo::get().get_isa()}); |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 190 | ARM_COMPUTE_ERROR_ON(uk == nullptr || uk->ukernel == nullptr); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 191 | |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 192 | _op = op; |
| 193 | _run_method = uk->ukernel; |
| 194 | _name = std::string("CpuElementwiseUnaryKernel").append("/").append(uk->name); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 195 | |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 196 | // If input shape is dynamic, expect a configured window and dst at run-time. |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 197 | if (src.is_dynamic()) |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 198 | { |
| 199 | return; |
| 200 | } |
| 201 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 202 | if (uk->prepare_func != nullptr) |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 203 | { |
| 204 | _lut = uk->prepare_func(op, &src, &dst); |
| 205 | } |
| 206 | |
Sang-Hoon Park | d0b7b4b | 2021-03-09 10:47:30 +0000 | [diff] [blame] | 207 | auto shape_and_window = compute_output_shape_and_window(src.tensor_shape()); |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 208 | auto_init_if_empty(dst, shape_and_window.first, 1, src.data_type()); |
Yair Schwarzbaum | 46d44d2 | 2022-01-12 16:38:58 +0200 | [diff] [blame] | 209 | ICpuKernel::configure(shape_and_window.second); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 212 | Status CpuElementwiseUnaryKernel::validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst) |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 213 | { |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 214 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(&src); |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 215 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 216 | const auto *uk = CpuElementwiseUnaryKernel::get_implementation( |
| 217 | DataTypeISASelectorData{src.data_type(), CPUInfo::get().get_isa()}); |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 218 | |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 219 | ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr); |
| 220 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 221 | switch (op) |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 222 | { |
| 223 | case ElementWiseUnary::EXP: |
| 224 | case ElementWiseUnary::RSQRT: |
| 225 | case ElementWiseUnary::LOG: |
| 226 | case ElementWiseUnary::ROUND: |
| 227 | case ElementWiseUnary::SIN: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 228 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&src, 1, DataType::F16, DataType::F32, |
| 229 | DataType::QASYMM8, DataType::QASYMM8_SIGNED); |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 230 | break; |
| 231 | case ElementWiseUnary::NEG: |
| 232 | case ElementWiseUnary::ABS: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 233 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&src, 1, DataType::F16, DataType::F32, DataType::S32, |
| 234 | DataType::QASYMM8, DataType::QASYMM8_SIGNED); |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 235 | break; |
| 236 | default: |
| 237 | ARM_COMPUTE_ERROR("ElementWiseUnary operation not supported"); |
| 238 | } |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 239 | // Validate in case of configured dst |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 240 | if (dst.total_size() > 0) |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 241 | { |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 242 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&src, &dst); |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 243 | } |
| 244 | |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 245 | return Status{}; |
| 246 | } |
| 247 | |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 248 | void CpuElementwiseUnaryKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 249 | { |
| 250 | ARM_COMPUTE_UNUSED(info); |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 251 | |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 252 | auto src = tensors.get_const_tensor(TensorType::ACL_SRC); |
| 253 | auto dst = tensors.get_tensor(TensorType::ACL_DST); |
| 254 | |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 255 | _run_method(src, dst, window, _op, _lut.get()); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 256 | } |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 257 | |
| 258 | const char *CpuElementwiseUnaryKernel::name() const |
| 259 | { |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 260 | return _name.c_str(); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 261 | } |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 262 | |
| 263 | const std::vector<CpuElementwiseUnaryKernel::ElementwiseUnaryKernel> &CpuElementwiseUnaryKernel::get_available_kernels() |
| 264 | { |
| 265 | return available_kernels; |
| 266 | } |
| 267 | |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 268 | } // namespace kernels |
| 269 | } // namespace cpu |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 270 | } // namespace arm_compute |