Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.cuda function

PyTorch torch.cuda function


PyTorch torch reference manual PyTorch torch reference manual

torch.cuda is a PyTorch module for CUDA management. It provides features such as CUDA device management, memory management, and synchronization.

Function definition

torch.cuda

The torch.cuda module contains the following commonly used functions:


Usage examples

Example

import

torch

Check whether CUDA is available

print

(

f

"CUDA available: {torch.cuda.is_available()}"

)

Get the number of CUDA devices

if

torch.

cuda

.

is_available

(

)

:

   

print

(

f

"CUDA device count: {torch.cuda.device_count()}"

)

   

print

(

f

"CUDA device name: {torch.cuda.get_device_name(0)}"

)


PyTorch torch reference manual PyTorch torch reference manual