Is there a way to create a at::Tensor using gpu memory object?

I want to create a tensor using a gpu memory object. Is it possible like the code below?

at::Tensor a = Tensor (*gpu_mem_pointer)

You can copy the values pointed by gpu_mem_pointer into a. You can do something like:

# assuming gpu_mem_pointer points to an array of n float values
auto options = ...# you'll need to set these options up depending on what you want to do
at::Tensor a = at::empty({n}, options);
auto a_ptr =<float>();
thurst::copy(a_ptr, a_ptr + n, gpu_mem_pointer);
1 Like