Compute Library
 21.02
NEPixelWiseMultiplicationKernel Class Reference

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

#include <NEPixelWiseMultiplicationKernel.h>

Collaboration diagram for NEPixelWiseMultiplicationKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEPixelWiseMultiplicationKernel ()
 Default constructor. More...
 
 NEPixelWiseMultiplicationKernel (const NEPixelWiseMultiplicationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEPixelWiseMultiplicationKerneloperator= (const NEPixelWiseMultiplicationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEPixelWiseMultiplicationKernel (NEPixelWiseMultiplicationKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEPixelWiseMultiplicationKerneloperator= (NEPixelWiseMultiplicationKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEPixelWiseMultiplicationKernel ()=default
 Default destructor. More...
 
void configure (ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy)
 Initialise the kernel's input, output and border mode. More...
 
void run_op (ITensorPack &tensors, 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...
 
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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy)
 Static function to check if given info will lead to a valid configuration of NEPixelWiseMultiplicationKernel. More...
 

Detailed Description

Interface for the kernel to perform addition between two tensors.

Definition at line 35 of file NEPixelWiseMultiplicationKernel.h.

Constructor & Destructor Documentation

◆ NEPixelWiseMultiplicationKernel() [1/3]

Default constructor.

Definition at line 1477 of file NEPixelWiseMultiplicationKernel.cpp.

Referenced by NEPixelWiseMultiplicationKernel::name().

1478  : _func_float(nullptr), _func_int(nullptr), _func_quantized(nullptr), _scale{ 0 }, _scale_exponent{ 0 }
1479 {
1480 }

◆ NEPixelWiseMultiplicationKernel() [2/3]

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

◆ NEPixelWiseMultiplicationKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEPixelWiseMultiplicationKernel()

Default destructor.

Referenced by NEPixelWiseMultiplicationKernel::name().

Member Function Documentation

◆ configure()

void configure ( ITensorInfo input1,
ITensorInfo input2,
ITensorInfo output,
float  scale,
ConvertPolicy  overflow_policy,
RoundingPolicy  rounding_policy 
)

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

Valid configurations (Input1,Input2) -> Output :

                                                  Support: Broadcast? Scale=1/255?
  • (U8,U8) -> U8, S16 N Y
  • (U8,S16) -> S16 N Y
  • (S16,U8) -> S16 N Y
  • (S16,S16) -> S16 N Y
  • (S32,S32) -> S32 Y N
  • (F16,F16) -> F16 N Y
  • (F32,F32) -> F32 Y Y
  • (QASYMM8,QASYMM8) -> QASYMM8 Y Y
  • (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED Y Y
  • (QSYMM16,QSYMM16) -> QSYMM16, S32 N Y
Note
For scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
Parameters
[in]input1First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
[in]input2Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
[out]outputOutput tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
[in]scaleScale to apply after multiplication. Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. If both input1, input2 and output are of datatype S32, scale cannot be 1/255
[in]overflow_policyOverflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
[in]rounding_policyRounding policy.

Definition at line 1482 of file NEPixelWiseMultiplicationKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, ITensorInfo::broadcast_shape_and_valid_region(), arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ITensorInfo::num_dimensions(), arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::QSYMM16, arm_compute::S16, arm_compute::S32, arm_compute::SATURATE, arm_compute::test::validation::scale, Dimensions< T >::set_num_dimensions(), arm_compute::set_shape_if_empty(), ITensorInfo::set_valid_region(), arm_compute::U8, arm_compute::test::validation::valid_region, and arm_compute::validate_arguments().

Referenced by NEPixelWiseMultiplicationKernel::name(), and NEComplexPixelWiseMultiplicationKernel::name().

1483 {
1484  ARM_COMPUTE_UNUSED(rounding_policy);
1485  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
1486 
1487  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input1, input2, output, scale, overflow_policy, rounding_policy));
1488 
1489  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(*input1, *input2);
1490  const TensorShape &out_shape = broadcast_pair.first;
1491  const ValidRegion &valid_region = broadcast_pair.second;
1492 
1493  // Auto initialize output if not initialized
1494  set_shape_if_empty(*output, out_shape);
1495 
1496  _scale = scale;
1497  _scale_exponent = 0;
1498  _func_quantized = nullptr;
1499  _func_int = nullptr;
1500  _func_float = nullptr;
1501 
1502  bool is_scale_255 = false;
1503  // Check and validate scaling factor
1504  if(std::abs(scale - scale255_constant) < 0.00001f)
1505  {
1506  is_scale_255 = true;
1507  }
1508  else
1509  {
1510  int exponent = 0;
1511 
1512  std::frexp(scale, &exponent);
1513 
1514  // Store the positive exponent. We know that we compute 1/2^n
1515  // Additionally we need to subtract 1 to compensate that frexp used a mantissa of 0.5
1516  _scale_exponent = std::abs(exponent - 1);
1517  }
1518 
1519  const DataType dt_input1 = input1->data_type();
1520  const DataType dt_input2 = input2->data_type();
1521  const DataType dt_output = output->data_type();
1522  const bool is_sat = (overflow_policy == ConvertPolicy::SATURATE);
1523 
1524  switch(dt_input1)
1525  {
1526  case DataType::QASYMM8:
1527  if(dt_input2 == DataType::QASYMM8 && dt_output == DataType::QASYMM8)
1528  {
1529  _func_quantized = &mul_saturate_quantized_8<uint8_t>;
1530  }
1531  break;
1533  if(dt_input2 == DataType::QASYMM8_SIGNED)
1534  {
1535  _func_quantized = &mul_saturate_quantized_8<int8_t>;
1536  ;
1537  }
1538  break;
1539  case DataType::QSYMM16:
1540  if(dt_input2 == DataType::QSYMM16 && dt_output == DataType::QSYMM16)
1541  {
1542  _func_quantized = &mul_saturate_QSYMM16_QSYMM16_QSYMM16;
1543  }
1544  else if(dt_input2 == DataType::QSYMM16 && dt_output == DataType::S32)
1545  {
1546  _func_int = &mul_QSYMM16_QSYMM16_S32;
1547  }
1548  break;
1549  case DataType::S16:
1550  if(DataType::U8 == dt_input2 && DataType::S16 == dt_output)
1551  {
1552  if(is_scale_255)
1553  {
1554  _func_int = is_sat ? &mul_S16_U8_S16<true, true> : &mul_S16_U8_S16<true, false>;
1555  }
1556  else
1557  {
1558  _func_int = is_sat ? &mul_S16_U8_S16<false, true> : &mul_S16_U8_S16<false, false>;
1559  }
1560  }
1561  if(DataType::S16 == dt_input2 && DataType::S16 == dt_output)
1562  {
1563  if(is_scale_255)
1564  {
1565  _func_int = is_sat ? &mul_S16_S16_S16<true, true> : &mul_S16_S16_S16<true, false>;
1566  }
1567  else
1568  {
1569  _func_int = is_sat ? &mul_S16_S16_S16<false, true> : &mul_S16_S16_S16<false, false>;
1570  }
1571  }
1572  break;
1573  case DataType::S32:
1574  if(DataType::S32 == dt_input2 && DataType::S32 == dt_output)
1575  {
1576  _func_int = is_sat ? &mul_S32_S32_S32<true> : &mul_S32_S32_S32<false>;
1577  }
1578  break;
1579  case DataType::U8:
1580  if(DataType::U8 == dt_input2 && DataType::U8 == dt_output)
1581  {
1582  if(is_scale_255)
1583  {
1584  _func_int = is_sat ? &mul_U8_U8_U8<true, true> : &mul_U8_U8_U8<true, false>;
1585  }
1586  else
1587  {
1588  _func_int = is_sat ? &mul_U8_U8_U8<false, true> : &mul_U8_U8_U8<false, false>;
1589  }
1590  }
1591  else if(DataType::U8 == dt_input2 && DataType::S16 == dt_output)
1592  {
1593  if(is_scale_255)
1594  {
1595  _func_int = is_sat ? &mul_U8_U8_S16<true, true> : &mul_U8_U8_S16<true, false>;
1596  }
1597  else
1598  {
1599  _func_int = is_sat ? &mul_U8_U8_S16<false, true> : &mul_U8_U8_S16<false, false>;
1600  }
1601  }
1602  else if(DataType::S16 == dt_input2 && DataType::S16 == dt_output)
1603  {
1604  if(is_scale_255)
1605  {
1606  _func_int = is_sat ? &mul_U8_S16_S16<true, true> : &mul_U8_S16_S16<true, false>;
1607  }
1608  else
1609  {
1610  _func_int = is_sat ? &mul_U8_S16_S16<false, true> : &mul_U8_S16_S16<false, false>;
1611  }
1612  }
1613  break;
1614 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1615  case DataType::F16:
1616  _func_float = &mul_F16_F16_F16;
1617  break;
1618 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
1619  case DataType::F32:
1620  _func_float = &mul_F32_F32_F32;
1621  break;
1622  default:
1623  ARM_COMPUTE_ERROR("You called with the wrong img formats");
1624  }
1625 
1626  // Configure kernel window
1627  Coordinates coord;
1628  coord.set_num_dimensions(output->num_dimensions());
1629  output->set_valid_region(valid_region);
1630  Window win = calculate_max_window(valid_region, Steps());
1631 
1632  INEKernel::configure(win);
1633 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
const ValidRegion valid_region
Definition: Scale.cpp:221
static std::pair< TensorShape, ValidRegion > broadcast_shape_and_valid_region(const Infos &... infos)
If infos are broadcast compatible tensor info&#39;s, return the broadcasted shape and the intersection of...
Definition: ITensorInfo.h:271
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
quantized, asymmetric fixed-point 8-bit number unsigned
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
1 channel, 1 S16 per channel
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
quantized, asymmetric fixed-point 8-bit number signed
DataType
Available data types.
Definition: Types.h:77

◆ name()

◆ operator=() [1/2]

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

Referenced by NEPixelWiseMultiplicationKernel::name().

◆ operator=() [2/2]

Allow instances of this class to be moved.

◆ 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 1644 of file NEPixelWiseMultiplicationKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, TensorShape::broadcast_shape(), arm_compute::F32, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::detail::have_different_dimensions(), ITensorInfo::tensor_shape(), TensorShape::total_size(), ITensorInfo::total_size(), and IKernel::window().

Referenced by NEPixelWiseMultiplicationKernel::name(), and NEComplexPixelWiseMultiplicationKernel::name().

1645 {
1649 
1650  auto input1 = tensors.get_const_tensor(TensorType::ACL_SRC_0);
1651  auto input2 = tensors.get_const_tensor(TensorType::ACL_SRC_1);
1652  auto output = tensors.get_tensor(TensorType::ACL_DST);
1653 
1654  if(_func_quantized != nullptr)
1655  {
1656  (*_func_quantized)(input1, input2, output, window, _scale);
1657  }
1658  else if(_func_int != nullptr)
1659  {
1660  (*_func_int)(input1, input2, output, window, _scale_exponent);
1661  }
1662  else
1663  {
1664  ARM_COMPUTE_ERROR_ON(_func_float == nullptr);
1665  (*_func_float)(input1, input2, output, window, _scale);
1666  }
1667 }
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
#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 input1,
const ITensorInfo input2,
const ITensorInfo output,
float  scale,
ConvertPolicy  overflow_policy,
RoundingPolicy  rounding_policy 
)
static

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

Valid configurations (Input1,Input2) -> Output : Support: Broadcast? Scale=1/255?

  • (U8,U8) -> U8, S16 N Y
  • (U8,S16) -> S16 N Y
  • (S16,U8) -> S16 N Y
  • (S16,S16) -> S16 N Y
  • (S32,S32) -> S32 Y N
  • (F16,F16) -> F16 N Y
  • (F32,F32) -> F32 Y Y
  • (QASYMM8,QASYMM8) -> QASYMM8 Y Y
  • (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED Y Y
  • (QSYMM16,QSYMM16) -> QSYMM16, S32 N Y
Note
For scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
Parameters
[in]input1First input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
[in]input2Second input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
[in]outputOutput tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
[in]scaleScale to apply after multiplication. Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. If both input1, input2 and output are of datatype S32, scale cannot be 1/255
[in]overflow_policyOverflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
[in]rounding_policyRounding policy.
Returns
a status

Definition at line 1635 of file NEPixelWiseMultiplicationKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by NEPixelWiseMultiplicationKernel::name(), NEComplexPixelWiseMultiplicationKernel::name(), and NEPixelWiseMultiplication::validate().

1637 {
1638  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
1639  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input1, input2, output, scale, overflow_policy, rounding_policy));
1640 
1641  return Status{};
1642 }
#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)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

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