Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU] Enchant Edge "to string" logic (#27563)

Egor Duplenskii094279712b3f
diff --git a/src/plugins/intel_cpu/src/edge.cpp b/src/plugins/intel_cpu/src/edge.cpp
index c314718bb82..82bde8edae2 100644
--- a/src/plugins/intel_cpu/src/edge.cpp
+++ b/src/plugins/intel_cpu/src/edge.cpp
@@ -235,7 +235,7 @@ Edge::ReorderStatus Edge::needReorder() {
}
void Edge::reuse(MemoryPtr ptr) {
- OPENVINO_ASSERT(ptr != nullptr, "Attempt to reuse initialized memory in " + name());
+ OPENVINO_ASSERT(ptr != nullptr, "Attempt to reuse initialized memory in ", *this);
memoryPtr = ptr;
changeStatus(Status::Allocated);
@@ -286,15 +286,14 @@ void Edge::allocate(MemoryBlockPtr memBlock) {
allocateCommon(allocateFunc);
}
-std::string Edge::name() const {
+std::string Edge::hash() const {
auto parentPtr = getParent();
auto childPtr = getChild();
std::stringstream result;
- result << parentPtr->getName() << " port " << parent_port << " <-> " << childPtr->getName() << " port " << child_port;
-
- return result.str();
+ return parentPtr->getName() + "_" + std::to_string(parent_port) + "_" +
+ childPtr->getName() + "_" + std::to_string(child_port);
}
void Edge::externalAllocate(WeightsSharing::Ptr weightsCache) {
@@ -312,7 +311,7 @@ void Edge::externalAllocate(WeightsSharing::Ptr weightsCache) {
return memoryPtr;
};
- auto ptr = weightsCache->findOrCreate(name(), alloc, false);
+ auto ptr = weightsCache->findOrCreate(hash(), alloc, false);
memoryPtr = *ptr;
DEBUG_LOG(*this, " memoryPtr=", memoryPtr);
useExternalMemory = true;
@@ -330,7 +329,7 @@ void Edge::changeStatus(Edge::Status state) {
OPENVINO_THROW("Incorrect behaviour! Use method validate()");
}
if (Status::Validated == this->status) {
- OPENVINO_THROW("Unexpected attempt of memory change on edge: ", name());
+ OPENVINO_THROW("Unexpected attempt of memory change on edge: ", *this);
}
if (this->status != Status::Uninitialized && state == Status::NeedAllocation)
return;
@@ -419,7 +418,7 @@ const MemoryDesc& Edge::getDesc() const {
const IMemory &Edge::getMemory() {
auto memPtr = getMemoryPtr();
- OPENVINO_ASSERT(memPtr != nullptr, " Dereferencing NULL memory in edge: ", name());
+ OPENVINO_ASSERT(memPtr != nullptr, " Dereferencing NULL memory in edge: ", *this);
return *memPtr;
}
@@ -449,7 +448,7 @@ void Edge::validate() {
EdgePtr Edge::getSharedEdge() const {
auto memoryFromEdgePtr = memoryFromEdge.lock();
if (!memoryFromEdgePtr) {
- OPENVINO_THROW("Cannot get memory ptr for edge( ", name(), " ). The pointer on the edge with memory is empty!");
+ OPENVINO_THROW("Cannot get memory ptr for edge( ", *this, " ). The pointer on the edge with memory is empty!");
}
return memoryFromEdgePtr;
}
@@ -494,7 +493,7 @@ EdgePtr Edge::getBaseEdge(int look) {
OPENVINO_ASSERT(!(parentInPlacePort >= 0 && childInPlacePort >= 0),
"Unresolved in place memory conflict detected on edge: ",
- name());
+ *this);
if ((childInPlacePort >= 0) && (look & LOOK_DOWN)) {
auto ch_edges = getChild()->getChildEdgesAtPort(childInPlacePort);
@@ -592,5 +591,12 @@ NodePtr Edge::modifiedInPlace() const {
return nullptr;
}
+std::ostream& operator<<(std::ostream &os, const Edge& edge) {
+ return os << "(" << edge.getParent()->getName() << ")" << "[" << edge.getInputNum() << "] "
+ << "<->"
+ << "(" << edge.getChild()->getName() << ")" << "[" << edge.getOutputNum() << "]"
+ << ":" << Edge::statusToString(edge.getStatus());
+}
+
} // namespace intel_cpu
} // namespace ov
diff --git a/src/plugins/intel_cpu/src/edge.h b/src/plugins/intel_cpu/src/edge.h
index 29cb8113943..5c418b26659 100644
--- a/src/plugins/intel_cpu/src/edge.h
+++ b/src/plugins/intel_cpu/src/edge.h
@@ -5,6 +5,7 @@
#pragma once
#include "cpu_shape.h"
+#include "internal_properties.hpp"
#include "memory_desc/cpu_memory_desc.h"
#include "nodes/node_config.h"
#include "weights_cache.hpp"
@@ -47,6 +48,21 @@ public:
return status;
}
+ static std::string statusToString(Status status) {
+#define CASE(_status) \
+ case Status::_status: \
+ return #_status;
+ switch (status) {
+ CASE(Uninitialized);
+ CASE(NeedAllocation);
+ CASE(NotAllocated);
+ CASE(Allocated);
+ CASE(Validated);
+ }
+#undef CASE
+ return "Unexpected";
+ }
+
void changeStatus(Status state);
bool inPlace(LOOK look = LOOK_BOTH) const;
@@ -81,7 +97,7 @@ public:
return getDesc().hasDefinedMaxSize();
}
- std::string name() const;
+ std::string hash() const;
private:
std::weak_ptr<Node> parent;
@@ -110,6 +126,8 @@ private:
friend class Graph;
};
+std::ostream& operator<<(std::ostream &os, const Edge& edge);
+
} // namespace intel_cpu
} // namespace ov
diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cpp
index 9b9357b5b2f..86fb7bf4ded 100644
--- a/src/plugins/intel_cpu/src/graph.cpp
+++ b/src/plugins/intel_cpu/src/graph.cpp
@@ -516,7 +516,7 @@ void Graph::CreatePrimitivesAndExecConstants() const {
auto edgePtr = node->getChildEdgeAt(i);
if (edgePtr) {
if (edgePtr->isUseExternalMemory()) {
- auto ptr = m_context->getWeightsCache()->get(edgePtr->name());
+ auto ptr = m_context->getWeightsCache()->get(edgePtr->hash());
outputs.emplace_back(ptr);
if (!ptr->isValid())
hasExternalInvalidEdges = true;
@@ -1635,7 +1635,7 @@ NodePtr Graph::InsertReorder(EdgePtr edge,
reorder->setOptimized(isOptimized);
reorder->setSrcPermutation(src_perm);
- DEBUG_LOG(reorder->getName(), " edge=", edge->name(), " isOptimized=", isOptimized);
+ DEBUG_LOG(reorder->getName(), " edge=", *edge, " isOptimized=", isOptimized);
DEBUG_LOG(" inDesc: ", inDesc.getShape().toString(), inDesc.getPrecision().get_type_name(), " ", inDesc.serializeFormat());
DEBUG_LOG(" outDesc: ", outDesc.getShape().toString(), outDesc.getPrecision().get_type_name(), " ", outDesc.serializeFormat());
diff --git a/src/plugins/intel_cpu/src/infer_request.cpp b/src/plugins/intel_cpu/src/infer_request.cpp
index f0b817dcda8..26cdaf08601 100644
--- a/src/plugins/intel_cpu/src/infer_request.cpp
+++ b/src/plugins/intel_cpu/src/infer_request.cpp
@@ -159,7 +159,7 @@ std::vector<ov::ProfilingInfo> SyncInferRequest::get_profiling_info() const {
static inline void change_edge_ptr(const EdgePtr& edge, ov::SoPtr<ov::ITensor>& tensor) {
auto mem = edge->getMemoryPtr();
- OPENVINO_ASSERT(mem != nullptr, "Edge with name '", edge->name(), "' doesn't have allocated memory object.");
+ OPENVINO_ASSERT(mem != nullptr, "Edge with name '", *edge, "' doesn't have allocated memory object.");
if (tensor->get_element_type() == element::string) {
auto memBlock = dynamic_cast<StringMemory *>(mem.get())->getStringMemoryBlockPtr();
diff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cpp
index 7c23d55fc41..f4c2b0eb686 100644
--- a/src/plugins/intel_cpu/src/node.cpp
+++ b/src/plugins/intel_cpu/src/node.cpp
@@ -475,7 +475,7 @@ void Node::resolveInPlaceEdges(Edge::LOOK look) {
auto parentEdge = getParentEdgeAt(i);
OPENVINO_ASSERT(parentEdge->getStatus() == Edge::Status::NotAllocated,
" Unexpected inplace resolve call to an allocated edge: ",
- parentEdge->name());
+ *parentEdge);
//search for already allocated edge
const auto& childEdges = getChildEdgesAtPort(inplaceOutIndx);
@@ -504,7 +504,7 @@ void Node::resolveInPlaceEdges(Edge::LOOK look) {
for (auto& childEdge : childEdges) {
OPENVINO_ASSERT(childEdge->getStatus() == Edge::Status::NotAllocated,
" Unexpected inplace resolve call to an allocated edge: ",
- childEdge->name());
+ *childEdge);
auto newMem = std::make_shared<Memory>(getEngine(), selected_pd->getConfig().outConfs[i].getMemDesc(), memBlock);
childEdge->reuse(newMem);
}
diff --git a/src/plugins/intel_cpu/src/nodes/concat.cpp b/src/plugins/intel_cpu/src/nodes/concat.cpp
index 576361de7e6..ed8e34328fb 100644
--- a/src/plugins/intel_cpu/src/nodes/concat.cpp
+++ b/src/plugins/intel_cpu/src/nodes/concat.cpp
@@ -709,7 +709,7 @@ void Concat::resolveInPlaceEdges(Edge::LOOK look) {
OPENVINO_ASSERT(parentEdge->getStatus() == Edge::Status::NotAllocated,
" Unexpected inplace resolve call to an allocated edge: ",
- parentEdge->name());
+ *parentEdge);
auto memDesc = selected_pd->getConfig().inConfs[i].getMemDesc();
MemoryPtr newMem;
diff --git a/src/plugins/intel_cpu/src/nodes/memory.cpp b/src/plugins/intel_cpu/src/nodes/memory.cpp
index 565597bdcc2..1c6e2aca6fa 100644
--- a/src/plugins/intel_cpu/src/nodes/memory.cpp
+++ b/src/plugins/intel_cpu/src/nodes/memory.cpp
@@ -254,7 +254,7 @@ void MemoryOutput::resolveInPlaceEdges(Edge::LOOK look) {
auto parentEdge = getParentEdgeAt(0); // always only one parent edge
OPENVINO_ASSERT(one_of(parentEdge->getStatus(), Edge::Status::Uninitialized, Edge::Status::NotAllocated),
- " Unexpected inplace resolve call to an allocated edge: ", parentEdge->name());
+ " Unexpected inplace resolve call to an allocated edge: ", *parentEdge);
auto memDesc = selected_pd->getConfig().inConfs.front().getMemDesc();
memBlock = std::make_shared<ProxyMemoryBlock>();
@@ -350,7 +350,7 @@ void MemoryOutputStub::resolveInPlaceEdges(Edge::LOOK look) {
auto parentEdge = getParentEdgeAt(0); // always only one parent edge
OPENVINO_ASSERT(one_of(parentEdge->getStatus(), Edge::Status::Uninitialized, Edge::Status::NotAllocated),
- " Unexpected inplace resolve call to an allocated edge: ", parentEdge->name());
+ " Unexpected inplace resolve call to an allocated edge: ", *parentEdge);
auto memDesc = selected_pd->getConfig().inConfs.front().getMemDesc();
// make a fake memory
@@ -717,7 +717,7 @@ void MemoryInput::resolveInPlaceEdges(Edge::LOOK look) {
for (auto&& edge : getChildEdgesAtPort(0)) { // always only one child port
OPENVINO_ASSERT(one_of(edge->getStatus(), Edge::Status::Uninitialized, Edge::Status::NotAllocated),
- " Unexpected inplace resolve call to an allocated edge: ", edge->name());
+ " Unexpected inplace resolve call to an allocated edge: ", *edge);
auto edgeMem = std::make_shared<Memory>(getEngine(), memDesc, memBlock);
edge->reuse(edgeMem);
@@ -846,7 +846,7 @@ void MemoryInputSDPA::resolveInPlaceEdges(Edge::LOOK look) {
auto memDesc = getBaseMemDescAtOutputPort(0);
for (auto&& edge : getChildEdgesAtPort(0)) { // always only one child port
OPENVINO_ASSERT(one_of(edge->getStatus(), Edge::Status::Uninitialized, Edge::Status::NotAllocated),
- " Unexpected inplace resolve call to an allocated edge: ", edge->name());
+ " Unexpected inplace resolve call to an allocated edge: ", *edge);
auto edgeMem = std::make_shared<MemoryStub>(getEngine(), memDesc);
edge->reuse(edgeMem);
diff --git a/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp b/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp
index 69b3da9be00..fcc983d8416 100644
--- a/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp
+++ b/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp
@@ -151,12 +151,6 @@ std::ostream & operator<<(std::ostream & os, const NodeDesc& desc) {
return os;
}
-std::ostream & operator<<(std::ostream & os, const Edge& edge) {
- os << edge.getParent()->getName() << "[" << edge.getInputNum() << "]->"
- << edge.getChild()->getName() << "[" << edge.getOutputNum() << "]";
- return os;
-}
-
std::ostream & operator<<(std::ostream & os, const Node &c_node) {
Node & node = const_cast<Node &>(c_node);
const int align_col = 50;
diff --git a/src/plugins/intel_cpu/src/utils/debug_capabilities.h b/src/plugins/intel_cpu/src/utils/debug_capabilities.h
index 7faf02429b4..7a1158d259a 100644
--- a/src/plugins/intel_cpu/src/utils/debug_capabilities.h
+++ b/src/plugins/intel_cpu/src/utils/debug_capabilities.h
@@ -102,7 +102,6 @@ std::ostream & operator<<(std::ostream & os, const ov::intel_cpu::Graph& graph);
std::ostream & operator<<(std::ostream & os, const Shape& shape);
std::ostream & operator<<(std::ostream & os, const MemoryDesc& desc);
std::ostream & operator<<(std::ostream & os, const IMemory& mem);
-std::ostream & operator<<(std::ostream & os, const Edge& edge);
std::ostream & operator<<(std::ostream & os, const PrintableModel& model);
std::ostream & operator<<(std::ostream & os, const PrintableDelta& us);
std::ostream & operator<<(std::ostream & os, const Edge::ReorderStatus reorderStatus);