Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get raw pointer from tensors? #1649

Closed
yuandong-tian opened this issue May 25, 2017 · 6 comments

Comments

@yuandong-tian
Copy link

commented May 25, 2017

Hi all, I want to know how to get raw pointer from PyTorch tensors?

Background: I want to have multiple C threads writing the network input tensor in parallel.

@soumith

This comment has been minimized.

Copy link
Member

commented May 25, 2017

x.data_ptr gives you the raw pointer

@soumith soumith closed this May 25, 2017
@SuperShinyEyes

This comment has been minimized.

Copy link

commented Mar 31, 2019

I'm puzzled how this works when one is using a GPU. Does data_ptr loads tensors to CPU from GPU? If that is the case, how does it keep the content synced between CPU and GPU during a runtime?

@soumith

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

@SuperShinyEyes data_ptr for a GPU Tensor will point to a pointer to GPU memory. You cannot operate on that pointer directly, and have to give it to a CUDA kernel

@bhilburn

This comment has been minimized.

Copy link

commented Apr 24, 2019

@soumith - Thanks so much for your comment about about the pointer being to GPU memory! Just stumbled across this issue, and your comment made post-issue-close was very helpful.

@zimenglan-sysu-512

This comment has been minimized.

Copy link

commented Aug 11, 2019

hi @soumith
is it a way to get access to the raw GPU data of a tensor for pyCUDA and convert back?
thanks.

@BarakChamo

This comment has been minimized.

Copy link

commented Sep 27, 2019

I've been following this post on looking at other information about interoperability between PyTorch tensors and other CUDA libraries.

Seems like the way to go is to create an empty tensor of the right size and stride and write to its GPU pointer from elsewhere? (i.e. PyCuda, Numba). I couldn't find any way of creating a Tensor from a pointer.

This is an example I've ben following from the forums

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.