ArmNN
 22.02
OutputSlot Class Referencefinal

#include <Layer.hpp>

Inheritance diagram for OutputSlot:
IOutputSlot

Public Member Functions

 OutputSlot (Layer &owner, OutputHandler &outputHandler)
 
 OutputSlot (const OutputSlot &)=delete
 
OutputSlotoperator= (const OutputSlot &)=delete
 
OutputSlotoperator= (OutputSlot &&)=delete
 
 OutputSlot (OutputSlot &&)=default
 
 ~OutputSlot ()
 
LayerGetOwningLayer () const
 
const IConnectableLayerGetOwningIConnectableLayer () const override
 
LayerGuid GetOwningLayerGuid () const override
 
const OutputHandlerGetOutputHandler () const
 
OutputHandlerGetOutputHandler ()
 
int Connect (InputSlot &destination)
 
void Disconnect (InputSlot &slot)
 
const std::vector< InputSlot * > & GetConnections () const
 
const std::vector< EdgeStrategy > & GetEdgeStrategies () const
 
bool ValidateTensorShape (const TensorShape &shape) const
 
void DisconnectAll ()
 
void MoveAllConnections (OutputSlot &destination)
 Moves all connections to another OutputSlot. More...
 
unsigned int GetNumConnections () const override
 
const InputSlotGetConnection (unsigned int index) const override
 
InputSlotGetConnection (unsigned int index) override
 
void SetTensorInfo (const TensorInfo &tensorInfo) override
 
const TensorInfoGetTensorInfo () const override
 
bool IsTensorInfoSet () const override
 
int Connect (IInputSlot &destination) override
 
void Disconnect (IInputSlot &slot) override
 
unsigned int CalculateIndexOnOwner () const override
 
bool operator== (const OutputSlot &other) const
 
void SetTensorHandleFactory (const ITensorHandleFactory::FactoryId &id)
 
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId () const
 
void SetEdgeStrategy (unsigned int connectionIndex, EdgeStrategy strategy)
 
EdgeStrategy GetEdgeStrategyForConnection (unsigned int connectionIdx) const
 

Additional Inherited Members

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

Detailed Description

Definition at line 86 of file Layer.hpp.

Constructor & Destructor Documentation

◆ OutputSlot() [1/3]

OutputSlot ( Layer owner,
OutputHandler outputHandler 
)
inlineexplicit

Definition at line 89 of file Layer.hpp.

90  : m_OwningLayer(owner)
91  , m_OutputHandler(outputHandler)
92  , m_TensorHandleFactoryId(ITensorHandleFactory::LegacyFactoryId)
93  {}
static const FactoryId LegacyFactoryId

◆ OutputSlot() [2/3]

OutputSlot ( const OutputSlot )
delete

◆ OutputSlot() [3/3]

OutputSlot ( OutputSlot &&  )
default

◆ ~OutputSlot()

~OutputSlot ( )
inline

Definition at line 101 of file Layer.hpp.

102  {
103  try
104  {
105  // Coverity fix: DisconnectAll() may throw uncaught exceptions.
106  DisconnectAll();
107  }
108  catch (const std::exception& e)
109  {
110  // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
111  // exception of type std::length_error.
112  // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
113  std::cerr << "WARNING: An error has occurred when disconnecting all output slots: "
114  << e.what() << std::endl;
115  }
116  }
void DisconnectAll()
Definition: Layer.cpp:110

Member Function Documentation

◆ CalculateIndexOnOwner()

unsigned int CalculateIndexOnOwner ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 133 of file Layer.cpp.

References ARMNN_ASSERT_MSG, Layer::GetNumOutputSlots(), Layer::GetOutputSlot(), and InputSlot::GetOwningLayer().

Referenced by DebugLayer::CreateWorkload().

