ArmNN  NotReleased
Layer Class Referenceabstract

#include <Layer.hpp>

Inheritance diagram for Layer:
IConnectableLayer AbsLayer BindableLayer ConstantLayer ConvertFp16ToFp32Layer ConvertFp32ToFp16Layer DebugLayer DequantizeLayer ElementwiseBaseLayer FloorLayer GatherLayer LayerWithParameters< Parameters > MemCopyLayer MemImportLayer MergeLayer PreluLayer QuantizedLstmLayer QuantizeLayer RsqrtLayer SwitchLayer LayerWithParameters< ActivationDescriptor > LayerWithParameters< ArgMinMaxDescriptor > LayerWithParameters< BatchNormalizationDescriptor > LayerWithParameters< BatchToSpaceNdDescriptor > LayerWithParameters< ComparisonDescriptor > LayerWithParameters< Convolution2dDescriptor > LayerWithParameters< DepthToSpaceDescriptor > LayerWithParameters< DepthwiseConvolution2dDescriptor > LayerWithParameters< DetectionPostProcessDescriptor > LayerWithParameters< ElementwiseUnaryDescriptor > LayerWithParameters< FakeQuantizationDescriptor > LayerWithParameters< FullyConnectedDescriptor > LayerWithParameters< InstanceNormalizationDescriptor > LayerWithParameters< L2NormalizationDescriptor > LayerWithParameters< LogSoftmaxDescriptor > LayerWithParameters< LstmDescriptor > LayerWithParameters< MeanDescriptor > LayerWithParameters< NormalizationDescriptor > LayerWithParameters< OriginsDescriptor > LayerWithParameters< PadDescriptor > LayerWithParameters< PermuteDescriptor > LayerWithParameters< Pooling2dDescriptor > LayerWithParameters< PreCompiledDescriptor > LayerWithParameters< ReshapeDescriptor > LayerWithParameters< ResizeDescriptor > LayerWithParameters< SliceDescriptor > LayerWithParameters< SoftmaxDescriptor > LayerWithParameters< SpaceToBatchNdDescriptor > LayerWithParameters< SpaceToDepthDescriptor > LayerWithParameters< StackDescriptor > LayerWithParameters< StandInDescriptor > LayerWithParameters< StridedSliceDescriptor > LayerWithParameters< TransposeConvolution2dDescriptor > LayerWithParameters< ViewsDescriptor >

Public Member Functions

 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
 
const std::string & GetNameStr () const
 
const OutputHandlerGetOutputHandler (unsigned int i=0) const
 
OutputHandlerGetOutputHandler (unsigned int i=0)
 
const std::vector< InputSlot > & GetInputSlots () const
 
const std::vector< OutputSlot > & GetOutputSlots () const
 
std::vector< InputSlot >::iterator BeginInputSlots ()
 
std::vector< InputSlot >::iterator EndInputSlots ()
 
std::vector< OutputSlot >::iterator BeginOutputSlots ()
 
std::vector< OutputSlot >::iterator EndOutputSlots ()
 
bool IsOutputUnconnected ()
 
void ResetPriority () const
 
LayerPriority GetPriority () const
 
LayerType GetType () const
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id)
 
virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const =0
 
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
 
virtual LayerClone (Graph &graph) const =0
 
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
 
virtual void ValidateTensorShapesFromInputs ()=0
 
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 
virtual void SerializeLayerParameters (ParameterStringifyFunction &fn) const
 
virtual void ReleaseConstantData ()
 
template<typename Op >
void OperateOnConstantTensors (Op op)
 
const char * GetName () const override
 
unsigned int GetNumInputSlots () const override
 
unsigned int GetNumOutputSlots () const override
 
const InputSlotGetInputSlot (unsigned int index) const override
 
InputSlotGetInputSlot (unsigned int index) override
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 
void AddRelatedLayerName (const std::string layerName)
 
const std::list< std::string > & GetRelatedLayerNames ()
 
virtual void Reparent (Graph &dest, std::list< Layer *>::const_iterator iterator)=0
 
- Public Member Functions inherited from IConnectableLayer
virtual void Accept (ILayerVisitor &visitor) const =0
 

Protected Types

using ConstantTensors = std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >>
 

Protected Member Functions

virtual ~Layer ()=default
 
template<typename QueueDescriptor >
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
virtual ConstantTensors GetConstantTensorsByRef ()
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle. More...
 

Protected Attributes

std::vector< OutputHandlerm_OutputHandlers
 

Friends

class Graph
 

Detailed Description

Definition at line 209 of file Layer.hpp.

Member Typedef Documentation

◆ ConstantTensors

using ConstantTensors = std::vector<std::reference_wrapper<std::unique_ptr<ScopedCpuTensorHandle> >>
protected

Definition at line 356 of file Layer.hpp.

Constructor & Destructor Documentation

◆ Layer() [1/2]

