Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/plugins/intel_cpu/src/edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
20 changes: 19 additions & 1 deletion src/plugins/intel_cpu/src/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -47,6 +48,21 @@ class Edge {
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;

Expand Down Expand Up @@ -81,7 +97,7 @@ class Edge {
return getDesc().hasDefinedMaxSize();
}

std::string name() const;
std::string hash() const;

private:
std::weak_ptr<Node> parent;
Expand Down Expand Up @@ -110,6 +126,8 @@ class Edge {
friend class Graph;
};

std::ostream& operator<<(std::ostream &os, const Edge& edge);

} // namespace intel_cpu
} // namespace ov

4 changes: 2 additions & 2 deletions src/plugins/intel_cpu/src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,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;
Expand Down Expand Up @@ -1640,7 +1640,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());

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/src/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_cpu/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/src/nodes/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_cpu/src/nodes/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/intel_cpu/src/utils/debug_capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_cpu/src/utils/debug_capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading