23.05
|
Go to the documentation of this file.
16 #include <client/include/IProfilingService.hpp>
18 #include <fmt/format.h>
26 NullDescriptor Layer::m_NullDescriptor;
54 if (prevSlot !=
nullptr)
77 ValidateConnectionIndex(index);
78 return m_Connections[index];
83 ValidateConnectionIndex(index);
84 return m_Connections[index];
115 m_Connections.push_back(&destination);
117 return armnn::numeric_cast<int>(m_Connections.size() - 1);
123 auto it = std::find(m_Connections.begin(), m_Connections.end(), &slot);
125 if (it == m_Connections.end())
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());
133 m_EdgeStrategies.erase(m_EdgeStrategies.begin() + idx);
150 "Cannot move connections once memory strategies have be established.");
154 destination.
Connect(connection);
187 void OutputSlot::ValidateConnectionIndex(
unsigned int index)
const
189 if (armnn::numeric_cast<std::size_t>(index) >= m_Connections.size())
202 m_TensorHandleFactoryId = id;
207 return m_TensorHandleFactoryId;
212 m_EdgeStrategies[connectionIndex] = strategy;
217 return m_EdgeStrategies[connectionIdx];
221 unsigned int numOutputSlots,
225 : m_OutputHandlers(numOutputSlots)
227 , m_LayerName(name ? name :
"")
231 , m_Guid(
arm::pipe::IProfilingService::GetNextGuid())
234 m_InputSlots.reserve(numInputSlots);
235 for (
unsigned int i = 0; i < numInputSlots; ++i)
237 m_InputSlots.emplace_back(*
this, i);
240 m_OutputSlots.reserve(numOutputSlots);
241 for (
unsigned int i = 0; i < numOutputSlots; ++i)
248 unsigned int numOutputSlots,
261 const OutputHandler& outputHandler = inputSlot.GetConnectedOutputSlot()->GetOutputHandler();
266 void Layer::CollectWorkloadOutputs(WorkloadDataCollector& dataCollector)
const
281 const bool IsMemoryManaged)
297 handleFactory = registry.
GetFactory(factoryId);
330 constexpr
LayerPriority inputPrio = std::numeric_limits<LayerPriority>::lowest();
331 constexpr
LayerPriority outputPrio = std::numeric_limits<LayerPriority>::max();
335 m_Priority = inputPrio;
339 m_Priority = outputPrio;
341 else if (m_Priority == 0)
350 const OutputSlot *outputSlot = slot.GetConnectedOutputSlot();
367 if (parentPrio >= outputPrio)
372 m_Priority = parentPrio + 1U;
382 for (
unsigned int i=0; i<expectedConnections; ++i)
387 fmt::format(
"Input connection #{0} must be connected "
388 "for {1} layer {2} {3}",
410 fmt::format(
"Default implementation for InferOutputShapes can only be used for "
411 "layers with the same number of input and output slots. This doesn't "
412 "hold for {0} layer {1} (#inputs={2} #outputs={3}) {4}",
425 const std::string& layerName,
426 const unsigned int outputSlotIndex)
430 if (m_AllowExpandedDims)
435 if (outputDims.size() != inferredDims.size())
437 std::stringstream ss;
438 ss << layerName <<
": TensorShape set on OutputSlot[" << outputSlotIndex <<
439 "] does not match the inferred shape. ";
440 ss << outputShape <<
" != " << inferredShape;
443 for (
unsigned int i = 0; i < outputDims.size(); ++i)
445 if (outputDims[i] != inferredDims[i])
447 std::stringstream ss;
448 ss << layerName <<
": TensorShape set on OutputSlot[" << outputSlotIndex <<
449 "] does not match the inferred shape at dimension index [";
450 ss << i <<
"] " << outputShape <<
" != " << inferredShape;
458 ConditionalThrowIfNotEqual<LayerValidationException>(
459 layerName +
": TensorShape set on OutputSlot[0] does not match the inferred shape.",
472 std::stringstream ss;
473 ss << layerName <<
": TensorShape set on OutputSlot[" << outputSlotIndex <<
474 "] does not match the inferred shape at dimension index [";
475 ss << i <<
"] " << outputShape <<
" != " << inferredShape;
485 info.GetQuantizationScale(),
486 info.GetQuantizationOffset());
495 ConditionalThrow<LayerValidationException>(
497 "Dimensionality can not be NotSpecified while using ShapeInferenceMethod::ValidateOnly");
499 ConditionalThrow<LayerValidationException>(
501 "Unspecified dimension while using ShapeInferenceMethod::ValidateOnly");
507 std::string guid = std::to_string(m_Guid);
509 std::string backendId = std::string(m_BackendId);
510 if (!(guid.compare(
"") == 0) && !guid.empty())
514 if(!(m_LayerName.compare(
"") == 0) && !m_LayerName.empty())
516 fn(
"LayerName",m_LayerName);
518 if(!(layerType.compare(
"") == 0) && !layerType.empty())
520 fn(
"LayerType",layerType);
522 if(!(backendId.compare(
"") == 0) && !backendId.empty())
524 fn(
"BackendID",backendId);
526 std::shared_ptr<ActivationDescriptor>
527 activationDescPtr = GetAdditionalInformation<ActivationDescriptor>();
529 if (activationDescPtr)
543 const Layer *constThis =
const_cast<const Layer*
>(
this);
547 for (
auto i : immutableData)
549 res.push_back(
const_cast<std::shared_ptr<ConstTensorHandle>&
>(i.get()));
556 return m_OwningLayer;
561 return m_OwningLayer;
566 return m_OwningLayer;
571 return m_OwningLayer;
void * m_AdditionalInfoObject
const IConnectableLayer & GetOwningIConnectableLayer() const override
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Dimensionality GetDimensionality() const
Function that returns the tensor type.
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.
static const FactoryId LegacyFactoryId
virtual void ReleaseConstantData()
@ ValidateOnly
Validate all output shapes.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
void SetTensorInfo(const TensorInfo &tensorInfo) override
bool IsTensorInfoSet() const override
void IgnoreUnused(Ts &&...)
void AssertNumberOfInputSlots(Layer &layer)
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > >> ConstantTensors
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
unsigned int LayerPriority
const OutputHandler & GetOutputHandler() const
virtual ConstantTensors GetConstantTensorsByRef() override final
bool operator==(const OutputSlot &other) const
ITensorHandle * GetData() const
Gets the allocated tensor memory.
void SetAdditionalInfo(QueueDescriptor &descriptor) const
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
Copyright (c) 2021 ARM Limited and Contributors.
const TensorInfo & GetTensorInfo() const override
bool ValidateTensorShape(const TensorShape &shape) const
std::string AsString() const
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
void Push(ITensorHandle *handle, const TensorInfo &info)
const std::string & GetNameStr() const
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
virtual const TensorInfo & GetTensorInfo() const =0
void ResetPriority() const
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
AdditionalInfoObjectPtr m_AdditionalInfoObject
virtual void ValidateTensorShapesFromInputs()=0
bool GetDimensionSpecificity(unsigned int i) const
Gets information about if the dimension size has been specified or not.
const OutputHandler & GetOutputHandler(unsigned int i=0) const
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
const InputSlot * GetConnection(unsigned int index) const override
unsigned int CalculateIndexOnOwner() const override
void SetTensorInfo(const TensorInfo &tensorInfo)
Sets the TensorInfo used by this output handler.
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
std::vector< unsigned int > SqueezeDims(const armnn::TensorShape &tensorShape)
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Layer & GetOwningLayer() const
const TensorShape & GetShape() const
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
std::vector< OutputHandler > m_OutputHandlers
const std::vector< InputSlot > & GetInputSlots() const
#define ARMNN_ASSERT_MSG(COND, MSG)
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
DataType GetDataType() const
void CreateTensorHandles(const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
Creates tensor handles used by the intermediate tensors.
Base class for all descriptors.
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
LayerGuid GetGuid() const final
Returns the unique id of the layer.
int Connect(InputSlot &destination)
void CollectWorkloadOutputs(WorkloadDataCollector &dataCollector) const
Fill the outputs for a given queue descriptor.
#define ARMNN_ASSERT(COND)
LayerGuid GetOwningLayerGuid() const override
unsigned int GetNumConnections() const override
void OperateOnConstantTensors(Op op)
LayerPriority GetPriority() const
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
const char * GetName() const override
Returns the name of the layer.
bool IsTensorInfoSet() const
Returns true if SetTensorInfo() has been called at least once on this.
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
void Disconnect(InputSlot &slot)
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > >> ImmutableConstantTensors
DataType GetDataType() const
bool AreAllDimensionsSpecified() const
Checks if there is at least one dimension not specified.
const char * GetLayerTypeAsCString(LayerType type)
@ InferAndValidate
Infer missing output shapes and validate all output shapes.
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Infer the shape of the output(s) based on the provided input shape(s)