39 Status validate_config(
const ITensorInfo *
input,
const Coordinates &reduction_axis,
bool keep_dims,
const ITensorInfo *output)
48 const unsigned int reduction_ops = reduction_axis.num_dimensions();
49 const int input_dims = input->num_dimensions();
50 Coordinates axis_local = reduction_axis;
52 for(
unsigned int i = 0; i < axis_local.num_dimensions(); ++i)
59 if(output->tensor_shape().total_size() != 0)
62 TensorShape out_shape = input->tensor_shape();
65 std::sort(axis_local.begin(), axis_local.begin() + reduction_ops);
66 for(
unsigned int i = 0; i < reduction_ops; ++i)
70 if(output->total_size() > 0 && keep_dims)
76 out_shape.set(axis_local[i], 1);
81 const unsigned int remove_index = axis_local[i] - i;
83 out_shape.remove_dimension(remove_index);
86 const TensorInfo out_info = input->clone()->set_tensor_shape(out_shape);
88 const bool requant =
is_data_type_quantized(input->data_type()) && input->quantization_info() != output->quantization_info();
91 TensorInfo input_no_quant(input->clone()->set_data_type(
DataType::F32));
93 TensorInfo output_no_quant(output->clone()->set_data_type(
DataType::F32));
102 : _memory_group(
std::move(memory_manager)), _reduction_kernels(), _reduced_outs(), _reshape(), _dequant(), _requant(), _reduction_ops(), _keep_dims(), _do_requant(), _input_no_quant(),
122 _reduction_kernels.resize(_reduction_ops);
123 _reduced_outs.resize(_reduction_ops - (keep_dims ? 1 : 0));
124 _keep_dims = keep_dims;
130 _memory_group.
manage(&_input_no_quant);
131 _memory_group.
manage(&_output_no_quant);
136 _dequant.
configure(compile_context, input, &_input_no_quant);
137 tmp_input = &_input_no_quant;
138 tmp_output = &_output_no_quant;
147 for(
int i = 0; i < _reduction_ops; ++i)
150 out_shape.
set(axis_local[i], 1);
151 auto in = (i == 0) ? tmp_input : (&_reduced_outs[i - 1]);
153 if(i == _reduction_ops - 1 && keep_dims)
160 _memory_group.
manage(&_reduced_outs[i]);
166 for(
int i = 0; i < _reduction_ops - (keep_dims ? 1 : 0); ++i)
168 _reduced_outs[i].allocator()->allocate();
178 std::sort(axis_local.
begin(), axis_local.
begin() + _reduction_ops);
179 for(
int i = 0; i < _reduction_ops; ++i)
184 _reshape.
configure(compile_context, &_reduced_outs[_reduction_ops - 1], tmp_output);
188 _requant.
configure(compile_context, &_output_no_quant, output);
196 return validate_config(input, reduction_axis, keep_dims, output);
207 for(
auto &kernel : _reduction_kernels)
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLDequantizationLayer.
void remove_dimension(size_t n)
Accessor to remove the dimension n from the tensor shape.
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
ITensorInfo & set_data_type(DataType data_type) override
Set the data type to the specified value.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
void configure(ICLTensor *input, const Coordinates &reduction_axis, bool keep_dims, ICLTensor *output)
Configure kernel.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
void run() override
Run the kernels contained in the function.
void run() override
Run the kernels contained in the function.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void run() override final
Run the kernels contained in the function.
TensorShape calculate_reduce_mean_shape(ITensorInfo *input, const Coordinates &reduction_axis, bool keep_dims)
Calculate the output tensor shape for the reduce mean operation.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
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...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void configure(const ICLTensor *input, ICLTensor *output)
Set the input and output tensors.
std::array< T, num_max_dimensions >::iterator begin()
Returns a read/write iterator that points to the first element in the dimension array.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
static Status validate(const ITensorInfo *input, const Coordinates &reduction_axis, bool keep_dims, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLReduceMean.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Memory group resources scope handling class.
Interface for OpenCL tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
void configure(const ICLTensor *input, ICLTensor *output)
Set the input and output tensors.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
CLReduceMean(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
Store the tensor's metadata.
void configure(const ICLTensor *input, ICLTensor *output)
Initialise the kernel's inputs and outputs.
quantized, asymmetric fixed-point 8-bit number signed
Coordinates & convert_negative_axis(Coordinates &coords, int max_value)
Convert negative coordinates to positive in the range [0, num_dims_input].
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLQuantizationLayer.
virtual size_t num_channels() const =0
The number of channels for each tensor element.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.