Hi, All
I have a running error with CUDA in C++ libtorch as follows:
terminate called after throwing an instance of ‘c10::Error’
what():  Tensor for argument #3 ‘mat2’ is on CPU, but expected it to be on GPU (while checking arguments for addmm)
Exception raised from checkSameGPU at /pytorch/aten/src/ATen/TensorUtils.cpp:122 (most recent call first):
It seems to me that it is a conflict between GPU and CPU. But I am not sure exactly what is the conflict and how to correct it.
The related code is:
torch::Tensor forward(int64_t batch_size, bool cuda = false){
torch::Tensor x=torch::autograd::Variable(torch::rand({batch_size,z_dim}));
if(cuda)
x = x.cuda();
x=torch::nn::functional::softplus(bn1(fc1(x))+bn1_b);
and before that I have a line related to CPU:
I have a line like:
return loss.data().cpu();
Shall I modify this line to other ways ? Any comments please ?
Thanks