ArmNN
 21.05
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
 
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 83 of file Layer.hpp.

Constructor & Destructor Documentation

◆ OutputSlot() [1/3]

OutputSlot ( Layer owner,
OutputHandler outputHandler 
)
inlineexplicit

Definition at line 86 of file Layer.hpp.

87  : m_OwningLayer(owner)
88  , m_OutputHandler(outputHandler)
89  , m_TensorHandleFactoryId(ITensorHandleFactory::LegacyFactoryId)
90  {}
static const FactoryId LegacyFactoryId

◆ OutputSlot() [2/3]

OutputSlot ( const OutputSlot )
delete

◆ OutputSlot() [3/3]

OutputSlot ( OutputSlot &&  )
default

◆ ~OutputSlot()

~OutputSlot ( )
inline

Definition at line 98 of file Layer.hpp.

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

Member Function Documentation

◆ CalculateIndexOnOwner()

unsigned int CalculateIndexOnOwner ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 130 of file Layer.cpp.

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

Referenced by DebugLayer::CreateWorkload(), and SubgraphViewSelector::SelectSubgraphs().

131 {
132  for (unsigned int i = 0; i < GetOwningLayer().GetNumOutputSlots(); i++)
133  {
134  if (GetOwningLayer().GetOutputSlot(i) == (*this))
135  {
136  return i;
137  }
138  }
139  ARMNN_ASSERT_MSG(false, "Did not find slot on owner.");
140  return 0; // Error
141 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:115
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
Definition: Layer.hpp:314
#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:318

◆ Connect() [1/2]

int Connect ( InputSlot destination)

Definition at line 83 of file Layer.cpp.

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

Referenced by AddBroadcastReshapeLayerOptimizerTest(), BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), CreateConvolution2dGraph(), CreateDepthwiseConvolution2dGraph(), CreateGatherGraph(), CreatePooling2dGraph(), CreateResizeBilinearGraph(), InputSlot::Insert(), Graph::InsertNewLayer(), and OutputSlot::MoveAllConnections().

84 {
85  destination.SetConnection(this);
86  m_Connections.push_back(&destination);
87  m_EdgeStrategies.push_back(EdgeStrategy::Undefined);
88  return armnn::numeric_cast<int>(m_Connections.size() - 1);
89 }
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 146 of file Layer.hpp.

References Connect().

147  {
148  return Connect(*PolymorphicDowncast<InputSlot*>(&destination));
149  }
int Connect(InputSlot &destination)
Definition: Layer.cpp:83

◆ Disconnect() [1/2]

void Disconnect ( InputSlot slot)

Definition at line 91 of file Layer.cpp.

References InputSlot::SetConnection().

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

◆ Disconnect() [2/2]

void Disconnect ( IInputSlot slot)
inlineoverridevirtual

Implements IOutputSlot.

Definition at line 151 of file Layer.hpp.

References armnnUtils::operator==().

152  {
153  return Disconnect(*PolymorphicDowncast<InputSlot*>(&slot));
154  }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:91

◆ DisconnectAll()

void DisconnectAll ( )

Definition at line 107 of file Layer.cpp.

References InputSlot::GetConnection().

108 {
109  while (GetNumConnections() > 0)
110  {
111  InputSlot& connection = *GetConnection(0);
112  Disconnect(connection);
113  }
114 }
void Disconnect(InputSlot &slot)
Definition: Layer.cpp:91
unsigned int GetNumConnections() const override
Definition: Layer.hpp:138
const InputSlot * GetConnection(unsigned int index) const override
Definition: Layer.cpp:46

◆ GetConnection() [1/2]

const InputSlot * GetConnection ( unsigned int  index) const
overridevirtual

Implements IOutputSlot.

Definition at line 46 of file Layer.cpp.

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

47 {
48  ValidateConnectionIndex(index);
49  return m_Connections[index];
50 }

◆ GetConnection() [2/2]

InputSlot * GetConnection ( unsigned int  index)
overridevirtual

Implements IOutputSlot.

Definition at line 52 of file Layer.cpp.

53 {
54  ValidateConnectionIndex(index);
55  return m_Connections[index];
56 }

◆ GetConnections()

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

◆ GetEdgeStrategies()

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

Definition at line 126 of file Layer.hpp.

Referenced by Graph::AddCompatibilityLayers().

126 { return m_EdgeStrategies; }

◆ GetEdgeStrategyForConnection()

EdgeStrategy GetEdgeStrategyForConnection ( unsigned int  connectionIdx) const

Definition at line 186 of file Layer.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

187 {
188  return m_EdgeStrategies[connectionIdx];
189 }

◆ GetNumConnections()

unsigned int GetNumConnections ( ) const
inlineoverridevirtual

Implements IOutputSlot.

Definition at line 138 of file Layer.hpp.

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

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

138 { 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 119 of file Layer.hpp.

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

119 { return m_OutputHandler; }

◆ GetOutputHandler() [2/2]

OutputHandler& GetOutputHandler ( )
inline

Definition at line 120 of file Layer.hpp.

References Connect().

120 { return m_OutputHandler; }

◆ GetOwningLayer()

◆ GetOwningLayerGuid()

LayerGuid GetOwningLayerGuid ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 166 of file Layer.cpp.

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

167 {
168  return GetOwningLayer().GetGuid();
169 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:115
LayerGuid GetGuid() const final
Returns the unique id of the layer.
Definition: Layer.hpp:322

◆ GetTensorHandleFactoryId()

◆ GetTensorInfo()

const TensorInfo & GetTensorInfo ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 63 of file Layer.cpp.

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

64 {
66 }
const OutputHandler & GetOutputHandler() const
Definition: Layer.hpp:119
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.

◆ IsTensorInfoSet()

bool IsTensorInfoSet ( ) const
overridevirtual

Implements IOutputSlot.

Definition at line 68 of file Layer.cpp.

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

Referenced by AddBroadcastReshapeLayerImpl::Run().

69 {
70  if (GetOwningLayer().GetShapeInferenceMethod() == ShapeInferenceMethod::InferAndValidate)
71  {
73  }
75 }
Layer & GetOwningLayer() const
Definition: Layer.hpp:115
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:119

◆ MoveAllConnections()

void MoveAllConnections ( OutputSlot destination)

Moves all connections to another OutputSlot.

Definition at line 116 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(), PermuteAsReshapeImpl::Run(), TransposeAsReshapeImpl::Run(), OptimizeConsecutiveReshapesImpl::Run(), OptimizeInverseConversionsImpl::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >::Run(), OptimizeInversePermutesImpl< PermuteType >::Run(), FuseBatchNorm< ConvLayer, ArmnnType, T >::Run(), and Graph::SubstituteSubgraph().

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

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

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

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

◆ SetEdgeStrategy()

void SetEdgeStrategy ( unsigned int  connectionIndex,
EdgeStrategy  strategy 
)

Definition at line 181 of file Layer.cpp.

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

182 {
183  m_EdgeStrategies[connectionIndex] = strategy;
184 }

◆ SetTensorHandleFactory()

void SetTensorHandleFactory ( const ITensorHandleFactory::FactoryId id)

Definition at line 171 of file Layer.cpp.

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

172 {
173  m_TensorHandleFactoryId = id;
174 }

◆ SetTensorInfo()

◆ ValidateTensorShape()

bool ValidateTensorShape ( const TensorShape shape) const

Definition at line 77 of file Layer.cpp.

References ARMNN_ASSERT_MSG.

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

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