Compute Library
 23.08
arm_compute::misc::shape_calculator Namespace Reference

Functions

TensorShape calculate_reduce_mean_shape (ITensorInfo *input, const Coordinates &reduction_axis, bool keep_dims)
 Calculate the output tensor shape for the reduce mean operation. More...
 
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. More...
 
TensorShape compute_permutation_output_shape (const ITensorInfo &input, const PermutationVector &perm)
 Calculate the permuted shape of an input given a permutation vector. More...
 
TensorShape compute_reorg_output_shape (const ITensorInfo &input, int32_t stride)
 Calculate the output shape of the reorg layer given a stride. More...
 
TensorShape compute_weights_reshaped_shape (const ITensorInfo &weights, bool has_bias=false, unsigned int num_groups=1)
 Calculate the reshaped shape of the weights. More...
 
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. More...
 
TensorShape compute_rhs_reshaped_shape (const ITensorInfo &a, const GEMMRHSMatrixInfo &rhs_info)
 Calculate the Right Hand Side matrix reshaped shape. More...
 
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. More...
 
TensorShape compute_transpose1xW_shape (const ITensorInfo &b)
 Calculate the transposed 1xW shape. More...
 
TensorShape compute_transpose1xW_with_element_size_shape (const ITensorInfo &b, int mult_transpose1xW_width=1)
 Calculate the transposed 1xW width element shape. More...
 
TensorShape compute_reductionA_shape (const ITensorInfo &b)
 Calculate the reductionA shape used in GEMMLowp. More...
 
TensorShape compute_reductionB_shape (const ITensorInfo &a)
 Calculate the reductionB shape used in GEMMLowp. More...
 
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. More...
 
TensorShape compute_transposed_shape (const ITensorInfo &input)
 Calculate the transposed shape of a tensor. More...
 
TensorShape compute_depthwise_convolution_shape (const ITensorInfo &input, const ITensorInfo &weights, const ConvolutionInfo &info)
 Calculate the depthwise convolution output shape of a tensor. More...
 
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. More...
 
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. More...
 
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, unsigned int input_pad_right=0)
 Calculate the im2col output shape of a tensor. More...
 
TensorShape compute_flatten_shape (const ITensorInfo *input)
 Calculate the flattened output shape of a tensor. More...
 
TensorShape compute_softmax_shape (const ITensorInfo *input, size_t axis=1)
 Calculate the softmax output shape of a tensor. More...
 
TensorShape compute_winograd_filter_transform_shape (const ITensorInfo &input, const WinogradInfo &winograd_info)
 Calculate the winograd filter transform shape. More...
 
TensorShape compute_winograd_input_transform_shape (const ITensorInfo &input, const WinogradInfo &winograd_info)
 Calculate the winograd input transform shape. More...
 
TensorShape compute_winograd_output_transform_shape (const ITensorInfo &input, const WinogradInfo &winograd_info)
 Calculate the winograd output transform shape. More...
 
TensorShape compute_deep_convolution_shape (const TensorShape &input_shape, DataLayout input_data_layout, const TensorShape &weights_shape, const PadStrideInfo &conv_info)
 Calculate the deep convolution shape output shape of a tensor. More...
 
TensorShape compute_deep_convolution_shape (const ITensorInfo &input, const ITensorInfo &weights, const PadStrideInfo &conv_info)
 Calculate the deep convolution shape output shape of a tensor. More...
 
TensorShape compute_indirect_buffer_shape (const TensorShape &input_shape, DataLayout input_data_layout, const TensorShape &weights_shape, const PadStrideInfo &conv_info, const DirectConvComputeKernelInfo &desc)
 Calculate the indirect buffer output shape used by the indirect convolution function. More...
 
TensorShape compute_min_max_shape (const ITensorInfo *input)
 Calculate the min/max shape output shape of a tensor. More...
 
TensorShape compute_pool_shape (const ITensorInfo &input, PoolingLayerInfo pool_info)
 Calculate the output pool shape of a tensor. More...
 
TensorShape compute_unpool_shape (const ITensorInfo &input, PoolingLayerInfo pool_info)
 Calculate the output unpool shape of a tensor. More...
 
TensorShape compute_roi_align_shape (const ITensorInfo &input, const ITensorInfo &rois, ROIPoolingLayerInfo pool_info)
 Calculate the output roi align shape of a tensor. More...
 
TensorShape compute_rnn_shape (const ITensorInfo *input, const unsigned int batch_size)
 Calculate the RNN shape of a tensor. More...
 
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. More...
 
TensorShape compute_mm_shape (const ITensorInfo &input0, const ITensorInfo &input1, const GEMMReshapeInfo &gemm_info)
 Calculate the matrix multiplication output shape of two tensors. More...
 
TensorShape compute_mm_shape (const ITensorInfo &input0, const ITensorInfo &input1, const GEMMKernelInfo &gemm_info)
 Calculate the matrix multiplication output shape of two tensors. More...
 
TensorShape compute_matmul_shape (const TensorShape &input0, const TensorShape &input1, const MatMulKernelInfo &matmul_info)
 Calculate the matrix multiplication output shape of two tensors. More...
 
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. More...
 
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. More...
 
TensorShape compute_slice_shape (const TensorShape &input_shape, const Coordinates &starts, const Coordinates &ends)
 Calculate the slice output shape of a tensor. More...
 
TensorShape compute_batch_to_space_shape (DataLayout data_layout, const TensorShape &input, int block_x, int block_y, const CropInfo &crop_info=CropInfo{})
 Calculate the batch to space output shape of a tensor. More...
 
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. More...
 
TensorShape compute_split_shape (const ITensorInfo *input, unsigned int axis, unsigned int num_splits)
 Calculate the split output shape of a tensor. More...
 
TensorShape compute_space_to_batch_shape (const ITensorInfo *input, int block_x, int block_y, const Size2D &padding_left, const Size2D &padding_right)
 Calculate the space to batch output shape of a tensor. More...
 
TensorShape compute_space_to_depth_shape (const ITensorInfo *input, int32_t block_shape)
 Calculate the space to batch output shape of a tensor. More...
 
TensorShape compute_prior_box_shape (const ITensorInfo &input, const PriorBoxLayerInfo &info)
 Calculate the prior box output shape of a tensor. More...
 
TensorShape compute_padded_shape (const TensorShape &input_shape, const PaddingList &padding)
 Calculate the padded shape of a tensor. More...
 
TensorShape compute_tiled_shape (const TensorShape &input_shape, const Multiples &multiples)
 Calculate the tiled shape of a tensor. More...
 
TensorShape compute_reduced_shape (const TensorShape &input, unsigned int axis, bool keep_dims=true)
 Calculate the reduced shape of a tensor given an axis. More...
 
TensorShape compute_upsample_shape (const ITensorInfo &input, const Size2D &info)
 Calculate the upsampled shape of a tensor. More...
 
template<typename T >
TensorShape extract_shape (T *data)
 Get the tensor shape. More...
 
TensorShape extract_shape (ITensorInfo *data)
 
TensorShape extract_shape (const ITensorInfo *data)
 
TensorShape extract_shape (const TensorShape *data)
 
TensorShape extract_shape (TensorShape *data)
 
TensorShape calculate_unstack_shape (TensorShape input_shape, unsigned int axis)
 Calculate the unstack shape of a tensor. More...
 
template<typename T >
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. More...
 
TensorShape compute_stack_shape (const ITensorInfo &a, unsigned int axis, unsigned int num_tensors)
 Calculate the stack output shape of a tensor. More...
 
TensorShape compute_conv3d_shape (const TensorShape &src, const TensorShape &weights, const Conv3dInfo &conv3d_info)
 Calculate the output shape of 3d Convolution. More...
 
TensorShape compute_pool3d_shape (const TensorShape &src, Pooling3dLayerInfo pool3d_info)
 Calculate the output pool3d shape of a tensor. More...
 
TensorShape compute_gather_shape (const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)
 Calculate the gather output shape of a tensor. More...
 

Function Documentation

◆ calculate_concatenate_shape()

TensorShape arm_compute::misc::shape_calculator::calculate_concatenate_shape ( const std::vector< T * > &  input,
size_t  axis 
)
inline

Calculate the concatenate output shape of the concatenate operation along a single axis.

Parameters
[in]inputVector containing the shapes of the inputs
[in]axisAxis along which to concatenate the input tensors
Returns
the calculated shape

Definition at line 1404 of file ShapeCalculator.h.

1405 {
1406  TensorShape out_shape = extract_shape(input[0]);
1407 
1408 #if defined(ARM_COMPUTE_ASSERTS_ENABLED)
1409  // All dimensions must match except the axis one
1410  for(unsigned int i = 0; i < MAX_DIMS; ++i)
1411  {
1412  if(i == axis)
1413  {
1414  continue;
1415  }
1416 
1417  for(const auto &tensor : input)
1418  {
1419  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
1420  const TensorShape shape = extract_shape(tensor);
1421  ARM_COMPUTE_ERROR_ON(out_shape[i] != shape[i]);
1422  }
1423  }
1424 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED)
1425 
1426  // Calculate output shape
1427  size_t new_size = 0;
1428  for(const auto &tensor : input)
1429  {
1430  const TensorShape shape = extract_shape(tensor);
1431  new_size += shape[axis];
1432  }
1433 
1434  out_shape.set(axis, new_size);
1435 
1436  return out_shape;
1437 }

References ARM_COMPUTE_ERROR_ON, extract_shape(), arm_compute::test::validation::input, arm_compute::MAX_DIMS, TensorShape::set(), arm_compute::test::validation::shape, and tensor.

Referenced by ConcatenateLayerNode::compute_output_descriptor(), CpuConcatenate::configure(), ClConcatenate::configure(), CLLSTMLayer::configure(), CpuConcatenate::validate(), ClConcatenate::validate(), NELSTMLayer::validate(), and CLLSTMLayer::validate().

◆ calculate_reduce_mean_shape()

TensorShape arm_compute::misc::shape_calculator::calculate_reduce_mean_shape ( ITensorInfo input,
const Coordinates reduction_axis,
bool  keep_dims 
)
inline

Calculate the output tensor shape for the reduce mean operation.

Parameters
[in]inputInput tensor shape
[in]reduction_axisReduction axis
[in]keep_dimsFlag to indicate if dimensions are kept
Returns
the calculated shape

Definition at line 52 of file ShapeCalculator.h.

53 {
54  const int reduction_ops = reduction_axis.num_dimensions();
55  Coordinates axis_local = reduction_axis;
56  const int input_dims = input->num_dimensions();
57  convert_negative_axis(axis_local, input_dims);
58  TensorShape out_shape = input->tensor_shape();
59  // Configure reshape layer if we want to drop the dimensions
60  if(!keep_dims)
61  {
62  // We have to sort the reduction axis vectors in order for remove_dimension
63  // to work properly
64  std::sort(axis_local.begin(), axis_local.begin() + reduction_ops);
65  for(int i = 0; i < reduction_ops; ++i)
66  {
67  out_shape.remove_dimension(axis_local[i] - i, false);
68  }
69  return out_shape;
70  }
71  else
72  {
73  for(int i = 0; i < reduction_ops; ++i)
74  {
75  out_shape.set(axis_local[i], 1);
76  }
77  return out_shape;
78  }
79 }

References Dimensions< T >::begin(), arm_compute::convert_negative_axis(), arm_compute::test::validation::input, Dimensions< T >::num_dimensions(), TensorShape::remove_dimension(), and TensorShape::set().

Referenced by NEReduceMean::configure(), and CLReduceMean::configure().

◆ calculate_unstack_shape()

TensorShape arm_compute::misc::shape_calculator::calculate_unstack_shape ( TensorShape  input_shape,
unsigned int  axis 
)
inline

Calculate the unstack shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]axisAxis on which to perform the unstack operation
Returns
the calculated shape

Definition at line 1389 of file ShapeCalculator.h.

1390 {
1391  ARM_COMPUTE_ERROR_ON(axis > input_shape.num_dimensions());
1392  input_shape.remove_dimension(axis);
1393  return input_shape;
1394 }

References ARM_COMPUTE_ERROR_ON, and arm_compute::test::validation::input_shape.

◆ compute_batch_to_space_shape()

TensorShape arm_compute::misc::shape_calculator::compute_batch_to_space_shape ( DataLayout  data_layout,
const TensorShape input,
int  block_x,
int  block_y,
const CropInfo crop_info = CropInfo{} 
)
inline

Calculate the batch to space output shape of a tensor.

Parameters
[in]data_layoutData layout
[in]inputInput tensor shape
[in]block_xBlock shape x value
[in]block_yBlock shape y value
[in]crop_infoInformation about how the output shape is cropped after batch to space is performed
Returns
the calculated shape

Definition at line 1113 of file ShapeCalculator.h.

1113  {})
1114 {
1115  ARM_COMPUTE_ERROR_ON(block_x < 1 || block_y < 1);
1116 
1117  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1118  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1119  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1120 
1121  TensorShape output_shape{ input };
1122 
1123  unsigned int new_width = input[idx_width] * static_cast<unsigned int>(block_x);
1124  unsigned int new_height = input[idx_height] * static_cast<unsigned int>(block_y);
1125  const unsigned int width_crop = crop_info.left + crop_info.right;
1126  const unsigned int height_crop = crop_info.top + crop_info.bottom;
1127  ARM_COMPUTE_ERROR_ON(new_width <= width_crop);
1128  ARM_COMPUTE_ERROR_ON(new_height <= height_crop);
1129  new_width -= width_crop;
1130  new_height -= height_crop;
1131 
1132  output_shape.set(idx_width, new_width);
1133  output_shape.set(idx_height, new_height);
1134  output_shape.set(idx_batch, input[idx_batch] / (block_x * block_y));
1135 
1136  return output_shape;
1137 }

Referenced by arm_compute::test::validation::reference::batch_to_space(), NEBatchToSpaceLayerKernel::configure(), and CLBatchToSpaceLayerKernel::configure().

◆ compute_col2im_shape()

TensorShape arm_compute::misc::shape_calculator::compute_col2im_shape ( const ITensorInfo input,
const Size2D convolved_dims,
bool  batch_size_on_z,
unsigned int  num_groups = 1 
)
inline

Calculate the Col2Im shape.

Parameters
[in]inputInput tensor info
[in]convolved_dimsConvolved dimensions
[in]batch_size_on_zTrue if batch size is on z axis
[in]num_groups(Optional) Number of groups when performing a grouped convolution
Returns
the calculated shape

Definition at line 373 of file ShapeCalculator.h.

374 {
376  ARM_COMPUTE_ERROR_ON(input.tensor_shape()[1] != (convolved_dims.area()));
377  ARM_COMPUTE_ERROR_ON((num_groups > 1) && input.tensor_shape()[2] != num_groups);
378 
379  const DataLayout data_layout = input.data_layout();
380  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
381  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
382  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
383 
384  TensorShape col2im_shape{ input.tensor_shape() };
385  // If batches start on 3rd dimension shift dimensions right by 1 to retain upper tensor shape,
386  // as first three will be override by H,W,C data
387  if(batch_size_on_z && num_groups == 1)
388  {
389  col2im_shape.shift_right(1);
390  }
391  col2im_shape.set(width_idx, convolved_dims.width);
392  col2im_shape.set(height_idx, convolved_dims.height);
393  col2im_shape.set(channel_idx, input.tensor_shape()[0] * num_groups);
394 
395  return col2im_shape;
396 }

References Size2D::area(), ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::num_groups, Size2D::width, and arm_compute::WIDTH.

Referenced by CpuCol2ImKernel::configure().

◆ compute_conv3d_shape()

TensorShape arm_compute::misc::shape_calculator::compute_conv3d_shape ( const TensorShape src,
const TensorShape weights,
const Conv3dInfo conv3d_info 
)
inline

Calculate the output shape of 3d Convolution.

Parameters
[in]srcInput tensor shape
[in]weightsWeights tensor shape
[in]conv3d_info3d Convolution Parameters object
Returns
the calculated shape

Definition at line 1476 of file ShapeCalculator.h.

1477 {
1478  // Weight tensor shape indices (D H W Cin Cout)
1479  constexpr unsigned int weights_depth_dim = 4u;
1480  constexpr unsigned int weights_height_dim = 3u;
1481  constexpr unsigned int weights_width_dim = 2u;
1482  constexpr unsigned int weights_CHout_dim = 0u;
1483 
1484  // Source/Destination Tensor shape indices (N D H W C)
1485  constexpr unsigned int batch_dim = 4u;
1486  constexpr unsigned int depth_dim = 3u;
1487  constexpr unsigned int height_dim = 2u;
1488  constexpr unsigned int width_dim = 1u;
1489  constexpr unsigned int channel_dim = 0u;
1490 
1491  TensorShape output_shape{ src };
1492  const size_t pad_left = conv3d_info.padding.left;
1493  const size_t pad_right = conv3d_info.padding.right;
1494  const size_t pad_top = conv3d_info.padding.top;
1495  const size_t pad_bottom = conv3d_info.padding.bottom;
1496  const size_t pad_front = conv3d_info.padding.front;
1497  const size_t pad_back = conv3d_info.padding.back;
1498  const size_t dilation_x = conv3d_info.dilation.width;
1499  const size_t dilation_y = conv3d_info.dilation.height;
1500  const size_t dilation_z = conv3d_info.dilation.depth;
1501  const size_t stride_x = conv3d_info.stride.x();
1502  const size_t stride_y = conv3d_info.stride.y();
1503  const size_t stride_z = conv3d_info.stride.z();
1504 
1505  int output_width_size = 0;
1506  int output_height_size = 0;
1507  int output_depth_size = 0;
1508 
1509  switch(conv3d_info.round_type)
1510  {
1511  case DimensionRoundingType::FLOOR:
1512  output_width_size = static_cast<int>(std::floor((static_cast<float>(src[width_dim] + pad_left + pad_right - (dilation_x * (weights[weights_width_dim] - 1) + 1)) / stride_x) + 1));
1513  output_height_size = static_cast<int>(std::floor((static_cast<float>(src[height_dim] + pad_top + pad_bottom - (dilation_y * (weights[weights_height_dim] - 1) + 1)) / stride_y) + 1));
1514  output_depth_size = static_cast<int>(std::floor((static_cast<float>(src[depth_dim] + pad_front + pad_back - (dilation_z * (weights[weights_depth_dim] - 1) + 1)) / stride_z) + 1));
1515  break;
1516  case DimensionRoundingType::CEIL:
1517  output_width_size = static_cast<int>(std::ceil((static_cast<float>(src[width_dim] + pad_left + pad_right - (dilation_x * (weights[weights_width_dim] - 1) + 1)) / stride_x) + 1));
1518  output_height_size = static_cast<int>(std::ceil((static_cast<float>(src[height_dim] + pad_top + pad_bottom - (dilation_y * (weights[weights_height_dim] - 1) + 1)) / stride_y) + 1));
1519  output_depth_size = static_cast<int>(std::ceil((static_cast<float>(src[depth_dim] + pad_front + pad_back - (dilation_z * (weights[weights_depth_dim] - 1) + 1)) / stride_z) + 1));
1520  break;
1521  default:
1522  ARM_COMPUTE_ERROR("Unsupported rounding type");
1523  }
1524 
1526  output_shape.set(width_dim, output_width_size);
1527  output_shape.set(height_dim, output_height_size);
1528  output_shape.set(depth_dim, output_depth_size);
1530  return output_shape;
1531 }

References ARM_COMPUTE_ERROR, Padding3D::back, batch_dim, Padding3D::bottom, arm_compute::CEIL, channel_dim, Size3D::depth, depth_dim, Conv3dInfo::dilation, arm_compute::FLOOR, Padding3D::front, Size3D::height, height_dim, Padding3D::left, arm_compute::test::validation::output_shape, Conv3dInfo::padding, Padding3D::right, Conv3dInfo::round_type, arm_compute::test::validation::src, Conv3dInfo::stride, Padding3D::top, weights_CHout_dim, weights_depth_dim, weights_height_dim, weights_width_dim, Size3D::width, width_dim, Size3D::x(), Size3D::y(), and Size3D::z().

Referenced by CpuDirectConv3dKernel::configure(), and arm_compute::test::validation::reference::conv3d().

◆ compute_deconvolution_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_deconvolution_output_shape ( const std::pair< unsigned int, unsigned int > &  out_dims,
const ITensorInfo input,
const ITensorInfo weights 
)
inline

Calculate the output shape of the deconvolution layer.

Parameters
[in]out_dimsOutput x and y shape dimensions
[in]inputInput tensor info
[in]weightsWeights tensor shape
Returns
the calculated shape

Definition at line 494 of file ShapeCalculator.h.

495 {
496  const TensorShape input_shape{ input.tensor_shape() };
497  const TensorShape weights_shape{ weights.tensor_shape() };
498 
499  const DataLayout data_layout = input.data_layout();
500  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
501  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
502  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
503  const int batch_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
504 
505  TensorShape out_shape{ input_shape };
506  out_shape.set(width_idx, out_dims.first);
507  out_shape.set(height_idx, out_dims.second);
508  out_shape.set(channel_idx, weights_shape[batch_idx]);
509  return out_shape;
510 }

References arm_compute::BATCHES, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::input_shape, ITensorInfo::tensor_shape(), arm_compute::test::validation::weights_shape, and arm_compute::WIDTH.

Referenced by ClTransposedConvolutionKernel::configure(), NEDeconvolutionLayer::configure(), CLDirectDeconvolutionLayer::configure(), NEDeconvolutionLayer::validate(), CLGEMMDeconvolutionLayer::validate(), and CLDirectDeconvolutionLayer::validate().

◆ compute_deconvolution_upsampled_shape()

TensorShape arm_compute::misc::shape_calculator::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 
)
inline

Calculate the upsampled output shape used for deconvolution.

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor shape
[in]sxStride on x axis
[in]syStride on y axis
[in]out_dimsOutput shape dimensions
[in]padxPadding on x axis
[in]padyPadding on y axis
Returns
the calculated shape

Definition at line 462 of file ShapeCalculator.h.

464 {
465  const DataLayout data_layout = input.data_layout();
466  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
467  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
468 
469  // Find the upsampled dimensions
470  unsigned int out_x = (input.dimension(idx_w) - 1) * sx + 1;
471  unsigned int out_y = (input.dimension(idx_h) - 1) * sy + 1;
472 
473  // Find the padding needed for the convolution with stride 1 in order to match output shape
474  padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1);
475  pady = out_dims.second - (out_y - weights.dimension(idx_h) + 1);
476  out_x += padx;
477  out_y += pady;
478 
479  TensorShape scale_out_shape(input.tensor_shape());
480  scale_out_shape.set(idx_w, out_x);
481  scale_out_shape.set(idx_h, out_y);
482 
483  return scale_out_shape;
484 }

