Fonction PyTorch torch.cuda.memory_allocated


Pytorch torch 参考手册Manuel de référence Pytorch torch

torch.cuda.memory_allocatedest une fonction de PyTorch utilisée pour obtenir la mémoire GPU allouée. Elle renvoie la taille de la mémoire allouée sur le périphérique CUDA actuel (en bytes).

Définition de fonction

torch.cuda.memory_allocated(device=None)

Exemple d'utilisation

Exemple

import torch

# Vérifier la mémoire GPU allouée
if torch.cuda.is_available():
    print(f"Mémoire initiale : {torch.cuda.memory_allocated()} bytes")

    # Créer un tenseur
    x = torch.randn(1000, 1000).cuda()
    print(f"Après allocation : {torch.cuda.memory_allocated()} bytes")

    # Supprimer le tenseur
    del x
    print(f"Après suppression : {torch.cuda.memory_allocated()} bytes")
else:
    print("CUDA non disponible")

Pytorch torch 参考手册Manuel de référence Pytorch torch

Autres extensions