Layer ( unsigned int  numInputSlots,
unsigned int  numOutputSlots,
LayerType  type,
const char *  name 
)
Parameters
name- Optional name for the layer (may be nullptr).

Definition at line 212 of file Layer.cpp.

References Layer::GetInputSlots(), Layer::m_OutputHandlers, and WorkloadDataCollector::Push().

216 : Layer(numInputSlots, numOutputSlots, type, DataLayout::NCHW, name)
217 {
218 }
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
Definition: Layer.cpp:212

◆ Layer() [2/2]

Layer ( unsigned int  numInputSlots,
unsigned int  numOutputSlots,
LayerType  type,
DataLayout  layout,
const char *  name 
)

Definition at line 187 of file Layer.cpp.

References Layer::m_OutputHandlers.

192 : m_OutputHandlers(numOutputSlots)
193 , m_LayerName(name ? name : "")
194 , m_Type(type)
195 , m_BackendId()
196 , m_Guid(profiling::ProfilingService::Instance().NextGuid())
197 {
198  boost::ignore_unused(layout);
199  m_InputSlots.reserve(numInputSlots);
200  for (unsigned int i = 0; i < numInputSlots; ++i)
201  {
202  m_InputSlots.emplace_back(*this, i);
203  }
204 
205  m_OutputSlots.reserve(numOutputSlots);
206  for (unsigned int i = 0; i < numOutputSlots; ++i)
207  {
208  m_OutputSlots.emplace_back(*this, m_OutputHandlers[i]);
209  }
210 }
static ProfilingService & Instance()
std::vector< OutputHandler > m_OutputHandlers
Definition: Layer.hpp:364

◆ ~Layer()

virtual ~Layer ( )
protectedvirtualdefault

Member Function Documentation

◆ AddRelatedLayerName()

void AddRelatedLayerName ( const std::string  layerName)
inline

Definition at line 318 of file Layer.hpp.

318 { m_RelatedLayerNames.emplace_back(layerName); }

◆ BeginInputSlots()

std::vector<InputSlot>::iterator BeginInputSlots ( )
inline

Definition at line 235 of file Layer.hpp.

Referenced by armnn::InsertConvertFp16ToFp32LayersBefore(), ConvertFp32NetworkToFp16Impl::Run(), and MovePermuteUpImpl::Run().

235 { return m_InputSlots.begin(); }

◆ BeginOutputSlots()

std::vector<OutputSlot>::iterator BeginOutputSlots ( )
inline

Definition at line 239 of file Layer.hpp.

Referenced by Graph::Graph(), armnn::InsertDebugLayerAfter(), ConvertFp32NetworkToFp16Impl::Run(), and SquashEqualSiblingsImpl< Comparable >::Run().

239 { return m_OutputSlots.begin(); }

◆ Clone()

◆ CloneBase()

LayerType * CloneBase ( Graph graph,
Params &&...  params 
) const
protected

Definition at line 14 of file LayerCloneBase.hpp.

References Graph::AddLayer(), Layer::GetBackendId(), and Layer::GetGuid().

15 {
16  LayerType* const layer = graph.AddLayer<LayerType>(std::forward<Params>(params)...);
17 
18  layer->SetBackendId(GetBackendId());
19  layer->SetGuid(GetGuid());
20 
21  return layer;
22 }
LayerGuid GetGuid() const final
Definition: Layer.hpp:316
const BackendId & GetBackendId() const
Definition: Layer.hpp:263

◆ CollectQueueDescriptorInputs()

void CollectQueueDescriptorInputs ( QueueDescriptor descriptor,
WorkloadInfo info 
) const
inlineprotected

Definition at line 329 of file Layer.hpp.

References QueueDescriptor::m_Inputs, and WorkloadInfo::m_InputTensorInfos.

330  {
331  WorkloadDataCollector dataCollector(descriptor.m_Inputs, info.m_InputTensorInfos);
332  CollectWorkloadInputs(dataCollector);
333  }

◆ CollectQueueDescriptorOutputs()

void CollectQueueDescriptorOutputs ( QueueDescriptor descriptor,
WorkloadInfo info 
) const
inlineprotected

Definition at line 336 of file Layer.hpp.

References QueueDescriptor::m_Outputs, and WorkloadInfo::m_OutputTensorInfos.

337  {
338  WorkloadDataCollector dataCollector(descriptor.m_Outputs, info.m_OutputTensorInfos);
339  CollectWorkloadOutputs(dataCollector);
340  }

◆ CreateTensorHandles()

void CreateTensorHandles ( const TensorHandleFactoryRegistry registry,
const IWorkloadFactory factory,
const bool  IsMemoryManaged = true 
)
virtual

Reimplemented in SplitterLayer, ConcatLayer, and OutputLayer.

Definition at line 239 of file Layer.cpp.

