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

PyTorch torch.cuda.memory_reserved function

PyTorch torch.cuda.memory_reserved function


PyTorch torch reference manual PyTorch torch reference manual

torch.cuda.memory_reserved is a PyTorch function for getting reserved GPU memory. It returns the memory size currently reserved by the CUDA caching allocator, in bytes.

Function definition

torch.cuda.memory_reserved(device=None)


Usage examples

Example

import

torch

Check reserved GPU memory

if

torch.

cuda

.

is_available

(

)

:

   

print

(

f

"Initial memory reserved: {torch.cuda.memory_reserved()} bytes"

)

   

Creating tensors

    x

=

torch.

randn

(

1000

,

1000

)

.

cuda

(

)

   

print

(

f

"After allocation: {torch.cuda.memory_reserved()} bytes"

)

   

Delete the tensor

   

del

x

   

print

(

f

"After deletion: {torch.cuda.memory_reserved()} bytes"

)

else

:

   

print

(

"CUDA not available"

)


PyTorch torch reference manual PyTorch torch reference manual