Skip to content
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

Retrieve additional info #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions GPUtil/GPUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
__version__ = '1.4.0'

class GPU:
def __init__(self, ID, uuid, load, memoryTotal, memoryUsed, memoryFree, driver, gpu_name, serial, display_mode, display_active, temp_gpu):
def __init__(self, ID, uuid, load, memoryTotal, memoryUsed, memoryFree, driver, gpu_name, serial, display_mode, display_active, temp_gpu, core_clock, memory_clock, vbios_version, fan_speed, power_draw, power_limit):
self.id = ID
self.uuid = uuid
self.load = load
Expand All @@ -52,11 +52,18 @@ def __init__(self, ID, uuid, load, memoryTotal, memoryUsed, memoryFree, driver,
self.memoryUsed = memoryUsed
self.memoryFree = memoryFree
self.driver = driver
self.vbios_version = vbios_version
self.name = gpu_name
self.serial = serial
self.display_mode = display_mode
self.display_active = display_active
self.temperature = temp_gpu
self.fan_speed = fan_speed
self.power_draw = power_draw
self.power_limit = power_limit
self.core_clock = core_clock
self.memory_clock = memory_clock


def safeFloatCast(strNumber):
try:
Expand All @@ -78,7 +85,7 @@ def getGPUs():

# Get ID, processing and memory utilization for all GPUs
try:
p = Popen([nvidia_smi,"--query-gpu=index,uuid,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode,temperature.gpu", "--format=csv,noheader,nounits"], stdout=PIPE)
p = Popen([nvidia_smi,"--query-gpu=index,uuid,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode,temperature.gpu,clocks.current.graphics,clocks.current.memory,vbios_version,fan.speed,power.draw,power.limit", "--format=csv,noheader,nounits"], stdout=PIPE)
stdout, stderror = p.communicate()
except:
return []
Expand All @@ -96,7 +103,7 @@ def getGPUs():
#print(line)
vals = line.split(', ')
#print(vals)
for i in range(12):
for i in range(len(vals)):
# print(vals[i])
if (i == 0):
deviceIds = int(vals[i])
Expand All @@ -121,8 +128,20 @@ def getGPUs():
elif (i == 10):
display_mode = vals[i]
elif (i == 11):
temp_gpu = safeFloatCast(vals[i]);
GPUs.append(GPU(deviceIds, uuid, gpuUtil, memTotal, memUsed, memFree, driver, gpu_name, serial, display_mode, display_active, temp_gpu))
temp_gpu = safeFloatCast(vals[i])
elif (i==12):
core_clock = int(vals[i])
elif (i==13):
memory_clock = int(vals[i])
elif (i==14):
vbios_version = vals[i]
elif (i==15):
fan_speed = int(vals[i])
elif (i==16):
power_draw = safeFloatCast(vals[i])
elif (i==17):
power_limit = safeFloatCast(vals[i])
GPUs.append(GPU(deviceIds, uuid, gpuUtil, memTotal, memUsed, memFree, driver, gpu_name, serial, display_mode, display_active, temp_gpu, core_clock, memory_clock, vbios_version, fan_speed, power_draw, power_limit))
return GPUs # (deviceIds, gpuUtil, memUtil)


Expand Down Expand Up @@ -210,10 +229,11 @@ def showUtilization(all=False, attrList=None, useOldCode=False):
GPUs = getGPUs()
if (all):
if (useOldCode):
print(' ID | Name | Serial | UUID || GPU util. | Memory util. || Memory total | Memory used | Memory free || Display mode | Display active |')
print('------------------------------------------------------------------------------------------------------------------------------')
print(' ID | Name | Serial | UUID || GPU util. | Memory util. || Memory total | Memory used | Memory free || Display mode | Display active || Core Clock | Memory Clock || Fan Speed | Power draw ')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------')
for gpu in GPUs:
print(' {0:2d} | {1:s} | {2:s} | {3:s} || {4:3.0f}% | {5:3.0f}% || {6:.0f}MB | {7:.0f}MB | {8:.0f}MB || {9:s} | {10:s}'.format(gpu.id,gpu.name,gpu.serial,gpu.uuid,gpu.load*100,gpu.memoryUtil*100,gpu.memoryTotal,gpu.memoryUsed,gpu.memoryFree,gpu.display_mode,gpu.display_active))
print(' {0:2d} | {1:s} | {2:s} | {3:s} || {4:3.0f}% | {5:3.0f}% || {6:.0f}MB | {7:.0f}MB | {8:.0f}MB || {9:s} | {10:s} || {11:d}Mhz | {12:d}Mhz || {13:2.0f}% | {14:2.0f}w'
.format(gpu.id,gpu.name,gpu.serial,gpu.uuid,gpu.load*100,gpu.memoryUtil*100,gpu.memoryTotal,gpu.memoryUsed,gpu.memoryFree,gpu.display_mode,gpu.display_active,gpu.core_clock,gpu.memory_clock,gpu.fan_speed,gpu.power_draw))
else:
attrList = [[{'attr':'id','name':'ID'},
{'attr':'name','name':'Name'},
Expand All @@ -226,16 +246,20 @@ def showUtilization(all=False, attrList=None, useOldCode=False):
{'attr':'memoryUsed','name':'Memory used','suffix':'MB','precision':0},
{'attr':'memoryFree','name':'Memory free','suffix':'MB','precision':0}],
[{'attr':'display_mode','name':'Display mode'},
{'attr':'display_active','name':'Display active'}]]
{'attr':'display_active','name':'Display active'}],
[{'attr':'core_clock','name':'Core Clock'},
{'attr':'memory_clock','name':'Memory Clock'}],
[{'attr':'fan_speed','name':'Fan Speed'},
{'attr':'power_draw','name':'Power draw'}]
]

else:
if (useOldCode):
print(' ID GPU MEM')
print('--------------')
for gpu in GPUs:
print(' {0:2d} {1:3.0f}% {2:3.0f}%'.format(gpu.id, gpu.load*100, gpu.memoryUtil*100))
elif attrList is None:
# if `attrList` was not specified, use the default one
else:
attrList = [[{'attr':'id','name':'ID'},
{'attr':'load','name':'GPU','suffix':'%','transform': lambda x: x*100,'precision':0},
{'attr':'memoryUtil','name':'MEM','suffix':'%','transform': lambda x: x*100,'precision':0}],
Expand Down
2 changes: 1 addition & 1 deletion GPUtil/demo_GPUtil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import GPUtil as GPU
import sys
# Get all device ids and their processing and memory utiliazion
# Get all device ids and their processing and memory utilization
# (deviceIds, gpuUtil, memUtil) = GPU.getGPUs()

# Print os and python version information
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ Helper class handle the attributes of each GPU. Quoted descriptions are copied f
* `serial` - This number matches the serial number physically printed on each board. It is a globally unique immutable alphanumeric value.
* `display_mode` - "A flag that indicates whether a physical display (e.g. monitor) is currently connected to any of the GPU's connectors. "Enabled" indicates an attached display. "Disabled" indicates otherwise."
* `display_active` - "A flag that indicates whether a display is initialized on the GPU's (e.g. memory is allocated on the device for display). Display can be active even when no monitor is physically attached. "Enabled" indicates an active display. "Disabled" indicates otherwise."
* `vbios_version` - "Bios version installed on the GPU."
* `fan_speed` - "Current fan speed."
* `power_draw` - "Current consumption of the GPU. The value is expressed in Watt."
* `power_limit` - "Max power that the GPU can consume."
* `core_clock` - "Current core clock."
* `memory_clock` - "Current memory clock."

```python
GPUs = GPUtil.getGPUs()
Expand Down