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);
84 return boost::numeric_cast<
int>(m_Connections.size() - 1);
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 :
"")
198 boost::ignore_unused(layout);
199 m_InputSlots.reserve(numInputSlots);
200 for (
unsigned int i = 0; i < numInputSlots; ++i)
202 m_InputSlots.emplace_back(*
this, i);
205 m_OutputSlots.reserve(numOutputSlots);
206 for (
unsigned int i = 0; i < numOutputSlots; ++i)
213 unsigned int numOutputSlots,
225 BOOST_ASSERT(inputSlot.GetConnection());
226 const OutputHandler& outputHandler = inputSlot.GetConnectedOutputSlot()->GetOutputHandler();
227 dataCollector.
Push(outputHandler.GetData(), outputHandler.GetTensorInfo());
235 outputHandler.CollectWorkloadOutputs(dataCollector);
241 const bool IsMemoryManaged)
257 BOOST_ASSERT(handleFactory);
268 handle.reset(
nullptr);
289 constexpr
LayerPriority inputPrio = std::numeric_limits<LayerPriority>::lowest();
290 constexpr
LayerPriority outputPrio = std::numeric_limits<LayerPriority>::max();
294 m_Priority = inputPrio;
298 m_Priority = outputPrio;
300 else if (m_Priority == 0)
309 const OutputSlot *outputSlot = slot.GetConnectedOutputSlot();
326 if (parentPrio >= outputPrio)
331 m_Priority = parentPrio + 1U;
341 for (
unsigned int i=0; i<expectedConnections; ++i)
348 "Input connection #%1% must be connected " 349 "for %2% layer %3% %4%")
355 if(!
GetInputSlot(i).GetConnection()->IsTensorInfoSet())
360 "TensorInfo of Input connection #%1% must be set on connected OutputSlot for " 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%")
400 std::string backendId = std::string(m_BackendId);
401 if(!(m_LayerName.compare(
"") == 0) && !m_LayerName.empty())
403 fn(
"LayerName",m_LayerName);
405 if(!(layerType.compare(
"") == 0) && !layerType.empty())
407 fn(
"LayerType",layerType);
409 if(!(backendId.compare(
"") == 0) && !backendId.empty())
411 fn(
"BackendID",backendId);
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
unsigned int GetNumOutputSlots() const override
LayerGuid GetGuid() const final
LayerType GetType() const
virtual void CreateTensorHandles(const TensorHandleFactoryRegistry ®istry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
virtual const TensorInfo & GetTensorInfo() const =0
virtual void ReleaseConstantData()
char const * GetLayerTypeAsCString(LayerType type)
void SetEdgeStrategy(unsigned int connectionIndex, EdgeStrategy strategy)
void Push(ITensorHandle *handle, const TensorInfo &info)
unsigned int LayerPriority
void ResetPriority() const
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
int Connect(InputSlot &destination)
const std::string & GetNameStr() const
LayerPriority GetPriority() const
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
static const FactoryId LegacyFactoryId
const std::vector< InputSlot > & GetInputSlots() const
DataType GetDataType() const
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
unsigned int GetNumConnections() const override
unsigned int CalculateIndexOnOwner() const override
void SetTensorInfo(const TensorInfo &tensorInfo) override
const InputSlot * GetConnection(unsigned int index) const override
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
void Disconnect(InputSlot &slot)
bool ValidateTensorShape(const TensorShape &shape) const
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
bool operator==(const OutputSlot &other) const
void CreateTensorHandles(const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
Creates tensor handles used by the intermediate tensors. Does not allocate memory.
std::vector< OutputHandler > m_OutputHandlers
bool IsTensorInfoSet() const override
void SetTensorInfo(const TensorInfo &tensorInfo)
Sets the TensorInfo used by this output handler.
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
DataType GetDataType() const
LayerGuid GetOwningLayerGuid() const override
void SetTensorHandleFactory(const ITensorHandleFactory::FactoryId &id)
void OperateOnConstantTensors(Op op)
unsigned int GetNumInputSlots() const override
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
const TensorInfo & GetTensorInfo() const override
Layer & GetOwningLayer() const
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
std::string AsString() const
const InputSlot & GetInputSlot(unsigned int index) const override