PyTorch torch.cuda.memory_reserved function
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
(
)
:
(
f
"Initial memory reserved: {torch.cuda.memory_reserved()} bytes"
)
Creating tensors
x
=
torch.
randn
(
1000
,
1000
)
.
cuda
(
)
(
f
"After allocation: {torch.cuda.memory_reserved()} bytes"
)
Delete the tensor
del
x
(
f
"After deletion: {torch.cuda.memory_reserved()} bytes"
)
else
:
(
"CUDA not available"
)