Compute Library
 19.08
NEGEMMMatrixVectorMultiplyKernel Class Reference

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

#include <NEGEMMMatrixVectorMultiplyKernel.h>

Collaboration diagram for NEGEMMMatrixVectorMultiplyKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEGEMMMatrixVectorMultiplyKernel ()
 Default constructor. More...
 
 NEGEMMMatrixVectorMultiplyKernel (const NEGEMMMatrixVectorMultiplyKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEGEMMMatrixVectorMultiplyKerneloperator= (const NEGEMMMatrixVectorMultiplyKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEGEMMMatrixVectorMultiplyKernel (NEGEMMMatrixVectorMultiplyKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGEMMMatrixVectorMultiplyKerneloperator= (NEGEMMMatrixVectorMultiplyKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ITensor *input0, const ITensor *input1, ITensor *output)
 Initialise the kernel's input and output. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. More...
 
- Public Member Functions inherited from ICPPSimpleKernel
 ICPPSimpleKernel ()
 Constructor. More...
 
 ICPPSimpleKernel (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICPPSimpleKerneloperator= (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICPPSimpleKernel (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
ICPPSimpleKerneloperator= (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~ICPPSimpleKernel ()=default
 Default destructor. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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...
 
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 NEGEMMMatrixVectorMultiplyKernel. More...
 

Detailed Description

Interface for the GEMM matrix vector multiply kernel.

Definition at line 34 of file NEGEMMMatrixVectorMultiplyKernel.h.

Constructor & Destructor Documentation

◆ NEGEMMMatrixVectorMultiplyKernel() [1/3]

Default constructor.

Definition at line 247 of file NEGEMMMatrixVectorMultiplyKernel.cpp.

248  : _func(nullptr), _input0(nullptr), _input1(nullptr), _output(nullptr), _border_size(0)
249 {
250 }

◆ NEGEMMMatrixVectorMultiplyKernel() [2/3]

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

◆ NEGEMMMatrixVectorMultiplyKernel() [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 252 of file NEGEMMMatrixVectorMultiplyKernel.cpp.

253 {
254  return _border_size;
255 }

Referenced by NEDepthwiseConvolutionLayer::configure().

◆ configure()

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

Initialise the kernel's input and output.

Parameters
[in]input0First Input tensor. Data types supported: QASYMM8/F16/F32
[in]input1Second Input tensor. Data types supported: same as input.
[out]outputOutput tensor which stores the interleaved matrix. Data type supported: same as input, S32 for QASYMM8 input.

Definition at line 257 of file NEGEMMMatrixVectorMultiplyKernel.cpp.

258 {
259  ARM_COMPUTE_ERROR_ON_NULLPTR(input0, input1, output);
260 
261  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input0->info(), input1->info(), output->info()));
262 
263  _input0 = input0;
264  _input1 = input1;
265  _output = output;
266 
267  // Set appropriate function to run
268  switch(input0->info()->data_type())
269  {
270  case DataType::QASYMM8:
271  _func = &NEGEMMMatrixVectorMultiplyKernel::matrix_vector_multiply<uint8_t, uint8_t, int32_t>;
272  break;
273 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
274  case DataType::F16:
275  _func = &NEGEMMMatrixVectorMultiplyKernel::matrix_vector_multiply<half, half, half>;
276  break;
277 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
278  case DataType::F32:
279  _func = &NEGEMMMatrixVectorMultiplyKernel::matrix_vector_multiply<float, float, float>;
280  break;
281  default:
282  ARM_COMPUTE_ERROR("Unsupported data type");
283  }
284 
285  // Configure kernel window
286  const unsigned int num_elems_read_per_iteration = 16 / _input0->info()->element_size();
287 
288  const unsigned int border_x = ceil_to_multiple(input0->info()->dimension(0), num_elems_read_per_iteration) - input0->info()->dimension(0);
289  _border_size = BorderSize(0, border_x);
290 
291  auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info());
292  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
293  INEKernel::configure(win_config.second);
294 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Container for 2D border size.
Definition: Types.h:259
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)
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
1 channel, 1 F16 per channel
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
quantized, asymmetric fixed-point 8-bit number
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::ceil_to_multiple(), ITensorInfo::data_type(), ITensorInfo::dimension(), ITensorInfo::element_size(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::QASYMM8, and arm_compute::validate_and_configure_window().

Referenced by NEDepthwiseConvolutionLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 37 of file NEGEMMMatrixVectorMultiplyKernel.h.

38  {
39  return "NEGEMMMatrixVectorMultiplyKernel";
40  }

◆ 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,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 304 of file NEGEMMMatrixVectorMultiplyKernel.cpp.

305 {
309 
310  Window window_slice = window.first_slice_window_3D();
311 
312  Window window_in(window);
313  Window window_weights(window_slice);
314  Window window_out(window);
315 
316  // Setup input0 slice
317  window_in.set(Window::DimX, Window::Dimension(0, _input0->info()->dimension(0), _input0->info()->dimension(0)));
318  window_in.set(Window::DimY, Window::Dimension(0, _input0->info()->dimension(1), 1));
319  window_in.set(Window::DimZ, Window::Dimension(0, _input0->info()->dimension(2), 1));
320 
321  // Setup input1 and output slice. Their dimensions are increased in the kernel.
322  window_weights.set(Window::DimX, Window::Dimension(0, 0, 0));
323  window_weights.set(Window::DimY, Window::Dimension(0, 0, 0));
324  window_weights.set(Window::DimZ, Window::Dimension(0, 0, 0));
325 
326  window_out.set(Window::DimX, Window::Dimension(0, 0, 0));
327  window_out.set(Window::DimY, Window::Dimension(0, 0, 0));
328  window_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
329 
330  if(_func != nullptr)
331  {
332  (this->*_func)(window_in, window_weights, window_out);
333  }
334 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
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

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, Window::first_slice_window_3D(), ITensor::info(), arm_compute::test::validation::info, Window::set(), 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 NEGEMMMatrixVectorMultiplyKernel.

Parameters
[in]input0First Input tensor. Data types supported: QASYMM8/F16/F32
[in]input1Second Input tensor. Data types supported: same as input.
[in]outputOutput tensor which stores the interleaved matrix. Data type supported: same as input, S32 for QASYMM8 input.
Returns
a status

Definition at line 296 of file NEGEMMMatrixVectorMultiplyKernel.cpp.

297 {
298  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input0, input1, output);
299  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input0, input1, output));
300  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input0->clone().get(), input1->clone().get(), output->clone().get()).first);
301  return Status{};
302 }
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163

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

Referenced by NEDepthwiseConvolutionLayer::validate().


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