134 {
135  for (unsigned int i = 0; i < GetOwningLayer().GetNumOutputSlots(); i++)
136  {
137  if (GetOwningLayer().GetOutputSlot(i) == (*this))
138  {
139  return i;
140  }
141  }
142  ARMNN_ASSERT_MSG(false, "Did not find slot on owner.");
143  return 0; // Error
144 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:118
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
Definition: Layer.hpp:319
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:323

◆ Connect() [1/2]

int Connect ( InputSlot destination)
Examples:
CustomMemoryAllocatorSample.cpp.

Definition at line 86 of file Layer.cpp.

References armnn::numeric_cast(), InputSlot::SetConnection(), and armnn::Undefined.

Referenced by NetworkImpl::AddFullyConnectedLayer(), CreateTestNetwork(), InputSlot::Insert(), Graph::InsertNewLayer(), OutputSlot::MoveAllConnections(), and TEST_SUITE().

87 {
88  destination.SetConnection(this);
89  m_Connections.push_back(&destination);
90  m_EdgeStrategies.push_back(EdgeStrategy::Undefined);
91  return armnn::numeric_cast<int>(m_Connections.size() - 1);
92 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ Connect() [2/2]

int Connect ( IInputSlot destination)
inlineoverridevirtual

Implements IOutputSlot.

Definition at line 151 of file Layer.hpp.

References Connect().

152  {
153  return Connect(*PolymorphicDowncast<InputSlot*>(&destination));
154  }
int Connect(InputSlot &destination)
Definition: Layer.cpp:86

◆ Disconnect() [1/2]

void Disconnect ( InputSlot slot)

Definition at line 94 of file Layer.cpp.

References InputSlot::SetConnection().

95 {
96  slot.SetConnection(nullptr);
97  auto it = std::find(m_Connections.begin(), m_Connections.end(), &slot);
98 
99  if (it == m_Connections.end())
100  {
101  return;
102  }
103 
104  auto idx = std::distance(m_Connections.begin(), it);
105  m_Connections.erase(std::remove(m_Connections.begin(), m_Connections.end(), &slot), m_Connections.end());
106 
107  m_EdgeStrategies.erase(m_EdgeStrategies.begin() + idx);
108 }

◆ Disconnect() [2/2]

void Disconnect ( IInputSlot slot)
inlineoverridevirtual

Implements IOutputSlot.

Definition at line 156 of file Layer.hpp.

References armnnUtils::operator==().

157  {
158  return Disconnect(*PolymorphicDowncast<InputSlot*>(&slot));
159  }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:94

◆ DisconnectAll()

void DisconnectAll ( )

Definition at line 110 of file Layer.cpp.

References InputSlot::GetConnection().

111 {
112  while (GetNumConnections() > 0)
113  {
114  InputSlot& connection = *GetConnection(0);
115  Disconnect(connection);
116  }
117 }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:94
unsigned int GetNumConnections() const override
Definition: Layer.hpp:143
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:49

◆ GetConnection() [1/2]

const InputSlot * GetConnection ( unsigned int  index) const
overridevirtual

Implements IOutputSlot.

Definition at line 49 of file Layer.cpp.

Referenced by SplitterLayer::CreateWorkload(), OutputSlot::operator==(), and TEST_SUITE().

50 {
51  ValidateConnectionIndex(index);
52  return m_Connections[index];
53 }

◆ GetConnection() [2/2]

InputSlot * GetConnection ( unsigned int  index)
overridevirtual

Implements IOutputSlot.

Definition at line 55 of file Layer.cpp.

56 {
57  ValidateConnectionIndex(index);
58  return m_Connections[index];
59 }

◆ GetConnections()

const std::vector<InputSlot*>& GetConnections ( ) const
inline

◆ GetEdgeStrategies()

const std::vector<EdgeStrategy>& GetEdgeStrategies ( ) const
inline

Definition at line 131 of file Layer.hpp.

Referenced by Graph::AddCompatibilityLayers().

131 { return m_EdgeStrategies; }

◆ GetEdgeStrategyForConnection()

EdgeStrategy GetEdgeStrategyForConnection ( unsigned int  connectionIdx) const

Definition at line 189 of file Layer.cpp.

Referenced by TEST_SUITE().

190 {
191  return m_EdgeStrategies[connectionIdx];
192 }

◆ GetNumConnections()

unsigned int GetNumConnections ( ) const
inlineoverridevirtual

Implements IOutputSlot.

Definition at line 143 of file Layer.hpp.

References InputSlot::GetConnection(), armnn::GetTensorInfo(), and armnn::numeric_cast().

Referenced by ConcatLayer::CreateWorkload(), OutputSlot::operator==(), LoadedNetwork::RegisterDebugCallback(), OptimizeConsecutiveReshapesImpl::Run(), MovePermuteUpImpl::Run(), MoveTransposeUpImpl::Run(), SquashEqualSiblingsImpl< Comparable >::Run(), and AddBroadcastReshapeLayerImpl::Run().

143 { return armnn::numeric_cast<unsigned int>(m_Connections.size()); }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ GetOutputHandler() [1/2]

const OutputHandler& GetOutputHandler ( ) const
inline

Definition at line 124 of file Layer.hpp.

Referenced by ConcatLayer::CreateWorkload(), OutputSlot::MoveAllConnections(), and TEST_SUITE().

124 { return m_OutputHandler; }

◆ GetOutputHandler() [2/2]

OutputHandler& GetOutputHandler ( )
inline

Definition at line 125 of file Layer.hpp.

References Connect().

125 { return m_OutputHandler; }

◆ GetOwningIConnectableLayer()

const IConnectableLayer & GetOwningIConnectableLayer ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 486 of file Layer.cpp.

487 {
488  return m_OwningLayer;
489 }

◆ GetOwningLayer()

◆ GetOwningLayerGuid()

LayerGuid GetOwningLayerGuid ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 169 of file Layer.cpp.

References Layer::GetGuid(), and InputSlot::GetOwningLayer().

170 {
171  return GetOwningLayer().GetGuid();
172 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:118
LayerGuid GetGuid() const final
Returns the unique id of the layer.
Definition: Layer.hpp:327

◆ GetTensorHandleFactoryId()

◆ GetTensorInfo()

const TensorInfo & GetTensorInfo ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 66 of file Layer.cpp.

Referenced by armnn::CheckScaleSetOnQuantizedType(), ConcatLayer::CreateWorkload(), armnn::optimizations::pad_fold::FoldPadIntoLayer2dImpl(), Layer::GetDataType(), LoadedNetwork::ImportInputs(), LoadedNetwork::ImportOutputs(), armnn::InsertConvertBf16ToFp32LayersBefore(), armnn::InsertConvertFp16ToFp32LayersBefore(), armnn::InsertConvertFp32ToBf16LayersAfter(), armnn::InsertConvertFp32ToBf16LayersBefore(), armnn::InsertConvertFp32ToFp16LayersAfter(), armnn::InsertDebugLayerAfter(), NeonBackend::OptimizeSubgraphView(), ClBackend::OptimizeSubgraphView(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), AddBroadcastReshapeLayerImpl::Run(), FuseBatchNorm< ConvLayer, ArmnnType, T >::Run(), Graph::SerializeToDot(), TEST_SUITE(), Layer::ValidateAndCopyShape(), ElementwiseBaseLayer::ValidateTensorShapesFromInputs(), RankLayer::ValidateTensorShapesFromInputs(), QuantizeLayer::ValidateTensorShapesFromInputs(), ActivationLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs(), ReduceLayer::ValidateTensorShapesFromInputs(), FillLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToBf16Layer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), CastLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), Pooling3dLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), ConvertBf16ToFp32Layer::ValidateTensorShapesFromInputs(), ShapeLayer::ValidateTensorShapesFromInputs(), SliceLayer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), TransposeLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), ChannelShuffleLayer::ValidateTensorShapesFromInputs(), PadLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), ReshapeLayer::ValidateTensorShapesFromInputs(), ConstantLayer::ValidateTensorShapesFromInputs(), Convolution3dLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), DetectionPostProcessLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), LogicalBinaryLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), SplitterLayer::ValidateTensorShapesFromInputs(), LstmLayer::ValidateTensorShapesFromInputs(), ConcatLayer::ValidateTensorShapesFromInputs(), UnidirectionalSequenceLstmLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), and QLstmLayer::ValidateTensorShapesFromInputs().