References arm_compute::test::validation::data_layout, ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input, TensorShape::set(), and arm_compute::WIDTH.

Referenced by NEDeconvolutionLayer::configure(), CLDirectDeconvolutionLayer::configure(), NEDeconvolutionLayer::validate(), and CLDirectDeconvolutionLayer::validate().

◆ compute_deep_convolution_shape() [1/2]

TensorShape arm_compute::misc::shape_calculator::compute_deep_convolution_shape ( const ITensorInfo input,
const ITensorInfo weights,
const PadStrideInfo conv_info 
)
inline

Calculate the deep convolution shape output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor info
[in]conv_infoContains padding and stride information
Returns
the calculated shape

Definition at line 746 of file ShapeCalculator.h.

747 {
748  return compute_deep_convolution_shape(input.tensor_shape(), input.data_layout(), weights.tensor_shape(), conv_info);
749 }

References compute_deep_convolution_shape(), arm_compute::test::validation::conv_info, arm_compute::test::validation::input, and ITensorInfo::tensor_shape().

◆ compute_deep_convolution_shape() [2/2]

TensorShape arm_compute::misc::shape_calculator::compute_deep_convolution_shape ( const TensorShape input_shape,
DataLayout  input_data_layout,
const TensorShape weights_shape,
const PadStrideInfo conv_info 
)
inline

Calculate the deep convolution shape output shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]input_data_layoutInput data layout
[in]weights_shapeWeights tensor shape
[in]conv_infoContains padding and stride information
Returns
the calculated shape

Definition at line 715 of file ShapeCalculator.h.

716 {
717  const size_t idx_width = get_data_layout_dimension_index(input_data_layout, DataLayoutDimension::WIDTH);
718  const size_t idx_height = get_data_layout_dimension_index(input_data_layout, DataLayoutDimension::HEIGHT);
719  const size_t idx_channel = get_data_layout_dimension_index(input_data_layout, DataLayoutDimension::CHANNEL);
720 
721  const unsigned int input_width = input_shape[idx_width];
722  const unsigned int input_height = input_shape[idx_height];
723  const unsigned int weights_width = weights_shape[idx_width];
724  const unsigned int weights_height = weights_shape[idx_height];
725  const unsigned int weights_out_channel = weights_shape[3];
726  unsigned int output_width = 0;
727  unsigned int output_height = 0;
728  std::tie(output_width, output_height) = scaled_dimensions(input_width, input_height, weights_width, weights_height, conv_info);
729 
730  TensorShape output_shape{ input_shape };
731  output_shape.set(idx_width, output_width);
732  output_shape.set(idx_height, output_height);
733  output_shape.set(idx_channel, weights_out_channel);
734 
735  return output_shape;
736 }

References arm_compute::CHANNEL, arm_compute::test::validation::conv_info, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, input_height, arm_compute::test::validation::input_shape, input_width, arm_compute::test::validation::output_shape, arm_compute::scaled_dimensions(), weights_height, arm_compute::test::validation::weights_shape, weights_width, and arm_compute::WIDTH.

Referenced by compute_deep_convolution_shape(), compute_indirect_buffer_shape(), CpuDirectConv2dKernel::configure(), ClIndirectConv2dKernel::configure(), ClIndirectConv2dAddressPrecalculationKernel::configure(), ClDirectConv2dKernel::configure(), ClConv2d::get_convolution_method(), arm_compute::test::validation::TEST_CASE(), ClComponentDirectConv2d::validate(), and arm_compute::cpu::kernels::validate_arguments().

◆ compute_depth_to_space_shape()

TensorShape arm_compute::misc::shape_calculator::compute_depth_to_space_shape ( const TensorShape input_shape,
DataLayout  data_layout,
int  block 
)
inline

Calculate the depth to space output shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]data_layoutOperation data layout
[in]blockBlock shape value
Returns
the calculated shape

Definition at line 1147 of file ShapeCalculator.h.

1148 {
1149  ARM_COMPUTE_ERROR_ON(block < 2);
1150 
1151  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1152  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1153  const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1154 
1155  TensorShape output_shape{ input_shape };
1158  output_shape.set(idx_channel, input_shape[idx_channel] / (block * block));
1159 
1160  return output_shape;
1161 }

References ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, and arm_compute::WIDTH.

Referenced by DepthToSpaceLayerNode::compute_output_descriptor(), NEDepthToSpaceLayerKernel::configure(), and CLDepthToSpaceLayerKernel::configure().

◆ compute_depthwise_convolution_shape()

TensorShape arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape ( const ITensorInfo input,
const ITensorInfo weights,
const ConvolutionInfo info 
)
inline

Calculate the depthwise convolution output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor info
[in]infoConvolution info
Returns
the calculated shape

Definition at line 422 of file ShapeCalculator.h.

423 {
424  const TensorShape input_shape{ input.tensor_shape() };
425  const TensorShape weights_shape{ weights.tensor_shape() };
426 
427  const DataLayout data_layout = input.data_layout();
428  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
429  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
430  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
431 
432  const DataLayout weights_data_layout = weights.data_layout();
433  const int weights_width_idx = get_data_layout_dimension_index(weights_data_layout, DataLayoutDimension::WIDTH);
434  const int weights_height_idx = get_data_layout_dimension_index(weights_data_layout, DataLayoutDimension::HEIGHT);
435 
436  unsigned int output_width = 0;
437  unsigned int output_height = 0;
438  std::tie(output_width, output_height) = scaled_dimensions(input_shape[width_idx], input_shape[height_idx],
439  weights_shape[weights_width_idx], weights_shape[weights_height_idx],
440  info.pad_stride_info, info.dilation);
441 
442  TensorShape output_shape{ input_shape };
443  output_shape.set(width_idx, output_width);
444  output_shape.set(height_idx, output_height);
445  output_shape.set(channel_idx, input_shape[channel_idx] * info.depth_multiplier);
446 
447  return output_shape;
448 }

References arm_compute::CHANNEL, ITensorInfo::data_layout(), arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::info, arm_compute::test::validation::input, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, arm_compute::scaled_dimensions(), ITensorInfo::tensor_shape(), arm_compute::test::validation::weights_shape, and arm_compute::WIDTH.

Referenced by CpuDepthwiseConv2dNativeKernel::configure(), CpuDepthwiseConv2dAssemblyWrapperKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CpuDepthwiseConv2dAssemblyWrapperKernel::validate(), CLDepthwiseConvolutionLayer::validate(), and ClComponentDepthwiseConv2d::validate().

◆ compute_flatten_shape()

TensorShape arm_compute::misc::shape_calculator::compute_flatten_shape ( const ITensorInfo input)
inline

Calculate the flattened output shape of a tensor.

Parameters
[in]inputInput tensor info
Returns
the calculated shape

Definition at line 563 of file ShapeCalculator.h.

564 {
565  // The output shape will be the flatten version of the input (i.e. [ width * height * channels, num_batches, ... ] ). Used for FlattenLayer and FullyConnectedLayer.
566 
567  TensorShape output_shape{ input->tensor_shape() };
568 
569  output_shape.collapse(3);
570 
571  return output_shape;
572 }

References arm_compute::test::validation::input, and arm_compute::test::validation::output_shape.

Referenced by NEFlattenLayer::configure(), CLFlattenLayer::configure(), NEFlattenLayer::validate(), CLFlattenLayer::validate(), CpuFullyConnected::validate(), and ClFullyConnected::validate().

◆ compute_gather_shape()

TensorShape arm_compute::misc::shape_calculator::compute_gather_shape ( const TensorShape input_shape,
const TensorShape indices_shape,
uint32_t  actual_axis 
)
inline

Calculate the gather output shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]indices_shapeIndices tensor shape. Only supports for 2d and 3d indices
[in]actual_axisAxis to be used in the computation
Note
Let input_shape be (X,Y,Z) and indices shape (W,O,P) and axis 1 the new shape is computed by replacing the axis in the input shape with the indice shape so the output shape will be (X,W,O,P,Z)
Returns
the calculated shape

Definition at line 1579 of file ShapeCalculator.h.

1580 {
1581  const auto input_num_dims = input_shape.num_dimensions();
1582  const auto indices_num_dims = indices_shape.num_dimensions();
1583 
1584  ARM_COMPUTE_ERROR_ON(actual_axis >= input_num_dims);
1585  ARM_COMPUTE_ERROR_ON(input_num_dims + indices_num_dims - 1 > Coordinates::num_max_dimensions);
1586 
1587  TensorShape output_shape;
1588  size_t dim_no = 0;
1589 
1590  for(; dim_no < actual_axis; ++dim_no)
1591  {
1592  output_shape.set(dim_no, input_shape[dim_no]);
1593  }
1594 
1595  for(; dim_no < actual_axis + indices_num_dims; ++dim_no)
1596  {
1597  output_shape.set(dim_no, indices_shape[dim_no - actual_axis]);
1598  }
1599 
1600  for(; dim_no < input_num_dims + indices_num_dims - 1; ++dim_no)
1601  {
1602  output_shape.set(dim_no, input_shape[dim_no + 1 - indices_num_dims]);
1603  }
1604 
1605  ARM_COMPUTE_ERROR_ON(input_shape.total_size() * indices_shape.total_size() != output_shape.total_size() * input_shape[actual_axis]);
1606 
1607  return output_shape;
1608 }

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::input_shape, Dimensions< T >::num_dimensions(), Dimensions< int >::num_max_dimensions, arm_compute::test::validation::output_shape, and TensorShape::total_size().

Referenced by NEGatherKernel::configure(), and arm_compute::test::validation::reference::gather().

◆ compute_im2col_conv_shape()

TensorShape arm_compute::misc::shape_calculator::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,
unsigned int  input_pad_right = 0 
)
inline

Calculate the im2col output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]kernel_dimsThe kernel dimensions (width and height).
[in]conv_infoContains padding and stride information
[in]has_biasIn case biases are provided expands the matrix with 1
[in]dilationDilation, in elements, across x and y
[in]batch_size_on_zTrue if batch size is on z axis
[in]num_groups(Optional) Number of groups when performing a grouped convolution
[in]input_pad_right(Optional) When fast-math is selected, per element padding for the im2col matrix may be necessary
Returns
the calculated shape

Definition at line 525 of file ShapeCalculator.h.

527 {
528  // The output shape will be the 3D shape [ out_channels * kernel_area, num_elems_per_out_channel, batches ] if batch_size_on_z == true
529  // or the 4D shape [ out_channels * kernel_area / num_groups, num_elems_per_out_channel, num_groups, batches ] if batch_size_on_z == false
530 
532  ARM_COMPUTE_ERROR_ON(num_groups > 1 && input->data_layout() != DataLayout::NCHW);
533  ARM_COMPUTE_ERROR_ON(num_groups > 1 && batch_size_on_z);
534 
535  TensorShape output_shape{ input->tensor_shape() };
536 
537  const DataLayout data_layout = input->data_layout();
538  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
539  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
540  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
541 
542  std::pair<unsigned int, unsigned int> out_dims = scaled_dimensions(output_shape[width_idx], output_shape[height_idx], kernel_dims.width, kernel_dims.height, conv_info, dilation);
543  output_shape.set(0, ((output_shape[channel_idx] + input_pad_right) / num_groups * kernel_dims.area() + (has_bias ? 1 : 0))); // NOLINT
544  output_shape.set(1, (out_dims.first * out_dims.second));
545  if(batch_size_on_z && output_shape.num_dimensions() >= 3)
546  {
547  output_shape.remove_dimension(2);
548  }
549  else
550  {
551  output_shape.set(2, num_groups);
552  }
553 
554  return output_shape;
555 }

