Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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 | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 24 | #include "src/core/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 | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 34 | #include "src/core/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 | { |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 46 | struct ActivationSelectorData |
| 47 | { |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 48 | DataType dt; |
| 49 | const CPUInfo &ci; |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | using ActivationSelectorPtr = std::add_pointer<bool(const ActivationSelectorData &data)>::type; |
| 53 | using ActivationKernelPtr = std::add_pointer<void(const ITensor *, ITensor *, const ActivationLayerInfo &, const Window &)>::type; |
| 54 | |
| 55 | struct ActivationKernel |
| 56 | { |
| 57 | const char *name; |
| 58 | const ActivationSelectorPtr is_selected; |
| 59 | ActivationKernelPtr ukernel; |
| 60 | }; |
| 61 | |
| 62 | static const ActivationKernel available_kernels[] = |
| 63 | { |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 64 | #if defined(ARM_COMPUTE_ENABLE_SVE) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 65 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 66 | "sve_fp16_activation", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 67 | [](const ActivationSelectorData & data) { return data.dt == DataType::F16 && data.ci.has_sve(); }, |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 68 | REGISTER_FP16_SVE(arm_compute::cpu::fp16_sve_activation) |
| 69 | }, |
| 70 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 71 | "sve_fp32_activation", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 72 | [](const ActivationSelectorData & data) { return data.dt == DataType::F32 && data.ci.has_sve(); }, |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 73 | REGISTER_FP32_SVE(arm_compute::cpu::fp32_sve_activation) |
| 74 | }, |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 75 | #endif /* defined(ARM_COMPUTE_ENABLE_SVE) */ |
| 76 | #if defined(ARM_COMPUTE_ENABLE_NEON) |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 77 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 78 | "neon_fp16_activation", |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 79 | [](const ActivationSelectorData & data) { return data.dt == DataType::F16; }, |
| 80 | REGISTER_FP16_NEON(arm_compute::cpu::fp16_neon_activation) |
| 81 | }, |
| 82 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 83 | "neon_fp32_activation", |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 84 | [](const ActivationSelectorData & data) { return data.dt == DataType::F32; }, |
| 85 | REGISTER_FP32_NEON(arm_compute::cpu::fp32_neon_activation) |
| 86 | }, |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 87 | #endif /* defined(ARM_COMPUTE_ENABLE_NEON) */ |
| 88 | #if defined(ARM_COMPUTE_ENABLE_SVE2) |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 89 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 90 | "sve_qu8_activation", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 91 | [](const ActivationSelectorData & data) { return data.dt == DataType::QASYMM8 && data.ci.has_sve2(); }, |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 92 | REGISTER_QASYMM8_SVE(arm_compute::cpu::qasymm8_sve_activation) |
| 93 | }, |
| 94 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 95 | "sve_qs8_activation", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 96 | [](const ActivationSelectorData & data) { return data.dt == DataType::QASYMM8_SIGNED && data.ci.has_sve2(); }, |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 97 | REGISTER_QASYMM8_SIGNED_SVE(arm_compute::cpu::qasymm8_signed_sve_activation) |
| 98 | }, |
| 99 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 100 | "sve_qs16_activation", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 101 | [](const ActivationSelectorData & data) { return data.dt == DataType::QSYMM16 && data.ci.has_sve2(); }, |
Michalis Spyrou | aa51a5b | 2020-11-22 00:49:42 +0000 | [diff] [blame] | 102 | REGISTER_QSYMM16_SVE(arm_compute::cpu::qsymm16_sve_activation) |
| 103 | }, |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 104 | #endif /* defined(ARM_COMPUTE_ENABLE_SVE2) */ |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 105 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 106 | "neon_qu8_activation", |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 107 | [](const ActivationSelectorData & data) { return data.dt == DataType::QASYMM8; }, |
| 108 | REGISTER_QASYMM8_NEON(arm_compute::cpu::qasymm8_neon_activation) |
| 109 | }, |
| 110 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 111 | "neon_qs8_activation", |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 112 | [](const ActivationSelectorData & data) { return data.dt == DataType::QASYMM8_SIGNED; }, |
| 113 | REGISTER_QASYMM8_SIGNED_NEON(arm_compute::cpu::qasymm8_signed_neon_activation) |
| 114 | }, |
| 115 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 116 | "neon_qs16_activation", |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 117 | [](const ActivationSelectorData & data) { return data.dt == DataType::QSYMM16; }, |
| 118 | REGISTER_QSYMM16_NEON(arm_compute::cpu::qsymm16_neon_activation) |
| 119 | }, |
| 120 | }; |
| 121 | |
| 122 | const ActivationKernel *get_implementation(const ActivationSelectorData &data) |
| 123 | { |
| 124 | for(const auto &uk : available_kernels) |
| 125 | { |
| 126 | if(uk.is_selected(data)) |
| 127 | { |
| 128 | return &uk; |
| 129 | } |
| 130 | } |
| 131 | return nullptr; |
| 132 | } |
| 133 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 134 | /* Supported activation in the 8-bit integer domain */ |
| 135 | static const std::array<ActivationLayerInfo::ActivationFunction, 7> qasymm8_activations = |
| 136 | { |
| 137 | ActivationLayerInfo::ActivationFunction::RELU, |
| 138 | ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, |
| 139 | ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, |
| 140 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 141 | ActivationLayerInfo::ActivationFunction::TANH, |
| 142 | ActivationLayerInfo::ActivationFunction::HARD_SWISH, |
| 143 | ActivationLayerInfo::ActivationFunction::LEAKY_RELU, |
| 144 | }; |
| 145 | /* Supported activation in the 16-bit integer domain */ |
| 146 | static const std::array<ActivationLayerInfo::ActivationFunction, 3> qsymm16_activations = |
| 147 | { |
| 148 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
| 149 | ActivationLayerInfo::ActivationFunction::TANH, |
| 150 | ActivationLayerInfo::ActivationFunction::HARD_SWISH |
| 151 | }; |
| 152 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 153 | 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] | 154 | { |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 155 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src); |
| 156 | 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] | 157 | |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 158 | const auto *uk = get_implementation(ActivationSelectorData{ src->data_type(), CPUInfo::get() }); |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 159 | ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr); |
| 160 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 161 | const DataType data_type = src->data_type(); |
| 162 | const QuantizationInfo &oq_info = (dst != nullptr) ? dst->quantization_info() : src->quantization_info(); |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 163 | const ActivationLayerInfo::ActivationFunction f_act = activation_info.activation(); |
| 164 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 165 | 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] | 166 | "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] | 167 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 168 | 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] | 169 | "For QSYMM16 only tanh and logistic are supported"); |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 170 | ARM_COMPUTE_RETURN_ERROR_ON((data_type == DataType::QASYMM8 || data_type == DataType::QASYMM16) && (f_act == ActivationLayerInfo::ActivationFunction::TANH) |
| 171 | && (oq_info != QuantizationInfo(1.f / 128.f, 128))); |
| 172 | ARM_COMPUTE_RETURN_ERROR_ON((data_type == DataType::QASYMM8 || data_type == DataType::QASYMM16) && (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) |
| 173 | && (oq_info != QuantizationInfo(1.f / 256.f, 0))); |
| 174 | |
| 175 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8_SIGNED && (f_act == ActivationLayerInfo::ActivationFunction::TANH) && (oq_info != QuantizationInfo(1.f / 128.f, 0))); |
| 176 | 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] | 177 | |
giuros01 | c9573f3 | 2019-06-20 10:30:17 +0100 | [diff] [blame] | 178 | 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))); |
| 179 | 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))); |
| 180 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 181 | // Checks performed when dst is configured |
| 182 | if((dst != nullptr) && (dst->total_size() != 0)) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 183 | { |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 184 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(src, dst); |
| 185 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return Status{}; |
| 189 | } |
| 190 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 191 | 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] | 192 | { |
Georgios Pinitas | 5a59453 | 2018-12-03 14:30:05 +0000 | [diff] [blame] | 193 | // Configure kernel window |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 194 | Window win = calculate_max_window(*src, Steps()); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 195 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 196 | if(dst != nullptr) |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 197 | { |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 198 | // dst auto inizialitation if not yet initialized |
| 199 | auto_init_if_empty(*dst, *src->clone()); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Georgios Pinitas | 5a59453 | 2018-12-03 14:30:05 +0000 | [diff] [blame] | 202 | return std::make_pair(Status{}, win); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 203 | } |
| 204 | } // namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 205 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 206 | void CpuActivationKernel::configure(const ITensorInfo *src, ITensorInfo *dst, ActivationLayerInfo activation_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 207 | { |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 208 | ARM_COMPUTE_ERROR_ON_NULLPTR(src); |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 209 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, activation_info)); |
Michel Iwaniec | 5dfeae6 | 2017-11-29 10:48:23 +0000 | [diff] [blame] | 210 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 211 | const auto uk = get_implementation(ActivationSelectorData{ src->data_type(), CPUInfo::get() }); |
| 212 | ARM_COMPUTE_ERROR_ON_NULLPTR(uk); |
| 213 | |
| 214 | _act_info = activation_info; |
| 215 | _run_method = uk->ukernel; |
| 216 | _name = std::string("CpuActivationKernel").append("/").append(uk->name); |
| 217 | |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 218 | // Configure kernel window |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 219 | auto win_config = validate_and_configure_window(src, dst); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 220 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 221 | ICPPKernel::configure(win_config.second); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 224 | 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] | 225 | { |
| 226 | ARM_COMPUTE_UNUSED(act_info); |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 227 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, act_info)); |
| 228 | 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] | 229 | |
| 230 | return Status{}; |
| 231 | } |
| 232 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 233 | void CpuActivationKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 234 | { |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 235 | // Early exit on disabled activation |
| 236 | if(!_act_info.enabled()) |
| 237 | { |
| 238 | return; |
| 239 | } |
| 240 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 241 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 242 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 243 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 244 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 245 | ARM_COMPUTE_ERROR_ON(tensors.empty()); |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 246 | ARM_COMPUTE_ERROR_ON(_run_method == nullptr); |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 247 | |
Michalis Spyrou | c4d4555 | 2020-10-19 12:41:30 +0100 | [diff] [blame] | 248 | const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC); |
| 249 | ITensor *dst = tensors.get_tensor(TensorType::ACL_DST); |
| 250 | |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 251 | _run_method(src, dst, _act_info, window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 252 | } |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 253 | |
| 254 | const char *CpuActivationKernel::name() const |
| 255 | { |
Georgios Pinitas | 5fdde99 | 2021-06-25 05:42:57 +0100 | [diff] [blame] | 256 | return _name.c_str(); |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 257 | } |
| 258 | } // namespace kernels |
| 259 | } // namespace cpu |
Michele Di Giorgio | f9b595a | 2020-07-03 13:34:52 +0100 | [diff] [blame] | 260 | } // namespace arm_compute |