56 : _weights_reshape_kernel()
65 (biases !=
nullptr) ? biases->
info() :
nullptr,
68 const ITensor *biases_to_use = (append_biases) ? biases :
nullptr;
70 _weights_reshape_kernel = std::make_unique<NEWeightsReshapeKernel>();
71 _weights_reshape_kernel->configure(weights, biases_to_use, output);
93 if((output !=
nullptr) && (output->
total_size() != 0))
111 : _memory_group(memory_manager), _weights_manager(weights_manager), _reshape_weights(), _reshape_weights_managed(), _im2col_kernel(), _mm_gemm(memory_manager), _mm_gemmlowp(memory_manager),
112 _col2im_kernel(), _reshape_layer(), _original_weights(nullptr), _original_output(nullptr), _im2col_output(), _weights_reshaped(), _gemm_output(), _gemm_output_3d(), _tmp_output(),
113 _data_layout(
DataLayout::
NCHW), _skip_im2col(false), _skip_col2im(false), _is_quantized(false), _is_prepared(false)
121 act_info, gemm_3d_depth, _skip_im2col));
125 gemm_3d_depth, _skip_im2col ,
156 int32_t min_activation =
type_min.get<int32_t>();
157 int32_t max_activation =
type_max.get<int32_t>();
159 if(supported_acts.count(act_info.
activation()) != 0)
172 _mm_gemmlowp.
configure(input, weights, biases, output,
GEMMInfo(
false,
false,
true, gemm_3d_depth, _skip_im2col,
false, output_info,
false,
false, act_info));
181 _mm_gemm.
configure(input, weights, biases, output, 1.0f, 0.0f, gemm_info);
190 const bool is_activation_enabled = act_info.
enabled();
194 gemm_3d_depth, skip_im2col ,
210 int32_t min_activation =
type_min.get<int32_t>();
211 int32_t max_activation =
type_max.get<int32_t>();
217 if(is_activation_enabled && supported_acts.count(act_info.
activation()) != 0)
231 std::unique_ptr<ITensorInfo> input_qa = input->
clone();
232 std::unique_ptr<ITensorInfo> weights_qa = weights->
clone();
235 return NEGEMMLowpMatrixMultiplyCore::validate(input_qa.get(), weights_qa.get(), biases, output,
GEMMInfo(
false,
false,
true, gemm_3d_depth, skip_im2col,
false, output_info,
false,
false, act_info));
240 return NEGEMM::validate(input, weights,
nullptr, output, 1.0f, 0.0f, gemm_info);
247 const unsigned int mult_y = skip_im2col ? 1
U : gemm_3d_depth;
248 const unsigned int mult_z = skip_im2col ? gemm_3d_depth : 1
U;
255 return validate_mm(&dummy_input_info, &dummy_weights_info,
nullptr, &dummy_output_info, act_info, gemm_3d_depth, skip_im2col);
265 biases !=
nullptr ? biases->
info() :
nullptr,
279 const unsigned int kernel_width = weights->
info()->
dimension(idx_width);
280 const unsigned int kernel_height = weights->
info()->
dimension(idx_height);
282 _is_prepared = weights_info.retain_internal_weights();
283 _original_weights = weights;
284 _original_output = output;
287 _skip_im2col = (data_layout ==
DataLayout::NHWC && kernel_width == 1 && kernel_height == 1 && conv_info.
stride().first == 1 && conv_info.
stride().second == 1);
290 ITensor *gemm_output_to_use = output;
293 unsigned int conv_w = 0;
294 unsigned int conv_h = 0;
305 _skip_col2im = bool(validate_gemm3d(input->
info(), weights->
info(), act_info, conv_h,
true));
309 _skip_im2col =
false;
314 _skip_col2im =
false;
318 unsigned int stride_x = 0;
319 unsigned int stride_y = 0;
320 std::tie(stride_x, stride_y) = conv_info.stride();
322 unsigned int mat_weights_cols = weights->
info()->
dimension(idx_kernels);
326 const ITensor *weights_to_use = weights;
330 _reshape_weights_managed.
configure(weights,
nullptr);
331 weights_to_use = _weights_manager->
acquire(weights, &_reshape_weights_managed);
335 _reshape_weights.
configure(weights,
nullptr, &_weights_reshaped);
336 weights_to_use = &_weights_reshaped;
342 _memory_group.
manage(&_im2col_output);
345 _im2col_kernel = std::make_unique<NEIm2ColKernel>();
346 _im2col_kernel->configure(input, &_im2col_output,
Size2D(kernel_width, kernel_height), conv_info,
false, dilation);
349 gemm_input_to_use = &_im2col_output;
360 shape_gemm.
set(0, mat_weights_cols);
361 shape_gemm.
set(1, conv_w * conv_h);
364 TensorInfo info_gemm(shape_gemm, 1, output_data_type);
368 _memory_group.
manage(&_gemm_output);
371 gemm_output_to_use = &_gemm_output;
379 _memory_group.
manage(&_gemm_output);
382 gemm_output_to_use = &_gemm_output_3d;
387 const unsigned int gemm_3d_depth = _skip_col2im ? conv_h : 0;
388 configure_mm(gemm_input_to_use, weights_to_use, biases, gemm_output_to_use, act_info, gemm_3d_depth);
400 _col2im_kernel = std::make_unique<NECol2ImKernel>();
401 _col2im_kernel->configure(gemm_output_to_use, output,
Size2D(conv_w, conv_h));
406 _reshape_layer.
configure(gemm_output_to_use, output);
412 _reshape_layer.
configure(gemm_output_to_use, output);
415 if(_is_quantized && !_skip_col2im)
423 "Output shape does not match the expected one");
443 const unsigned int kernel_width = weights->
dimension(idx_width);
444 const unsigned int kernel_height = weights->
dimension(idx_height);
454 const bool append_bias =
false;
457 bool skip_im2col = (data_layout ==
DataLayout::NHWC && kernel_width == 1 && kernel_height == 1 && conv_info.
stride().first == 1 && conv_info.
stride().second == 1);
460 unsigned int conv_w = 0;
461 unsigned int conv_h = 0;
471 bool skip_col2im =
false;
474 skip_col2im = bool(validate_gemm3d(input, weights, act_info, conv_h,
true));
485 if(!
bool(validate_gemm3d(input, weights, act_info, conv_h, skip_im2col)))
496 if(biases !=
nullptr)
514 unsigned int mat_weights_cols = weights->
dimension(idx_kernels);
521 weights_to_use = &weights_reshaped_info;
529 shape_im2col.
set(0, mat_weights_rows);
530 shape_im2col.
set(1, conv_w * conv_h);
531 shape_im2col.
set(2, 1);
533 im2col_reshaped_info =
TensorInfo(shape_im2col, 1, data_type);
537 gemm_input_to_use = &im2col_reshaped_info;
545 shape_gemm.
set(0, mat_weights_cols);
546 shape_gemm.
set(1, conv_w * conv_h);
547 info_gemm =
TensorInfo(shape_gemm, 1, output_data_type);
554 gemm_output_to_use = &info_gemm;
555 ARM_COMPUTE_RETURN_ON_ERROR(validate_mm(gemm_input_to_use, weights_to_use, biases, gemm_output_to_use, act_info, skip_col2im ? conv_h : 0, skip_im2col));
582 const ITensor *out_to_use = out_has_padding ? &_gemm_output : _original_output;
607 _reshape_layer.
run();
610 else if(out_has_padding)
612 _reshape_layer.
run();
624 _weights_manager->
run(_original_weights, &_reshape_weights_managed);
630 _reshape_weights.
run();
636 if(!_weights_reshaped.
is_used())
unsigned int top
top of the border
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Class describing the value of a pixel for any image format.
NEConvolutionLayerReshapeWeights()
Constructor.
void prepare() override
Prepare the function for executing.
Quantize using a fixed point multiplication.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
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...
bool enabled() const
Check if initialised.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
bool is_used() const
Flags if the tensor is used or not.
bool are_reshaped() const
Flag which specifies if the weights tensor has been reshaped.
1 channel, 1 F32 per channel
const DataLayout data_layout
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
unsigned int bottom
bottom of the border
int32_t gemmlowp_offset
GEMMLowp output stage offset used for quantizing to QASYMM8.
int32_t gemmlowp_max_bound
GEMMLowp max value used to saturate down the output result before converting back to QASYMM8...
~NEGEMMConvolutionLayer()
Default destructor.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Activation Layer Information class.
GEMMLowpOutputStageType type
GEMMLowp output stage type.
Interface for Neon tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1)
Static function to check if given info will lead to a valid configuration of NEGEMMConvolutionLayer.
Copyright (c) 2017-2021 Arm Limited.
static Status validate(const ITensorInfo *input, const ITensorInfo *biases, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NEWeightsReshapeKernel.
1 channel, 1 F16 per channel
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode...
ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info) override
Set the quantization settings (scale and offset) of the tensor.
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
bool is_quantized_per_channel
GEMMLowp quantized per-channel flag.
Convolution Layer Weights Information class.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
void mark_as_unused() const
Marks a tensor as unused.
1 channel, 1 S32 per channel
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
static Status validate(const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NEConvolutionLayerReshap...
16-bit brain floating-point number
bool are_weights_managed(const ITensor *weights)
Check if the weights are managed.
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of NEGEMM.
Quantization information.
void run() override
Run the kernels contained in the function.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *output, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel's inputs, output.
bool is_data_type_quantized_per_channel(DataType dt)
Check if a given data type is of per channel type.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo & set_data_layout(const DataLayout &data_layout)=0
Set the data layout of the tensor.
std::pair< int32_t, int32_t > get_quantized_activation_min_max(ActivationLayerInfo act_info, DataType data_type, UniformQuantizationInfo oq_info)
Returns a pair of minimum and maximum values for a quantized activation.
Status calculate_quantized_multipliers(const QuantizationInfo &iq_info, const QuantizationInfo &wq_info, const QuantizationInfo &oq_info, GEMMLowpOutputStageInfo &stage_info)
Calculate quantized representation of per-channel multipliers.
void run() override
Run the kernels contained in the function.
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
const unsigned int num_groups
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
GEMMLowp output stage info.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Padding and stride information class.
virtual PaddingSize padding() const =0
Padding of tensor.
virtual ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info)=0
Set the quantization settings (scale and offset) of the tensor.
void free() override
Free allocated CPU memory.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &convolved_dims)
Static function to check if given info will lead to a valid configuration of NECol2ImKernel.
Weights manager interface to handle weights transformations.
virtual ITensorInfo & set_data_type(DataType data_type)=0
Set the data type to the specified value.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
void run() override
Run the kernels contained in the function.
Num samples, channels, height, width.
src_info set_data_layout(data_layout)
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
quantized, symmetric per channel fixed-point 8-bit number
__constant DATA_TYPE16 type_min
Lower and Upper Bounded Rectifier ( )
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
NEGEMMConvolutionLayer(const std::shared_ptr< IMemoryManager > &memory_manager=nullptr, IWeightsManager *weights_manager=nullptr)
Constructor.
void run() override
Run the kernels contained in the function.
Memory group resources scope handling class.
Upper Bounded Rectifier ( )
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1)
Set the input and output tensors.
TensorShape compute_weights_reshaped_shape(const ITensorInfo &weights, bool has_bias=false, unsigned int num_groups=1)
Calculate the reshaped shape of the weights.
Class for specifying the size of an image or rectangle.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Num samples, height, width, channels.
void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel's inputs, output.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
void prepare() override
Prepare the function for executing.
__constant DATA_TYPE16 type_max
Status import_memory(void *memory)
Import an existing memory as a tensor's backing memory.
void configure(const ITensor *input, ITensor *output)
Initialise the kernel's inputs and outputs.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of NEGEMMLowpMatrixMultiply...
ITensor * run(const ITensor *weights, ITransformWeights *weights_transform)
Run the reshape function.
ActivationFunction activation() const
Get the type of activation function.
quantized, asymmetric fixed-point 8-bit number signed
void prepare() override
Prepare the function for executing.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
int32_t gemmlowp_min_bound
GEMMLowp min value used to saturate down the output result before converting back to QASYMM8...
void configure(const ITensor *weights, const ITensor *biases, ITensor *output)
Set the input and output tensors.
DataType
Available data types.
DataLayout
[DataLayout enum definition]
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation=Size2D(1U, 1U), unsigned int num_groups=1)
Static function to check if given info will lead to a valid configuration of NEIm2ColKernel.
~NEConvolutionLayerReshapeWeights()
Default destructor.
virtual bool extend_padding(const PaddingSize &padding)=0
Update the offset to the first element, the strides and the total size.
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
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 run() override
Run the kernels contained in the function.
ITensor * acquire(const ITensor *weights, ITransformWeights *weights_transform)
Acquire the requested reshape tensor of the selected weights.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
static IScheduler & get()
Access the scheduler singleton.