-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
72 lines (55 loc) · 1.98 KB
/
app.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
from flask import Flask, render_template
import datetime
import platform
import json
from _inspect_cuda import get_gpus
import config
app = Flask(__name__)
@app.route("/")
def index():
# Datetime
dt_str = datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y")
# Host name
page_title = platform.node()
main_title = f"{page_title} GPU Status".upper()
return render_template(
"index.html",
page_title=page_title,
main_title=main_title,
datetime_str=dt_str,
copyright_text=config.conf["copyright_text"],
)
@app.route("/status", methods=["POST"])
def status():
# Datetime
dt_str = datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y")
# Get GPUs
gpu_objects_dict, err_infos = get_gpus()
gpu_info_list = list(gpu_objects_dict.values())
# Driver version
driver_versions = set([g.driver_version for g in gpu_info_list])
cuda_versions = set([g.cuda_version for g in gpu_info_list])
driver_version = (
driver_versions.pop() if len(driver_versions) == 1 else tuple(driver_versions)
)
cuda_version = (
cuda_versions.pop() if len(cuda_versions) == 1 else tuple(cuda_versions)
)
# Processes
proc_info_list = [p for g in gpu_info_list for p in g.processes.values()]
for i in range(len(proc_info_list)):
# Set gloabl index
proc_info_list[i].global_index = i
return_data = {
"interval": config.conf["interval_ms"],
"datetime_str": dt_str,
"main_content" : render_template("status.html",
driver_version=driver_version,
cuda_version=cuda_version,
gpu_info_list=gpu_info_list,
proc_info_list=proc_info_list,
err_infos=err_infos)
}
return json.dumps(return_data)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=config.conf["port"], debug=True, threaded=True)