Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 3f70cd0 | 2023-05-17 13:46:13 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2023 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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/CpuActivationKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/ITensor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/TensorInfo.h" |
| 28 | #include "arm_compute/core/Utils.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 29 | #include "src/core/CPP/Validate.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 30 | #include "src/core/helpers/AutoConfiguration.h" |
| 31 | #include "src/core/helpers/WindowHelpers.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 33 | #include "src/core/common/Registrars.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 34 | #include "src/cpu/kernels/activation/list.h" |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 35 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 36 | #include <array> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 40 | namespace cpu |
| 41 | { |
| 42 | namespace kernels |
| 43 | { |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 44 | namespace |
| 45 | { |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 46 | static const std::vector<CpuActivationKernel::ActivationKernel> available_kernels = |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 47 | { |
Pablo Marquez Tello | d158609 | 2022-06-10 14:37:10 +0100 | [diff] [blame] | 48 | #ifdef ARM_COMPUTE_ENABLE_SVE |
| 49 | { |
SiCong Li | 3f70cd0 | 2023-05-17 13:46:13 +0100 | [diff] [blame] | 50 | "sve2_q8_activation_lut", |
| 51 | [](const ActivationDataTypeISASelectorData & data) { return ActivationLayerInfo::is_lut_supported(data.f, data.dt) && data.cpumodel == CPUModel::A510 && data.isa.sve2; }, |
| 52 | REGISTER_QASYMM8_SVE2(arm_compute::cpu::sve2_q8_activation_lut) |
Pablo Marquez Tello | d158609 | 2022-06-10 14:37:10 +0100 | [diff] [blame] | 53 | }, |
| 54 | #endif // ARM_COMPUTE_ENABLE_SVE |
Viet-Hoa Do | b042e39 | 2022-06-21 15:56:15 +0100 | [diff] [blame] | 55 | #ifdef __aarch64__ |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 56 | { |
| 57 | // Neon LUT implementantion takes precedence |
Viet-Hoa Do | 29db3d2 | 2022-08-10 11:56:49 +0100 | [diff] [blame] | 58 | "neon_q8_activation_lut", |
Viet-Hoa Do | b042e39 | 2022-06-21 15:56:15 +0100 | [diff] [blame] | 59 | [](const ActivationDataTypeISASelectorData & data) { return ActivationLayerInfo::is_lut_supported(data.f, data.dt); }, |
Viet-Hoa Do | 29db3d2 | 2022-08-10 11:56:49 +0100 | [diff] [blame] | 60 | REGISTER_Q8_NEON(arm_compute::cpu::neon_q8_activation_lut) |
Pablo Marquez Tello | 700b913 | 2022-06-22 11:23:53 +0100 | [diff] [blame] | 61 | }, |
Viet-Hoa Do | b042e39 | 2022-06-21 15:56:15 +0100 | [diff] [blame] | 62 | #endif // __aarch64__ |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 63 | { |
Dana Zlotnik | a538ae5 | 2022-02-21 13:12:41 +0200 | [diff] [blame] | 64 | "sve2_qu8_activation", |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 65 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::QASYMM8 && data.isa.sve2 && data.f != ActivationLayerInfo::ActivationFunction::GELU; }, |
Dana Zlotnik | a538ae5 | 2022-02-21 13:12:41 +0200 | [diff] [blame] | 66 | REGISTER_QASYMM8_SVE2(arm_compute::cpu::sve2_qasymm8_activation) |
| 67 | }, |
| 68 | { |
| 69 | "sve2_qs8_activation", |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 70 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::QASYMM8_SIGNED && data.isa.sve2 && data.f != ActivationLayerInfo::ActivationFunction::GELU; }, |
Dana Zlotnik | a538ae5 | 2022-02-21 13:12:41 +0200 | [diff] [blame] | 71 | REGISTER_QASYMM8_SIGNED_SVE2(arm_compute::cpu::sve2_qasymm8_signed_activation) |
| 72 | }, |
| 73 | { |
| 74 | "sve2_qs16_activation", |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 75 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::QSYMM16 && data.isa.sve2 && data.f != ActivationLayerInfo::ActivationFunction::GELU; }, |
Dana Zlotnik | a538ae5 | 2022-02-21 13:12:41 +0200 | [diff] [blame] | 76 | REGISTER_QSYMM16_SVE2(arm_compute::cpu::sve2_qsymm16_activation) |
| 77 | }, |
| 78 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 79 | "sve_fp16_activation", |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 80 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::F16 && data.isa.sve && data.isa.fp16 && data.f != ActivationLayerInfo::ActivationFunction::GELU; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 81 | REGISTER_FP16_SVE(arm_compute::cpu::sve_fp16_activation) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 82 | }, |
| 83 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 84 | "sve_fp32_activation", |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 85 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::F32 && data.isa.sve && data.f != ActivationLayerInfo::ActivationFunction::GELU; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 86 | REGISTER_FP32_SVE(arm_compute::cpu::sve_fp32_activation) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 87 | }, |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 88 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 89 | "neon_fp16_activation", |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 90 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::F16 && data.isa.fp16; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 91 | REGISTER_FP16_NEON(arm_compute::cpu::neon_fp16_activation) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 92 | }, |
| 93 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 94 | "neon_fp32_activation", |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 95 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::F32; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 96 | REGISTER_FP32_NEON(arm_compute::cpu::neon_fp32_activation) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 97 | }, |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 98 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 99 | "neon_qu8_activation", |
Viet-Hoa Do | b042e39 | 2022-06-21 15:56:15 +0100 | [diff] [blame] | 100 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::QASYMM8; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 101 | REGISTER_QASYMM8_NEON(arm_compute::cpu::neon_qasymm8_activation) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 102 | }, |
| 103 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 104 | "neon_qs8_activation", |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 105 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::QASYMM8_SIGNED; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 106 | REGISTER_QASYMM8_SIGNED_NEON(arm_compute::cpu::neon_qasymm8_signed_activation) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 107 | }, |
| 108 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 109 | "neon_qs16_activation", |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 110 | [](const ActivationDataTypeISASelectorData & data) { return data.dt == DataType::QSYMM16; }, |
Dana Zlotnik | 3229171 | 2021-11-25 09:58:27 +0200 | [diff] [blame] | 111 | REGISTER_QSYMM16_NEON(arm_compute::cpu::neon_qsymm16_activation) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 112 | }, |
| 113 | }; |
| 114 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 115 | /* Supported activation in the 8-bit integer domain */ |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 116 | static const std::array<ActivationLayerInfo::ActivationFunction, 8> qasymm8_activations = |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 117 | { |
| 118 | ActivationLayerInfo::ActivationFunction::RELU, |
| 119 | ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, |
| 120 | ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, |
| 121 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 122 | ActivationLayerInfo::ActivationFunction::TANH, |
| 123 | ActivationLayerInfo::ActivationFunction::HARD_SWISH, |
| 124 | ActivationLayerInfo::ActivationFunction::LEAKY_RELU, |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 125 | ActivationLayerInfo::ActivationFunction::GELU, |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 126 | }; |
| 127 | /* Supported activation in the 16-bit integer domain */ |
Pablo Marquez Tello | f55cca5 | 2022-04-06 14:31:25 +0100 | [diff] [blame] | 128 | static const std::array<ActivationLayerInfo::ActivationFunction, 4> qsymm16_activations = |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 129 | { |
| 130 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 131 | ActivationLayerInfo::ActivationFunction::TANH, |
Pablo Marquez Tello | f55cca5 | 2022-04-06 14:31:25 +0100 | [diff] [blame] | 132 | ActivationLayerInfo::ActivationFunction::HARD_SWISH, |
| 133 | ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 136 | Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst, const ActivationLayerInfo &activation_info) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 137 | { |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 138 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src); |
| 139 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::QASYMM8_SIGNED, DataType::QASYMM8, DataType::QSYMM16, DataType::F16, DataType::F32); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 140 | |
Pablo Marquez Tello | d158609 | 2022-06-10 14:37:10 +0100 | [diff] [blame] | 141 | const auto *uk = CpuActivationKernel::get_implementation(ActivationDataTypeISASelectorData{ src->data_type(), CPUInfo::get().get_cpu_model(), CPUInfo::get().get_isa(), activation_info.activation() }); |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 142 | ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr); |
| 143 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 144 | const DataType data_type = src->data_type(); |
| 145 | const QuantizationInfo &oq_info = (dst != nullptr) ? dst->quantization_info() : src->quantization_info(); |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 146 | const ActivationLayerInfo::ActivationFunction f_act = activation_info.activation(); |
| 147 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 148 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(is_data_type_quantized_asymmetric(data_type) && (std::find(std::begin(qasymm8_activations), std::end(qasymm8_activations), f_act) == std::end(qasymm8_activations)), |
Sang-Hoon Park | add8e81 | 2020-11-25 11:46:03 +0000 | [diff] [blame] | 149 | "For QASYMM8 only hard swish, leaky relu, tanh, logistic, relu and lower/upper bounded relu are supported"); |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 150 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 151 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(is_data_type_quantized_symmetric(data_type) && (std::find(std::begin(qsymm16_activations), std::end(qsymm16_activations), f_act) == std::end(qsymm16_activations)), |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 152 | "For QSYMM16 only tanh and logistic are supported"); |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 153 | ARM_COMPUTE_RETURN_ERROR_ON((data_type == DataType::QASYMM8 || data_type == DataType::QASYMM16) && (f_act == ActivationLayerInfo::ActivationFunction::TANH) |
| 154 | && (oq_info != QuantizationInfo(1.f / 128.f, 128))); |
| 155 | ARM_COMPUTE_RETURN_ERROR_ON((data_type == DataType::QASYMM8 || data_type == DataType::QASYMM16) && (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) |
| 156 | && (oq_info != QuantizationInfo(1.f / 256.f, 0))); |
| 157 | |
| 158 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8_SIGNED && (f_act == ActivationLayerInfo::ActivationFunction::TANH) && (oq_info != QuantizationInfo(1.f / 128.f, 0))); |
| 159 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8_SIGNED && (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) && (oq_info != QuantizationInfo(1.f / 256.f, -128))); |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 160 | |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 161 | ARM_COMPUTE_RETURN_ERROR_ON(is_data_type_quantized_symmetric(data_type) && (f_act == ActivationLayerInfo::ActivationFunction::TANH) && (oq_info != QuantizationInfo(1.f / 32768.f, 0))); |
| 162 | ARM_COMPUTE_RETURN_ERROR_ON(is_data_type_quantized_symmetric(data_type) && (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) && (oq_info != QuantizationInfo(1.f / 32768.f, 0))); |
| 163 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 164 | // Checks performed when dst is configured |
| 165 | if((dst != nullptr) && (dst->total_size() != 0)) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 166 | { |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 167 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(src, dst); |
| 168 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | return Status{}; |
| 172 | } |
| 173 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 174 | std::pair<Status, Window> validate_and_configure_window(const ITensorInfo *src, ITensorInfo *dst) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 175 | { |
Georgios Pinitas | 5a59453 | 2018-12-03 14:30:05 +0000 | [diff] [blame] | 176 | // Configure kernel window |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 177 | Window win = calculate_max_window(*src, Steps()); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 178 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 179 | if(dst != nullptr) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 180 | { |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 181 | // dst auto inizialitation if not yet initialized |
| 182 | auto_init_if_empty(*dst, *src->clone()); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Georgios Pinitas | 5a59453 | 2018-12-03 14:30:05 +0000 | [diff] [blame] | 185 | return std::make_pair(Status{}, win); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 186 | } |
| 187 | } // namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 188 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 189 | void CpuActivationKernel::configure(const ITensorInfo *src, ITensorInfo *dst, ActivationLayerInfo activation_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 190 | { |
Mohammed Suhail Munshi | fa79fda | 2022-09-20 11:49:23 +0100 | [diff] [blame] | 191 | ARM_COMPUTE_UNUSED(dst); |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 192 | ARM_COMPUTE_ERROR_ON_NULLPTR(src); |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 193 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, activation_info)); |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 194 | |
Pablo Marquez Tello | d158609 | 2022-06-10 14:37:10 +0100 | [diff] [blame] | 195 | const auto uk = CpuActivationKernel::get_implementation(ActivationDataTypeISASelectorData{ src->data_type(), CPUInfo::get().get_cpu_model(), CPUInfo::get().get_isa(), activation_info.activation() }); |
Mohammed Suhail Munshi | fa79fda | 2022-09-20 11:49:23 +0100 | [diff] [blame] | 196 | if(dst != nullptr) |
| 197 | { |
| 198 | // dst auto inizialitation if not yet initialized |
| 199 | auto_init_if_empty(*dst, *src->clone()); |
| 200 | } |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 201 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 202 | ARM_COMPUTE_ERROR_ON_NULLPTR(uk); |
| 203 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 204 | _run_method = uk->ukernel; |
| 205 | _name = std::string("CpuActivationKernel").append("/").append(uk->name); |
| 206 | |
Viet-Hoa Do | b042e39 | 2022-06-21 15:56:15 +0100 | [diff] [blame] | 207 | #ifdef __aarch64__ |
| 208 | if(ActivationLayerInfo::is_lut_supported(activation_info.activation(), src->data_type())) |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 209 | { |
Murray Kornelsen | 926f502 | 2022-07-13 21:22:39 -0400 | [diff] [blame] | 210 | activation_info.init_lut(src->data_type(), src->quantization_info().uniform(), (dst) ? dst->quantization_info().uniform() : src->quantization_info().uniform()); |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 211 | } |
Viet-Hoa Do | b042e39 | 2022-06-21 15:56:15 +0100 | [diff] [blame] | 212 | #endif // __aarch64__ |
Pablo Marquez Tello | d75cd8a | 2022-05-26 14:19:39 +0100 | [diff] [blame] | 213 | _act_info = activation_info; |
| 214 | |
Mohammed Suhail Munshi | fa79fda | 2022-09-20 11:49:23 +0100 | [diff] [blame] | 215 | Window win; |
| 216 | |
Viet-Hoa Do | 0a36f58 | 2022-10-18 15:23:46 +0100 | [diff] [blame] | 217 | // Use squashed window |
| 218 | std::tie(win, _split_dimension) = calculate_squashed_or_max_window(*src); |
| 219 | ICPPKernel::configure(win); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 222 | Status CpuActivationKernel::validate(const ITensorInfo *src, const ITensorInfo *dst, const ActivationLayerInfo &act_info) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 223 | { |
| 224 | ARM_COMPUTE_UNUSED(act_info); |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 225 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, act_info)); |
| 226 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), (dst != nullptr) ? dst->clone().get() : nullptr).first); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 227 | |
| 228 | return Status{}; |
| 229 | } |
| 230 | |
Dana Zlotnik | 4cdd6b8 | 2021-10-07 15:31:54 +0300 | [diff] [blame] | 231 | size_t CpuActivationKernel::get_mws(const CPUInfo &platform, size_t thread_count) const |
| 232 | { |
Dana Zlotnik | d7154db | 2021-11-10 11:50:58 +0200 | [diff] [blame] | 233 | ARM_COMPUTE_UNUSED(thread_count); |
Mohammed Suhail Munshi | 066607f | 2022-01-19 12:22:50 +0000 | [diff] [blame] | 234 | ARM_COMPUTE_UNUSED(platform); |
| 235 | |
Mohammed Suhail Munshi | 8307ecf | 2022-11-09 15:38:54 +0000 | [diff] [blame] | 236 | if(_split_dimension == Window::DimX) |
| 237 | { |
| 238 | // Don't split the work load too small if the tensor has been reinterpreted as 1D. |
| 239 | // This number is loosely chosen as threading overhead in each platform varies wildly. |
| 240 | return 1536; |
| 241 | } |
| 242 | return default_mws; |
Dana Zlotnik | 4cdd6b8 | 2021-10-07 15:31:54 +0300 | [diff] [blame] | 243 | } |
| 244 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 245 | void CpuActivationKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 246 | { |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 247 | // Early exit on disabled activation |
| 248 | if(!_act_info.enabled()) |
| 249 | { |
| 250 | return; |
| 251 | } |
| 252 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 253 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 254 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 255 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 256 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 257 | ARM_COMPUTE_ERROR_ON(tensors.empty()); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 258 | ARM_COMPUTE_ERROR_ON(_run_method == nullptr); |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 259 | |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 260 | const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC); |
| 261 | ITensor *dst = tensors.get_tensor(TensorType::ACL_DST); |
| 262 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 263 | _run_method(src, dst, _act_info, window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 264 | } |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 265 | |
| 266 | const char *CpuActivationKernel::name() const |
| 267 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 268 | return _name.c_str(); |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 269 | } |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 270 | |
| 271 | const std::vector<CpuActivationKernel::ActivationKernel> &CpuActivationKernel::get_available_kernels() |
| 272 | { |
| 273 | return available_kernels; |
| 274 | } |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 275 | } // namespace kernels |
| 276 | } // namespace cpu |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 277 | } // namespace arm_compute |