BVLC / caffe

Caffe: a fast open framework for deep learning.
http://caffe.berkeleyvision.org/
Other
34.04k stars 18.7k forks source link

Add support for opencl #408

Closed bhack closed 7 years ago

bhack commented 10 years ago

Hi Theano is adding support to opencl[1] trought CLBLAS[2]. Can caffe use this kind of solution to add opencl (more vendor neutral) support?

[1]https://github.com/Theano/libgpuarray [2]https://github.com/clMathLibraries/clBLAS

kloudkl commented 10 years ago

Ren Wu, the Distinguished Scientist of Baidu, gave a talk titled with "Deep Learning Meets Heterogeneous Computing" at the GTC 2014. He re-emphasized Baidu IDL's belief "Big data + Deep learning + Heterogeneous computing = Success". To make the DNN run on GPU supercomputers, data centers (cloud), smart phones, and wearable devices, they built their DNN technology based on highly optimized OpenCL since it is the only widely accepted heterogeneous computing open industry standard.

But it is not clear whether the vision of Caffe includes heterogeneous computing. Building a library that is compatible with multiple types of computing platforms will surely involves substantial expert level knowledge to optimize the usually not easily portable performance for those platforms and is probably out of the scope of this algorithm research oriented project. Even the people want to do that, because the current design of Caffe mixes the high level DNN algorithms with the low level hardware platform specific computing details, the code base needs to be refactored a lot which may break the stable state of Caffe and greatly hinder the ongoing researches.

You had better start a new project to experiment whether the performance of a DNN built on clBLAS is efficient and portable enough. Or you can even build a higher level library based on clBLAS in the way that mshadow wraps BLAS and then create an OpenCL counterpart of CXXNET (#382).

jeffdonahue commented 10 years ago

I don't have any plans to implement OpenCL support for Caffe myself (I don't personally have any use for it and I know nothing about it). But I'd be happy to see it supported in a similar way that Caffe (now) supports switching between MKL and other BLAS libraries, assuming such a thing is even possible (again, I know nothing about OpenCL -- maybe this is an absurd proposal).

I think there would basically be three steps, the second being by far the most time-consuming one (granted things always get much more complicated when you actually try to do something, but...):

(1) Factor out all CUDA (cuda*(...), curand*(...), cublas*(...), ...) calls and kernels in the code into wrapper libraries. A lot of the calls are already wrapped in math_functions.cu, and this would be valuable even without steps 2-3, as it would bring Caffe closer to being compilable without CUDA installed (though it's unclear to me how much more work there would still be -- I doubt it's just providing a Makefile switch to remove the nvcc calls).

(2) Reimplement the wrappers in OpenCL, potentially requiring changing some of the API you designed in step (1), depending on how mismatched the CUDA and OpenCL libraries are.

(3) Have the Makefile compile the OpenCL versions of the wrappers if a cuda/opencl switch in Makefile.config is set to opencl.

gururise commented 9 years ago

Any progress on OpenCL support? Its a shame that Caffe is locked to a single vendor for GPU support.

jramapuram commented 9 years ago

Alternatively you can use something like :

bhack commented 9 years ago

Another effort started at https://github.com/BVLC/caffe/pull/2195

source-data commented 8 years ago

anybody tested this https://github.com/BVLC/caffe/pull/2610 https://github.com/naibaf7/caffe ?

shelhamer commented 7 years ago

Done by the official opencl branch of BVLC Caffe.