Compute Library
 21.08
CpuGemmLowpOffsetContributionKernel Class Reference

Kernel used to add the offset contribution after CpuGemmLowpMatrixMultiplyKernel. More...

#include <CpuGemmLowpOffsetContributionKernel.h>

Collaboration diagram for CpuGemmLowpOffsetContributionKernel:
[legend]

Public Member Functions

 CpuGemmLowpOffsetContributionKernel ()=default
 Default constructor. More...
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuGemmLowpOffsetContributionKernel)
 
void configure (ITensorInfo *mm_result, ITensorInfo *vector_sum_col, ITensorInfo *vector_sum_row, int32_t k, int32_t a_offset, int32_t b_offset)
 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 *mm_result, const ITensorInfo *vector_sum_col, const ITensorInfo *vector_sum_row, int32_t a_offset, int32_t b_offset)
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Kernel used to add the offset contribution after CpuGemmLowpMatrixMultiplyKernel.

The computation is performed in-place

This kernel takes a final int32 accumulator value (the output of CpuGemmLowpMatrixMultiplyKernel), and adds to it the offset contribution of matrix A and matrix B in-place.

The final result is:

mm_result[i][k] = mm_result[i][k] + (vector_sum_col[k] * a_offset) + (vector_sum_row[i] * b_offset) + (a_offset * b_offset * k)

Definition at line 49 of file CpuGemmLowpOffsetContributionKernel.h.

Constructor & Destructor Documentation

◆ CpuGemmLowpOffsetContributionKernel()

Default constructor.

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuGemmLowpOffsetContributionKernel  )

◆ configure()

void configure ( ITensorInfo mm_result,
ITensorInfo vector_sum_col,
ITensorInfo vector_sum_row,
int32_t  k,
int32_t  a_offset,
int32_t  b_offset 
)

Initialise the kernel's input and output.

Parameters
[in,out]mm_resultInput tensor containing the result of CpuGemmLowpMatrixMultiplyKernel. Data type supported: S32
[in]vector_sum_colInput row-vector of sums of all the entries in each column of matrix B. Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: same as mm_result
[in]vector_sum_rowInput row-vector of sums of all the entries in each row of matrix A. Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: same as mm_result
[in]kNumber of matrix A columns or Matrix B rows
[in]a_offsetOffset to be added to each element of the matrix A.
[in]b_offsetOffset to be added to each element of the matrix B.

Definition at line 361 of file CpuGemmLowpOffsetContributionKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::calculate_max_window(), Dimensions< T >::num_dimensions(), and ITensorInfo::tensor_shape().

362 {
363  // Perform validate step
364  ARM_COMPUTE_UNUSED(vector_sum_row);
365  ARM_COMPUTE_ERROR_ON_NULLPTR(mm_result);
366  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(mm_result, vector_sum_col, vector_sum_row, a_offset, b_offset));
367 
368  _a_offset = a_offset;
369  _b_offset = b_offset;
370  _k_offset = a_offset * b_offset * k;
371 
372  // If a_offset == 0, vector_sum_col can be a nullptr
373  if(a_offset != 0)
374  {
375  // Check if vector_sum_col_shape should be slidden or not
376  // Don't slide vector_sum_col_shape along the y dimension if vector_sum_col_shape has just 1 dimension and vector_sum_row_shape more than 1
377  // This scenario can happen when the the matrix multiplication is used to perform a convolution operation
378  _slide_vector_sum_col = vector_sum_col->tensor_shape().num_dimensions() > 1;
379  }
380 
381  // Configure kernel window
382  Window win = calculate_max_window(*mm_result, Steps());
383  ICpuKernel::configure(win);
384 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 411 of file CpuGemmLowpOffsetContributionKernel.cpp.

412 {
413  return "CpuGemmLowpOffsetContributionKernel";
414 }

◆ 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 393 of file CpuGemmLowpOffsetContributionKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), ITensor::info(), ITensorInfo::num_dimensions(), and IKernel::window().

394 {
398 
399  auto vector_sum_col = tensors.get_const_tensor(TensorType::ACL_SRC_0);
400  auto vector_sum_row = tensors.get_const_tensor(TensorType::ACL_SRC_1);
401  auto mm_result = tensors.get_tensor(TensorType::ACL_DST);
402 
403  // Check if input is a 3D reinterpretation
404  const bool reinterpret_as_3d = vector_sum_row != nullptr
405  && mm_result->info()->num_dimensions() > 1
406  && mm_result->info()->tensor_shape().y() != vector_sum_row->info()->tensor_shape().x();
407 
408  run_offset_contribution(window, mm_result, vector_sum_col, vector_sum_row, _a_offset, _b_offset, _k_offset, _slide_vector_sum_col, reinterpret_as_3d);
409 }
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: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 mm_result,
const ITensorInfo vector_sum_col,
const ITensorInfo vector_sum_row,
int32_t  a_offset,
int32_t  b_offset 
)
static

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

Similar to CpuGemmLowpOffsetContributionKernel::configure()

Returns
a status

Definition at line 386 of file CpuGemmLowpOffsetContributionKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CpuGemmLowpMatrixMultiplyCore::validate().

388 {
389  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(mm_result, vector_sum_col, vector_sum_row, a_offset, b_offset));
390  return Status{};
391 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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