Skip to content

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

[NPUW] Fix ade:: namespace conflict (#26862)

Alexey Smirnov9201c57c5d29
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.cpp
index 7fc74923831..ea0d0ca7103 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.cpp
@@ -8,16 +8,19 @@
#include <algorithm>
#include <stack>
-ade::Nodes ade::Node::srcNodes() const {
- ade::Nodes src_nodes;
+own::ade::Nodes own::ade::Node::srcNodes() const {
+ own::ade::Nodes src_nodes;
src_nodes.reserve(m_src_edges.size());
- std::transform(m_src_edges.begin(), m_src_edges.end(), std::back_inserter(src_nodes), [](ade::EdgeHandle edge) {
- return edge->srcNode();
- });
+ std::transform(m_src_edges.begin(),
+ m_src_edges.end(),
+ std::back_inserter(src_nodes),
+ [](own::ade::EdgeHandle edge) {
+ return edge->srcNode();
+ });
// FIXME: this was introduced to make the graph
// the same every run when created the same way.
// FIXME: cache this information
- std::sort(src_nodes.begin(), src_nodes.end(), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
+ std::sort(src_nodes.begin(), src_nodes.end(), [&](const own::ade::NodeHandle& a, const own::ade::NodeHandle& b) {
auto locked_graph = m_graph.lock();
return locked_graph->meta(a).get<detail::CreateIdx>().m_idx <
locked_graph->meta(b).get<detail::CreateIdx>().m_idx;
@@ -25,16 +28,19 @@ ade::Nodes ade::Node::srcNodes() const {
return src_nodes;
}
-ade::Nodes ade::Node::dstNodes() const {
- ade::Nodes dst_nodes;
+own::ade::Nodes own::ade::Node::dstNodes() const {
+ own::ade::Nodes dst_nodes;
dst_nodes.reserve(m_dst_edges.size());
- std::transform(m_dst_edges.begin(), m_dst_edges.end(), std::back_inserter(dst_nodes), [](ade::EdgeHandle edge) {
- return edge->dstNode();
- });
+ std::transform(m_dst_edges.begin(),
+ m_dst_edges.end(),
+ std::back_inserter(dst_nodes),
+ [](own::ade::EdgeHandle edge) {
+ return edge->dstNode();
+ });
// FIXME: this was introduced to make the graph
// the same every run when created the same way.
// FIXME: cache this information
- std::sort(dst_nodes.begin(), dst_nodes.end(), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
+ std::sort(dst_nodes.begin(), dst_nodes.end(), [&](const own::ade::NodeHandle& a, const own::ade::NodeHandle& b) {
auto locked_graph = m_graph.lock();
return locked_graph->meta(a).get<detail::CreateIdx>().m_idx <
locked_graph->meta(b).get<detail::CreateIdx>().m_idx;
@@ -42,23 +48,23 @@ ade::Nodes ade::Node::dstNodes() const {
return dst_nodes;
}
-ade::Edges ade::Node::srcEdges() const {
+own::ade::Edges own::ade::Node::srcEdges() const {
return {m_src_edges.begin(), m_src_edges.end()};
}
-ade::Edges ade::Node::dstEdges() const {
+own::ade::Edges own::ade::Node::dstEdges() const {
return {m_dst_edges.begin(), m_dst_edges.end()};
}
-ade::NodeHandle ade::Graph::create() {
- auto node = std::make_shared<ade::Node>(shared_from_this());
- ade::NodeHandle nh(node);
- m_nodes.emplace(node.get(), MetaPtr<ade::Node>{node, ade::Meta{}});
+own::ade::NodeHandle own::ade::Graph::create() {
+ auto node = std::make_shared<own::ade::Node>(shared_from_this());
+ own::ade::NodeHandle nh(node);
+ m_nodes.emplace(node.get(), MetaPtr<own::ade::Node>{node, own::ade::Meta{}});
this->meta(nh).set(detail::CreateIdx{m_create_idx++});
return nh;
}
-void ade::Graph::remove(ade::NodeHandle nh) {
+void own::ade::Graph::remove(own::ade::NodeHandle nh) {
auto src_edges = nh->srcEdges();
for (size_t i = 0; i < src_edges.size(); ++i) {
remove(src_edges[i]);
@@ -70,7 +76,7 @@ void ade::Graph::remove(ade::NodeHandle nh) {
m_nodes.erase(nh.get());
}
-void ade::Graph::remove(ade::EdgeHandle eh) {
+void own::ade::Graph::remove(own::ade::EdgeHandle eh) {
auto src = eh->srcNode();
auto dst = eh->dstNode();
src->m_dst_edges.erase(eh);
@@ -78,44 +84,44 @@ void ade::Graph::remove(ade::EdgeHandle eh) {
m_edges.erase(eh.get());
}
-ade::EdgeHandle ade::Graph::link(ade::NodeHandle src, ade::NodeHandle dst) {
- auto edge = std::make_shared<ade::Edge>(src, dst);
- ade::EdgeHandle eh{edge};
- m_edges.emplace(edge.get(), MetaPtr<ade::Edge>{edge, ade::Meta{}});
+own::ade::EdgeHandle own::ade::Graph::link(own::ade::NodeHandle src, own::ade::NodeHandle dst) {
+ auto edge = std::make_shared<own::ade::Edge>(src, dst);
+ own::ade::EdgeHandle eh{edge};
+ m_edges.emplace(edge.get(), MetaPtr<own::ade::Edge>{edge, own::ade::Meta{}});
src->m_dst_edges.insert(eh);
dst->m_src_edges.insert(eh);
return eh;
}
-ade::Meta& ade::Graph::meta(ade::NodeHandle handle) {
+own::ade::Meta& own::ade::Graph::meta(own::ade::NodeHandle handle) {
const auto it = m_nodes.find(handle.get());
ASSERT(it != m_nodes.end());
return it->second.meta;
}
-const ade::Meta& ade::Graph::meta(ade::NodeHandle handle) const {
+const own::ade::Meta& own::ade::Graph::meta(own::ade::NodeHandle handle) const {
const auto it = m_nodes.find(handle.get());
ASSERT(it != m_nodes.end());
return it->second.meta;
}
-ade::Meta& ade::Graph::meta(ade::EdgeHandle handle) {
+own::ade::Meta& own::ade::Graph::meta(own::ade::EdgeHandle handle) {
const auto it = m_edges.find(handle.get());
ASSERT(it != m_edges.end());
return it->second.meta;
}
-const ade::Meta& ade::Graph::meta(ade::EdgeHandle handle) const {
+const own::ade::Meta& own::ade::Graph::meta(own::ade::EdgeHandle handle) const {
const auto it = m_edges.find(handle.get());
ASSERT(it != m_edges.end());
return it->second.meta;
}
-bool ade::Graph::contains(ade::NodeHandle handle) const {
+bool own::ade::Graph::contains(own::ade::NodeHandle handle) const {
return m_nodes.find(handle.get()) != m_nodes.end();
}
-bool ade::Graph::linked(ade::NodeHandle src, ade::NodeHandle dst) {
+bool own::ade::Graph::linked(own::ade::NodeHandle src, own::ade::NodeHandle dst) {
for (const auto& edge : src->m_dst_edges) {
if (edge->dstNode() == dst) {
return true;
@@ -124,23 +130,23 @@ bool ade::Graph::linked(ade::NodeHandle src, ade::NodeHandle dst) {
return false;
}
-std::vector<ade::NodeHandle> ade::Graph::nodes() const {
- std::vector<ade::NodeHandle> ret;
+std::vector<own::ade::NodeHandle> own::ade::Graph::nodes() const {
+ std::vector<own::ade::NodeHandle> ret;
std::transform(m_nodes.begin(), m_nodes.end(), std::back_inserter(ret), [](const auto& p) {
- return ade::NodeHandle{p.second.ptr};
+ return own::ade::NodeHandle{p.second.ptr};
});
return ret;
}
-void ade::Graph::dfs(ade::NodeHandle& nh,
- std::unordered_set<ade::NodeHandle>& visited,
- std::stack<ade::NodeHandle>& stack) const {
+void own::ade::Graph::dfs(own::ade::NodeHandle& nh,
+ std::unordered_set<own::ade::NodeHandle>& visited,
+ std::stack<own::ade::NodeHandle>& stack) const {
visited.insert(nh);
auto dst_nodes = nh->dstNodes();
// FIXME: this was introduced to make the graph
// the same every run when created the same way.
- std::sort(dst_nodes.begin(), dst_nodes.end(), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
+ std::sort(dst_nodes.begin(), dst_nodes.end(), [&](const own::ade::NodeHandle& a, const own::ade::NodeHandle& b) {
return this->meta(a).get<detail::CreateIdx>().m_idx < this->meta(b).get<detail::CreateIdx>().m_idx;
});
@@ -153,14 +159,14 @@ void ade::Graph::dfs(ade::NodeHandle& nh,
stack.push(nh);
}
-std::vector<ade::NodeHandle> ade::Graph::sorted() const {
- std::unordered_set<ade::NodeHandle> visited;
- std::stack<ade::NodeHandle> stack;
+std::vector<own::ade::NodeHandle> own::ade::Graph::sorted() const {
+ std::unordered_set<own::ade::NodeHandle> visited;
+ std::stack<own::ade::NodeHandle> stack;
auto nodes = this->nodes();
// FIXME: this was introduced to make the graph
// the same every run when created the same way.
- std::sort(nodes.begin(), nodes.end(), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
+ std::sort(nodes.begin(), nodes.end(), [&](const own::ade::NodeHandle& a, const own::ade::NodeHandle& b) {
return this->meta(a).get<detail::CreateIdx>().m_idx < this->meta(b).get<detail::CreateIdx>().m_idx;
});
@@ -170,7 +176,7 @@ std::vector<ade::NodeHandle> ade::Graph::sorted() const {
dfs(nh, visited, stack);
}
}
- std::vector<ade::NodeHandle> sorted;
+ std::vector<own::ade::NodeHandle> sorted;
while (!stack.empty()) {
sorted.push_back(stack.top());
stack.pop();
@@ -178,7 +184,7 @@ std::vector<ade::NodeHandle> ade::Graph::sorted() const {
return sorted;
}
-ade::Meta& ade::Meta::operator+=(const ade::Meta& other) {
+own::ade::Meta& own::ade::Meta::operator+=(const own::ade::Meta& other) {
for (const auto& p : other.store) {
ASSERT(store.emplace(p.first, p.second).second);
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.hpp
index 58b3e96918d..439cb623f1f 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/graph.hpp
@@ -46,6 +46,7 @@ namespace detail {
}
} // anonymous namespace
+namespace own {
namespace ade {
namespace detail {
@@ -73,16 +74,18 @@ struct CreateIdx {
} // namespace detail
} // namespace ade
+} // namespace own
namespace std {
template <typename T>
-struct hash<ade::detail::WeakHandle<T>> {
- uint64_t operator()(const ade::detail::WeakHandle<T>& handle) const {
+struct hash<own::ade::detail::WeakHandle<T>> {
+ uint64_t operator()(const own::ade::detail::WeakHandle<T>& handle) const {
return std::hash<T*>()(handle.get());
}
};
} // namespace std
+namespace own {
namespace ade {
class Graph;
@@ -217,3 +220,4 @@ private:
};
} // namespace ade
+} // namespace own
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.cpp
index 96ad696e911..d09f0b8a710 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.cpp
@@ -22,8 +22,8 @@ using ov::npuw::online::detail::isOp;
Group::Group(const std::shared_ptr<ov::Node>& node,
size_t gid,
- ade::NodeHandle nh,
- const std::shared_ptr<ade::Graph>& g,
+ own::ade::NodeHandle nh,
+ const std::shared_ptr<own::ade::Graph>& g,
const std::weak_ptr<Snapshot>& snapshot)
: m_nh(std::move(nh)),
m_id(gid),
@@ -35,8 +35,8 @@ Group::Group(const std::shared_ptr<ov::Node>& node,
}
Group::Group(size_t gid,
- ade::NodeHandle nh,
- const std::shared_ptr<ade::Graph>& g,
+ own::ade::NodeHandle nh,
+ const std::shared_ptr<own::ade::Graph>& g,
const std::weak_ptr<Snapshot>& snapshot)
: m_nh(std::move(nh)),
m_id(gid),
@@ -140,15 +140,15 @@ size_t Group::getId() const {
return m_id;
}
-std::vector<ade::NodeHandle> Group::srcNodes() const {
+std::vector<own::ade::NodeHandle> Group::srcNodes() const {
return m_nh->srcNodes();
}
-std::vector<ade::NodeHandle> Group::dstNodes() const {
+std::vector<own::ade::NodeHandle> Group::dstNodes() const {
return m_nh->dstNodes();
}
-ade::NodeHandle Group::getHandle() const {
+own::ade::NodeHandle Group::getHandle() const {
return m_nh;
}
@@ -234,7 +234,7 @@ void Group::fuse(const Group::GPtr& gptr_prod) {
// This group absorbs the consumer
void Group::fuseWith(const Group::GPtr& gptr_cons) {
- // Update ov::node to ade::NodeHandle map
+ // Update ov::node to own::ade::NodeHandle map
auto locked_snapshot = m_snapshot.lock();
auto node_to_gr = locked_snapshot->getNodeToGroupMap();
for (const auto& layer : gptr_cons->m_content) {
@@ -261,7 +261,7 @@ void Group::fuseInputs(const std::pair<Group::GPtr, Group::GPtr>& gptr_inputs) {
auto locked_snapshot = m_snapshot.lock();
auto node_to_gr = locked_snapshot->getNodeToGroupMap();
- // Update ov::node to ade::NodeHandle map and merge all contents together
+ // Update ov::node to own::ade::NodeHandle map and merge all contents together
for (const auto& layer : absorbed_group->m_content) {
node_to_gr->at(layer) = absorbing_group;
absorbing_group->m_content.insert(layer);
@@ -296,9 +296,9 @@ void Group::takeFlags(const Group::GPtr& gptr_other) {
// Check if there is indirect path from this to gptr_cons
bool Group::hasCycle(const Group::GPtr& gptr_cons) const {
- std::unordered_set<ade::NodeHandle> visited;
+ std::unordered_set<own::ade::NodeHandle> visited;
- std::stack<ade::NodeHandle> st;
+ std::stack<own::ade::NodeHandle> st;
for (const auto& prod : gptr_cons->srcNodes()) {
// skip self during this iter
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.hpp
index dc48be6e4e0..69688248a0b 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/group.hpp
@@ -32,21 +32,21 @@ public:
Group() = delete;
Group(const std::shared_ptr<ov::Node>& node,
size_t gid,
- ade::NodeHandle nh,
- const std::shared_ptr<ade::Graph>& g,
+ own::ade::NodeHandle nh,
+ const std::shared_ptr<own::ade::Graph>& g,
const std::weak_ptr<Snapshot>& snapshot);
Group(size_t gid,
- ade::NodeHandle nh,
- const std::shared_ptr<ade::Graph>& g,
+ own::ade::NodeHandle nh,
+ const std::shared_ptr<own::ade::Graph>& g,
const std::weak_ptr<Snapshot>& snapshot);
// After we formed a final structure of partitioning,
// we append excluded Convert layers to properly link submodels
// Convert this representation to plugin-compatible one
ov::npuw::Group toGroup() const;
- std::vector<ade::NodeHandle> srcNodes() const;
- std::vector<ade::NodeHandle> dstNodes() const;
- ade::NodeHandle getHandle() const;
+ std::vector<own::ade::NodeHandle> srcNodes() const;
+ std::vector<own::ade::NodeHandle> dstNodes() const;
+ own::ade::NodeHandle getHandle() const;
// Note: can only be used during initial group initialization
std::shared_ptr<ov::Node> getInitialNode() const;
void addInput(const std::shared_ptr<ov::Node>& node);
@@ -95,9 +95,9 @@ private:
detail::OVNodeSet m_content;
detail::OVNodeSet m_output_layers;
- ade::NodeHandle m_nh;
+ own::ade::NodeHandle m_nh;
size_t m_id; // used for utility prints only
- std::shared_ptr<ade::Graph> m_graph;
+ std::shared_ptr<own::ade::Graph> m_graph;
std::weak_ptr<Snapshot> m_snapshot;
bool m_frozen = false;
bool m_nofold = false;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp
index a35f33eab49..c621dbafd3d 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp
@@ -213,11 +213,13 @@ void Snapshot::fuseRemnants() {
}
auto consumers = group->dstNodes();
if (!consumers.empty()) {
- std::sort(consumers.begin(), consumers.end(), [&](const ade::NodeHandle& nh1, const ade::NodeHandle& nh2) {
- Group::GPtr g1 = m_graph->meta(nh1).get<Group::GPtr>();
- Group::GPtr g2 = m_graph->meta(nh2).get<Group::GPtr>();
- return g1->size() < g2->size();
- });
+ std::sort(consumers.begin(),
+ consumers.end(),
+ [&](const own::ade::NodeHandle& nh1, const own::ade::NodeHandle& nh2) {
+ Group::GPtr g1 = m_graph->meta(nh1).get<Group::GPtr>();
+ Group::GPtr g2 = m_graph->meta(nh2).get<Group::GPtr>();
+ return g1->size() < g2->size();
+ });
for (const auto& cons : consumers) { // FIXME: pick the smallest flops
Group::GPtr cons_group = m_graph->meta(cons).get<Group::GPtr>();
if (!group->hasCycle(cons_group)) {
@@ -1051,7 +1053,7 @@ const ov::npuw::online::detail::OVNodeToGroupMapPtr& Snapshot::getNodeToGroupMap
return m_node_to_gr;
}
-std::shared_ptr<ade::Graph> Snapshot::getGraph() const {
+std::shared_ptr<own::ade::Graph> Snapshot::getGraph() const {
return m_graph;
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.hpp
index df7f48d76b5..72a62781580 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.hpp
@@ -29,7 +29,7 @@ class Snapshot : public std::enable_shared_from_this<Snapshot> {
public:
Snapshot(const std::shared_ptr<ov::Model>& model)
: m_model(model),
- m_graph(std::make_shared<ade::Graph>()),
+ m_graph(std::make_shared<own::ade::Graph>()),
m_node_to_prod_cons(std::make_shared<detail::OVNodeMap>()),
m_node_to_gr(std::make_shared<detail::OVNodeToGroupMap>()) {}
@@ -53,7 +53,7 @@ public:
void resetExcludedRep();
// Utility
- std::shared_ptr<ade::Graph> getGraph() const;
+ std::shared_ptr<own::ade::Graph> getGraph() const;
size_t graphSize() const;
const detail::OVNodeSet& getNodeProducers(const detail::OVNodePtr& node) const;
const detail::OVNodeSet& getNodeConsumers(const detail::OVNodePtr& node) const;
@@ -81,7 +81,7 @@ private:
void completeRepeating(const std::shared_ptr<Repeated>& reptag, const detail::GPtrSet& gset);
std::shared_ptr<ov::Model> m_model;
- std::shared_ptr<ade::Graph> m_graph;
+ std::shared_ptr<own::ade::Graph> m_graph;
detail::OVNodeMapPtr m_node_to_prod_cons;
detail::OVNodeToGroupMapPtr m_node_to_gr;
PassContext m_ctx;