Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 Arm Limited. |
| 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 | */ |
Jakub Sujak | 1ed6a14 | 2023-04-13 21:14:42 +0100 | [diff] [blame] | 24 | #include "src/gpu/cl/kernels/ClMatMulNativeKernel.h" |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/CL/ICLTensor.h" |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/ITensorPack.h" |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/TensorInfo.h" |
| 30 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 31 | |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 32 | #include "src/common/utils/Log.h" |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 33 | #include "src/core/CL/CLUtils.h" |
| 34 | #include "src/core/helpers/AutoConfiguration.h" |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 35 | #include "src/core/helpers/WindowHelpers.h" |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 36 | #include "src/gpu/cl/kernels/gemm/ClGemmHelpers.h" |
| 37 | |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 38 | #include "support/Cast.h" |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 39 | #include "support/StringSupport.h" |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace opencl |
| 44 | { |
| 45 | namespace kernels |
| 46 | { |
| 47 | namespace |
| 48 | { |
| 49 | Status validate_matmul_kernel_info(const MatMulKernelInfo &matmul_kernel_info) |
| 50 | { |
| 51 | const bool adj_lhs = matmul_kernel_info.adj_lhs; |
| 52 | const bool adj_rhs = matmul_kernel_info.adj_rhs; |
| 53 | const int m0 = matmul_kernel_info.m0; |
| 54 | const int n0 = matmul_kernel_info.n0; |
| 55 | const int k0 = matmul_kernel_info.k0; |
| 56 | |
| 57 | // Validate M0 |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 58 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(m0 < 1, "Only positive integers are supported for M0"); |
| 59 | |
| 60 | if(adj_lhs) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 61 | { |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 62 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(((m0 & (m0 - 1)) && (m0 != 3)) || (m0 > 16), "Only 1,2,3,4,8,16 are supported for M0 for Lhs transposed"); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Validate N0 |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 66 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(n0 < 1, "Only positive integers are supported for N0"); |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(((n0 & (n0 - 1)) && (n0 != 3)) || (n0 > 16), "Only 1,2,3,4,8,16 are supported for N0"); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 68 | |
| 69 | // Validate K0 |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 70 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(k0 < 1, "Only positive integers are supported for K0"); |
| 71 | if(!adj_lhs || adj_rhs) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 72 | { |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(((k0 & (k0 - 1)) && (k0 != 3)) || (k0 > 16), "Only 1,2,3,4,8,16 are supported for K0"); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 74 | } |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 75 | |
| 76 | return Status{}; |
| 77 | } |
| 78 | |
| 79 | Status validate_input_shapes(const TensorShape &lhs_shape, const TensorShape &rhs_shape, const MatMulKernelInfo &matmul_kernel_info) |
| 80 | { |
| 81 | const size_t lhs_k = matmul_kernel_info.adj_lhs ? lhs_shape.y() : lhs_shape.x(); |
| 82 | const size_t rhs_k = matmul_kernel_info.adj_rhs ? rhs_shape.x() : rhs_shape.y(); |
| 83 | |
| 84 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(lhs_k != rhs_k, "K dimension in Lhs and Rhs matrices must match."); |
| 85 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(lhs_shape.total_size() == 0, "Lhs tensor can't be empty"); |
| 86 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(rhs_shape.total_size() == 0, "Rhs tensor can't be empty"); |
| 87 | |
| 88 | constexpr size_t batch_dim_start = 2; |
| 89 | for(size_t i = batch_dim_start; i < Coordinates::num_max_dimensions; ++i) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 90 | { |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 91 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(lhs_shape[i] != rhs_shape[i], "Batch dimension broadcasting is not supported"); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | return Status{}; |
| 95 | } |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 96 | |
| 97 | Status validate_export_to_cl_image(const ITensorInfo *rhs, const MatMulKernelInfo &matmul_kernel_info) |
| 98 | { |
| 99 | ARM_COMPUTE_RETURN_ERROR_ON(matmul_kernel_info.export_rhs_to_cl_image && rhs->lock_paddings()); |
| 100 | if(matmul_kernel_info.export_rhs_to_cl_image) |
| 101 | { |
| 102 | if(matmul_kernel_info.adj_rhs) |
| 103 | { |
| 104 | const int k0 = matmul_kernel_info.k0; |
| 105 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(k0 != 4 && k0 != 8 && k0 != 16, "K0 can only be: 4, 8, and 16 for Rhs transposed"); |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | const int n0 = matmul_kernel_info.n0; |
| 110 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(n0 != 4 && n0 != 8 && n0 != 16, "N0 can only be: 4, 8, and 16 for Rhs non-transposed"); |
| 111 | } |
| 112 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!export_to_cl_image(rhs), "Export to CLImage is not supported for this device/configuration"); |
| 113 | } |
| 114 | |
| 115 | return Status {}; |
| 116 | } |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 117 | } |
Jakub Sujak | 1ed6a14 | 2023-04-13 21:14:42 +0100 | [diff] [blame] | 118 | ClMatMulNativeKernel::ClMatMulNativeKernel() |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 119 | { |
| 120 | _type = CLKernelType::GEMM; |
| 121 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 122 | |
| 123 | Status ClMatMulNativeKernel::validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *dst, const MatMulKernelInfo &matmul_kernel_info) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 124 | { |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 125 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(lhs, rhs, dst); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 126 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(lhs, 1, DataType::F32, DataType::F16); |
| 127 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(lhs, rhs); |
| 128 | ARM_COMPUTE_RETURN_ON_ERROR(validate_matmul_kernel_info(matmul_kernel_info)); |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 129 | ARM_COMPUTE_RETURN_ON_ERROR(validate_input_shapes(lhs->tensor_shape(), rhs->tensor_shape(), matmul_kernel_info)); |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 130 | ARM_COMPUTE_RETURN_ON_ERROR(validate_export_to_cl_image(rhs, matmul_kernel_info)); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 131 | |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 132 | if(dst->total_size() != 0) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 133 | { |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 134 | const TensorInfo tensor_info_dst = dst->clone()->set_tensor_shape(misc::shape_calculator::compute_matmul_shape(lhs->tensor_shape(), rhs->tensor_shape(), matmul_kernel_info)); |
| 135 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(dst, &tensor_info_dst); |
| 136 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(lhs, dst); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 137 | } |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 138 | |
| 139 | return Status{}; |
| 140 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 141 | void ClMatMulNativeKernel::configure(const ClCompileContext &compile_context, ITensorInfo *lhs, ITensorInfo *rhs, ITensorInfo *dst, const MatMulKernelInfo &matmul_kernel_info) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 142 | { |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 143 | ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs, dst, &compile_context, &matmul_kernel_info); |
| 144 | ARM_COMPUTE_LOG_PARAMS(lhs, rhs, dst, matmul_kernel_info); |
| 145 | ARM_COMPUTE_ERROR_THROW_ON(validate(lhs, rhs, dst, matmul_kernel_info)); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 146 | |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 147 | // dst tensor auto initialization if not yet initialized |
| 148 | auto_init_if_empty(*dst, lhs->clone()->set_tensor_shape(misc::shape_calculator::compute_matmul_shape(lhs->tensor_shape(), rhs->tensor_shape(), matmul_kernel_info))); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 149 | |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 150 | const int m = dst->dimension(1); |
| 151 | const int n = dst->dimension(0); |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 152 | const int k = matmul_kernel_info.adj_lhs ? lhs->tensor_shape().y() : lhs->tensor_shape().x(); |
| 153 | const bool adj_lhs = matmul_kernel_info.adj_lhs; |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 154 | |
Gunes Bayir | 8918b23 | 2023-03-17 13:52:21 +0000 | [diff] [blame] | 155 | int m0 = adj_lhs ? adjust_vec_size(matmul_kernel_info.m0, m) : std::min(matmul_kernel_info.m0, m); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 156 | int n0 = adjust_vec_size(matmul_kernel_info.n0, n); |
| 157 | |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 158 | _export_rhs_to_cl_image = matmul_kernel_info.export_rhs_to_cl_image && !rhs->lock_paddings(); |
| 159 | |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 160 | // Configure kernel window |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 161 | Window win = calculate_max_window(*dst, Steps(n0, m0)); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 162 | win = win.collapse(win, Window::DimZ); |
| 163 | IClKernel::configure_internal(win); |
| 164 | |
| 165 | // Calculate partial (store instead of load) M0 and partial N0 for the partial blocks at the end of a row/column if any. This is to avoid padding. |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 166 | const unsigned int partial_store_m0 = m % m0; |
| 167 | const unsigned int partial_store_n0 = n % n0; |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 168 | |
| 169 | CLBuildOptions build_opts; |
| 170 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(lhs->data_type())); |
| 171 | build_opts.add_option("-DM0=" + support::cpp11::to_string(m0)); |
| 172 | build_opts.add_option("-DN0=" + support::cpp11::to_string(n0)); |
| 173 | build_opts.add_option("-DK0=" + support::cpp11::to_string(matmul_kernel_info.k0)); |
| 174 | build_opts.add_option("-DPARTIAL_STORE_M0=" + support::cpp11::to_string(partial_store_m0)); |
| 175 | build_opts.add_option("-DPARTIAL_STORE_N0=" + support::cpp11::to_string(partial_store_n0)); |
| 176 | build_opts.add_option("-DK=" + support::cpp11::to_string(k)); |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 177 | build_opts.add_option_if_else(_export_rhs_to_cl_image, "-DRHS_TENSOR_TYPE=IMAGE", "-DRHS_TENSOR_TYPE=BUFFER"); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 178 | |
| 179 | std::string kernel_name("mat_mul_native"); |
| 180 | kernel_name += matmul_kernel_info.adj_lhs ? "_t" : "_nt"; |
| 181 | kernel_name += matmul_kernel_info.adj_rhs ? "_t" : "_nt"; |
| 182 | |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 183 | // A macro guard to compile ONLY the kernel of interest |
| 184 | build_opts.add_option("-D" + upper_string(kernel_name)); |
| 185 | |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 186 | if(_export_rhs_to_cl_image) |
| 187 | { |
| 188 | gemm::update_padding_for_cl_image(rhs); |
| 189 | } |
| 190 | |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 191 | // Create kernel |
| 192 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
| 193 | |
| 194 | // Set config_id for enabling LWS tuning |
| 195 | _config_id = kernel_name; |
| 196 | _config_id += "_"; |
| 197 | _config_id += lower_string(string_from_data_type(lhs->data_type())); |
| 198 | _config_id += "_"; |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 199 | _config_id += support::cpp11::to_string(m); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 200 | _config_id += "_"; |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 201 | _config_id += support::cpp11::to_string(n); |
| 202 | _config_id += "_"; |
| 203 | _config_id += support::cpp11::to_string(k); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 204 | _config_id += "_"; |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 205 | _config_id += support::cpp11::to_string(dst->dimension(2)); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 206 | _config_id += "_"; |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 207 | _config_id += support::cpp11::to_string(_export_rhs_to_cl_image); |
| 208 | _config_id += "_"; |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 209 | _config_id += support::cpp11::to_string(m0); |
| 210 | _config_id += "_"; |
| 211 | _config_id += support::cpp11::to_string(n0); |
| 212 | _config_id += "_"; |
| 213 | _config_id += support::cpp11::to_string(matmul_kernel_info.k0); |
| 214 | } |
| 215 | |
Jakub Sujak | 1ed6a14 | 2023-04-13 21:14:42 +0100 | [diff] [blame] | 216 | void ClMatMulNativeKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 217 | { |
| 218 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 219 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window); |
| 220 | |
| 221 | const ICLTensor *lhs = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0)); |
| 222 | const ICLTensor *rhs = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1)); |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 223 | ICLTensor *dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST)); |
| 224 | ARM_COMPUTE_ERROR_ON_NULLPTR(lhs, rhs, dst); |
| 225 | ARM_COMPUTE_LOG_PARAMS(lhs, rhs, dst); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 226 | |
| 227 | unsigned int idx = 0; |
| 228 | Window window_collapsed = window.collapse(ICLKernel::window(), Window::DimZ); |
| 229 | |
| 230 | add_3d_tensor_nhw_argument(idx, lhs); |
Gunes Bayir | bbeef72 | 2023-03-20 10:19:10 +0000 | [diff] [blame] | 231 | |
| 232 | cl::Image2D rhs_cl_image; |
| 233 | if(_export_rhs_to_cl_image) |
| 234 | { |
| 235 | const size_t image_w = rhs->info()->dimension(0) / 4; |
| 236 | const size_t image_h = rhs->info()->tensor_shape().total_size() / rhs->info()->dimension(0); |
| 237 | const TensorShape shape2d(image_w, image_h); |
| 238 | const size_t image_row_pitch = rhs->info()->strides_in_bytes()[1]; |
| 239 | |
| 240 | // Export cl_buffer to cl_image |
| 241 | rhs_cl_image = create_image2d_from_buffer(CLKernelLibrary::get().context(), rhs->cl_buffer(), shape2d, rhs->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly); |
| 242 | _kernel.setArg(idx++, rhs_cl_image); |
| 243 | } |
| 244 | |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 245 | add_3d_tensor_nhw_argument(idx, rhs); |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame^] | 246 | add_3d_tensor_nhw_argument(idx, dst); |
Ramy Elgammal | 2b6ebfe | 2023-03-09 21:15:37 +0000 | [diff] [blame] | 247 | |
| 248 | enqueue(queue, *this, window_collapsed, lws_hint()); |
| 249 | } |
| 250 | |
| 251 | } // namespace kernels |
| 252 | } // namespace opencl |
| 253 | } // namespace arm_compute |