Compute Library
 21.02
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...
 
 ~NEGEMMMatrixAdditionKernel ()=default
 Default destructor. 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...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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 113 of file NEGEMMMatrixAdditionKernel.cpp.

Referenced by NEGEMMMatrixAdditionKernel::name().

114  : INESimpleKernel(), _func(nullptr), _beta(0.0f)
115 {
116 }
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.

◆ ~NEGEMMMatrixAdditionKernel()

Default destructor.

Referenced by NEGEMMMatrixAdditionKernel::name().

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

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

Referenced by NEGEMMMatrixAdditionKernel::name().

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

◆ name()

◆ operator=() [1/2]

NEGEMMMatrixAdditionKernel& operator= ( const NEGEMMMatrixAdditionKernel )
delete

Prevent instances of this class from being copied.

Referenced by NEGEMMMatrixAdditionKernel::name().

◆ 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.

Reimplemented from ICPPKernel.

Definition at line 153 of file NEGEMMMatrixAdditionKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NEGEMMMatrixAdditionKernel::name().

154 {
158 
159  if(_beta != 0.0f)
160  {
161  (*_func)(_input, _output, window, _beta);
162  }
163 }
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:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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

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

Referenced by NEGEMMMatrixAdditionKernel::name(), and NEGEMM::validate().

147 {
149  ARM_COMPUTE_RETURN_ON_ERROR(INESimpleKernel::validate(input->clone().get(), output->clone().get(), num_elems_processed_per_iteration));
150  return Status{};
151 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
unsigned int num_elems_processed_per_iteration

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