PyTorch torch.cuda.memory_allocated function
PyTorch torch reference manual
torch.cuda.memory_allocated is a PyTorch function for getting allocated GPU memory. It returns the memory size currently allocated on the CUDA device, in bytes.
Function definition
torch.cuda.memory_allocated(device=None)
Usage examples
Example
import
torch
Check allocated GPU memory
if
torch.
cuda
.
is_available
(
)
:
(
f
"Initial memory: {torch.cuda.memory_allocated()} bytes"
)
Creating tensors
x
=
torch.
randn
(
1000
,
1000
)
.
cuda
(
)
(
f
"After allocation: {torch.cuda.memory_allocated()} bytes"
)
Delete the tensor
del
x
(
f
"After deletion: {torch.cuda.memory_allocated()} bytes"
)
else
:
(
"CUDA not available"
)