AMD Ryzen 7 2700X (8 core 16 thread, 3.7GHz) vs NVIDIA GeForce RTX 2070
결론: pytorch를 다룰 때 GPU가 17배 빠르다.
import platform
import cpuinfo
import psutil
cpu = cpuinfo.get_cpu_info()
print("Processor:", platform.processor())
print("CPU Model:", cpu["brand_raw"])
print("Architecture:", cpu["arch"])
print("Cores:", cpu["count"])
print("Physical Cores:", psutil.cpu_count(logical=False))
print("Total Threads:", psutil.cpu_count(logical=True))
Processor: AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD
CPU Model: AMD Ryzen 7 2700X Eight-Core Processor
Architecture: X86_64
Cores: 16
Physical Cores: 8
Total Threads: 16
import torch
print("PyTorch Version:", torch.__version__)
print("CUDA Available:", torch.cuda.is_available())
print("GPU Name:", torch.cuda.get_device_name(0) if torch.cuda.is_available() else "No GPU found")
PyTorch Version: 2.5.1+cu121
CUDA Available: True
GPU Name: NVIDIA GeForce RTX 2070
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print("Using device:", device)
# Create a tensor and move it to GPU
x = torch.rand(3, 3).to(device)
print("Tensor on:", x.device)
Using device: cuda
Tensor on: cuda:0
import time
# Set device
device_cpu = torch.device("cpu")
device_gpu = torch.device("cuda")
# Create large random tensors (10,000 x 10,000)
size = 10000
A = torch.rand(size, size)
B = torch.rand(size, size)
# CPU Benchmark
A_cpu = A.to(device_cpu)
B_cpu = B.to(device_cpu)
start = time.time()
C_cpu = torch.matmul(A_cpu, B_cpu) # Matrix multiplication on CPU
end = time.time()
print(f"CPU Time: {end - start:.4f} seconds")
# GPU Benchmark
A_gpu = A.to(device_gpu)
B_gpu = B.to(device_gpu)
torch.cuda.synchronize() # Sync GPU before timing
start = time.time()
C_gpu = torch.matmul(A_gpu, B_gpu) # Matrix multiplication on GPU
torch.cuda.synchronize() # Sync GPU after timing
end = time.time()
print(f"GPU Time: {end - start:.4f} seconds")
CPU Time: 7.2340 seconds
GPU Time: 0.4093 seconds