Compute Library
 21.08
NEReductionOperationKernel Class Reference

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

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 1675 of file NEReductionOperationKernel.cpp.

Referenced by NEReductionOperationKernel::name().

1676  : _input(nullptr), _output(nullptr), _reduction_axis(0), _op(ReductionOperation::SUM_SQUARE)
1677 {
1678 }

◆ 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.
[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 1680 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, arm_compute::S32, and ITensorInfo::tensor_shape().

Referenced by NEReductionOperationKernel::name().

1681 {
1683 
1684  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), axis, op));
1685 
1686  _input = input;
1687  _output = output;
1688  _op = op;
1689  _reduction_axis = axis;
1690 
1691  // Configure kernel window
1692  Window win = calculate_max_window(*input->info(), Steps());
1693  INEKernel::configure(win);
1694 
1695  // Calculate output shape and set if empty
1696  const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(input->info()->tensor_shape(), axis);
1697  // Output auto initialization if not yet initialized
1698  const bool is_arg_min_max = (op == ReductionOperation::ARG_IDX_MIN || op == ReductionOperation::ARG_IDX_MAX);
1699  DataType output_data_type = is_arg_min_max ? DataType::S32 : input->info()->data_type();
1700  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));
1701 }
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...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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 1710 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().

1711 {
1715 
1716  reduce_op(window, _input, _output, _reduction_axis, _op);
1717 }
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 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.
[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 1703 of file NEReductionOperationKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

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

1704 {
1705  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, axis, op));
1706 
1707  return Status{};
1708 }
#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: