-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
316 lines (243 loc) · 8.96 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import re
import os
import datetime
import json
import copy
import math
# this file is run by the mkdocs macros plugin
base_gpu_info = {
'a40':{'ram':'48GB','cc':'sm_86'},
'a100_1g.5gb':{'ram':'5GB','cc':'sm_80'},
'a100_2g.10gb':{'ram':'10GB','cc':'sm_80'},
'a100_3g.20gb':{'ram':'20GB','cc':'sm_80'},
'a100-pcie':{'ram':'40GB','cc':'sm_80'},
'a100-sxm4-80gb':{'ram':'80GB','cc':'sm_80'},
'v100-fhhl-16G':{'ram':'16GB','cc':'sm_70'},
'v100-pcie-16G':{'ram':'16GB','cc':'sm_70'},
'v100-pcie-32G':{'ram':'32GB','cc':'sm_70'},
'v100-sxm2-32G':{'ram':'32GB','cc':'sm_70'},
'rtx_2080_Ti':{'ram':'11GB','cc':'sm_75'},
'rtx_6000':{'ram':'24GB','cc':'sm_75'},
'gtx_1080_ti':{'ram':'11GB','cc':'sm_61'},
}
def parse_features(input):
return [feature for feature in input.split(",")]
def format_features(features):
displayed_features = []
# keep the highest
if "AVX512" in features:
displayed_features.append("AVX512")
elif "AVX2" in features:
displayed_features.append("AVX2")
elif "AVX" in features:
displayed_features.append("AVX")
if "NVLINK" in features:
displayed_features.append("NVLINK")
if "EL9" in features:
displayed_features.append("EL9")
return "<br />".join(displayed_features)
def parse_gres(input):
gres = {}
if input != "(null)":
for match in re.finditer(r'gpu:(?P<card_type>[^:]+):(?P<quantity>\d+)\([S0-9_:,-]+\),?', input):
if match.group('card_type') not in gres:
gres[match.group('card_type')] = int(match.group('quantity'))
else:
gres[match.group('card_type')] += int(match.group('quantity'))
return gres
def parse_sinfo_line(server_info, line):
hostname, partition, sockets, cores_per_socket, threads_per_core, ram_in_mb, features, gres = line.strip().split("|")
# memory reserved for system use
# no way to get this from sinfo
# presently 10240 for all nodes
mem_spec_limit = 10240
if hostname not in server_info:
server_info[hostname] = {
"partitions":[],
"cores": int(sockets) * int(cores_per_socket) * int(threads_per_core),
"memory": math.floor((int(ram_in_mb) - int(mem_spec_limit)) / 1024),
"features": parse_features(features),
"gpus": parse_gres(gres),
}
if partition != "whatever*":
server_info[hostname]["partitions"].append(partition)
def parse_slurm_conf_line(partition_info, line):
info = {}
line = line.strip()
for item in line.split(' '):
key, value = item.split('=')
info[key] = value
partition_info[info['PartitionName']] = info
def parse_host_procs(host_processors_info, line):
info = {}
line = line.strip()
hostname, processor = line.split("\t")
processor = processor.replace(" CPU ", " ")
processor = processor.replace("(R)", "")
processor = processor.replace("(TM)", "")
processor = processor.replace(" 32-Core Processor", "")
processor = processor.split(" @ ")[0]
host_processors_info[hostname] = processor
def get_gpu_info(server_info):
gpu_info = copy.deepcopy(base_gpu_info)
for gpu_type in gpu_info:
gpu_info[gpu_type]["quantity"] = 0
gpu_info[gpu_type]["nodelist"] = []
for hostname in server_info:
hinfo = server_info[hostname]
if "gpu" not in hinfo["partitions"]:
continue
for gpu_type, gpu_quantity in hinfo["gpus"].items():
gpu_info[gpu_type]["quantity"] += gpu_quantity
gpu_info[gpu_type]["nodelist"].append(hostname.split(".")[0])
return gpu_info
def define_env(env):
"Hook function"
server_info = {}
with open(os.path.dirname(os.path.realpath(__file__)) + '/data/sinfo.txt', 'r') as input_file:
for line in input_file:
parse_sinfo_line(server_info, line)
partition_info = {}
with open(os.path.dirname(os.path.realpath(__file__)) + '/data/slurm.conf', 'r') as input_file:
for line in input_file:
parse_slurm_conf_line(partition_info, line)
host_processors_info = {}
with open(os.path.dirname(os.path.realpath(__file__)) + '/data/procs.txt', 'r') as input_file:
for line in input_file:
parse_host_procs(host_processors_info, line)
@env.macro
def partition_hardware_table(partition):
table = """
<table class="docutils">
""".strip()
table += """
<thead>
<tr>
<th>Server Name</th>
<th>CPU Model</th>
<th>CPU Cores</th>
<th>RAM</th>
<th>Features</th>
</tr>
</thead>
""".strip()
for hostname in server_info:
hinfo = server_info[hostname]
features = format_features(hinfo["features"])
cpu_model = ""
if hostname in host_processors_info:
cpu_model = host_processors_info[hostname]
if partition in hinfo["partitions"]:
table += f"""
<tr>
<td>{hostname}</td>
<td>{cpu_model}</td>
<td>{hinfo["cores"]}</td>
<td>{hinfo["memory"]} GB</td>
<td>{features}</td>
</tr>
""".strip()
table += "</table>".strip()
return table
@env.macro
def partition_info_section(partition):
pinfo = partition_info[partition]
max_time_list = pinfo['MaxTime'].split('-')
if len(max_time_list) > 1:
max_time = max_time_list[0] + " days"
else:
t = datetime.datetime.strptime(max_time_list[0],"%H:%M:%S")
max_time = f"{t.hour} hours"
timeslicing = "enabled" if "FORCE" in pinfo['OverSubscribe'] else "disabled"
info_section = f"""
Jobs on this partition have a max runtime of {max_time}, and time slicing is {timeslicing}.
""".strip()
return info_section
@env.macro
def gpu_partition_hardware_table(partition):
table = """
<table class="docutils">
""".strip()
table += """
<thead>
<tr>
<th>Server Name</th>
<th>GPUs</th>
<th>CPU Cores</th>
<th>RAM</th>
<th>Features</th>
</tr>
</thead>
""".strip()
for hostname in server_info:
hinfo = server_info[hostname]
gpus = "<br />".join([f"{gpu_type} x {gpu_quantity}" for gpu_type, gpu_quantity in hinfo["gpus"].items()])
features = format_features(hinfo["features"])
if partition in hinfo["partitions"]:
table += f"""
<tr>
<td>{hostname}</td>
<td>{gpus}</td>
<td>{hinfo["cores"]}</td>
<td>{hinfo["memory"]} GB</td>
<td>{features}</td>
</tr>
""".strip()
table += "</table>".strip()
return table
@env.macro
def gpu_types_table():
gpu_info = get_gpu_info(server_info)
table = """
<table class="docutils">
""".strip()
table += """
<thead>
<tr>
<th>GPU Type</th>
<th>RAM</th>
<th><a href="https://developer.nvidia.com/cuda-gpus">Compute Capability</a></th>
<th>Quantity</th>
</tr>
</thead>
""".strip()
for gpu_type, gpu_stats in gpu_info.items():
if gpu_stats["quantity"] == 0:
continue
table += f"""
<tr>
<td>{gpu_type}</td>
<td>{gpu_stats["ram"]}</td>
<td>{gpu_stats["cc"]}</td>
<td>{gpu_stats["quantity"]}</td>
</tr>
""".strip()
table += "</table>".strip()
return table
@env.macro
def job_script_generator_acceptable_gpus_names():
gpu_info = get_gpu_info(server_info)
acceptable_names = [x for x in gpu_info if gpu_info[x]["quantity"] > 0]
return json.dumps(acceptable_names)
@env.macro
def job_script_generator_acceptable_gpus_info():
gpu_info = get_gpu_info(server_info)
return json.dumps(gpu_info)
@env.macro
def job_script_generator_partition_info():
pinfo = {}
for hostname in server_info:
hinfo = server_info[hostname]
for partition in hinfo["partitions"]:
if partition not in pinfo:
pinfo[partition] = {
"max_ram": hinfo["memory"],
"max_cores": hinfo["cores"]
}
else:
pinfo[partition]["max_ram"] = max(pinfo[partition]["max_ram"], hinfo["memory"])
pinfo[partition]["max_cores"] = max(pinfo[partition]["max_cores"], hinfo["cores"])
return json.dumps(pinfo)
@env.macro
def recommended_mlgpu_version():
return "20230427"