ArmNN
 24.02
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]

const OutputSlot* GetConnectedOutputSlot ( ) const
inline

Definition at line 56 of file Layer.hpp.

56 { return m_Connection; }

Referenced by armnn::BuildAddMulAddTensorInfoLists(), armnn::ConnectedToLayerType(), armnn::ConnectedToLayerWithNCHW(), ConvertActivationToTosaOperator(), ConvertAvgPool2DIgnoreValueToTosaOperator(), ConvertConcatToTosaOperator(), ConvertConv2dToTosaOperator(), ConvertElementwiseBinaryToTosaOperator(), ConvertElementwiseUnaryOperator(), ConvertPooling2DToTosaOperator(), ConvertQuantizeToTosaOperator(), ConvertReshapeToTosaOperator(), ConvertResizeToTosaOperator(), ConvertSliceToTosaOperator(), ConvertTransposeConv2dToTosaOperator(), ConvertTransposeToTosaOperator(), DebugLayer::CreateWorkload(), armnn::optimizations::pad_fold::FoldPadIntoLayer2dImpl(), LayerWithParameters< StridedSliceDescriptor >::GetConnectedConstantAsInputTensors(), InputSlot::GetConnection(), armnn::GetLayerInOutDatatype(), LoadedNetwork::ImportOutputs(), InputSlot::Insert(), armnn::InsertConvertFp16ToFp32LayersBefore(), armnn::InsertConvertFp32ToFp16LayersAfter(), armnn::InsertDebugLayerAfter(), Graph::InsertNewLayer(), RefBackend::OptimizeSubgraphView(), NeonBackend::OptimizeSubgraphView(), ClBackend::OptimizeSubgraphView(), GpuFsaBackend::OptimizeSubgraphView(), armnn::RemoveReshapeLayer(), OptimizeConsecutiveReshapesImpl::Run(), ConvertConstPermuteLayersToConstLayers::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), OptimizeInverseConversionsImpl::Run(), ConvertConstDequantisationLayersToConstLayersImpl::Run(), MoveTransposeUpImpl::Run(), MovePermuteUpImpl::Run(), OptimizeInversePermutesImpl< PermuteType >::Run(), SquashEqualSiblingsImpl< Comparable >::Run(), FuseBatchNorm< ConvLayer, ArmnnType, T >::Run(), and AddBroadcastReshapeLayerImpl::Run().

◆ GetConnection() [1/2]

◆ GetConnection() [2/2]

IOutputSlot* GetConnection ( )
overridevirtual

Implements IInputSlot.

◆ GetOwningIConnectableLayer() [1/2]

IConnectableLayer & GetOwningIConnectableLayer ( ) const
overridevirtual

Implements IInputSlot.

Definition at line 577 of file Layer.cpp.

578 {
579  return m_OwningLayer;
580 }

◆ 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(), 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 592 of file Layer.cpp.

593 {
594  if (m_OverriddenTensorInfo.has_value())
595  {
596  return m_OverriddenTensorInfo.value();
597  }
598  else
599  {
600  return GetConnection()->GetTensorInfo();
601  }
602 }

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

Referenced by armnn::BuildAddMulAddTensorInfoLists(), armnn::ConnectedToLayerType(), 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(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), TransposeLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), CastLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), Pooling3dLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), ShapeLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), PadLayer::ValidateTensorShapesFromInputs(), ReshapeLayer::ValidateTensorShapesFromInputs(), Convolution3dLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), GatherNdLayer::ValidateTensorShapesFromInputs(), TileLayer::ValidateTensorShapesFromInputs(), BatchMatMulLayer::ValidateTensorShapesFromInputs(), ElementwiseBinaryLayer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), ReverseV2Layer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), ReduceLayer::ValidateTensorShapesFromInputs(), DetectionPostProcessLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), LogicalBinaryLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), LstmLayer::ValidateTensorShapesFromInputs(), ConcatLayer::ValidateTensorShapesFromInputs(), UnidirectionalSequenceLstmLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), and QLstmLayer::ValidateTensorShapesFromInputs().

◆ Insert()

void Insert ( Layer layer)

Definition at line 48 of file Layer.cpp.

49 {
50  ARMNN_ASSERT(layer.GetNumOutputSlots() == 1);
51 
52  OutputSlot* const prevSlot = GetConnectedOutputSlot();
53 
54  if (prevSlot != nullptr)
55  {
56  // Disconnects parent from this.
57  prevSlot->Disconnect(*this);
58 
60 
61  // Connects inserted layer to parent.
62  int idx = prevSlot->Connect(layer.GetInputSlot(0));
63  prevSlot->SetEdgeStrategy(armnn::numeric_cast<unsigned int>(idx), EdgeStrategy::Undefined);
64 
65  // Sets tensor info for inserted layer.
66  const TensorInfo& tensorInfo = prevSlot->GetTensorInfo();
67  layer.GetOutputHandler().SetTensorInfo(tensorInfo);
68  }
69 
70  // Connects inserted layer to this.
71  layer.GetOutputSlot(0).Connect(*this);
72  layer.GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::Undefined);
73 }

References ARMNN_ASSERT, 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 609 of file Layer.cpp.

610 {
611  return m_OverriddenTensorInfo.has_value();
612 }

◆ 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 604 of file Layer.cpp.

605 {
606  return m_OverriddenTensorInfo.has_value() || (GetConnection() && GetConnection()->IsTensorInfoSet());
607 }

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 587 of file Layer.cpp.

588 {
589  m_OverriddenTensorInfo = Optional<TensorInfo>(tensorInfo);
590 }

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


The documentation for this class was generated from the following files:
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::IOutputSlot::GetTensorInfo
virtual const TensorInfo & GetTensorInfo() const =0
armnn::EdgeStrategy::Undefined
@ Undefined
armnn::OutputSlot::Disconnect
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:120
armnn::InputSlot::GetConnection
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:219
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