Compute Library
 22.08
ClGemmMatrixMultiplyNativeKernel Class Reference

OpenCL kernel to multiply matrices when neither of the input matrices have been reshaped. More...

#include <ClGemmMatrixMultiplyNativeKernel.h>

Collaboration diagram for ClGemmMatrixMultiplyNativeKernel:
[legend]

Public Member Functions

 ClGemmMatrixMultiplyNativeKernel ()
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (ClGemmMatrixMultiplyNativeKernel)
 
void configure (const ClCompileContext &compile_context, ITensorInfo *src0, ITensorInfo *src1, 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 dst. More...
 
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. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
CLKernelType type () const
 Returns the CL kernel type. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
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. More...
 
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 if the condition is true. More...
 
void add_3D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_5D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 5D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_3d_tensor_nhw_argument (unsigned int &idx, const ICLTensor *tensor)
 Add the passed NHW 3D tensor's parameters to the object's kernel's arguments by passing strides, dimensions and the offset to the first valid element in bytes. More...
 
void add_4d_tensor_nhwc_argument (unsigned int &idx, const ICLTensor *tensor)
 Add the passed NHWC 4D tensor's parameters to the object's kernel's arguments by passing strides, dimensions and the offset to the first valid element in bytes. More...
 
virtual void run (const Window &window, cl::CommandQueue &queue)
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
virtual void run_composite_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue, const experimental::dynamic_fusion::ClExecutionDescriptor &exec_desc)
 The execution is carried out through run_op method. But the run_op method needs to be extended to include ClExecutionDescriptor as now LWS GWS tuning will be separated from the IKernel. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
void set_wbsm_hint (const cl_int &wbsm_hint)
 Set the workgroup batch size modifier hint. More...
 
cl_int wbsm_hint () const
 Return the workgroup batch size modifier hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

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. More...
 
- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_3d_tensor_nhw ()
 Returns the number of arguments enqueued per NHW 3D Tensor object. More...
 
static constexpr unsigned int num_arguments_per_4d_tensor_nhwc ()
 Returns the number of arguments enqueued per NHWC 4D Tensor object. More...
 
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

OpenCL kernel to multiply matrices when neither of the input matrices have been reshaped.

Definition at line 39 of file ClGemmMatrixMultiplyNativeKernel.h.

Constructor & Destructor Documentation

◆ ClGemmMatrixMultiplyNativeKernel()

Definition at line 220 of file ClGemmMatrixMultiplyNativeKernel.cpp.

References arm_compute::GEMM.

221 {
222  _type = CLKernelType::GEMM;
223 }
Convolution using GEMM.

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( ClGemmMatrixMultiplyNativeKernel  )

◆ configure()