References Size2D::area(), ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::conv_info, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::test::validation::has_bias, Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::NCHW, arm_compute::test::validation::num_groups, arm_compute::test::validation::output_shape, arm_compute::scaled_dimensions(), Size2D::width, and arm_compute::WIDTH.

Referenced by CpuIm2ColKernel::configure(), and ClGemmConv2d::validate().

◆ compute_indirect_buffer_shape()

TensorShape arm_compute::misc::shape_calculator::compute_indirect_buffer_shape ( const TensorShape input_shape,
DataLayout  input_data_layout,
const TensorShape weights_shape,
const PadStrideInfo conv_info,
const DirectConvComputeKernelInfo desc 
)
inline

Calculate the indirect buffer output shape used by the indirect convolution function.

Parameters
[in]input_shapeInput tensor shape
[in]input_data_layoutInput data layout
[in]weights_shapeWeights tensor shape
[in]conv_infoContains padding and stride information
[in]descContains the direct/indirect convolution compute arguments, such as the tiling dimensions
Returns
the calculated shape

Definition at line 761 of file ShapeCalculator.h.

763 {
764  ARM_COMPUTE_ERROR_ON_MSG(input_data_layout != DataLayout::NHWC, "The data layout can only be NHWC");
765  ARM_COMPUTE_ERROR_ON_MSG(desc.m0 <= 0 || desc.m0 > 8, "M0 can only be greater than 0 and less than or equal to 8");
766 
767  const unsigned int m0 = desc.m0;
768  const unsigned int kw = weights_shape[1];
769  const unsigned int kh = weights_shape[2];
770 
771  TensorShape output_conv2d_shape = compute_deep_convolution_shape(input_shape, input_data_layout, weights_shape, conv_info);
772 
773  const unsigned int output_w = m0 * kw * kh;
774  const unsigned int output_h = DIV_CEIL(output_conv2d_shape[1] * output_conv2d_shape[2], m0);
775  const unsigned int output_b = output_conv2d_shape[3];
776 
777  return TensorShape(output_w, output_h, output_b);
778 }

References ARM_COMPUTE_ERROR_ON_MSG, compute_deep_convolution_shape(), arm_compute::test::validation::conv_info, arm_compute::DIV_CEIL(), arm_compute::test::validation::input_shape, DirectConvComputeKernelInfo::m0, arm_compute::NHWC, and arm_compute::test::validation::weights_shape.

Referenced by ClIndirectConv2dAddressPrecalculationKernel::configure(), and ClIndirectConv2d::validate().

◆ compute_interleaved_shape()

TensorShape arm_compute::misc::shape_calculator::compute_interleaved_shape ( const ITensorInfo a,
int  mult_interleave4x4_height = 1,
bool  reinterpret_input_as_3d = false 
)
inline

Calculate the interleaved shape of an input tensor.

Parameters
[in]aInput tensor info
[in]mult_interleave4x4_height(Optional) Interleave4x4 height
[in]reinterpret_input_as_3d(Optional) Set to true if the input need to be interpreted as 3d
Returns
the calculated shape

Definition at line 262 of file ShapeCalculator.h.

263 {
264  // The interleaved output matrix will have the following shape: [ a_height * W, ceil(a_width / W) ] where W = 4 * mult_interleave4x4_height
265  ARM_COMPUTE_ERROR_ON(mult_interleave4x4_height < 1);
266  const int interleave_width = 4 * mult_interleave4x4_height;
267  TensorShape shape_interleaved_a{ a.tensor_shape() };
268  shape_interleaved_a.set(0, a.dimension(0) * interleave_width);
269  if(reinterpret_input_as_3d)
270  {
271  const int M = a.dimension(1) * a.dimension(2);
272  const int height = std::ceil(M / static_cast<float>(interleave_width));
273  shape_interleaved_a.set(1, height);
274 
275  // When the data format is NHWC and the shapes are Nx1x1
276  // the tensor shape num_dimensions is automatically set to 1 instead of 3.
277  // To avoid failures by removing a dimension that doesn't exist
278  // check if the number of dimensions is greater than 2.
279  if(shape_interleaved_a.num_dimensions() > 2)
280  {
281  shape_interleaved_a.remove_dimension(2);
282  }
283  }
284  else
285  {
286  shape_interleaved_a.set(1, std::ceil(a.dimension(1) / static_cast<float>(interleave_width)));
287  }
288 
289  return shape_interleaved_a;
290 }

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), M, TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by CpuGemmInterleave4x4Kernel::configure(), CpuGemmLowpMatrixMultiplyCore::configure(), CpuGemmInterleave4x4Kernel::validate(), and CpuGemm::validate().

◆ compute_lhs_reshaped_shape()

TensorShape arm_compute::misc::shape_calculator::compute_lhs_reshaped_shape ( const ITensorInfo a,
const GEMMLHSMatrixInfo lhs_info,
bool  reinterpret_input_as_3d = false 
)
inline

Calculate the Left Hand Side matrix reshaped shape.

Parameters
[in]aInput tensor info
[in]lhs_infoLeft Hand Side matrix information
[in]reinterpret_input_as_3d(Optional) Set to true if the input need to be interpreted as 3d
Returns
the calculated shape

Definition at line 182 of file ShapeCalculator.h.

183 {
187 
188  // Input width/height
189  const unsigned int input_width = a.dimension(0);
190  const unsigned int input_height = reinterpret_input_as_3d ? a.dimension(1) * a.dimension(2) : a.dimension(1);
191 
192  // Number of horizontal/vertical blocks in the input tensor
193  const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(lhs_info.k0));
194  const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(lhs_info.m0));
195 
196  // Block size
197  const unsigned int block_size = lhs_info.m0 * lhs_info.k0;
198 
199  // Output width/height
200  const unsigned int output_width = block_size * num_horiz_blocks * lhs_info.v0;
201  const unsigned int output_height = std::ceil(num_vert_blocks / static_cast<float>(lhs_info.v0));
202 
203  TensorShape lhs_shape{ a.tensor_shape() };
204  lhs_shape.set(0, output_width);
205  lhs_shape.set(1, output_height);
206 
207  if((reinterpret_input_as_3d) && (lhs_shape.num_dimensions() > 2))
208  {
209  // When the data format is NHWC and the shapes are Nx1x1
210  // the tensor shape num_dimensions is automatically set to 1 instead of 3.
211  // To avoid failures by removing a dimension that doesn't exist
212  // check if the number of dimensions is greater than 2.
213  lhs_shape.remove_dimension(2);
214  }
215 
216  return lhs_shape;
217 }

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), input_height, input_width, arm_compute::test::validation::lhs_info, TensorShape::remove_dimension(), TensorShape::set(), and ITensorInfo::tensor_shape().

◆ compute_matmul_shape()

TensorShape arm_compute::misc::shape_calculator::compute_matmul_shape ( const TensorShape input0,
const TensorShape input1,
const MatMulKernelInfo matmul_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]matmul_infoBatch MatMul Kernel info to know which matrix is transposed
Returns
the calculated shape

Definition at line 1019 of file ShapeCalculator.h.

1020 {
1021  TensorShape output_shape{ input0 };
1022 
1023  if(matmul_info.adj_lhs)
1024  {
1025  output_shape.set(1, input0[0]); // The vertical (M) dimension
1026  }
1027 
1028  if(matmul_info.adj_rhs)
1029  {
1030  output_shape.set(0, input1[1]); // The horizontal (N) dimension
1031  }
1032  else
1033  {
1034  output_shape.set(0, input1[0]); // The horizontal (N) dimension
1035  }
1036 
1037  return output_shape;
1038 }

References MatMulKernelInfo::adj_lhs, MatMulKernelInfo::adj_rhs, and arm_compute::test::validation::output_shape.

Referenced by ClMatMulNativeKernel::configure(), ClMatMulLowpNativeKernel::configure(), ClMatMulNativeMMULKernel::configure(), ClMatMulNativeKernel::validate(), ClMatMulLowpNativeKernel::validate(), and ClMatMulNativeMMULKernel::validate().

◆ compute_min_max_shape()

TensorShape arm_compute::misc::shape_calculator::compute_min_max_shape ( const ITensorInfo input)
inline

Calculate the min/max shape output shape of a tensor.

Parameters
[in]inputInput tensor info
Returns
the calculated shape

Definition at line 786 of file ShapeCalculator.h.

787 {
788  TensorShape output_shape{ input->tensor_shape() };
789  output_shape.set(Window::DimX, 2);
790  output_shape.remove_dimension(1);
791  output_shape.remove_dimension(1);
792 
793  return output_shape;
794 }

References Window::DimX, arm_compute::test::validation::input, and arm_compute::test::validation::output_shape.

◆ compute_mm_shape() [1/3]

TensorShape arm_compute::misc::shape_calculator::compute_mm_shape ( const ITensorInfo input0,
const ITensorInfo input1,
bool  is_interleaved_transposed,
const GEMMReshapeInfo reshape_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]is_interleaved_transposedTrue if the input is interleaved transposed
[in]reshape_infoGEMM reshape info
Returns
the calculated shape

Definition at line 907 of file ShapeCalculator.h.

908 {
909  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
910  ARM_COMPUTE_ERROR_ON_MSG(is_interleaved_transposed && reshape_info.reinterpret_input_as_3d(), "The first input tensor cannot be reinterpreted as 3D if is_interleaved_transposed is true");
911 
912  const bool reinterpret_input_as_3d = reshape_info.reinterpret_input_as_3d();
913  const bool reinterpret_output_as_3d = reshape_info.depth_output_gemm3d() != 0;
914  const int depth_output_gemm3d = reinterpret_output_as_3d ? reshape_info.depth_output_gemm3d() : 1;
915  const int m = reshape_info.reinterpret_input_as_3d() ? input0.dimension(1) * input0.dimension(2) : input0.dimension(1);
916 
917  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
918  // dimension of the output tensor
919  const int dim0 = is_interleaved_transposed ? reshape_info.n() : input1.dimension(0);
920  const int dim1 = is_interleaved_transposed ? reshape_info.m() / depth_output_gemm3d : m / depth_output_gemm3d;
921  const int dim2 = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
922  const int dim3 = reinterpret_input_as_3d ? 1 : input0.tensor_shape()[3];
923 
924  TensorShape output_shape{ input0.tensor_shape() };
925 
926  output_shape.set(0, dim0);
927  output_shape.set(1, dim1);
928  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2);
929  output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3);
930  output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1);
931 
932  return output_shape;
933 }

References ARM_COMPUTE_ERROR_ON_MSG, GEMMReshapeInfo::depth_output_gemm3d(), ITensorInfo::dimension(), arm_compute::test::validation::m, GEMMReshapeInfo::m(), GEMMReshapeInfo::n(), ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, GEMMReshapeInfo::reinterpret_input_as_3d(), and ITensorInfo::tensor_shape().

Referenced by ClGemmMatrixMultiplyNativeKernel::configure(), ClGemmMatrixMultiplyReshapedOnlyRhsMMULKernel::configure(), ClGemmMatrixMultiplyReshapedOnlyRhsKernel::configure(), ClGemmMatrixMultiplyReshapedKernel::configure(), ClGemmLowpMatrixMultiplyCore::validate(), and CpuGemm::validate().

◆ compute_mm_shape() [2/3]

TensorShape arm_compute::misc::shape_calculator::compute_mm_shape ( const ITensorInfo input0,
const ITensorInfo input1,
const GEMMKernelInfo gemm_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]gemm_infoGEMM kernel info used to retrieve the original dimensions of the input matrices
Returns
the calculated shape

Definition at line 981 of file ShapeCalculator.h.

982 {
983  ARM_COMPUTE_UNUSED(input1);
984  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
985 
986  const bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d;
987  const bool reinterpret_output_as_3d = gemm_info.depth_output_gemm3d != 0;
988  const unsigned int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.depth_output_gemm3d : 1;
989 
990  TensorShape output_shape{ input0.tensor_shape() };
991 
992  if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
993  {
994  output_shape.set(0, gemm_info.n);
995  output_shape.set(1, gemm_info.m);
996  }
997  else
998  {
999  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
1000  // dimension of the output tensor
1001  const unsigned int batch_size = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
1002  output_shape.set(0, gemm_info.n);
1003  output_shape.set(1, gemm_info.m / depth_output_gemm3d);
1004  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
1005  output_shape.set(3, reinterpret_output_as_3d ? batch_size : 1);
1006  }
1007 
1008  return output_shape;
1009 }

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, arm_compute::test::validation::gemm_info, ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, and ITensorInfo::tensor_shape().

◆ compute_mm_shape() [3/3]

TensorShape arm_compute::misc::shape_calculator::compute_mm_shape ( const ITensorInfo input0,
const ITensorInfo input1,
const GEMMReshapeInfo gemm_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]gemm_infoGEMM reshape info
Returns
the calculated shape

Definition at line 943 of file ShapeCalculator.h.

944 {
945  ARM_COMPUTE_UNUSED(input1);
946  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
947 
948  const bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
949  const bool reinterpret_output_as_3d = gemm_info.depth_output_gemm3d() != 0;
950  const int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.depth_output_gemm3d() : 1;
951 
952  TensorShape output_shape{ input0.tensor_shape() };
953 
954  if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
955  {
956  output_shape.set(0, gemm_info.n());
957  output_shape.set(1, gemm_info.m());
958  }
959  else
960  {
961  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
962  // dimension of the output tensor
963  const int batch_size = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
964  output_shape.set(0, gemm_info.n());
965  output_shape.set(1, gemm_info.m() / depth_output_gemm3d);
966  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
967  output_shape.set(3, reinterpret_output_as_3d ? batch_size : 1);
968  }
969 
970  return output_shape;
971 }

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, arm_compute::test::validation::gemm_info, ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, and ITensorInfo::tensor_shape().

◆ compute_output_stage_shape()

TensorShape arm_compute::misc::shape_calculator::compute_output_stage_shape ( const ITensorInfo input,
unsigned int  gemm_3d_depth = 1,
bool  batch_size_on_z = false 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]inputInput tensor info
[in]gemm_3d_depth(Optional) GEMM 3d depth
[in]batch_size_on_z(Optional) True if batch size is on z axis
Returns
the calculated shape

Definition at line 1047 of file ShapeCalculator.h.

1048 {
1049  ARM_COMPUTE_ERROR_ON(input.data_layout() != DataLayout::NHWC && gemm_3d_depth > 1);
1050 
1051  TensorShape output_shape = input.tensor_shape();
1052  if(gemm_3d_depth > 1)
1053  {
1054  if(batch_size_on_z)
1055  {
1056  output_shape.shift_right(1);
1057  }
1058  output_shape.set(0, input.tensor_shape().x());
1059  output_shape.set(1, input.tensor_shape().y() / gemm_3d_depth);
1060  output_shape.set(2, gemm_3d_depth);
1061  }
1062 
1063  return output_shape;
1064 }

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::input, arm_compute::NHWC, and arm_compute::test::validation::output_shape.

◆ compute_padded_shape()

TensorShape arm_compute::misc::shape_calculator::compute_padded_shape ( const TensorShape input_shape,
const PaddingList padding 
)
inline

Calculate the padded shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]paddingPaddings list
Returns
the calculated shape

Definition at line 1276 of file ShapeCalculator.h.

1277 {
1278  TensorShape padded_shape = input_shape;
1279  for(size_t dim = 0; dim < padding.size(); ++dim)
1280  {
1281  const auto &padding_pair = padding[dim];
1282  const uint32_t shape_on_index = (padded_shape.num_dimensions() <= dim) ? 1 : input_shape[dim];
1283  padded_shape.set(dim, padding_pair.first + shape_on_index + padding_pair.second);
1284  }
1285  return padded_shape;
1286 }

References arm_compute::test::validation::input_shape, Dimensions< T >::num_dimensions(), and TensorShape::set().

Referenced by NEPadLayerKernel::configure(), CLPadLayerKernel::configure(), NEPadLayer::configure(), arm_compute::test::validation::reference::pad_layer(), and NEPadLayer::validate().

◆ compute_permutation_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_permutation_output_shape ( const ITensorInfo input,
const PermutationVector perm 
)
inline

Calculate the permuted shape of an input given a permutation vector.

Parameters
[in]inputInput tensor info
[in]permPermutation vector
Returns
the calculated shape

Definition at line 110 of file ShapeCalculator.h.

111 {
112  TensorShape output_shape = input.tensor_shape();
113  permute(output_shape, perm);
114  return output_shape;
115 }

References arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::permute().

Referenced by CpuPermuteKernel::configure(), CPPPermuteKernel::configure(), ClSoftmax::validate(), and CpuSoftmaxGeneric< IS_LOG >::validate().

◆ compute_pool3d_shape()

TensorShape arm_compute::misc::shape_calculator::compute_pool3d_shape ( const TensorShape src,
Pooling3dLayerInfo  pool3d_info 
)
inline

Calculate the output pool3d shape of a tensor.

Parameters
[in]srcInput tensor info
[in]pool3d_infoPooling layer info
Returns
the calculated shape

Definition at line 1540 of file ShapeCalculator.h.

1541 {
1542  TensorShape output_shape{ src };
1543 
1544  const auto data_layout = DataLayout::NDHWC;
1545  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1546  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1547  const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::DEPTH);
1548  const int pool_size_width = pool3d_info.is_global_pooling ? src[idx_width] : pool3d_info.pool_size.width;
1549  const int pool_size_height = pool3d_info.is_global_pooling ? src[idx_height] : pool3d_info.pool_size.height;
1550  const int pool_size_depth = pool3d_info.is_global_pooling ? src[idx_depth] : pool3d_info.pool_size.depth;
1551  int output_width = 0;
1552  int output_height = 0;
1553  int output_depth = 0;
1554 
1555  std::tie(output_width, output_height, output_depth) = scaled_3d_dimensions_signed(src[idx_width], src[idx_height], src[idx_depth], pool_size_width, pool_size_height,
1556  pool_size_depth, pool3d_info);
1557 
1558  ARM_COMPUTE_ERROR_ON_MSG((output_width < 1 || output_height < 1 || output_depth < 1), "Calculated output dimension size is invalid");
1559 
1560  output_shape.set(idx_width, static_cast<size_t>(output_width));
1561  output_shape.set(idx_height, static_cast<size_t>(output_height));
1562  output_shape.set(idx_depth, static_cast<size_t>(output_depth));
1563 
1564  return output_shape;
1565 }

References ARM_COMPUTE_ERROR_ON_MSG, arm_compute::test::validation::data_layout, Size3D::depth, arm_compute::DEPTH, arm_compute::get_data_layout_dimension_index(), Size3D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, Pooling3dLayerInfo::is_global_pooling, arm_compute::NDHWC, arm_compute::test::validation::output_shape, Pooling3dLayerInfo::pool_size, arm_compute::scaled_3d_dimensions_signed(), arm_compute::test::validation::src, Size3D::width, and arm_compute::WIDTH.

Referenced by ClPool3dKernel::configure(), CpuPool3dKernel::configure(), and arm_compute::test::validation::reference::pooling_3d_layer_internal().

◆ compute_pool_shape()

TensorShape arm_compute::misc::shape_calculator::compute_pool_shape ( const ITensorInfo input,
PoolingLayerInfo  pool_info 
)
inline

Calculate the output pool shape of a tensor.

Parameters
[in]inputInput tensor info
[in]pool_infoPooling layer info
Returns
the calculated shape

Definition at line 803 of file ShapeCalculator.h.

804 {
805  int pooled_w = 0;
806  int pooled_h = 0;
807 
808  TensorShape output_shape{ input.tensor_shape() };
809 
810  const bool is_global_pooling = pool_info.is_global_pooling;
811  const int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
812  const int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
813  const int input_width = input.tensor_shape()[idx_width];
814  const int input_height = input.tensor_shape()[idx_height];
815  const int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size.width;
816  const int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size.height;
817 
818  std::tie(pooled_w, pooled_h) = scaled_dimensions_signed(input_width, input_height,
819  pool_size_x, pool_size_y,
820  pool_info.pad_stride_info);
821 
822  ARM_COMPUTE_ERROR_ON_MSG((pooled_w < 1 || pooled_h < 1), "Calculated output dimension size is invalid");
823 
824  output_shape.set(idx_width, static_cast<size_t>(pooled_w));
825  output_shape.set(idx_height, static_cast<size_t>(pooled_h));
826 
827  return output_shape;
828 }

References ARM_COMPUTE_ERROR_ON_MSG, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, input_height, input_width, PoolingLayerInfo::is_global_pooling, arm_compute::test::validation::output_shape, PoolingLayerInfo::pad_stride_info, PoolingLayerInfo::pool_size, arm_compute::scaled_dimensions_signed(), Size2D::width, and arm_compute::WIDTH.

Referenced by ClPool2dKernel::configure(), CpuPool2dAssemblyWrapperKernel::configure(), GpuPool2d::create_op(), GpuPool2d::is_supported_op(), arm_compute::test::validation::reference::pooling_layer_internal(), ClComponentPool2d::validate(), and GpuPool2d::validate_op().

◆ compute_prior_box_shape()

TensorShape arm_compute::misc::shape_calculator::compute_prior_box_shape ( const ITensorInfo input,
const PriorBoxLayerInfo info 
)
inline

Calculate the prior box output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]infoPriorBoxLayer info
Returns
the calculated shape

Definition at line 1255 of file ShapeCalculator.h.

1256 {
1257  DataLayout data_layout = input.data_layout();
1258  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1259  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1260  const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
1261 
1262  TensorShape output_shape{};
1263  output_shape.set(0, input.dimension(idx_w) * input.dimension(idx_h) * num_priors * 4);
1264  output_shape.set(1, 2);
1265 
1266  return output_shape;
1267 }

References arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::info, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::WIDTH.

◆ compute_reduced_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reduced_shape ( const TensorShape input,
unsigned int  axis,
bool  keep_dims = true 
)
inline

Calculate the reduced shape of a tensor given an axis.

Parameters
[in]inputInput tensor info
[in]axisAxis on which to perform reduction
[in]keep_dims(Optional) Whether to keep the dimension after reduction operation. Defaults to true.
Returns
the calculated shape

Definition at line 1313 of file ShapeCalculator.h.

1314 {
1315  TensorShape output_shape{ input };
1316 
1317  if(!keep_dims)
1318  {
1319  output_shape.remove_dimension(axis);
1320  }
1321  else
1322  {
1323  output_shape.set(axis, 1);
1324  }
1325 
1326  return output_shape;
1327 }

References arm_compute::test::validation::input, and arm_compute::test::validation::output_shape.

Referenced by NEReductionOperationKernel::configure(), CLReductionOperationKernel::configure(), NEReductionOperation::configure(), CLReductionOperation::configure(), CLArgMinMaxLayer::configure(), ReductionLayerNode::configure_output(), ArgMinMaxLayerNode::configure_output(), NEReductionOperation::validate(), CLArgMinMaxLayer::validate(), and CLReductionOperation::validate().