67 {
69 }
const OutputHandler & GetOutputHandler() const
Definition: Layer.hpp:124
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.

◆ IsTensorInfoSet()

bool IsTensorInfoSet ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 71 of file Layer.cpp.

References InputSlot::GetOwningLayer(), armnn::InferAndValidate, and Layer::ValidateTensorShapesFromInputs().

Referenced by AddBroadcastReshapeLayerImpl::Run().

72 {
73  if (GetOwningLayer().GetShapeInferenceMethod() == ShapeInferenceMethod::InferAndValidate)
74  {
76  }
78 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:118
bool IsTensorInfoSet() const
Returns true if SetTensorInfo() has been called at least once on this.
virtual void ValidateTensorShapesFromInputs()=0
Infer missing output shapes and validate all output shapes.
const OutputHandler & GetOutputHandler() const
Definition: Layer.hpp:124

◆ MoveAllConnections()

void MoveAllConnections ( OutputSlot destination)

Moves all connections to another OutputSlot.

Definition at line 119 of file Layer.cpp.

References ARMNN_ASSERT_MSG, OutputSlot::Connect(), InputSlot::GetConnection(), OutputSlot::GetOutputHandler(), armnn::GetTensorInfo(), OutputHandler::SetTensorInfo(), and armnn::Undefined.

Referenced by Graph::InsertNewLayer(), TransposeAsReshapeImpl::Run(), PermuteAsReshapeImpl::Run(), OptimizeConsecutiveReshapesImpl::Run(), OptimizeInverseConversionsImpl::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), OptimizeInversePermutesImpl< PermuteType >::Run(), and FuseBatchNorm< ConvLayer, ArmnnType, T >::Run().

