Compute Library
 19.08
NEUnstack Class Reference

Basic function to unpack a rank-R tensor into rank-(R-1) tensors. More...

#include <NEUnstack.h>

Collaboration diagram for NEUnstack:
[legend]

Public Member Functions

 NEUnstack ()
 Default constructor. More...
 
void configure (const ITensor *input, const std::vector< ITensor * > &output_vector, int axis)
 Set the input, output and unstacking axis. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const std::vector< ITensorInfo * > &output_vector, int axis)
 Static function to check if given info will lead to a valid configuration of NEUnstack. More...
 

Detailed Description

Basic function to unpack a rank-R tensor into rank-(R-1) tensors.

This function calls the following functions:

  1. NEStridedSlice

Definition at line 43 of file NEUnstack.h.

Constructor & Destructor Documentation

◆ NEUnstack()

NEUnstack ( )

Default constructor.

Definition at line 56 of file NEUnstack.cpp.

57  : _num_slices(0),
58  _strided_slice_vector()
59 {
60 }

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
const std::vector< ITensor * > &  output_vector,
int  axis 
)

Set the input, output and unstacking axis.

Parameters
[in]inputA tensor to be unstacked. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
[in,out]output_vectorA vector of tensors. Data types supported: Same as input. Note: The number of elements of the vector will be used as the number of slices to be taken from the axis.
[in]axisThe axis to unstack along. Valid values are [-R,R) where R is the input's rank. Negative values wrap around.

Definition at line 62 of file NEUnstack.cpp.

63 {
64  std::vector<ITensorInfo *> outputs_vector_info(output_vector.size());
65  std::transform(output_vector.begin(), output_vector.end(), outputs_vector_info.begin(), [](ITensor * t)
66  {
68  return t->info();
69  });
70 
72  ARM_COMPUTE_ERROR_THROW_ON(NEUnstack::validate(input->info(), outputs_vector_info, axis));
73 
74  // Wrap around negative values
75  const unsigned int axis_u = wrap_axis(axis, input->info());
76  _num_slices = std::min(outputs_vector_info.size(), input->info()->dimension(axis_u));
77  _strided_slice_vector.resize(_num_slices);
78 
79  Coordinates slice_start;
80  int32_t slice_end_mask;
81  setup_slice_coordinates_and_mask(slice_start, slice_end_mask, input->info()->tensor_shape().num_dimensions());
82  for(unsigned int slice = 0; slice < _num_slices; ++slice)
83  {
84  // Adjusts start and end coordinates to take a 2D slice at a time
85  slice_start.set(axis_u, slice);
86  _strided_slice_vector[slice].configure(input, output_vector[slice], slice_start, Coordinates(), BiStrides(), 0, slice_end_mask, (1 << axis_u));
87  }
88 }
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:49
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
static Status validate(const ITensorInfo *input, const std::vector< ITensorInfo * > &output_vector, int axis)
Static function to check if given info will lead to a valid configuration of NEUnstack.
Definition: NEUnstack.cpp:90
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::test::validation::axis, ITensorInfo::dimension(), ITensor::info(), Dimensions< T >::num_dimensions(), Dimensions< T >::set(), arm_compute::test::validation::reference::slice(), ITensorInfo::tensor_shape(), and NEUnstack::validate().

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 112 of file NEUnstack.cpp.

113 {
114  for(unsigned i = 0; i < _num_slices; ++i)
115  {
116  _strided_slice_vector[i].run();
117  }
118 }

◆ validate()

Status validate ( const ITensorInfo input,
const std::vector< ITensorInfo * > &  output_vector,
int  axis 
)
static

Static function to check if given info will lead to a valid configuration of NEUnstack.

Parameters
[in]inputInput tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[in]output_vectorVector of output tensors' info. Data types supported: Same as input.
[in]axisThe axis to unstack along. Valid values are [-R,R) where R is the input's rank. Negative values wrap around.
Returns
a status

Definition at line 90 of file NEUnstack.cpp.

91 {
93  ARM_COMPUTE_RETURN_ERROR_ON(output_vector.empty());
94  ARM_COMPUTE_RETURN_ERROR_ON(axis < (-static_cast<int>(input->tensor_shape().num_dimensions())));
95  ARM_COMPUTE_RETURN_ERROR_ON(axis >= static_cast<int>(input->tensor_shape().num_dimensions()));
96 
97  const unsigned int num_slices = std::min(output_vector.size(), input->dimension(wrap_axis(axis, input)));
98  ARM_COMPUTE_RETURN_ERROR_ON(num_slices > input->dimension(wrap_axis(axis, input)));
99  ARM_COMPUTE_RETURN_ERROR_ON(num_slices > output_vector.size());
100 
101  Coordinates slice_start;
102  int32_t slice_end_mask;
103  for(size_t k = 0; k < num_slices; ++k)
104  {
105  slice_start.set(wrap_axis(axis, input), k);
106  setup_slice_coordinates_and_mask(slice_start, slice_end_mask, input->tensor_shape().num_dimensions());
107  ARM_COMPUTE_RETURN_ON_ERROR(NEStridedSlice::validate(input, output_vector[k], slice_start, Coordinates(), BiStrides(), 0, slice_end_mask, (1 << wrap_axis(axis, input))));
108  }
109  return Status{};
110 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:49
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:244
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0)
Static function to check if given info will lead to a valid configuration of NEStridedSlice.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::axis, ITensorInfo::dimension(), Dimensions< T >::num_dimensions(), Dimensions< T >::set(), ITensorInfo::tensor_shape(), and NEStridedSlice::validate().

Referenced by NEUnstack::configure().


The documentation for this class was generated from the following files: