Compute Library
 21.08
CLFlattenLayer Class Reference

Basic function to execute flatten. More...

#include <CLFlattenLayer.h>

Collaboration diagram for CLFlattenLayer:
[legend]

Public Member Functions

 CLFlattenLayer ()
 
 ~CLFlattenLayer ()
 Destructor. More...
 
 CLFlattenLayer (const CLFlattenLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLFlattenLayer (CLFlattenLayer &&)
 Default move constructor. More...
 
CLFlattenLayeroperator= (const CLFlattenLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLFlattenLayeroperator= (CLFlattenLayer &&)
 Default move assignment operator. More...
 
void configure (const ICLTensor *input, ICLTensor *output)
 Initialise the kernel's input and output. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output)
 Initialise the kernel's input 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 ITensorInfo *input, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of CLFlattenLayer. More...
 

Detailed Description

Basic function to execute flatten.

Definition at line 38 of file CLFlattenLayer.h.

Constructor & Destructor Documentation

◆ CLFlattenLayer() [1/3]

Definition at line 44 of file CLFlattenLayer.cpp.

References CLFlattenLayer::operator=(), and CLFlattenLayer::~CLFlattenLayer().

45  : _impl(std::make_unique<Impl>())
46 {
47 }

◆ ~CLFlattenLayer()

~CLFlattenLayer ( )
default

Destructor.

Referenced by CLFlattenLayer::CLFlattenLayer().

◆ CLFlattenLayer() [2/3]

CLFlattenLayer ( const CLFlattenLayer )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLFlattenLayer() [3/3]

CLFlattenLayer ( CLFlattenLayer &&  )
default

Default move constructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor input,
ICLTensor output 
)

Initialise the kernel's input and output.

Valid data layouts:

  • All

Valid data type configurations:

src dst
All All
Parameters
[in]inputFirst input tensor to flatten with at least 3 dimensions. The dimensions above the third will be interpreted as batches. Data types supported: All.
[out]outputOutput tensor with shape [w*h*d, input_batches] where: w = width input tensor, h = height input tensor and d = depth input tensor. Data type supported: same as input

Definition at line 52 of file CLFlattenLayer.cpp.

References CLKernelLibrary::get().

53 {
54  configure(CLKernelLibrary::get().get_compile_context(), input, output);
55 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input, ICLTensor *output)
Initialise the kernel&#39;s input and output.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor input,
ICLTensor output 
)

Initialise the kernel's input and output.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputFirst input tensor to flatten with at least 3 dimensions. The dimensions above the third will be interpreted as batches. Data types supported: All.
[out]outputOutput tensor with shape [w*h*d, input_batches] where: w = width input tensor, h = height input tensor and d = depth input tensor. Data type supported: same as input

Definition at line 57 of file CLFlattenLayer.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::auto_init_if_empty(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_flatten_shape(), ITensor::info(), and arm_compute::test::validation::input.

58 {
60  _impl->src = input;
61  _impl->dst = output;
62  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(misc::shape_calculator::compute_flatten_shape(input->info())));
63 
64  _impl->op = std::make_unique<opencl::ClFlatten>();
65  _impl->op->configure(compile_context, _impl->src->info(), _impl->dst->info());
66 }
TensorShape compute_flatten_shape(const ITensorInfo *input)
Calculate the flattened output shape of a tensor.
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...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ operator=() [1/2]

CLFlattenLayer& operator= ( const CLFlattenLayer )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by CLFlattenLayer::CLFlattenLayer().

◆ operator=() [2/2]

CLFlattenLayer & operator= ( CLFlattenLayer &&  )
default

Default move assignment operator.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For CPU 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 79 of file CLFlattenLayer.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ITensorPack::add_tensor(), and arm_compute::test::validation::pack.

80 {
81  ITensorPack pack;
82  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
83  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
84  _impl->op->run(pack);
85 }
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output 
)
static

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

Parameters
[in]inputFirst input tensor to flatten with at least 3 dimensions. The dimensions above the third will be interpreted as batches. Data types supported: All.
[out]outputOutput tensor with shape [w*h*d, input_batches] where: w = width input tensor, h = height input tensor and d = depth input tensor. Data type supported: same as input
Returns
a status

Definition at line 68 of file CLFlattenLayer.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES, ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_flatten_shape(), ITensorInfo::total_size(), and ClFlatten::validate().

69 {
70  // Checks performed when output is configured
71  if(output->total_size() != 0)
72  {
73  const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(misc::shape_calculator::compute_flatten_shape(input));
74  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
75  }
76  return opencl::ClFlatten::validate(input, output);
77 }
TensorShape compute_flatten_shape(const ITensorInfo *input)
Calculate the flattened output shape of a tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
Definition: ClFlatten.cpp:40

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