Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 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 | */ |
| 24 | #include "arm_compute/core/CL/kernels/CLActivationLayerKernel.h" |
| 25 | |
Pablo Tello | db8485a | 2019-09-24 11:03:47 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLCoreRuntimeContext.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/CLHelpers.h" |
Vidhya Sudhan Loganathan | f1f4906 | 2018-05-25 13:21:26 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CL/CLValidate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/CL/ICLTensor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/TensorInfo.h" |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/Types.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/Utils.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/Window.h" |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 34 | #include "arm_compute/core/utils/helpers/float_ops.h" |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 35 | #include "arm_compute/core/utils/misc/Cast.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 36 | #include "support/StringSupport.h" |
Georgios Pinitas | 00394ae | 2017-06-22 18:13:55 +0100 | [diff] [blame] | 37 | |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 38 | #include <set> |
Georgios Pinitas | 00394ae | 2017-06-22 18:13:55 +0100 | [diff] [blame] | 39 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 42 | namespace |
| 43 | { |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 44 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 45 | { |
Vidhya Sudhan Loganathan | f1f4906 | 2018-05-25 13:21:26 +0100 | [diff] [blame] | 46 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Michele Di Giorgio | f6f7876 | 2020-07-06 11:27:21 +0100 | [diff] [blame] | 47 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::QSYMM16, DataType::F16, DataType::F32); |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 48 | |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 49 | static std::set<ActivationLayerInfo::ActivationFunction> quantized_supported_activations = |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 50 | { |
| 51 | ActivationLayerInfo::ActivationFunction::RELU, |
| 52 | ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, |
| 53 | ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, |
| 54 | ActivationLayerInfo::ActivationFunction::LOGISTIC, |
morgolock | 6b3865a | 2020-03-04 14:57:46 +0000 | [diff] [blame] | 55 | ActivationLayerInfo::ActivationFunction::TANH, |
| 56 | ActivationLayerInfo::ActivationFunction::HARD_SWISH |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 57 | }; |
| 58 | const DataType data_type = input->data_type(); |
| 59 | const QuantizationInfo &oq_info = (output != nullptr) ? output->quantization_info() : input->quantization_info(); |
| 60 | const ActivationLayerInfo::ActivationFunction f_act = act_info.activation(); |
| 61 | |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 62 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(is_data_type_quantized(data_type) && (quantized_supported_activations.count(f_act) == 0), |
| 63 | "For Quantized data type only tanh, logistic, relu and lower/upper bounded relu are supported"); |
| 64 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8 && (f_act == ActivationLayerInfo::ActivationFunction::TANH) && (oq_info != QuantizationInfo(1.f / 128.f, 128))); |
| 66 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8 && (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) && (oq_info != QuantizationInfo(1.f / 256.f, 0))); |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 67 | |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 68 | 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))); |
| 69 | 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))); |
| 70 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 71 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8_SIGNED && (f_act == ActivationLayerInfo::ActivationFunction::TANH) && (oq_info != QuantizationInfo(1.f / 128.f, 0))); |
| 72 | ARM_COMPUTE_RETURN_ERROR_ON(data_type == DataType::QASYMM8_SIGNED && (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) && (oq_info != QuantizationInfo(1.f / 256.f, -128))); |
| 73 | |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 74 | // Checks performed when output is configured |
| 75 | if((output != nullptr) && (output->total_size() != 0)) |
| 76 | { |
| 77 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output); |
| 78 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 81 | return Status{}; |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 82 | } |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 83 | } // namespace |
| 84 | |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 85 | CLActivationLayerKernel::CLActivationLayerKernel() |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 86 | : _run_in_place(false) |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 87 | { |
| 88 | } |
| 89 | |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 90 | void CLActivationLayerKernel::configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *output, ActivationLayerInfo act_info) |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 91 | { |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 92 | ARM_COMPUTE_ERROR_ON_NULLPTR(input); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 93 | |
Michele Di Giorgio | dde9ec9 | 2018-02-13 15:24:04 +0000 | [diff] [blame] | 94 | _run_in_place = (output == nullptr) || (output == input); |
| 95 | |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 96 | if(output != nullptr) |
| 97 | { |
| 98 | // Output auto inizialitation if not yet initialized |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 99 | auto_init_if_empty(*output, *input->clone()); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 100 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 102 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, (output != nullptr) ? output : nullptr, act_info)); |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 103 | |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 104 | const unsigned int num_elems_processed_per_iteration = adjust_vec_size(16 / input->element_size(), input->dimension(0)); |
| 105 | |
| 106 | const DataType dt = input->data_type(); |
| 107 | float a_const = act_info.a(); |
| 108 | float b_const = act_info.b(); |
Georgios Pinitas | 05078ec | 2017-11-02 13:06:59 +0000 | [diff] [blame] | 109 | |
morgolock | 6b3865a | 2020-03-04 14:57:46 +0000 | [diff] [blame] | 110 | const ActivationLayerInfo::ActivationFunction f_act = act_info.activation(); |
| 111 | const bool is_quantized = is_data_type_quantized(dt); |
| 112 | const bool perform_activation_in_float = |
| 113 | (f_act == ActivationLayerInfo::ActivationFunction::LOGISTIC) || (f_act == ActivationLayerInfo::ActivationFunction::TANH) || (f_act == ActivationLayerInfo::ActivationFunction::HARD_SWISH); |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 114 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 115 | // Set build options |
Michele Di Giorgio | e5bf4c5 | 2019-02-14 17:47:33 +0000 | [diff] [blame] | 116 | CLBuildOptions build_opts; |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 117 | build_opts.add_option_if(perform_activation_in_float, "-DFLOAT_DOMAIN"); |
| 118 | build_opts.add_option_if(_run_in_place, "-DIN_PLACE"); |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 119 | build_opts.add_option("-DACT=" + lower_string(string_from_activation_func(f_act))); |
| 120 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(dt)); |
| 121 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration)); |
| 122 | build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(input->dimension(0) % num_elems_processed_per_iteration)); |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 123 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 124 | std::string kernel_name = std::string("activation_layer"); |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 125 | |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 126 | // Set quantization info build options |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 127 | if(is_quantized) |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 128 | { |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 129 | const UniformQuantizationInfo iq_info = input->quantization_info().uniform(); |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 130 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 131 | if(!perform_activation_in_float) |
| 132 | { |
| 133 | int a_const_int = 0; |
| 134 | int b_const_int = 0; |
| 135 | |
| 136 | // Create quantized version of constants a, b if needed |
| 137 | switch(dt) |
| 138 | { |
| 139 | case DataType::QASYMM8: |
| 140 | { |
| 141 | a_const_int = quantize_qasymm8(a_const, iq_info); |
| 142 | b_const_int = quantize_qasymm8(b_const, iq_info); |
| 143 | } |
| 144 | break; |
| 145 | case DataType::QASYMM8_SIGNED: |
| 146 | { |
| 147 | a_const_int = quantize_qasymm8_signed(a_const, iq_info); |
| 148 | b_const_int = quantize_qasymm8_signed(b_const, iq_info); |
| 149 | } |
| 150 | break; |
| 151 | case DataType::QSYMM16: |
| 152 | { |
| 153 | a_const_int = quantize_qsymm16(a_const, iq_info); |
| 154 | b_const_int = quantize_qsymm16(b_const, iq_info); |
| 155 | } |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | build_opts.add_option(("-DA_VAL=" + support::cpp11::to_string(a_const_int))); |
| 161 | build_opts.add_option(("-DB_VAL=" + support::cpp11::to_string(b_const_int))); |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | build_opts.add_option(("-DA_VAL=" + float_to_string_with_full_precision(a_const))); |
| 166 | build_opts.add_option(("-DB_VAL=" + float_to_string_with_full_precision(b_const))); |
| 167 | } |
| 168 | |
Michele Di Giorgio | dde9ec9 | 2018-02-13 15:24:04 +0000 | [diff] [blame] | 169 | // Quantized value of 0 corresponds to the offset o1 |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 170 | build_opts.add_option(("-DCONST_0=" + (is_data_type_quantized_asymmetric(dt) ? support::cpp11::to_string(iq_info.offset) : "0"))); |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 171 | build_opts.add_option(("-DS1_VAL=" + float_to_string_with_full_precision(iq_info.scale))); |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 172 | build_opts.add_option_if(is_data_type_quantized_asymmetric(dt), "-DO1_VAL=" + support::cpp11::to_string(iq_info.offset)); |
Michele Di Giorgio | dde9ec9 | 2018-02-13 15:24:04 +0000 | [diff] [blame] | 173 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 174 | // Set correct kernel name |
| 175 | kernel_name += perform_activation_in_float ? std::string("_quant_f32") : std::string("_quant"); |
| 176 | |
Giorgio Arena | a0d1183 | 2018-01-17 16:13:46 +0000 | [diff] [blame] | 177 | // Set scale and offset of the input and output if they have different quantization info |
Georgios Pinitas | 4b3fba1 | 2019-06-04 17:31:46 +0100 | [diff] [blame] | 178 | if(output != nullptr) |
Georgios Pinitas | 05078ec | 2017-11-02 13:06:59 +0000 | [diff] [blame] | 179 | { |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 180 | const UniformQuantizationInfo oq_info = output->quantization_info().uniform(); |
Giorgio Arena | a0d1183 | 2018-01-17 16:13:46 +0000 | [diff] [blame] | 181 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 182 | if(iq_info != oq_info) |
Giorgio Arena | a0d1183 | 2018-01-17 16:13:46 +0000 | [diff] [blame] | 183 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 184 | build_opts.add_option(("-DS2_VAL=" + float_to_string_with_full_precision(oq_info.scale))); |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 185 | build_opts.add_option_if(is_data_type_quantized_asymmetric(dt), "-DO2_VAL=" + support::cpp11::to_string(oq_info.offset)); |
Giorgio Arena | a0d1183 | 2018-01-17 16:13:46 +0000 | [diff] [blame] | 186 | } |
Georgios Pinitas | 05078ec | 2017-11-02 13:06:59 +0000 | [diff] [blame] | 187 | } |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 188 | } |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 189 | else |
Michele Di Giorgio | e5bf4c5 | 2019-02-14 17:47:33 +0000 | [diff] [blame] | 190 | { |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 191 | // Set A, B constants in build options for float types |
| 192 | build_opts.add_option(("-DA_VAL=" + float_to_string_with_full_precision(a_const))); |
| 193 | build_opts.add_option(("-DB_VAL=" + float_to_string_with_full_precision(b_const))); |
Michele Di Giorgio | e5bf4c5 | 2019-02-14 17:47:33 +0000 | [diff] [blame] | 194 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 195 | |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 196 | // Create kernel |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 197 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
| 198 | |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 199 | // Configure kernel window |
Giorgio Arena | d304adb | 2020-10-02 10:20:11 +0100 | [diff] [blame] | 200 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
| 201 | ICLKernel::configure_internal(win); |
Giorgio Arena | 63485ce | 2017-11-15 16:04:20 +0000 | [diff] [blame] | 202 | |
| 203 | // Set config_id for enabling LWS tuning |
| 204 | _config_id = "activation_layer_"; |
| 205 | _config_id += lower_string(string_from_data_type(dt)); |
| 206 | _config_id += "_"; |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 207 | _config_id += support::cpp11::to_string(input->dimension(0)); |
Giorgio Arena | 63485ce | 2017-11-15 16:04:20 +0000 | [diff] [blame] | 208 | _config_id += "_"; |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 209 | _config_id += support::cpp11::to_string(input->dimension(1)); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 212 | Status CLActivationLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info) |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 213 | { |
Giorgio Arena | 2995f5b | 2017-11-29 17:33:59 +0000 | [diff] [blame] | 214 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, act_info)); |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 215 | return Status{}; |
Georgios Pinitas | f9d3a0a | 2017-11-03 19:01:44 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 218 | void CLActivationLayerKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 219 | { |
| 220 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 221 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window); |
| 222 | |
Georgios Pinitas | 0499dff | 2020-07-31 22:21:38 +0100 | [diff] [blame] | 223 | const auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC)); |
| 224 | auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST)); |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 225 | ARM_COMPUTE_ERROR_ON(_run_in_place && src != dst); |
| 226 | |
Anthony Barbier | be35b0e | 2017-07-11 18:13:08 +0100 | [diff] [blame] | 227 | Window collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); |
| 228 | Window slice = collapsed.first_slice_window_3D(); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 229 | |
| 230 | do |
| 231 | { |
| 232 | unsigned int idx = 0; |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 233 | add_3D_tensor_argument(idx, src, slice); |
Michele Di Giorgio | dde9ec9 | 2018-02-13 15:24:04 +0000 | [diff] [blame] | 234 | if(!_run_in_place) |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 235 | { |
Georgios Pinitas | ab23dd0 | 2020-07-06 14:57:36 +0100 | [diff] [blame] | 236 | add_3D_tensor_argument(idx, dst, slice); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 237 | } |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 238 | enqueue(queue, *this, slice, lws_hint()); |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 239 | } |
Anthony Barbier | be35b0e | 2017-07-11 18:13:08 +0100 | [diff] [blame] | 240 | while(collapsed.slide_window_slice_3D(slice)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 241 | } |
Michele Di Giorgio | cbbed28 | 2019-12-20 13:26:08 +0000 | [diff] [blame] | 242 | } // namespace arm_compute |