ArmNN  NotReleased
StackLayer Class Reference

This layer represents a stack operation. More...

#include <StackLayer.hpp>

Inheritance diagram for StackLayer:
LayerWithParameters< StackDescriptor > Layer IConnectableLayer

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 
StackLayerClone (Graph &graph) const override
 
void ValidateTensorShapesFromInputs () override
 
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 
void Accept (ILayerVisitor &visitor) const override
 
- Public Member Functions inherited from LayerWithParameters< StackDescriptor >
const StackDescriptorGetParameters () const
 
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 
- Public Member Functions inherited from Layer
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
 
const std::string & GetNameStr () const
 
const OutputHandlerGetOutputHandler (unsigned int i=0) const
 
OutputHandlerGetOutputHandler (unsigned int i=0)
 
const std::vector< InputSlot > & GetInputSlots () const
 
const std::vector< OutputSlot > & GetOutputSlots () const
 
std::vector< InputSlot >::iterator BeginInputSlots ()
 
std::vector< InputSlot >::iterator EndInputSlots ()
 
std::vector< OutputSlot >::iterator BeginOutputSlots ()
 
std::vector< OutputSlot >::iterator EndOutputSlots ()
 
bool IsOutputUnconnected ()
 
void ResetPriority () const
 
LayerPriority GetPriority () const
 
LayerType GetType () const
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id)
 
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
 
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
 
virtual void ReleaseConstantData ()
 
template<typename Op >
void OperateOnConstantTensors (Op op)
 
const char * GetName () const override
 
unsigned int GetNumInputSlots () const override
 
unsigned int GetNumOutputSlots () const override
 
const InputSlotGetInputSlot (unsigned int index) const override
 
InputSlotGetInputSlot (unsigned int index) override
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 
void AddRelatedLayerName (const std::string layerName)
 
const std::list< std::string > & GetRelatedLayerNames ()
 
virtual void Reparent (Graph &dest, std::list< Layer *>::const_iterator iterator)=0
 

Protected Member Functions

 StackLayer (const StackDescriptor &param, const char *name)
 
 ~StackLayer ()=default
 Default destructor. More...
 
- Protected Member Functions inherited from LayerWithParameters< StackDescriptor >
 LayerWithParameters (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const StackDescriptor &param, const char *name)
 
 ~LayerWithParameters ()=default
 
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
- Protected Member Functions inherited from Layer
virtual ~Layer ()=default
 
template<typename QueueDescriptor >
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
virtual ConstantTensors GetConstantTensorsByRef ()
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle. More...
 

Additional Inherited Members

- Public Types inherited from LayerWithParameters< StackDescriptor >
using DescriptorType = StackDescriptor
 
- Protected Types inherited from Layer
using ConstantTensors = std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >>
 
- Protected Attributes inherited from LayerWithParameters< StackDescriptor >
StackDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.). More...
 
- Protected Attributes inherited from Layer
std::vector< OutputHandlerm_OutputHandlers
 

Detailed Description

This layer represents a stack operation.

Definition at line 13 of file StackLayer.hpp.

Constructor & Destructor Documentation

◆ StackLayer()

StackLayer ( const StackDescriptor param,
const char *  name 
)
protected

Constructor to create a StackLayer.

Parameters
[in]paramStackDescriptor to configure the stack operation.
[in]nameOptional name for the layer.

Definition at line 17 of file StackLayer.cpp.

18  : LayerWithParameters(param.m_NumInputs, 1, LayerType::Stack, param, name)
19 {
20 }
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const StackDescriptor &param, const char *name)

◆ ~StackLayer()

~StackLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Accept()

void Accept ( ILayerVisitor visitor) const
overridevirtual

Implements IConnectableLayer.

Definition at line 95 of file StackLayer.cpp.

References Layer::GetName(), LayerWithParameters< StackDescriptor >::GetParameters(), and ILayerVisitor::VisitStackLayer().

96 {
97  visitor.VisitStackLayer(this, GetParameters(), GetName());
98 }
const char * GetName() const override
Definition: Layer.hpp:305

◆ Clone()

StackLayer * Clone ( Graph graph) const
overridevirtual

Creates a dynamically-allocated copy of this layer.

Parameters
[in]graphThe graph into which this layer is being cloned.

Implements Layer.

Definition at line 28 of file StackLayer.cpp.

References Layer::GetName(), and LayerWithParameters< StackDescriptor >::m_Param.

29 {
30  return CloneBase<StackLayer>(graph, m_Param, GetName());
31 }
const char * GetName() const override
Definition: Layer.hpp:305
StackDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).

◆ CreateWorkload()

