Skip to content

Instantly share code, notes, and snippets.

@telegraphic
Created September 23, 2016 00:37
Show Gist options
  • Save telegraphic/ecb8161aedb02d3a09e39f9585e91735 to your computer and use it in GitHub Desktop.
Save telegraphic/ecb8161aedb02d3a09e39f9585e91735 to your computer and use it in GitHub Desktop.
Parse nvidia-smi from python
"""
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)
@telegraphic
Copy link
Author

@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