◆ compute_reductionA_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reductionA_shape ( const ITensorInfo b)
inline

Calculate the reductionA shape used in GEMMLowp.

Parameters
[in]bInput tensor info
Returns
the calculated shape

Definition at line 335 of file ShapeCalculator.h.

336 {
337  TensorShape shape_vector_sum_col{ b.tensor_shape() };
338  if(shape_vector_sum_col.num_dimensions() > 1)
339  {
340  shape_vector_sum_col.remove_dimension(1);
341  }
342 
343  return shape_vector_sum_col;
344 }

References arm_compute::test::validation::b.

Referenced by ClGemmLowpMatrixMultiplyCore::configure(), CpuGemmLowpMatrixMultiplyCore::configure(), ClGemmLowpMatrixMultiplyCore::validate(), and CpuGemmLowpMatrixMultiplyCore::validate().

◆ compute_reductionB_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reductionB_shape ( const ITensorInfo a)
inline

Calculate the reductionB shape used in GEMMLowp.

Parameters
[in]aInput tensor info
Returns
the calculated shape

Definition at line 352 of file ShapeCalculator.h.

353 {
354  TensorShape shape_vector_sum_row{ a.tensor_shape() };
355  shape_vector_sum_row.set(Window::DimX, a.dimension(1));
356  if(shape_vector_sum_row.num_dimensions() > 1)
357  {
358  shape_vector_sum_row.remove_dimension(1);
359  }
360 
361  return shape_vector_sum_row;
362 }

References ITensorInfo::dimension(), Window::DimX, TensorShape::remove_dimension(), TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by ClGemmLowpMatrixMultiplyCore::configure(), CpuGemmLowpMatrixMultiplyCore::configure(), ClGemmLowpMatrixMultiplyCore::validate(), and CpuGemmLowpMatrixMultiplyCore::validate().

◆ compute_reorg_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reorg_output_shape ( const ITensorInfo input,
int32_t  stride 
)
inline

Calculate the output shape of the reorg layer given a stride.

Parameters
[in]inputInput tensor info
[in]strideStride
Returns
the calculated shape

Definition at line 124 of file ShapeCalculator.h.

125 {
126  const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
127  const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
128  const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
129 
130  ARM_COMPUTE_ERROR_ON(stride <= 0);
131  ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_width] % stride != 0), "The width of the input tensor must be a multiple of stride");
132  ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_height] % stride != 0), "The height of the input tensor must be a multiple of stride");
133 
134  TensorShape output_shape{ input.tensor_shape() };
135 
138  output_shape.set(idx_channel, output_shape[idx_channel] * stride * stride);
139 
140  return output_shape;
141 }

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::CHANNEL, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::WIDTH.

Referenced by NEReorgLayerKernel::configure(), CLReorgLayerKernel::configure(), and arm_compute::test::validation::reference::reorg_layer().

◆ compute_rhs_reshaped_shape()

TensorShape arm_compute::misc::shape_calculator::compute_rhs_reshaped_shape ( const ITensorInfo a,
const GEMMRHSMatrixInfo rhs_info 
)
inline

Calculate the Right Hand Side matrix reshaped shape.

Parameters
[in]aInput tensor info
[in]rhs_infoRight Hand Side matrix information
Returns
the calculated shape

Definition at line 226 of file ShapeCalculator.h.

227 {
231 
232  // Input width/height
233  const unsigned int input_width = a.dimension(0);
234  const unsigned int input_height = a.dimension(1);
235 
236  // Number of horizontal/vertical blocks in the input tensor
237  const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(rhs_info.n0));
238  const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(rhs_info.k0));
239 
240  // Block size
241  const unsigned int block_size = rhs_info.n0 * rhs_info.k0;
242 
243  // Output width/height
244  const unsigned int output_width = block_size * num_vert_blocks * rhs_info.h0;
245  const unsigned int output_height = std::ceil(num_horiz_blocks / static_cast<float>(rhs_info.h0));
246 
247  TensorShape rhs_shape{ a.tensor_shape() };
248  rhs_shape.set(0, output_width);
249  rhs_shape.set(1, output_height);
250 
251  return rhs_shape;
252 }

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), input_height, input_width, arm_compute::test::validation::rhs_info, TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by arm_compute::opencl::kernels::gemm::select_lhs_rhs_info(), and ClGemmLowpMatrixMultiplyCore::validate().

◆ compute_rnn_shape()

TensorShape arm_compute::misc::shape_calculator::compute_rnn_shape ( const ITensorInfo input,
const unsigned int  batch_size 
)
inline

Calculate the RNN shape of a tensor.

Parameters
[in]inputInput tensor info
[in]batch_sizeBatch size
Returns
the calculated shape

Definition at line 890 of file ShapeCalculator.h.

891 {
892  TensorShape output_shape{ input->tensor_shape() };
893  output_shape.set(1, batch_size);
894 
895  return output_shape;
896 }

References arm_compute::test::validation::input, and arm_compute::test::validation::output_shape.

Referenced by NERNNLayer::configure(), CLRNNLayer::configure(), NERNNLayer::validate(), and CLRNNLayer::validate().

◆ compute_roi_align_shape()

TensorShape arm_compute::misc::shape_calculator::compute_roi_align_shape ( const ITensorInfo input,
const ITensorInfo rois,
ROIPoolingLayerInfo  pool_info 
)
inline

Calculate the output roi align shape of a tensor.

Parameters
[in]inputInput tensor info
[in]roisRois tensor info
[in]pool_infoPooling layer info
Returns
the calculated shape

Definition at line 869 of file ShapeCalculator.h.

870 {
871  TensorShape output_shape{ input.tensor_shape() };
872 
873  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
874  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
875 
876  output_shape.set(idx_width, pool_info.pooled_width());
877  output_shape.set(idx_height, pool_info.pooled_height());
878  output_shape.set(3, rois.dimension(1));
879 
880  return output_shape;
881 }

References ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, ROIPoolingLayerInfo::pooled_height(), ROIPoolingLayerInfo::pooled_width(), and arm_compute::WIDTH.

Referenced by NEROIAlignLayerKernel::configure(), and CLROIAlignLayerKernel::configure().

◆ compute_slice_shape()

TensorShape arm_compute::misc::shape_calculator::compute_slice_shape ( const TensorShape input_shape,
const Coordinates starts,
const Coordinates ends 
)
inline

Calculate the slice output shape of a tensor.

Parameters
[in]input_shapeInput tensor info
[in]startsThe starts of the dimensions of the input tensor to be sliced
[in]endsThe ends of the dimensions of the input tensor to be sliced
Returns
the calculated shape

Definition at line 1094 of file ShapeCalculator.h.

1095 {
1097 
1099  starts, ends, BiStrides(),
1100  0, construct_slice_end_mask(ends), 0);
1101 }

References arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape(), arm_compute::helpers::tensor_transform::construct_slice_end_mask(), and arm_compute::test::validation::input_shape.

Referenced by SliceLayerNode::compute_output_descriptor(), and arm_compute::test::validation::reference::slice().

◆ compute_softmax_shape()

TensorShape arm_compute::misc::shape_calculator::compute_softmax_shape ( const ITensorInfo input,
size_t  axis = 1 
)
inline

Calculate the softmax output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]axis(Optional) Softmax axis
Returns
the calculated shape

Definition at line 581 of file ShapeCalculator.h.

582 {
583  // The output shape will be a 2D version of the input. For instance:
584  // - [x,y,z] and axis 1 will return [x, y*z]
585  // - [x,y,z,w] and axis 2 will return [x*y, w*z]
586  // - [x,y,z,w] and axis 3 will return [x*y*z, w]
587  TensorShape shape2D = input->tensor_shape();
588 
589  if(axis < input->num_dimensions())
590  {
591  // Collapse from axis onward (this changes the shape)
592  shape2D.collapse_from(axis);
593 
594  // Collapse the rest (collapse is inclusive)
595  shape2D.collapse(shape2D.num_dimensions() - 1);
596  }
597  else
598  {
599  // Collapse everything
600  shape2D.collapse(shape2D.num_dimensions());
601  }
602 
603  if(axis == 0)
604  {
605  // If axis is zero the first dim should be one. Since
606  // collapse is an inclusive operation we need to shift
607  shape2D.shift_right(1);
608  }
609 
610  return shape2D;
611 }

References TensorShape::collapse(), Dimensions< T >::collapse_from(), arm_compute::test::validation::input, Dimensions< T >::num_dimensions(), and TensorShape::shift_right().

◆ compute_space_to_batch_shape()

TensorShape arm_compute::misc::shape_calculator::compute_space_to_batch_shape ( const ITensorInfo input,
int  block_x,
int  block_y,
const Size2D padding_left,
const Size2D padding_right 
)
inline

Calculate the space to batch output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]block_xBlock shape x value
[in]block_yBlock shape y value
[in]padding_leftLeft padding values
[in]padding_rightRight padding values
Returns
the calculated shape

Definition at line 1206 of file ShapeCalculator.h.

1207 {
1208  TensorShape output_shape{ input->tensor_shape() };
1209 
1210  const DataLayout data_layout = input->data_layout();
1211  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1212  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1213  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1214 
1215  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) % block_x != 0);
1216  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) % block_y != 0);
1217 
1218  output_shape.set(idx_width, (input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) / block_x);
1219  output_shape.set(idx_height, (input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) / block_y);
1220  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] * block_x * block_y);
1221 
1222  return output_shape;
1223 }

References ARM_COMPUTE_ERROR_ON, arm_compute::BATCHES, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, arm_compute::WIDTH, Size2D::x(), and Size2D::y().

Referenced by NESpaceToBatchLayerKernel::configure(), and CLSpaceToBatchLayerKernel::configure().

◆ compute_space_to_depth_shape()

TensorShape arm_compute::misc::shape_calculator::compute_space_to_depth_shape ( const ITensorInfo input,
int32_t  block_shape 
)
inline

Calculate the space to batch output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]block_shapeBlock shape value
Returns
the calculated shape

Definition at line 1232 of file ShapeCalculator.h.

1233 {
1234  TensorShape output_shape{ input->tensor_shape() };
1235 
1236  const DataLayout data_layout = input->data_layout();
1237  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1238  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1239  const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1240 
1241  output_shape.set(idx_width, input->tensor_shape()[idx_width] / block_shape);
1242  output_shape.set(idx_height, input->tensor_shape()[idx_height] / block_shape);
1243  output_shape.set(idx_depth, input->tensor_shape()[idx_depth] * (block_shape * block_shape));
1244 
1245  return output_shape;
1246 }

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::WIDTH.

Referenced by NESpaceToDepthLayerKernel::configure(), and CLSpaceToDepthLayerKernel::configure().

◆ compute_split_shape()

TensorShape arm_compute::misc::shape_calculator::compute_split_shape ( const ITensorInfo input,
unsigned int  axis,
unsigned int  num_splits 
)
inline

Calculate the split output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]axisAxis on which to split the input
[in]num_splitsNumber of splits
Returns
the calculated shape

Definition at line 1171 of file ShapeCalculator.h.

1172 {
1173  TensorShape empty_shape;
1174  empty_shape.set(0, 0);
1175 
1176  TensorShape out_shape{ input->tensor_shape() };
1177 
1178  // Return empty shape if axis is invalid
1179  if(axis > input->tensor_shape().num_dimensions())
1180  {
1181  return empty_shape;
1182  }
1183 
1184  size_t axis_size = out_shape[axis];
1185 
1186  // Return empty shape if num_split is not valid
1187  if(axis_size % num_splits)
1188  {
1189  return empty_shape;
1190  }
1191 
1192  out_shape[axis] = axis_size / num_splits;
1193  return out_shape;
1194 }

References arm_compute::test::validation::input, and TensorShape::set().

Referenced by CPPSplit< CLSlice, ICLTensor >::configure(), and CPPSplit< CLSlice, ICLTensor >::validate().

◆ compute_stack_shape()

TensorShape arm_compute::misc::shape_calculator::compute_stack_shape ( const ITensorInfo a,
unsigned int  axis,
unsigned int  num_tensors 
)
inline

Calculate the stack output shape of a tensor.

Parameters
[in]aInput tensor info
[in]axisAxis on which to perform the stack operation
[in]num_tensorsNumber of tensors to stack
Returns
the calculated shape

Definition at line 1446 of file ShapeCalculator.h.

1447 {
1448  ARM_COMPUTE_ERROR_ON(axis > a.num_dimensions());
1449  ARM_COMPUTE_ERROR_ON(a.num_dimensions() > 4);
1450 
1451  TensorShape shape_out{ a.tensor_shape() };
1452  shape_out.set(axis, num_tensors);
1453 
1454  unsigned int i_shift = 0;
1455 
1456  for(unsigned int i = 0; i < a.num_dimensions(); ++i)
1457  {
1458  if(i == axis)
1459  {
1460  i_shift++;
1461  }
1462 
1463  shape_out.set(i + i_shift, a.tensor_shape()[i]);
1464  }
1465  return shape_out;
1466 }

References ARM_COMPUTE_ERROR_ON, ITensorInfo::num_dimensions(), TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by StackLayerNode::compute_output_descriptor().

◆ compute_strided_slice_shape()

TensorShape arm_compute::misc::shape_calculator::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 
)
inline

Calculate the strided slice output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]startsThe starts of the dimensions of the input tensor to be sliced
[in]endsThe ends of the dimensions of the input tensor to be sliced
[in]stridesThe strides of the dimensions of the input tensor to be sliced
[in]begin_maskIf the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
[in]end_maskIf the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
[in]shrink_axis_maskIf the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1
Returns
the calculated shape

Definition at line 1078 of file ShapeCalculator.h.

1081 {
1083  return compute_strided_slice_output_shape(input.tensor_shape(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
1084 }

References arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape(), and arm_compute::test::validation::input.

Referenced by CLStridedSliceKernel::configure().

◆ compute_tiled_shape()

TensorShape arm_compute::misc::shape_calculator::compute_tiled_shape ( const TensorShape input_shape,
const Multiples multiples 
)
inline

Calculate the tiled shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]multiplesPaddings list
Returns
the calculated shape

Definition at line 1295 of file ShapeCalculator.h.

1296 {
1297  TensorShape tiled_shape = input_shape;
1298  for(size_t dim = 0; dim < multiples.size(); ++dim)
1299  {
1300  tiled_shape.set(dim, input_shape[dim] * multiples[dim]);
1301  }
1302  return tiled_shape;
1303 }

References arm_compute::test::validation::input_shape, and TensorShape::set().

Referenced by NETileKernel::configure(), CLTileKernel::configure(), and arm_compute::test::validation::reference::tile().

◆ compute_transpose1xW_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transpose1xW_shape ( const ITensorInfo b)
inline

Calculate the transposed 1xW shape.

Parameters
[in]bInput tensor info
Returns
the calculated shape

Definition at line 298 of file ShapeCalculator.h.

299 {
300  // The transpose1xW output matrix will have the following shape: [ b_height * 16, ceil(b_width / 16.0f) ]
301  TensorShape shape_transposed1xW_b{ b.tensor_shape() };
302  shape_transposed1xW_b.set(0, b.dimension(1) * 16);
303  shape_transposed1xW_b.set(1, std::ceil(b.dimension(0) / 16.f));
304 
305  return shape_transposed1xW_b;
306 }

References arm_compute::test::validation::b.

Referenced by CpuGemmLowpMatrixMultiplyCore::configure().

◆ compute_transpose1xW_with_element_size_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transpose1xW_with_element_size_shape ( const ITensorInfo b,
int  mult_transpose1xW_width = 1 
)
inline

Calculate the transposed 1xW width element shape.

Parameters
[in]bInput tensor info
[in]mult_transpose1xW_width(Optional) Transpose1xW width
Returns
the calculated shape

Definition at line 315 of file ShapeCalculator.h.

316 {
317  // Note: mult_transpose1xW_width expresses the number of chunks with size 1x(W) we want to store on the same row
318  // The transpose1xW output matrix will have the following shape:
319  // [ b_height * W, ceil(b_width / W) ] where W = (16 / element size of the tensor) * mult_transpose1xW_width
320  ARM_COMPUTE_ERROR_ON(mult_transpose1xW_width < 1);
321  TensorShape shape_transposed1xW_b{ b.tensor_shape() };
322  const size_t transpose_width = (16 / b.element_size()) * mult_transpose1xW_width;
323  shape_transposed1xW_b.set(0, b.dimension(1) * transpose_width);
324  shape_transposed1xW_b.set(1, static_cast<size_t>(std::ceil(b.dimension(0) / static_cast<float>(transpose_width))));
325 
326  return shape_transposed1xW_b;
327 }

References ARM_COMPUTE_ERROR_ON, and arm_compute::test::validation::b.

Referenced by CpuGemmTranspose1xWKernel::configure(), CpuGemmTranspose1xWKernel::validate(), and CpuGemm::validate().

◆ compute_transposed_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transposed_shape ( const ITensorInfo input)
inline

Calculate the transposed shape of a tensor.

Parameters
[in]inputInput tensor info
Returns
the calculated shape

Definition at line 404 of file ShapeCalculator.h.

405 {
406  TensorShape shape_transposed{ input.tensor_shape() };
407 
408  shape_transposed.set(0, input.dimension(1), false);
409  shape_transposed.set(1, input.dimension(0), false);
410 
411  return shape_transposed;
412 }

References arm_compute::test::validation::input.

Referenced by CpuTransposeKernel::configure(), ClTransposeKernel::configure(), NELSTMLayer::configure(), CLLSTMLayer::configure(), CpuTransposeKernel::validate(), ClTransposeKernel::validate(), CpuMatMul::validate(), CpuFullyConnected::validate(), ClFullyConnected::validate(), NELSTMLayer::validate(), and CLLSTMLayer::validate().

◆ compute_unpool_shape()

TensorShape arm_compute::misc::shape_calculator::compute_unpool_shape ( const ITensorInfo input,
PoolingLayerInfo  pool_info 
)
inline

Calculate the output unpool shape of a tensor.

Parameters
[in]inputInput tensor info
[in]pool_infoPooling layer info
Returns
the calculated shape

Definition at line 837 of file ShapeCalculator.h.

838 {
839  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
840  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
841  const TensorShape input_shape = input.tensor_shape();
843  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
844  const unsigned int stride_x = pad_stride_info.stride().first;
845  const unsigned int stride_y = pad_stride_info.stride().second;
846 
847  const int pad_left = pad_stride_info.pad_left();
848  const int pad_top = pad_stride_info.pad_top();
849  const int pad_right = pad_stride_info.pad_right();
850  const int pad_bottom = pad_stride_info.pad_bottom();
851 
852  TensorShape output_shape = input_shape;
853  const unsigned int out_width = (input_shape[idx_width] - 1) * stride_x - pad_left - pad_right + pool_info.pool_size.width;
854  const unsigned int out_height = (input_shape[idx_height] - 1) * stride_y - pad_top - pad_bottom + pool_info.pool_size.height;
855 
856  output_shape.set(idx_width, out_width);
857  output_shape.set(idx_height, out_height);
858  return output_shape;
859 }

References ARM_COMPUTE_ERROR_ON, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, PadStrideInfo::pad_bottom(), PadStrideInfo::pad_left(), PadStrideInfo::pad_right(), PoolingLayerInfo::pad_stride_info, PadStrideInfo::pad_top(), PoolingLayerInfo::pool_size, PadStrideInfo::stride(), Size2D::width, and arm_compute::WIDTH.

Referenced by CpuMaxUnpoolingLayerKernel::configure(), and CLMaxUnpoolingLayerKernel::configure().

◆ compute_upsample_shape()

TensorShape arm_compute::misc::shape_calculator::compute_upsample_shape ( const ITensorInfo input,
const Size2D info 
)
inline

Calculate the upsampled shape of a tensor.

Parameters
[in]inputInput tensor info
[in]infoContains stride information (x and y)
Returns
the calculated shape

Definition at line 1336 of file ShapeCalculator.h.

1337 {
1338  const DataLayout data_layout = input.data_layout();
1339  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1340  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1341 
1342  TensorShape scale_out_shape(input.tensor_shape());
1343  const unsigned int out_x = input.dimension(idx_width) * info.x();
1344  const unsigned int out_y = input.dimension(idx_height) * info.y();
1345  scale_out_shape.set(idx_width, out_x);
1346  scale_out_shape.set(idx_height, out_y);
1347 
1348  return scale_out_shape;
1349 }

References arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::info, arm_compute::test::validation::input, TensorShape::set(), and arm_compute::WIDTH.

◆ compute_vector_to_tensor_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_vector_to_tensor_output_shape ( const TensorShape input,
size_t  conv_w,
size_t  conv_h,
const DataLayout data_layout 
)
inline

Calculate the output tensor shape of a vector input given the convolution dimensions.

Parameters
[in]inputInput tensor shape
[in]conv_wConvolution width
[in]conv_hConvolution height
[in]data_layoutData layout
Returns
the calculated shape

Definition at line 89 of file ShapeCalculator.h.

90 {
91  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
92  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
93  const size_t idx_c = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
94 
95  TensorShape output_shape(input);
96  output_shape.set(idx_w, conv_w);
97  output_shape.set(idx_h, conv_h);
98  output_shape.set(idx_c, input.x() / (conv_w * conv_h));
99 
100  return output_shape;
101 }

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::WIDTH.

◆ compute_weights_reshaped_shape()

TensorShape arm_compute::misc::shape_calculator::compute_weights_reshaped_shape ( const ITensorInfo weights,
bool  has_bias = false,
unsigned int  num_groups = 1 
)
inline

Calculate the reshaped shape of the weights.

Parameters
[in]weightsWeights tensor info
[in]has_bias(Optional) Set to true if there is bias
[in]num_groups(Optional) Number of groups
Returns
the calculated shape of the reshaped weights

Definition at line 151 of file ShapeCalculator.h.

152 {
153  // Number of groups greater than one are only supported for NCHW data layout, and the number of weights must be a multiple of it.
155  ARM_COMPUTE_ERROR_ON(weights.data_layout() == DataLayout::NHWC && num_groups > 1);
156  ARM_COMPUTE_ERROR_ON((weights.dimension(3) % num_groups) != 0);
157 
158  // Calculate output shape
159  TensorShape weights_reshaped{ weights.tensor_shape() };
160  weights_reshaped.set(3, weights_reshaped[3] / num_groups);
161 
162  weights_reshaped.collapse(3);
163  const size_t tmp_dim = weights_reshaped[0];
164  weights_reshaped.set(0, weights_reshaped[1]);
165  weights_reshaped.set(1, tmp_dim + (has_bias ? 1 : 0));
166  if(weights.num_dimensions() < 5)
167  {
168  weights_reshaped.set(2, num_groups);
169  }
170 
171  return weights_reshaped;
172 }

References ARM_COMPUTE_ERROR_ON, TensorShape::collapse(), ITensorInfo::data_layout(), ITensorInfo::dimension(), arm_compute::test::validation::has_bias, arm_compute::NHWC, ITensorInfo::num_dimensions(), arm_compute::test::validation::num_groups, TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by ClWeightsReshapeKernel::configure(), ClGemmConv2d::validate(), and CpuGemmConv2d::validate().

◆ compute_winograd_filter_transform_shape()

TensorShape arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape ( const ITensorInfo input,
const WinogradInfo winograd_info 
)
inline

Calculate the winograd filter transform shape.

Parameters
[in]inputInput tensor info
[in]winograd_infoWinograd information
Returns
the calculated shape

Definition at line 620 of file ShapeCalculator.h.

621 {
622  TensorShape tensor_shape{ input.tensor_shape() };
623 
624  const Size2D kernel_size = winograd_info.kernel_size;
625  const Size2D output_tile_size = winograd_info.output_tile_size;
626  const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
627 
628  tensor_shape.remove_dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH));
629  tensor_shape.set(Window::DimX, input.dimension(3));
630  tensor_shape.set(Window::DimY, input.dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL)));
631  tensor_shape.set(Window::DimZ, input_tile_size.area());
632 
633  return tensor_shape;
634 }