120 {
121  while (GetNumConnections() > 0)
122  {
123  ARMNN_ASSERT_MSG(m_EdgeStrategies[0] == EdgeStrategy::Undefined,
124  "Cannot move connections once memory strategies have be established.");
125 
126  InputSlot& connection = *GetConnection(0);
127  Disconnect(connection);
128  destination.Connect(connection);
129  destination.GetOutputHandler().SetTensorInfo(GetOutputHandler().GetTensorInfo());
130  }
131 }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:94
unsigned int GetNumConnections() const override
Definition: Layer.hpp:143
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
const OutputHandler & GetOutputHandler() const
Definition: Layer.hpp:124
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:66
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:49

◆ operator=() [1/2]

OutputSlot& operator= ( const OutputSlot )
delete

◆ operator=() [2/2]

OutputSlot& operator= ( OutputSlot &&  )
delete

◆ operator==()

bool operator== ( const OutputSlot other) const

Definition at line 146 of file Layer.cpp.

References InputSlot::GetConnection(), OutputSlot::GetConnection(), and OutputSlot::GetNumConnections().

147 {
148  bool isSame = other.GetNumConnections() == GetNumConnections();
149  if (!isSame)
150  {
151  return false;
152  }
153 
154  for (unsigned int i = 0; i < GetNumConnections(); i++)
155  {
156  isSame &= other.GetConnection(i) == GetConnection(i);
157  }
158  return isSame;
159 }
unsigned int GetNumConnections() const override
Definition: Layer.hpp:143
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:49

◆ SetEdgeStrategy()

void SetEdgeStrategy ( unsigned int  connectionIndex,
EdgeStrategy  strategy 
)

Definition at line 184 of file Layer.cpp.

Referenced by Graph::AddCompatibilityLayers(), InputSlot::Insert(), armnn::SelectTensorHandleStrategy(), and TEST_SUITE().

185 {
186  m_EdgeStrategies[connectionIndex] = strategy;
187 }

◆ SetTensorHandleFactory()

void SetTensorHandleFactory ( const ITensorHandleFactory::FactoryId id)

Definition at line 174 of file Layer.cpp.

Referenced by Graph::AddCompatibilityLayers(), and armnn::SelectTensorHandleStrategy().

175 {
176  m_TensorHandleFactoryId = id;
177 }

◆ SetTensorInfo()

◆ ValidateTensorShape()

bool ValidateTensorShape ( const TensorShape shape) const

Definition at line 80 of file Layer.cpp.

References ARMNN_ASSERT_MSG.

81 {
82  ARMNN_ASSERT_MSG(IsTensorInfoSet(), "TensorInfo must be set in order to validate the shape.");
83  return shape == m_OutputHandler.GetTensorInfo().GetShape();
84 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
bool IsTensorInfoSet() const override
Definition: Layer.cpp:71
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.

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