std::unique_ptr< IWorkload > CreateWorkload ( const IWorkloadFactory factory) const
overridevirtual

Makes a workload for the Stack type.

Parameters
[in]graphThe graph where this layer can be found.
[in]factoryThe workload factory which will create the workload.
Returns
A pointer to the created workload, or nullptr if not created.

Implements Layer.

Definition at line 22 of file StackLayer.cpp.

References IWorkloadFactory::CreateStack(), and LayerWithParameters< StackDescriptor >::PrepInfoAndDesc().

23 {
24  StackQueueDescriptor descriptor;
25  return factory.CreateStack(descriptor, PrepInfoAndDesc(descriptor));
26 }
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > &  inputShapes) const
overridevirtual

By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.

Parameters
[in]inputShapesThe input shapes layer has.
Returns
A vector to the inferred output shape.

Reimplemented from Layer.

Definition at line 33 of file StackLayer.cpp.

References TensorShape::GetNumDimensions(), StackDescriptor::m_Axis, StackDescriptor::m_InputShape, StackDescriptor::m_NumInputs, and LayerWithParameters< StackDescriptor >::m_Param.

Referenced by StackInferOutputShapeImpl(), and StackLayer::ValidateTensorShapesFromInputs().

34 {
35  boost::ignore_unused(inputShapes);
36 
37  const TensorShape& inputShape = m_Param.m_InputShape;
38  const unsigned int inputNumDimensions = inputShape.GetNumDimensions();
39  const unsigned int axis = m_Param.m_Axis;
40 
41  BOOST_ASSERT(axis <= inputNumDimensions);
42 
43  std::vector<unsigned int> dimensionSizes(inputNumDimensions + 1, 0);
44  for (unsigned int i = 0; i < axis; ++i)
45  {
46  dimensionSizes[i] = inputShape[i];
47  }
48 
49  dimensionSizes[axis] = m_Param.m_NumInputs;
50 
51  for (unsigned int i = axis + 1; i < inputNumDimensions + 1; ++i)
52  {
53  dimensionSizes[i] = inputShape[i-1];
54  }
55 
56  TensorShape targetShape = TensorShape(inputNumDimensions + 1, dimensionSizes.data());
57 
58  return std::vector<TensorShape>({ targetShape });
59 }
uint32_t m_Axis
0-based axis along which to stack the input tensors.
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:43
TensorShape m_InputShape
Required shape of all input tensors.
uint32_t m_NumInputs
Number of input tensors.
StackDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

Check if the input tensor shape(s) will lead to a valid configuration of StackLayer.

Implements Layer.

Definition at line 61 of file StackLayer.cpp.

References CHECK_LOCATION, InputSlot::GetConnection(), Layer::GetInputSlot(), Layer::GetNumInputSlots(), Layer::GetOutputSlot(), TensorInfo::GetShape(), IOutputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), StackLayer::InferOutputShapes(), StackDescriptor::m_InputShape, StackDescriptor::m_NumInputs, LayerWithParameters< StackDescriptor >::m_Param, and Layer::VerifyLayerConnections().

62 {
63  // Validates Stack layer.
64  ConditionalThrowIfNotEqual<LayerValidationException>(
65  "StackLayer: Num Input Slots must match Num Inputs.",
68 
70 
71  // Constructs and validates input shapes
72  std::vector<TensorShape> inputShapes;
73  for (unsigned int i = 0; i < GetNumInputSlots(); ++i)
74  {
75  TensorShape inputShape = GetInputSlot(i).GetConnection()->GetTensorInfo().GetShape();
76  if (inputShape != m_Param.m_InputShape)
77  {
78  throw LayerValidationException("StackLayer: TensorShape set on InputSlot[" +
79  std::to_string(i) +
80  "] does not match defined input shape");
81  }
82  inputShapes.push_back(inputShape);
83  }
84 
85  auto inferredShapes = InferOutputShapes(inputShapes);
86 
87  BOOST_ASSERT(inferredShapes.size() == 1);
88 
89  ConditionalThrowIfNotEqual<LayerValidationException>(
90  "StackLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
92  inferredShapes[0]);
93 }
virtual const TensorInfo & GetTensorInfo() const =0
TensorShape m_InputShape
Required shape of all input tensors.
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
uint32_t m_NumInputs
Number of input tensors.
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
StackDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:337
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Definition: StackLayer.cpp:33
unsigned int GetNumInputSlots() const override
Definition: Layer.hpp:307
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Definition: Layer.hpp:312
const InputSlot & GetInputSlot(unsigned int index) const override
Definition: Layer.hpp:310

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