-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_gpu.py
More file actions
101 lines (76 loc) · 2.51 KB
/
Copy pathcheck_gpu.py
File metadata and controls
101 lines (76 loc) · 2.51 KB
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
import platform
import subprocess
import shutil
def check_nvidia_smi():
"""Check GPUs using nvidia-smi."""
if shutil.which("nvidia-smi") is None:
print("❌ nvidia-smi not found.")
return
print("=" * 60)
print("NVIDIA GPUs (nvidia-smi)")
print("=" * 60)
try:
result = subprocess.run(
[
"nvidia-smi",
"--query-gpu=index,name,memory.total,driver_version",
"--format=csv,noheader",
],
capture_output=True,
text=True,
check=True,
)
gpus = result.stdout.strip().splitlines()
if not gpus:
print("No NVIDIA GPUs detected.")
return
print(f"Found {len(gpus)} GPU(s):\n")
for gpu in gpus:
idx, name, memory, driver = [x.strip() for x in gpu.split(",")]
print(f"GPU {idx}")
print(f" Name : {name}")
print(f" Memory : {memory}")
print(f" Driver : {driver}")
print()
except Exception as e:
print("Error:", e)
def check_torch():
"""Check GPUs using PyTorch if installed."""
try:
import torch
print("=" * 60)
print("PyTorch")
print("=" * 60)
print("PyTorch version:", torch.__version__)
print("CUDA available :", torch.cuda.is_available())
print("GPU count :", torch.cuda.device_count())
if torch.cuda.is_available():
for i in range(torch.cuda.device_count()):
props = torch.cuda.get_device_properties(i)
print(f"\nGPU {i}")
print(f" Name : {props.name}")
print(f" VRAM : {props.total_memory / 1024**3:.2f} GB")
print(f" Capability: {props.major}.{props.minor}")
except ImportError:
print("PyTorch is not installed.")
def check_tensorflow():
"""Check GPUs using TensorFlow if installed."""
try:
import tensorflow as tf
print("=" * 60)
print("TensorFlow")
print("=" * 60)
gpus = tf.config.list_physical_devices("GPU")
print("Detected GPUs:", len(gpus))
for gpu in gpus:
print(gpu)
except ImportError:
print("TensorFlow is not installed.")
if __name__ == "__main__":
print(f"Python : {platform.python_version()}")
print(f"System : {platform.system()} {platform.release()}\n")
check_nvidia_smi()
print()
check_torch()
print()
check_tensorflow()