PyTorch torch.cuda.is_available function
PyTorch torch reference manual
torch.cuda.is_available is a PyTorch function for checking whether CUDA is available.
Function definition
torch.cuda.is_available()
Usage examples
Example
import
torch
Check whether CUDA is available
if
torch.
cuda
.
is_available
(
)
:
(
"CUDA is available!"
)
(
"GPU count:"
,
torch.
cuda
.
device_count
(
)
)
(
"GPU name:"
,
torch.
cuda
.
get_device_name
(
0
)
)
else
:
(
"CUDA is not available"
)