Compute Library
 23.11
CpuConcatenate Class Reference

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

#include <CpuConcatenate.h>

Collaboration diagram for CpuConcatenate:
[legend]

Public Member Functions

 CpuConcatenate ()=default
 
void configure (const std::vector< const ITensorInfo * > &srcs_vector, ITensorInfo *dst, size_t axis)
 Configure operator for a given list of arguments. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from INEOperator
 INEOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 INEOperator (const INEOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 INEOperator (INEOperator &&)=default
 Default move constructor. More...
 
INEOperatoroperator= (const INEOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
INEOperatoroperator= (INEOperator &&)=default
 Default move assignment operator. More...
 
 ~INEOperator ()
 Default destructor. 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 * > &srcs_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::CpuConcatenateWidthKernel (if underlying concatenation axis is 0).
  2. kernels::CpuConcatenateHeightKernel (if underlying concatenation axis is 1).
  3. kernels::CpuConcatenateDepthKernel (if underlying concatenation axis is 2).
  4. kernels::CpuConcatenateBatchKernel (if underlying concatenation axis is 3).

Definition at line 43 of file CpuConcatenate.h.

Constructor & Destructor Documentation

◆ CpuConcatenate()

CpuConcatenate ( )
default

Member Function Documentation

◆ configure()

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

Configure operator for a given list of arguments.

Note
Input and output tensor dimensions preconditions defer depending on the concatenation axis.
Preconditions can be found respectively at kernels::CpuConcatenateWidthKernel, kernels::CpuConcatenateHeightKernel, kernels::CpuConcatenateDepthKernel and kernels::CpuConcatenateBatchKernel.
Parameters
[in,out]srcs_vectorThe vectors containing all the tensors to concatenate. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[out]dstOutput tensor. Data types supported: Same as srcs_vector.
[in]axisConcatenation axis. Supported underlying concatenation axis are 0, 1, 2 and 3.

Definition at line 45 of file CpuConcatenate.cpp.

46 {
47  ARM_COMPUTE_ERROR_ON(dst == nullptr);
48  ARM_COMPUTE_LOG_PARAMS(srcs_vector, dst, axis);
49 
50  _axis = axis;
51  _num_srcs = srcs_vector.size();
52 
54 
55  // Output auto inizialitation if not yet initialized
56  auto_init_if_empty(*dst, dst_shape, 1, srcs_vector[0]->data_type());
58 
59  unsigned int offset = 0;
60 
61  for (unsigned int i = 0; i < _num_srcs; ++i)
62  {
63  switch (axis)
64  {
65  case Window::DimX:
66  {
67  auto kernel = std::make_unique<kernels::CpuConcatenateWidthKernel>();
68  kernel->configure(srcs_vector.at(i), offset, dst);
69  _concat_kernels.emplace_back(std::move(kernel));
70  break;
71  }
72  case Window::DimY:
73  {
74  auto kernel = std::make_unique<kernels::CpuConcatenateHeightKernel>();
75  kernel->configure(srcs_vector.at(i), offset, dst);
76  _concat_kernels.emplace_back(std::move(kernel));
77  break;
78  }
79  case Window::DimZ:
80  {
81  auto kernel = std::make_unique<kernels::CpuConcatenateDepthKernel>();
82  kernel->configure(srcs_vector.at(i), offset, dst);
83  _concat_kernels.emplace_back(std::move(kernel));
84  break;
85  }
86  case 3:
87  {
88  auto kernel = std::make_unique<kernels::CpuConcatenateBatchKernel>();
89  kernel->configure(srcs_vector.at(i), offset, dst);
90  _concat_kernels.emplace_back(std::move(kernel));
91  break;
92  }
93  default:
94  ARM_COMPUTE_ERROR("Axis not supported");
95  }
96  offset += srcs_vector.at(i)->dimension(axis);
97  }
98 }

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, 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(), and CpuConcatenate::validate().

◆ 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 INEOperator.

Definition at line 147 of file CpuConcatenate.cpp.

148 {
149  if (tensors.empty())
150  {
151  ARM_COMPUTE_ERROR("No inputs provided");
152  }
153 
154  if (static_cast<int>(tensors.size() - 1) != static_cast<int>(_num_srcs))
155  {
156  ARM_COMPUTE_ERROR("Configured with different number of inputs");
157  }
158 
159  int i = 0;
160  for (auto &k : _concat_kernels)
161  {
162  ITensorPack pack;
163  pack.add_tensor(TensorType::ACL_SRC, tensors.get_const_tensor(ACL_SRC_VEC + i));
164  pack.add_tensor(TensorType::ACL_DST, tensors.get_tensor(ACL_DST));
165  NEScheduler::get().schedule_op(k.get(), Window::DimY, k->window(), pack);
166  ++i;
167  }
168 }

References arm_compute::ACL_DST, arm_compute::ACL_SRC, arm_compute::ACL_SRC_VEC, ITensorPack::add_tensor(), ARM_COMPUTE_ERROR, Window::DimY, ITensorPack::empty(), Scheduler::get(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::pack, IScheduler::schedule_op(), and ITensorPack::size().

◆ validate()

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

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

Similar to CpuConcatenate::configure()

Returns
a status

Definition at line 101 of file CpuConcatenate.cpp.

102 {
104  ARM_COMPUTE_RETURN_ERROR_ON(srcs_vector.size() < 2);
105 
106  unsigned int offset = 0;
107  for (const auto &src : srcs_vector)
108  {
110  switch (axis)
111  {
112  case Window::DimX:
113  {
115  break;
116  }
117  case Window::DimY:
118  {
120  break;
121  }
122  case Window::DimZ:
123  {
125  break;
126  }
127  case 3:
128  {
130  break;
131  }
132  default:
133  ARM_COMPUTE_ERROR("Axis not supported");
134  }
135  offset += src->dimension(axis);
136  }
137 
138  if (dst->total_size() != 0)
139  {
141  ARM_COMPUTE_RETURN_ERROR_ON(dst_shape.total_size() != dst->tensor_shape().total_size());
142  }
143 
144  return Status{};
145 }

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, arm_compute::test::validation::dst_shape, offset(), arm_compute::test::validation::src, TensorShape::total_size(), CpuConcatenateBatchKernel::validate(), CpuConcatenateWidthKernel::validate(), CpuConcatenateHeightKernel::validate(), and CpuConcatenateDepthKernel::validate().

Referenced by CpuConcatenate::configure(), and NEConcatenateLayer::validate().


The documentation for this class was generated from the following files:
arm_compute::test::validation::dst_shape
TensorShape dst_shape
Definition: DFT.cpp:164
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::IScheduler::schedule_op
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
arm_compute::Window::DimX
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
ARM_COMPUTE_ERROR
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:354
arm_compute::misc::shape_calculator::calculate_concatenate_shape
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.
Definition: ShapeCalculator.h:1494
arm_compute::ITensorPack::add_tensor
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:38
arm_compute::cpu::kernels::CpuConcatenateDepthKernel::validate
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.
Definition: CpuConcatenateDepthKernel.cpp:192
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:205
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:466
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
ARM_COMPUTE_RETURN_ERROR_ON
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:298
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::auto_init_if_empty
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...
Definition: AutoConfiguration.h:43
arm_compute::TensorShape::total_size
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:175
arm_compute::Scheduler::get
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1128
arm_compute::test::validation::pack
ITensorPack pack
Definition: Im2Col.cpp:188
arm_compute::ACL_SRC_VEC
@ ACL_SRC_VEC
Definition: Types.h:68
arm_compute::Window::DimY
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
arm_compute::test::validation::data_type
data_type
Definition: Cast.cpp:222
arm_compute::cpu::kernels::CpuConcatenateHeightKernel::validate
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.
Definition: CpuConcatenateHeightKernel.cpp:79
arm_compute::Window::DimZ
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
arm_compute::cpu::CpuConcatenate::validate
static Status validate(const std::vector< const ITensorInfo * > &srcs_vector, const ITensorInfo *dst, size_t axis)
Static function to check if given info will lead to a valid configuration.
Definition: CpuConcatenate.cpp:101
arm_compute::cpu::kernels::CpuConcatenateWidthKernel::validate
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.
Definition: CpuConcatenateWidthKernel.cpp:73
arm_compute::ACL_SRC
@ ACL_SRC
Definition: Types.h:44
arm_compute::cpu::kernels::CpuConcatenateBatchKernel::validate
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.
Definition: CpuConcatenateBatchKernel.cpp:194
ARM_COMPUTE_LOG_PARAMS
#define ARM_COMPUTE_LOG_PARAMS(...)
Definition: Log.h:35