Advertisement
Guest User

sge load sensor for nvidia gpgpus

a guest
Nov 22nd, 2011
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import subprocess
  4. from xml.etree import ElementTree
  5. from sys import stderr
  6.  
  7. try:
  8.     p = subprocess.Popen(["uname", "-n"],
  9.         stdout=subprocess.PIPE,
  10.         stderr=subprocess.STDOUT)
  11.     p.wait()
  12.     hostname = p.communicate()[0].strip()
  13. except:
  14.     print >> stderr, "Oops. Couldn't determine my hostname using `uname`"
  15.     exit(1)
  16.  
  17. def getUnoccupiedGPUCount():
  18.     result = 0
  19.     try:
  20.         p = subprocess.Popen(["nvidia-smi", "-q", "-x"],
  21.             stdout=subprocess.PIPE,
  22.             stderr=subprocess.STDOUT)
  23.         p.wait()
  24.         xmlt = ElementTree.XML(p.communicate()[0])
  25.         for gpu in xmlt.getiterator(tag="gpu"):
  26.             if len(gpu.find("compute_processes").getchildren()) < 1:
  27.                 result += 1
  28.     except:
  29.         result = 0
  30.         print >> stderr, "Oops. Something went wrong, when I tried reading from nvidia-smi. I will exit now!"
  31.         exit(1)
  32.     return result
  33.  
  34. while(True):
  35.     cmd = ""
  36.     try:
  37.         cmd = raw_input()
  38.     except:
  39.         pass
  40.  
  41.     if cmd == "quit":
  42.         exit()
  43.  
  44.     print "begin\n"+hostname+":gpu:"+str(getUnoccupiedGPUCount())+"\nend"
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement