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

[Python] GPU in Python: Exposing GPU pointers in a Caffe.Blob #2102

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

tnarihi
Copy link
Contributor

@tnarihi tnarihi commented Mar 11, 2015

Dependencies: #2147 #2148

Main changes:

  • Exposed GPU (CUDA device) pointers of data and diff in Blob to Python as integer so that we manipulate GPU data via various choices of Python CUDA wrappers such as PyCuda, gnumpy, Theano, etc.
  • Expose cuBlas handle of Caffe singleton
  • Added PyCuda utilities and tests as one of choies. In this implementation, you can initialize gpuarray in PyCuda without copying memory and can manipulate it via functions provided by PyCuda or some of its extensions.

Once dependencies are fixed, I'll rebased this.

Old description

This changes many things as described in individual commits. First 4 commits are just for utilities. The 5-th commit is the main parts of this PR. I exposed GPU (CUDA device) pointers of data and diff in Blob to Python as integer so that we manipulate GPU data via various choices of Python CUDA wrappers such as PyCuda, gnumpy, Theano, etc. I added PyCuda utilities and tests as one of choies. In this implementation, you can initialize gpuarray in PyCuda without copying memory and can manipulate it via functions provided by PyCuda or some of its extensions. Please see python/caffe/test/test_pycuda.py for usage.

@tnarihi
Copy link
Contributor Author

tnarihi commented Mar 14, 2015

Now we can call cuBlas functions though Scikits.CUDA using cuBlas handle which is hold by Caffe. See 63def1b test_pycuda.py for usage of Sgemm.

@bhack
Copy link
Contributor

bhack commented Mar 14, 2015

@tnarihi What do you think about libgpuarray approach?

@bhack
Copy link
Contributor

bhack commented Mar 14, 2015

See also motivations

@tnarihi
Copy link
Contributor Author

tnarihi commented Mar 14, 2015

@bhack Thanks for sharing it! I didn't know this, and the concept and motivation are quite interesting for me. As far as I look at the motivation page and source code on GitHub, they are developing a C version of numpy.ndarray on GPU (abstracting multiple backends, CUDA and OpenCL so far.), which could be used by writing wrapper regardless languages such as C++, Python, Ruby etc, and they provide Python wrapper already. It seems like they are trying to replace the other existing libraries' array type such as PyCUDA.gpuarray, CudaMat etc, because they are still a subset of numpy.ndarray on GPU.

I reconsidered about this PR. The main point of this PR is exposing GPU (CUDA device) pointers of a Caffe.Blob to python so that we can manipulate them through various existing Python CUDA wrappers. Then, some of examples I implement are PyCUDA and Scikits.CUDA. You can use any other libraries in your own Python scripting. If we see libgpuarray as python interface (pygpu), it could be one of choices of python CUDA wrappers. It seems there is no relation directly from libgpuarray to pycaffe and even C++ Caffe as long as we don't replace Blob with libgpuarray. This is my understanding. What do you think about it?

@tnarihi tnarihi changed the title GPU in Python: converting Blob to PyCuda.gpuarray (no copy) GPU in Python: Exposing GPU pointers in a Caffe.Blob to Python Mar 14, 2015
@bhack
Copy link
Contributor

bhack commented Mar 14, 2015

I almost share your view. Under a strategic point of view it could be interesting to share and increase the momentum on libgpuarray together an important deep learning framework like Theano but still in a "vendor" neutral way. On the other hand the library started before arrayfire was opensourced under BSD. Is arrayfire another candidate? Have it a too large target?

@tnarihi
Copy link
Contributor Author

tnarihi commented Mar 14, 2015

Yeah, interesting if we could share core computation and data structures in multiple backends together with other deep learning frameworks but it seems we need much effort to do this.
@jeffdonahue @shelhamer @longjon Any thought? I am still not unclear about how we could share these momentums with Caffe. It looks far bigger discussion than this PR.

@bhack
Copy link
Contributor

bhack commented Mar 14, 2015

Yes it is becoming off topic and too hi level for this PR. Brew grand masters are needed.

@tnarihi tnarihi force-pushed the python-gpu branch 4 times, most recently from add0160 to 0ffe2e0 Compare March 17, 2015 22:36
.def("reshape", &Layer<Dtype>::Reshape)
.def("Reshape", bp::raw_function(&Layer_Reshape))
.def("Forward", bp::raw_function(&Layer_Forward))
.def("Backward", bp::raw_function(&Layer_Backward))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I want to use lower case attribute names for them, but lower case names are already reserved by PythonLayer.

@tnarihi
Copy link
Contributor Author

tnarihi commented Mar 17, 2015

Now this PR is too much bigger. I added a lot of new features. Should I split them into individual PRs?

@longjon
Copy link
Contributor

longjon commented Mar 18, 2015

@tnarihi, yes, it's always best to split PRs into the smallest sensible units; reviewing effort is superlinear in patch length.

Sorry I haven't had much time lately to look carefully at this and your other Python changes; this seems like a nice direction so hopefully we'll dive into it soon.

@tnarihi
Copy link
Contributor Author

tnarihi commented Mar 18, 2015

@longjon Sure. I'll consider dependencies among commits and split them into the smallest units later. Thanks for your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants