-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
[GPU] Use array for tracking memory usage instead of map #25269
Conversation
`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.
No need to lock mutex to update atomic values
build_jenkins |
Hi @ialbrecht, |
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.
_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); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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();
As in description
`fetch_add` returns old value, therefore we need to increment current memory usage value before storing current max.
Details:
std::map
has very slow access are requires lock on every access. We can usestd::array
instead to hold compile time known number of buckets.array
container has lower access latency and memory overhead.