References OutputHandler::CreateTensorHandles(), TensorHandleFactoryRegistry::GetFactory(), Layer::GetNumOutputSlots(), Layer::GetOutputHandler(), Layer::GetOutputSlot(), OutputSlot::GetTensorHandleFactoryId(), and ITensorHandleFactory::LegacyFactoryId.

242 {
243  for (unsigned int idx=0; idx < GetNumOutputSlots(); idx++)
244  {
245 
246  OutputSlot& slot = GetOutputSlot(idx);
247  ITensorHandleFactory::FactoryId factoryId = slot.GetTensorHandleFactoryId();
248 
249  OutputHandler& handler = GetOutputHandler(idx);
250  if (factoryId == ITensorHandleFactory::LegacyFactoryId)
251  {
252  handler.CreateTensorHandles(workloadFactory, IsMemoryManaged);
253  }
254  else
255  {
256  ITensorHandleFactory* handleFactory = registry.GetFactory(factoryId);
257  BOOST_ASSERT(handleFactory);
258  handler.CreateTensorHandles(*handleFactory, IsMemoryManaged);
259  }
260  }
261 }
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Definition: Layer.hpp:221
unsigned int GetNumOutputSlots() const override
Definition: Layer.hpp:308
static const FactoryId LegacyFactoryId
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Definition: Layer.hpp:312

◆ CreateWorkload()

◆ EndInputSlots()

std::vector<InputSlot>::iterator EndInputSlots ( )
inline

Definition at line 236 of file Layer.hpp.

Referenced by armnn::InsertConvertFp16ToFp32LayersBefore(), ConvertFp32NetworkToFp16Impl::Run(), and MovePermuteUpImpl::Run().

236 { return m_InputSlots.end(); }

◆ EndOutputSlots()

std::vector<OutputSlot>::iterator EndOutputSlots ( )
inline

Definition at line 240 of file Layer.hpp.

Referenced by armnn::InsertDebugLayerAfter(), and ConvertFp32NetworkToFp16Impl::Run().

240 { return m_OutputSlots.end(); }

◆ GetBackendId()

◆ GetConstantTensorsByRef()

virtual ConstantTensors GetConstantTensorsByRef ( )
inlineprotectedvirtual

Reimplemented in LstmLayer, QuantizedLstmLayer, Convolution2dLayer, DepthwiseConvolution2dLayer, FullyConnectedLayer, TransposeConvolution2dLayer, BatchNormalizationLayer, ConstantLayer, and DetectionPostProcessLayer.

Definition at line 357 of file Layer.hpp.

357 {return ConstantTensors(); };
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
Definition: Layer.hpp:356

◆ GetDataType()

DataType GetDataType ( ) const

Definition at line 272 of file Layer.cpp.

References InputSlot::GetConnection(), TensorInfo::GetDataType(), Layer::GetInputSlot(), Layer::GetNumInputSlots(), Layer::GetOutputSlot(), IOutputSlot::GetTensorInfo(), and OutputSlot::GetTensorInfo().

Referenced by BOOST_AUTO_TEST_CASE(), ConvertFp32NetworkToFp16Impl::Run(), IsFloat32Layer::Test(), and IsFloat16Layer::Test().

273 {
274  if (GetNumInputSlots() > 0) // Ignore the input layer.
275  {
277  }
279 }
virtual const TensorInfo & GetTensorInfo() const =0
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
DataType GetDataType() const
Definition: Tensor.hpp:95
unsigned int GetNumInputSlots() const override
Definition: Layer.hpp:307
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Definition: Layer.hpp:312
const InputSlot & GetInputSlot(unsigned int index) const override
Definition: Layer.hpp:310

◆ GetGuid()

LayerGuid GetGuid ( ) const
inlinefinalvirtual

◆ GetInputSlot() [1/2]

const InputSlot& GetInputSlot ( unsigned int  index) const
inlineoverridevirtual

Implements IConnectableLayer.

Definition at line 310 of file Layer.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), CreateConvolution2dGraph(), CreateDepthwiseConvolution2dGraph(), CreateGatherGraph(), CreatePooling2dGraph(), CreateResizeBilinearGraph(), ConcatLayer::CreateWorkload(), DebugLayer::CreateWorkload(), Layer::GetDataType(), Graph::Graph(), InputSlot::Insert(), armnn::InsertConvertFp16ToFp32LayersBefore(), armnn::InsertConvertFp32ToFp16LayersAfter(), armnn::InsertDebugLayerAfter(), IWorkloadFactory::IsLayerSupported(), PermuteAsReshapeImpl::Run(), FoldPadIntoConvolution2dImpl::Run(), OptimizeConsecutiveReshapesImpl::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl::Run(), OptimizeInverseConversionsImpl::Run(), OptimizeInversePermutesImpl::Run(), MovePermuteUpImpl::Run(), DepthwiseConvolution2dLayer::SerializeLayerParameters(), Convolution2dLayer::SerializeLayerParameters(), ElementwiseBaseLayer::ValidateTensorShapesFromInputs(), QuantizeLayer::ValidateTensorShapesFromInputs(), ActivationLayer::ValidateTensorShapesFromInputs(), SliceLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), ConcatLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), OutputLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), LstmLayer::ValidateTensorShapesFromInputs(), and Layer::VerifyLayerConnections().

