-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_cuda.py
More file actions
29 lines (26 loc) · 1.02 KB
/
check_cuda.py
File metadata and controls
29 lines (26 loc) · 1.02 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
import torch
import sys
print("Python版本:", sys.version)
print("PyTorch版本:", torch.__version__)
print("CUDA可用:", torch.cuda.is_available())
if torch.cuda.is_available():
print("CUDA版本:", torch.version.cuda)
print("当前CUDA设备:", torch.cuda.current_device())
print("设备数量:", torch.cuda.device_count())
print("设备名称:", torch.cuda.get_device_name(0))
print("设备属性:", torch.cuda.get_device_properties(0))
else:
print("CUDA不可用,PyTorch将使用CPU运行")
print("\n尝试其他方法检测GPU...")
try:
import subprocess
if sys.platform == 'win32':
gpu_info = subprocess.check_output('nvidia-smi', shell=True).decode('utf-8')
print("NVIDIA-SMI输出:")
print(gpu_info)
else:
gpu_info = subprocess.check_output(['nvidia-smi'], stderr=subprocess.STDOUT).decode('utf-8')
print("NVIDIA-SMI输出:")
print(gpu_info)
except Exception as e:
print(f"获取GPU信息时出错: {e}")