Compute Library
 21.05
arm_compute::cl_gemm Namespace Reference

Namespaces

 auto_heuristics
 

Data Structures

class  CLGEMMDefaultConfigNativeBifrost
 Bifrost based OpenCL GEMMNative configuration. More...
 
class  CLGEMMDefaultConfigNativeMidgard
 Midgard based OpenCL GEMMNative configuration. More...
 
class  CLGEMMDefaultConfigNativeValhall
 Valhall based OpenCL GEMMNative configuration. More...
 
class  CLGEMMDefaultConfigReshapedBifrost
 Bifrost based OpenCL GEMMReshaped configuration. More...
 
class  CLGEMMDefaultConfigReshapedRHSOnlyBifrost
 Bifrost based OpenCL GEMMReshapedOnlyRHS configuration. More...
 
class  CLGEMMDefaultConfigReshapedRHSOnlyValhall
 Valhall based OpenCL GEMMReshapedOnlyRHS configuration. More...
 
class  CLGEMMDefaultConfigReshapedValhall
 Valhall based OpenCL GEMMReshaped configuration. More...
 
class  CLGEMMDefaultTypeBifrost
 Bifrost based OpenCL GEMMKernel selection. More...
 
class  CLGEMMDefaultTypeMidgard
 Midgard based OpenCL GEMMKernel selection. More...
 
class  CLGEMMDefaultTypeValhall
 Valhall based OpenCL GEMMKernel selection. More...
 
class  CLGEMMKernelSelectionFactory
 CLGEMMKernelSelection factory class. More...
 
class  CLGEMMNativeKernelConfigurationFactory
 CLGEMMNative factory class. More...
 
class  CLGEMMReshapedKernelConfigurationFactory
 CLGEMMReshaped factory class. More...
 
class  CLGEMMReshapedOnlyRHSKernelConfigurationFactory
 CLGEMMReshapedOnlyRHS factory class. More...
 
class  ICLGEMMKernelSelection
 Basic interface for the GEMM kernel selection. More...
 

Functions

std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfoconfigure_lhs_rhs_info (unsigned int m, unsigned int n, unsigned int m0, unsigned int n0, unsigned int k0, unsigned int v0, unsigned int h0, bool lhs_interleave, bool rhs_interleave, bool lhs_transpose, bool rhs_transpose, bool export_to_cl_image=false)
 Configure GEMMLHSMatrixInfo and GEMMRHSMatrixInfo. More...
 
std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfoselect_lhs_rhs_info (std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > info_img, std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > info_buf, unsigned int n, unsigned int k, unsigned int b, DataType data_type)
 Select GEMMLHSMatrixInfo and GEMMRHSMatrixInfo. More...
 
void update_padding_for_cl_image (ITensorInfo *tensor)
 Update padding required to export the OpenCL buffer to OpenCL image2d. More...
 
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. More...
 

Function Documentation

◆ configure_lhs_rhs_info()

std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > configure_lhs_rhs_info ( unsigned int  m,
unsigned int  n,
unsigned int  m0,
unsigned int  n0,
unsigned int  k0,
unsigned int  v0,
unsigned int  h0,
bool  lhs_interleave,
bool  rhs_interleave,
bool  lhs_transpose,
bool  rhs_transpose,
bool  export_to_cl_image = false 
)

Configure GEMMLHSMatrixInfo and GEMMRHSMatrixInfo.

Parameters
[in]mNumber of rows (M) in the LHS matrix not reshaped
[in]nNumber of columns (N) in the RHS matrix not reshaped
[in]m0Number of rows processed by each thread/work-item
[in]n0Number of columns processed by each thread/work-item
[in]k0Number of inner accumulation performed by each thread/work-item
[in]v0Number of vertical blocks of size (m0xk0) stored on the same output row
[in]h0Number of horizontal blocks of size (k0xn0) stored on the same output row
[in]lhs_interleaveTrue if the v0 (m0xk0) blocks have to be interleaved in the output row
[in]rhs_interleaveTrue if the h0 (k0xn0) blocks have to be interleaved in the output row
[in]lhs_transposeTrue if the (m0xk0) block has to be transposed before been stored
[in]rhs_transposeTrue if the (k0xn0) block has to be transposed before been stored
[in]export_to_cl_image(Optional) True if the RHS reshaped matrix has to be exported to cl_image
Returns
GEMMLHSMatrixInfo and GEMMRHSMatrixInfo

Definition at line 40 of file CLGEMMHelpers.cpp.

42 {
43  ARM_COMPUTE_ERROR_ON(m0 == 0 || n0 == 0);
44  v0 = std::max(std::min(static_cast<int>(m / m0), static_cast<int>(v0)), static_cast<int>(1));
45  h0 = std::max(std::min(static_cast<int>(n / n0), static_cast<int>(h0)), static_cast<int>(1));
46 
47  const GEMMLHSMatrixInfo lhs_info(m0, k0, v0, lhs_transpose, lhs_interleave);
48  const GEMMRHSMatrixInfo rhs_info(n0, k0, h0, rhs_transpose, rhs_interleave, export_to_cl_image);
49 
50  return std::make_pair(lhs_info, rhs_info);
51 }
#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

References ARM_COMPUTE_ERROR_ON.

Referenced by arm_compute::cl_gemm::auto_heuristics::select_mlgo_gemm_config_native(), arm_compute::cl_gemm::auto_heuristics::select_mlgo_gemm_config_reshaped(), and arm_compute::cl_gemm::auto_heuristics::select_mlgo_gemm_config_reshaped_only_rhs().

◆ select_lhs_rhs_info()

std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo > select_lhs_rhs_info ( std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo info_img,
std::pair< GEMMLHSMatrixInfo, GEMMRHSMatrixInfo info_buf,
unsigned int  n,
unsigned int  k,
unsigned int  b,
DataType  data_type 
)

Select GEMMLHSMatrixInfo and GEMMRHSMatrixInfo.

This function accepts two pairs of GEMMLHSMatrixInfo/GEMMRHSMatrixInfo where only the first is with cl_image2d support, and selects the valid one validating the GEMMRHSMatrixInfo. If the validation passes, the functions will return the first GEMMLHSMatrixInfo/GEMMRHSMatrixInfo pair with cl_image2d support.

Parameters
[in]info_imgGEMMLHSMatrixInfo/GEMMRHSMatrixInfo with cl_image2d support
[in]info_bufGEMMLHSMatrixInfo/GEMMRHSMatrixInfo to fall-back if cl_image2d cannot be used
[in]nNumber of columns (N) in the RHS matrix not reshaped
[in]kNumber of rows (K) in the RHS matrix not reshaped
[in]bBatch size
[in]data_typeData type
Returns
GEMMLHSMatrixInfo and GEMMRHSMatrixInfo

Definition at line 53 of file CLGEMMHelpers.cpp.

56 {
57  const TensorInfo tensor_rhs_info(TensorShape(n, k, b), 1, data_type);
58  const TensorShape shape = compute_rhs_reshaped_shape(tensor_rhs_info, info_img.second);
59  const TensorInfo tensor_reshaped_info(shape, 1, data_type);
60 
61  if(bool(validate_image2d_support_on_rhs(tensor_reshaped_info, info_img.second)))
62  {
63  return info_img;
64  }
65  else
66  {
67  return info_buf;
68  }
69 }
SimpleTensor< float > b
Definition: DFT.cpp:157
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.
const DataType data_type
Definition: Im2Col.cpp:150
TensorShape compute_rhs_reshaped_shape(const ITensorInfo &a, const GEMMRHSMatrixInfo &rhs_info)
Calculate the Right Hand Side matrix reshaped shape.

References arm_compute::test::validation::b, arm_compute::misc::shape_calculator::compute_rhs_reshaped_shape(), arm_compute::test::validation::data_type, arm_compute::test::validation::shape, and validate_image2d_support_on_rhs().

◆ update_padding_for_cl_image()

void update_padding_for_cl_image ( ITensorInfo tensor)

Update padding required to export the OpenCL buffer to OpenCL image2d.

Parameters
[in,out]tensorITensorInfo of the tensor required to be exported to OpenCL image2d

Definition at line 71 of file CLGEMMHelpers.cpp.

