Compute Library
 19.08
CLGEMMMatrixVectorMultiplyKernel Class Reference

Interface for the GEMM matrix vector multiply kernel. More...

#include <CLGEMMMatrixVectorMultiplyKernel.h>

Collaboration diagram for CLGEMMMatrixVectorMultiplyKernel:
[legend]

Public Member Functions

 CLGEMMMatrixVectorMultiplyKernel ()
 Default constructor. More...
 
 CLGEMMMatrixVectorMultiplyKernel (const CLGEMMMatrixVectorMultiplyKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLGEMMMatrixVectorMultiplyKerneloperator= (const CLGEMMMatrixVectorMultiplyKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLGEMMMatrixVectorMultiplyKernel (CLGEMMMatrixVectorMultiplyKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLGEMMMatrixVectorMultiplyKerneloperator= (CLGEMMMatrixVectorMultiplyKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output)
 Set the input and output of the kernel. 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...
 
BorderSize border_size () const override
 The size of the border for that kernel. 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...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of CLGEMMMatrixVectorMultiplyKernel. 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

Interface for the GEMM matrix vector multiply kernel.

Definition at line 34 of file CLGEMMMatrixVectorMultiplyKernel.h.

Constructor & Destructor Documentation

◆ CLGEMMMatrixVectorMultiplyKernel() [1/3]

Default constructor.

Definition at line 74 of file CLGEMMMatrixVectorMultiplyKernel.cpp.

75  : _input0(nullptr), _input1(nullptr), _output(nullptr), _num_rows_read_per_iteration(0), _border_size(0)
76 {
77 }

◆ CLGEMMMatrixVectorMultiplyKernel() [2/3]

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

◆ CLGEMMMatrixVectorMultiplyKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 78 of file CLGEMMMatrixVectorMultiplyKernel.cpp.

79 {
80  return _border_size;
81 }

Referenced by CLDepthwiseConvolutionLayer::configure(), and CLGEMMMatrixVectorMultiplyKernel::run().

◆ configure()

void configure ( const ICLTensor input0,
const ICLTensor input1,
ICLTensor output 
)

Set the input and output of the kernel.

Parameters
[in]input0The reshaped input tensor. Data types supported: QASYMM8/F16/F32
[in]input1The 2D reshaped weights tensor. Data type supported: Same as input, S32 for QASYMM8 input.
[out]outputThe output 2D tensor. Data types supported: Same as input

Definition at line 83 of file CLGEMMMatrixVectorMultiplyKernel.cpp.

84 {
85  ARM_COMPUTE_ERROR_ON_NULLPTR(input0, input1, output);
86  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input0->info(), input1->info(), output->info()));
87 
88  _input0 = input0;
89  _input1 = input1;
90  _output = output;
91 
92  // Check if is a quantized operation
93  bool is_quantized = is_data_type_quantized_asymmetric(_input0->info()->data_type());
94 
95  // Create kernel
96  CLBuildOptions build_opts;
97  build_opts.add_option_if(!is_quantized, "-DDATA_TYPE=" + get_cl_type_from_data_type(input0->info()->data_type()));
98  build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input0->info()->dimension(0)));
99  build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(input0->info()->dimension(1)));
100 
101  std::string kernel_name = is_quantized ? std::string("gemm_mv_quantized") : std::string("gemm_mv");
102  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
103 
104  // Add static arguments
105  if(is_quantized)
106  {
107  const UniformQuantizationInfo iq0_info = _input0->info()->quantization_info().uniform();
108  const UniformQuantizationInfo iq1_info = _input1->info()->quantization_info().uniform();
109 
111  _kernel.setArg<int>(idx++, -iq0_info.offset);
112  _kernel.setArg<int>(idx++, -iq1_info.offset);
113  }
114 
115  // Configure kernel window
116  _num_rows_read_per_iteration = num_rows_read_per_iteration;
117 
118  const unsigned int border_x = ceil_to_multiple(input0->info()->dimension(0), num_elems_read_per_iteration) - input0->info()->dimension(0);
119  const unsigned int border_y = ceil_to_multiple(input0->info()->dimension(1), _num_rows_read_per_iteration) - input0->info()->dimension(1);
120 
121  _border_size = BorderSize(border_y, border_x);
122 
123  auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info());
124  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
125  ICLKernel::configure_internal(win_config.second);
126 }
static constexpr unsigned int num_arguments_per_1D_tensor()
Returns the number of arguments enqueued per 1D tensor object.
Definition: ICLKernel.h:184
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:200
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
Definition: Utils.h:66
UniformQuantizationInfo uniform() const
Return per layer quantization info.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:35
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:192
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
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1030
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::ceil_to_multiple(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::is_data_type_quantized_asymmetric(), ICLKernel::num_arguments_per_1D_tensor(), ICLKernel::num_arguments_per_2D_tensor(), ICLKernel::num_arguments_per_3D_tensor(), UniformQuantizationInfo::offset, ITensorInfo::quantization_info(), arm_compute::support::cpp11::to_string(), QuantizationInfo::uniform(), and arm_compute::validate_and_configure_window().

Referenced by CLDepthwiseConvolutionLayer::configure().

◆ 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 136 of file CLGEMMMatrixVectorMultiplyKernel.cpp.

137 {
140 
141  Window slice_in = window.first_slice_window_3D();
142  Window slice_in2 = window.first_slice_window_3D();
143  Window slice_out = window.first_slice_window_3D();
144 
145  // Setup input0 slice
146  slice_in.set(Window::DimX, Window::Dimension(0, _input0->info()->dimension(0), _input0->info()->dimension(0)));
147  slice_in.set(Window::DimY, Window::Dimension(0, _input0->info()->dimension(1) + border_size().bottom, _num_rows_read_per_iteration));
148  slice_in.set(Window::DimZ, Window::Dimension(0, _input0->info()->dimension(2), 1));
149 
150  // Setup input1 and output slice. Their dimensions are increased in the cl kernel.
151  slice_in2.set(Window::DimX, Window::Dimension(0, 0, 0));
152  slice_in2.set(Window::DimY, Window::Dimension(0, 0, 0));
153  slice_in2.set(Window::DimZ, Window::Dimension(0, 0, 0));
154 
155  slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
156  slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
157  slice_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
158 
159  unsigned int idx_1 = num_arguments_per_3D_tensor();
160 
161  add_2D_tensor_argument(idx_1, _input1, slice_in2);
162 
163  do
164  {
165  unsigned int idx_0 = 0;
166  unsigned int idx_2 = num_arguments_per_3D_tensor() + num_arguments_per_2D_tensor();
167  add_3D_tensor_argument(idx_0, _input0, slice_in);
168  add_1D_tensor_argument(idx_2, _output, slice_out);
169  enqueue(queue, *this, slice_in, lws_hint());
170  }
171  while(window.slide_window_slice_3D(slice_in) && window.slide_window_slice_3D(slice_out));
172 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
BorderSize border_size() const override
The size of the border for that kernel.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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:341
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 size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
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.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:48
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:192
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:319
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's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:134
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
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.
Definition: ICLKernel.h:110
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ICLKernel::add_1D_tensor_argument(), ICLKernel::add_2D_tensor_argument(), ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, CLGEMMMatrixVectorMultiplyKernel::border_size(), BorderSize::bottom, ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::enqueue(), Window::first_slice_window_3D(), ITensor::info(), ICLKernel::lws_hint(), ICLKernel::num_arguments_per_2D_tensor(), ICLKernel::num_arguments_per_3D_tensor(), Window::set(), Window::slide_window_slice_3D(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input0,
const ITensorInfo input1,
const ITensorInfo output 
)
static

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

Parameters
[in]input0The reshaped input tensor. Data types supported: QASYMM8/F16/F32
[in]input1The 2D reshaped weights tensor. Data type supported: Same as input, S32 for QASYMM8 input.
[in]outputThe output 2D tensor. Data types supported: Same as input
Returns
a status

Definition at line 128 of file CLGEMMMatrixVectorMultiplyKernel.cpp.

129 {
130  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input0, input1, output));
131  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input0->clone().get(), input1->clone().get(), output->clone().get()).first);
132 
133  return Status{};
134 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by CLDepthwiseConvolutionLayer::validate().


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