24.02
|
Go to the documentation of this file.
44 size_t reduction_window_split_dimension(
unsigned int axis)
63 : _memory_group(memory_manager),
69 _is_reshape_required(false)
77 "Reduction axis greater than max number of dimensions");
80 const auto is_reshape_required = !keep_dims;
82 auto *output_internal = output;
86 if (is_reshape_required)
88 const TensorInfo expected_output_shape = output->
clone()->set_tensor_shape(
92 auto shape_before_reshape =
input->tensor_shape();
93 shape_before_reshape.set(axis, 1);
95 const auto input_num_channles =
input->num_channels();
96 const auto input_qinfo =
input->quantization_info();
105 output_internal = &info_before_reshape;
110 if (is_reshape_required)
124 _is_reshape_required = !keep_dims;
126 auto *output_internal = output;
129 if (_is_reshape_required)
131 const auto output_internal_shape =
133 const auto output_external_shape =
135 const auto output_data_type = is_arg_min_max ?
DataType::S32 :
input->info()->data_type();
136 const auto num_channels =
input->info()->num_channels();
137 const auto qinfo =
input->info()->quantization_info();
141 ->set_data_type(output_data_type)
142 .set_tensor_shape(output_internal_shape)
144 .set_is_resizable(
true)
145 .set_num_channels(num_channels)
146 .set_quantization_info(
qinfo));
147 _memory_group.
manage(&_output_internal);
148 output_internal = &_output_internal;
151 ->set_data_type(output_data_type)
152 .set_tensor_shape(output_external_shape)
154 .set_is_resizable(
true));
160 _reduction_kernel = std::make_unique<NEReductionOperationKernel>();
161 _reduction_kernel->configure(
input, output_internal, axis, op);
162 _window_split = reduction_window_split_dimension(axis);
163 _reduction_axis = axis;
165 if (_is_reshape_required)
167 _reshape.
configure(output_internal, output);
176 if (_is_reshape_required)
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
virtual ITensorInfo & set_num_channels(int num_channels)=0
Set the number of channels to the specified value.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
virtual ITensorInfo & set_tensor_shape(const TensorShape &shape)=0
Set the shape of an already initialized tensor.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void run() override
Run the kernels contained in the function.
~NEReductionOperation()
Default destructor.
Interface for CPU tensor.
ITensorInfo & set_data_type(DataType data_type) override
Set the data type to the specified value.
ReductionOperation
Available reduction operations.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
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...
static IScheduler & get()
Access the scheduler singleton.
NEReductionOperation(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op, bool keep_dims=true)
Static function to check if given info will lead to a valid configuration of NEReductionOperation.
TensorShape compute_reduced_shape(const TensorShape &input, unsigned int axis, bool keep_dims=true)
Calculate the reduced shape of a tensor given an axis.
@ ARG_IDX_MAX
Index of the max value.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NEReshapeLayer.
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
Store the tensor's metadata.
@ ARG_IDX_MIN
Index of the min value.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Memory group resources scope handling class.
Copyright (c) 2017-2024 Arm Limited.
@ S32
signed 32-bit number
Store the tensor's metadata.
void configure(ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op, bool keep_dims=true)
Set the input and output tensors.
void configure(const ITensor *input, ITensor *output)
Initialise the kernel's inputs and outputs.
#define ARM_COMPUTE_LOG_PARAMS(...)
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 NEReductionOperationKern...
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
void run() override
Run the kernels contained in the function.
const QuantizationInfo qinfo
virtual ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info)=0
Set the quantization settings (scale and offset) of the tensor.