23.02
|
Go to the documentation of this file.
38 class IWorkloadFactory;
46 : m_OwningLayer(owner)
47 , m_Connection(nullptr)
48 , m_SlotIndex(slotIndex)
65 if (m_Connection !=
nullptr && source !=
nullptr)
68 "but the latter already has a connection");
70 m_Connection = source;
84 const unsigned int m_SlotIndex;
91 : m_OwningLayer(owner)
92 , m_OutputHandler(outputHandler)
109 catch (
const std::exception& e)
114 std::cerr <<
"WARNING: An error has occurred when disconnecting all output slots: "
115 << e.what() << std::endl;
145 unsigned int GetNumConnections()
const override {
return armnn::numeric_cast<unsigned int>(m_Connections.size()); }
155 return Connect(*PolymorphicDowncast<InputSlot*>(&destination));
160 return Disconnect(*PolymorphicDowncast<InputSlot*>(&slot));
174 void ValidateConnectionIndex(
unsigned int index)
const;
176 Layer& m_OwningLayer;
178 std::vector<InputSlot*> m_Connections;
181 std::vector<EdgeStrategy> m_EdgeStrategies;
188 if (m_Connection !=
nullptr)
195 catch (
const std::exception& e)
200 std::cerr <<
"WARNING: An error has occurred when disconnecting an input slot: "
201 << e.what() << std::endl;
210 class ScopedTensorHandle;
221 Layer(
unsigned int numInputSlots,
unsigned int numOutputSlots,
LayerType type,
const char* name);
222 Layer(
unsigned int numInputSlots,
unsigned int numOutputSlots,
LayerType type,
DataLayout layout,
const char* name);
245 const std::vector<InputSlot>&
GetInputSlots()
const {
return m_InputSlots; }
250 std::vector<InputSlot>::iterator
EndInputSlots() {
return m_InputSlots.end(); }
254 std::vector<OutputSlot>::iterator
EndOutputSlots() {
return m_OutputSlots.end(); }
259 unsigned int numConnections = 0;
263 numConnections += output.GetNumConnections();
286 const bool IsMemoryManaged =
true);
296 std::vector<TensorShape>
InferOutputShapes(
const std::vector<TensorShape>& inputShapes)
const override;
305 template<
typename Op>
319 const char*
GetName()
const override {
return m_LayerName.c_str(); }
321 unsigned int GetNumInputSlots()
const override {
return static_cast<unsigned int>(m_InputSlots.size()); }
322 unsigned int GetNumOutputSlots()
const override {
return static_cast<unsigned int>(m_OutputSlots.size()); }
336 virtual void Reparent(
Graph& dest, std::list<Layer*>::const_iterator iterator) = 0;
340 m_BackendHint = backend;
351 m_AllowExpandedDims = allowExpandedDims;
370 virtual ~Layer() =
default;
372 template <
typename QueueDescriptor>
376 CollectWorkloadInputs(dataCollector);
379 template <
typename QueueDescriptor>
383 CollectWorkloadOutputs(dataCollector);
389 const std::string& layerName,
390 const unsigned int outputSlotIndex = 0);
395 template <
typename QueueDescriptor>
404 template <
typename LayerType,
typename ... Params>
426 const std::string m_LayerName;
428 std::vector<InputSlot> m_InputSlots;
429 std::vector<OutputSlot> m_OutputSlots;
437 mutable bool m_Visiting =
false;
439 bool m_AllowExpandedDims =
false;
443 std::list<std::string> m_RelatedLayerNames;
456 unsigned int numOutputSlots,
460 :
Layer(numInputSlots, numOutputSlots, type, name)
Null Descriptor used as a return value from the IConnectableLayer GetParameters method by layers whic...
const IConnectableLayer & GetOwningIConnectableLayer() const override
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
void SetShapeInferenceMethod(ShapeInferenceMethod shapeInferenceMethod)
void SetGuid(LayerGuid guid)
LayerType * CloneBase(Graph &graph, Params &&... params) const
std::vector< InputSlot >::iterator BeginInputSlots()
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
virtual void ReleaseConstantData()
void AddRelatedLayerName(const std::string layerName)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
void SetTensorInfo(const TensorInfo &tensorInfo) override
OutputHandler & GetOutputHandler()
void SetBackendId(const BackendId &id) override
Set the backend of the IConnectableLayer.
OutputSlot(Layer &owner, OutputHandler &outputHandler)
BindableLayer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name, LayerBindingId id)
bool IsTensorInfoSet() const override
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > >> ConstantTensors
void BackendSelectionHint(Optional< BackendId > backend) final
Provide a hint for the optimizer as to which backend to prefer for this layer.
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
unsigned int LayerPriority
const OutputHandler & GetOutputHandler() const
bool operator==(const OutputSlot &other) const
std::vector< InputSlot >::iterator EndInputSlots()
void SetAdditionalInfo(QueueDescriptor &descriptor) const
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
ShapeInferenceMethod m_ShapeInferenceMethod
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
virtual void Reparent(Graph &dest, std::list< Layer * >::const_iterator iterator)=0
Copyright (c) 2021 ARM Limited and Contributors.
LayerBindingId GetBindingId() const
const TensorInfo & GetTensorInfo() const override
void SetAllowExpandedDims(bool allowExpandedDims)
void CollectQueueDescriptorInputs(QueueDescriptor &descriptor, WorkloadInfo &info) const
bool ValidateTensorShape(const TensorShape &shape) const
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
const std::string & GetNameStr() const
std::shared_ptr< void > AdditionalInfoObjectPtr
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
OutputSlot & GetOutputSlot(unsigned int index=0) override
Get the output slot handle by slot index.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
void ResetPriority() const
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
AdditionalInfoObjectPtr m_AdditionalInfoObject
virtual void ValidateTensorShapesFromInputs()=0
virtual Layer * Clone(Graph &graph) const =0
Creates a dynamically-allocated copy of this layer.
void CollectQueueDescriptorOutputs(QueueDescriptor &descriptor, WorkloadInfo &info) const
const OutputHandler & GetOutputHandler(unsigned int i=0) const
const std::vector< InputSlot * > & GetConnections() const
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
virtual const BaseDescriptor & GetParameters() const override
If the layer has a descriptor return it.
const InputSlot * GetConnection(unsigned int index) const override
const std::vector< OutputSlot > & GetOutputSlots() const
bool GetAllowExpandedDims() const
unsigned int CalculateIndexOnOwner() const override
const std::list< std::string > & GetRelatedLayerNames()
An output connection slot for a layer.
bool IsOutputUnconnected()
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
const BackendId & GetBackendId() const
std::vector< OutputSlot >::iterator BeginOutputSlots()
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
OutputHandler & GetOutputHandler(unsigned int i=0)
Layer & GetOwningLayer() const
OutputSlot & operator=(const OutputSlot &)=delete
std::vector< OutputHandler > m_OutputHandlers
void Disconnect(IInputSlot &slot) override
const std::vector< InputSlot > & GetInputSlots() const
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
virtual ConstantTensors GetConstantTensorsByRef() override
void SetAdditionalInfoForObject(const AdditionalInfoObjectPtr &additionalInfo)
std::vector< OutputSlot >::iterator EndOutputSlots()
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Contains information about TensorInfos of a layer.
DataType GetDataType() const
Base class for all descriptors.
std::shared_ptr< T > GetAdditionalInformation() const
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
LayerGuid GetGuid() const final
Returns the unique id of the layer.
int Connect(InputSlot &destination)
Optional< BackendId > GetBackendHint() const
LayerGuid GetOwningLayerGuid() const override
const std::vector< EdgeStrategy > & GetEdgeStrategies() const
unsigned int GetNumConnections() const override
void OperateOnConstantTensors(Op op)
LayerPriority GetPriority() const
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const =0
std::vector< ITensorHandle * > m_Outputs
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
InputSlot & GetInputSlot(unsigned int index) override
Get the input slot handle by slot index.
const char * GetName() const override
Returns the name of the layer.
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
void Disconnect(InputSlot &slot)
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
int Connect(IInputSlot &destination) override
ShapeInferenceMethod GetShapeInferenceMethod() const
std::vector< ITensorHandle * > m_Inputs
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Infer the shape of the output(s) based on the provided input shape(s)