Compute Library
 21.08
CpuGemmMatrixAdditionKernel Class Reference

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 <CpuGemmMatrixAdditionKernel.h>

Collaboration diagram for CpuGemmMatrixAdditionKernel:
[legend]

Public Member Functions

 CpuGemmMatrixAdditionKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuGemmMatrixAdditionKernel)
 
void configure (const ITensorInfo *src, ITensorInfo *dst, float beta)
 Initialise the kernel's input and output. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
- 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *src, const ITensorInfo *dst, float beta)
 Static function to check if given info will lead to a valid configuration of CpuGemmMatrixAdditionKernel. More...
 

Detailed Description

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 44 of file CpuGemmMatrixAdditionKernel.h.

Constructor & Destructor Documentation

◆ CpuGemmMatrixAdditionKernel()

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuGemmMatrixAdditionKernel  )

◆ configure()

void configure ( const ITensorInfo src,
ITensorInfo dst,
float  beta 
)

Initialise the kernel's input and output.

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

Definition at line 133 of file CpuGemmMatrixAdditionKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, and CpuGemmMatrixAdditionKernel::validate().

134 {
137 
138  // Perform validation step
140 
141  _beta = beta;
142  switch(src->data_type())
143  {
144  case DataType::F32:
145  _func = &matrix_addition_f32;
146  break;
147  case DataType::F16:
148 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
149  _func = &matrix_addition_f16;
150  break;
151 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
152  default:
153  ARM_COMPUTE_ERROR("Data type not supported");
154  break;
155  }
156 
157  // Configure kernel window
158  Window win = calculate_max_window(*src, Steps());
159  ICPPKernel::configure(win);
160 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#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
SimpleTensor< float > src
Definition: DFT.cpp:155
1 channel, 1 F16 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, float beta)
Static function to check if given info will lead to a valid configuration of CpuGemmMatrixAdditionKer...

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 194 of file CpuGemmMatrixAdditionKernel.cpp.

195 {
196  return "CpuGemmMatrixAdditionKernel";
197 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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 178 of file CpuGemmMatrixAdditionKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::empty(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::src, and IKernel::window().

179 {
183  ARM_COMPUTE_ERROR_ON(tensors.empty());
184 
185  const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC);
186  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
187 
188  if(_beta != 0.0f)
189  {
190  (*_func)(src, dst, window, _beta);
191  }
192 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dst,
float  beta 
)
static

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

Note
The input and output tensor must have the same dimensions

Similar to CpuGemmMatrixAdditionKernel::configure()

Returns
a status

Definition at line 162 of file CpuGemmMatrixAdditionKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_UNUSED, arm_compute::F16, arm_compute::F32, and ITensorInfo::total_size().

Referenced by CpuGemmMatrixAdditionKernel::configure(), and CpuGemm::validate().

163 {
165  ARM_COMPUTE_UNUSED(beta);
166 
169 
170  if(dst->total_size() > 0)
171  {
174  }
175  return Status{};
176 }
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:115
1 channel, 1 F32 per channel
SimpleTensor< float > src
Definition: DFT.cpp:155
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788

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