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

[utils] add synchronized cuda memory monitor #740

Merged
merged 1 commit into from
Apr 13, 2022
Merged

[utils] add synchronized cuda memory monitor #740

merged 1 commit into from
Apr 13, 2022

Conversation

1SAA
Copy link
Contributor

@1SAA 1SAA commented Apr 12, 2022

No description provided.

@1SAA 1SAA requested a review from feifeibear April 12, 2022 09:11
def finish(self):
torch.cuda.synchronize()
self.time_stamps.append(time())
max_usage = torch.cuda.max_memory_allocated()
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pytorch uses a caching allocator.
max_memory_allocated returns maximum cuda memory used by tensors.
max_memory_reserved returns maximum cuda memory used by the allocator.
If user still has enough memory in GPU, caching allocator may not recycle unused segments.
So the reserved memory can be much bigger than allocated memory. This will bring inaccuracy when we trying
to know maximum memory used by all tensors.
But there is a possiblity that the maximum cuda memory used is bigger than memory allocated.
We are better to set the maximum cuda memory slightly smaller than the actual cuda memory.
So there is some memory to place buffer for Pytorch.

@1SAA 1SAA merged commit 340e59f into hpcaitech:main Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants