Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 2023 Arm Limited. |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +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/gpu/cl/kernels/ClElementwiseKernel.h" |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/ICLTensor.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Utils.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/utils/ActivationFunctionUtils.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/utils/helpers/AdjustVecSize.h" |
| 31 | #include "arm_compute/core/utils/StringUtils.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | |
Georgios Pinitas | 8a5146f | 2021-01-12 15:51:07 +0000 | [diff] [blame] | 33 | #include "src/common/utils/Validate.h" |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 34 | #include "src/core/CL/CLValidate.h" |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 35 | #include "src/core/helpers/AutoConfiguration.h" |
| 36 | #include "src/core/helpers/WindowHelpers.h" |
| 37 | #include "support/Cast.h" |
| 38 | #include "support/StringSupport.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 39 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 40 | #include <map> |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | namespace opencl |
| 45 | { |
| 46 | namespace kernels |
| 47 | { |
| 48 | namespace |
| 49 | { |
| 50 | constexpr unsigned int vector_size_byte_opencl = 16; |
| 51 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 52 | std::map<ArithmeticOperation, std::string> supported_arithmetic_ops = { |
| 53 | {ArithmeticOperation::ADD, "ADD"}, {ArithmeticOperation::SUB, "SUB"}, |
| 54 | {ArithmeticOperation::DIV, "DIV"}, {ArithmeticOperation::SQUARED_DIFF, "SQUARED_DIFF"}, |
| 55 | {ArithmeticOperation::MIN, "MIN"}, {ArithmeticOperation::MAX, "MAX"}, |
| 56 | {ArithmeticOperation::POWER, "POWER"}, {ArithmeticOperation::PRELU, "PRELU"}, |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 59 | std::map<ArithmeticOperation, std::string> supported_sat_arithmetic_ops = { |
| 60 | {ArithmeticOperation::ADD, "ADD"}, |
| 61 | {ArithmeticOperation::SUB, "SUB"}, |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 64 | std::string |
| 65 | generate_id_for_tuning_common(const std::string &kernel_name, const ITensorInfo &src1, const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 66 | { |
| 67 | std::string config_id; |
| 68 | // Set config_id for enabling LWS tuning |
| 69 | config_id = kernel_name; |
| 70 | config_id += "_"; |
| 71 | config_id += lower_string(string_from_data_type(src1.data_type())); |
| 72 | config_id += "_"; |
| 73 | config_id += support::cpp11::to_string(dst.dimension(0)); |
| 74 | config_id += "_"; |
| 75 | config_id += support::cpp11::to_string(dst.dimension(1)); |
| 76 | return config_id; |
| 77 | } |
| 78 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 79 | Status validate_in_place_output_shape(const bool in_place, |
| 80 | const bool src1_in_place, |
| 81 | const ITensorInfo &src1, |
| 82 | const ITensorInfo &src2, |
| 83 | const ITensorInfo &dst, |
| 84 | const TensorShape &out_shape) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 85 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 86 | if (in_place) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 87 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 88 | ARM_COMPUTE_RETURN_ERROR_ON_MSG( |
| 89 | detail::have_different_dimensions(out_shape, src1_in_place ? src1.tensor_shape() : src2.tensor_shape(), 0), |
| 90 | "Wrong shape for dst, cannot do in_place calculation"); |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 91 | } |
| 92 | else |
| 93 | { |
| 94 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, dst.tensor_shape(), 0), |
| 95 | "Wrong shape for dst"); |
| 96 | } |
| 97 | return Status{}; |
| 98 | } |
| 99 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 100 | Status validate_arguments_with_float_only_supported_rules(const ITensorInfo &src1, |
| 101 | const ITensorInfo &src2, |
| 102 | const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 103 | { |
| 104 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(&src1, &src2, &dst); |
| 105 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&src1); |
| 106 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&src1, 1, DataType::F16, DataType::F32); |
| 107 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&src1, &src2); |
| 108 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 109 | // Check whether it is in_place calculation |
| 110 | const bool in_place = (&src1 == &dst) || (&src2 == &dst); |
| 111 | const bool src1_in_place = in_place && (&src1 == &dst); |
| 112 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 113 | const TensorShape out_shape = TensorShape::broadcast_shape(src1.tensor_shape(), src2.tensor_shape()); |
| 114 | |
| 115 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 116 | |
| 117 | // Validate in case of configured dst |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 118 | if (dst.total_size() > 0) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 119 | { |
| 120 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&dst, 1, DataType::F16, DataType::F32); |
| 121 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&src1, &dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 122 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 123 | validate_in_place_output_shape(in_place, src1_in_place, src1, src2, dst, out_shape)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | return Status{}; |
| 127 | } |
| 128 | |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 129 | Status validate_arguments_divide_operation(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst) |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 130 | { |
| 131 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src1, src2, dst); |
| 132 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(src1); |
| 133 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src1, 1, DataType::F16, DataType::F32, DataType::S32); |
| 134 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src1, src2); |
| 135 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 136 | // Check whether it is in_place calculation |
| 137 | const bool in_place = (src1 == dst) || (src2 == dst); |
| 138 | const bool src1_in_place = in_place && (src1 == dst); |
| 139 | |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 140 | const TensorShape out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape()); |
| 141 | |
| 142 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 143 | |
| 144 | // Validate in case of configured dst |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 145 | if (dst->total_size() > 0) |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 146 | { |
| 147 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dst, 1, DataType::F16, DataType::F32, DataType::S32); |
| 148 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src1, dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 149 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 150 | validate_in_place_output_shape(in_place, src1_in_place, *src1, *src2, *dst, out_shape)); |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | return Status{}; |
| 154 | } |
| 155 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 156 | Status |
| 157 | validate_arguments_with_arithmetic_rules(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 158 | { |
| 159 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(&src1); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 160 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&src1, 1, DataType::U8, DataType::QASYMM8, |
| 161 | DataType::QASYMM8_SIGNED, DataType::S16, DataType::QSYMM16, |
| 162 | DataType::F16, DataType::S32, DataType::F32); |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 163 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&src1, &src2); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 164 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 165 | if (is_data_type_quantized_symmetric(src1.data_type())) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 166 | { |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 167 | const int32_t in1_offset = src1.quantization_info().uniform().offset; |
| 168 | const int32_t in2_offset = src2.quantization_info().uniform().offset; |
| 169 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(in1_offset != 0, "For quantized symmetric, offset must be zero"); |
| 170 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(in2_offset != 0, "For quantized symmetric, offset must be zero"); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 173 | // Check whether it is in_place calculation |
| 174 | const bool in_place = (&src1 == &dst) || (&src2 == &dst); |
| 175 | const bool src1_in_place = in_place && (&src1 == &dst); |
| 176 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 177 | const TensorShape out_shape = TensorShape::broadcast_shape(src1.tensor_shape(), src2.tensor_shape()); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 178 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible"); |
| 179 | |
| 180 | // Validate in case of configured dst |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 181 | if (dst.total_size() > 0) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 182 | { |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 183 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(&src1, &dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 184 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, dst.tensor_shape(), 0), |
| 185 | "Wrong shape for dst"); |
| 186 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 187 | validate_in_place_output_shape(in_place, src1_in_place, src1, src2, dst, out_shape)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 188 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 189 | if (is_data_type_quantized_symmetric(dst.data_type())) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 190 | { |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 191 | const int32_t offset = dst.quantization_info().uniform().offset; |
| 192 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(offset != 0, "For quantized symmetric, offset must be zero"); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | return Status{}; |
| 196 | } |
| 197 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 198 | CLBuildOptions generate_build_options_with_arithmetic_rules(const ITensorInfo &src1, |
| 199 | const ITensorInfo &src2, |
| 200 | const ITensorInfo &dst, |
| 201 | const std::string &operation_string) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 202 | { |
| 203 | CLBuildOptions build_opts; |
| 204 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 205 | const unsigned int num_elems_processed_per_iteration = |
| 206 | adjust_vec_size(vector_size_byte_opencl / dst.element_size(), dst.dimension(0)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 207 | |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 208 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src1.data_type())); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 209 | build_opts.add_option("-DVEC_SIZE_IN1=" + |
| 210 | support::cpp11::to_string(src1.dimension(0) == 1 ? 1 : num_elems_processed_per_iteration)); |
| 211 | build_opts.add_option("-DVEC_SIZE_IN2=" + |
| 212 | support::cpp11::to_string(src2.dimension(0) == 1 ? 1 : num_elems_processed_per_iteration)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 213 | build_opts.add_option("-DVEC_SIZE_OUT=" + support::cpp11::to_string(num_elems_processed_per_iteration)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 214 | build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + |
| 215 | support::cpp11::to_string(dst.dimension(0) % num_elems_processed_per_iteration)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 216 | build_opts.add_option("-DOP=" + operation_string); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 217 | if (is_data_type_quantized(src1.data_type())) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 218 | { |
| 219 | const UniformQuantizationInfo iq1info = src1.quantization_info().uniform(); |
| 220 | const UniformQuantizationInfo iq2info = src2.quantization_info().uniform(); |
| 221 | const UniformQuantizationInfo oqinfo = dst.quantization_info().uniform(); |
| 222 | |
| 223 | build_opts.add_option("-DOFFSET_IN1=" + support::cpp11::to_string(iq1info.offset)); |
| 224 | build_opts.add_option("-DOFFSET_IN2=" + support::cpp11::to_string(iq2info.offset)); |
| 225 | build_opts.add_option("-DOFFSET_OUT=" + support::cpp11::to_string(oqinfo.offset)); |
| 226 | build_opts.add_option("-DSCALE_IN1=" + float_to_string_with_full_precision(iq1info.scale)); |
| 227 | build_opts.add_option("-DSCALE_IN2=" + float_to_string_with_full_precision(iq2info.scale)); |
| 228 | build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(oqinfo.scale)); |
| 229 | } |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 230 | build_opts.add_option_if(src1.data_type() == DataType::S32, "-DS32"); |
| 231 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 232 | // Check whether it is in_place calculation |
| 233 | const bool in_place = (&src1 == &dst) || (&src2 == &dst); |
| 234 | const bool src1_in_place = in_place && (&src1 == &dst); |
| 235 | build_opts.add_option_if(in_place, "-DIN_PLACE"); |
| 236 | build_opts.add_option_if(src1_in_place, "-DSRC1_IN_PLACE"); |
| 237 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 238 | return build_opts; |
| 239 | } |
| 240 | |
| 241 | std::pair<Status, Window> configure_window_arithmetic_common(ITensorInfo &dst) |
| 242 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 243 | const unsigned int num_elems_processed_per_iteration = |
| 244 | adjust_vec_size(vector_size_byte_opencl / dst.element_size(), dst.dimension(0)); |
| 245 | Window win = calculate_max_window(dst, Steps(num_elems_processed_per_iteration)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 246 | return std::make_pair(Status{}, win); |
| 247 | } |
| 248 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 249 | std::pair<Status, Window> |
| 250 | validate_and_configure_window_for_arithmetic_operators(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 251 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 252 | const std::pair<TensorShape, ValidRegion> broadcast_pair = |
| 253 | ITensorInfo::broadcast_shape_and_valid_region(src1, src2); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 254 | const TensorShape &out_shape = broadcast_pair.first; |
| 255 | |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 256 | auto_init_if_empty(dst, out_shape, 1, src1.data_type()); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 257 | |
| 258 | return configure_window_arithmetic_common(dst); |
| 259 | } |
| 260 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 261 | std::pair<Status, Window> |
| 262 | validate_and_configure_window_for_logical_binary_operators(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 263 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 264 | const std::pair<TensorShape, ValidRegion> broadcast_pair = |
| 265 | ITensorInfo::broadcast_shape_and_valid_region(src1, src2); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 266 | const TensorShape &out_shape = broadcast_pair.first; |
| 267 | |
| 268 | set_shape_if_empty(dst, out_shape); |
| 269 | set_data_type_if_unknown(dst, DataType::U8); |
| 270 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 271 | return configure_window_arithmetic_common(dst); |
| 272 | } |
| 273 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 274 | std::pair<Status, Window> |
| 275 | validate_and_configure_window_for_division(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 276 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 277 | const std::pair<TensorShape, ValidRegion> broadcast_pair = |
| 278 | ITensorInfo::broadcast_shape_and_valid_region(src1, src2); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 279 | const TensorShape &out_shape = broadcast_pair.first; |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 280 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 281 | auto_init_if_empty(dst, out_shape, 1, src1.data_type()); |
Georgios Pinitas | da81675 | 2021-07-02 09:22:14 +0100 | [diff] [blame] | 282 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 283 | return configure_window_arithmetic_common(dst); |
| 284 | } |
| 285 | } // namespace |
| 286 | |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 287 | ClElementwiseKernel::ClElementwiseKernel() |
| 288 | { |
| 289 | _type = CLKernelType::ELEMENTWISE; |
| 290 | } |
| 291 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 292 | void ClElementwiseKernel::configure_common(const ClCompileContext &compile_context, |
| 293 | ITensorInfo *src1, |
| 294 | ITensorInfo *src2, |
| 295 | ITensorInfo *dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 296 | { |
| 297 | // Configure kernel window |
| 298 | auto win_config = validate_and_configure_window(*src1, *src2, *dst); |
| 299 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 300 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 301 | std::string kernel_name = "elementwise_operation_" + name(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 302 | if (is_data_type_quantized(src1->data_type())) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 303 | { |
| 304 | kernel_name += "_quantized"; |
| 305 | } |
| 306 | |
| 307 | // Set kernel build options |
| 308 | CLBuildOptions build_opts = generate_build_options(*src1, *src2, *dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 309 | if (_act_info.enabled()) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 310 | { |
| 311 | build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(_act_info.activation()))); |
| 312 | build_opts.add_option("-DA_VAL=" + float_to_string_with_full_precision(_act_info.a())); |
| 313 | build_opts.add_option("-DB_VAL=" + float_to_string_with_full_precision(_act_info.b())); |
| 314 | } |
| 315 | |
| 316 | // Create kernel |
| 317 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
| 318 | |
| 319 | ICLKernel::configure_internal(win_config.second); |
| 320 | |
| 321 | _config_id = generate_id_for_tuning(kernel_name, *src1, *dst); |
| 322 | } |
| 323 | |
| 324 | void ClElementwiseKernel::run_op(ITensorPack &tensors, const Window &window, ::cl::CommandQueue &queue) |
| 325 | { |
| 326 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 327 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window); |
| 328 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 329 | const auto src_0 = |
| 330 | utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0)); |
| 331 | const auto src_1 = |
| 332 | utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1)); |
| 333 | auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 334 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 335 | ARM_COMPUTE_ERROR_ON_NULLPTR(src_0, src_1, dst); |
| 336 | |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 337 | const TensorShape &in_shape1 = src_0->info()->tensor_shape(); |
| 338 | const TensorShape &in_shape2 = src_1->info()->tensor_shape(); |
| 339 | const TensorShape &out_shape = dst->info()->tensor_shape(); |
| 340 | |
| 341 | bool can_collapse = true; |
| 342 | const bool is_vector = in_shape1.num_dimensions() == 1 || in_shape2.num_dimensions() == 1; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 343 | if (std::min(in_shape1.total_size(), in_shape2.total_size()) > 1 && !is_vector) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 344 | { |
| 345 | can_collapse = (std::min(in_shape1.num_dimensions(), in_shape2.num_dimensions()) > Window::DimZ); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 346 | for (size_t d = Window::DimZ; can_collapse && (d < out_shape.num_dimensions()); d++) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 347 | { |
| 348 | can_collapse = (in_shape1[d] == in_shape2[d]); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | bool has_collapsed = false; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 353 | Window collapsed = |
| 354 | can_collapse ? window.collapse_if_possible(ICLKernel::window(), Window::DimZ, &has_collapsed) : window; |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 355 | |
| 356 | const TensorShape &in_shape1_collapsed = has_collapsed ? in_shape1.collapsed_from(Window::DimZ) : in_shape1; |
| 357 | const TensorShape &in_shape2_collapsed = has_collapsed ? in_shape2.collapsed_from(Window::DimZ) : in_shape2; |
| 358 | |
| 359 | Window slice = collapsed.first_slice_window_3D(); |
| 360 | Window slice_src1 = slice.broadcast_if_dimension_le_one(in_shape1_collapsed); |
| 361 | Window slice_src2 = slice.broadcast_if_dimension_le_one(in_shape2_collapsed); |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 362 | |
| 363 | // Check whether it is in_place calculation |
| 364 | const bool in_place = (src_0 == dst) || (src_1 == dst); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 365 | do |
| 366 | { |
| 367 | unsigned int idx = 0; |
| 368 | add_3D_tensor_argument(idx, src_0, slice_src1); |
| 369 | add_3D_tensor_argument(idx, src_1, slice_src2); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 370 | if (!in_place) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 371 | { |
| 372 | add_3D_tensor_argument(idx, dst, slice); |
| 373 | } |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 374 | |
| 375 | enqueue(queue, *this, slice, lws_hint()); |
| 376 | ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_src1)); |
| 377 | ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_src2)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 378 | } while (collapsed.slide_window_slice_3D(slice)); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** Logical binary */ |
| 382 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 383 | void ClLogicalBinaryKernel::configure(const ClCompileContext &compile_context, |
| 384 | LogicalOperation op, |
| 385 | ITensorInfo *src1, |
| 386 | ITensorInfo *src2, |
| 387 | ITensorInfo *dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 388 | { |
| 389 | ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst); |
| 390 | ARM_COMPUTE_ERROR_THROW_ON(ClLogicalBinaryKernel::validate(op, src1, src2, dst)); |
| 391 | _op = op; |
| 392 | configure_common(compile_context, src1, src2, dst); |
| 393 | } |
| 394 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 395 | Status ClLogicalBinaryKernel::validate(LogicalOperation op, |
| 396 | const ITensorInfo *src1, |
| 397 | const ITensorInfo *src2, |
| 398 | const ITensorInfo *dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 399 | { |
| 400 | ARM_COMPUTE_UNUSED(op); |
| 401 | ARM_COMPUTE_ASSERT(op != LogicalOperation::Unknown && op != LogicalOperation::Not); |
| 402 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src1, src2, dst); |
| 403 | |
| 404 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src1, 1, DataType::U8); |
| 405 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src1, src2); |
| 406 | |
| 407 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*src1, *src2, *dst)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 408 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 409 | validate_and_configure_window_for_logical_binary_operators(*src1->clone(), *src2->clone(), *dst->clone()) |
| 410 | .first); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 411 | |
| 412 | return Status{}; |
| 413 | } |
| 414 | |
| 415 | std::string ClLogicalBinaryKernel::name() |
| 416 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 417 | switch (_op) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 418 | { |
| 419 | case LogicalOperation::And: |
| 420 | return "AND"; |
| 421 | case LogicalOperation::Or: |
| 422 | return "OR"; |
| 423 | case LogicalOperation::Not: |
| 424 | /* fall through */ |
| 425 | default: |
| 426 | ARM_COMPUTE_ASSERT(true); |
| 427 | } |
| 428 | return ""; |
| 429 | } |
| 430 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 431 | std::pair<Status, Window> |
| 432 | ClLogicalBinaryKernel::validate_and_configure_window(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 433 | { |
| 434 | return validate_and_configure_window_for_logical_binary_operators(src1, src2, dst); |
| 435 | } |
| 436 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 437 | CLBuildOptions |
| 438 | ClLogicalBinaryKernel::generate_build_options(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 439 | { |
| 440 | // The arithmetic utility functions can be share |
| 441 | return generate_build_options_with_arithmetic_rules(src1, src2, dst, name()); |
| 442 | } |
| 443 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 444 | std::string ClLogicalBinaryKernel::generate_id_for_tuning(const std::string &kernel_name, |
| 445 | const ITensorInfo &src1, |
| 446 | const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 447 | { |
| 448 | return generate_id_for_tuning_common(kernel_name, src1, dst); |
| 449 | } |
| 450 | |
| 451 | /** Arithmetic operations with saturation*/ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 452 | void ClSaturatedArithmeticKernel::configure(const ClCompileContext &compile_context, |
| 453 | ArithmeticOperation op, |
| 454 | ITensorInfo *input1, |
| 455 | ITensorInfo *input2, |
| 456 | ITensorInfo *output, |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 457 | const ConvertPolicy &policy, |
| 458 | const ActivationLayerInfo &act_info) |
| 459 | { |
| 460 | ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output); |
| 461 | ARM_COMPUTE_ERROR_THROW_ON(ClSaturatedArithmeticKernel::validate(op, input1, input2, output, policy, act_info)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 462 | auto padding_info = get_padding_info({input1, input2, output}); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 463 | |
| 464 | _policy = policy; |
| 465 | _op = op; |
| 466 | _act_info = act_info; |
| 467 | configure_common(compile_context, input1, input2, output); |
| 468 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
| 469 | } |
| 470 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 471 | Status ClSaturatedArithmeticKernel::validate(ArithmeticOperation op, |
| 472 | const ITensorInfo *input1, |
| 473 | const ITensorInfo *input2, |
| 474 | const ITensorInfo *output, |
| 475 | const ConvertPolicy &policy, |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 476 | const ActivationLayerInfo &act_info) |
| 477 | { |
| 478 | ARM_COMPUTE_UNUSED(op, policy); |
| 479 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); |
| 480 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*input1, *input2, *output)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 481 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 482 | validate_and_configure_window_for_arithmetic_operators(*input1->clone(), *input2->clone(), *output->clone()) |
| 483 | .first); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 484 | ARM_COMPUTE_RETURN_ERROR_ON(act_info.enabled() && !is_data_type_float(output->data_type())); |
| 485 | |
| 486 | return Status{}; |
| 487 | } |
| 488 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 489 | std::pair<Status, Window> ClSaturatedArithmeticKernel::validate_and_configure_window(ITensorInfo &input1, |
| 490 | ITensorInfo &input2, |
| 491 | ITensorInfo &output) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 492 | { |
| 493 | return validate_and_configure_window_for_arithmetic_operators(input1, input2, output); |
| 494 | } |
| 495 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 496 | CLBuildOptions ClSaturatedArithmeticKernel::generate_build_options(const ITensorInfo &input1, |
| 497 | const ITensorInfo &input2, |
| 498 | const ITensorInfo &output) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 499 | { |
| 500 | const bool has_float_out = is_data_type_float(output.data_type()); |
| 501 | auto build_options = generate_build_options_with_arithmetic_rules(input1, input2, output, name()); |
| 502 | build_options.add_option((_policy == ConvertPolicy::WRAP || has_float_out) ? "-DWRAP" : "-DSATURATE"); |
| 503 | return build_options; |
| 504 | } |
| 505 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 506 | std::string ClSaturatedArithmeticKernel::generate_id_for_tuning(const std::string &kernel_name, |
| 507 | const ITensorInfo &input1, |
| 508 | const ITensorInfo &output) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 509 | { |
| 510 | auto config_id = generate_id_for_tuning_common(kernel_name, input1, output); |
| 511 | config_id += (_policy == ConvertPolicy::WRAP) ? "_wrap_" : "_saturate_"; |
| 512 | config_id += lower_string(string_from_data_layout(input1.data_layout())); |
| 513 | return config_id; |
| 514 | } |
| 515 | |
| 516 | std::string ClSaturatedArithmeticKernel::name() |
| 517 | { |
| 518 | return supported_sat_arithmetic_ops[_op]; |
| 519 | } |
| 520 | |
| 521 | /** Arithmetic operations*/ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 522 | void ClArithmeticKernel::configure(const ClCompileContext &compile_context, |
| 523 | ArithmeticOperation op, |
| 524 | ITensorInfo *src1, |
| 525 | ITensorInfo *src2, |
| 526 | ITensorInfo *dst, |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 527 | const ActivationLayerInfo &act_info) |
| 528 | { |
| 529 | ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst); |
| 530 | ARM_COMPUTE_ERROR_THROW_ON(ClArithmeticKernel::validate(op, src1, src2, dst, act_info)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 531 | auto padding_info = get_padding_info({src1, src2, dst}); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 532 | |
| 533 | _op = op; |
| 534 | _act_info = act_info; |
| 535 | configure_common(compile_context, src1, src2, dst); |
| 536 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
| 537 | } |
| 538 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 539 | Status ClArithmeticKernel::validate(ArithmeticOperation op, |
| 540 | const ITensorInfo *src1, |
| 541 | const ITensorInfo *src2, |
| 542 | const ITensorInfo *dst, |
| 543 | const ActivationLayerInfo &act_info) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 544 | { |
| 545 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src1, src2, dst); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 546 | if (op == ArithmeticOperation::DIV) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 547 | { |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 548 | // Partial integer support S32/F32/F16 |
| 549 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_divide_operation(src1, src2, dst)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 550 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 551 | validate_and_configure_window_for_division(*src1->clone(), *src2->clone(), *dst->clone()).first); |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 552 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 553 | else if (op == ArithmeticOperation::POWER) |
Suhail Munshi | ae1c9fe | 2021-04-14 12:16:49 +0100 | [diff] [blame] | 554 | { |
| 555 | // Power operators doesn't support integer arithmetic |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 556 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_float_only_supported_rules(*src1, *src2, *dst)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 557 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 558 | validate_and_configure_window_for_division(*src1->clone(), *src2->clone(), *dst->clone()).first); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 559 | } |
| 560 | else |
| 561 | { |
| 562 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*src1, *src2, *dst)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 563 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 564 | validate_and_configure_window_for_arithmetic_operators(*src1->clone(), *src2->clone(), *dst->clone()) |
| 565 | .first); |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 566 | } |
| 567 | ARM_COMPUTE_RETURN_ERROR_ON(act_info.enabled() && !is_data_type_float(dst->data_type())); |
| 568 | |
| 569 | return Status{}; |
| 570 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 571 | std::pair<Status, Window> |
| 572 | ClArithmeticKernel::validate_and_configure_window(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 573 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 574 | if (_op == ArithmeticOperation::DIV || _op == ArithmeticOperation::POWER) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 575 | { |
| 576 | // Division and Power operators don't support integer arithmetic |
| 577 | return validate_and_configure_window_for_division(src1, src2, dst); |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | return validate_and_configure_window_for_arithmetic_operators(src1, src2, dst); |
| 582 | } |
| 583 | } |
| 584 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 585 | CLBuildOptions |
| 586 | ClArithmeticKernel::generate_build_options(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 587 | { |
| 588 | return generate_build_options_with_arithmetic_rules(src1, src2, dst, name()); |
| 589 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 590 | std::string ClArithmeticKernel::generate_id_for_tuning(const std::string &kernel_name, |
| 591 | const ITensorInfo &src1, |
| 592 | const ITensorInfo &dst) |
Michele Di Giorgio | 1e0208a | 2021-01-22 15:42:59 +0000 | [diff] [blame] | 593 | { |
| 594 | return generate_id_for_tuning_common(kernel_name, src1, dst); |
| 595 | } |
| 596 | |
| 597 | std::string ClArithmeticKernel::name() |
| 598 | { |
| 599 | return supported_arithmetic_ops[_op]; |
| 600 | } |
| 601 | } // namespace kernels |
| 602 | } // namespace opencl |
| 603 | } // namespace arm_compute |