Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | 3cce35d | 2022-12-30 16:07:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2023 Arm Limited. |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +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 | */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 24 | #include "src/core/CL/kernels/CLDepthwiseConvolutionLayerNativeKernel.h" |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 25 | |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CL/ICLTensor.h" |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/TensorInfo.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/utils/ActivationFunctionUtils.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/utils/helpers/AdjustVecSize.h" |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 34 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 35 | #include "arm_compute/core/utils/StringUtils.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 36 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 37 | #include "src/core/CL/CLUtils.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 38 | #include "src/core/CL/CLValidate.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 39 | #include "src/core/CL/ICLKernel.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 40 | #include "src/core/helpers/AutoConfiguration.h" |
| 41 | #include "src/core/helpers/WindowHelpers.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 42 | #include "src/gpu/cl/kernels/gemm/ClGemmHelpers.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 43 | #include "support/StringSupport.h" |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 44 | |
| 45 | namespace arm_compute |
| 46 | { |
| 47 | namespace |
| 48 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 49 | Status validate_arguments(const ITensorInfo *input, |
| 50 | const ITensorInfo *weights, |
| 51 | const ITensorInfo *biases, |
| 52 | const ITensorInfo *output, |
| 53 | const DWCComputeKernelInfo &dwc_info, |
| 54 | const ConvolutionInfo &conv_info, |
| 55 | const ITensorInfo *output_multipliers, |
| 56 | const ITensorInfo *output_shifts) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 57 | { |
Gian Marco Iodice | c63b722 | 2021-06-30 08:39:44 +0000 | [diff] [blame] | 58 | ARM_COMPUTE_UNUSED(dwc_info); |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 59 | bool in_place = false; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 60 | if (output == nullptr || output == input) |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 61 | { |
| 62 | in_place = true; |
| 63 | output = input; |
| 64 | } |
| 65 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 66 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(input, DataLayout::NHWC); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 68 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, |
| 69 | DataType::F16, DataType::F32); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 70 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first > 1 && dwc_info.m0 != 1); |
| 71 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation.x() > 1 && dwc_info.m0 != 1); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 72 | ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_input_to_cl_image == true)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((dwc_info.export_weights_to_cl_image == true) && |
| 74 | (export_to_cl_image(weights) == false), |
| 75 | "Weights cannot be exported to cl_image!"); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 76 | ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_weights_to_cl_image == true) && ((dwc_info.n0 % 4) != 0)); |
| 77 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first < 1); |
| 78 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().second < 1); |
| 79 | ARM_COMPUTE_RETURN_ERROR_ON((conv_info.dilation.x() < 1) || (conv_info.dilation.y() < 1)); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 80 | const size_t idx_c = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL); |
| 81 | ARM_COMPUTE_UNUSED(idx_c); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 82 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_c) != (input->dimension(idx_c) * conv_info.depth_multiplier)); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 83 | |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 84 | // In place restrictions |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 85 | if (in_place) |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 86 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 87 | const int weights_width_idx = |
| 88 | get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::WIDTH); |
| 89 | const int weights_height_idx = |
| 90 | get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::HEIGHT); |
| 91 | ARM_COMPUTE_RETURN_ERROR_ON(weights->tensor_shape()[weights_width_idx] != 1U || |
| 92 | weights->tensor_shape()[weights_height_idx] != 1U); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 93 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.depth_multiplier != 1U); |
| 94 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride() != std::make_pair(1U, 1U)); |
| 95 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation != Size2D(1U, 1U)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 96 | ARM_COMPUTE_RETURN_ERROR_ON( |
| 97 | conv_info.pad_stride_info |
| 98 | .has_padding()); // Note that in princple padding can be supported with in_place but we choose not to support it |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 101 | const ConvolutionInfo info{conv_info.pad_stride_info, conv_info.depth_multiplier, ActivationLayerInfo(), |
| 102 | conv_info.dilation}; |
| 103 | const TensorShape output_shape = |
| 104 | arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 105 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 106 | if (conv_info.depth_multiplier > 1 && dwc_info.n0 > 1) |
Gian Marco Iodice | 211a55d | 2022-08-31 11:47:08 +0100 | [diff] [blame] | 107 | { |
| 108 | ARM_COMPUTE_RETURN_ERROR_ON((conv_info.depth_multiplier % dwc_info.n0) != 0); |
| 109 | } |
| 110 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 111 | const bool is_quantized = is_data_type_quantized(input->data_type()); |
| 112 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 113 | if (biases != nullptr) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 114 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 115 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != output_shape[idx_c]); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 116 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 117 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 118 | if (is_quantized) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 119 | { |
| 120 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 121 | } |
| 122 | else |
| 123 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 124 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, biases); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 125 | } |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 128 | if (is_quantized) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 129 | { |
| 130 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output_multipliers, output_shifts); |
| 131 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output_multipliers, 1, DataType::S32); |
| 132 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output_shifts, 1, DataType::S32); |
| 133 | ARM_COMPUTE_RETURN_ERROR_ON(output_multipliers->num_dimensions() > 1); |
| 134 | ARM_COMPUTE_RETURN_ERROR_ON(output_shifts->num_dimensions() > 1); |
| 135 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 136 | if (is_data_type_quantized_per_channel(weights->data_type())) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 137 | { |
| 138 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QSYMM8_PER_CHANNEL); |
| 139 | ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_multipliers->dimension(0)); |
| 140 | ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_shifts->dimension(0)); |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 145 | ARM_COMPUTE_RETURN_ERROR_ON(1 != output_multipliers->dimension(0)); |
| 146 | ARM_COMPUTE_RETURN_ERROR_ON(1 != output_shifts->dimension(0)); |
| 147 | } |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 152 | } |
| 153 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 154 | if (output->total_size() != 0) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 155 | { |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 156 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
Michele Di Giorgio | 4cd4cde | 2020-01-06 14:07:44 +0000 | [diff] [blame] | 157 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 160 | if (is_data_type_quantized(input->data_type())) |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 161 | { |
| 162 | const UniformQuantizationInfo iq_info = input->quantization_info().uniform(); |
| 163 | const UniformQuantizationInfo wq_info = weights->quantization_info().uniform(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 164 | const UniformQuantizationInfo oq_info = |
| 165 | (output->total_size() != 0) ? output->quantization_info().uniform() : iq_info; |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 166 | |
| 167 | float multiplier = iq_info.scale * wq_info.scale / oq_info.scale; |
| 168 | int output_multiplier = 0; |
| 169 | int output_shift = 0; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 170 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 171 | quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift)); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 174 | return Status{}; |
| 175 | } |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 176 | } // namespace |
| 177 | |
| 178 | CLDepthwiseConvolutionLayerNativeKernel::CLDepthwiseConvolutionLayerNativeKernel() |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 179 | : _input(nullptr), |
| 180 | _weights(nullptr), |
| 181 | _biases(nullptr), |
| 182 | _output(nullptr), |
| 183 | _depth_multiplier(1), |
| 184 | _output_multipliers(nullptr), |
| 185 | _output_shifts(nullptr), |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 186 | _export_input_to_cl_image(false), |
| 187 | _export_weights_to_cl_image(false), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 188 | _is_quantized(false) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 189 | { |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 190 | _type = CLKernelType::DEPTHWISE; |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 193 | void CLDepthwiseConvolutionLayerNativeKernel::configure(ICLTensor *input, |
| 194 | const ICLTensor *weights, |
| 195 | const ICLTensor *biases, |
| 196 | ICLTensor *output, |
| 197 | const DWCComputeKernelInfo &dwc_info, |
| 198 | const ConvolutionInfo &conv_info, |
| 199 | const ICLTensor *output_multipliers, |
| 200 | const ICLTensor *output_shifts) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 201 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 202 | configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, dwc_info, conv_info, |
| 203 | output_multipliers, output_shifts); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 206 | void CLDepthwiseConvolutionLayerNativeKernel::configure(const CLCompileContext &compile_context, |
| 207 | ICLTensor *input, |
| 208 | const ICLTensor *weights, |
| 209 | const ICLTensor *biases, |
| 210 | ICLTensor *output, |
| 211 | const DWCComputeKernelInfo &dwc_info, |
| 212 | const ConvolutionInfo &conv_info, |
| 213 | const ICLTensor *output_multipliers, |
| 214 | const ICLTensor *output_shifts) |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 215 | { |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 216 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 217 | if (output == nullptr) |
SiCongLi | bc4e311 | 2021-06-29 13:18:30 +0100 | [diff] [blame] | 218 | { |
| 219 | // In-place |
| 220 | output = input; |
| 221 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 222 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments( |
| 223 | input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), dwc_info, |
| 224 | conv_info, (output_multipliers != nullptr) ? output_multipliers->info() : nullptr, |
| 225 | (output_shifts != nullptr) ? output_shifts->info() : nullptr)); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 226 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 227 | auto padding_info = get_padding_info({input, output}); |
Giorgio Arena | 79acd77 | 2020-10-22 14:29:50 +0100 | [diff] [blame] | 228 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 229 | const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape( |
| 230 | *(input->info()), *(weights->info()), conv_info); |
| 231 | auto_init_if_empty(*(output->info()), input->info() |
| 232 | ->clone() |
| 233 | ->set_tensor_shape(output_shape) |
| 234 | .set_quantization_info(output->info()->quantization_info())); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 235 | |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 236 | _input = input; |
| 237 | _output = output; |
| 238 | _weights = weights; |
| 239 | _biases = biases; |
| 240 | _depth_multiplier = conv_info.depth_multiplier; |
| 241 | _output_multipliers = output_multipliers; |
| 242 | _output_shifts = output_shifts; |
| 243 | _export_input_to_cl_image = dwc_info.export_input_to_cl_image; |
| 244 | _export_weights_to_cl_image = dwc_info.export_weights_to_cl_image; |
| 245 | _is_quantized = is_data_type_quantized(input->info()->data_type()); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 246 | |
Gian Marco Iodice | 211a55d | 2022-08-31 11:47:08 +0100 | [diff] [blame] | 247 | const unsigned int n0 = adjust_vec_size(dwc_info.n0, output->info()->dimension(0)); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 248 | const unsigned int m0 = std::min(dwc_info.m0, (unsigned int)output->info()->dimension(1)); |
| 249 | std::string kernel_name = ""; |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 250 | |
| 251 | CLBuildOptions build_opts; |
Gian Marco Iodice | c63b722 | 2021-06-30 08:39:44 +0000 | [diff] [blame] | 252 | |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 253 | // Update the padding for the input/weights tensor if we can export to cl_image |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 254 | if (_export_input_to_cl_image) |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 255 | { |
| 256 | arm_compute::opencl::kernels::gemm::update_padding_for_cl_image(input->info()); |
| 257 | } |
| 258 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 259 | if (_export_weights_to_cl_image) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 260 | { |
| 261 | arm_compute::opencl::kernels::gemm::update_padding_for_cl_image(weights->info()); |
| 262 | } |
| 263 | |
Gian Marco Iodice | 1257131 | 2022-08-25 12:25:44 +0100 | [diff] [blame] | 264 | // Conditions of -cl-fast-relaxed-math causing accuracy issues can be traced from COMPMID-5324 |
Gunes Bayir | fdb5342 | 2022-05-25 10:09:39 +0100 | [diff] [blame] | 265 | const GPUTarget gpu_target = get_target(); |
| 266 | const auto act_function = conv_info.act_info.activation(); |
| 267 | const auto dst_data_type = _output->info()->data_type(); |
| 268 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 269 | if ((gpu_target != GPUTarget::G71 && (gpu_target & GPUTarget::GPU_ARCH_MASK) == GPUTarget::BIFROST) && |
| 270 | (act_function == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU || |
| 271 | act_function == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) && |
| 272 | (dst_data_type == DataType::F32 || dst_data_type == DataType::F16)) |
Gunes Bayir | fdb5342 | 2022-05-25 10:09:39 +0100 | [diff] [blame] | 273 | { |
| 274 | // -cl-fast-relaxed-math also sets -cl-finite-math-only and -cl-unsafe-math-optimizations |
| 275 | // to disable -cl-finite-math-only, we only include -cl-unsafe-math-optimizations |
| 276 | build_opts.add_option("-cl-unsafe-math-optimizations"); |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | build_opts.add_option("-cl-fast-relaxed-math"); |
| 281 | } |
| 282 | |
| 283 | build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_function))); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 284 | build_opts.add_option("-DDEPTH_MULTIPLIER=" + support::cpp11::to_string(conv_info.depth_multiplier)); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 285 | build_opts.add_option_if_else(_export_input_to_cl_image, "-DSRC_TENSOR_TYPE=IMAGE", "-DSRC_TENSOR_TYPE=BUFFER"); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 286 | // Note: SRC_DATA_TYPE must have the same data type of WEI_DATA_TYPE. In quantized, we could |
| 287 | // have a case where the data types for the activation and weights are different. However, since the implementation |
| 288 | // only works when both have same data type, we have to change the offset to take into account this aspect |
| 289 | build_opts.add_option("-DSRC_DATA_TYPE=" + get_cl_type_from_data_type(_input->info()->data_type())); |
| 290 | build_opts.add_option("-DDST_TENSOR_TYPE=BUFFER"); |
Gunes Bayir | fdb5342 | 2022-05-25 10:09:39 +0100 | [diff] [blame] | 291 | build_opts.add_option("-DDST_DATA_TYPE=" + get_cl_type_from_data_type(dst_data_type)); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 292 | build_opts.add_option_if_else(_export_weights_to_cl_image, "-DWEI_TENSOR_TYPE=IMAGE", "-DWEI_TENSOR_TYPE=BUFFER"); |
| 293 | build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(_input->info()->dimension(1))); |
| 294 | build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(_input->info()->dimension(2))); |
| 295 | build_opts.add_option("-DDST_WIDTH=" + support::cpp11::to_string(_output->info()->dimension(1))); |
| 296 | build_opts.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(_output->info()->dimension(2))); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 297 | build_opts.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(_weights->info()->dimension(1))); |
| 298 | build_opts.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(_weights->info()->dimension(2))); |
| 299 | build_opts.add_option("-DWEI_DATA_TYPE=" + get_cl_type_from_data_type(_weights->info()->data_type())); |
| 300 | build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_top())); |
| 301 | build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_left())); |
| 302 | build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().first)); |
| 303 | build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().second)); |
| 304 | build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(conv_info.dilation.x())); |
| 305 | build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(conv_info.dilation.y())); |
| 306 | build_opts.add_option("-DN0=" + support::cpp11::to_string(n0)); |
| 307 | build_opts.add_option("-DM0=" + support::cpp11::to_string(m0)); |
Gian Marco Iodice | 5e28181 | 2021-07-06 13:19:41 +0100 | [diff] [blame] | 308 | build_opts.add_option("-DM0_A=" + support::cpp11::to_string(_weights->info()->dimension(1) + m0 - 1)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 309 | build_opts.add_option_if_else(conv_info.depth_multiplier > 1, "-DN0_A=1", |
| 310 | "-DN0_A=" + support::cpp11::to_string(n0)); |
Gian Marco Iodice | 211a55d | 2022-08-31 11:47:08 +0100 | [diff] [blame] | 311 | build_opts.add_option("-DPARTIAL_N0=" + support::cpp11::to_string(_output->info()->dimension(0) % n0)); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 312 | build_opts.add_option_if(_input->info()->num_dimensions() > 3, "-DBATCHED_EXECUTION"); |
Gian Marco Iodice | 5e28181 | 2021-07-06 13:19:41 +0100 | [diff] [blame] | 313 | |
| 314 | // Force unroll with pragma when any of the following values exceed the maximum number of manual unroll |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 315 | set_unroll_with_pragma(build_opts, {static_cast<int>(_weights->info()->dimension(1) + m0 - 1), |
| 316 | static_cast<int>(_weights->info()->dimension(1)), |
| 317 | static_cast<int>(_weights->info()->dimension(2))}); |
Gian Marco Iodice | 5e28181 | 2021-07-06 13:19:41 +0100 | [diff] [blame] | 318 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 319 | if (biases != nullptr) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 320 | { |
| 321 | build_opts.add_option(std::string("-DHAS_BIAS")); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 322 | build_opts.add_option( |
| 323 | std::string("-DBIA_DATA_TYPE=" + get_cl_type_from_data_type(biases->info()->data_type()))); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 324 | } |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 325 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 326 | if (_is_quantized) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 327 | { |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 328 | kernel_name = "dwc_native_quantized_nhwc"; |
| 329 | const UniformQuantizationInfo iqinfo = input->info()->quantization_info().uniform(); |
| 330 | const UniformQuantizationInfo wqinfo = weights->info()->quantization_info().uniform(); |
| 331 | const UniformQuantizationInfo oqinfo = output->info()->quantization_info().uniform(); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 332 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 333 | PixelValue zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info()); |
| 334 | int zero_value_s32; |
| 335 | zero_value.get(zero_value_s32); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 336 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 337 | float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale; |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 338 | int output_multiplier = 0; |
| 339 | int output_shift = 0; |
| 340 | quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 341 | build_opts.add_option("-DDST_MULTIPLIER=" + support::cpp11::to_string(output_multiplier)); |
| 342 | build_opts.add_option("-DDST_SHIFT=" + support::cpp11::to_string(output_shift)); |
| 343 | build_opts.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(-iqinfo.offset)); |
| 344 | build_opts.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(-wqinfo.offset)); |
| 345 | build_opts.add_option("-DDST_OFFSET=" + support::cpp11::to_string(oqinfo.offset)); |
| 346 | build_opts.add_option("-DZERO_VALUE=" + support::cpp11::to_string(zero_value_s32)); |
| 347 | build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(DataType::S32)); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 348 | build_opts.add_option("-DDST_MULTIPLIERS_DATA_TYPE=" + |
| 349 | get_cl_type_from_data_type(_output_multipliers->info()->data_type())); |
| 350 | build_opts.add_option("-DDST_SHIFTS_DATA_TYPE=" + |
| 351 | get_cl_type_from_data_type(_output_shifts->info()->data_type())); |
| 352 | build_opts.add_option_if_else(weights->info()->data_type() == DataType::QSYMM8_PER_CHANNEL, |
| 353 | "-DQUANTIZATION_TYPE=PER_CHANNEL", "-DQUANTIZATION_TYPE=PER_TENSOR"); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 354 | // Note: We expect the input and output tensors to always adopt a per-tensor quantization approach |
| 355 | int a_val{}; |
| 356 | int b_val{}; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 357 | std::tie(b_val, a_val) = |
| 358 | get_quantized_activation_min_max(conv_info.act_info, input->info()->data_type(), oqinfo); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 359 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 360 | build_opts.add_option_if(conv_info.act_info.enabled(), "-DA_VAL=" + support::cpp11::to_string(a_val)); |
| 361 | build_opts.add_option_if(conv_info.act_info.enabled(), "-DB_VAL=" + support::cpp11::to_string(b_val)); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 365 | kernel_name = "dwc_native_fp_nhwc"; |
| 366 | build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 367 | build_opts.add_option_if(conv_info.act_info.enabled(), |
| 368 | "-DA_VAL=" + float_to_string_with_full_precision(conv_info.act_info.a())); |
| 369 | build_opts.add_option_if(conv_info.act_info.enabled(), |
| 370 | "-DB_VAL=" + float_to_string_with_full_precision(conv_info.act_info.b())); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 371 | } |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 372 | |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 373 | Window win = calculate_max_window(*(output->info()), Steps(n0, m0)); |
Giorgio Arena | 79acd77 | 2020-10-22 14:29:50 +0100 | [diff] [blame] | 374 | ICLKernel::configure_internal(win); |
| 375 | |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 376 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 377 | |
Giorgio Arena | 79acd77 | 2020-10-22 14:29:50 +0100 | [diff] [blame] | 378 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
| 379 | |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 380 | // Set config_id for enabling LWS tuning |
| 381 | _config_id = kernel_name; |
| 382 | _config_id += "_"; |
| 383 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 384 | _config_id += "_"; |
| 385 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 386 | _config_id += "_"; |
| 387 | _config_id += support::cpp11::to_string(input->info()->dimension(2)); |
| 388 | _config_id += "_"; |
| 389 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 390 | _config_id += "_"; |
| 391 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
| 392 | _config_id += "_"; |
| 393 | _config_id += support::cpp11::to_string(output->info()->dimension(2)); |
| 394 | _config_id += "_"; |
| 395 | _config_id += string_from_data_type(input->info()->data_type()); |
| 396 | } |
| 397 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 398 | Status CLDepthwiseConvolutionLayerNativeKernel::validate(const ITensorInfo *input, |
| 399 | const ITensorInfo *weights, |
| 400 | const ITensorInfo *biases, |
| 401 | const ITensorInfo *output, |
| 402 | const DWCComputeKernelInfo &dwc_info, |
| 403 | const ConvolutionInfo &conv_info, |
| 404 | const ITensorInfo *output_multipliers, |
| 405 | const ITensorInfo *output_shifts) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 406 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 407 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 408 | validate_arguments(input, weights, biases, output, dwc_info, conv_info, output_multipliers, output_shifts)); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 409 | return Status{}; |
| 410 | } |
| 411 | |
| 412 | void CLDepthwiseConvolutionLayerNativeKernel::run(const Window &window, cl::CommandQueue &queue) |
| 413 | { |
| 414 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 415 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 416 | |
| 417 | // Collapse window |
| 418 | Window window_collapsed = window.collapse(ICLKernel::window(), Window::DimZ); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 419 | |
| 420 | Window slice = window_collapsed.first_slice_window_4D(); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 421 | |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 422 | cl::Image2D input_cl_image; |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 423 | cl::Image2D weights_cl_image; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 424 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 425 | if (_export_input_to_cl_image || _export_weights_to_cl_image) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 426 | { |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 427 | // Export cl_buffer to cl_image |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 428 | if (_export_input_to_cl_image) |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 429 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 430 | const size_t image_w = _input->info()->dimension(0) / 4; |
| 431 | const size_t image_h = |
| 432 | _input->info()->dimension(1) * _input->info()->dimension(2) * _input->info()->dimension(3); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 433 | const TensorShape shape2d(image_w, image_h); |
| 434 | const size_t image_row_pitch = _input->info()->strides_in_bytes()[1]; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 435 | input_cl_image = |
| 436 | create_image2d_from_buffer(CLKernelLibrary::get().context(), _input->cl_buffer(), shape2d, |
| 437 | _input->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 440 | if (_export_weights_to_cl_image) |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 441 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 442 | const size_t image_w = _weights->info()->dimension(0) / 4; |
| 443 | const size_t image_h = |
| 444 | _weights->info()->dimension(1) * _weights->info()->dimension(2) * _weights->info()->dimension(3); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 445 | const TensorShape shape2d(image_w, image_h); |
| 446 | const size_t image_row_pitch = _weights->info()->strides_in_bytes()[1]; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 447 | weights_cl_image = |
| 448 | create_image2d_from_buffer(CLKernelLibrary::get().context(), _weights->cl_buffer(), shape2d, |
| 449 | _weights->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly); |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 450 | } |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | unsigned int idx = 0; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 454 | if (_export_input_to_cl_image) |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 455 | { |
| 456 | _kernel.setArg(idx++, input_cl_image); |
| 457 | } |
Sheri Zhang | e3b1974 | 2021-11-10 13:08:40 +0000 | [diff] [blame] | 458 | add_4d_tensor_nhwc_argument(idx, _input); |
| 459 | add_4d_tensor_nhwc_argument(idx, _output); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 460 | if (_export_weights_to_cl_image) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 461 | { |
| 462 | _kernel.setArg(idx++, weights_cl_image); |
| 463 | } |
Gian Marco Iodice | 3cce35d | 2022-12-30 16:07:45 +0000 | [diff] [blame] | 464 | add_4d_tensor_nhwc_argument(idx, _weights); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 465 | if (_is_quantized) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 466 | { |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 467 | add_1D_tensor_argument(idx, _output_multipliers, slice); |
| 468 | add_1D_tensor_argument(idx, _output_shifts, slice); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 469 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 470 | if (_biases != nullptr) |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 471 | { |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 472 | add_1D_tensor_argument(idx, _biases, slice); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 473 | } |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 474 | enqueue(queue, *this, slice, lws_hint()); |
Gian Marco Iodice | 9285adb | 2019-09-05 16:10:27 +0100 | [diff] [blame] | 475 | } |
| 476 | } // namespace arm_compute |