310 { return m_InputSlots.at(index); }

◆ GetInputSlot() [2/2]

InputSlot& GetInputSlot ( unsigned int  index)
inlineoverridevirtual

Implements IConnectableLayer.

Definition at line 311 of file Layer.hpp.

311 { return m_InputSlots.at(index); }

◆ GetInputSlots()

const std::vector<InputSlot>& GetInputSlots ( ) const
inline

◆ GetName()

const char* GetName ( ) const
inlineoverridevirtual

Implements IConnectableLayer.

Definition at line 305 of file Layer.hpp.

Referenced by AdditionLayer::Accept(), QuantizeLayer::Accept(), MultiplicationLayer::Accept(), DivisionLayer::Accept(), MaximumLayer::Accept(), SubtractionLayer::Accept(), MinimumLayer::Accept(), ActivationLayer::Accept(), AbsLayer::Accept(), NormalizationLayer::Accept(), FloorLayer::Accept(), InputLayer::Accept(), InstanceNormalizationLayer::Accept(), RsqrtLayer::Accept(), SoftmaxLayer::Accept(), L2NormalizationLayer::Accept(), SwitchLayer::Accept(), DequantizeLayer::Accept(), PadLayer::Accept(), GatherLayer::Accept(), LogSoftmaxLayer::Accept(), MeanLayer::Accept(), MergeLayer::Accept(), ArgMinMaxLayer::Accept(), DetectionPostProcessLayer::Accept(), Pooling2dLayer::Accept(), ElementwiseUnaryLayer::Accept(), ResizeLayer::Accept(), SliceLayer::Accept(), BatchToSpaceNdLayer::Accept(), StackLayer::Accept(), StridedSliceLayer::Accept(), PreluLayer::Accept(), SpaceToBatchNdLayer::Accept(), SpaceToDepthLayer::Accept(), DepthToSpaceLayer::Accept(), ComparisonLayer::Accept(), StandInLayer::Accept(), ConstantLayer::Accept(), BatchNormalizationLayer::Accept(), OutputLayer::Accept(), TransposeConvolution2dLayer::Accept(), FullyConnectedLayer::Accept(), DepthwiseConvolution2dLayer::Accept(), Convolution2dLayer::Accept(), ConcatLayer::Accept(), ReshapeLayer::Accept(), SplitterLayer::Accept(), PermuteLayer::Accept(), QuantizedLstmLayer::Accept(), LstmLayer::Accept(), Graph::AddCompatibilityLayers(), BOOST_AUTO_TEST_CASE(), armnnTfParser::CalcPadding(), QuantizeLayer::Clone(), ActivationLayer::Clone(), ConvertFp32ToFp16Layer::Clone(), RsqrtLayer::Clone(), DequantizeLayer::Clone(), NormalizationLayer::Clone(), PermuteLayer::Clone(), Pooling2dLayer::Clone(), FakeQuantizationLayer::Clone(), L2NormalizationLayer::Clone(), FloorLayer::Clone(), AbsLayer::Clone(), ReshapeLayer::Clone(), ResizeLayer::Clone(), MemImportLayer::Clone(), SwitchLayer::Clone(), SliceLayer::Clone(), InputLayer::Clone(), InstanceNormalizationLayer::Clone(), BatchToSpaceNdLayer::Clone(), DebugLayer::Clone(), StridedSliceLayer::Clone(), AdditionLayer::Clone(), SoftmaxLayer::Clone(), MemCopyLayer::Clone(), StackLayer::Clone(), MergeLayer::Clone(), MultiplicationLayer::Clone(), StandInLayer::Clone(), ArgMinMaxLayer::Clone(), PadLayer::Clone(), SpaceToDepthLayer::Clone(), DepthToSpaceLayer::Clone(), SpaceToBatchNdLayer::Clone(), DivisionLayer::Clone(), SubtractionLayer::Clone(), ElementwiseUnaryLayer::Clone(), MaximumLayer::Clone(), ConvertFp16ToFp32Layer::Clone(), LogSoftmaxLayer::Clone(), GatherLayer::Clone(), PreluLayer::Clone(), MeanLayer::Clone(), ComparisonLayer::Clone(), MinimumLayer::Clone(), ConstantLayer::Clone(), DetectionPostProcessLayer::Clone(), PreCompiledLayer::Clone(), TransposeConvolution2dLayer::Clone(), DepthwiseConvolution2dLayer::Clone(), FullyConnectedLayer::Clone(), Convolution2dLayer::Clone(), ConcatLayer::Clone(), SplitterLayer::Clone(), BatchNormalizationLayer::Clone(), OutputLayer::Clone(), QuantizedLstmLayer::Clone(), LstmLayer::Clone(), armnn::InsertConvertFp16ToFp32LayersBefore(), armnn::InsertConvertFp32ToFp16LayersAfter(), PermuteAsReshapeImpl::Run(), FoldPadIntoConvolution2dImpl::Run(), OptimizeConsecutiveReshapesImpl::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl::Run(), and ErasedLayerNamesObservable::Update().

