Compute Library
 23.08
ClGemmMatrixMultiplyReshapedOnlyRhsKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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  */
25 
30 #include "src/core/CL/CLUtils.h"
31 #include "src/core/CL/CLValidate.h"
37 #include "support/Cast.h"
38 #include "support/StringSupport.h"
39 
40 namespace arm_compute
41 {
42 namespace opencl
43 {
44 namespace kernels
45 {
46 namespace
47 {
48 using ElementsProcessed = Steps;
49 
50 const auto post_op_utils = experimental::PostOpCLKernelUtils(
51 {
52  // PostOp sequence -> {Kernel Postfix, PostOp Slots}
53  { {}, { "", {} } },
54  { { experimental::PostOpType::Activation }, { "", { 1 } } },
55 
56  { { experimental::PostOpType::Eltwise_Add }, { "_post_act_eltwise_op_act", { 2 } } },
57  { { experimental::PostOpType::Eltwise_PRelu }, { "_post_act_eltwise_op_act", { 2 } } },
58 
59  { { experimental::PostOpType::Activation, experimental::PostOpType::Eltwise_Add }, { "_post_act_eltwise_op_act", { 1, 2 } } },
60  { { experimental::PostOpType::Activation, experimental::PostOpType::Eltwise_PRelu }, { "_post_act_eltwise_op_act", { 1, 2 } } },
61 
62  { { experimental::PostOpType::Eltwise_Add, experimental::PostOpType::Activation }, { "_post_act_eltwise_op_act", { 2, 3 } } },
63  { { experimental::PostOpType::Eltwise_PRelu, experimental::PostOpType::Activation }, { "_post_act_eltwise_op_act", { 2, 3 } } },
64 
67 });
68 
69 Status validate_arguments(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float alpha, float beta,
70  const GEMMLHSMatrixInfo &lhs_info, const GEMMRHSMatrixInfo &rhs_info, const GEMMKernelInfo &gemm_info)
71 {
72  ARM_COMPUTE_UNUSED(alpha);
77  ARM_COMPUTE_RETURN_ERROR_ON_MSG(src0->num_dimensions() > 4, "The number of dimensions for the LHS matrix must be <= 4");
78  ARM_COMPUTE_RETURN_ERROR_ON_MSG(src1->num_dimensions() > 3, "The number of dimensions for the RHS matrix must be <= 3");
79  ARM_COMPUTE_RETURN_ERROR_ON_MSG(lhs_info.m0 < 1 || lhs_info.m0 > 8, "Only 1,2,3,4,5,6,7,8 are supported for m0");
81  ARM_COMPUTE_RETURN_ERROR_ON_MSG(((rhs_info.k0 & (rhs_info.k0 - 1)) && rhs_info.k0 != 3), "Only 2,3,4,8,16 are supported for k0");
83  ARM_COMPUTE_RETURN_ERROR_ON_MSG(((rhs_info.n0 & (rhs_info.n0 - 1)) && rhs_info.n0 != 3), "Only 2,3,4,8,16 are supported for n0");
84  ARM_COMPUTE_RETURN_ERROR_ON_MSG((gemm_info.reinterpret_input_as_3d || gemm_info.depth_output_gemm3d != 0) && (src2 != nullptr)
85  && (!gemm_info.broadcast_bias),
86  "Bias addition only supported with broadcast mode in case the input or dst has to be reinterpreted as 3D");
87  ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.fp_mixed_precision, "Mixed precision not supported");
89  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!post_op_utils.is_post_op_sequence_supported(gemm_info.post_ops), "The sequence of Post Ops is not supported");
90 
91  const unsigned int m = gemm_info.m;
92  const unsigned int n = gemm_info.n;
93  const unsigned int k = gemm_info.k;
94 
95  TensorShape tensor_shape1{ src1->tensor_shape() };
96  tensor_shape1.set(0, n);
97  tensor_shape1.set(1, k);
98 
99  if(src2 != nullptr && !(helpers::float_ops::is_zero(beta)))
100  {
101  const unsigned int src2_dim0 = src2->dimension(0);
102  const unsigned int src2_dim1 = src2->dimension(1);
103 
105  if(gemm_info.broadcast_bias)
106  {
107  ARM_COMPUTE_RETURN_ERROR_ON_MSG((src2_dim1 != 1 || src2_dim0 != n), "Incorrect dimension of bias matrix which is to be broadcasted");
108  }
109  else
110  {
111  ARM_COMPUTE_RETURN_ERROR_ON_MSG((src2_dim0 != n || src2_dim1 != m), "Incorrect dimension of bias matrix");
112  }
113  }
114 
115  const TensorInfo tensor_info1 = src1->clone()->set_tensor_shape(tensor_shape1);
116 
117  const TensorInfo tensor_info_reshaped1 = src1->clone()->set_tensor_shape(misc::shape_calculator::compute_rhs_reshaped_shape(tensor_info1, rhs_info));
118 
119  ARM_COMPUTE_RETURN_ERROR_ON(src0->dimension(0) != k);
120  if(gemm_info.reinterpret_input_as_3d)
121  {
122  ARM_COMPUTE_RETURN_ERROR_ON(src0->dimension(1) * src0->dimension(2) != m);
123  }
124  else
125  {
126  ARM_COMPUTE_RETURN_ERROR_ON(src0->dimension(1) != m);
127  }
128  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(src1, &tensor_info_reshaped1);
129 
130  if(dst->total_size() != 0)
131  {
132  const TensorInfo tensor_info_dst = dst->clone()->set_tensor_shape(misc::shape_calculator::compute_mm_shape(*src0, *src1, gemm_info));
135  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!post_op_utils.are_post_op_shapes_compliant(dst, gemm_info.post_ops), "The Post Op shapes are not compliant");
136  }
137 
138  return Status{};
139 }
140 
141 Window validate_and_configure_window(ITensorInfo *src0, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const GEMMLHSMatrixInfo &lhs_info,
142  const GEMMRHSMatrixInfo &rhs_info, const GEMMKernelInfo &gemm_info, ElementsProcessed &num_elements_processed)
143 {
144  ARM_COMPUTE_UNUSED(src0, src1, src2);
145  unsigned int &num_elems_processed_per_iteration_x = num_elements_processed[0];
146  unsigned int &num_elems_processed_per_iteration_y = num_elements_processed[1];
147  bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d;
148  bool reinterpret_output_as_3d = gemm_info.depth_output_gemm3d != 0;
149 
150  // In case both input and dst have to be reinterpreted as 3D tensors,
151  // force reinterpret_input_as_3d and reinterpret_output_as_3d to be false.
152  // This approach should only be used when the input/dst tensors have pad on the y direction
153  if((reinterpret_input_as_3d == reinterpret_output_as_3d) && gemm_info.has_pad_y)
154  {
155  reinterpret_output_as_3d = false;
156  }
157 
158  TensorInfo tmp_info(*dst);
159 
160  if(reinterpret_output_as_3d)
161  {
162  // Since the dst tensor has to be reinterpreted as 3D and the execute window is based on a 2D GEMM,
163  // the window needs to be constructed on the 2D collapsed version of the tensor
164  TensorShape tmp_shape(dst->tensor_shape());
165  tmp_shape.collapse(2U, 1U);
166  tmp_info.set_tensor_shape(tmp_shape);
167  }
168 
169  // Configure kernel window
170  num_elems_processed_per_iteration_x = rhs_info.n0;
171  num_elems_processed_per_iteration_y = lhs_info.m0;
172 
173  Window win = calculate_max_window(tmp_info, Steps(num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y));
174 
175  // Collapse along the Z direction
176  // This collapse needs to be here in order to tune the Z dimension of LWS
177  const unsigned int dimension_to_collapse = std::min(static_cast<unsigned int>(dst->num_dimensions()), 2u);
178  Window collapsed = win.collapse(win, dimension_to_collapse);
179 
180  return collapsed;
181 }
182 } // namespace
183 
185 {
186  _type = CLKernelType::GEMM;
187 }
188 
190  const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, ITensorInfo *dst, float alpha, float beta,
192 {
193  ARM_COMPUTE_ERROR_ON_NULLPTR(src0, src1, dst);
194 
195  // dst tensor auto initialization if not yet initialized
196  auto_init_if_empty(*dst, src0->clone()->set_tensor_shape(misc::shape_calculator::compute_mm_shape(*src0, *src1, gemm_info)));
197 
198  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src0, src1, src2, dst, alpha, beta, lhs_info, rhs_info, gemm_info));
199 
200  _reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d;
201  _reinterpret_output_as_3d = gemm_info.depth_output_gemm3d != 0;
202  _use_dummy_work_items = preferred_dummy_work_items_support(CLKernelLibrary::get().get_device());
203  _add_bias = src2 != nullptr;
204  _export_to_cl_image = rhs_info.export_to_cl_image;
205  _has_pad_y = gemm_info.has_pad_y;
206  _num_post_op_args = gemm_info.post_ops.total_num_arguments();
207 
208  auto padding_info = get_padding_info({ src0, src1, src2, dst });
209 
210  // In case both input and dst have to be reinterpreted as 3D tensors,
211  // force reinterpret_input_as_3d and reinterpret_output_as_3d to be false.
212  if((_reinterpret_input_as_3d == _reinterpret_output_as_3d) && _has_pad_y)
213  {
214  _reinterpret_input_as_3d = false;
215  _reinterpret_output_as_3d = false;
216  }
217 
218  // Check if we need to slide the matrix B
219  const unsigned int num_dimensions_src0 = src0->num_dimensions();
220  _slide_matrix_b = (src1->num_dimensions() >= num_dimensions_src0);
221 
222  ElementsProcessed num_elements_processed{};
223 
224  // Configure kernel window
225  Window win = validate_and_configure_window(src0->clone().get(), src1->clone().get(), (src2 != nullptr) ? src2->clone().get() : nullptr, dst->clone().get(), lhs_info, rhs_info, gemm_info,
226  num_elements_processed);
227  ICLKernel::configure_internal(win);
228 
229  // If _reinterpret_input_as_3d = reinterpret_output_as_3d = true,
230  // we will dispatch a batched-GEMM to reduce the complexity of the address calculation within the OpenCL kernel.
231  // This means that the actual m used by the kernel is given by dst->dimension(1) and not by gemm_info.m
232  const unsigned int internal_m = _reinterpret_output_as_3d ? gemm_info.m : dst->dimension(1);
233 
234  // These variables are used only if gemm_info.has_pad_y == true
235  const unsigned int h_gemm_3d = _reinterpret_output_as_3d ? dst->dimension(1) : src0->dimension(1);
236  const unsigned int d_gemm_3d = _reinterpret_output_as_3d ? dst->dimension(2) : src0->dimension(2);
237 
238  // Shrink M0 to be always <= M (internal_m) to prevent out-of-bounds reads.
239  // NOTE: This might have implications on heuristics and performance
240  const unsigned int internal_m0 = std::min(internal_m, lhs_info.m0);
241 
242  // 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.
243  const unsigned int partial_store_m0 = internal_m % internal_m0;
244  const unsigned int partial_store_n0 = gemm_info.n % rhs_info.n0;
245  _m = internal_m;
246  _n = gemm_info.n;
247  _k = gemm_info.k;
248  // Create build options
249  CLBuildOptions build_opts;
250  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src0->data_type()));
251  build_opts.add_option_if(!(helpers::float_ops::is_one(alpha)), "-DALPHA=" + float_to_string_with_full_precision(alpha));
252  build_opts.add_option_if(src2 != nullptr, "-DBETA=" + float_to_string_with_full_precision(beta));
253  build_opts.add_option_if(helpers::float_ops::is_one(beta), "-DUNIT_BETA");
254  build_opts.add_option_if(gemm_info.broadcast_bias, "-DBROADCAST_BIAS");
255  build_opts.add_option_if(!_slide_matrix_b, "-DMATRIX_B_DEPTH=" + support::cpp11::to_string(src1->dimension(2)));
256  build_opts.add_option_if(rhs_info.interleave, "-DRHS_INTERLEAVE");
257  build_opts.add_option_if(_use_dummy_work_items, "-DDUMMY_WORK_ITEMS");
258  build_opts.add_option_if(rhs_info.export_to_cl_image, "-DOPENCL_IMAGE_SUPPORT");
259  build_opts.add_option("-DRHS_HEIGHT=" + support::cpp11::to_string(src1->dimension(1)));
260  build_opts.add_option("-DM0=" + support::cpp11::to_string(internal_m0));
261  build_opts.add_option("-DN0=" + support::cpp11::to_string(rhs_info.n0));
262  build_opts.add_option("-DK0=" + support::cpp11::to_string(rhs_info.k0));
263  build_opts.add_option("-DH0=" + support::cpp11::to_string(rhs_info.h0));
264  build_opts.add_option("-DPARTIAL_STORE_M0=" + support::cpp11::to_string(partial_store_m0));
265  build_opts.add_option("-DPARTIAL_STORE_N0=" + support::cpp11::to_string(partial_store_n0));
266  if(_has_pad_y)
267  {
268  build_opts.add_option_if(_reinterpret_input_as_3d, "-DREINTERPRET_INPUT_AS_3D");
269  build_opts.add_option_if(_reinterpret_output_as_3d, "-DREINTERPRET_OUTPUT_AS_3D");
270  build_opts.add_option_if(_reinterpret_input_as_3d || _reinterpret_output_as_3d, "-DHEIGHT_GEMM3D=" + support::cpp11::to_string(h_gemm_3d));
271  build_opts.add_option_if(_reinterpret_input_as_3d || _reinterpret_output_as_3d, "-DDEPTH_GEMM3D=" + support::cpp11::to_string(d_gemm_3d));
272  }
273  // If post_ops are used, then we disable the use of gemm_info.activation_info
274  if(gemm_info.post_ops.size() > 0)
275  {
276  post_op_utils.set_post_ops_cl_build_options(build_opts, gemm_info.post_ops);
277  }
278  else
279  {
280  build_opts.add_option_if(gemm_info.activation_info.enabled(), "-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(gemm_info.activation_info.activation())));
281  build_opts.add_option_if(gemm_info.activation_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(gemm_info.activation_info.a()));
282  build_opts.add_option_if(gemm_info.activation_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(gemm_info.activation_info.b()));
283  }
284 
285  std::string kernel_name("gemm_mm_reshaped_only_rhs_");
286  kernel_name += rhs_info.transpose ? "t" : "nt";
287  kernel_name += rhs_info.export_to_cl_image ? "_texture" : "";
288  post_op_utils.set_post_ops_cl_kernel_name(kernel_name, gemm_info.post_ops);
289 
290  // A macro guard to compile ONLY the kernel of interest
291  build_opts.add_option("-D" + upper_string(kernel_name));
292 
293  // Create kernel
294  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
295 
296  // Set config_id for enabling LWS tuning
297  _config_id = kernel_name;
298  _config_id += "_";
299  _config_id += (_has_pad_y ? "" : "no_pad_y_");
300  _config_id += (_add_bias ? "add_bias_" : "");
301  _config_id += (gemm_info.broadcast_bias ? "broadcast_bias_" : "");
302  _config_id += (_reinterpret_input_as_3d ? "3di_" : "");
303  _config_id += (_reinterpret_output_as_3d ? "3do_" : "");
304  _config_id += (gemm_info.activation_info.enabled() ? "fused_activation_" : "");
305  _config_id += lower_string(string_from_data_type(src0->data_type()));
306  _config_id += "_";
307  _config_id += support::cpp11::to_string(dst->dimension(1));
308  _config_id += "_";
309  _config_id += support::cpp11::to_string(dst->dimension(0));
310  _config_id += "_";
311  _config_id += support::cpp11::to_string(gemm_info.k);
312  _config_id += "_";
313  _config_id += support::cpp11::to_string(dst->dimension(2));
314  _config_id += "_";
315  _config_id += support::cpp11::to_string(lhs_info.m0);
316  _config_id += "_";
317  _config_id += support::cpp11::to_string(rhs_info.n0);
318  _config_id += "_";
319  _config_id += support::cpp11::to_string(rhs_info.k0);
320  _config_id += "_";
321  _config_id += support::cpp11::to_string(rhs_info.h0);
322  _config_id += "_";
323  _config_id += support::cpp11::to_string(rhs_info.interleave);
324 
326 }
327 
328 Status ClGemmMatrixMultiplyReshapedOnlyRhsKernel::validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float alpha, float beta,
331 {
332  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src0, src1, src2, dst, alpha, beta, lhs_info, rhs_info, gemm_info));
333  return Status{};
334 }
335 
336 void ClGemmMatrixMultiplyReshapedOnlyRhsKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
337 {
340 
341  const auto src0 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0));
342  const auto src1 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1));
343  const auto src2 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_2));
344  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
345 
346  ARM_COMPUTE_ERROR_ON_NULLPTR(src0, src1, dst);
347  ARM_COMPUTE_ERROR_ON(_add_bias && src2 == nullptr);
348 
349  if(src1->info()->num_dimensions() < 3)
350  {
351  // The stride_z for matrix B must be zero if we do not slice
352  ARM_COMPUTE_ERROR_ON(src1->info()->strides_in_bytes()[3] != 0);
353  }
354 
355  const size_t lhs_idx_batch_size = _reinterpret_input_as_3d && !_has_pad_y ? 3u : 2u;
356  const size_t rhs_idx_batch_size = 2u;
357  const size_t bia_idx_batch_size = 2u;
358  const size_t out_idx_batch_size = _reinterpret_output_as_3d && !_has_pad_y ? 3u : 2u;
359 
361  Window slice_matrix_b = slice;
362 
363  slice_matrix_b.set(Window::DimX, Window::Dimension(0, 1, 1));
364  slice_matrix_b.set(Window::DimY, Window::Dimension(0, 1, 1));
365 
366  // Get cross plane pads
367  const unsigned int total_cross_plane_pad_lhs = src0->info()->padding().top + src0->info()->padding().bottom;
368  const unsigned int total_cross_plane_pad_out = dst->info()->padding().top + dst->info()->padding().bottom;
369 
370  // The execution should fail if we try to run with has_pad_y = false but we have padding in either the LHS or DST tensor
371  ARM_COMPUTE_ERROR_ON(!_has_pad_y && ((total_cross_plane_pad_lhs != 0) || (total_cross_plane_pad_out != 0)));
372 
373  cl::Image2D src1_image2d;
374 
375  if(_export_to_cl_image)
376  {
377  const TensorShape shape2d(src1->info()->dimension(0) / 4, src1->info()->dimension(1) * src1->info()->dimension(2));
378  const size_t image_row_pitch = src1->info()->strides_in_bytes()[1];
379 
380  src1_image2d = create_image2d_from_buffer(CLKernelLibrary::get().context(), src1->cl_buffer(), shape2d, src1->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly);
381  }
382 
383  do
384  {
385  Window slice_b = slice;
386  // Don't slice matrix B along the z dimension if matrix B has just 2 dimensions and matrix A more than 2
387  // This scenario can happen when the matrix multiplication is used to perform a convolution operation
388  if(!_slide_matrix_b)
389  {
390  slice_b = slice_matrix_b;
391  }
392 
393  unsigned int idx = 0;
394 
395  // LHS buffer
396  add_2D_tensor_argument(idx, src0, slice);
397 
398  // RHS buffer or RHS OpenCL image (_export_to_cl_image == true)
399  if(_export_to_cl_image)
400  {
401  _kernel.setArg(idx++, src1_image2d);
402  }
403  else
404  {
405  add_2D_tensor_argument(idx, src1, slice_b);
406  }
407 
408  // Bias buffer (_add_bias == true)
409  add_2D_tensor_argument_if(_add_bias, idx, src2, slice);
410 
411  // dst buffer
413 
414  // post op argument buffers
415  for(size_t i = 0; i < _num_post_op_args; ++i)
416  {
417  const auto post_op_arg = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(experimental::get_post_op_arg_type(i)));
418  add_2D_tensor_argument(idx, post_op_arg, slice);
419  }
420 
421  // LHS stride_z
422  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src0->info()->strides_in_bytes()[lhs_idx_batch_size]));
423 
424  // RHS stride_z (not used if _export_to_cl_image == true)
425  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src1->info()->strides_in_bytes()[rhs_idx_batch_size]));
426 
427  // Bias stride_z (if _add_bias == true)
428  if(_add_bias)
429  {
430  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src2->info()->strides_in_bytes()[bia_idx_batch_size]));
431  }
432 
433  // dst stride_z
434  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(dst->info()->strides_in_bytes()[out_idx_batch_size]));
435  // post op argument stride_z
436  for(size_t i = 0; i < _num_post_op_args; ++i)
437  {
438  const auto post_op_arg = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(experimental::get_post_op_arg_type(i)));
439  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(post_op_arg->info()->strides_in_bytes()[2]));
440  }
441 
442  // Cross-plan padding (if _reinterpret_input_as_3d = true)
443  if(_reinterpret_input_as_3d && _has_pad_y)
444  {
445  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(total_cross_plane_pad_lhs));
446  }
447 
448  // Cross-plan padding (if reinterpret_output_as_3d = true)
449  if(_reinterpret_output_as_3d && _has_pad_y)
450  {
451  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(total_cross_plane_pad_out));
452  }
453 
454  // Pass m, n and k at runtime as signed ints, to ensure results of any subractions they could be operand in, would still be signed.
455  _kernel.setArg<cl_int>(idx++, _m);
456  _kernel.setArg<cl_int>(idx++, _n);
457  _kernel.setArg<cl_int>(idx++, _k);
458 
459  enqueue(queue, *this, slice, lws_hint(), _use_dummy_work_items);
460  }
462 }
463 } // namespace kernels
464 } // namespace opencl
465 } // namespace arm_compute
arm_compute::support::cpp11::to_string
std::string to_string(T &&value)
Convert integer and float values to string.
Definition: StringSupport.h:168
Cast.h
StringSupport.h
ICLTensor.h
arm_compute::CLBuildOptions::options
const StringSet & options() const
Gets the current options list set.
Definition: CLCompileContext.cpp:72
arm_compute::calculate_max_window
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Definition: WindowHelpers.cpp:28
arm_compute::preferred_dummy_work_items_support
bool preferred_dummy_work_items_support(const cl::Device &device)
Helper function to check if "dummy work-items" are preferred to have a power of two NDRange In case d...
Definition: CLHelpers.cpp:367
arm_compute::misc::shape_calculator::compute_mm_shape
TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo &input1, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info)
Calculate the matrix multiplication output shape of two tensors.
Definition: ShapeCalculator.h:907
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
arm_compute::lower_string
std::string lower_string(const std::string &val)
Lower a given string.
Definition: StringUtils.cpp:38
arm_compute::cpu::kernels::validate_arguments
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
Definition: CpuDirectConv2dKernel.cpp:60
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:1004
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:528
arm_compute::Window::DimX
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
arm_compute::opencl::kernels::gemm::validate_image2d_support_on_rhs
Status validate_image2d_support_on_rhs(const ITensorInfo &tensor_reshaped_info, const GEMMRHSMatrixInfo &rhs_info)
Utility function to validate the image2d OpenCL object support on the RHS reshaped matrix.
Definition: ClGemmHelpers.cpp:105
arm_compute::opencl::kernels::ClGemmMatrixMultiplyReshapedOnlyRhsKernel::configure
void configure(const ClCompileContext &compile_context, const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, ITensorInfo *dst, float alpha, float beta, const GEMMLHSMatrixInfo &lhs_info, const GEMMRHSMatrixInfo &rhs_info, const GEMMKernelInfo &gemm_info)
Initialise the kernel's input and output.
Definition: ClGemmMatrixMultiplyReshapedOnlyRhsKernel.cpp:189
arm_compute::test::validation::lhs_info
lhs_info
Definition: GEMMMatrixMultiplyReshaped.cpp:862
arm_compute::test::validation::k
const unsigned int k
Definition: GEMMMatrixMultiplyNative.cpp:361
ClGemmHelpers.h
arm_compute::experimental::PostOpType::Eltwise_Add
@ Eltwise_Add
float_ops.h
arm_compute::ITensorPack::get_tensor
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:64
arm_compute::opencl::kernels::ClGemmMatrixMultiplyReshapedOnlyRhsKernel::ClGemmMatrixMultiplyReshapedOnlyRhsKernel
ClGemmMatrixMultiplyReshapedOnlyRhsKernel()
Definition: ClGemmMatrixMultiplyReshapedOnlyRhsKernel.cpp:184
arm_compute::string_from_data_type
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: DataTypeUtils.cpp:31
arm_compute::ACL_SRC_0
@ ACL_SRC_0
Definition: Types.h:45
arm_compute::upper_string
std::string upper_string(const std::string &val)
Raise a given string to upper case.
Definition: StringUtils.cpp:45
arm_compute::GEMMKernelInfo
Descriptor used by the GEMM kernels.
Definition: KernelDescriptors.h:59
arm_compute::ACL_SRC_1
@ ACL_SRC_1
Definition: Types.h:46
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:39
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:630
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:877
arm_compute::ACL_SRC_2
@ ACL_SRC_2
Definition: Types.h:47
StringUtils.h
arm_compute::ICLKernel::add_2D_tensor_argument
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:198
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
arm_compute::ITensorInfo::dimension
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
arm_compute::experimental::PostOpType::Eltwise_PRelu
@ Eltwise_PRelu
CLUtils.h
arm_compute::test::validation::m
const unsigned int m
Definition: GEMMMatrixMultiplyNative.cpp:359
arm_compute::test::validation::rhs_info
rhs_info
Definition: GEMMMatrixMultiplyReshaped.cpp:862
ClGemmMatrixMultiplyReshapedOnlyRhsKernel.h
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::ITensorPack::get_const_tensor
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
arm_compute::ICLKernel::add_2D_tensor_argument_if
void add_2D_tensor_argument_if(bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx ...
Definition: ICLKernel.h:209
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:456
arm_compute::helpers::float_ops::is_zero
bool is_zero(float a, float epsilon=0.00001f)
Checks if the input floating point number is 0.0f checking if the difference is within a range define...
Definition: float_ops.h:109
arm_compute::ITensorPack
Tensor packing service.
Definition: ITensorPack.h:39
arm_compute::CLBuildOptions::add_option
void add_option(std::string option)
Adds option to the existing build option list.
Definition: CLCompileContext.cpp:41
arm_compute::test::validation::gemm_info
gemm_info
Definition: GEMMMatrixMultiplyReshaped.cpp:862
arm_compute::CLCompileContext
CLCompileContext class.
Definition: CLCompileContext.h:204
arm_compute::CLImage2DType::ReadOnly
@ ReadOnly
ARM_COMPUTE_RETURN_ERROR_ON
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:297
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::auto_init_if_empty
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
Definition: AutoConfiguration.h:43
ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
Definition: CLValidate.h:35
arm_compute::create_kernel
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
Definition: CLHelpers.cpp:404
arm_compute::Status
Status class.
Definition: Error.h:52
WindowHelpers.h
arm_compute::CLBuildOptions::add_option_if
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
Definition: CLCompileContext.cpp:46
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
arm_compute::float_to_string_with_full_precision
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: StringUtils.cpp:52
arm_compute::ITensorInfo::data_type
virtual DataType data_type() const =0
Data type used for each element of the tensor.
arm_compute::Window::slide_window_slice_3D
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:349
arm_compute::cpu::kernels::validate_and_configure_window
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *src, ITensorInfo *dst)
Definition: CpuDirectConv2dKernel.cpp:92
arm_compute::opencl::kernels::ClGemmMatrixMultiplyReshapedOnlyRhsKernel::run_op
void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
Definition: ClGemmMatrixMultiplyReshapedOnlyRhsKernel.cpp:336
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
arm_compute::test::validation::context
auto context
Definition: DirectConv2d.cpp:160
arm_compute::Window::Dimension
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:79
arm_compute::opencl::kernels::ClGemmMatrixMultiplyReshapedOnlyRhsKernel::validate
static Status validate(const ITensorInfo *src0, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float alpha, float beta, const GEMMLHSMatrixInfo &lhs_info, const GEMMRHSMatrixInfo &rhs_info, const GEMMKernelInfo &gemm_info)
Static function to check if given info will lead to a valid configuration.
Definition: ClGemmMatrixMultiplyReshapedOnlyRhsKernel.cpp:328
arm_compute::Window::set
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
PostOpUtils.h
arm_compute::Window::DimY
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
AutoConfiguration.h
ActivationFunctionUtils.h
arm_compute::Window::first_slice_window_3D
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:305
arm_compute::experimental::PostOpType::Activation
@ Activation
CLValidate.h
arm_compute::experimental::get_post_op_arg_type
TensorType get_post_op_arg_type(size_t index)
Get post op argument TensorType from post op argument index in a flattened, ordered post op argument ...
Definition: PostOpUtils.h:77
arm_compute::IKernel::window
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
arm_compute::get_cl_type_from_data_type
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:40
arm_compute::misc::ICloneable::clone
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
arm_compute::misc::shape_calculator::compute_rhs_reshaped_shape
TensorShape compute_rhs_reshaped_shape(const ITensorInfo &a, const GEMMRHSMatrixInfo &rhs_info)
Calculate the Right Hand Side matrix reshaped shape.
Definition: ShapeCalculator.h:226
ShapeCalculator.h
arm_compute::GEMMLHSMatrixInfo
GEMM LHS (Left Hand Side) matrix information.
Definition: Types.h:1803
arm_compute::Window
Describe a multidimensional execution window.
Definition: Window.h:39
arm_compute::create_image2d_from_buffer
cl::Image2D create_image2d_from_buffer(const cl::Context &ctx, const cl::Buffer &buffer, const TensorShape &shape2d, DataType data_type, size_t image_row_pitch, CLImage2DType image_type)
Create a cl::Image2D object from an OpenCL buffer.
Definition: CLUtils.cpp:63
ARM_COMPUTE_RETURN_ERROR_ON_MSG
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:245
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::DataType::F16
@ F16
16-bit floating-point number
arm_compute::has_padding_changed
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Definition: Utils.cpp:462
arm_compute::ICLKernel::lws_hint
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:371
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
arm_compute::string_from_activation_func
const std::string & string_from_activation_func(const ActivationFunction &act)
Translates a given activation function to a string.
Definition: ActivationFunctionUtils.cpp:31
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:43
arm_compute::DataType::F32
@ F32
32-bit floating-point number
arm_compute::CLBuildOptions
Build options.
Definition: CLCompileContext.h:38
arm_compute::GEMMRHSMatrixInfo
GEMM RHS (Right Hand Side) matrix information.
Definition: Types.h:1818
arm_compute::GEMM
@ GEMM
GEMM CL kernel type.
Definition: CLTypes.h:86
arm_compute::get_padding_info
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
Definition: Utils.cpp:447
arm_compute::test::validation::reference::slice
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
Definition: SliceOperations.cpp:38
arm_compute::ITensorInfo::num_dimensions
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
arm_compute::test::validation::n
const unsigned int n
Definition: GEMMMatrixMultiplyNative.cpp:360
arm_compute::helpers::float_ops::is_one
bool is_one(float a, float epsilon=0.00001f)
Checks if the input floating point number is 1.0f checking if the difference is within a range define...
Definition: float_ops.h:97
kernel_name
std::string kernel_name
Definition: ClIm2ColKernel.cpp:57
arm_compute::enqueue
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:32