-
Notifications
You must be signed in to change notification settings - Fork 36
/
gfs.py
99 lines (74 loc) · 2.43 KB
/
gfs.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from atomicwrites import atomic_write
from subprocess import check_output, CalledProcessError
class Utilization:
def __init__(self, gpu, memory):
self.gpu = float(gpu)
self.memory = float(memory)
if self.gpu < 2:
self.gpu = 2
def set_gpu(self, gpu):
self.gpu = gpu
def set_mem(self, memory):
self.memory = memory
def set_id(self, id):
self.id = id
def set_cap(self, wa, wb):
self.cap = wa*self.gpu + wb*self.memory
output_gpu = check_output('nvidia-smi --query-gpu=utilization.gpu --format=csv', shell=True)
output_gpu_split = output_gpu.split('\n')
device_num = len(output_gpu_split) - 2
d_gpu = []
for i in range(device_num):
d_gpu.append(filter(str.isdigit, output_gpu_split[i+1]))
#print d_gpu[i]
output_memory = check_output('nvidia-smi --query-gpu=memory.used --format=csv', shell=True)
output_memory_split = output_memory.split('\n')
d_memory = []
for i in range(device_num):
d_memory.append(filter(str.isdigit, output_memory_split[i+1]))
#print d_memory[i]
output_memory = check_output('nvidia-smi --query-gpu=memory.total --format=csv', shell=True)
output_memory_split = output_memory.split('\n')
for i in range(device_num):
d_memory[i] = float(d_memory[i]) / float(filter(str.isdigit, output_memory_split[i+1]))
#print d_memory[i]
Wa = 0.5
Wb = 0.5
device_obj=[]
for i in range(device_num):
device_obj.append(Utilization(d_gpu[i], d_memory[i]))
device_obj[i].set_cap(Wa, Wb)
device_obj[i].set_id(i)
#print device_obj[i].gpu
#print device_obj[i].memory
#print device_obj[i].cap
#print device_obj[i].id
v_gpu = []
f_gpu = []
file = open('/home/coldfunction/qCUDA_0.2/qCUDA/.gpu_info', 'r')
for i in range(device_num):
line = file.readline()
num = float(line)
v_gpu.append(num)
f_gpu.append(num)
# if num == 0:
# print(num)
file.close()
for i in range(device_num):
if v_gpu[i] == 0:
v_gpu[i] = 1.0
device_obj[i].cap = (v_gpu[i] * device_obj[i].cap)
#print (device_obj[i].cap)
#print(v_gpu[i])
#print
device_obj.sort(key=lambda i: i.cap)
id = device_obj[0].id
f_gpu[id] = device_obj[0].cap
with atomic_write('/home/coldfunction/qCUDA_0.2/qCUDA/.gpu_info', overwrite=True) as f:
for i in range(device_num):
f.write(str(f_gpu[i]))
f.write('\n')
print id
#f = open(".select_g", 'w')
#s = str(device_obj[0].id)
#f.write(s)