24.02.1
|
Go to the documentation of this file.
42 validate_config(
const ITensorInfo *
input,
const Coordinates &reduction_axis,
bool keep_dims,
const ITensorInfo *output)
52 const unsigned int reduction_ops = reduction_axis.num_dimensions();
53 const int input_dims =
input->num_dimensions();
54 Coordinates axis_local = reduction_axis;
56 for (
unsigned int i = 0; i < axis_local.num_dimensions(); ++i)
63 if (output->tensor_shape().total_size() != 0)
66 TensorShape out_shape =
input->tensor_shape();
72 #pragma GCC diagnostic push
73 #pragma GCC diagnostic ignored "-Warray-bounds"
74 std::sort(axis_local.begin(), axis_local.begin() + reduction_ops);
75 #pragma GCC diagnostic pop
77 for (
unsigned int i = 0; i < reduction_ops; ++i)
81 if (output->total_size() > 0 && keep_dims)
87 out_shape.set(axis_local[i], 1);
92 const unsigned int remove_index = axis_local[i] - i;
94 out_shape.remove_dimension(remove_index,
false);
97 const TensorInfo out_info =
input->clone()->set_tensor_shape(out_shape);
105 TensorInfo output_no_quant(output->clone()->set_data_type(
DataType::F32));
114 : _memory_group(std::move(memory_manager)),
115 _reduction_kernels(),
151 _reduction_kernels.resize(_reduction_ops);
152 _reduced_outs.resize(_reduction_ops - (keep_dims ? 1 : 0));
153 _keep_dims = keep_dims;
159 _memory_group.
manage(&_input_no_quant);
160 _memory_group.
manage(&_output_no_quant);
166 tmp_input = &_input_no_quant;
167 tmp_output = &_output_no_quant;
176 for (
int i = 0; i < _reduction_ops; ++i)
180 out_shape.
set(axis_local[i], 1);
181 auto in = (i == 0) ? tmp_input : (&_reduced_outs[i - 1]);
183 if (i == _reduction_ops - 1 && keep_dims)
185 _reduction_kernels[i].configure(compile_context, in, tmp_output, axis_local[i],
193 _memory_group.
manage(&_reduced_outs[i]);
194 _reduction_kernels[i].configure(compile_context, in, &_reduced_outs[i], axis_local[i],
200 for (
int i = 0; i < _reduction_ops - (keep_dims ? 1 : 0); ++i)
202 _reduced_outs[i].allocator()->allocate();
215 #pragma GCC diagnostic push
216 #pragma GCC diagnostic ignored "-Warray-bounds"
217 std::sort(axis_local.
begin(), axis_local.
begin() + _reduction_ops);
218 #pragma GCC diagnostic pop
219 for (
int i = 0; i < _reduction_ops; ++i)
224 _reshape.
configure(compile_context, &_reduced_outs[_reduction_ops - 1], tmp_output);
228 _requant.
configure(compile_context, &_output_no_quant, output);
239 return validate_config(
input, reduction_axis, keep_dims, output);
250 for (
auto &kernel : _reduction_kernels)
virtual size_t num_channels() const =0
The number of channels for each tensor element.
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
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 configure(ICLTensor *input, const Coordinates &reduction_axis, bool keep_dims, ICLTensor *output)
Configure kernel.
Interface for OpenCL tensor.
ITensorInfo & set_data_type(DataType data_type) override
Set the data type to the specified value.
TensorShape calculate_reduce_mean_shape(ITensorInfo *input, const Coordinates &reduction_axis, bool keep_dims)
Calculate the output tensor shape for the reduce mean operation.
void run() override
Run the kernels contained in the function.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
void run() override
Run the kernels contained in the function.
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...
CLReduceMean(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
virtual DataType data_type() const =0
Data type used for each element of the tensor.
void configure(const ICLTensor *input, ICLTensor *output)
Set the input and output tensors.
void configure(const ICLTensor *input, ICLTensor *output)
Set the input and output tensors.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
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.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
void run() override
Run the kernels contained in the function.
Store the tensor's metadata.
void run() override
Run the kernels contained in the function.
Memory group resources scope handling class.
Copyright (c) 2017-2024 Arm Limited.
void remove_dimension(size_t n, bool apply_dim_correction=true)
Accessor to remove the dimension n from the tensor shape.
@ F16
16-bit floating-point number
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLQuantizationLayer.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLDequantizationLayer.
Store the tensor's metadata.
@ F32
32-bit floating-point number
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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.
void configure(const ICLTensor *input, ICLTensor *output)
Initialise the kernel's inputs and outputs.
Coordinates & convert_negative_axis(Coordinates &coords, int max_value)
Convert negative coordinates to positive in the range [0, num_dims_input].
#define ARM_COMPUTE_LOG_PARAMS(...)
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)