-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
base: master
Are you sure you want to change the base?
Conversation
Now we can call cuBlas functions though Scikits.CUDA using cuBlas handle which is hold by Caffe. See 63def1b |
@tnarihi What do you think about libgpuarray approach? |
See also motivations |
@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? |
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? |
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. |
Yes it is becoming off topic and too hi level for this PR. Brew grand masters are needed. |
add0160
to
0ffe2e0
Compare
.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)) |
There was a problem hiding this comment.
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.
Now this PR is too much bigger. I added a lot of new features. Should I split them into individual PRs? |
@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. |
@longjon Sure. I'll consider dependencies among commits and split them into the smallest units later. Thanks for your comment. |
135518f
to
9810395
Compare
72bf6a4
to
520cd13
Compare
for checking current device mode.
Blob_Shape not to use raw_function
…util-func' into HEAD
… into HEAD Conflicts: python/caffe/__init__.py
The pointers could be used by CUDA wrapper libraries in Python such as PyCUDA, gnumpy, Theano etc. Blob_Gpu{Data/Diff}Ptr not to use raw_function
Dependencies: #2147 #2148
Main changes:
data
anddiff
inBlob
to Python as integer so that we manipulate GPU data via various choices of Python CUDA wrappers such as PyCuda, gnumpy, Theano, etc.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 ofdata
anddiff
inBlob
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 initializegpuarray
in PyCuda without copying memory and can manipulate it via functions provided by PyCuda or some of its extensions. Please seepython/caffe/test/test_pycuda.py
for usage.