ArmNN
 25.11
Loading...
Searching...
No Matches
StackLayer Class Reference

This layer represents a stack operation. More...

#include <StackLayer.hpp>

Inheritance diagram for StackLayer:
[legend]
Collaboration diagram for StackLayer:
[legend]

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the Stack type.
StackLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer.
void ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of StackLayer.
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 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.
void ExecuteStrategy (IStrategy &strategy) const override
 Apply a visitor to this layer.
Public Member Functions inherited from LayerWithParameters< StackDescriptor >
const StackDescriptorGetParameters () const override
 If the layer has a descriptor return it.
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
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)
ShapeInferenceMethod GetShapeInferenceMethod () const
bool GetAllowExpandedDims () const
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 override
 Returns the armnn::LayerType of this layer.
DataType GetDataType () const
const BackendIdGetBackendId () const
void SetBackendId (const BackendId &id) override
 Set the backend of the IConnectableLayer.
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
 Returns the name of the layer.
unsigned int GetNumInputSlots () const override
 Returns the number of connectable input slots.
unsigned int GetNumOutputSlots () const override
 Returns the number of connectable output slots.
const InputSlotGetInputSlot (unsigned int index) const override
 Get a const input slot handle by slot index.
InputSlotGetInputSlot (unsigned int index) override
 Get the input slot handle by slot index.
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 Get the const output slot handle by slot index.
OutputSlotGetOutputSlot (unsigned int index=0) override
 Get the output slot handle by slot index.
void SetGuid (LayerGuid guid)
LayerGuid GetGuid () const final
 Returns the unique id of the layer.
void AddRelatedLayerName (const std::string layerName)
const std::list< std::string > & GetRelatedLayerNames ()
virtual void Reparent (Graph &dest, std::list< Layer * >::const_iterator iterator)=0
void BackendSelectionHint (Optional< BackendId > backend) final
 Provide a hint for the optimizer as to which backend to prefer for this layer.
Optional< BackendIdGetBackendHint () const
void SetShapeInferenceMethod (ShapeInferenceMethod shapeInferenceMethod)
void SetAllowExpandedDims (bool allowExpandedDims)
template<typename T>
std::shared_ptr< T > GetAdditionalInformation () const
void SetAdditionalInfoForObject (const AdditionalInfoObjectPtr &additionalInfo)

Protected Member Functions

 StackLayer (const StackDescriptor &param, const char *name)
 Constructor to create a StackLayer.
 ~StackLayer ()=default
 Default destructor.
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.
Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors () const
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
void ValidateAndCopyShape (const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void VerifyShapeInferenceType (const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
template<typename QueueDescriptor>
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload.
template<typename LayerType, typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
virtual ConstantTensors GetConstantTensorsByRef () override final
virtual ImmutableConstantTensors GetConstantTensorsByRef () const override
void SetAdditionalInfo (QueueDescriptor &descriptor) const
Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle.

Additional Inherited Members

Public Types inherited from LayerWithParameters< StackDescriptor >
using DescriptorType
Public Types inherited from IConnectableLayer
using ConstantTensors = std::vector<std::reference_wrapper<std::shared_ptr<ConstTensorHandle>>>
using ImmutableConstantTensors = std::vector<std::reference_wrapper<const std::shared_ptr<ConstTensorHandle>>>
Protected Attributes inherited from LayerWithParameters< StackDescriptor >
StackDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.).
Protected Attributes inherited from Layer
AdditionalInfoObjectPtr m_AdditionalInfoObject
std::vector< OutputHandlerm_OutputHandlers
ShapeInferenceMethod m_ShapeInferenceMethod

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}

References LayerWithParameters< StackDescriptor >::LayerWithParameters(), and armnn::Stack().

Referenced by Clone().

◆ ~StackLayer()

~StackLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ 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 30 of file StackLayer.cpp.

31{
32 return CloneBase<StackLayer>(graph, m_Param, GetName());
33}

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

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

23{
24 StackQueueDescriptor descriptor;
25 SetAdditionalInfo(descriptor);
26
27 return factory.CreateWorkload(LayerType::Stack, descriptor, PrepInfoAndDesc(descriptor));
28}

References IWorkloadFactory::CreateWorkload(), LayerWithParameters< StackDescriptor >::PrepInfoAndDesc(), Layer::SetAdditionalInfo(), and armnn::Stack.

◆ ExecuteStrategy()

void ExecuteStrategy ( IStrategy & strategy) const
overridevirtual

Apply a visitor to this layer.

Reimplemented from LayerWithParameters< StackDescriptor >.

Definition at line 107 of file StackLayer.cpp.

108{
109 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
110}

References IStrategy::ExecuteStrategy(), Layer::GetName(), and LayerWithParameters< StackDescriptor >::GetParameters().

◆ 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 35 of file StackLayer.cpp.

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 if (axis > inputNumDimensions)
42 {
43 throw armnn::Exception("axis must not be greater than input dimensions (\""
44 + std::to_string(axis) +
45 "\" vs \""
46 + std::to_string(inputNumDimensions) + "\").");
47 }
48
49 std::vector<unsigned int> dimensionSizes(inputNumDimensions + 1, 0);
50 for (unsigned int i = 0; i < axis; ++i)
51 {
52 dimensionSizes[i] = inputShape[i];
53 }
54
55 dimensionSizes[axis] = m_Param.m_NumInputs;
56
57 for (unsigned int i = axis + 1; i < inputNumDimensions + 1; ++i)
58 {
59 dimensionSizes[i] = inputShape[i-1];
60 }
61
62 TensorShape targetShape = TensorShape(inputNumDimensions + 1, dimensionSizes.data());
63
64 return std::vector<TensorShape>({ targetShape });
65}

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

Referenced by ValidateTensorShapesFromInputs().

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

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

Parameters
[in]shapeInferenceMethodIndicates if output shape shall be overwritten or just validated.

Implements Layer.

Definition at line 67 of file StackLayer.cpp.

68{
69 // Validates Stack layer.
70 ConditionalThrowIfNotEqual<LayerValidationException>(
71 "StackLayer: Num Input Slots must match Num Inputs.",
72 m_Param.m_NumInputs,
73 GetNumInputSlots());
74
75 VerifyLayerConnections(m_Param.m_NumInputs, CHECK_LOCATION());
76
77 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
78
79 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
80
81 // Constructs and validates input shapes
82 std::vector<TensorShape> inputShapes;
83 for (unsigned int i = 0; i < GetNumInputSlots(); ++i)
84 {
85 TensorShape inputShape = GetInputSlot(i).GetTensorInfo().GetShape();
86 if (inputShape != m_Param.m_InputShape)
87 {
88 throw LayerValidationException("StackLayer: TensorShape set on InputSlot[" +
89 std::to_string(i) +
90 "] does not match defined input shape");
91 }
92 inputShapes.push_back(inputShape);
93 }
94
95 auto inferredShapes = InferOutputShapes(inputShapes);
96
97 if (inferredShapes.size() != 1)
98 {
99 throw armnn::LayerValidationException("inferredShapes has "
100 + std::to_string(inferredShapes.size()) +
101 " elements - should only have 1.");
102 }
103
104 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "StackLayer");
105}
#define CHECK_LOCATION()

References CHECK_LOCATION, armnn::ConditionalThrowIfNotEqual(), Layer::GetInputSlot(), Layer::GetNumInputSlots(), Layer::GetOutputSlot(), TensorInfo::GetShape(), InputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), InferOutputShapes(), LayerWithParameters< StackDescriptor >::m_Param, Layer::m_ShapeInferenceMethod, Layer::ValidateAndCopyShape(), Layer::VerifyLayerConnections(), and Layer::VerifyShapeInferenceType().


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