void configure ( const ClCompileContext compile_context,
ITensorInfo src0,
ITensorInfo src1,
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 dst.

Parameters
[in]compile_contextThe compile context to be used.
[in]src0Input tensor for the LHS matrix. Data type supported: F32/F16. The number of dimensions for the LHS matrix must be less or equal than 4.
[in]src1Input tensor for the RHS matrix. Data type supported: same as src0. The number of dimensions for the RHS matrix must be less or equal than 3.
[in]src2Input tensor containing the bias matrix. Data type supported: same as src0.
[out]dstdst tensor info. Data type supported: same as src0
[in]alphaWeight of the matrix product
[in]betaWeight of the matrix bias
[in]lhs_infoLHS matrix information used to retrieve the number of rows and accumulations to be processed by each thread. Only the following values are supported: lhs_info.m0: 1,2,3,4,5,6,7,8 lhs_info.k0: 2,3,4,8,16
[in]rhs_infoRHS matrix information used to retrieve the number of columns and accumulations to be processed by each thread. Only the following values are supported: rhs_info.n0: 2,3,4,8,16 rhs_info.k0: same of lhs_info.k0
[in]gemm_infoGEMM information used to retrieve the original dimensions of the input matrices

Definition at line 225 of file ClGemmMatrixMultiplyNativeKernel.cpp.

References ActivationLayerInfo::a(), ActivationLayerInfo::activation(), GEMMKernelInfo::activation_info, CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ActivationLayerInfo::b(), GEMMKernelInfo::broadcast_bias, ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_mm_shape(), arm_compute::create_kernel(), ITensorInfo::data_type(), GEMMKernelInfo::depth_output_gemm3d, ITensorInfo::dimension(), ActivationLayerInfo::enabled(), arm_compute::float_to_string_with_full_precision(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_padding_info(), arm_compute::has_padding_changed(), arm_compute::helpers::float_ops::is_one(), GEMMKernelInfo::k, GEMMRHSMatrixInfo::k0, kernel_name, arm_compute::lower_string(), GEMMKernelInfo::m, GEMMLHSMatrixInfo::m0, GEMMKernelInfo::n, GEMMRHSMatrixInfo::n0, ITensorInfo::num_dimensions(), CLBuildOptions::options(), GEMMKernelInfo::post_ops, arm_compute::preferred_dummy_work_items_support(), GEMMKernelInfo::reinterpret_input_as_3d, arm_compute::string_from_activation_func(), arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), arm_compute::upper_string(), arm_compute::cpu::kernels::validate_and_configure_window(), and arm_compute::cpu::kernels::validate_arguments().

229 {
230  ARM_COMPUTE_ERROR_ON_NULLPTR(src0, src1, dst);
231 
232  // dst tensor auto initialization if not yet initialized
233  auto_init_if_empty(*dst, src0->clone()->set_tensor_shape(misc::shape_calculator::compute_mm_shape(*src0, *src1, gemm_info)));
234 
235  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src0, src1, src2, dst, alpha, beta, lhs_info, rhs_info, gemm_info));
236 
237  auto padding_info = get_padding_info({ src0, dst });
238  _reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d;
239  _reinterpret_output_as_3d = gemm_info.depth_output_gemm3d != 0;
240  _use_dummy_work_items = preferred_dummy_work_items_support(CLKernelLibrary::get().get_device());
241  _add_bias = src2 != nullptr;
242  _num_post_op_args = gemm_info.post_ops.total_num_arguments();
243 
244  // In case both input and dst have to be reinterpreted as 3D tensors,
245  // force reinterpret_input_as_3d and reinterpret_output_as_3d to be false.
246  if(_reinterpret_input_as_3d == _reinterpret_output_as_3d)
247  {
248  _reinterpret_input_as_3d = false;
249  _reinterpret_output_as_3d = false;
250  }
251 
252  // Check if we need to slide the matrix B
253  const unsigned int num_dimensions_src0 = src0->num_dimensions();
254  _slide_matrix_b = (src1->num_dimensions() >= num_dimensions_src0);
255 
256  ElementsProcessed num_elements_processed{};
257 
258  // Configure kernel window
259  auto win_config = validate_and_configure_window(src0, src1, src2 != nullptr ? src2 : nullptr, dst, lhs_info, rhs_info, gemm_info, num_elements_processed);
260  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
261  IClKernel::configure_internal(win_config.second);
262 
263  // If _reinterpret_input_as_3d = _reinterpret_output_as_3d = true,
264  // we will dispatch a batched-GEMM to reduce the complexity of the address calculation within the OpenCL kernel.
265  // This means that the actual m used by the kernel is given by dst->dimension(1) and not by gemm_info.m
266  const unsigned int internal_m = _reinterpret_output_as_3d ? gemm_info.m : dst->dimension(1);
267 
268  const unsigned int h_gemm_3d = _reinterpret_output_as_3d ? dst->dimension(1) : src0->dimension(1);
269  const unsigned int d_gemm_3d = _reinterpret_output_as_3d ? dst->dimension(2) : src0->dimension(2);
270 
271  // 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.
272  const unsigned int partial_store_m0 = internal_m % lhs_info.m0;
273  const unsigned int partial_store_n0 = gemm_info.n % rhs_info.n0;
274 
275  // Shrink M0 to be always <= M (internal_m) to prevent out-of-bounds reads.
276  // NOTE: This might have implications on heuristics and performance
277  const unsigned int internal_m0 = std::min(internal_m, lhs_info.m0);
278  _m = internal_m;
279  _n = gemm_info.n;
280  _k = gemm_info.k;
281 
282  // Create build options
283  CLBuildOptions build_opts;
284  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src0->data_type()));
285  build_opts.add_option_if(!(helpers::float_ops::is_one(alpha)), "-DALPHA=" + float_to_string_with_full_precision(alpha));
286  build_opts.add_option_if(src2 != nullptr, "-DBETA=" + float_to_string_with_full_precision(beta));
287  build_opts.add_option_if(helpers::float_ops::is_one(beta), "-DUNIT_BETA");
288  build_opts.add_option_if(gemm_info.broadcast_bias, "-DBROADCAST_BIAS");
289  build_opts.add_option_if(_reinterpret_input_as_3d, "-DREINTERPRET_INPUT_AS_3D");
290  build_opts.add_option_if(_reinterpret_output_as_3d, "-DREINTERPRET_OUTPUT_AS_3D");
291  build_opts.add_option_if(_reinterpret_input_as_3d || _reinterpret_output_as_3d, "-DHEIGHT_GEMM3D=" + support::cpp11::to_string(h_gemm_3d));
292  build_opts.add_option_if(_reinterpret_input_as_3d || _reinterpret_output_as_3d, "-DDEPTH_GEMM3D=" + support::cpp11::to_string(d_gemm_3d));
293  build_opts.add_option_if(!_slide_matrix_b, "-DMATRIX_B_DEPTH=" + support::cpp11::to_string(src1->dimension(2)));
294  build_opts.add_option_if(_use_dummy_work_items, "-DDUMMY_WORK_ITEMS");
295  build_opts.add_option("-DM0=" + support::cpp11::to_string(internal_m0));
296  build_opts.add_option("-DN0=" + support::cpp11::to_string(rhs_info.n0));
297  build_opts.add_option("-DK0=" + support::cpp11::to_string(rhs_info.k0));
298  build_opts.add_option("-DPARTIAL_STORE_M0=" + support::cpp11::to_string(partial_store_m0));
299  build_opts.add_option("-DPARTIAL_STORE_N0=" + support::cpp11::to_string(partial_store_n0));
300  // If post_ops are used, then we disable the use of gemm_info.activation_info
301  if(gemm_info.post_ops.size() > 0)
302  {
303  post_op_utils.set_post_ops_cl_build_options(build_opts, gemm_info.post_ops);
304  }
305  else
306  {
307  build_opts.add_option_if(gemm_info.activation_info.enabled(), "-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(gemm_info.activation_info.activation())));
308  build_opts.add_option_if(gemm_info.activation_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(gemm_info.activation_info.a()));
309  build_opts.add_option_if(gemm_info.activation_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(gemm_info.activation_info.b()));
310  }
311 
312  std::string kernel_name("gemm_mm_native");
313  post_op_utils.set_post_ops_cl_kernel_name(kernel_name, gemm_info.post_ops);
314 
315  // A macro guard to compile ONLY the kernel of interest
316  build_opts.add_option("-D" + upper_string(kernel_name));
317 
318  // Create kernel
319  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
320 
321  // Set config_id for enabling LWS tuning
322  _config_id = kernel_name;
323  _config_id += "_";
324  _config_id += (_add_bias ? "add_bias_" : "");
325  _config_id += (gemm_info.broadcast_bias ? "broadcast_bias_" : "");
326  _config_id += (_reinterpret_input_as_3d ? "3di_" : "");
327  _config_id += (_reinterpret_output_as_3d ? "3do_" : "");
328  _config_id += (gemm_info.activation_info.enabled() ? "fused_activation_" : "");
329  _config_id += lower_string(string_from_data_type(src0->data_type()));
330  _config_id += "_";
331  _config_id += support::cpp11::to_string(dst->dimension(1));
332  _config_id += "_";
333  _config_id += support::cpp11::to_string(dst->dimension(0));
334  _config_id += "_";
335  _config_id += support::cpp11::to_string(gemm_info.k);
336  _config_id += "_";
337  _config_id += support::cpp11::to_string(dst->dimension(2));
338  _config_id += "_";
339  _config_id += support::cpp11::to_string(lhs_info.m0);
340  _config_id += "_";
341  _config_id += support::cpp11::to_string(rhs_info.n0);
342  _config_id += "_";
343  _config_id += support::cpp11::to_string(rhs_info.k0);
344 
346 }
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
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
std::string to_string(T &&value)
Convert integer and float values to string.
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.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
Definition: Utils.cpp:163
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:351
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
std::string upper_string(const std::string &val)
Raise a given string to upper case.
Definition: Utils.cpp:358
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
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1124
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:39
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...
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:601
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *src, ITensorInfo *dst)
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:586
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
std::string kernel_name

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]tensorsA vector containing the tensors to operato on.
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Reimplemented from ICLKernel.

