the result from torch.concat() is stored in cpu(memory)?

Viewed 18

the code

c = torch.rand((2000, 64, 64)).to('cuda')
d = torch.rand((2000, 64, 64)).to('cuda')
t3 = time.time()
s1 = c+d
s2 = torch.concat((a, b), dim=2)
t4 = time.time()

s1's device is gpu, but s2's device is cpu.

So I can't understand it. What is the principle of this?

1 Answers

Torch will do an operation if all necessary variable for the operation are on the same device.

I suppose that a and b where on CPU thus torch.concat((a, b), dim=2) is too.

When you did .to('cuda'), you have moved c and d to GPU, thus s1 is on GPU too.

Related