305 { return m_LayerName.c_str(); }

◆ GetNameStr()

◆ GetNumInputSlots()

◆ GetNumOutputSlots()

◆ GetOutputHandler() [1/2]

◆ GetOutputHandler() [2/2]

OutputHandler& GetOutputHandler ( unsigned int  i = 0)
inline

Definition at line 226 of file Layer.hpp.

227  {
228  return const_cast<OutputHandler&>(const_cast<const Layer*>(this)->GetOutputHandler(i));
229  }
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Definition: Layer.hpp:221
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
Definition: Layer.cpp:212

◆ GetOutputSlot() [1/2]

const OutputSlot& GetOutputSlot ( unsigned int  index = 0) const
inlineoverridevirtual

Implements IConnectableLayer.

Definition at line 312 of file Layer.hpp.

Referenced by Graph::AddCompatibilityLayers(), BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), armnnTfParser::CalcPadding(), OutputSlot::CalculateIndexOnOwner(), armnn::CheckScaleSetOnQuantizedType(), CreateConvolution2dGraph(), CreateDepthwiseConvolution2dGraph(), CreateGatherGraph(), CreatePooling2dGraph(), CreateResizeBilinearGraph(), ConcatLayer::CreateTensorHandles(), SplitterLayer::CreateTensorHandles(), Layer::CreateTensorHandles(), SplitterLayer::CreateWorkload(), ConcatLayer::CreateWorkload(), Layer::GetDataType(), InputSlot::Insert(), armnn::InsertConvertFp16ToFp32LayersBefore(), armnn::InsertConvertFp32ToFp16LayersAfter(), armnn::InsertDebugLayerAfter(), IsConnected(), IWorkloadFactory::IsLayerSupported(), PermuteAsReshapeImpl::Run(), OptimizeConsecutiveReshapesImpl::Run(), FoldPadIntoConvolution2dImpl::Run(), PermuteAndBatchToSpaceAsDepthToSpaceImpl::Run(), OptimizeInverseConversionsImpl::Run(), OptimizeInversePermutesImpl::Run(), MovePermuteUpImpl::Run(), armnn::SelectTensorHandleStrategy(), ElementwiseBaseLayer::ValidateTensorShapesFromInputs(), QuantizeLayer::ValidateTensorShapesFromInputs(), ActivationLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), ReshapeLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), SliceLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), InputLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), ConstantLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), DetectionPostProcessLayer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), SplitterLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), and LstmLayer::ValidateTensorShapesFromInputs().

312 { return m_OutputSlots.at(index); }

◆ GetOutputSlot() [2/2]

OutputSlot& GetOutputSlot ( unsigned int  index = 0)
inlineoverridevirtual

Implements IConnectableLayer.

Definition at line 313 of file Layer.hpp.

313 { return m_OutputSlots.at(index); }

◆ GetOutputSlots()

const std::vector<OutputSlot>& GetOutputSlots ( ) const
inline

Definition at line 232 of file Layer.hpp.

Referenced by Graph::AddCompatibilityLayers(), armnn::ForEachLayerOutput(), and IWorkloadFactory::IsLayerSupported().

232 { return m_OutputSlots; }

◆ GetPriority()

LayerPriority GetPriority ( ) const

Definition at line 287 of file Layer.cpp.

References Layer::GetInputSlots(), OutputSlot::GetOwningLayer(), Layer::GetPriority(), Layer::GetType(), armnn::Input, and armnn::Output.

Referenced by Layer::GetPriority(), and SquashEqualSiblingsImpl< Comparable >::Run().