Definition at line 367 of file ClGemmMatrixMultiplyNativeKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, arm_compute::ACL_SRC_2, ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimX, Window::DimY, arm_compute::enqueue(), Window::first_slice_window_3D(), ITensorPack::get_const_tensor(), arm_compute::experimental::get_post_op_arg_type(), ITensorPack::get_tensor(), ICLKernel::lws_hint(), ICLKernel::num_arguments_per_2D_tensor(), Window::set(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().

368 {
371 
372  const auto src0 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0));
373  const auto src1 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1));
374  const auto src2 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_2));
375  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
376 
377  ARM_COMPUTE_ERROR_ON_NULLPTR(src0, src1, dst);
378  ARM_COMPUTE_ERROR_ON(_add_bias && src2 == nullptr);
379 
380  if(src1->info()->num_dimensions() < 3)
381  {
382  // The stride_z for matrix B must be zero if we do not slice
383  ARM_COMPUTE_ERROR_ON(src1->info()->strides_in_bytes()[3] != 0);
384  }
385 
387  Window slice_matrix_b = slice;
388 
389  slice_matrix_b.set(Window::DimX, Window::Dimension(0, 1, 1));
390  slice_matrix_b.set(Window::DimY, Window::Dimension(0, 1, 1));
391 
392  if(_reinterpret_input_as_3d)
393  {
394  // Pass bottom paddings to the kernel if the input has to be reinterpreted as 3D tensor
395  unsigned int idx0;
396  if(_add_bias)
397  {
398  idx0 = (4 + _num_post_op_args) * num_arguments_per_2D_tensor() + (7 + _num_post_op_args);
399  }
400  else
401  {
402  idx0 = (3 + _num_post_op_args) * num_arguments_per_2D_tensor() + (6 + _num_post_op_args);
403  }
404  const unsigned int total_cross_plane_pad = src0->info()->padding().top + src0->info()->padding().bottom;
405  _kernel.setArg<cl_uint>(idx0, static_cast<unsigned int>(total_cross_plane_pad));
406  }
407 
408  if(_reinterpret_output_as_3d)
409  {
410  // Pass bottom paddings to the kernel if the dst has to be reinterpreted as 3D tensor
411  unsigned int idx0;
412  if(_add_bias)
413  {
414  idx0 = (4 + _num_post_op_args) * num_arguments_per_2D_tensor() + 7 + (_reinterpret_input_as_3d ? 1 : 0) + _num_post_op_args;
415  }
416  else
417  {
418  idx0 = (3 + _num_post_op_args) * num_arguments_per_2D_tensor() + 6 + (_reinterpret_input_as_3d ? 1 : 0) + _num_post_op_args;
419  }
420  const unsigned int total_cross_plane_pad = dst->info()->padding().top + dst->info()->padding().bottom;
421  _kernel.setArg<cl_uint>(idx0, static_cast<unsigned int>(total_cross_plane_pad));
422  }
423 
424  do
425  {
426  Window slice_b = slice;
427  // Don't slice matrix B along the z dimension if matrix B has just 2 dimensions and matrix A more than 2
428  // This scenario can happen when the matrix multiplication is used to perform a convolution operation
429  if(!_slide_matrix_b)
430  {
431  slice_b = slice_matrix_b;
432  }
433 
434  unsigned int idx = 0;
435  add_2D_tensor_argument(idx, src0, slice);
436  add_2D_tensor_argument(idx, src1, slice_b);
437  if(_add_bias)
438  {
439  add_2D_tensor_argument(idx, src2, slice);
440  }
441  add_2D_tensor_argument(idx, dst, slice);
442  // post op argument buffers
443  for(size_t i = 0; i < _num_post_op_args; ++i)
444  {
445  const auto post_op_arg = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(experimental::get_post_op_arg_type(i)));
446  add_2D_tensor_argument(idx, post_op_arg, slice);
447  }
448  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src0->info()->strides_in_bytes()[2]));
449  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src1->info()->strides_in_bytes()[2]));
450  if(_add_bias)
451  {
452  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src2->info()->strides_in_bytes()[2]));
453  }
454  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(dst->info()->strides_in_bytes()[2]));
455  // post op argument stride_z
456  for(size_t i = 0; i < _num_post_op_args; ++i)
457  {
458  const auto post_op_arg = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(experimental::get_post_op_arg_type(i)));
459  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(post_op_arg->info()->strides_in_bytes()[2]));
460  }
461 
462  // Pass m, n and k at runtime
463  _kernel.setArg<cl_int>(idx++, _m);
464  _kernel.setArg<cl_int>(idx++, _n);
465  _kernel.setArg<cl_int>(idx++, _k);
466 
467  enqueue(queue, *this, slice, lws_hint(), _use_dummy_work_items);
468  }
469  while(window.slide_window_slice_3D(slice));
470 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:384
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
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:79
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:306
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:349
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:203
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:305
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

◆ validate()

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

Static function to check if given info will lead to a valid configuration.

Similar to ClGemmMatrixMultiplyNativeKernel::configure()

Returns
a status

Definition at line 348 of file ClGemmMatrixMultiplyNativeKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), arm_compute::test::validation::gemm_info, arm_compute::test::validation::lhs_info, arm_compute::test::validation::rhs_info, arm_compute::cpu::kernels::validate_and_configure_window(), and arm_compute::cpu::kernels::validate_arguments().

351 {
352  ElementsProcessed num_elements_processed{};
353  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src0, src1, src2, dst, alpha, beta, lhs_info, rhs_info, gemm_info));
355  src1->clone().get(),
356  src2 != nullptr ? src2->clone().get() : nullptr,
357  dst->clone().get(),
358  lhs_info,
359  rhs_info,
360  gemm_info,
361  num_elements_processed)
362  .first);
363 
364  return Status{};
365 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *src, ITensorInfo *dst)

The documentation for this class was generated from the following files: