PyTorch torch.cuda.memory_reserved Function
PyTorch torch Reference Manual
torch.cuda.memory_reservedIt is a function in PyTorch used to obtain the reserved GPU memory. It returns the size of memory currently reserved by the CUDA caching manager (in bytes).
Function Definition
torch.cuda.memory_reserved(device=None)
Usage Example
Example
import torch
# Check reserved GPU memory
if torch.cuda.is_available():
print(f"Initial memory reserved: {torch.cuda.memory_reserved()} bytes")
# Create tensor
x = torch.randn(1000, 1000).cuda()
print(f"After allocation: {torch.cuda.memory_reserved()} bytes")
# Delete tensor
del x
print(f"After deletion: {torch.cuda.memory_reserved()} bytes")
else:
print("CUDA not available")
# Check reserved GPU memory
if torch.cuda.is_available():
print(f"Initial memory reserved: {torch.cuda.memory_reserved()} bytes")
# Create tensor
x = torch.randn(1000, 1000).cuda()
print(f"After allocation: {torch.cuda.memory_reserved()} bytes")
# Delete tensor
del x
print(f"After deletion: {torch.cuda.memory_reserved()} bytes")
else:
print("CUDA not available")
Other Extensions