288 {
289  constexpr LayerPriority inputPrio = std::numeric_limits<LayerPriority>::lowest();
290  constexpr LayerPriority outputPrio = std::numeric_limits<LayerPriority>::max();
291 
292  if (GetType() == LayerType::Input)
293  {
294  m_Priority = inputPrio;
295  }
296  else if (GetType() == LayerType::Output)
297  {
298  m_Priority = outputPrio;
299  }
300  else if (m_Priority == 0)
301  {
302  if (m_Visiting)
303  {
304  throw GraphValidationException("Graph has circular dependencies: cannot walk");
305  }
306 
307  auto maxPrio = [](const LayerPriority prio, const InputSlot& slot) -> LayerPriority
308  {
309  const OutputSlot *outputSlot = slot.GetConnectedOutputSlot();
310  if (outputSlot)
311  {
312  const Layer& input = outputSlot->GetOwningLayer();
313  return std::max(prio, input.GetPriority());
314  }
315  else
316  {
317  // unconnected input slot
318  return prio;
319  }
320  };
321 
322  m_Visiting = true;
323  LayerPriority parentPrio = std::accumulate(GetInputSlots().cbegin(), GetInputSlots().cend(), 0U, maxPrio);
324  m_Visiting = false;
325 
326  if (parentPrio >= outputPrio)
327  {
328  throw GraphValidationException("Graph has too many edges");
329  }
330 
331  m_Priority = parentPrio + 1U;
332  }
333 
334  return m_Priority;
335 }
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
Definition: Layer.cpp:212
LayerType GetType() const
Definition: Layer.hpp:259
unsigned int LayerPriority
Definition: Layer.hpp:207
const std::vector< InputSlot > & GetInputSlots() const
Definition: Layer.hpp:231

◆ GetRelatedLayerNames()

const std::list<std::string>& GetRelatedLayerNames ( )
inline

Definition at line 320 of file Layer.hpp.

Referenced by ErasedLayerNamesObservable::Update().

320 { return m_RelatedLayerNames; }

◆ GetType()

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > &  inputShapes) const
overridevirtual

Implements IConnectableLayer.

Reimplemented in LstmLayer, QuantizedLstmLayer, SplitterLayer, ConcatLayer, Convolution2dLayer, DepthwiseConvolution2dLayer, FullyConnectedLayer, TransposeConvolution2dLayer, ConstantLayer, StandInLayer, BatchToSpaceNdLayer, PermuteLayer, Pooling2dLayer, ReshapeLayer, ResizeLayer, SliceLayer, StackLayer, MergeLayer, ComparisonLayer, DepthToSpaceLayer, PreluLayer, SpaceToBatchNdLayer, SpaceToDepthLayer, ArgMinMaxLayer, ElementwiseUnaryLayer, StridedSliceLayer, and ElementwiseBaseLayer.

Definition at line 370 of file Layer.cpp.

References CHECK_LOCATION, armnn::GetLayerTypeAsCString(), Layer::GetNameStr(), Layer::GetNumInputSlots(), Layer::GetNumOutputSlots(), and Layer::GetType().

Referenced by QuantizeLayer::ValidateTensorShapesFromInputs(), ActivationLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), and BatchNormalizationLayer::ValidateTensorShapesFromInputs().

371 {
372  BOOST_ASSERT(GetNumInputSlots() != 0);
373  BOOST_ASSERT(GetNumOutputSlots() != 0);
374 
375  // By default we return what we got, meaning the output shape(s) are the same as the input(s).
376  // This only works if the number of inputs and outputs are the same. Since we are in the Layer
377  // base class, this means the implementation needs to be overridden in the specific layers for
378  // the other cases. So the missing implementation justifies the UnimplementedException.
379 
381  {
382  throw UnimplementedException(
383  boost::str(
384  boost::format(
385  "Default implementation for InferOutputShapes can only be used for "
386  "layers with the same number of input and output slots. This doesn't "
387  "hold for %1% layer %2% (#inputs=%3% #outputs=%4%) %5%")
388  % GetLayerTypeAsCString(this->GetType())
389  % GetNameStr()
390  % GetNumInputSlots()
392  % CHECK_LOCATION().AsString()));
393  }
394  return inputShapes;
395 }
unsigned int GetNumOutputSlots() const override
Definition: Layer.hpp:308
LayerType GetType() const
Definition: Layer.hpp:259
char const * GetLayerTypeAsCString(LayerType type)
const std::string & GetNameStr() const
Definition: Layer.hpp:216
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
unsigned int GetNumInputSlots() const override
Definition: Layer.hpp:307

◆ IsOutputUnconnected()

bool IsOutputUnconnected ( )
inline

Definition at line 243 of file Layer.hpp.

Referenced by OptimizeForConnectionImpl< BaseType, ChildType, Wrapped >::Run().

244  {
245  unsigned int numConnections = 0;
246 
247  for (auto&& output : GetOutputSlots())
248  {
249  numConnections += output.GetNumConnections();
250  }
251 
252  return (GetNumOutputSlots() > 0) && (numConnections == 0);
253  }
unsigned int GetNumOutputSlots() const override
Definition: Layer.hpp:308
const std::vector< OutputSlot > & GetOutputSlots() const
Definition: Layer.hpp:232

◆ OperateOnConstantTensors()

void OperateOnConstantTensors ( Op  op)
inline

Definition at line 292 of file Layer.hpp.

Referenced by Layer::ReleaseConstantData(), and ConvertConstants< Converter, Predicate >::Run().