References Size2D::area(), arm_compute::CHANNEL, Window::DimX, Window::DimY, Window::DimZ, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::test::validation::input, WinogradInfo::kernel_size, WinogradInfo::output_tile_size, Size2D::width, and arm_compute::WIDTH.

Referenced by ClWinogradFilterTransformKernel::configure().

◆ compute_winograd_input_transform_shape()

TensorShape arm_compute::misc::shape_calculator::compute_winograd_input_transform_shape ( const ITensorInfo input,
const WinogradInfo winograd_info 
)
inline

Calculate the winograd input transform shape.

Parameters
[in]inputInput tensor info
[in]winograd_infoWinograd information
Returns
the calculated shape

Definition at line 643 of file ShapeCalculator.h.

644 {
645  const PadStrideInfo conv_info = winograd_info.convolution_info;
646  const Size2D kernel_size = winograd_info.kernel_size;
647  const Size2D output_tile_size = winograd_info.output_tile_size;
648  const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
649 
650  const size_t idx_w = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
651  const size_t idx_h = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
652  const size_t idx_c = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
653 
654  // Compute the number of output tiles along the x and y direction of size "output_tile_size"
655  const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(input.tensor_shape()[idx_w], input.tensor_shape()[idx_h]),
656  kernel_size,
657  output_tile_size,
658  conv_info);
659 
660  const unsigned int width = input.tensor_shape()[idx_c];
661  const unsigned int height = num_tiles.area();
662  const unsigned int depth = input_tile_size.area();
663 
664  TensorShape output_shape{ input.tensor_shape() };
665  output_shape.set(0, width);
666  output_shape.set(1, height);
667  output_shape.set(2, depth);
668 
669  return output_shape;
670 }

References Size2D::area(), arm_compute::CHANNEL, arm_compute::compute_winograd_convolution_tiles(), arm_compute::test::validation::conv_info, WinogradInfo::convolution_info, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, WinogradInfo::kernel_size, arm_compute::test::validation::output_shape, WinogradInfo::output_tile_size, Size2D::width, and arm_compute::WIDTH.

Referenced by ClWinogradInputTransformKernel::configure().

◆ compute_winograd_output_transform_shape()

TensorShape arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape ( const ITensorInfo input,
const WinogradInfo winograd_info 
)
inline

Calculate the winograd output transform shape.

Parameters
[in]inputInput tensor info
[in]winograd_infoWinograd information
Returns
the calculated shape

Definition at line 679 of file ShapeCalculator.h.

680 {
681  const PadStrideInfo conv_info = winograd_info.convolution_info;
682  const Size2D kernel_size = winograd_info.kernel_size;
683  const Size2D input_dimensions = winograd_info.input_dimensions;
684  const DataLayout data_layout = winograd_info.output_data_layout;
685 
686  // Compute output shape
687  unsigned int output_width = 0;
688  unsigned int output_height = 0;
689  std::tie(output_width, output_height) = scaled_dimensions(input_dimensions.width, input_dimensions.height,
690  kernel_size.width, kernel_size.height, conv_info);
691 
692  TensorShape tensor_shape{ input.tensor_shape() };
693 
694  // Output dimension
695  const unsigned int out_w = output_width;
696  const unsigned int out_h = output_height;
697  const unsigned int out_c = input.dimension(0);
698 
699  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH), out_w);
700  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT), out_h);
701  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL), out_c);
702 
703  return tensor_shape;
704 }

References arm_compute::CHANNEL, arm_compute::test::validation::conv_info, WinogradInfo::convolution_info, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, WinogradInfo::input_dimensions, WinogradInfo::kernel_size, WinogradInfo::output_data_layout, arm_compute::scaled_dimensions(), Size2D::width, and arm_compute::WIDTH.

Referenced by ClWinogradOutputTransformKernel::configure().

◆ extract_shape() [1/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( const ITensorInfo data)
inline

Definition at line 1367 of file ShapeCalculator.h.

1368 {
1369  return data->tensor_shape();
1370 }

References ITensorInfo::tensor_shape().

◆ extract_shape() [2/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( const TensorShape data)
inline

Definition at line 1372 of file ShapeCalculator.h.

1373 {
1374  return *data;
1375 }

◆ extract_shape() [3/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( ITensorInfo data)
inline

Definition at line 1363 of file ShapeCalculator.h.

1364 {
1365  return data->tensor_shape();
1366 }

References ITensorInfo::tensor_shape().

◆ extract_shape() [4/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( T *  data)
inline

Get the tensor shape.

Parameters
[in]dataInput data
Returns
the extracted tensor shape

Definition at line 1358 of file ShapeCalculator.h.

1359 {
1360  return data->info()->tensor_shape();
1361 }

Referenced by calculate_concatenate_shape().

◆ extract_shape() [5/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( TensorShape data)
inline

Definition at line 1377 of file ShapeCalculator.h.

1378 {
1379  return *data;
1380 }
weights_CHout_dim
constexpr unsigned int weights_CHout_dim
Definition: Conv3D.cpp:43
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::BiStrides
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:82
arm_compute::test::validation::idx_height
const int idx_height
Definition: Scale.cpp:263
input_width
const size_t input_width
Definition: impl.cpp:63
arm_compute::DataLayout
DataLayout
[DataLayout enum definition]
Definition: CoreTypes.h:109
arm_compute::test::validation::output_shape
const auto output_shape
Definition: ConvolutionLayer.cpp:411
arm_compute::helpers::tensor_transform
Definition: tensor_transform.h:33
arm_compute::compute_winograd_convolution_tiles
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.
Definition: Helpers.h:248
weights_depth_dim
constexpr unsigned int weights_depth_dim
Definition: Conv3D.cpp:39
ARM_COMPUTE_ERROR
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:353
arm_compute::scaled_dimensions
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.
Definition: Utils.cpp:288
arm_compute::helpers::tensor_transform::construct_slice_end_mask
int32_t construct_slice_end_mask(Coordinates ends)
Constructs end mask in case we want to perform a slice operation using the strided slice interface.
Definition: tensor_transform.cpp:172
arm_compute::test::validation::lhs_info
lhs_info
Definition: GEMMMatrixMultiplyReshaped.cpp:862
arm_compute::permute
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
Definition: Helpers.h:146
arm_compute::test::validation::idx_width
const int idx_width
Definition: Scale.cpp:262
arm_compute::DIV_CEIL
constexpr auto DIV_CEIL(S val, T m) -> decltype((val+m - 1)/m)
Calculate the rounded up quotient of val / m.
Definition: Math.h:37
weights_width_dim
constexpr unsigned int weights_width_dim
Definition: Conv3D.cpp:41
arm_compute::scaled_dimensions_signed
std::pair< int, int > scaled_dimensions_signed(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info)
Returns calculated width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:322
arm_compute::test::validation::data_layout
const auto data_layout
Definition: ConvolutionLayer.cpp:406
height_dim
constexpr unsigned int height_dim
Definition: Conv3D.cpp:34
arm_compute::test::validation::m
const unsigned int m
Definition: GEMMMatrixMultiplyNative.cpp:359
arm_compute::test::validation::rhs_info
rhs_info
Definition: GEMMMatrixMultiplyReshaped.cpp:862
arm_compute::test::validation::has_bias
const bool has_bias
Definition: Im2Col.cpp:152
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
depth_dim
constexpr unsigned int depth_dim
Definition: Conv3D.cpp:33
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::MAX_DIMS
constexpr size_t MAX_DIMS
Constant value used to indicate maximum dimensions of a Window, TensorShape and Coordinates.
Definition: Dimensions.h:38
weights_width
const size_t weights_width
Definition: impl.cpp:54
arm_compute::test::validation::gemm_info
gemm_info
Definition: GEMMMatrixMultiplyReshaped.cpp:862
ARM_COMPUTE_ERROR_ON_MSG
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:457
width_dim
constexpr unsigned int width_dim
Definition: Conv3D.cpp:35
arm_compute::misc::shape_calculator::compute_deep_convolution_shape
TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, const PadStrideInfo &conv_info)
Calculate the deep convolution shape output shape of a tensor.
Definition: ShapeCalculator.h:746
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:66
channel_dim
constexpr unsigned int channel_dim
Definition: Conv3D.cpp:36
weights_height_dim
constexpr unsigned int weights_height_dim
Definition: Conv3D.cpp:40
arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape
TensorShape compute_strided_slice_output_shape(TensorShape input_shape, Coordinates starts, Coordinates ends, Coordinates strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0, bool return_unshrinked=false)
Computes output shape of strided slice.
Definition: tensor_transform.cpp:139
arm_compute::test::validation::input_shape
const auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
Definition: ConvolutionLayer.cpp:408
arm_compute::get_data_layout_dimension_index
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:203
arm_compute::test::validation::num_groups
const unsigned int num_groups
Definition: Im2Col.cpp:153
M
unsigned int M
Definition: CpuGemmAssemblyDispatch.cpp:95
arm_compute::test::validation::b
SimpleTensor< float > b
Definition: DFT.cpp:157
arm_compute::scaled_3d_dimensions_signed
std::tuple< int, int, int > scaled_3d_dimensions_signed(int width, int height, int depth, int kernel_width, int kernel_height, int kernel_depth, const Pooling3dLayerInfo &pool3d_info)
Returns calculated width, height and depth of output scaled tensor depending on dimensions rounding m...
Definition: Utils.cpp:351
arm_compute::test::validation::conv_info
const auto conv_info
Definition: ConvolutionLayer.cpp:407
weights_height
const size_t weights_height
Definition: impl.cpp:55
arm_compute::test::validation::weights_shape
const auto weights_shape
Definition: ConvolutionLayer.cpp:409
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::convert_negative_axis
Coordinates & convert_negative_axis(Coordinates &coords, int max_value)
Convert negative coordinates to positive in the range [0, num_dims_input].
Definition: Helpers.h:278
batch_dim
constexpr unsigned int batch_dim
Definition: Conv3D.cpp:32
arm_compute::misc::shape_calculator::extract_shape
TensorShape extract_shape(TensorShape *data)
Definition: ShapeCalculator.h:1377
input_height
const size_t input_height
Definition: impl.cpp:62
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486