ArmNN
 24.08
InputSlot Class Referencefinal

#include <Layer.hpp>

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

Public Member Functions

 InputSlot (Layer &owner, unsigned int slotIndex)
 
 ~InputSlot ()
 
LayerGetOwningLayer () const
 
unsigned int GetSlotIndex () const override
 
const OutputSlotGetConnectedOutputSlot () const
 
OutputSlotGetConnectedOutputSlot ()
 
const IConnectableLayerGetOwningIConnectableLayer () const override
 
IConnectableLayerGetOwningIConnectableLayer () override
 
void SetConnection (OutputSlot *source)
 Links the slot to an output slot or breaks an existing link if passing nullptr. More...
 
void Insert (Layer &layer)
 
const IOutputSlotGetConnection () const override
 
IOutputSlotGetConnection () override
 
void SetTensorInfo (const TensorInfo tensorInfo) override
 Sets the TensorInfo for this InputSlot. More...
 
const TensorInfoGetTensorInfo () const override
 Gets the TensorInfo for this InputSlot. More...
 
bool IsTensorInfoSet () const override
 Returns true if this InputSlot either has an overridden TensorInfo for this InputSlot that was set through a call to SetTensorInfo() or is Connected to an OutputSlot that has its TensorInfo set. More...
 
bool IsTensorInfoOverridden () const override
 Returns true if this InputSlot has an overridden TensorInfo that was set through a call to SetTensorInfo(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from IInputSlot
 ~IInputSlot ()
 Not user deletable. More...
 

Detailed Description

Definition at line 42 of file Layer.hpp.

Constructor & Destructor Documentation

◆ InputSlot()

InputSlot ( Layer owner,
unsigned int  slotIndex 
)
inlineexplicit

Definition at line 45 of file Layer.hpp.

46  : m_OwningLayer(owner)
47  , m_Connection(nullptr)
48  , m_SlotIndex(slotIndex)
49  {}

◆ ~InputSlot()

~InputSlot ( )
inline

Definition at line 199 of file Layer.hpp.

200 {
201  if (m_Connection != nullptr)
202  {
203  try
204  {
205  // Coverity fix: Disconnect() may throw uncaught exceptions.
206  m_Connection->Disconnect(*this);
207  }
208  catch (const std::exception& e)
209  {
210  // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
211  // exception of type std::length_error.
212  // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
213  std::cerr << "WARNING: An error has occurred when disconnecting an input slot: "
214  << e.what() << std::endl;
215  }
216  }
217 }

References OutputSlot::Disconnect().

Member Function Documentation

◆ GetConnectedOutputSlot() [1/2]

OutputSlot* GetConnectedOutputSlot ( )
inline

Definition at line 57 of file Layer.hpp.

57 { return m_Connection; }

◆ GetConnectedOutputSlot() [2/2]

◆ GetConnection() [1/2]

◆ GetConnection() [2/2]

IOutputSlot* GetConnection ( )
overridevirtual

Implements IInputSlot.

◆ GetOwningIConnectableLayer() [1/2]

IConnectableLayer & GetOwningIConnectableLayer ( ) const
overridevirtual

Implements IInputSlot.

Definition at line 599 of file Layer.cpp.

600 {
601  return m_OwningLayer;
602 }

◆ GetOwningIConnectableLayer() [2/2]

IConnectableLayer& GetOwningIConnectableLayer ( )
overridevirtual

Implements IInputSlot.

◆ GetOwningLayer()

◆ GetSlotIndex()

unsigned int GetSlotIndex ( ) const
inlineoverridevirtual

Implements IInputSlot.

Definition at line 54 of file Layer.hpp.

54 { return m_SlotIndex; }

Referenced by Graph::AddCompatibilityLayers(), GetTosaMapping(), and armnn::RemoveReshapeLayer().

◆ GetTensorInfo()

const TensorInfo & GetTensorInfo ( ) const
overridevirtual

Gets the TensorInfo for this InputSlot.

If the InputSlot's TensorInfo has not been set then this will get the TensorInfo from the Connected TensorInfo.

Implements IInputSlot.

Definition at line 614 of file Layer.cpp.

615 {
616  if (m_OverriddenTensorInfo.has_value())
617  {
618  return m_OverriddenTensorInfo.value();
619  }
620  else
621  {
622  return GetConnection()->GetTensorInfo();
623  }
624 }

References InputSlot::GetConnection(), and IOutputSlot::GetTensorInfo().

Referenced by armnn::BuildAddMulAddTensorInfoLists(), armnn::ConnectedToLayerType(), ConvertConstantToTosaOperator(), LayerWithParameters< StridedSliceDescriptor >::GetConnectedConstantAsInputTensors(), Layer::GetDataType(), LoadedNetwork::ImportOutputs(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), Convolution3dLayer::SerializeLayerParameters(), DepthwiseConvolution2dLayer::SerializeLayerParameters(), Convolution2dLayer::SerializeLayerParameters(), ElementwiseBaseLayer::ValidateTensorShapesFromInputs(), QuantizeLayer::ValidateTensorShapesFromInputs(), ChannelShuffleLayer::ValidateTensorShapesFromInputs(), ActivationLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs(), FillLayer::ValidateTensorShapesFromInputs(), SliceLayer::ValidateTensorShapesFromInputs(), ShapeLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), TransposeLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), CastLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), Pooling3dLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), PadLayer::ValidateTensorShapesFromInputs(), ReshapeLayer::ValidateTensorShapesFromInputs(), Convolution3dLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), GatherNdLayer::ValidateTensorShapesFromInputs(), ScatterNdLayer::ValidateTensorShapesFromInputs(), TileLayer::ValidateTensorShapesFromInputs(), BatchMatMulLayer::ValidateTensorShapesFromInputs(), ElementwiseBinaryLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), ReduceLayer::ValidateTensorShapesFromInputs(), ReverseV2Layer::ValidateTensorShapesFromInputs(), DetectionPostProcessLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), LogicalBinaryLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), LstmLayer::ValidateTensorShapesFromInputs(), UnidirectionalSequenceLstmLayer::ValidateTensorShapesFromInputs(), ConcatLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), and QLstmLayer::ValidateTensorShapesFromInputs().

