Compute Library
 19.08
NEArithmeticSubtractionKernel Class Reference

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

#include <NEArithmeticSubtractionKernel.h>

Collaboration diagram for NEArithmeticSubtractionKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEArithmeticSubtractionKernel ()
 Default constructor. More...
 
 NEArithmeticSubtractionKernel (const NEArithmeticSubtractionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEArithmeticSubtractionKerneloperator= (const NEArithmeticSubtractionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEArithmeticSubtractionKernel (NEArithmeticSubtractionKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEArithmeticSubtractionKerneloperator= (NEArithmeticSubtractionKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEArithmeticSubtractionKernel ()=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...
 
BorderSize border_size () const override
 The size of the border for that kernel. 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...
 
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 NEArithmeticSubtractionKernel. More...
 

Detailed Description

Interface for the kernel to perform subtraction between two tensors.

Definition at line 35 of file NEArithmeticSubtractionKernel.h.

Constructor & Destructor Documentation

◆ NEArithmeticSubtractionKernel() [1/3]

Default constructor.

Definition at line 445 of file NEArithmeticSubtractionKernel.cpp.

446  : _func(nullptr), _input1(nullptr), _input2(nullptr), _output(nullptr)
447 {
448 }

◆ NEArithmeticSubtractionKernel() [2/3]

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

◆ NEArithmeticSubtractionKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEArithmeticSubtractionKernel()

Default destructor.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 518 of file NEArithmeticSubtractionKernel.cpp.

519 {
520  const unsigned int replicateSize = _output->info()->dimension(0) - std::min(_input1->info()->dimension(0), _input2->info()->dimension(0));
521  const unsigned int border = std::min<unsigned int>(num_elems_processed_per_iteration - 1U, replicateSize);
522  return BorderSize{ 0, border, 0, 0 };
523 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Container for 2D border size.
Definition: Types.h:259
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.

References ITensorInfo::dimension(), ITensor::info(), and arm_compute::U.

◆ 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
  • (QASYMM8, QASYMM8) -> QASYMM8
  • (S16,U8) -> S16
  • (U8,S16) -> S16
  • (S16,S16) -> S16
  • (F16,F16) -> F16
  • (F32,F32) -> F32
Parameters
[in]input1An input tensor. Data types supported: U8/QASYMM8/S16/F16/F32
[in]input2An input tensor. Data types supported: U8/QASYMM8/S16/F16/F32
[out]outputThe output tensor. Data types supported: U8/QASYMM8/S16/F16/F32.
[in]policyOverflow policy. Convert policy cannot be WRAP if datatype is QASYMM8

Definition at line 450 of file NEArithmeticSubtractionKernel.cpp.

451 {
452  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
453  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info(), policy));
454 
455  // Configure kernel window
456  auto win_config = validate_and_configure_window(*input1->info(), *input2->info(), *output->info());
457  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
458 
459  static std::map<std::string, NEArithmeticSubtractionKernel::SubFunction *> map_function =
460  {
461  { "sub_wrap_U8_U8_U8", &sub_wrap_U8_U8_U8 },
462  { "sub_wrap_U8_U8_S16", &sub_wrap_U8_U8_S16 },
463  { "sub_saturate_U8_U8_U8", &sub_saturate_U8_U8_U8 },
464  { "sub_saturate_U8_U8_S16", &sub_saturate_U8_U8_S16 },
465  { "sub_saturate_QASYMM8_QASYMM8_QASYMM8", &sub_saturate_QAYSMM8_QAYSMM8_QAYSMM8 },
466  { "sub_wrap_U8_S16_S16", &sub_wrap_U8_S16_S16 },
467  { "sub_wrap_S16_U8_S16", &sub_wrap_S16_U8_S16 },
468  { "sub_saturate_U8_S16_S16", &sub_saturate_U8_S16_S16 },
469  { "sub_saturate_S16_U8_S16", &sub_saturate_S16_U8_S16 },
470  { "sub_wrap_S16_S16_S16", &sub_wrap_S16_S16_S16 },
471  { "sub_saturate_S16_S16_S16", &sub_saturate_S16_S16_S16 },
472  { "sub_wrap_F32_F32_F32", &sub_F32_F32_F32 },
473  { "sub_saturate_F32_F32_F32", &sub_F32_F32_F32 },
474  { "sub_wrap_F16_F16_F16", &sub_F16_F16_F16 },
475  { "sub_saturate_F16_F16_F16", &sub_F16_F16_F16 },
476  };
477 
478  _input1 = input1;
479  _input2 = input2;
480  _output = output;
481 
482  std::string function_to_call("sub_");
483  function_to_call += policy == ConvertPolicy::WRAP ? "wrap_" : "saturate_";
484  function_to_call += string_from_data_type(input1->info()->data_type()) + "_";
485  function_to_call += string_from_data_type(input2->info()->data_type()) + "_";
486  function_to_call += string_from_data_type(output->info()->data_type());
487 
488  auto it = map_function.find(function_to_call);
489 
490  if(it != map_function.end())
491  {
492  _func = it->second;
493  }
494 
495  INEKernel::configure(win_config.second);
496 }
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 NELSTMLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NEArithmeticSubtractionKernel.h.

39  {
40  return "NEArithmeticSubtractionKernel";
41  }

◆ operator=() [1/2]

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 508 of file NEArithmeticSubtractionKernel.cpp.

509 {
513  ARM_COMPUTE_ERROR_ON(_func == nullptr);
514 
515  (*_func)(_input1, _input2, _output, window);
516 }
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 NEArithmeticSubtractionKernel.

Note
Convert policy cannot be WRAP if datatype is QASYMM8
Parameters
[in]input1First tensor input. Data types supported: U8/QASYMM8/S16/F16/F32
[in]input2Second tensor input. Data types supported: U8/QASYMM8/S16/F16/F32
[in]outputOutput tensor. Data types supported: U8/QASYMM8/S16/F16/F32
[in]policyPolicy to use to handle overflow. Convert policy cannot be WRAP if datatype is QASYMM8
Returns
a status

Definition at line 498 of file NEArithmeticSubtractionKernel.cpp.

499 {
500  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
501 
502  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(*input1, *input2, *output, policy));
503  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(*input1->clone(), *input2->clone(), *output->clone()).first);
504 
505  return Status{};
506 }
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 NEArithmeticSubtraction::validate(), and NELSTMLayer::validate().


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