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;
97 const unsigned int m_SlotIndex;
104 : m_OwningLayer(owner)
105 , m_OutputHandler(outputHandler)
122 catch (
const std::exception& e)
127 std::cerr <<
"WARNING: An error has occurred when disconnecting all output slots: "
128 << e.what() << std::endl;
187 void ValidateConnectionIndex(
unsigned int index)
const;
189 Layer& m_OwningLayer;
191 std::vector<InputSlot*> m_Connections;
194 std::vector<EdgeStrategy> m_EdgeStrategies;
201 if (m_Connection !=
nullptr)
206 m_Connection->Disconnect(*
this);
208 catch (
const std::exception& e)
213 std::cerr <<
"WARNING: An error has occurred when disconnecting an input slot: "
214 << e.what() << std::endl;
234 Layer(
unsigned int numInputSlots,
unsigned int numOutputSlots,
LayerType type,
const char* name);
235 Layer(
unsigned int numInputSlots,
unsigned int numOutputSlots,
LayerType type,
DataLayout layout,
const char* name);
252 return const_cast<OutputHandler&
>(
const_cast<const Layer*
>(
this)->GetOutputHandler(i));
258 const std::vector<InputSlot>&
GetInputSlots()
const {
return m_InputSlots; }
263 std::vector<InputSlot>::iterator
EndInputSlots() {
return m_InputSlots.end(); }
267 std::vector<OutputSlot>::iterator
EndOutputSlots() {
return m_OutputSlots.end(); }
272 unsigned int numConnections = 0;
276 numConnections += output.GetNumConnections();
299 const bool IsMemoryManaged =
true);
309 std::vector<TensorShape>
InferOutputShapes(
const std::vector<TensorShape>& inputShapes)
const override;
318 template<
typename Op>
332 const char*
GetName()
const override {
return m_LayerName.c_str(); }
334 unsigned int GetNumInputSlots()
const override {
return static_cast<unsigned int>(m_InputSlots.size()); }
335 unsigned int GetNumOutputSlots()
const override {
return static_cast<unsigned int>(m_OutputSlots.size()); }
349 virtual void Reparent(
Graph& dest, std::list<Layer*>::const_iterator iterator) = 0;
353 m_BackendHint = backend;
364 m_AllowExpandedDims = allowExpandedDims;
385 template <
typename QueueDescriptor>
389 CollectWorkloadInputs(dataCollector);
392 template <
typename QueueDescriptor>
396 CollectWorkloadOutputs(dataCollector);
402 const std::string& layerName,
403 const unsigned int outputSlotIndex = 0);
408 template <
typename QueueDescriptor>
418 template <
typename LayerType,
typename ... Params>
444 const std::string m_LayerName;
446 std::vector<InputSlot> m_InputSlots;
447 std::vector<OutputSlot> m_OutputSlots;
455 mutable bool m_Visiting =
false;
457 bool m_AllowExpandedDims =
false;
461 std::list<std::string> m_RelatedLayerNames;
474 unsigned int numOutputSlots,
478 :
Layer(numInputSlots, numOutputSlots, type, name)
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
LayerBindingId GetBindingId() const
BindableLayer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name, LayerBindingId id)
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > > > ConstantTensors
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > > > ImmutableConstantTensors
An output connection slot for a layer.
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
Workload interface to enqueue a layer computation.
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const =0
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
const std::vector< OutputSlot > & GetOutputSlots() const
bool IsOutputUnconnected()
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
void SetBackendId(const BackendId &id) override
Set the backend of the IConnectableLayer.
void SetAllowExpandedDims(bool allowExpandedDims)
void AddRelatedLayerName(const std::string layerName)
virtual void ReleaseConstantData()
ShapeInferenceMethod GetShapeInferenceMethod() const
const std::string & GetNameStr() const
void OperateOnConstantTensors(Op op)
std::vector< InputSlot >::iterator EndInputSlots()
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
void SetShapeInferenceMethod(ShapeInferenceMethod shapeInferenceMethod)
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.
void CollectQueueDescriptorOutputs(QueueDescriptor &descriptor, WorkloadInfo &info) const
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
const std::vector< InputSlot > & GetInputSlots() const
OutputHandler & GetOutputHandler(unsigned int i=0)
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)
void SetGuid(LayerGuid guid)
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
virtual void ValidateTensorShapesFromInputs()=0
const std::list< std::string > & GetRelatedLayerNames()
std::vector< OutputSlot >::iterator BeginOutputSlots()
LayerGuid GetGuid() const final
Returns the unique id of the layer.
virtual ConstantTensors GetConstantTensorsByRef() override final
LayerType * CloneBase(Graph &graph, Params &&... params) const
std::vector< OutputHandler > m_OutputHandlers
InputSlot & GetInputSlot(unsigned int index) override
Get the input slot handle by slot index.
OutputSlot & GetOutputSlot(unsigned int index=0) override
Get the output slot handle by slot index.
void ResetPriority() const
virtual Layer * Clone(Graph &graph) const =0
Creates a dynamically-allocated copy of this layer.
std::shared_ptr< T > GetAdditionalInformation() const
const OutputHandler & GetOutputHandler(unsigned int i=0) const
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
AdditionalInfoObjectPtr m_AdditionalInfoObject
const char * GetName() const override
Returns the name of the layer.
bool GetAllowExpandedDims() 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.
std::vector< InputSlot >::iterator BeginInputSlots()
const BackendId & GetBackendId() const
Optional< BackendId > GetBackendHint() const
virtual void Reparent(Graph &dest, std::list< Layer * >::const_iterator iterator)=0
void SetAdditionalInfoForObject(const AdditionalInfoObjectPtr &additionalInfo)
DataType GetDataType() const
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void SetAdditionalInfo(QueueDescriptor &descriptor) const
LayerPriority GetPriority() const
std::vector< OutputSlot >::iterator EndOutputSlots()
void CollectQueueDescriptorInputs(QueueDescriptor &descriptor, WorkloadInfo &info) const
ShapeInferenceMethod m_ShapeInferenceMethod
const InputSlot * GetConnection(unsigned int index) const override
const IConnectableLayer & GetOwningIConnectableLayer() const override
OutputSlot(OutputSlot &&)=default
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
int Connect(IInputSlot &destination) override
unsigned int GetNumConnections() const override
unsigned int CalculateIndexOnOwner() const override
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
OutputHandler & GetOutputHandler()
OutputSlot(Layer &owner, OutputHandler &outputHandler)
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
LayerGuid GetOwningLayerGuid() const override
const OutputHandler & GetOutputHandler() const
OutputSlot & operator=(const OutputSlot &)=delete
void SetTensorInfo(const TensorInfo &tensorInfo) override
Layer & GetOwningLayer() const
const std::vector< EdgeStrategy > & GetEdgeStrategies() const
bool operator==(const OutputSlot &other) const
const std::vector< InputSlot * > & GetConnections() const
OutputSlot(const OutputSlot &)=delete
bool IsTensorInfoSet() const override
bool ValidateTensorShape(const TensorShape &shape) const
void Disconnect(InputSlot &slot)
OutputSlot & operator=(OutputSlot &&)=delete
void Disconnect(IInputSlot &slot) override
const TensorInfo & GetTensorInfo() const override
int Connect(InputSlot &destination)
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
Copyright (c) 2021 ARM Limited and Contributors.
std::shared_ptr< void > AdditionalInfoObjectPtr
unsigned int LayerPriority
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
DestType PolymorphicDowncast(SourceType *value)
Polymorphic downcast for build in pointers only.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
Base class for all descriptors.
Null Descriptor used as a return value from the IConnectableLayer GetParameters method by layers whic...
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs
Contains information about TensorInfos of a layer.