Compute Library
 19.08
NEArithmeticAdditionKernel Class Reference

Interface for the kernel to perform addition between two tensors. More...

#include <NEArithmeticAdditionKernel.h>

Collaboration diagram for NEArithmeticAdditionKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEArithmeticAdditionKernel ()
 Default constructor. More...
 
 NEArithmeticAdditionKernel (const NEArithmeticAdditionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEArithmeticAdditionKerneloperator= (const NEArithmeticAdditionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEArithmeticAdditionKernel (NEArithmeticAdditionKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEArithmeticAdditionKerneloperator= (NEArithmeticAdditionKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEArithmeticAdditionKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input1, const ITensor *input2, ITensor *output, ConvertPolicy policy)
 Initialise the kernel's input, output and border mode. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. 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 *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
 Static function to check if given info will lead to a valid configuration of NEArithmeticAdditionKernel. More...
 

Detailed Description

Interface for the kernel to perform addition between two tensors.

Definition at line 35 of file NEArithmeticAdditionKernel.h.

Constructor & Destructor Documentation

◆ NEArithmeticAdditionKernel() [1/3]

Default constructor.

Definition at line 718 of file NEArithmeticAdditionKernel.cpp.

719  : _func(nullptr), _input1(nullptr), _input2(nullptr), _output(nullptr), _policy()
720 {
721 }

◆ NEArithmeticAdditionKernel() [2/3]

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

◆ NEArithmeticAdditionKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEArithmeticAdditionKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input1,
const ITensor input2,
ITensor output,
ConvertPolicy  policy 
)

Initialise the kernel's input, output and border mode.

Valid configurations (Input1,Input2) -> Output :

  • (U8,U8) -> U8
  • (U8,U8) -> S16
  • (S16,U8) -> S16
  • (U8,S16) -> S16
  • (S16,S16) -> S16
  • (F16,F16) -> F16
  • (F32,F32) -> F32
  • (QASYMM8,QASYMM8) -> QASYMM8
  • (QSYMM16,QSYMM16) -> QSYMM16
Parameters
[in]input1An input tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32
[in]input2An input tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32
[out]outputThe output tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32.
[in]policyOverflow policy.

Definition at line 723 of file NEArithmeticAdditionKernel.cpp.

724 {
725  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
726  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info(), policy));
727 
728  // Configure kernel window
729  auto win_config = validate_and_configure_window(*input1->info(), *input2->info(), *output->info());
730  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
731 
732  static std::map<std::string, AddFunction *> map_function =
733  {
734  { "add_wrap_QASYMM8_QASYMM8_QASYMM8", &add_QASYMM8_QASYMM8_QASYMM8 },
735  { "add_saturate_QASYMM8_QASYMM8_QASYMM8", &add_QASYMM8_QASYMM8_QASYMM8 },
736  { "add_wrap_QSYMM16_QSYMM16_QSYMM16", &add_QSYMM16_QSYMM16_QSYMM16 },
737  { "add_saturate_QSYMM16_QSYMM16_QSYMM16", &add_QSYMM16_QSYMM16_QSYMM16 },
738  { "add_wrap_U8_U8_U8", &add_same<uint8_t, false> },
739  { "add_saturate_U8_U8_U8", &add_same<uint8_t, true> },
740  { "add_wrap_S16_U8_S16", &add_S16_U8_S16 },
741  { "add_saturate_S16_U8_S16", &add_S16_U8_S16 },
742  { "add_wrap_U8_S16_S16", &add_U8_S16_S16 },
743  { "add_saturate_U8_S16_S16", &add_U8_S16_S16 },
744  { "add_wrap_U8_U8_S16", &add_U8_U8_S16 },
745  { "add_saturate_U8_U8_S16", &add_U8_U8_S16 },
746  { "add_wrap_S16_S16_S16", &add_same<int16_t, false> },
747  { "add_saturate_S16_S16_S16", &add_same<int16_t, true> },
748  { "add_wrap_F32_F32_F32", &add_same<float, false> },
749  { "add_saturate_F32_F32_F32", &add_same<float, false> },
750 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
751  { "add_wrap_F16_F16_F16", &add_same<float16_t, false> },
752  { "add_saturate_F16_F16_F16", &add_same<float16_t, false> },
753 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
754  };
755 
756  _input1 = input1;
757  _input2 = input2;
758  _output = output;
759  _policy = policy;
760 
761  std::string function_to_call("add_");
762  function_to_call += policy == ConvertPolicy::WRAP ? "wrap_" : "saturate_";
763  function_to_call += string_from_data_type(input1->info()->data_type()) + "_";
764  function_to_call += string_from_data_type(input2->info()->data_type()) + "_";
765  function_to_call += string_from_data_type(output->info()->data_type());
766 
767  auto it = map_function.find(function_to_call);
768 
769  if(it != map_function.end())
770  {
771  _func = it->second;
772  }
773 
774  INEKernel::configure(win_config.second);
775 }
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.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ITensorInfo::data_type(), ITensor::info(), arm_compute::test::validation::policy, arm_compute::string_from_data_type(), arm_compute::validate_and_configure_window(), and arm_compute::WRAP.

Referenced by NERNNLayer::configure(), NELSTMLayer::configure(), and NEGEMMConvolutionLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NEArithmeticAdditionKernel.h.

39  {
40  return "NEArithmeticAdditionKernel";
41  }

◆ operator=() [1/2]

NEArithmeticAdditionKernel& operator= ( const NEArithmeticAdditionKernel )
delete

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 787 of file NEArithmeticAdditionKernel.cpp.

788 {
792  ARM_COMPUTE_ERROR_ON(_func == nullptr);
793 
794  (*_func)(_input1, _input2, _output, _policy, window);
795 }
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:337
#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, 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 input1,
const ITensorInfo input2,
const ITensorInfo output,
ConvertPolicy  policy 
)
static

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

Parameters
[in]input1An input tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32
[in]input2An input tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32
[in]outputThe output tensor. Data types supported: U8/QASYMM8/S16/QSYMM16/F16/F32.
[in]policyOverflow policy.
Returns
a status

Definition at line 777 of file NEArithmeticAdditionKernel.cpp.

778 {
779  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
780 
781  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output, policy));
782  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(*input1->clone(), *input2->clone(), *output->clone()).first);
783 
784  return Status{};
785 }
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(), arm_compute::test::validation::policy, and arm_compute::validate_and_configure_window().

Referenced by NEArithmeticAddition::validate(), NERNNLayer::validate(), and NEGEMMConvolutionLayer::validate().


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