I have a tensor which is on gpu 0.
how can I move (or make a copy of it one gpu 1)?
A = torch.rand(1)
cuda0 = torch.device('cuda:0')
cuda1 = torch.device('cuda:1')
# now I want to move A to gpu 1
gives me error:
RuntimeError: CUDA error: invalid device ordinal
Are you sure the second GPU is properly available? What does device_count() returns?
You might be hidding the second GPU with CUDA_VISIBLE_DEVICES=0 as well.
yeah my bad. I missed to change the number of devices in CUDA_VISIBLE.
Thanks for pointing that out
Would you tell me what happened when tensor.to is called? Is the tensor transfered directly from gpu 1 to gpu 2, or it is first transferred from gpu 1 to cpu memory and then transferred from cpu to gpu 2?
It depends on the hardware you have.
If possible, it will be sent directly from one GPU to the other. But not all cards support that AFAIK and it might have to go through the CPU.