Move tensor to the same gpu of another tensor

As far as I understand, you would like to move b to the same device as a.
This should work:

a = torch.randn(10, 10).cuda()
print(a)
b = a.new(a)
print(b)
c = a.new(10, 10)
print(c)
1 Like