Compute Library
 21.02
NEReductionOperationKernel Class Reference

Neon kernel to perform a reduction operation. More...

#include <NEReductionOperationKernel.h>

Collaboration diagram for NEReductionOperationKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEReductionOperationKernel ()
 Default constructor. More...
 
 NEReductionOperationKernel (const NEReductionOperationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEReductionOperationKerneloperator= (const NEReductionOperationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEReductionOperationKernel (NEReductionOperationKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEReductionOperationKerneloperator= (NEReductionOperationKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEReductionOperationKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op)
 Set the source, destination of the kernel. 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...
 
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...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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 *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
 Static function to check if given info will lead to a valid configuration of NEReductionOperationKernel. More...
 

Detailed Description

Neon kernel to perform a reduction operation.

Note
For ARG_MIN/ARG_MAX reduction, the default data type for an uninitialized output tensor is signed 32-bit integer (S32). It is the user's responsibility to check that the results do not overflow because the indices are computed in unsigned 32-bit (U32).

Definition at line 40 of file NEReductionOperationKernel.h.

Constructor & Destructor Documentation

◆ NEReductionOperationKernel() [1/3]

Default constructor.

Definition at line 1655 of file NEReductionOperationKernel.cpp.

Referenced by NEReductionOperationKernel::name().

1656  : _input(nullptr), _output(nullptr), _reduction_axis(0), _op(ReductionOperation::SUM_SQUARE)
1657 {
1658 }

◆ NEReductionOperationKernel() [2/3]

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

◆ NEReductionOperationKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEReductionOperationKernel()

Default destructor.

Referenced by NEReductionOperationKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
unsigned int  axis,
ReductionOperation  op 
)

Set the source, destination of the kernel.

Parameters
[in]inputSource tensor. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32. Data layouts supported: NCHW.
[out]outputDestination tensor.Data types and data layouts supported: same as input, S32 for ARG_MIX/ARG_MAX. Output will have the same number of dimensions as input.
[in]axisAxis along which to reduce. Supported reduction axis : 0
[in]opReduction operation to perform.

Definition at line 1660 of file NEReductionOperationKernel.cpp.

References arm_compute::ARG_IDX_MAX, arm_compute::ARG_IDX_MIN, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_reduced_shape(), ITensorInfo::data_type(), ITensor::info(), arm_compute::test::validation::input, ITensorInfo::num_dimensions(), arm_compute::S32, Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), and arm_compute::validate_arguments().

Referenced by NEReductionOperationKernel::name().

1661 {
1663 
1664  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), axis, op));
1665 
1666  _input = input;
1667  _output = output;
1668  _op = op;
1669  _reduction_axis = axis;
1670 
1671  // Configure kernel window
1672  Coordinates coord;
1673  coord.set_num_dimensions(input->info()->num_dimensions());
1674  input->info()->set_valid_region(ValidRegion(coord, input->info()->tensor_shape()));
1675  Window win = calculate_max_window(*input->info(), Steps());
1676  INEKernel::configure(win);
1677 
1678  // Calculate output shape and set if empty
1679  const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(input->info()->tensor_shape(), axis);
1680  // Output auto initialization if not yet initialized
1681  const bool is_arg_min_max = (op == ReductionOperation::ARG_IDX_MIN || op == ReductionOperation::ARG_IDX_MAX);
1682  DataType output_data_type = is_arg_min_max ? DataType::S32 : input->info()->data_type();
1683  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape).set_data_type(output_data_type).reset_padding().set_is_resizable(true));
1684  output->info()->set_valid_region(ValidRegion(coord, output_shape));
1685 }
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
1 channel, 1 S32 per channel
TensorShape compute_reduced_shape(const TensorShape &input, unsigned int axis, bool keep_dims=true)
Calculate the reduced shape of a tensor given an axis.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
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
DataType
Available data types.
Definition: Types.h:77

◆ name()

◆ operator=() [1/2]

NEReductionOperationKernel& operator= ( const NEReductionOperationKernel )
delete

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

Referenced by NEReductionOperationKernel::name().

◆ 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.

Reimplemented from ICPPKernel.

Definition at line 1694 of file NEReductionOperationKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NEReductionOperationKernel::name().

1695 {
1699 
1700  reduce_op(window, _input, _output, _reduction_axis, _op);
1701 }
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: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 input,
const ITensorInfo output,
unsigned int  axis,
ReductionOperation  op 
)
static

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

Parameters
[in]inputSource tensor info. Data type supported: QASYMM8_SIGNED/QASYMM8/F16/F32/S32. Data layouts supported: NCHW.
[in]outputDestination tensor info.Data types and data layouts supported: same as input, S32 for ARG_MIX/ARG_MAX. Output will have the same number of dimensions as input.
[in]axisAxis along which to reduce. Supported reduction axis : 0
[in]opReduction operation to perform.
Returns
a status

Definition at line 1687 of file NEReductionOperationKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by NEReductionOperationKernel::name(), and NEReductionOperation::validate().

1688 {
1690 
1691  return Status{};
1692 }
#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)

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