12 #include <boost/cast.hpp> 13 #include <boost/format.hpp> 26 if (prevSlot !=
nullptr)
29 prevSlot->Disconnect(*
this);
37 const TensorInfo& tensorInfo = prevSlot->GetTensorInfo();
48 ValidateConnectionIndex(index);
49 return m_Connections[index];
54 ValidateConnectionIndex(index);
55 return m_Connections[index];
60 GetOutputHandler().SetTensorInfo(tensorInfo);
65 return GetOutputHandler().GetTensorInfo();
70 return GetOutputHandler().IsTensorInfoSet();
75 BOOST_ASSERT_MSG(IsTensorInfoSet(),
"TensorInfo must be set in order to validate the shape.");
76 return shape == m_OutputHandler.GetTensorInfo().GetShape();
82 m_Connections.push_back(&destination);
90 auto it = std::find(m_Connections.begin(), m_Connections.end(), &slot);
92 if (it == m_Connections.end())
97 auto idx = std::distance(m_Connections.begin(), it);
98 m_Connections.erase(std::remove(m_Connections.begin(), m_Connections.end(), &slot), m_Connections.end());
100 m_EdgeStrategies.erase(m_EdgeStrategies.begin() + idx);
105 while (GetNumConnections() > 0)
108 Disconnect(connection);
114 while (GetNumConnections() > 0)
117 "Cannot move connections once memory strategies have be established.");
120 Disconnect(connection);
121 destination.
Connect(connection);
134 BOOST_ASSERT_MSG(
false,
"Did not find slot on owner.");
146 for (
unsigned int i = 0; i < GetNumConnections(); i++)
153 void OutputSlot::ValidateConnectionIndex(
unsigned int index)
const 155 if (boost::numeric_cast<std::size_t>(index) >= m_Connections.size())
158 boost::str(boost::format(
"GetConnection: Invalid index %1% provided") % index));
169 m_TensorHandleFactoryId = id;
174 return m_TensorHandleFactoryId;
179 m_EdgeStrategies[connectionIndex] = strategy;
184 return m_EdgeStrategies[connectionIdx];
188 unsigned int numOutputSlots,
192 : m_OutputHandlers(numOutputSlots)
193 , m_LayerName(name ? name :
"")
200 m_InputSlots.reserve(numInputSlots);
201 for (
unsigned int i = 0; i < numInputSlots; ++i)
203 m_InputSlots.emplace_back(*
this, i);
206 m_OutputSlots.reserve(numOutputSlots);
207 for (
unsigned int i = 0; i < numOutputSlots; ++i)
214 unsigned int numOutputSlots,
226 BOOST_ASSERT(inputSlot.GetConnection());
227 const OutputHandler& outputHandler = inputSlot.GetConnectedOutputSlot()->GetOutputHandler();
228 dataCollector.
Push(outputHandler.GetData(), outputHandler.GetTensorInfo());
236 outputHandler.CollectWorkloadOutputs(dataCollector);
242 const bool IsMemoryManaged)
258 BOOST_ASSERT(handleFactory);
269 handle.reset(
nullptr);
290 constexpr
LayerPriority inputPrio = std::numeric_limits<LayerPriority>::lowest();
291 constexpr
LayerPriority outputPrio = std::numeric_limits<LayerPriority>::max();
295 m_Priority = inputPrio;
299 m_Priority = outputPrio;
301 else if (m_Priority == 0)
310 const OutputSlot *outputSlot = slot.GetConnectedOutputSlot();
327 if (parentPrio >= outputPrio)
332 m_Priority = parentPrio + 1U;
342 for (
unsigned int i=0; i<expectedConnections; ++i)
349 "Input connection #%1% must be connected " 350 "for %2% layer %3% %4%")
356 if(!
GetInputSlot(i).GetConnection()->IsTensorInfoSet())
361 "TensorInfo of Input connection #%1% must be set on connected OutputSlot for " 386 "Default implementation for InferOutputShapes can only be used for " 387 "layers with the same number of input and output slots. This doesn't " 388 "hold for %1% layer %2% (#inputs=%3% #outputs=%4%) %5%")
401 std::string backendId = std::string(m_BackendId);
402 if(!(m_LayerName.compare(
"") == 0) && !m_LayerName.empty())
404 fn(
"LayerName",m_LayerName);
406 if(!(layerType.compare(
"") == 0) && !layerType.empty())
408 fn(
"LayerType",layerType);
410 if(!(backendId.compare(
"") == 0) && !backendId.empty())
412 fn(
"BackendID",backendId);
virtual void ReleaseConstantData()
bool ValidateTensorShape(const TensorShape &shape) const
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
std::string AsString() const
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)
LayerGuid GetOwningLayerGuid() const override
void OperateOnConstantTensors(Op op)
Layer & GetOwningLayer() const
int Connect(InputSlot &destination)
unsigned int LayerPriority
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
const std::vector< InputSlot > & GetInputSlots() const
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
void Disconnect(InputSlot &slot)
void CreateTensorHandles(const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
Creates tensor handles used by the intermediate tensors.
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
unsigned int GetNumConnections() const override
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
void ResetPriority() const
char const * GetLayerTypeAsCString(LayerType type)
DataType GetDataType() const
void Push(ITensorHandle *handle, const TensorInfo &info)
const std::string & GetNameStr() const
LayerPriority GetPriority() const
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
std::vector< OutputHandler > m_OutputHandlers
void SetTensorInfo(const TensorInfo &tensorInfo)
Sets the TensorInfo used by this output handler.
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
bool operator==(const OutputSlot &other) const
const OutputHandler & GetOutputHandler(unsigned int i=0) const
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
void SetTensorInfo(const TensorInfo &tensorInfo) override
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
DataType GetDataType() const
LayerType GetType() const
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
virtual const TensorInfo & GetTensorInfo() const =0
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
bool IsTensorInfoSet() const override
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
const TensorInfo & GetTensorInfo() const override
static const FactoryId LegacyFactoryId
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
const InputSlot * GetConnection(unsigned int index) const override
LayerGuid GetGuid() const final
Returns the unique id of the layer.
unsigned int CalculateIndexOnOwner() const override