Created
July 27, 2018 22:06
-
-
Save vardaan123/53a49a789b27bf829bb3799c60e26705 to your computer and use it in GitHub Desktop.
GPU memory consumption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_gpu_memory_map(): | |
"""Get the current gpu usage. | |
Returns | |
------- | |
usage: dict | |
Keys are device ids as integers. | |
Values are memory usage as integers in MB. | |
""" | |
result = subprocess.check_output( | |
[ | |
'nvidia-smi', '--query-gpu=memory.used', | |
'--format=csv,nounits,noheader' | |
], encoding='utf-8') | |
# Convert lines into a dictionary | |
gpu_memory = [int(x) for x in result.strip().split('\n')] | |
gpu_memory_map = dict(zip(range(len(gpu_memory)), gpu_memory)) | |
print(gpu_memory_map) | |
return gpu_memory_map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment