Check CUDA version in PyTorch

This article explains how to check CUDA version, CUDA availability, number of available GPUs and other CUDA device related details in PyTorch. torch.cuda package in PyTorch provides several methods to get details on CUDA devices.

PyTorch Installation

For following code snippet in this article PyTorch needs to be installed in your system. If you don't have PyTorch installed, refer How to install PyTorch for installation.

Check CUDA availability in PyTorch

   
import torch

print(torch.cuda.is_available())
 

Check CUDA version in PyTorch

   
print(torch.version.cuda)
 

Get number of available GPUs in PyTorch

   
print(torch.cuda.device_count())
 

Get properties of CUDA device in PyTorch

   
print(torch.cuda.get_device_properties("cuda:0"))
 

In case you more than one GPUs than you can check their properties by changing "cuda:0" to "cuda:1', "cuda:2" and so on.

Get CUDA device name in PyTorch

   
print(torch.cuda.get_device_name("cuda:0"))
 

In case you more than one GPUs than you can check their names by changing "cuda:0" to "cuda:1', "cuda:2" and so on.

Categories: PyTorch

Similar Articles