CUDA gives PyTorch a compute-device interface for running tensor operations on an NVIDIA GPU. Create a device with torch.device("cuda"), move tensors with .to(device), and reuse the same operations. section 1.2.1
Keep device placement consistent:
- Move every tensor involved in an operation to the same device; mixing cuda:0 and cpu produces a device-mismatch RuntimeError. section 1.2.1
- Move CUDA tensors back with .cpu() before converting them to NumPy arrays or passing them to Matplotlib. section 1.2.1
- Benchmark realistic sizes: large matrix multiplication can benefit substantially, while smaller matrices may reduce the speedup. section 1.2.1
print("Is CUDA available? :", torch.cuda.is_available())
device = torch.device("cuda")
Is CUDA available? : True
Check CUDA availability, then create the device reference used for subsequent tensor transfers. section 1.2.1



