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] Enable memory reuse for nested graphs #27521

Conversation

EgorDuplensky
Copy link
Contributor

@EgorDuplensky EgorDuplensky commented Nov 12, 2024

Details:

  • All the nested graphs are now must be a part of a global memory reuse logic
  • The core logic of the memory reuse is untouched (a bit refactored)
  • Instead of solving memory reuse for every graph / subgraph, now all the edges and global execution indices are collected from the "virtually flatten" graph first and then memory reuse is solved once for a model.
  • All the nodes with nested graphs are updated, including:
    1. LoRa
    2. Composite
    3. If
    4. TensorIterator
    5. Convolution + Sum fallback subgraph

Tickets:

  • ticket-id

@EgorDuplensky EgorDuplensky requested review from a team as code owners November 12, 2024 10:53
@github-actions github-actions bot added category: inference OpenVINO Runtime library - Inference category: CPU OpenVINO CPU plugin category: build OpenVINO cmake script / infra labels Nov 12, 2024
@EgorDuplensky EgorDuplensky changed the title Enable memory reuse for nested graps Enable memory reuse for nested graphs Nov 12, 2024
@EgorDuplensky EgorDuplensky changed the title Enable memory reuse for nested graphs [CPU] Enable memory reuse for nested graphs Nov 12, 2024
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch from da1d1a0 to 18563de Compare November 12, 2024 15:27
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch 2 times, most recently from 4734e61 to e140018 Compare November 13, 2024 13:32
@github-actions github-actions bot removed the category: inference OpenVINO Runtime library - Inference label Nov 13, 2024
@EgorDuplensky
Copy link
Contributor Author

@maxnick Ready for review. Could you please take a look?

@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch from e140018 to d5bda07 Compare November 13, 2024 13:51
@EgorDuplensky
Copy link
Contributor Author

Added a fix for Convolution + Sum fallback graph.
Now such graph is also a part of memory reuse.

src/plugins/intel_cpu/src/compiled_model.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/edge.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/edge.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/node.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/composite.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/conv.cpp Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/lora.cpp Outdated Show resolved Hide resolved
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch 2 times, most recently from 408e748 to 11a5115 Compare November 25, 2024 15:28
src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch 2 times, most recently from 7f3fadf to 9e170ae Compare December 10, 2024 17:56
Copy link
Contributor

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label Dec 26, 2024
@mg-intel mg-intel removed the Stale label Jan 2, 2025
Copy link
Contributor

This PR will be closed in a week because of 2 weeks of no activity.

@github-actions github-actions bot added the Stale label Jan 17, 2025
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch 3 times, most recently from ed7ca84 to 467ef3b Compare January 28, 2025 17:32
Comment on lines +28 to +29
m_auxiliaryNetworkMemoryControl(std::make_shared<NetworkMemoryControl>()),
m_memoryControl(m_auxiliaryNetworkMemoryControl->createMemoryControlUnit()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmitry-gorokhov I decided to not create a wrapper around m_auxiliaryNetworkMemoryControl and m_memoryControl.
Instead, it is redesigned, so m_memoryControl is just one memory control instance of m_auxiliaryNetworkMemoryControl

src/plugins/intel_cpu/src/node.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/lora.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/edge.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/infer_request.cpp Outdated Show resolved Hide resolved
Comment on lines +1151 to +1136
if (memoryControl->allocated()) {
return; // memory is already allocated globally
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem here is the way the legacy graph pipeline stages are implemented.
With a proper pipeline such situation will not be possible.

src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/compiled_model.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/compiled_model.h Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/memory.cpp Outdated Show resolved Hide resolved
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch 3 times, most recently from 9ac1226 to 2497eb3 Compare January 30, 2025 12:19
src/plugins/intel_cpu/src/compiled_model.h Outdated Show resolved Hide resolved
Comment on lines +1151 to +1136
if (memoryControl->allocated()) {
return; // memory is already allocated globally
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any plans of implementing the proper pipeline? How it should look like?

src/plugins/intel_cpu/src/graph.cpp Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/graph_context.h Show resolved Hide resolved
src/plugins/intel_cpu/src/infer_request.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/if.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/if.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/input.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/memory.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/memory.cpp Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/memory.cpp Outdated Show resolved Hide resolved
src/plugins/intel_cpu/src/nodes/lora.cpp Show resolved Hide resolved
src/plugins/intel_cpu/tests/unit/graph/memory_state.cpp Outdated Show resolved Hide resolved
@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch from c1d5f75 to 482a180 Compare February 3, 2025 18:10
@EgorDuplensky
Copy link
Contributor Author

@maxnick Could you please check one more time?

@maxnick maxnick added this to the 2025.1 milestone Feb 4, 2025
@maxnick
Copy link
Contributor

maxnick commented Feb 5, 2025

@dmitry-gorokhov , could you please make the final review?

@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch from 5f112c1 to aa3a98b Compare February 5, 2025 20:45
@EgorDuplensky
Copy link
Contributor Author

Rebased to fix merge conflict

@EgorDuplensky EgorDuplensky force-pushed the enable_memory_reuse_for_nested_graphs branch from aa3a98b to 3c5620c Compare February 6, 2025 12:44
@maxnick maxnick added this pull request to the merge queue Feb 6, 2025
Merged via the queue into openvinotoolkit:master with commit be3edd1 Feb 6, 2025
181 checks passed
@maxnick maxnick deleted the enable_memory_reuse_for_nested_graphs branch February 6, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: CPU OpenVINO CPU plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants