Compute Library
 19.11
CLGEMMReshapeLHSMatrixKernel Class Reference

OpenCL kernel to reshape the LHS matrix when performing the matrix multiplication. More...

#include <CLGEMMReshapeLHSMatrixKernel.h>

Collaboration diagram for CLGEMMReshapeLHSMatrixKernel:
[legend]

Public Member Functions

 CLGEMMReshapeLHSMatrixKernel ()
 Default constructor. More...
 
 CLGEMMReshapeLHSMatrixKernel (const CLGEMMReshapeLHSMatrixKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLGEMMReshapeLHSMatrixKerneloperator= (const CLGEMMReshapeLHSMatrixKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLGEMMReshapeLHSMatrixKernel (CLGEMMReshapeLHSMatrixKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLGEMMReshapeLHSMatrixKerneloperator= (CLGEMMReshapeLHSMatrixKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLTensor *input, ICLTensor *output, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d=false)
 Initialise the kernel's input and output. More...
 
void run (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...
 
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...
 
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...
 
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<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...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
- 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d)
 Static function to check if given info will lead to a valid configuration of CLGEMMReshapeLHSMatrixKernel. More...
 
- Static Public Member Functions inherited from ICLKernel
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 reshape the LHS matrix when performing the matrix multiplication.

In particular, this function splits the input matrix in blocks of size M0xK0 (defined through GEMMLHSInfo) and stores each one in the output matrix unrolling the values

Definition at line 37 of file CLGEMMReshapeLHSMatrixKernel.h.

Constructor & Destructor Documentation

◆ CLGEMMReshapeLHSMatrixKernel() [1/3]

Default constructor.

Definition at line 117 of file CLGEMMReshapeLHSMatrixKernel.cpp.

118  : _input(nullptr), _output(nullptr), _reinterpret_input_as_3d(false)
119 {
120 }

◆ CLGEMMReshapeLHSMatrixKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLGEMMReshapeLHSMatrixKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input,
ICLTensor output,
const GEMMLHSMatrixInfo lhs_info,
bool  reinterpret_input_as_3d = false 
)

Initialise the kernel's input and output.

Parameters
[in]inputInput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[out]outputOutput tensor. Data type supported: same as input
[in]lhs_infoLHS matrix information to be used for reshaping. This object contains all the necessary information to reshape the input tensor. Only the following values are supported: lhs_info.m0: 2,3,4,5,6,7,8 lhs_info.k0: 2,3,4,8,16 lhs_info.v0: greater than 0 lhs_info.transpose: true, false lhs_info.interleave: true, false
[in]reinterpret_input_as_3d(Optional) True if the input has to be reinterpreted as 3D tensor

Definition at line 122 of file CLGEMMReshapeLHSMatrixKernel.cpp.

123 {
125 
126  // Perform validate step
127  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), lhs_info, reinterpret_input_as_3d));
128 
129  _input = input;
130  _output = output;
131  _reinterpret_input_as_3d = reinterpret_input_as_3d;
132 
133  // Create build options
134  CLBuildOptions build_opts;
135  build_opts.add_option("-DM0=" + support::cpp11::to_string(lhs_info.m0));
136  build_opts.add_option("-DK0=" + support::cpp11::to_string(lhs_info.k0));
137  build_opts.add_option("-DV0=" + support::cpp11::to_string(lhs_info.v0));
138  build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input->info()->dimension(0)));
139  build_opts.add_option_if(lhs_info.interleave, "-DINTERLEAVE");
140  build_opts.add_option_if(_reinterpret_input_as_3d, "-DREINTERPRET_INPUT_AS_3D");
141  build_opts.add_option_if(_reinterpret_input_as_3d, "-DHEIGHT_GEMM3D=" + support::cpp11::to_string(input->info()->dimension(1)));
142  build_opts.add_option_if(_reinterpret_input_as_3d, "-DDEPTH_GEMM3D=" + support::cpp11::to_string(input->info()->dimension(2)));
143  build_opts.add_option("-DDATA_TYPE=" + get_cl_unsigned_type_from_element_size(input->info()->element_size()));
144 
145  std::string kernel_name("gemm_reshape_lhs_matrix_");
146  kernel_name += lhs_info.transpose ? "t" : "nt";
147 
148  // Create kernel
149  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
150 
151  // Configure kernel window
152  auto win_config = validate_and_configure_window(input->info(), output->info(), lhs_info, reinterpret_input_as_3d);
153  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
154  ICLKernel::configure_internal(win_config.second);
155 
156  // Set config_id for enabling LWS tuning
157  _config_id = "gemm_reshape_lhs_matrix_";
158  _config_id += (_reinterpret_input_as_3d ? "3d_" : "");
159  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
160  _config_id += "_";
161  _config_id += support::cpp11::to_string(output->info()->dimension(0));
162  _config_id += "_";
163  _config_id += support::cpp11::to_string(output->info()->dimension(1));
164  _config_id += "_";
165  _config_id += support::cpp11::to_string(output->info()->dimension(2));
166  _config_id += "_";
167  _config_id += support::cpp11::to_string(lhs_info.m0);
168  _config_id += "_";
169  _config_id += support::cpp11::to_string(lhs_info.k0);
170  _config_id += "_";
171  _config_id += support::cpp11::to_string(lhs_info.v0);
172  _config_id += "_";
173  _config_id += support::cpp11::to_string(lhs_info.interleave);
174  _config_id += "_";
175  _config_id += support::cpp11::to_string(lhs_info.transpose);
176 }
std::string to_string(T &&value)
Convert integer and float values to string.
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:333
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
std::string get_cl_unsigned_type_from_element_size(size_t element_size)
Translates the element size to an unsigned integer data type.
Definition: CLHelpers.cpp:101

References CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::create_kernel(), ITensorInfo::dimension(), CLKernelLibrary::get(), arm_compute::get_cl_unsigned_type_from_element_size(), ITensor::info(), arm_compute::test::validation::input, GEMMLHSMatrixInfo::interleave, GEMMLHSMatrixInfo::k0, arm_compute::lower_string(), GEMMLHSMatrixInfo::m0, CLBuildOptions::options(), arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), GEMMLHSMatrixInfo::transpose, and GEMMLHSMatrixInfo::v0.

◆ operator=() [1/2]

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

Allow instances of this class to be moved.

◆ run()

void run ( 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]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.

Implements ICLKernel.

Definition at line 186 of file CLGEMMReshapeLHSMatrixKernel.cpp.

187 {
190 
192 
193  if(_reinterpret_input_as_3d)
194  {
195  // Pass bottom paddings to the kernel if the input has to be reinterpreted as 3D tensor
196  const unsigned int idx0 = 2 * num_arguments_per_3D_tensor();
197  const unsigned int total_cross_plane_pad = _input->info()->padding().top + _input->info()->padding().bottom;
198  _kernel.setArg<cl_uint>(idx0, static_cast<unsigned int>(total_cross_plane_pad));
199  }
200 
201  do
202  {
203  unsigned int idx = 0;
204  add_3D_tensor_argument(idx, _input, slice);
205  add_3D_tensor_argument(idx, _output, slice);
206  enqueue(queue, *this, slice, lws_hint());
207  }
209 }
unsigned int top
top of the border
Definition: Types.h:348
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:39
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
unsigned int bottom
bottom of the border
Definition: Types.h:350
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.
Definition: ICLKernel.h:158
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:200
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual PaddingSize padding() const =0
Padding of tensor.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:333
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:289
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, BorderSize::bottom, arm_compute::enqueue(), Window::first_slice_window_3D(), ITensor::info(), ICLKernel::lws_hint(), ICLKernel::num_arguments_per_3D_tensor(), ITensorInfo::padding(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), BorderSize::top, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const GEMMLHSMatrixInfo lhs_info,
bool  reinterpret_input_as_3d 
)
static

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

Parameters
[in]inputInput tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]outputOutput tensor info which stores the interleaved matrix. Data type supported: same as input.
[in]lhs_infoLHS matrix information to be used for reshaping. This object contains all the necessary information to reshape the input tensor. Only the following values are supported: lhs_info.m0: 2,3,4,5,6,7,8 lhs_info.k0: 2,3,4,8,16 lhs_info.v0: greater than 0 lhs_info.transpose: true, false lhs_info.interleave: true, false
[in]reinterpret_input_as_3dTrue if the input has to be reinterpreted as 3D tensor
Returns
a status

Definition at line 178 of file CLGEMMReshapeLHSMatrixKernel.cpp.

179 {
180  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, lhs_info, reinterpret_input_as_3d));
181  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), lhs_info, reinterpret_input_as_3d).first);
182 
183  return Status{};
184 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), and arm_compute::test::validation::input.


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