-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpu.py
54 lines (42 loc) · 1.8 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
import torch
import sys
def check_pytorch_installation():
print("PyTorch Installation Check")
print("==========================")
# Check PyTorch version
print(f"PyTorch version: {torch.__version__}")
# Check CUDA availability
cuda_available = torch.cuda.is_available()
print(f"CUDA available: {cuda_available}")
if cuda_available:
print("\nCUDA Information:")
print("-----------------")
print(f"CUDA version: {torch.version.cuda}")
print(f"Number of CUDA devices: {torch.cuda.device_count()}")
current_device = torch.cuda.current_device()
print(f"Current CUDA device ID: {current_device}")
device = torch.device(f'cuda:{current_device}')
print(f"Current CUDA device: {device}")
device_name = torch.cuda.get_device_name(current_device)
print(f"CUDA device name: {device_name}")
print("\nTensor Operations:")
print("------------------")
try:
x = torch.tensor(1).to(device)
print(f"Moved tensor: {x}")
y = torch.tensor(1, device=device)
print(f"Created tensor: {y}")
if x.device.type == 'cuda' and y.device.type == 'cuda':
print("\nSuccess: PyTorch is correctly installed with CUDA support!")
else:
print("\nWarning: Tensors were not properly moved to CUDA devices.")
except Exception as e:
print(f"\nError during tensor operations: {e}")
else:
print("\nNote: CUDA is not available. PyTorch will run on CPU only.")
print("\nSystem Information:")
print("-------------------")
print(f"Python version: {sys.version}")
print(f"Operating System: {sys.platform}")
if __name__ == "__main__":
check_pytorch_installation()