Compute Library
 19.08
NEGEMMMatrixAdditionKernel Class Reference

NEON kernel to perform the in-place matrix addition between 2 matrices taking into account that the second matrix might be weighted by a scalar value beta: More...

#include <NEGEMMMatrixAdditionKernel.h>

Collaboration diagram for NEGEMMMatrixAdditionKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEGEMMMatrixAdditionKernel ()
 Constructor. More...
 
 NEGEMMMatrixAdditionKernel (const NEGEMMMatrixAdditionKernel &)=delete
 Prevent instances of this class from being copied. More...
 
NEGEMMMatrixAdditionKerneloperator= (const NEGEMMMatrixAdditionKernel &)=delete
 Prevent instances of this class from being copied. More...
 
 NEGEMMMatrixAdditionKernel (NEGEMMMatrixAdditionKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGEMMMatrixAdditionKerneloperator= (NEGEMMMatrixAdditionKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ITensor *input, ITensor *output, float beta)
 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...
 
- 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...
 
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, float beta)
 Static function to check if given info will lead to a valid configuration of NEGEMMMatrixAdditionKernel. More...
 

Detailed Description

NEON kernel to perform the in-place matrix addition between 2 matrices taking into account that the second matrix might be weighted by a scalar value beta:

Note
[ MTX_OUT = MTX_0 + beta * MTX_1 ] with MTX_0 and MTX_1 of the same size
This stage is used to finalize the GEMM result and it is computed if and only if beta != 0.0. In case this kernel is used for finalizing GEMM result, we have:

Definition at line 41 of file NEGEMMMatrixAdditionKernel.h.

Constructor & Destructor Documentation

◆ NEGEMMMatrixAdditionKernel() [1/3]

Constructor.

Definition at line 111 of file NEGEMMMatrixAdditionKernel.cpp.

112  : INESimpleKernel(), _func(nullptr), _beta(0.0f)
113 {
114 }
ICPPSimpleKernel INESimpleKernel
Interface for simple NEON kernels having 1 tensor input and 1 tensor output.

◆ NEGEMMMatrixAdditionKernel() [2/3]

Prevent instances of this class from being copied.

◆ NEGEMMMatrixAdditionKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
float  beta 
)

Initialise the kernel's input and output.

Note
The input and output tensor must have the same dimensions
Parameters
[in]inputInput tensor (Matrix C). Data types supported: F16/F32
[in,out]outputOutput tensor. If this kernel is used to finalize the GEMM result, output contains the result obtained by the kernel NEGEMMMatrixMultiplyKernel. Data type supported: the same as input.
[in]betaWeight of matrix C

Definition at line 116 of file NEGEMMMatrixAdditionKernel.cpp.

117 {
118  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
119 
120  // Perform validation step
121  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), beta));
122 
123  switch(input->info()->data_type())
124  {
125  case DataType::F32:
126  _func = &matrix_addition_f32;
127  break;
128  case DataType::F16:
129 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
130  _func = &matrix_addition_f16;
131  break;
132 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
133  default:
134  ARM_COMPUTE_ERROR("Data type not supported");
135  break;
136  }
137 
138  // Configure kernel window
139  INESimpleKernel::configure(input, output, num_elems_processed_per_iteration);
140 
141  _beta = beta;
142 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
1 channel, 1 F16 per channel
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, and ITensor::info().

Referenced by NEGEMM::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 44 of file NEGEMMMatrixAdditionKernel.h.

45  {
46  return "NEGEMMMatrixAdditionKernel";
47  }

◆ operator=() [1/2]

NEGEMMMatrixAdditionKernel& operator= ( const NEGEMMMatrixAdditionKernel )
delete

Prevent instances of this class from being copied.

◆ 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 151 of file NEGEMMMatrixAdditionKernel.cpp.

152 {
156 
157  if(_beta != 0.0f)
158  {
159  (*_func)(_input, _output, window, _beta);
160  }
161 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#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, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
float  beta 
)
static

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

Note
The input and output tensor must have the same dimensions
Parameters
[in]inputInput tensor info (Matrix C). Data types supported: F16/F32
[in]outputOutput tensor info. If this kernel is used to finalize the GEMM result, output contains the result obtained by the kernel NEGEMMMatrixMultiplyKernel. Data type supported: the same as input.
[in]betaWeight of matrix C
Returns
a status

Definition at line 144 of file NEGEMMMatrixAdditionKernel.cpp.

145 {
146  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, beta));
147  ARM_COMPUTE_RETURN_ON_ERROR(INESimpleKernel::validate(input->clone().get(), output->clone().get(), num_elems_processed_per_iteration));
148  return Status{};
149 }
#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, and ICloneable< T >::clone().

Referenced by NEGEMM::validate().


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