-
Notifications
You must be signed in to change notification settings - Fork 61
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 cupy to measure memory leak #777
Use cupy to measure memory leak #777
Conversation
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.
I'm much happier with this change than #776. Thank you!
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.
Agree that using cuda-python is preferable to GPUtil. We can also get this info from CuPy without adding the dependency, though (see suggestion). Let me know what you think.
dependencies.yaml
Outdated
packages: | ||
- cuda-python>=12.0,<13.0a0 | ||
- matrix: {cuda: "11.*"} | ||
packages: &test_cuda_python_cu11 |
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.
out of curiosity, what does this &test_cuda_python_cu11
notation do?
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.
This is a YAML anchor. We use this to define a list that we re-use in *test_cuda_python_cu11
. We need a "fallback" list when the cuda
selector is not defined.
def get_used_gpu_memory_mib(): | ||
"""Get the used GPU memory in MiB.""" | ||
status, free, total = cuda.cudart.cudaMemGetInfo() | ||
if status != cuda.cudart.cudaError_t.cudaSuccess: | ||
raise RuntimeError("Failed to get GPU memory info.") | ||
memory_used = (total - free) / (2**20) | ||
return memory_used | ||
|
||
status, num_gpus = cuda.cudart.cudaGetDeviceCount() | ||
if status != cuda.cudart.cudaError_t.cudaSuccess or num_gpus == 0: |
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.
We can also potentially just use CuPy for this and avoid having to add the cuda-python dependency:
add up top:
import cupy as cp
then can use here:
def get_used_gpu_memory_mib():
"""Get the used GPU memory in MiB."""
dev = cp.cuda.Device()
free, total = dev.mem_info
memory_used = (total - free) / (2**20)
return memory_used
num_gpus = cp.cuda.runtime.getDeviceCount()
if num_gpus == 0:
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.
Great. I'll implement that and remove the cuda-python dependency.
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.
re-approving, awesome that the net result here is -1 dependencies 😁
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 great, thanks!
Thanks @bdice for fixing the issue! |
/merge |
While adding support for Python 3.12 in #773, we found a problem where
GPUtil
does not support Python 3.12 (#775).This PR removes the dependency on
GPUtil
and replaces it withcupy
, which is already a dependency.Closes #775. Closes #776.