tom:

You’d need to make it a tensor first and then move to CUDA.


Are you suggesting I do this ?
float tensor2Data[]{42,0,0,0};
auto tensor2=torch::from_blob(tensor2Data,{1, 1, 2, 2},torch::kCPU);
tensor2.to(torch::kCUDA);

Because I tried, but then when I do
cout << "tensor2:" << endl << tensor2

All I get is:

tensor2:
(1,1,.,.) =
42 0
0 0
[ CPUFloatType{1,1,2,2} ]

Which indicates tensor2 is still on the CPU (CPUFloatType), it didn’t move to the CPU.