Skip to content

Instantly share code, notes, and snippets.

@hagope
Created December 19, 2022 21:39
Show Gist options
  • Save hagope/d92bf354de317cb6c0ee8fe6340cfdf0 to your computer and use it in GitHub Desktop.
Save hagope/d92bf354de317cb6c0ee8fe6340cfdf0 to your computer and use it in GitHub Desktop.
import torch
cpu = torch.device('cpu')
alloc_size = 16e9
print('Allocating')
x = torch.zeros(int(alloc_size / 8),
dtype=torch.float32,
device=cpu)
print('Pinning')
x = x.pin_memory()
print('Accessing')
m = torch.mean(x)
assert m == 0
print('Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment