Hi,
I am noticing a ~3Gb increase in CPU RAM occupancy after the first .cuda() call. The CPU RAM occupancy increase is partially independent from the moved object original CPU size, whether it is a single tensor or a nn.Module subclass.
I’ve noticed this behavior in my workstation:
OS: Ubuntu 20.04.4 LTS
Processor: Intel® Xeon(R) W-2223 CPU @ 3.60GHz × 8
GPU: 2*RTXA6000
Pytorch: 1.10.0+cu111
And also on the Nvidia Jetson Nano.
Here is a minimal example that, defining a one-element tensor, results in a +3Gb increase on CPU RAM occupancy
import os
import torch
def get_ram():
_, cpu_used, cf= map(int, os.popen('free -t -m').readlines()[-1].split()[1:])
gpu_allocated = (torch.cuda.memory_allocated(0))/10**6
return cpu_used,gpu_allocated
# Initial GPU/CPU occupation
c0,g0 = get_ram()
# Occupation after defining a tensor on CPU
tensor = torch.tensor([0])
c1,g1 = get_ram()
# Occupation after moving the tensor to CUDA
tensor = tensor.cuda()
c2,g2 = get_ram()
print('Occupancy after CPU tensor definition:')
print()
print('CPU used: \t{}\tMb'.format(c1-c0))
print('GPU used: \t{}\tMb'.format(g1-g0))
print()
print('Occupancy after moving tensor to CUDA:')
print()
print('CPU used: \t{}\tMb'.format(c2-c0))
print('GPU used: \t{}\tMb'.format(g2-g0))
output:
Occupancy after CPU tensor definition:
CPU used: 1 Mb
GPU used: 0.0 Mb
Occupancy after moving tensor to CUDA:
CPU used: 3297 Mb
GPU used: 0.000512 Mb
I do not known what is the cause of this behavior. Is it normal? Can it be mitigated?
It is particularly problematic for me as I am developing DNN applications on Jetson Nano, and this RAM jump almost saturates the available memory by default