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