ArmNN
 22.05.01
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:136

Member Function Documentation

◆ CalculateIndexOnOwner()

unsigned int CalculateIndexOnOwner ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 159 of file Layer.cpp.

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

Referenced by DebugLayer::CreateWorkload().

160 {
161  for (unsigned int i = 0; i < GetOwningLayer().GetNumOutputSlots(); i++)
162  {
163  if (GetOwningLayer().GetOutputSlot(i) == (*this))
164  {
165  return i;
166  }
167  }
168  ARMNN_ASSERT_MSG(false, "Did not find slot on owner.");
169  return 0; // Error
170 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:118
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
Definition: Layer.hpp:320
#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:324

◆ Connect() [1/2]

int Connect ( InputSlot destination)

Definition at line 112 of file Layer.cpp.

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

Referenced by NetworkImpl::AddConvolution2dLayer(), NetworkImpl::AddDepthwiseConvolution2dLayer(), NetworkImpl::AddFullyConnectedLayer(), armnn::optimizations::pad_fold::FoldPadIntoLayer2dImpl(), InputSlot::Insert(), Graph::InsertNewLayer(), OutputSlot::MoveAllConnections(), FuseBatchNorm< ConvLayer, ArmnnType, T >::Run(), and TEST_SUITE().

113 {
114  destination.SetConnection(this);
115  m_Connections.push_back(&destination);
116  m_EdgeStrategies.push_back(EdgeStrategy::Undefined);
117  return armnn::numeric_cast<int>(m_Connections.size() - 1);
118 }
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:112

◆ Disconnect() [1/2]

void Disconnect ( InputSlot slot)

Definition at line 120 of file Layer.cpp.

References InputSlot::SetConnection().

Referenced by armnn::optimizations::pad_fold::FoldPadIntoLayer2dImpl(), and FuseBatchNorm< ConvLayer, ArmnnType, T >::Run().

121 {
122  slot.SetConnection(nullptr);
123  auto it = std::find(m_Connections.begin(), m_Connections.end(), &slot);
124 
125  if (it == m_Connections.end())
126  {
127  return;
128  }
129 
130  auto idx = std::distance(m_Connections.begin(), it);
131  m_Connections.erase(std::remove(m_Connections.begin(), m_Connections.end(), &slot), m_Connections.end());
132 
133  m_EdgeStrategies.erase(m_EdgeStrategies.begin() + idx);
134 }

◆ 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:120

◆ DisconnectAll()

void DisconnectAll ( )

Definition at line 136 of file Layer.cpp.

References InputSlot::GetConnection().

137 {
138  while (GetNumConnections() > 0)
139  {
140  InputSlot& connection = *GetConnection(0);
141  Disconnect(connection);
142  }
143 }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:120
unsigned int GetNumConnections() const override
Definition: Layer.hpp:143
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:75

◆ GetConnection() [1/2]

const InputSlot * GetConnection ( unsigned int  index) const
overridevirtual

Implements IOutputSlot.

Definition at line 75 of file Layer.cpp.

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

76 {
77  ValidateConnectionIndex(index);
78  return m_Connections[index];
79 }

◆ GetConnection() [2/2]

InputSlot * GetConnection ( unsigned int  index)
overridevirtual

Implements IOutputSlot.

Definition at line 81 of file Layer.cpp.

82 {
83  ValidateConnectionIndex(index);
84  return m_Connections[index];
85 }

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

Referenced by TEST_SUITE().

216 {
217  return m_EdgeStrategies[connectionIdx];
218 }

◆ GetNumConnections()

unsigned int GetNumConnections ( ) const
inlineoverridevirtual

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

542 {
543  return m_OwningLayer;
544 }

◆ GetOwningLayer()

◆ GetOwningLayerGuid()

LayerGuid GetOwningLayerGuid ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 195 of file Layer.cpp.

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

196 {
197  return GetOwningLayer().GetGuid();
198 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:118
LayerGuid GetGuid() const final
Returns the unique id of the layer.
Definition: Layer.hpp:328

◆ GetTensorHandleFactoryId()

◆ GetTensorInfo()

const TensorInfo & GetTensorInfo ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 92 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(), ConvertConstDequantisationLayersToConstLayersImpl::Run(), ConvertConstPermuteLayersToConstLayers::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), PermuteDepthwiseConv2dWeightsImpl::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(), SliceLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToBf16Layer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), CastLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), Pooling3dLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), ConvertBf16ToFp32Layer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), ShapeLayer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), TransposeLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), ChannelShuffleLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), PadLayer::ValidateTensorShapesFromInputs(), ReshapeLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), ConstantLayer::ValidateTensorShapesFromInputs(), Convolution3dLayer::ValidateTensorShapesFromInputs(), GatherNdLayer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), DetectionPostProcessLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), LogicalBinaryLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), SplitterLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), UnidirectionalSequenceLstmLayer::ValidateTensorShapesFromInputs(), ConcatLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), LstmLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), and QLstmLayer::ValidateTensorShapesFromInputs().

93 {
95 }
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 97 of file Layer.cpp.

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

Referenced by AddBroadcastReshapeLayerImpl::Run().

98 {
99  if (GetOwningLayer().GetShapeInferenceMethod() == ShapeInferenceMethod::InferAndValidate)
100  {
102  }
104 }
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 145 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(), ConvertConstDequantisationLayersToConstLayersImpl::Run(), PermuteAsReshapeImpl::Run(), TransposeAsReshapeImpl::Run(), OptimizeConsecutiveReshapesImpl::Run(), ConvertConstPermuteLayersToConstLayers::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), OptimizeInverseConversionsImpl::Run(), OptimizeInversePermutesImpl< PermuteType >::Run(), and FuseBatchNorm< ConvLayer, ArmnnType, T >::Run().

146 {
147  while (GetNumConnections() > 0)
148  {
149  ARMNN_ASSERT_MSG(m_EdgeStrategies[0] == EdgeStrategy::Undefined,
150  "Cannot move connections once memory strategies have be established.");
151 
152  InputSlot& connection = *GetConnection(0);
153  Disconnect(connection);
154  destination.Connect(connection);
155  destination.GetOutputHandler().SetTensorInfo(GetOutputHandler().GetTensorInfo());
156  }
157 }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:120
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:92
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:75

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

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

173 {
174  bool isSame = other.GetNumConnections() == GetNumConnections();
175  if (!isSame)
176  {
177  return false;
178  }
179 
180  for (unsigned int i = 0; i < GetNumConnections(); i++)
181  {
182  isSame &= other.GetConnection(i) == GetConnection(i);
183  }
184  return isSame;
185 }
unsigned int GetNumConnections() const override
Definition: Layer.hpp:143
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:75

◆ SetEdgeStrategy()

void SetEdgeStrategy ( unsigned int  connectionIndex,
EdgeStrategy  strategy 
)

Definition at line 210 of file Layer.cpp.

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

211 {
212  m_EdgeStrategies[connectionIndex] = strategy;
213 }

◆ SetTensorHandleFactory()

void SetTensorHandleFactory ( const ITensorHandleFactory::FactoryId id)

Definition at line 200 of file Layer.cpp.

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

201 {
202  m_TensorHandleFactoryId = id;
203 }

◆ SetTensorInfo()

◆ ValidateTensorShape()

bool ValidateTensorShape ( const TensorShape shape) const

Definition at line 106 of file Layer.cpp.

References ARMNN_ASSERT_MSG.

107 {
108  ARMNN_ASSERT_MSG(IsTensorInfoSet(), "TensorInfo must be set in order to validate the shape.");
109  return shape == m_OutputHandler.GetTensorInfo().GetShape();
110 }
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:97
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.

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