24 #ifndef ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H 25 #define ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H 40 namespace shape_calculator
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);
94 output_shape.
set(idx_w, conv_w);
95 output_shape.
set(idx_h, conv_h);
96 output_shape.
set(idx_c, input.
x() / (conv_w * conv_h));
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;
305 const size_t num_channels = input.
dimension(channel_idx);
306 const size_t num_rows = input.
dimension(height_idx);
307 const size_t num_cols = input.
dimension(width_idx);
309 weights_shape.set(0, num_rows * num_cols * info.
c0);
310 weights_shape.set(1,
DIV_CEIL(num_channels, info.
c0));
311 return weights_shape;
325 shape_transposed1xW_b.
set(1, std::ceil(b.
dimension(0) / 16.f));
327 return shape_transposed1xW_b;
344 const size_t transpose_width = (16 / b.
element_size()) * mult_transpose1xW_width;
345 shape_transposed1xW_b.
set(0, b.
dimension(1) * transpose_width);
346 shape_transposed1xW_b.
set(1, static_cast<size_t>(std::ceil(b.
dimension(0) /
static_cast<float>(transpose_width))));
348 return shape_transposed1xW_b;
360 if(shape_vector_sum_col.num_dimensions() > 1)
365 return shape_vector_sum_col;
378 if(shape_vector_sum_row.num_dimensions() > 1)
383 return shape_vector_sum_row;
413 col2im_shape.set(width_idx, convolved_dims.
width);
414 col2im_shape.set(height_idx, convolved_dims.
height);
433 return shape_transposed;
461 unsigned int output_width = 0;
462 unsigned int output_height = 0;
464 weights_shape[weights_width_idx], weights_shape[weights_height_idx],
465 conv_info, dilation);
488 std::pair<unsigned int, unsigned int> &out_dims, uint32_t &padx, uint32_t &pady)
495 unsigned int out_x = (input.
dimension(idx_w) - 1) * sx + 1;
496 unsigned int out_y = (input.
dimension(idx_h) - 1) * sy + 1;
499 padx = out_dims.first - (out_x - weights.
dimension(idx_w) + 1);
500 pady = out_dims.second - (out_y - weights.
dimension(idx_h) + 1);
505 scale_out_shape.
set(idx_w, out_x);
506 scale_out_shape.
set(idx_h, out_y);
508 return scale_out_shape;
531 out_shape.
set(width_idx, out_dims.first);
532 out_shape.
set(height_idx, out_dims.second);
533 out_shape.
set(channel_idx, weights_shape[batch_idx]);
613 if(axis < input->num_dimensions())
685 const unsigned int height = num_tiles.area();
686 const unsigned int depth = input_tile_size.
area();
711 unsigned int output_width = 0;
712 unsigned int output_height = 0;
719 const unsigned int out_w = output_width;
720 const unsigned int out_h = output_height;
721 const unsigned int out_c = input.
dimension(0);
751 const unsigned int weights_out_channel = weights_shape[3];
752 unsigned int output_width = 0;
753 unsigned int output_height = 0;
754 std::tie(output_width, output_height) =
scaled_dimensions(input_width, input_height, weights_width, weights_height, conv_info);
789 unsigned int pooled_w = 0;
790 unsigned int pooled_h = 0;
826 const unsigned int stride_x = pad_stride_info.
stride().first;
827 const unsigned int stride_y = pad_stride_info.
stride().second;
829 const int pad_left = pad_stride_info.
pad_left();
830 const int pad_top = pad_stride_info.
pad_top();
831 const int pad_right = pad_stride_info.
pad_right();
832 const int pad_bottom = pad_stride_info.
pad_bottom();
835 const unsigned int out_width = (input_shape[
idx_width] - 1) * stride_x - pad_left - pad_right + pool_info.
pool_size.
width;
836 const unsigned int out_height = (input_shape[idx_height] - 1) * stride_y - pad_top - pad_bottom + pool_info.
pool_size.
height;
838 output_shape.
set(idx_width, out_width);
839 output_shape.
set(idx_height, out_height);
896 const int depth_output_gemm3d = reinterpret_output_as_3d ? reshape_info.
depth_output_gemm3d() : 1;
901 const int dim0 = is_interleaved_transposed ? reshape_info.
n() : input1.
dimension(0);
902 const int dim1 = is_interleaved_transposed ? reshape_info.
m() / depth_output_gemm3d : m / depth_output_gemm3d;
904 const int dim3 = reinterpret_input_as_3d ? 1 : input0.
tensor_shape()[3];
910 output_shape.
set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2);
932 const int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.
depth_output_gemm3d() : 1;
936 if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
948 output_shape.
set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
970 const unsigned int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.
depth_output_gemm3d : 1;
974 if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
986 output_shape.
set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
1006 if(gemm_3d_depth > 1)
1013 output_shape.set(1, input.
tensor_shape().
y() / gemm_3d_depth);
1014 output_shape.set(2, gemm_3d_depth);
1034 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
1101 output_shape.
set(idx_channel, input_shape[idx_channel] / (block * block));
1117 empty_shape.
set(0, 0);
1127 size_t axis_size = out_shape[axis];
1130 if(axis_size % num_splits)
1135 out_shape[axis] = axis_size / num_splits;
1222 for(
size_t dim = 0; dim < padding.size(); ++dim)
1224 const auto &padding_pair = padding[dim];
1225 const uint32_t shape_on_index = (padded_shape.
num_dimensions() <= dim) ? 1 : input_shape[dim];
1226 padded_shape.
set(dim, padding_pair.first + shape_on_index + padding_pair.second);
1228 return padded_shape;
1241 for(
size_t dim = 0; dim < multiples.size(); ++dim)
1243 tiled_shape.
set(dim, input_shape[dim] * multiples[dim]);
1286 const unsigned int out_x = input.
dimension(idx_width) * info.
x();
1287 const unsigned int out_y = input.
dimension(idx_height) * info.
y();
1288 scale_out_shape.set(idx_width, out_x);
1289 scale_out_shape.set(idx_height, out_y);
1291 return scale_out_shape;
1300 template <
typename T>
1303 return data->info()->tensor_shape();
1346 template <
typename T>
1351 #if defined(ARM_COMPUTE_ASSERTS_ENABLED) 1353 for(
unsigned int i = 0; i <
MAX_DIMS; ++i)
1360 for(
const auto &tensor : input)
1367 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED) 1370 size_t new_size = 0;
1371 for(
const auto &tensor : input)
1374 new_size += shape[axis];
1377 out_shape.
set(axis, new_size);
1395 shape_out.
set(axis, num_tensors);
1397 unsigned int i_shift = 0;
1418 output_shape[actual_axis] = indices_shape[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 compute_depth_to_space_shape(const TensorShape &input_shape, DataLayout data_layout, int block)
Calculate the depth to space 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.
DataLayout output_data_layout
Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) ...
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.
TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info, unsigned int depth_multiplier, const Size2D &dilation=Size2D(1U, 1U))
Calculate the depthwise convolution 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.
PadStrideInfo convolution_info
Convolution info (Pads, strides,...)
std::vector< float > aspect_ratios() const
Get aspect ratios.
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.
const size_t input_height
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_reshaped_depthwise_weights_shape(const ITensorInfo &input, const DepthwiseConvolutionReshapeInfo &info)
Calculate the reshaped shape of the weights to use in depthwise convolution.
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.
const size_t weights_height
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.
constexpr auto DIV_CEIL(S val, T m) -> decltype((val+m - 1)/m)
Calculate the rounded up quotient of val / m.
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.
T x() const
Alias to access the size of the first dimension.
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.
Size2D output_tile_size
Width and height of the output tile.
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.
Padding and stride information class.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
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.
unsigned int c0
Number of channels processed by the depth-wise convolution.
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.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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.
std::vector< float > max_sizes() const
Get max sizes.
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.
Size2D kernel_size
Width and height of the kernel.
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
unsigned int m0
Number of rows processed by the matrix multiplication.
T y() const
Alias to access the size of the second dimension.
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.
Size2D input_dimensions
Width and height of the input tensor before the convolution is applied.
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...
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.
const size_t weights_width
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.
std::vector< float > min_sizes() const
Get min sizes.
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)