72 {
73  constexpr unsigned int num_floats_per_pixel = 4;
74 
75  const unsigned int stride_y_in_elements = tensor->strides_in_bytes()[1] / tensor->element_size();
76  const unsigned int pixel_alignment = get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device());
77 
78  ARM_COMPUTE_ERROR_ON_MSG(pixel_alignment == 0, "Cannot retrieve cl_image pitch alignment");
79  if(pixel_alignment == 0)
80  {
81  return;
82  }
83 
84  const unsigned int row_pitch_alignment = pixel_alignment * num_floats_per_pixel;
85  const unsigned int round_up_width = ((stride_y_in_elements + row_pitch_alignment - 1) / row_pitch_alignment) * row_pitch_alignment;
86  const unsigned int padding = round_up_width - stride_y_in_elements;
87 
88  tensor->extend_padding(PaddingSize(0, padding, 0, 0));
89 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
BorderSize PaddingSize
Container for 2D padding size.
Definition: Types.h:382
size_t get_cl_image_pitch_alignment(const cl::Device &device)
Helper function to get the cl_image pitch alignment in pixels.
Definition: CLHelpers.cpp:373

References ARM_COMPUTE_ERROR_ON_MSG, ITensorInfo::element_size(), ITensorInfo::extend_padding(), CLKernelLibrary::get(), arm_compute::get_cl_image_pitch_alignment(), and ITensorInfo::strides_in_bytes().

Referenced by ClDirectConvolutionKernel::configure().

◆ 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.

Parameters
[in]tensor_reshaped_infoTensorInfo for the RHS reshaped matrix
[in]rhs_infoGEMMRHSMatrixInfo
Returns
Status reporting if we can use the image2d OpenCL object on the RHS reshaped matrix

Definition at line 91 of file CLGEMMHelpers.cpp.

92 {
93  if(rhs_info.export_to_cl_image)
94  {
95  ARM_COMPUTE_RETURN_ERROR_ON_MSG((rhs_info.n0 == 2) || (rhs_info.n0 == 3), "Export to cl_image only supported with n0 = 4, 8 or 16");
96  ARM_COMPUTE_RETURN_ERROR_ON_MSG((rhs_info.k0 == 2) || (rhs_info.k0 == 3), "Export to cl_image only supported with k0 = 4, 8 or 16");
97  ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(&tensor_reshaped_info, DataType::F32, DataType::F16);
98  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!image2d_from_buffer_supported(CLKernelLibrary::get().get_device()), "The extension cl_khr_image2d_from_buffer is not supported on the target platform");
99  ARM_COMPUTE_RETURN_ERROR_ON_MSG(get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) == 0, "Impossible to retrieve the cl_image pitch alignment");
100 
101  // Check the width and height of the output tensor.
102  // Since we cannot create a 3d image from a buffer, the third dimension is collapsed on the second dimension
103  const size_t max_image_w = CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_WIDTH>();
104  const size_t max_image_h = CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_HEIGHT>();
105 
106  ARM_COMPUTE_RETURN_ERROR_ON_MSG(tensor_reshaped_info.tensor_shape()[0] > max_image_w * 4, "Not supported width for cl_image");
107  ARM_COMPUTE_RETURN_ERROR_ON_MSG(tensor_reshaped_info.tensor_shape()[1] * tensor_reshaped_info.tensor_shape()[2] > max_image_h, "Not supported height for cl_image");
108  }
109 
110  return Status{};
111 }
bool image2d_from_buffer_supported(const cl::Device &device)
Helper function to check whether the cl_khr_image2d_from_buffer extension is supported.
Definition: CLHelpers.cpp:368
size_t get_cl_image_pitch_alignment(const cl::Device &device)
Helper function to get the cl_image pitch alignment in pixels.
Definition: CLHelpers.cpp:373
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
Definition: Validate.h:690

References ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MSG, GEMMRHSMatrixInfo::export_to_cl_image, arm_compute::F16, arm_compute::F32, CLKernelLibrary::get(), arm_compute::get_cl_image_pitch_alignment(), CLKernelLibrary::get_device(), arm_compute::image2d_from_buffer_supported(), GEMMRHSMatrixInfo::k0, GEMMRHSMatrixInfo::n0, and ITensorInfo::tensor_shape().

Referenced by select_lhs_rhs_info().