-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu.py
97 lines (89 loc) · 3.1 KB
/
gpu.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
import platform
import subprocess
import time
def get_gpu_info():
system = platform.system()
if system == "Windows":
return get_gpu_info_windows()
elif system == "Linux":
return get_gpu_info_linux()
elif system == "Darwin":
return get_gpu_info_macos()
else:
raise NotImplementedError(f"Unsupported OS: {system}")
def get_gpu_info_windows():
gpus = []
try:
output = subprocess.check_output("wmic path win32_VideoController get name", shell=True)
lines = output.decode().split("\n")
for line in lines:
if line.strip() and line.strip() != "Name":
gpus.append(line.strip())
except Exception as e:
print(f"Error: {e}")
return gpus
def get_gpu_info_linux():
gpus = []
try:
output = subprocess.check_output("lspci | grep VGA", shell=True)
lines = output.decode().split("\n")
for line in lines:
if line.strip():
gpus.append(line.strip())
except Exception as e:
print(f"Error: {e}")
return gpus
def get_gpu_info_macos():
gpus = []
try:
output = subprocess.check_output("system_profiler SPDisplaysDataType", shell=True)
lines = output.decode().split("\n")
for line in lines:
if "Chipset Model:" in line:
gpus.append(line.split(":")[1].strip())
except Exception as e:
print(f"Error: {e}")
return gpus
def get_current_gpu_driver():
system = platform.system()
if system == "Windows":
return get_current_gpu_driver_windows()
elif system == "Linux":
return get_current_gpu_driver_linux()
elif system == "Darwin":
return get_current_gpu_driver_macos()
else:
raise NotImplementedError(f"Unsupported OS: {system}")
def get_current_gpu_driver_windows():
try:
output = subprocess.check_output("wmic path win32_VideoController get DriverVersion", shell=True)
lines = output.decode().split("\n")
for line in lines:
if line.strip() and line.strip() != "DriverVersion":
return line.strip()
except Exception as e:
print(f"Error: {e}")
return None
def get_current_gpu_driver_linux():
try:
output = subprocess.check_output("glxinfo | grep 'OpenGL version'", shell=True)
line = output.decode().strip()
if line:
return line.split(":")[1].strip()
except Exception as e:
if "glxinfo" in str(e):
print('Please install mesa-demos.')
else:
print(f"Error: {e}")
return None
def get_current_gpu_driver_macos():
try:
output = subprocess.check_output("system_profiler SPDisplaysDataType", shell=True)
lines = output.decode().split("\n")
for line in lines:
if "EFI Driver Version:" in line:
return line.split(":")[1].strip()
return "Apple Silicon APU - No driver publicily checkable."
except Exception as e:
print(f"Error: {e}")
return None