◆ Insert()

void Insert ( Layer layer)

Definition at line 53 of file Layer.cpp.

54 {
55  if (layer.GetNumOutputSlots() != 1)
56  {
57  throw armnn::Exception("layer must have one output slot.");
58  }
59 
60  OutputSlot* const prevSlot = GetConnectedOutputSlot();
61 
62  if (prevSlot != nullptr)
63  {
64  // Disconnects parent from this.
65  prevSlot->Disconnect(*this);
66 
68 
69  // Connects inserted layer to parent.
70  int idx = prevSlot->Connect(layer.GetInputSlot(0));
71  prevSlot->SetEdgeStrategy(armnn::numeric_cast<unsigned int>(idx), EdgeStrategy::Undefined);
72 
73  // Sets tensor info for inserted layer.
74  const TensorInfo& tensorInfo = prevSlot->GetTensorInfo();
75  layer.GetOutputHandler().SetTensorInfo(tensorInfo);
76  }
77 
78  // Connects inserted layer to this.
79  layer.GetOutputSlot(0).Connect(*this);
80  layer.GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::Undefined);
81 }

References armnn::AssertNumberOfInputSlots(), OutputSlot::Connect(), OutputSlot::Disconnect(), InputSlot::GetConnectedOutputSlot(), Layer::GetInputSlot(), Layer::GetNumOutputSlots(), Layer::GetOutputHandler(), Layer::GetOutputSlot(), OutputSlot::GetTensorInfo(), OutputSlot::SetEdgeStrategy(), OutputHandler::SetTensorInfo(), and armnn::Undefined.

Referenced by Graph::InsertNewLayer().

◆ IsTensorInfoOverridden()

bool IsTensorInfoOverridden ( ) const
overridevirtual

Returns true if this InputSlot has an overridden TensorInfo that was set through a call to SetTensorInfo().

Implements IInputSlot.

Definition at line 631 of file Layer.cpp.

632 {
633  return m_OverriddenTensorInfo.has_value();
634 }

◆ IsTensorInfoSet()

bool IsTensorInfoSet ( ) const
overridevirtual

Returns true if this InputSlot either has an overridden TensorInfo for this InputSlot that was set through a call to SetTensorInfo() or is Connected to an OutputSlot that has its TensorInfo set.

Implements IInputSlot.

Definition at line 626 of file Layer.cpp.

627 {
628  return m_OverriddenTensorInfo.has_value() || (GetConnection() && GetConnection()->IsTensorInfoSet());
629 }

References InputSlot::GetConnection(), and IOutputSlot::IsTensorInfoSet().

◆ SetConnection()

void SetConnection ( OutputSlot source)
inline

Links the slot to an output slot or breaks an existing link if passing nullptr.

Definition at line 63 of file Layer.hpp.

64  {
65  if (m_Connection != nullptr && source != nullptr)
66  {
67  throw InvalidArgumentException("Tried to connect an output slot to an input slot, "
68  "but the latter already has a connection");
69  }
70  m_Connection = source;
71  }

Referenced by OutputSlot::Connect(), and OutputSlot::Disconnect().

◆ SetTensorInfo()

void SetTensorInfo ( const TensorInfo  tensorInfo)
overridevirtual

Sets the TensorInfo for this InputSlot.

This can be used to override the TensorInfo and if set will be returned instead of the TensorInfo for the Connected OutputSlot.

Implements IInputSlot.

Definition at line 609 of file Layer.cpp.

610 {
611  m_OverriddenTensorInfo = Optional<TensorInfo>(tensorInfo);
612 }

Referenced by Graph::Graph(), and armnn::RemoveReshapeLayer().


The documentation for this class was generated from the following files:
armnn::IOutputSlot::GetTensorInfo
virtual const TensorInfo & GetTensorInfo() const =0
armnn::EdgeStrategy::Undefined
@ Undefined
armnn::OutputSlot::Disconnect
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:131
armnn::InputSlot::GetConnection
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:219
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::AssertNumberOfInputSlots
void AssertNumberOfInputSlots(Layer &layer)
Definition: Layer.cpp:28
armnn::IOutputSlot::IsTensorInfoSet
virtual bool IsTensorInfoSet() const =0
armnn::InputSlot::GetConnectedOutputSlot
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:56