Created
September 23, 2016 00:37
-
-
Save telegraphic/ecb8161aedb02d3a09e39f9585e91735 to your computer and use it in GitHub Desktop.
Parse nvidia-smi from python
This file contains 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
""" | |
Parse output of nvidia-smi into a python dictionary. | |
This is very basic! | |
""" | |
import subprocess | |
import pprint | |
sp = subprocess.Popen(['nvidia-smi', '-q'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
out_str = sp.communicate() | |
out_list = out_str[0].split('\n') | |
out_dict = {} | |
for item in out_list: | |
try: | |
key, val = item.split(':') | |
key, val = key.strip(), val.strip() | |
out_dict[key] = val | |
except: | |
pass | |
pprint.pprint(out_dict) |
One point need to be paid attention to.
If there are two or more processes on GPUs, the dict will overwrite the value of the key "Process ID",
also other keys.
Just in case you didn't know... http://pypi.python.org/pypi/nvidia-ml-py/
The page has no description or documentation on how to use it. Did you find any resources on how to use the pip package?
@amanuel1995 -- that package is looking a bit old now, but here's some alternative links:
https://github.com/jonsafari/nvidia-ml-py
https://github.com/nicolargo/nvidia-ml-py3
https://github.com/petronny/nvsmi
https://github.com/fbcotter/py3nvml
I haven't been keeping up to date on this front though, so there may be a better approach!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I create a repo to do this.
It parses and maps the output of
nvidia-smi -q
into a Python object.You can get the attributes like:
And I have re-implemented the table when running
nvidia-smi
.Please see https://github.com/petronny/nvsmi