Tensor .data() returning null (Release Version Only)


(Ty) #1

I’m currently having a problem only on the release version of libtorch where tensor.data_ptr() is returning a null pointer (both data() and data_ptr() return null). This however does not occur on the debug version.

Failing on a basic example like this:

c10::IntArrayRef dim = { 1, channels_, width_, height_ };
at::TensorOptions opts = torch::TensorOptions()
.dtype(torch::kFloat32)
.device(torch::kCPU)
.requires_grad(false);

input_ = torch::empty(dim, opts);

float* data = input_.data(); // returns NULL for release build

Currently using the latest download of Nightly Cuda 9.0 Windows release and building on Visual C++ 2017

Anybody got an idea on what’s goin on?

UPDATE: Managed to resolve using this thread: https://github.com/pytorch/pytorch/issues/14000
So all I had to do was declare the tensor as flat memory, and the pointer was no longer NULL. Then after writing to the data pointer, I just called input_.resize_(dim).