Skip to content

Instantly share code, notes, and snippets.

@ThoenigAdrian
Created October 29, 2020 08:53
Show Gist options
  • Save ThoenigAdrian/b3b8f97a8aca88a9348d75e858d5cffc to your computer and use it in GitHub Desktop.
Save ThoenigAdrian/b3b8f97a8aca88a9348d75e858d5cffc to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/a/53374933/5130800
import torch
# setting device on GPU if available, else CPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)
print()
#Additional Info when using cuda
if device.type == 'cuda':
print(torch.cuda.get_device_name(0))
print('Memory Usage:')
print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
print('Cached: ', round(torch.cuda.memory_cached(0)/1024**3,1), 'GB')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment