Compute Library
 22.08
NEFlattenLayer Class Reference

Basic function to execute flatten layer kernel. More...

#include <NEFlattenLayer.h>

Collaboration diagram for NEFlattenLayer:
[legend]

Public Member Functions

 NEFlattenLayer ()
 
 ~NEFlattenLayer ()
 Destructor. More...
 
 NEFlattenLayer (const NEFlattenLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEFlattenLayer (NEFlattenLayer &&)
 Default move constructor. More...
 
NEFlattenLayeroperator= (const NEFlattenLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEFlattenLayeroperator= (NEFlattenLayer &&)
 Default move assignment operator. More...
 
void configure (const ITensor *input, ITensor *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 NEFlattenLayer. More...
 

Detailed Description

Basic function to execute flatten layer kernel.

Definition at line 38 of file NEFlattenLayer.h.

Constructor & Destructor Documentation

◆ NEFlattenLayer() [1/3]

Definition at line 41 of file NEFlattenLayer.cpp.

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

42  : _impl(std::make_unique<Impl>())
43 {
44 }

◆ ~NEFlattenLayer()

~NEFlattenLayer ( )
default

Destructor.

Referenced by NEFlattenLayer::NEFlattenLayer().

◆ NEFlattenLayer() [2/3]

NEFlattenLayer ( const NEFlattenLayer )
delete

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

◆ NEFlattenLayer() [3/3]

NEFlattenLayer ( NEFlattenLayer &&  )
default

Default move constructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor 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 over 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 49 of file NEFlattenLayer.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.

50 {
52  _impl->src = input;
53  _impl->dst = output;
54  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(misc::shape_calculator::compute_flatten_shape(input->info())));
55 
56  _impl->op = std::make_unique<cpu::CpuFlatten>();
57  _impl->op->configure(_impl->src->info(), _impl->dst->info());
58 }
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]

NEFlattenLayer& operator= ( const NEFlattenLayer )
delete

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

Referenced by NEFlattenLayer::NEFlattenLayer().

◆ operator=() [2/2]

NEFlattenLayer & operator= ( NEFlattenLayer &&  )
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 70 of file NEFlattenLayer.cpp.

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

71 {
72  ITensorPack pack;
73  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
74  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
75  _impl->op->run(pack);
76 }
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 NEFlattenLayer.

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 60 of file NEFlattenLayer.cpp.

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

Referenced by arm_compute::test::validation::DATA_TEST_CASE().

61 {
62  // Checks performed when output is configured
63  if(output->total_size() != 0)
64  {
65  const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(misc::shape_calculator::compute_flatten_shape(input));
66  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
67  }
68  return cpu::CpuFlatten::validate(input, output);
69 }
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
Definition: CpuFlatten.cpp:42
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

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