24.02
|
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();
263 if (inputSlot.IsTensorInfoOverridden() && outputHandler.
GetData())
270 dataCollector.
Push(handler.get(), inputSlot.GetTensorInfo());
275 dataCollector.
Push(outputHandler.
GetData(), inputSlot.GetTensorInfo());
279 void Layer::CollectWorkloadOutputs(WorkloadDataCollector& dataCollector)
const
294 const bool IsMemoryManaged)
310 handleFactory = registry.
GetFactory(factoryId);
343 constexpr
LayerPriority inputPrio = std::numeric_limits<LayerPriority>::lowest();
344 constexpr
LayerPriority outputPrio = std::numeric_limits<LayerPriority>::max();
348 m_Priority = inputPrio;
352 m_Priority = outputPrio;
354 else if (m_Priority == 0)
363 const OutputSlot *outputSlot = slot.GetConnectedOutputSlot();
380 if (parentPrio >= outputPrio)
385 m_Priority = parentPrio + 1U;
395 for (
unsigned int i=0; i<expectedConnections; ++i)
400 fmt::format(
"Input connection #{0} must be connected "
401 "for {1} layer {2} {3}",
423 fmt::format(
"Default implementation for InferOutputShapes can only be used for "
424 "layers with the same number of input and output slots. This doesn't "
425 "hold for {0} layer {1} (#inputs={2} #outputs={3}) {4}",
438 const std::string& layerName,
439 const unsigned int outputSlotIndex)
443 if (m_AllowExpandedDims)
448 if (outputDims.size() != inferredDims.size())
450 std::stringstream ss;
451 ss << layerName <<
": TensorShape set on OutputSlot[" << outputSlotIndex <<
452 "] does not match the inferred shape. ";
453 ss << outputShape <<
" != " << inferredShape;
456 for (
unsigned int i = 0; i < outputDims.size(); ++i)
458 if (outputDims[i] != inferredDims[i])
460 std::stringstream ss;
461 ss << layerName <<
": TensorShape set on OutputSlot[" << outputSlotIndex <<
462 "] does not match the inferred shape at dimension index [";
463 ss << i <<
"] " << outputShape <<
" != " << inferredShape;
471 ConditionalThrowIfNotEqual<LayerValidationException>(
472 layerName +
": TensorShape set on OutputSlot[0] does not match the inferred shape.",
485 std::stringstream ss;
486 ss << layerName <<
": TensorShape set on OutputSlot[" << outputSlotIndex <<
487 "] does not match the inferred shape at dimension index [";
488 ss << i <<
"] " << outputShape <<
" != " << inferredShape;
498 info.GetQuantizationScale(),
499 info.GetQuantizationOffset());
508 ConditionalThrow<LayerValidationException>(
510 "Dimensionality can not be NotSpecified while using ShapeInferenceMethod::ValidateOnly");
512 ConditionalThrow<LayerValidationException>(
514 "Unspecified dimension while using ShapeInferenceMethod::ValidateOnly");
520 std::string guid = std::to_string(m_Guid);
522 std::string backendId = std::string(m_BackendId);
523 if (!(guid.compare(
"") == 0) && !guid.empty())
527 if(!(m_LayerName.compare(
"") == 0) && !m_LayerName.empty())
529 fn(
"LayerName",m_LayerName);
531 if(!(layerType.compare(
"") == 0) && !layerType.empty())
533 fn(
"LayerType",layerType);
535 if(!(backendId.compare(
"") == 0) && !backendId.empty())
537 fn(
"BackendID",backendId);
539 std::shared_ptr<ActivationDescriptor>
540 activationDescPtr = GetAdditionalInformation<ActivationDescriptor>();
542 if (activationDescPtr)
556 const Layer *constThis =
const_cast<const Layer*
>(
this);
560 for (
auto i : immutableData)
562 res.push_back(
const_cast<std::shared_ptr<ConstTensorHandle>&
>(i.get()));
569 return m_OwningLayer;
574 return m_OwningLayer;
579 return m_OwningLayer;
584 return m_OwningLayer;
594 if (m_OverriddenTensorInfo.has_value())
596 return m_OverriddenTensorInfo.value();
611 return m_OverriddenTensorInfo.has_value();
#define ARMNN_ASSERT(COND)
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
bool operator==(const OutputSlot &other) const
const char * GetLayerTypeAsCString(LayerType type)
const TensorInfo & GetTensorInfo() const override
std::vector< unsigned int > SqueezeDims(const armnn::TensorShape &tensorShape)
bool ValidateTensorShape(const TensorShape &shape) const
const OutputHandler & GetOutputHandler() const
void OperateOnConstantTensors(Op op)
AdditionalInfoObjectPtr m_AdditionalInfoObject
void SetTensorInfo(const TensorInfo &tensorInfo) override
bool GetDimensionSpecificity(unsigned int i) const
Gets information about if the dimension size has been specified or not.
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
unsigned int LayerPriority
void SetTensorInfo(const TensorInfo &tensorInfo)
Sets the TensorInfo used by this output handler.
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > >> ConstantTensors
bool AreAllDimensionsSpecified() const
Checks if there is at least one dimension not specified.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
std::vector< OutputHandler > m_OutputHandlers
void CreateTensorHandles(const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
Creates tensor handles used by the intermediate tensors.
virtual ConstantTensors GetConstantTensorsByRef() override final
const IConnectableLayer & GetOwningIConnectableLayer() const override
virtual const TensorInfo & GetTensorInfo() const =0
const std::vector< InputSlot > & GetInputSlots() const
int Connect(InputSlot &destination)
#define ARMNN_ASSERT_MSG(COND, MSG)
std::string AsString() const
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
bool IsTensorInfoSet() const override
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
ITensorHandle * GetData() const
Gets the allocated tensor memory.
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
LayerGuid GetOwningLayerGuid() const override
const char * GetName() const override
Returns the name of the layer.
static const FactoryId LegacyFactoryId
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > >> ImmutableConstantTensors
virtual std::shared_ptr< ITensorHandle > DecorateTensorHandle(const TensorInfo &tensorInfo)
Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it.
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
unsigned int CalculateIndexOnOwner() const override
Layer & GetOwningLayer() const
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
void Disconnect(InputSlot &slot)
bool IsTensorInfoSet() const
Returns true if SetTensorInfo() has been called at least once on this.
unsigned int GetNumConnections() const override
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
LayerGuid GetGuid() const final
Returns the unique id of the layer.
const OutputHandler & GetOutputHandler(unsigned int i=0) const
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
void * m_AdditionalInfoObject
void SetAdditionalInfo(QueueDescriptor &descriptor) const
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Base class for all descriptors.
void Push(ITensorHandle *handle, const TensorInfo &info)
virtual void ReleaseConstantData()
DataType GetDataType() const
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
const std::string & GetNameStr() const
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
@ ValidateOnly
Validate all output shapes.
@ InferAndValidate
Infer missing output shapes and validate all output shapes.
void AssertNumberOfInputSlots(Layer &layer)
DataType GetDataType() const
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
virtual bool IsTensorInfoSet() const =0
const TensorShape & GetShape() const
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
void IgnoreUnused(Ts &&...)
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
Copyright (c) 2021 ARM Limited and Contributors.
virtual void ValidateTensorShapesFromInputs()=0
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)
LayerPriority GetPriority() const
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
Dimensionality GetDimensionality() const
Function that returns the tensor type.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
const InputSlot * GetConnection(unsigned int index) const override
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
void CollectWorkloadOutputs(WorkloadDataCollector &dataCollector) const
Fill the outputs for a given queue descriptor.
void ResetPriority() const