Compute Library
 19.08
CLStackLayer Class Reference

Basic function to stack tensors along an axis. More...

#include <CLStackLayer.h>

Collaboration diagram for CLStackLayer:
[legend]

Public Member Functions

 CLStackLayer ()
 Default constructor. More...
 
void configure (const std::vector< ICLTensor * > &input, int axis, ICLTensor *output)
 Initialise the kernel's inputs vector and output. 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 std::vector< ITensorInfo * > &input, int axis, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of CLStackLayerKernel. More...
 

Detailed Description

Basic function to stack tensors along an axis.

This function calls the following kernel:

  1. CLStackLayerKernel

Definition at line 44 of file CLStackLayer.h.

Constructor & Destructor Documentation

◆ CLStackLayer()

Default constructor.

Definition at line 40 of file CLStackLayer.cpp.

41  : _input(),
42  _stack_kernels(),
43  _num_inputs(0)
44 {
45 }

Member Function Documentation

◆ configure()

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

Initialise the kernel's inputs vector and output.

Note
Supported input tensor rank: up to 4
Parameters
[in]inputThe vectors containing all the tensors with the same shape to stack. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]axisThe dimension to stack the tensors along. It must be smaller than the number of input dimensions. Negative values wrap around
[out]outputOutput tensor. Data types supported: Same as input.

Definition at line 47 of file CLStackLayer.cpp.

48 {
49  _num_inputs = input.size();
50  _stack_kernels.resize(_num_inputs);
51 
52  // Wrap around negative values
53  const unsigned int axis_u = wrap_around(axis, static_cast<int>(input[0]->info()->num_dimensions() + 1));
54 
55  for(unsigned int i = 0; i < _num_inputs; i++)
56  {
57  _stack_kernels[i].configure(input[i], axis_u, i, _num_inputs, output);
58  }
59 }
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:764

References arm_compute::test::validation::axis, arm_compute::test::validation::info, and arm_compute::wrap_around().

◆ 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 83 of file CLStackLayer.cpp.

84 {
85  for(unsigned i = 0; i < _num_inputs; i++)
86  {
87  CLScheduler::get().enqueue(_stack_kernels[i], false);
88  }
89 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:95

References CLScheduler::enqueue(), and CLScheduler::get().

◆ validate()

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

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

Note
Supported input tensor rank: up to 4
Parameters
[in]inputThe vectors containing all the tensors info with the same shape to stack. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]axisThe dimension to stack the tensors along. It must be smaller than the number of input dimensions. Negative values wrap around
[in]outputOutput tensor info. Data types supported: Same as input.
Returns
a status

Definition at line 61 of file CLStackLayer.cpp.

62 {
64  ARM_COMPUTE_RETURN_ERROR_ON(input.empty());
65 
66  // Wrap around negative values
67  const size_t rank = input[0]->num_dimensions();
68  const unsigned int axis_u = wrap_around(axis, static_cast<int>(rank + 1));
69 
70  const unsigned int num_inputs = input.size();
71 
72  for(unsigned int i = 0; i < num_inputs; i++)
73  {
74  // All the tensors must have the same rank
75  ARM_COMPUTE_RETURN_ERROR_ON(input[i]->num_dimensions() != rank);
76  // Validate Kernel
77  ARM_COMPUTE_RETURN_ON_ERROR(CLStackLayerKernel::validate(input[i], axis_u, i, num_inputs, output));
78  }
79 
80  return Status{};
81 }
static Status validate(const ITensorInfo *input, unsigned int axis, unsigned int idx_input, unsigned int num_tensors, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLStackLayerKernel.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Status class.
Definition: Error.h:52
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:244
T wrap_around(T x, T m)
Wrap-around a number within the range 0 <= x < m.
Definition: Helpers.h:764
#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, CLStackLayerKernel::validate(), and arm_compute::wrap_around().


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