PyTorch torch.cuda.memory_reserved 関数
torch.cuda.memory_reservedPyTorch で予約済みビデオメモリを取得するための関数です。CUDAキャッシュマネージャが現在予約しているメモリサイズを(バイト単位で)返します。
関数定義
torch.cuda.memory_reserved(device=None)
使用例
実例
import torch
# 予約済みGPUメモリを確認
if torch.cuda.is_available():
print(f"Initial memory reserved: {torch.cuda.memory_reserved()} bytes")
# テンソルを作成
x = torch.randn(1000, 1000).cuda()
print(f"After allocation: {torch.cuda.memory_reserved()} bytes")
# テンソルを削除
del x
print(f"After deletion: {torch.cuda.memory_reserved()} bytes")
else:
print("CUDA not available")
# 予約済みGPUメモリを確認
if torch.cuda.is_available():
print(f"Initial memory reserved: {torch.cuda.memory_reserved()} bytes")
# テンソルを作成
x = torch.randn(1000, 1000).cuda()
print(f"After allocation: {torch.cuda.memory_reserved()} bytes")
# テンソルを削除
del x
print(f"After deletion: {torch.cuda.memory_reserved()} bytes")
else:
print("CUDA not available")
その他の拡張機能
Pytorch torch リファレンスマニュアル