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

[GPU] Use array for tracking memory usage instead of map #25269

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ialbrecht
Copy link

Details:

  • Any additional locking and synchronization on memory allocation might have negative impact on MT execution.
  • std::map has very slow access are requires lock on every access. We can use std::array instead to hold compile time known number of buckets.
  • array container has lower access latency and memory overhead.
  • We might me able to remove mutex lock on stat collection.

`std::map` has very slow access are requires lock on every access. We can use `std::array` instead to hold compile time known number of buckets. This method should have less latency and memory overhead, as well as possibly no lock on access.
@ialbrecht ialbrecht requested review from a team as code owners June 27, 2024 20:50
@github-actions github-actions bot added the category: GPU OpenVINO GPU plugin label Jun 27, 2024
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Jun 27, 2024
No need to lock mutex to update atomic values
@rkazants
Copy link
Contributor

build_jenkins

@rkazants rkazants added the ExternalIntelPR External contributor from Intel label Jun 28, 2024
@rkazants
Copy link
Contributor

Hi @ialbrecht,
any data with concrete numbers on how it can affect MT execution in your case?

@ialbrecht
Copy link
Author

Hi @ialbrecht, any data with concrete numbers on how it can affect MT execution in your case?

We had benchmarks were memory allocation was on the critical performance path and we were looking at all possible ways to optimize it.

Make sure atomic values are zero initialized.
@vladimir-paramuzov vladimir-paramuzov changed the title Use array for tracking memory usage instead of map [GPU] Use array for tracking memory usage instead of map Jul 3, 2024
_peak_memory_usage_map[type] = _memory_usage_map[type].load();
auto idx = static_cast<size_t>(type);
_memory_usage_data[idx] += bytes;
auto new_val = _memory_usage_data[idx].fetch_add(bytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the part above has a mistake - you count bytes twice (+= and fetch_add).
So I think here you need to replace fetch_add with load()

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. Still trying to get used to git and revieing my own diffs...

Copy link
Contributor

Choose a reason for hiding this comment

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

fetch_add returns value before sum. I think it should be either:

auto new_val = _memory_usage_data[idx].fetch_add(bytes) + bytes;

or

_memory_usage_data[idx] += bytes;
auto new_val = _memory_usage_data[idx].load();

`fetch_add` returns old value, therefore we need to increment current memory usage value before storing current max.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: GPU OpenVINO GPU plugin ExternalIntelPR External contributor from Intel ExternalPR External contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants