24 #ifndef ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H 25 #define ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H 40 namespace shape_calculator
54 const int input_dims =
input->num_dimensions();
62 std::sort(axis_local.
begin(), axis_local.
begin() + reduction_ops);
63 for(
int i = 0; i < reduction_ops; ++i)
71 for(
int i = 0; i < reduction_ops; ++i)
73 out_shape.
set(axis_local[i], 1);
161 const size_t tmp_dim = weights_reshaped[0];
162 weights_reshaped.set(0, weights_reshaped[1]);
163 weights_reshaped.set(1, tmp_dim + (
has_bias ? 1 : 0));
169 return weights_reshaped;
191 const unsigned int num_horiz_blocks = std::ceil(
input_width / static_cast<float>(lhs_info.
k0));
192 const unsigned int num_vert_blocks = std::ceil(
input_height / static_cast<float>(lhs_info.
m0));
195 const unsigned int block_size = lhs_info.
m0 * lhs_info.
k0;
198 const unsigned int output_width = block_size * num_horiz_blocks * lhs_info.
v0;
199 const unsigned int output_height = std::ceil(num_vert_blocks / static_cast<float>(lhs_info.
v0));
202 lhs_shape.
set(0, output_width);
203 lhs_shape.
set(1, output_height);
205 if((reinterpret_input_as_3d) && (lhs_shape.num_dimensions() > 2))
235 const unsigned int num_horiz_blocks = std::ceil(
input_width / static_cast<float>(rhs_info.
n0));
236 const unsigned int num_vert_blocks = std::ceil(
input_height / static_cast<float>(rhs_info.
k0));
239 const unsigned int block_size = rhs_info.
n0 * rhs_info.
k0;
242 const unsigned int output_width = block_size * num_vert_blocks * rhs_info.
h0;
243 const unsigned int output_height = std::ceil(num_horiz_blocks / static_cast<float>(rhs_info.
h0));
246 rhs_shape.
set(0, output_width);
247 rhs_shape.
set(1, output_height);
264 const int interleave_width = 4 * mult_interleave4x4_height;
266 shape_interleaved_a.
set(0, a.
dimension(0) * interleave_width);
267 if(reinterpret_input_as_3d)
270 const int height = std::ceil(
M / static_cast<float>(interleave_width));
271 shape_interleaved_a.set(1, height);
277 if(shape_interleaved_a.num_dimensions() > 2)
279 shape_interleaved_a.remove_dimension(2);
284 shape_interleaved_a.set(1, std::ceil(a.
dimension(1) / static_cast<float>(interleave_width)));
287 return shape_interleaved_a;
300 shape_transposed1xW_b.set(0,
b.dimension(1) * 16);
301 shape_transposed1xW_b.set(1, std::ceil(
b.dimension(0) / 16.f));
303 return shape_transposed1xW_b;
320 const size_t transpose_width = (16 /
b.element_size()) * mult_transpose1xW_width;
321 shape_transposed1xW_b.set(0,
b.dimension(1) * transpose_width);
322 shape_transposed1xW_b.set(1, static_cast<size_t>(std::ceil(
b.dimension(0) / static_cast<float>(transpose_width))));
324 return shape_transposed1xW_b;
336 if(shape_vector_sum_col.num_dimensions() > 1)
338 shape_vector_sum_col.remove_dimension(1);
341 return shape_vector_sum_col;
354 if(shape_vector_sum_row.num_dimensions() > 1)
359 return shape_vector_sum_row;
387 col2im_shape.shift_right(1);
389 col2im_shape.set(width_idx, convolved_dims.
width);
390 col2im_shape.set(height_idx, convolved_dims.
height);
406 shape_transposed.set(0,
input.dimension(1));
407 shape_transposed.set(1,
input.dimension(0));
409 return shape_transposed;
434 unsigned int output_width = 0;
435 unsigned int output_height = 0;
437 weights_shape[weights_width_idx], weights_shape[weights_height_idx],
438 info.pad_stride_info,
info.dilation);
461 std::pair<unsigned int, unsigned int> &out_dims, uint32_t &padx, uint32_t &pady)
468 unsigned int out_x = (
input.dimension(idx_w) - 1) * sx + 1;
469 unsigned int out_y = (
input.dimension(idx_h) - 1) * sy + 1;
472 padx = out_dims.first - (out_x - weights.
dimension(idx_w) + 1);
473 pady = out_dims.second - (out_y - weights.
dimension(idx_h) + 1);
478 scale_out_shape.
set(idx_w, out_x);
479 scale_out_shape.
set(idx_h, out_y);
481 return scale_out_shape;
504 out_shape.
set(width_idx, out_dims.first);
505 out_shape.
set(height_idx, out_dims.second);
506 out_shape.
set(channel_idx, weights_shape[batch_idx]);
586 if(axis < input->num_dimensions())
657 const unsigned int width =
input.tensor_shape()[idx_c];
658 const unsigned int height = num_tiles.area();
659 const unsigned int depth = input_tile_size.
area();
684 unsigned int output_width = 0;
685 unsigned int output_height = 0;
692 const unsigned int out_w = output_width;
693 const unsigned int out_h = output_height;
694 const unsigned int out_c =
input.dimension(0);
724 const unsigned int weights_out_channel = weights_shape[3];
725 unsigned int output_width = 0;
726 unsigned int output_height = 0;
762 unsigned int pooled_w = 0;
763 unsigned int pooled_h = 0;
799 const unsigned int stride_x = pad_stride_info.
stride().first;
800 const unsigned int stride_y = pad_stride_info.
stride().second;
802 const int pad_left = pad_stride_info.
pad_left();
803 const int pad_top = pad_stride_info.
pad_top();
804 const int pad_right = pad_stride_info.
pad_right();
805 const int pad_bottom = pad_stride_info.
pad_bottom();
869 const int depth_output_gemm3d = reinterpret_output_as_3d ? reshape_info.
depth_output_gemm3d() : 1;
874 const int dim0 = is_interleaved_transposed ? reshape_info.
n() : input1.
dimension(0);
875 const int dim1 = is_interleaved_transposed ? reshape_info.
m() / depth_output_gemm3d : m / depth_output_gemm3d;
877 const int dim3 = reinterpret_input_as_3d ? 1 : input0.
tensor_shape()[3];
883 output_shape.
set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2);
905 const int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.
depth_output_gemm3d() : 1;
909 if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
921 output_shape.
set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
943 const unsigned int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.
depth_output_gemm3d : 1;
947 if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
959 output_shape.
set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
979 if(gemm_3d_depth > 1)
1007 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
1090 empty_shape.
set(0, 0);
1095 if(axis >
input->tensor_shape().num_dimensions())
1100 size_t axis_size = out_shape[axis];
1103 if(axis_size % num_splits)
1108 out_shape[axis] = axis_size / num_splits;
1176 const int num_priors =
info.aspect_ratios().size() *
info.min_sizes().size() +
info.max_sizes().size();
1195 for(
size_t dim = 0; dim < padding.size(); ++dim)
1197 const auto &padding_pair = padding[dim];
1199 padded_shape.
set(dim, padding_pair.first + shape_on_index + padding_pair.second);
1201 return padded_shape;
1214 for(
size_t dim = 0; dim < multiples.size(); ++dim)
1264 return scale_out_shape;
1273 template <
typename T>
1276 return data->info()->tensor_shape();
1319 template <
typename T>
1324 #if defined(ARM_COMPUTE_ASSERTS_ENABLED) 1326 for(
unsigned int i = 0; i <
MAX_DIMS; ++i)
1333 for(
const auto &tensor :
input)
1340 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED) 1343 size_t new_size = 0;
1344 for(
const auto &tensor :
input)
1347 new_size +=
shape[axis];
1350 out_shape.
set(axis, new_size);
1368 shape_out.
set(axis, num_tensors);
1370 unsigned int i_shift = 0;
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
void shift_right(size_t step)
Shifts right the tensor shape increasing its dimensions.
TensorShape compute_slice_shape(const TensorShape &input_shape, const Coordinates &starts, const Coordinates &ends)
Calculate the slice output shape of a tensor.
TensorShape compute_permutation_output_shape(const ITensorInfo &input, const PermutationVector &perm)
Calculate the permuted shape of an input given a permutation vector.
TensorShape calculate_concatenate_shape(const std::vector< T * > &input, size_t axis)
Calculate the concatenate output shape of the concatenate operation along a single axis.
TensorShape compute_depth_to_space_shape(const TensorShape &input_shape, DataLayout data_layout, int block)
Calculate the depth to space output shape of a tensor.
TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, const ConvolutionInfo &info)
Calculate the depthwise convolution output shape of a tensor.
void remove_dimension(size_t n)
Accessor to remove the dimension n from the tensor shape.
TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd input transform shape.
TensorShape calculate_unstack_shape(TensorShape input_shape, unsigned int axis)
Calculate the unstack shape of a tensor.
TensorShape compute_transpose1xW_with_element_size_shape(const ITensorInfo &b, int mult_transpose1xW_width=1)
Calculate the transposed 1xW width element shape.
Descriptor used by the GEMM kernels.
TensorShape compute_stack_shape(const ITensorInfo &a, unsigned int axis, unsigned int num_tensors)
Calculate the stack output shape of a tensor.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
std::vector< PaddingInfo > PaddingList
List of padding information.
TensorShape compute_roi_align_shape(const ITensorInfo &input, const ITensorInfo &rois, ROIPoolingLayerInfo pool_info)
Calculate the output roi align shape of a tensor.
TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info)
Calculate the deep convolution shape output shape of a tensor.
unsigned int v0
Number of vertical blocks of size (m0xk0) stored on the same output row.
unsigned int depth_output_gemm3d
Depth of the output tensor in case is reinterpreted as 3D.
GEMM reshape information class.
TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo &input1, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info)
Calculate the matrix multiplication output shape of two tensors.
TensorShape compute_reductionA_shape(const ITensorInfo &b)
Calculate the reductionA shape used in GEMMLowp.
TensorShape compute_softmax_shape(const ITensorInfo *input, size_t axis=1)
Calculate the softmax output shape of a tensor.
Coordinates BiStrides
Bidirectional strides.
TensorShape compute_space_to_batch_shape(const ITensorInfo *input, const int block_x, const int block_y, const Size2D &padding_left, const Size2D &padding_right)
Calculate the space to batch output shape of a tensor.
unsigned int h0
Number of horizontal blocks of size (k0xn0) stored on the same output row.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
TensorShape compute_rnn_shape(const ITensorInfo *input, const unsigned int batch_size)
Calculate the RNN shape of a tensor.
const DataLayout data_layout
GEMM LHS (Left Hand Side) matrix information.
Store the tensor's metadata.
Size2D compute_winograd_convolution_tiles(const Size2D &in_dims, const Size2D &kernel_size, const Size2D &output_tile_size, const PadStrideInfo &conv_info)
Calculate the number of output tiles required by Winograd Convolution layer.
TensorShape compute_reorg_output_shape(const ITensorInfo &input, int32_t stride)
Calculate the output shape of the reorg layer given a stride.
size_t x() const
Semantic accessor for width as x.
unsigned int pooled_width() const
Get the pooled width of the layer.
unsigned int pad_top() const
Get the top padding.
TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height=1, bool reinterpret_input_as_3d=false)
Calculate the interleaved shape of an input tensor.
TensorShape compute_output_stage_shape(const ITensorInfo &input, unsigned int gemm_3d_depth=1, bool batch_size_on_z=false)
Calculate the matrix multiplication output shape of two tensors.
Copyright (c) 2017-2021 Arm Limited.
size_t height
Height of the image region or rectangle.
TensorShape compute_min_max_shape(const ITensorInfo *input)
Calculate the min/max shape output shape of a tensor.
TensorShape compute_strided_slice_shape(const ITensorInfo &input, const Coordinates &starts, const Coordinates &ends, const Coordinates &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
Calculate the strided slice output shape of a tensor.
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.
constexpr size_t MAX_DIMS
Constant value used to indicate maximum dimensions of a Window, TensorShape and Coordinates.
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
TensorShape compute_deconvolution_output_shape(const std::pair< unsigned int, unsigned int > &out_dims, const ITensorInfo &input, const ITensorInfo &weights)
Calculate the output shape of the deconvolution layer.
TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
Calculate the output pool shape of a tensor.
int n() const
Number of matrix B columns.
TensorShape compute_flatten_shape(const ITensorInfo *input)
Calculate the flattened output shape of a tensor.
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
TensorShape compute_prior_box_shape(const ITensorInfo &input, const PriorBoxLayerInfo &info)
Calculate the prior box output shape of a tensor.
TensorShape compute_vector_to_tensor_output_shape(const TensorShape &input, size_t conv_w, size_t conv_h, const DataLayout &data_layout)
Calculate the output tensor shape of a vector input given the convolution dimensions.
unsigned int m
Number of LHS rows.
unsigned int n
Number of RHS columns.
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void collapse_from(size_t start)
Collapse dimensions starting from a given point.
TensorShape compute_lhs_reshaped_shape(const ITensorInfo &a, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d=false)
Calculate the Left Hand Side matrix reshaped shape.
TensorShape calculate_reduce_mean_shape(ITensorInfo *input, const Coordinates &reduction_axis, bool keep_dims)
Calculate the output tensor shape for the reduce mean operation.
GEMM RHS (Right Hand Side) matrix information.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
TensorShape compute_unpool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
Calculate the output unpool shape of a tensor.
unsigned int n0
Number of columns processed by the matrix multiplication.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
const unsigned int num_groups
TensorShape compute_tiled_shape(const TensorShape &input_shape, const Multiples &multiples)
Calculate the tiled shape of a tensor.
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
TensorShape compute_reduced_shape(const TensorShape &input, unsigned int axis, bool keep_dims=true)
Calculate the reduced shape of a tensor given an axis.
Pooling Layer Information struct.
TensorShape compute_rhs_reshaped_shape(const ITensorInfo &a, const GEMMRHSMatrixInfo &rhs_info)
Calculate the Right Hand Side matrix reshaped shape.
bool reinterpret_input_as_3d
Flag used to reinterpret the input as 3D.
TensorShape compute_deconvolution_upsampled_shape(const ITensorInfo &input, const ITensorInfo &weights, unsigned int sx, unsigned int sy, std::pair< unsigned int, unsigned int > &out_dims, uint32_t &padx, uint32_t &pady)
Calculate the upsampled output shape used for deconvolution.
unsigned int pad_right() const
Get the right padding.
const size_t input_height
Padding and stride information class.
std::array< T, num_max_dimensions >::iterator begin()
Returns a read/write iterator that points to the first element in the dimension array.
TensorShape compute_winograd_filter_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd filter transform shape.
TensorShape compute_padded_shape(const TensorShape &input_shape, const PaddingList &padding)
Calculate the padded shape of a tensor.
Num samples, channels, height, width.
size_t y() const
Semantic accessor for height as y.
Strides of an item in bytes.
TensorShape compute_reductionB_shape(const ITensorInfo &a)
Calculate the reductionB shape used in GEMMLowp.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
TensorShape extract_shape(T *data)
Get the tensor shape.
const size_t weights_width
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
const size_t weights_height
PadStrideInfo pad_stride_info
TensorShape compute_upsample_shape(const ITensorInfo &input, const Size2D &info)
Calculate the upsampled shape of a tensor.
TensorShape compute_winograd_output_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd output transform shape.
size_t width
Width of the image region or rectangle.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
unsigned int pooled_height() const
Get the pooled height of the layer.
TensorShape compute_weights_reshaped_shape(const ITensorInfo &weights, bool has_bias=false, unsigned int num_groups=1)
Calculate the reshaped shape of the weights.
int m() const
Number of matrix A rows.
ROI Pooling Layer Information class.
Class for specifying the size of an image or rectangle.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Num samples, height, width, channels.
TensorShape compute_batch_to_space_shape(const ITensorInfo *input, const int block_x, const int block_y)
Calculate the batch to space output shape of a tensor.
TensorShape compute_transpose1xW_shape(const ITensorInfo &b)
Calculate the transposed 1xW shape.
int depth_output_gemm3d() const
Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
unsigned int m0
Number of rows processed by the matrix multiplication.
Coordinates & convert_negative_axis(Coordinates &coords, int max_value)
Convert negative coordinates to positive in the range [0, num_dims_input].
TensorShape compute_col2im_shape(const ITensorInfo &input, const Size2D &convolved_dims, bool batch_size_on_z, unsigned int num_groups=1)
Calculate the Col2Im shape.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
unsigned int pad_bottom() const
Get the bottom padding.
bool reinterpret_input_as_3d() const
Flag which specifies if the input tensor has to be reinterpreted as 3D.
TensorShape compute_split_shape(const ITensorInfo *input, unsigned int axis, unsigned int num_splits)
Calculate the split output shape of a tensor.
unsigned int pad_left() const
Get the left padding.
DataLayout
[DataLayout enum definition]
std::vector< uint32_t > Multiples
Information to produce a tiled version of a Tensor.
TensorShape compute_im2col_conv_shape(const ITensorInfo *input, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, bool batch_size_on_z, unsigned int num_groups=1)
Calculate the im2col output shape of a tensor.
void collapse(size_t n, size_t first=0)
Collapse the first n dimensions.
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.
size_t area() const
The area of the image or rectangle calculated as (width * height)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
TensorShape compute_space_to_depth_shape(const ITensorInfo *input, int32_t block_shape)
Calculate the space to batch output shape of a tensor.
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)