Skip to content

[NFC][SYCL][Graph] Introduce nodes_range utility #19295

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 7, 2025

Conversation

aelovikov-intel
Copy link
Contributor

@aelovikov-intel aelovikov-intel commented Jul 3, 2025

It looks like lots of std::vector<std::weak_ptr<node_impl>> aren't actually used for lifetime management and aren't expected to ever have an "expired" std::weak_ptr. As such, it would make sense to transition many of them to raw pointers/references (e.g.
std::vector<node_impl *>). This utility should help to make such transition a bit easier.

However, I expect it to be useful even after the elimination of unnecessary weak_ptrs and that can be seen even as part of this PR already.

  • Scenario A: we need to process both std::vector<node_impl *> passed around as function parameters or created as a local variable on stack, and std::vector<node> or std::vector<std::shared_ptr<node_impl>> that is used for lifetime management (e.g. handler's data member, or all the nodes in the graph). This utility would allow such an API to have a single overload to work with both scenarios.

  • Scenario B: no conversion between std::set->std::vector<> (already updated here) is necessary and no templates required to support them both via single overload.

Another potentially useful application would be to provide "getters" like
nodes_range node_impl::successors() to hide away implementation details of the underlying container.

@aelovikov-intel aelovikov-intel requested a review from a team as a code owner July 3, 2025 15:54
@aelovikov-intel aelovikov-intel requested a review from EwanC July 3, 2025 15:54
N.registerSuccessor(Node);
this->removeRoot(Node);
}
if (Node->MPredecessors.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the "root" invariant should be handled completely automatically between node_impl's ctor and add/removePredecessor methods. I'm not familiar with the implementation though, so can't state for certain that it would work and even if so, that should be left to a separate patch.

However, I've changed graph_impl::add overload to stop appending node_impls from std::set to an std::vector and am making to calls to addDepsToNode instead, hence this particular change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That refactor of how root nodes gets recording makes, sense but agree that's for a separate patch.

It looks like lots of `std::vector<std::weak_ptr<node_impl>>` aren't
actually used for lifetime management and aren't expected to ever have
an "expired" `std::weak_ptr`. As such, it would make sense to transition
many of them to raw pointers/references (e.g.
`std::vector<node_impl *>`). This utility should help to make such
transition a bit easier.

However, I expect it to be useful even after the elimination of
unnecessary `weak_ptr`s and that can be seen even as part of this PR
already.

* Scenario A: we need to process both `std::vector<node_impl *>` passed
around as function parameters or created as a local variable on stack,
and `std::vector<node>` or `std::vector<std::shared_ptr<node_impl>>`
that *is* used for lifetime management (e.g. `handler`'s data member, or
all the nodes in the graph). This utility would allow such an API to
have a single overload to work with both scenarios.

* Scenario B: no conversion between `std::set`->`std::vector<>` (already
updated here) is necessary and no templates required to support them
both via single overload.
@aelovikov-intel
Copy link
Contributor Author

aelovikov-intel commented Jul 3, 2025

For extra context, follow-up changes would look like this: 05d00da (not sure if I'll be able to split in multiple PRs yet).

Copy link
Contributor

@EwanC EwanC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your observation that the node weak-ptrs are expected to always be alive is correct. So the move to raw ptrs/reference is a good direction and this is a nice step to get there, thanks.

N.registerSuccessor(Node);
this->removeRoot(Node);
}
if (Node->MPredecessors.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That refactor of how root nodes gets recording makes, sense but agree that's for a separate patch.

@aelovikov-intel aelovikov-intel merged commit 322cd13 into intel:sycl Jul 7, 2025
28 of 29 checks passed
@aelovikov-intel aelovikov-intel deleted the nodes_range branch July 7, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants