-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgpu.py
More file actions
35 lines (26 loc) · 1012 Bytes
/
gpu.py
File metadata and controls
35 lines (26 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""This module fetches GPU information and returns a JSON with the GPU data"""
import GPUtil
class GPUdata:
"""Class to fetch, format and return GPU information"""
gpudata = None
def __init__(self):
self.gpudata = []
def check_attr(self,attr, val):
try:
val = getattr(attr, val)
except: # pylint: disable=bare-except
val = None
return val
def retrieve_gpu_info(self):
gpu = GPUtil.getGPUs()
for x in gpu:
gpu = {}
gpu["name"] = self.check_attr(x,"gpu_name")
gpu["uuid"] = self.check_attr(x,"uuid")
gpu["serial_number"] = self.check_attr(x,"serial")
gpu["load"] = self.check_attr(x,"load")
gpu["total_memory"] = self.check_attr(x,"memoryTotal")
gpu["memory_used"] = self.check_attr(x,"memoryUsed")
gpu["memory_free"] = self.check_attr(x,"memoryFree")
self.gpudata.append(gpu)
return self.gpudata