Skip to content

[NFC][SYCL][Graph] Store raw node_impl * in MPredecessors/MSuccessors #19438

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

Merged
merged 1 commit into from
Jul 16, 2025
Merged
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
17 changes: 6 additions & 11 deletions sycl/source/detail/graph/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,11 +1321,9 @@ void exec_graph_impl::duplicateNodes() {
auto &Successors = PredNode.MSuccessors;

// Remove the subgraph node from this nodes successors
Successors.erase(std::remove_if(Successors.begin(), Successors.end(),
[NewNode](auto WeakNode) {
return WeakNode.lock() == NewNode;
}),
Successors.end());
Successors.erase(
std::remove(Successors.begin(), Successors.end(), NewNode.get()),
Successors.end());

// Add all input nodes from the subgraph as successors for this node
// instead
Expand All @@ -1339,12 +1337,9 @@ void exec_graph_impl::duplicateNodes() {
auto &Predecessors = SuccNode.MPredecessors;

// Remove the subgraph node from this nodes successors
Predecessors.erase(std::remove_if(Predecessors.begin(),
Predecessors.end(),
[NewNode](auto WeakNode) {
return WeakNode.lock() == NewNode;
}),
Predecessors.end());
Predecessors.erase(
std::remove(Predecessors.begin(), Predecessors.end(), NewNode.get()),
Predecessors.end());

// Add all Output nodes from the subgraph as predecessors for this node
// instead
Expand Down
32 changes: 13 additions & 19 deletions sycl/source/detail/graph/node_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
/// Unique identifier for this node.
id_type MID = getNextNodeID();
/// List of successors to this node.
std::vector<std::weak_ptr<node_impl>> MSuccessors;
std::vector<node_impl *> MSuccessors;
/// List of predecessors to this node.
///
/// Using weak_ptr here to prevent circular references between nodes.
std::vector<std::weak_ptr<node_impl>> MPredecessors;
std::vector<node_impl *> MPredecessors;
/// Type of the command-group for the node.
sycl::detail::CGType MCGType = sycl::detail::CGType::None;
/// User facing type of the node.
Expand All @@ -123,26 +123,22 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
/// Add successor to the node.
/// @param Node Node to add as a successor.
void registerSuccessor(node_impl &Node) {
if (std::find_if(MSuccessors.begin(), MSuccessors.end(),
[&Node](const std::weak_ptr<node_impl> &Ptr) {
return Ptr.lock().get() == &Node;
}) != MSuccessors.end()) {
if (std::find(MSuccessors.begin(), MSuccessors.end(), &Node) !=
MSuccessors.end()) {
return;
}
MSuccessors.push_back(Node.weak_from_this());
MSuccessors.push_back(&Node);
Node.registerPredecessor(*this);
}

/// Add predecessor to the node.
/// @param Node Node to add as a predecessor.
void registerPredecessor(node_impl &Node) {
if (std::find_if(MPredecessors.begin(), MPredecessors.end(),
[&Node](const std::weak_ptr<node_impl> &Ptr) {
return Ptr.lock().get() == &Node;
}) != MPredecessors.end()) {
if (std::find(MPredecessors.begin(), MPredecessors.end(), &Node) !=
MPredecessors.end()) {
return;
}
MPredecessors.push_back(Node.weak_from_this());
MPredecessors.push_back(&Node);
}

/// Construct an empty node.
Expand Down Expand Up @@ -393,15 +389,13 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
Visited.push_back(this);

printDotCG(Stream, Verbose);
for (const auto &Dep : MPredecessors) {
auto NodeDep = Dep.lock();
Stream << " \"" << NodeDep.get() << "\" -> \"" << this << "\""
<< std::endl;
for (node_impl *Pred : MPredecessors) {
Stream << " \"" << Pred << "\" -> \"" << this << "\"" << std::endl;
}

for (std::weak_ptr<node_impl> Succ : MSuccessors) {
if (MPartitionNum == Succ.lock()->MPartitionNum)
Succ.lock()->printDotRecursive(Stream, Visited, Verbose);
for (node_impl *Succ : MSuccessors) {
if (MPartitionNum == Succ->MPartitionNum)
Succ->printDotRecursive(Stream, Visited, Verbose);
}
}

Expand Down
Loading
Loading