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

#include <PreluLayer.hpp>

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

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the PReLU type.
PreluLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer.
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 ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of PreluLayer.
void ExecuteStrategy (IStrategy &strategy) const override
 Apply a visitor to this layer.
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 SerializeLayerParameters (ParameterStringifyFunction &fn) const
 Helper to serialize the layer parameters to string.
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)
virtual const BaseDescriptorGetParameters () const override
 If the layer has a descriptor return it.

Protected Member Functions

 PreluLayer (const char *name)
 Constructor to create a PreluLayer.
 ~PreluLayer ()=default
 Default destructor.
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 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 Layer
AdditionalInfoObjectPtr m_AdditionalInfoObject
std::vector< OutputHandlerm_OutputHandlers
ShapeInferenceMethod m_ShapeInferenceMethod

Detailed Description

Definition at line 14 of file PreluLayer.hpp.

Constructor & Destructor Documentation

◆ PreluLayer()

PreluLayer ( const char * name)
protected

Constructor to create a PreluLayer.

Parameters
[in]nameOptional name for the layer.

Definition at line 19 of file PreluLayer.cpp.

20 : Layer(2, 1, LayerType::Prelu, name)
21{}

References Layer::Layer(), and armnn::Prelu.

Referenced by Clone().

◆ ~PreluLayer()

~PreluLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Clone()

PreluLayer * 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 31 of file PreluLayer.cpp.

32{
33 auto layer = CloneBase<PreluLayer>(graph, GetName());
34
35 return std::move(layer);
36}

References Layer::CloneBase(), Layer::GetName(), Layer::Graph, and PreluLayer().

◆ CreateWorkload()

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

Makes a workload for the PReLU 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 23 of file PreluLayer.cpp.

24{
25 PreluQueueDescriptor descriptor;
26 SetAdditionalInfo(descriptor);
27
28 return factory.CreateWorkload(LayerType::Prelu, descriptor, PrepInfoAndDesc(descriptor));
29}

References IWorkloadFactory::CreateWorkload(), armnn::Prelu, Layer::PrepInfoAndDesc(), and Layer::SetAdditionalInfo().

◆ ExecuteStrategy()

void ExecuteStrategy ( IStrategy & strategy) const
overridevirtual

Apply a visitor to this layer.

Reimplemented from Layer.

Definition at line 138 of file PreluLayer.cpp.

139{
140 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
141}

References IStrategy::ExecuteStrategy(), Layer::GetName(), and Layer::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 38 of file PreluLayer.cpp.

39{
40 if (inputShapes.size() != 2)
41 {
42 throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) +
43 "\" - should be \"2\".");
44 }
45
46 const TensorShape& inputShape = inputShapes[0];
47 const TensorShape& alphaShape = inputShapes[1];
48
49 const unsigned int inputShapeDimensions = inputShape.GetNumDimensions();
50 const unsigned int alphaShapeDimensions = alphaShape.GetNumDimensions();
51
52 if (inputShapeDimensions == 0)
53 {
54 throw armnn::Exception("inputShapeDimensions must be greater than 0.");
55 }
56
57 if (alphaShapeDimensions == 0)
58 {
59 throw armnn::Exception("alphaShapeDimensions must be not be zero (\""
60 + std::to_string(alphaShapeDimensions) + "\")");
61 }
62
63 // The size of the output is the maximum size along each dimension of the input operands,
64 // it starts with the trailing dimensions, and works its way forward
65
66 unsigned int outputDimensions = std::max(inputShapeDimensions, alphaShapeDimensions);
67
68 TensorShape outputShape(outputDimensions);
69
70 int inputShapeIndex = armnn::numeric_cast<int>(inputShapeDimensions) - 1;
71 int alphaShapeIndex = armnn::numeric_cast<int>(alphaShapeDimensions) - 1;
72 unsigned int outputShapeIndex = outputDimensions - 1;
73
74 // Loop backwards through the common part of the shapes
75 while (inputShapeIndex >= 0 && alphaShapeIndex >= 0)
76 {
77 unsigned int inputDimension = inputShape[armnn::numeric_cast<unsigned int>(inputShapeIndex)];
78 unsigned int alphaDimension = alphaShape[armnn::numeric_cast<unsigned int>(alphaShapeIndex)];
79
80 // Check that the inputs are broadcast compatible
81 if (inputDimension != alphaDimension && inputDimension != 1 && alphaDimension != 1)
82 {
83 throw armnn::Exception("PreluLayer: Dimensions should either match or one should be of size 1");
84 }
85
86 outputShape[outputShapeIndex] = std::max(inputDimension, alphaDimension);
87
88 inputShapeIndex--;
89 alphaShapeIndex--;
90 outputShapeIndex--;
91 }
92
93 // Loop backwards through the remaing part of the input shape (if any)
94 while (inputShapeIndex >= 0)
95 {
96 outputShape[outputShapeIndex] = inputShape[armnn::numeric_cast<unsigned int>(inputShapeIndex)];
97
98 inputShapeIndex--;
99 outputShapeIndex--;
100 }
101
102 // Loop backwards through the remaing part of the alpha shape (if any)
103 while (alphaShapeIndex >= 0)
104 {
105 outputShape[outputShapeIndex] = alphaShape[armnn::numeric_cast<unsigned int>(alphaShapeIndex)];
106
107 alphaShapeIndex--;
108 outputShapeIndex--;
109 }
110
111 return { outputShape };
112}
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)

References TensorShape::GetNumDimensions(), and armnn::numeric_cast().

Referenced by ValidateTensorShapesFromInputs().

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

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

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

Implements Layer.

Definition at line 114 of file PreluLayer.cpp.

115{
116 VerifyLayerConnections(2, CHECK_LOCATION());
117
118 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
119
120 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
121
122 std::vector<TensorShape> inferredShapes = InferOutputShapes(
123 {
124 GetInputSlot(0).GetTensorInfo().GetShape(),
125 GetInputSlot(1).GetTensorInfo().GetShape()
126 });
127
128 if (inferredShapes.size() != 1)
129 {
130 throw armnn::LayerValidationException("inferredShapes has "
131 + std::to_string(inferredShapes.size()) +
132 " elements - should only have 1.");
133 }
134
135 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "PreluLayer");
136}
#define CHECK_LOCATION()

References CHECK_LOCATION, Layer::GetInputSlot(), Layer::GetOutputSlot(), TensorInfo::GetShape(), InputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), InferOutputShapes(), Layer::m_ShapeInferenceMethod, Layer::ValidateAndCopyShape(), Layer::VerifyLayerConnections(), and Layer::VerifyShapeInferenceType().


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