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] Simplify edge clusters collection procedure #28876

Merged

Conversation

EgorDuplensky
Copy link
Contributor

@EgorDuplensky EgorDuplensky commented Feb 7, 2025

By utilizing the fact, that the base edge is always the first edge in the cluster.
This helps to avoid unnecessary looping when updating the referencing edges.
Also allocated dynamic output edges before the regions are created, so there is no need to create those regions and then removed them anyway.

@EgorDuplensky EgorDuplensky requested review from a team as code owners February 7, 2025 13:21
@github-actions github-actions bot added the category: CPU OpenVINO CPU plugin label Feb 7, 2025
@EgorDuplensky EgorDuplensky force-pushed the simplify_memory_reuse_new_3 branch 2 times, most recently from 240f806 to 8f6c29c Compare February 10, 2025 12:09
@EgorDuplensky EgorDuplensky force-pushed the simplify_memory_reuse_new_3 branch from 8f6c29c to ece7d35 Compare February 10, 2025 12:14
@dmitry-gorokhov
Copy link
Contributor

@maxnick Could you please take a look?

* - The first edge in the cluster (base edge) must have the status `NeedAllocation`.
* - All subsequent edges in the cluster must have the status `NotAllocated`.
*
* @param clusters A collection of edges.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add description for the second remaining parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* - base edge of a cluster is a "ov::element::string" type of edge
* - base edge of a cluster is a Constant edge
*
* @return a remaining number of clusters to process (left partition)
*/
static size_t AllocateStringsAndConstants(EdgeClusters& clusters, const GraphContext::CPtr& context) {
static size_t AllocateStringsAndConstants(EdgeClusters& clusters, size_t remaining, const GraphContext::CPtr& context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT. May be it does make sense to rename remaining to clusters_to_process within these subroutines? remaining makes sense within SolveMemoryReuse implementation, but at this level clusters_to_process would enhance code readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case remaining means remaining to allocate. I mean we are allocating the clusters piece by piece and after each step there are remaining clusters which still need to be allocated.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's simply more difficult to quickly figure out what does remaining means, and my proposal is to give it more obvious name.

@EgorDuplensky EgorDuplensky force-pushed the simplify_memory_reuse_new_3 branch from ece7d35 to 0f6bfb4 Compare February 19, 2025 13:04
* - base edge of a cluster is a "ov::element::string" type of edge
* - base edge of a cluster is a Constant edge
*
* @return a remaining number of clusters to process (left partition)
*/
static size_t AllocateStringsAndConstants(EdgeClusters& clusters, const GraphContext::CPtr& context) {
static size_t AllocateStringsAndConstants(EdgeClusters& clusters, size_t remaining, const GraphContext::CPtr& context) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case remaining means remaining to allocate. I mean we are allocating the clusters piece by piece and after each step there are remaining clusters which still need to be allocated.

* - The first edge in the cluster (base edge) must have the status `NeedAllocation`.
* - All subsequent edges in the cluster must have the status `NotAllocated`.
*
* @param clusters A collection of edges.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@EgorDuplensky
Copy link
Contributor Author

@maxnick Could you please take a look.
There is a chance this PR fixes and issue introduced by the original PR with memory reuse for nested graphs

Comment on lines +1161 to +1163
MemoryControl::MemorySolution solution;
EdgeClusters edgeClusters;
std::tie(solution, edgeClusters, m_outputNodesMemBlocks) =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxnick FYI
This change actually fixes regression introduced by the previous PR, because structured binding actually creates a new m_outputNodesMemBlocks variable which shadows the original member variable. So, member variable was not actually updated.

@EgorDuplensky EgorDuplensky force-pushed the simplify_memory_reuse_new_3 branch from 0f6bfb4 to 99ad44a Compare February 19, 2025 14:39
@EgorDuplensky
Copy link
Contributor Author

@maxnick Could you please take a look.
The PR includes a regression fix so we better to merge it asap.
Or we can merge this one I have created just in case which contains only the fix:

@maxnick maxnick added this pull request to the merge queue Feb 20, 2025
Merged via the queue into openvinotoolkit:master with commit fd5f91a Feb 20, 2025
183 checks passed
@maxnick maxnick deleted the simplify_memory_reuse_new_3 branch February 20, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: CPU OpenVINO CPU plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants