Compute Library
 22.05
ClConcatenate Class Reference

Basic function to execute concatenate tensors along a given axis. More...

#include <ClConcatenate.h>

Collaboration diagram for ClConcatenate:
[legend]

Public Member Functions

 ClConcatenate ()=default
 
void configure (const ClCompileContext &compile_context, const std::vector< ITensorInfo *> &src_vector, ITensorInfo *dst, size_t axis)
 Initialise the kernel's inputs vector and dst. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from ICLOperator
 ICLOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 ICLOperator (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLOperator (ICLOperator &&)=default
 Default move constructor. More...
 
ICLOperatoroperator= (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLOperatoroperator= (ICLOperator &&)=default
 Default move assignment operator. More...
 
void prepare (ITensorPack &constants) override
 Prepare the function for executing. More...
 
MemoryRequirements workspace () const override
 Return the memory requirements required by the workspace. More...
 
- Public Member Functions inherited from IOperator
virtual ~IOperator ()=default
 Destructor. More...
 

Static Public Member Functions

static Status validate (const std::vector< const ITensorInfo *> &src_vector, const ITensorInfo *dst, size_t axis)
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Basic function to execute concatenate tensors along a given axis.

This function calls the following kernels:

  1. kernels::ClWidthConcatenateKernel (if underlying concatenation axis is 0).
  2. kernels::ClHeightConcatenateKernel (if underlying concatenation axis is 1).
  3. kernels::ClDepthConcatenateKernel (if underlying concatenation axis is 2).
  4. kernels::ClBatchConcatenateKernel (if underlying concatenation axis is 3).

Definition at line 44 of file ClConcatenate.h.

Constructor & Destructor Documentation

◆ ClConcatenate()

ClConcatenate ( )
default

Member Function Documentation

◆ configure()

void configure ( const ClCompileContext compile_context,
const std::vector< ITensorInfo *> &  src_vector,
ITensorInfo dst,
size_t  axis 
)

Initialise the kernel's inputs vector and dst.

Note
Input and dst tensor dimensions preconditions defer depending on the concatenation axis.
Preconditions can be found respectively at kernels::ClWidthConcatenateKernel, kernels::ClHeightConcatenateKernel and kernels::ClDepthConcatenateKernel.
Parameters
[in]compile_contextThe compile context to be used.
[in,out]src_vectorThe vectors containing all the tensors info to concatenate. Data types supported: All
[out]dstDestination tensor info. Data types supported: same as src_vector.
[in]axisConcatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.

Definition at line 47 of file ClConcatenate.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_LOG_PARAMS, arm_compute::auto_init_if_empty(), arm_compute::misc::shape_calculator::calculate_concatenate_shape(), arm_compute::test::validation::data_type, Window::DimX, Window::DimY, Window::DimZ, arm_compute::test::validation::dst, arm_compute::test::validation::dst_shape, offset(), tf_frozen_model_extractor::t, and ClConcatenate::validate().

48 {
49  ARM_COMPUTE_ERROR_ON(dst == nullptr);
50  ARM_COMPUTE_LOG_PARAMS(src_vector, dst, axis);
51  _axis = axis;
52  _num_inputs = src_vector.size();
53 
55  std::vector<const ITensorInfo *> const_src_vector(src_vector.size());
56  std::transform(src_vector.begin(), src_vector.end(), const_src_vector.begin(), [](ITensorInfo * t)
57  {
59  return t;
60  });
61 
62  // dst auto inizialitation if not yet initialized
63  auto_init_if_empty(*dst, dst_shape, 1, src_vector[0]->data_type());
64  ARM_COMPUTE_ERROR_THROW_ON(ClConcatenate::validate(const_src_vector, dst, axis));
65 
66  unsigned int offset = 0;
67  switch(_axis)
68  {
69  case Window::DimX:
70  {
71  switch(_num_inputs)
72  {
73  case 2:
74  {
75  // Configure WidthConcatenate2Tensors kernel
76  auto kernel = std::make_unique<kernels::ClWidthConcatenate2TensorsKernel>();
77  kernel->configure(compile_context, src_vector.at(0), src_vector.at(1), dst);
78  _concat_kernels.emplace_back(std::move(kernel));
79  break;
80  }
81  case 4:
82  {
83  // Configure WidthConcatenate4Tensors kernel
84  auto kernel = std::make_unique<kernels::ClWidthConcatenate4TensorsKernel>();
85  kernel->configure(compile_context, src_vector.at(0), src_vector.at(1), src_vector.at(2), src_vector.at(3), dst);
86  _concat_kernels.emplace_back(std::move(kernel));
87  break;
88  }
89  default:
90  {
91  // Configure generic case WidthConcatenate kernels
92  for(unsigned int i = 0; i < _num_inputs; ++i)
93  {
94  auto kernel = std::make_unique<kernels::ClWidthConcatenateKernel>();
95  kernel->configure(compile_context, src_vector.at(i), offset, dst);
96  offset += src_vector.at(i)->dimension(_axis);
97  _concat_kernels.emplace_back(std::move(kernel));
98  }
99  break;
100  }
101  }
102  break;
103  }
104  case Window::DimY:
105  {
106  for(unsigned int i = 0; i < _num_inputs; ++i)
107  {
108  auto kernel = std::make_unique<kernels::ClHeightConcatenateKernel>();
109  kernel->configure(compile_context, src_vector.at(i), offset, dst);
110  offset += src_vector.at(i)->dimension(_axis);
111  _concat_kernels.emplace_back(std::move(kernel));
112  }
113  break;
114  }
115  case Window::DimZ:
116  {
117  for(unsigned int i = 0; i < _num_inputs; ++i)
118  {
119  auto kernel = std::make_unique<kernels::ClDepthConcatenateKernel>();
120  kernel->configure(compile_context, src_vector.at(i), offset, dst);
121  offset += src_vector.at(i)->dimension(_axis);
122  _concat_kernels.emplace_back(std::move(kernel));
123  }
124  break;
125  }
126  case 3:
127  {
128  for(unsigned int i = 0; i < _num_inputs; ++i)
129  {
130  auto kernel = std::make_unique<kernels::ClBatchConcatenateKernel>();
131  kernel->configure(compile_context, src_vector.at(i), offset, dst);
132  offset += src_vector.at(i)->dimension(_axis);
133  _concat_kernels.emplace_back(std::move(kernel));
134  }
135  break;
136  }
137  default:
138  ARM_COMPUTE_ERROR("Axis not supported");
139  }
140 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1083
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
static Status validate(const std::vector< const ITensorInfo *> &src_vector, const ITensorInfo *dst, size_t axis)
Static function to check if given info will lead to a valid configuration.
#define ARM_COMPUTE_LOG_PARAMS(...)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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...

◆ run()

void run ( ITensorPack tensors)
overridevirtual

Run the kernels contained in the function.

Parameters
[in]tensorsVector that contains the tensors to operate on.

Reimplemented from ICLOperator.

Definition at line 219 of file ClConcatenate.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, arm_compute::ACL_SRC_VEC, ITensorPack::add_tensor(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, Window::DimX, ITensorPack::empty(), CLScheduler::enqueue_op(), CLScheduler::get(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::k, arm_compute::test::validation::pack, and ITensorPack::size().

220 {
221  if(tensors.empty())
222  {
223  ARM_COMPUTE_ERROR("No inputs provided");
224  }
225 
226  if(static_cast<int>(tensors.size()) - 1 != static_cast<int>(_num_inputs))
227  {
228  ARM_COMPUTE_ERROR("Configured with different number of inputs");
229  }
230 
231  if(_axis == Window::DimX && (_num_inputs == 2 || _num_inputs == 4))
232  {
233  ARM_COMPUTE_ERROR_ON(_concat_kernels.empty());
234  CLScheduler::get().enqueue_op(*_concat_kernels.at(0), tensors, true);
235  }
236  else
237  {
238  int i = 0;
239  for(auto &k : _concat_kernels)
240  {
241  ITensorPack pack;
242  pack.add_tensor(TensorType::ACL_SRC, tensors.get_const_tensor(ACL_SRC_VEC + i));
243  pack.add_tensor(TensorType::ACL_DST, tensors.get_tensor(ACL_DST));
244  CLScheduler::get().enqueue_op(*k, pack, true);
245  ++i;
246  }
247  }
248 }
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39

◆ validate()

Status validate ( const std::vector< const ITensorInfo *> &  src_vector,
const ITensorInfo dst,
size_t  axis 
)
static

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

Similar to ClConcatenate::configure()

Returns
a status

Definition at line 142 of file ClConcatenate.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::misc::shape_calculator::calculate_concatenate_shape(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::test::validation::dst_shape, offset(), arm_compute::test::validation::src, ITensorInfo::tensor_shape(), TensorShape::total_size(), ITensorInfo::total_size(), ClWidthConcatenate2TensorsKernel::validate(), ClWidthConcatenateKernel::validate(), ClHeightConcatenateKernel::validate(), ClWidthConcatenate4TensorsKernel::validate(), ClDepthConcatenateKernel::validate(), and ClBatchConcatenateKernel::validate().

Referenced by ClConcatenate::configure(), and CLConcatenateLayer::validate().

143 {
144  ARM_COMPUTE_RETURN_ERROR_ON(dst == nullptr);
145  const unsigned int num_inputs = src_vector.size();
146 
148  ARM_COMPUTE_RETURN_ERROR_ON(num_inputs < 2);
149 
150  unsigned int offset = 0;
151  switch(axis)
152  {
153  case Window::DimX:
154  {
155  switch(num_inputs)
156  {
157  case 2:
158  // Validate WidthConcatenate2Tensors kernels if there are 2 inputs
159  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src_vector[0], src_vector[1]);
161  break;
162  case 4:
163  // Validate WidthConcatenate4Tensors kernels if there are 4 inputs
164  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src_vector[0], src_vector[1], src_vector[2], src_vector[3]);
165  ARM_COMPUTE_RETURN_ON_ERROR(kernels::ClWidthConcatenate4TensorsKernel::validate(src_vector[0], src_vector[1], src_vector[2], src_vector[3], dst));
166  break;
167  default:
168  // Validate generic case of WidthConcatenate kernel
169  for(const auto &src : src_vector)
170  {
173  offset += src->dimension(axis);
174  }
175  break;
176  }
177  break;
178  }
179  case Window::DimY:
180  {
181  for(const auto &src : src_vector)
182  {
184  offset += src->dimension(axis);
185  }
186  break;
187  }
188  case Window::DimZ:
189  {
190  for(const auto &src : src_vector)
191  {
193  offset += src->dimension(axis);
194  }
195  break;
196  }
197  case 3:
198  {
199  for(const auto &src : src_vector)
200  {
202  offset += src->dimension(axis);
203  }
204  break;
205  }
206  default:
207  ARM_COMPUTE_ERROR("Axis not supported");
208  }
209 
210  if(dst->total_size() != 0)
211  {
213  ARM_COMPUTE_RETURN_ERROR_ON(dst_shape.total_size() != dst->tensor_shape().total_size());
214  }
215 
216  return Status{};
217 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1083
static Status validate(const ITensorInfo *src, unsigned int depth_offset, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
static Status validate(const ITensorInfo *src, unsigned int batch_offset, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
static Status validate(const ITensorInfo *src, unsigned int width_offset, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *src3, const ITensorInfo *src4, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
static Status validate(const ITensorInfo *src, unsigned int height_offset, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
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...

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