Compute Library
 19.08
CLLocallyConnectedMatrixMultiplyKernel Class Reference

OpenCL kernel to multiply each row of first tensor with low 2 dimensions of second tensor. More...

#include <CLLocallyConnectedMatrixMultiplyKernel.h>

Collaboration diagram for CLLocallyConnectedMatrixMultiplyKernel:
[legend]

Public Member Functions

 CLLocallyConnectedMatrixMultiplyKernel ()
 Default constructor. More...
 
 CLLocallyConnectedMatrixMultiplyKernel (const CLLocallyConnectedMatrixMultiplyKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLLocallyConnectedMatrixMultiplyKerneloperator= (const CLLocallyConnectedMatrixMultiplyKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLLocallyConnectedMatrixMultiplyKernel (CLLocallyConnectedMatrixMultiplyKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLLocallyConnectedMatrixMultiplyKerneloperator= (CLLocallyConnectedMatrixMultiplyKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output)
 Initialise the kernel's input, output and alpha. 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 *input0, const ITensorInfo *input1, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of CLLocallyConnectedMatrixMultiplyKernel. 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 multiply each row of first tensor with low 2 dimensions of second tensor.

Attention
The second input tensor must have at least 2 dimensions (matrix)

Definition at line 38 of file CLLocallyConnectedMatrixMultiplyKernel.h.

Constructor & Destructor Documentation

◆ CLLocallyConnectedMatrixMultiplyKernel() [1/3]

Default constructor.

Definition at line 44 of file CLLocallyConnectedMatrixMultiplyKernel.cpp.

45  : _input0(nullptr), _input1(nullptr), _output(nullptr)
46 {
47 }

◆ CLLocallyConnectedMatrixMultiplyKernel() [2/3]

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

◆ CLLocallyConnectedMatrixMultiplyKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

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

Initialise the kernel's input, output and alpha.

Parameters
[in]input0First input tensor. Data types supported: F32
[in]input1Second input tensor. Data type supported: same as input0
[out]outputOutput tensor to store the result. Data type supported: same as input0

Definition at line 84 of file CLLocallyConnectedMatrixMultiplyKernel.cpp.

85 {
86  ARM_COMPUTE_ERROR_ON_NULLPTR(input0, input1, output);
87  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input0->info(), input1->info(), output->info()));
88 
89  _input0 = input0;
90  _input1 = input1;
91  _output = output;
92 
93  cl::NDRange lws_hint;
94  if(output->info()->dimension(1) == 196)
95  {
96  lws_hint = cl::NDRange(1, 7);
97  }
98  else
99  {
100  lws_hint = cl::NDRange(8, 8);
101  }
102 
103  std::ostringstream mm_arguments;
104  std::set<std::string> build_opts;
105 
106  mm_arguments << "-DWIDTH_VECTOR_A=" << input0->info()->dimension(0) << " ";
107  build_opts.emplace(mm_arguments.str());
108 
109  // Create kernel
110  std::string data_type_name = lower_string(string_from_data_type(input0->info()->data_type()));
111  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(("gemm_lc_vm_" + data_type_name), build_opts));
112 
113  // Configure kernel window
114  auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info());
115 
116  ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config));
117 
118  ICLKernel::configure_internal(std::get<1>(win_config), lws_hint);
119 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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)
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
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
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), CLKernelLibrary::get(), ITensor::info(), arm_compute::lower_string(), ICLKernel::lws_hint(), arm_compute::string_from_data_type(), and arm_compute::validate_and_configure_window().

Referenced by CLLocallyConnectedLayer::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 129 of file CLLocallyConnectedMatrixMultiplyKernel.cpp.

130 {
133 
135 
136  Window matrix_b_window;
137  matrix_b_window.use_tensor_dimensions(_input1->info()->tensor_shape());
138  Window slice_matrix_b = matrix_b_window.first_slice_window_3D();
139 
140  do
141  {
142  unsigned int idx = 0;
143  add_2D_tensor_argument(idx, _input0, slice);
144  add_3D_tensor_argument(idx, _input1, slice_matrix_b);
145  add_2D_tensor_argument(idx, _output, slice);
146  enqueue(queue, *this, slice, lws_hint());
147  }
149 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
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
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
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
Definition: Window.inl:250
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:307
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_2D_tensor_argument(), ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), Window::first_slice_window_3D(), ITensor::info(), ICLKernel::lws_hint(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), ITensorInfo::tensor_shape(), Window::use_tensor_dimensions(), 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 CLLocallyConnectedMatrixMultiplyKernel.

Parameters
[in]input0First input tensor info. Data types supported: F32
[in]input1Second input tensor info. Data type supported: same as input0
[in]outputOutput tensor info. Data type supported: same as input0
Returns
a status

Definition at line 121 of file CLLocallyConnectedMatrixMultiplyKernel.cpp.

122 {
123  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input0, input1, output));
124  ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input0->clone().get(), input1->clone().get(), output->clone().get())));
125 
126  return Status{};
127 }
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
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

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

Referenced by CLLocallyConnectedLayer::validate().


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