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

Use array for tracking memory usage instead of map #25269

Open
wants to merge 2 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?

std::map<allocation_type, std::atomic<uint64_t>> _memory_usage_map;
std::map<allocation_type, std::atomic<uint64_t>> _peak_memory_usage_map;
std::array<std::atomic<uint64_t>, static_cast<size_t>(allocation_type::max_value)> _memory_usage_data;
std::array<std::atomic<uint64_t>, static_cast<size_t>(allocation_type::max_value)> _peak_memory_usage_data;
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 array content has undefined values due to lack of explicit initialization

_memory_usage_data[idx] += bytes;
auto new_val = _memory_usage_data[idx].fetch_add(bytes);
// Make sure actual maximum value is stored
while (new_val > _peak_memory_usage_data[idx]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to have while instead of if here?

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