What’s the difference between tensor.cuda() and tensor.to(0)?
I copy function CUDA_tensor_apply2 from ATen/cuda/CUDAApplyUtils.cuh and use it as a PyTorch extension.
When I run
import torch
import my_extension.run as run

x = torch.rand(3, 4)
y = x.cuda()
print(run(y))  # all is well
print(y)  # all is well
print(x)  # all is well

But if I run
import torch
import my_extension.run as run

x = torch.rand(3, 4)
y = x.to(0)
print(run(y))  # incorrect result
print(y)  # RuntimeError (700)
print(x)  # no problem

z = x.cuda()  # RuntimeError (700)

I got the error RuntimeError (700) : an illegal memory access was encountered at /pytorch/aten/src/THC/THCReduceAll.cuh:327
Why? Is this error related to at::cuda::current_device()?