293  {
294  for (auto constant : GetConstantTensorsByRef())
295  {
296  if (constant.get())
297  {
298  op(constant);
299  }
300  }
301  };
virtual ConstantTensors GetConstantTensorsByRef()
Definition: Layer.hpp:357

◆ PrepInfoAndDesc()

WorkloadInfo PrepInfoAndDesc ( QueueDescriptor descriptor) const
inlineprotected

◆ ReleaseConstantData()

void ReleaseConstantData ( )
virtual

Reimplemented in ConstantLayer.

Definition at line 263 of file Layer.cpp.

References Layer::OperateOnConstantTensors().

Referenced by BOOST_AUTO_TEST_CASE().

264 {
265  // Now free up the static data.
266  OperateOnConstantTensors([](std::unique_ptr<ScopedCpuTensorHandle>& handle)
267  {
268  handle.reset(nullptr);
269  });
270 }
void OperateOnConstantTensors(Op op)
Definition: Layer.hpp:292

◆ Reparent()

virtual void Reparent ( Graph dest,
std::list< Layer *>::const_iterator  iterator 
)
pure virtual

◆ ResetPriority()

void ResetPriority ( ) const

Definition at line 281 of file Layer.cpp.

282 {
283  m_Priority = 0;
284  m_Visiting = false;
285 }

◆ SerializeLayerParameters()

void SerializeLayerParameters ( ParameterStringifyFunction fn) const
virtual

Helper to serialize the layer parameters to string. (currently used in DotSerializer and company).

Reimplemented in Convolution2dLayer, DepthwiseConvolution2dLayer, LayerWithParameters< Parameters >, LayerWithParameters< FakeQuantizationDescriptor >, LayerWithParameters< SoftmaxDescriptor >, LayerWithParameters< LstmDescriptor >, LayerWithParameters< LogSoftmaxDescriptor >, LayerWithParameters< PreCompiledDescriptor >, LayerWithParameters< BatchToSpaceNdDescriptor >, LayerWithParameters< PermuteDescriptor >, LayerWithParameters< SpaceToBatchNdDescriptor >, LayerWithParameters< DepthToSpaceDescriptor >, LayerWithParameters< ReshapeDescriptor >, LayerWithParameters< ElementwiseUnaryDescriptor >, LayerWithParameters< SpaceToDepthDescriptor >, LayerWithParameters< OriginsDescriptor >, LayerWithParameters< ViewsDescriptor >, LayerWithParameters< Pooling2dDescriptor >, LayerWithParameters< Convolution2dDescriptor >, LayerWithParameters< ActivationDescriptor >, LayerWithParameters< StandInDescriptor >, LayerWithParameters< StackDescriptor >, LayerWithParameters< MeanDescriptor >, LayerWithParameters< ComparisonDescriptor >, LayerWithParameters< InstanceNormalizationDescriptor >, LayerWithParameters< TransposeConvolution2dDescriptor >, LayerWithParameters< BatchNormalizationDescriptor >, LayerWithParameters< ArgMinMaxDescriptor >, LayerWithParameters< DetectionPostProcessDescriptor >, LayerWithParameters< PadDescriptor >, LayerWithParameters< L2NormalizationDescriptor >, LayerWithParameters< SliceDescriptor >, LayerWithParameters< DepthwiseConvolution2dDescriptor >, LayerWithParameters< NormalizationDescriptor >, LayerWithParameters< FullyConnectedDescriptor >, LayerWithParameters< StridedSliceDescriptor >, and LayerWithParameters< ResizeDescriptor >.

Definition at line 397 of file Layer.cpp.

References armnn::GetLayerTypeAsCString().

Referenced by LayerWithParameters< ResizeDescriptor >::SerializeLayerParameters().

398 {
399  std::string layerType = GetLayerTypeAsCString(m_Type);
400  std::string backendId = std::string(m_BackendId);
401  if(!(m_LayerName.compare("") == 0) && !m_LayerName.empty())
402  {
403  fn("LayerName",m_LayerName);
404  }
405  if(!(layerType.compare("") == 0) && !layerType.empty())
406  {
407  fn("LayerType",layerType);
408  }
409  if(!(backendId.compare("") == 0) && !backendId.empty())
410  {
411  fn("BackendID",backendId);
412  }
413 }
char const * GetLayerTypeAsCString(LayerType type)

◆ SetBackendId()

void SetBackendId ( const BackendId id)
inline

◆ SetGuid()

void SetGuid ( LayerGuid  guid)
inline

Definition at line 315 of file Layer.hpp.

315 { m_Guid = guid; }

◆ ValidateTensorShapesFromInputs()

◆ VerifyLayerConnections()

void VerifyLayerConnections ( unsigned int  expectedConnections,
const CheckLocation location 
) const

Definition at line 337 of file Layer.cpp.

