PyTorch torch.cuda.is_available Function
Pytorch torch Reference Manual
torch.cuda.is_availableis a function in PyTorch used to check whether CUDA is available.
Function Definition
torch.cuda.is_available()
Usage Example
Example
import torch
# Check whether CUDA is available
if torch.cuda.is_available():
print("CUDA available!")
print("Number of GPUs:", torch.cuda.device_count())
print("GPU name:", torch.cuda.get_device_name(0))
else:
print("CUDA unavailable")
# Check whether CUDA is available
if torch.cuda.is_available():
print("CUDA available!")
print("Number of GPUs:", torch.cuda.device_count())
print("GPU name:", torch.cuda.get_device_name(0))
else:
print("CUDA unavailable")
Other Extensions