Skip to content

Building: Caffe Support

Christopher Canel edited this page Sep 5, 2018 · 1 revision

Supported versions

SAF has been tested with the following versions of Caffe:

Building

# Checkout/download the appropriate version of Caffe
cp ./Makefile.config.example ./Makefile.config
# Enable OPENCV 3 support in Makefile.config

Ubuntu hiccups

Note that if the above doesn't work out of the box with your hdf5, edit your Makefile.config and Makefile.

# Makefile.config
-INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
+INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
# Makefile
-LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

Using Intel Caffe with a local copy of MKL-DNN

Intel Caffe installation process will look for a globally-installed version of MKL-DNN on the system. If it finds one, it will use that. If not, it will automatically download and build a local copy. The following instructions are for this latter case.

The symptom is that SAF will fail to link, saying that is cannot find MKL-DNN. The underlying issues is that the Intel Caffe build system links against its local copy of libmkldnn.so using a relative path instead of an absolute path. You can verify that this is indeed the issue by running ldd on libcaffe.so.

Note: This issue does not apply to BVLC Caffe or any version of Caffe that does not use MKL-DNN.

Solution:

  1. Build Intel Caffe (https://github.com/intel/caffe) as usual using the above instructions. This step is important: If you do steps 2-4 before building Caffe for the first time, it will not compile.

  2. Remove the generated libraries to force Caffe's build system to relink them

    rm /path/to/caffe/build/lib/*
    rm /path/to/caffe/distribute/lib/*
    
  3. Apply the change below to Makefile.mkldnn

    diff --git a/Makefile.mkldnn b/Makefile.mkldnn
    index ec1a70bc..ed8c8046 100644
    --- a/Makefile.mkldnn
    +++ b/Makefile.mkldnn
    @@ -1,5 +1,5 @@
    CAFFE_ROOTDIR := $(shell pwd)
    -MKLDNN_ROOTDIR := external/mkldnn
    +MKLDNN_ROOTDIR := $(CAFFE_ROOTDIR)/external/mkldnn
    MKLDNN_TMPDIR := $(MKLDNN_ROOTDIR)/tmp
    MKLDNN_SRCDIR := $(MKLDNN_ROOTDIR)/src
    MKLDNN_BUILDDIR := $(MKLDNN_ROOTDIR)/build
    
  4. Relink Caffe

    make && make distribute
    

At this point, SAF should successfully link against Intel Caffe. You can verify that libcaffe.so is using an absolute path for libmkldnn.so by running ldd.

Configuring SAF

You must point SAF's build system to Caffe's location.

cmake -DUSE_CAFFE=yes -DCAFFE_HOME=<path to Caffe>/distribute ..