Create Tensor on CUDA device in C++

I have an array that I would like to place inside a Tensor that should live on the GPU.

I have previously done this with:

double array[] = { 1, 2, 3, 4, 5};
auto options = torch::TensorOptions().dtype(torch::kFloat64).device(torch::kCUDA, 1);
torch::Tensor tharray = torch::from_blob(array, {5}, options);

It has been awhile (2 years) since I used this approach but I seem to remember it working and it’s reasonably upvoted on StackOverflow.

Today I tried running this code and I get the error:

terminate called after throwing an instance of 'c10::Error'
  what():  CUDA error: invalid argument
Exception raised from getDeviceFromPtr at ../aten/src/ATen/cuda/CUDADevice.h:13 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x69 (0x7ffff7ba5eb9 in /home/josh/git/AlphaZeroCpp/libtorch/lib/libc10.so)
frame #1: <unknown function> + 0x31d398f (0x7fffb3cc998f in /home/josh/git/AlphaZeroCpp/libtorch/lib/libtorch_cuda.so)
frame #2: at::Context::getDeviceFromPtr(void*, c10::DeviceType) + 0xba (0x55555559f52c in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)
frame #3: at::from_blob(void*, c10::ArrayRef<long>, c10::ArrayRef<long>, c10::TensorOptions const&) + 0xb7 (0x55555559fbac in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)
frame #4: at::from_blob(void*, c10::ArrayRef<long>, c10::TensorOptions const&) + 0x86 (0x5555555a00c9 in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)
frame #5: torch::from_blob(void*, c10::ArrayRef<long>, c10::TensorOptions const&)::{lambda()#1}::operator()() const + 0x70 (0x5555555a0fd2 in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)
frame #6: torch::from_blob(void*, c10::ArrayRef<long>, c10::TensorOptions const&) + 0x57 (0x5555555a108a in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)
frame #7: main + 0x101 (0x5555555ab9ee in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)
frame #8: __libc_start_main + 0xe7 (0x7fffaf760bf7 in /lib/x86_64-linux-gnu/libc.so.6)
frame #9: _start + 0x2a (0x55555558bf2a in /home/josh/git/AlphaZeroCpp/build/AlphaZeroCpp)

Has something changed regarding creating tensors from blobs? Am I doing anything obviously incorrect?

I can work around this by creating my tensor on the CPU and then moving it to the GPU, but I would like to understand why I can’t create the Tensor on the GPU directly?