References CheckLocation::AsString(), Layer::GetInputSlot(), armnn::GetLayerTypeAsCString(), Layer::GetNameStr(), Layer::GetNumInputSlots(), and Layer::GetType().

Referenced by ElementwiseBaseLayer::ValidateTensorShapesFromInputs(), QuantizeLayer::ValidateTensorShapesFromInputs(), ActivationLayer::ValidateTensorShapesFromInputs(), SwitchLayer::ValidateTensorShapesFromInputs(), AbsLayer::ValidateTensorShapesFromInputs(), Pooling2dLayer::ValidateTensorShapesFromInputs(), ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs(), FakeQuantizationLayer::ValidateTensorShapesFromInputs(), SliceLayer::ValidateTensorShapesFromInputs(), ReshapeLayer::ValidateTensorShapesFromInputs(), ResizeLayer::ValidateTensorShapesFromInputs(), FloorLayer::ValidateTensorShapesFromInputs(), RsqrtLayer::ValidateTensorShapesFromInputs(), BatchToSpaceNdLayer::ValidateTensorShapesFromInputs(), SoftmaxLayer::ValidateTensorShapesFromInputs(), StackLayer::ValidateTensorShapesFromInputs(), PermuteLayer::ValidateTensorShapesFromInputs(), DebugLayer::ValidateTensorShapesFromInputs(), InstanceNormalizationLayer::ValidateTensorShapesFromInputs(), L2NormalizationLayer::ValidateTensorShapesFromInputs(), DequantizeLayer::ValidateTensorShapesFromInputs(), MemCopyLayer::ValidateTensorShapesFromInputs(), MemImportLayer::ValidateTensorShapesFromInputs(), MergeLayer::ValidateTensorShapesFromInputs(), NormalizationLayer::ValidateTensorShapesFromInputs(), ConvertFp16ToFp32Layer::ValidateTensorShapesFromInputs(), GatherLayer::ValidateTensorShapesFromInputs(), MeanLayer::ValidateTensorShapesFromInputs(), LogSoftmaxLayer::ValidateTensorShapesFromInputs(), StridedSliceLayer::ValidateTensorShapesFromInputs(), ElementwiseUnaryLayer::ValidateTensorShapesFromInputs(), ArgMinMaxLayer::ValidateTensorShapesFromInputs(), DetectionPostProcessLayer::ValidateTensorShapesFromInputs(), DepthwiseConvolution2dLayer::ValidateTensorShapesFromInputs(), SpaceToDepthLayer::ValidateTensorShapesFromInputs(), FullyConnectedLayer::ValidateTensorShapesFromInputs(), SpaceToBatchNdLayer::ValidateTensorShapesFromInputs(), TransposeConvolution2dLayer::ValidateTensorShapesFromInputs(), PreluLayer::ValidateTensorShapesFromInputs(), ComparisonLayer::ValidateTensorShapesFromInputs(), DepthToSpaceLayer::ValidateTensorShapesFromInputs(), Convolution2dLayer::ValidateTensorShapesFromInputs(), ConcatLayer::ValidateTensorShapesFromInputs(), BatchNormalizationLayer::ValidateTensorShapesFromInputs(), QuantizedLstmLayer::ValidateTensorShapesFromInputs(), and LstmLayer::ValidateTensorShapesFromInputs().

338 {
339  BOOST_ASSERT(GetNumInputSlots() == expectedConnections);
340 
341  for (unsigned int i=0; i<expectedConnections; ++i)
342  {
343  if (GetInputSlot(i).GetConnection() == nullptr)
344  {
345  throw LayerValidationException(
346  boost::str(
347  boost::format(
348  "Input connection #%1% must be connected "
349  "for %2% layer %3% %4%")
350  % i
351  % GetLayerTypeAsCString(this->GetType())
352  % GetNameStr()
353  % location.AsString()));
354  }
355  if(! GetInputSlot(i).GetConnection()->IsTensorInfoSet())
356  {
357  throw LayerValidationException(
358  boost::str(
359  boost::format(
360  "TensorInfo of Input connection #%1% must be set on connected OutputSlot for "
361  "%2% layer %3% %4%")
362  % i
363  % GetLayerTypeAsCString(this->GetType())
364  % GetNameStr()
365  % location.AsString()));
366  }
367  }
368 }
LayerType GetType() const
Definition: Layer.hpp:259
char const * GetLayerTypeAsCString(LayerType type)
const std::string & GetNameStr() const
Definition: Layer.hpp:216
unsigned int GetNumInputSlots() const override
Definition: Layer.hpp:307
const InputSlot & GetInputSlot(unsigned int index) const override
Definition: Layer.hpp:310

Friends And Related Function Documentation

◆ Graph

friend class Graph
friend

Definition at line 325 of file Layer.hpp.

Member Data Documentation

◆ m_OutputHandlers

std::vector<OutputHandler> m_OutputHandlers
protected

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