Caffe openCL macOS Sierra AMD

Arthur Carabott
2 min readDec 29, 2016

--

No Nvidia/CUDA in the new macs, trying my luck with the openCL branch of Caffe

Dependencies

Install http://brew.sh/ if you don’t have it

Python 2.7 and numpy if you ain’t got it

brew install pythonpip install --upgrade pip setuptoolspip install numpy

As per http://caffe.berkeleyvision.org/install_osx.html

brew install -vd snappy leveldb gflags glog szip lmdbbrew tap homebrew/sciencebrew install hdf5 opencvbrew install --build-from-source --with-python -vd protobubrew install --build-from-source -vd boost boost-python

ViennaCL

brew install viennacl

CUDA even though you can’t run it, you’ll need it installed to stop compilation complains

brew cask install cuda

Caffe

I’m cloning into a folder at ~/src feel free to use another location

cd ~mkdir src cd srcgit clone git@github.com:BVLC/caffe.gitcd caffegit checkout opencl

Compilation time (from: http://caffe.berkeleyvision.org/installation.html#compilation)

cp Makefile.config.example Makefile.config

Open Makefile.config if your text editor, update the python include path on line 104

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/site-packages/numpy/core/include

Edit: Was getting a nasty malloc error when running caffe, fix from this discussion is to uncomment USE_LEVELDB := 0 on line 52

Also note that on line 13 USE_GREENTEA := 1 should be uncommented, confirms we are on the openCL branch

Double check that the files it needs are actually there

ls /usr/include/python2.7/ | grep Python.h# blank line bad, file name goodls /usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/ | grep arrayobject.h# blank line bad, file name good

If you get blank lines, your Python 2.7 and/or numpy installation isn’t right, double check these.

Notes for the future

  • Line 45 of Makefile.config has the CPU_ONLY flag, can try this later if openCL fails
  • Line 86 of Makefile.config can change the BLAS library choice, some people recommend Intel’s MKL over the macOS native BLAS

Compiling

(the -j flag will use multiple cores to compile, you can determine this by running sysctl -n hw.ncpu mine returns 8

make all -j8make test -j8make runtest -j8

All tests passed!

Testing

Trying the LeNet MINST example from http://caffe.berkeleyvision.org/gathered/examples/mnist.html

Not convinced my GPU is being used…

Requires High Perf GPU: No :(

Well at least it finished, took ~12 mins.

Multi-Person-Pose-Estimation

So the real goal was to get this jaw dropper running….

They have wrapped things up nicely in a custom Caffe repo, unfortunately this is for regular CUDA powered Caffe. Trying to get this working without CUDA…

cd ~/srcgit clone git@github.com:CMU-Perceptual-Computing-Lab/caffe_demo.git cd model./getModels.sh

First walls hit… haven’t managed to compile successfully yet. As they aren’t using the OpenCL branch I’ve had to port a bunch of their changes, you can find them here on the rtpose-opencl and rtpose-cpu branches: https://github.com/acarabott/caffe

--

--