Installation

Grigori Fursin edited this page Aug 30, 2018 · 74 revisions

[ Home ]

This framework and documentation is continuously updated - please help us improve it via CK mailing list

We need to have easily customizable Caffe builds via JSON API to be able to plug it to our framework for collaborative benchmarking and optimization of workloads across diverse hardware and inputs (see project page and papers 1, 2, 3 for more details).

Table of Contents

Introduction and conventions

CK helps automate and customize installation of Caffe using different compilers, libraries (openBLAS, clBLAS, CLBlast, ViennaCL, libDNN, cuBLAS, cuDNN), run-time (CPU, CUDA, OpenCL) and models (AlexNet, GoogleNet, SqueezeNet) across different hardware (GPUs from NVIDIA, Intel, ARM, AMD, Qualcomm, Odroid XU3/4, Raspberry Pi 3, Chromebooks, Android-based mobile phones and tablets) and OS (Linux, Windows, Android). CK also helps us quickly prototype various platform-independent experimental workflows via unified JSON API. See CK wiki and portable CK workflows for more details about CK concepts.

Note that in this guide, shell commands prefixed with `'$'` should be run as user, whereas commands prefixed with `'#'` should be run as root (or as user with `'sudo'`).

Configuring hardware

CUDA-based devices

If you do not yet have CUDA installed, we suggest you to install the latest GPGPU driver and CUDA for your device and OS from NVIDIA website.

On NVIDIA's Tegra platform and Ubuntu, you can install optimized OpenCV either via JetPack or via apt:

# apt install libopencv4tegra-dev

OpenCL-based devices

AMD GPU

We tested Caffe OpenCL branch on Windows 10 with OpenCL driver as a part of the Catalyst software. Please, check this page with the installation details.

Intel CPU/GPU (Linux)

We tested Caffe OpenCL branch on experimental Ubuntu 17.04 with kernel version > 4.7 (to avoid kernel recompilation). You can download latest OpenCL drivers from Intel website. Please, follow instructions carefully!

Then download and install Intel OpenCL SDK here.

Intel CPU/GPU (Windows)

Your latest GPU driver should normally support OpenCL. You just need to download and install the Intel OpenCL SDK.

ARM Mali GPU

To use OpenCL on supported developments boards with ARM Mali GPUs, you should download user-space binary drivers and place them in a directory where CK can find them (e.g. `/usr/lib').

Qualcomm Adreno GPU

Download and install drivers and SDK from this page.

Installing software dependencies for Caffe

Ubuntu target

You need to install the following common dependencies:

# apt install python-dev python-pip git wget unzip \
              coreutils build-essential make cmake \

Then you can install Caffe dependencies (note that you can also build latest OpenCV and Boost via CK if needed):

# apt install libboost-all-dev \
              libgflags-dev libgoogle-glog-dev \
              libhdf5-serial-dev \
              liblmdb-dev libleveldb-dev \
              libprotobuf-dev \
              protobuf-compiler \
              libsnappy-dev \
              libopencv-dev \
              protobuf 

You may also want to install optional productivity dependencies:

# apt install libatlas-base-dev python-opencv
# pip install jupyter pandas numpy scipy \
              matplotlib scikit-image scikit-learn pyyaml \
              protobuf

See detailed Ubuntu installation (if needed).

Gentoo target

See detailed Gentoo installation.

Yocto target

See detailed Yocto installation.

MacOSX target (experimental)

  • Visit brew.sh to install brew if you don't have it already
  • Use brew to install certain common dependencies that will be later autodetected and used by CK:
# brew install wget cmake llvm\@5 gcc\@6 snappy

Windows target

Download and install the following tools or unzip them to %USERPROFILE%\CK-TOOLS (to be automatically detected by CK):

  • Git: link
  • Anaconda scientific Python (2.7+ or 3.4+): link
  • Microsoft Visual Studio and Microsoft SDK (we tested free Visual Studio 2015 and 2017 x64 Community Edition; do not forget to select "Desktop development with C++" to install C++ compiler): link

During installation, CK will also automatically install:

Android target (Linux or Windows host)

Download and install or unzip to CK-TOOLS sub-directory in your home directory (CK will automatically detect them):

Note: we can build Caffe with standard GCC 4.9.x but LLVM still fails: see this note.

Installing CK and CK-Caffe

The minimal installation requires:

  • Python 2.7 or 3.3+ (limitation is mainly due to unitests)
  • Git command line client.

Linux/MacOS

You can install CK in your local user space simply as follows:

$ git clone http://github.com/ctuning/ck ck-master
$ export PATH=$PWD/ck-master/bin:$PATH
$ export PYTHONPATH=$PWD/ck-master:$PYTHONPATH

or via pip with sudo (then you don't need to set up environment variables yourself)

# pip install ck

Windows

First you need to download and install a few dependencies from the following sites:

You can then install CK as follows:

 $ git clone https://github.com/ctuning/ck.git ck-master
 $ set PATH={CURRENT PATH}\ck-master\bin;%PATH%
 $ set PYTHONPATH={CURRENT PATH}\ck-master;%PYTHONPATH%

or via pip

$ pip install ck

You can test that it's installed correctly via

$ ck version

For advanced CK installation, please check CK readme.

ck-caffe repository

You can now install CK-Caffe repository with all dependencies simply via

$ ck pull repo --url=https://github.com/dividiti/ck-caffe

Automatically building and running Caffe via CK

CK helps automatically rebuild and run various experimental scenarios on a given platform in a unified way.

By default, CK installs different versions of different packages to the {HOME}/CK-TOOLS directory. However it may be more convenient to install packages to CK "env" entries to be able to find and even delete them similar to virtual env. You can tell CK to install packages to CK entries as follows:

 $ ck set kernel var.install_to_env=yes

Next we will demonstrate how to time various models or perform image classification using CK-Caffe.

Linux

In order to time some model (AlexNet, GoogleNet, SqueezeNet) using Caffe CPU version just type

$ ck compile program:caffe-time --speed
$ ck run program:caffe-time

CK will normally pick up all installed dependencies on your host OS, download and install missing ones, ask you when there is more than once choice available, run timing scenario and return all times in JSON.

See other Caffe scenarios available via

$ ck search program:caffe*

For example, you can now classify an image on your host OS simply via

$ ck compile program:caffe-classification
$ ck run program:caffe-classification

Note, that if you want to compile and run timing and classification using CUDA or OpenCL Caffe versions just add "-cuda" or "-opencl" to a program such as

$ ck compile program:caffe-time-cuda
$ ck compile program:caffe-time-opencl

Finally, you can run caffe front-end with multiple command line options via

$ ck run program:caffe

Note that if you machine does not have much memory (Odroid, Raspberry Pi), you may first need to install a given package while reducing the number of parallel build jobs to 1-2 as follows:

$ ck install package --tags=lib,caffe,vcpu --env.CK_HOST_CPU_NUMBER_OF_PROCESSORS=1

Windows

CK allows you to install Caffe in exactly the same way as descried above for Linux.

The only note is that CK will need to download ~600Mb of various sources to automatically rebuild all dependencies on Windows including OpenCV, Boost, HDF5, etc - it may take 10-40 minutes to complete the whole build depending on your host machine.

Android

CK allows to easily retarget builds using shared OS descriptions. You can find the ones related to Android via

$ ck list os:android*

You can then compile Caffe classification example with all dependencies for an Android target (we use CK OS "android21-arm64" for Samsung S7) via

$ ck compile program:caffe-classification --target_os=android21-arm64

Note that CK will need to download ~600Mb of various sources to automatically rebuild all dependencies including OpenCV, Boost, etc - it may take 10-40 minutes to complete the whole build depending on your host machine.

If you device is connected to your host OS via adb, you can then run this scenario (CK will automatically copy all necessary binary files, libraries, models, and images to your device) via

$ ck run program:caffe-classification --target_os=android21-arm64

Note that we use above workflow to build various scenarios for our Android app to let users participate in collaborative DNN optimization (crowd-benchmarking and crowd-tuning) and share results via public CK repo.

Raspberry Pi

If you are getting build errors in which the compiler is being killed, it is likely that the compiler is running out of memory (especially if you are on Raspberry Pi 1, 2 or Zero, which have less than 1GB of RAM), this can often be rectified by increasing the swapfile size on the Pi by editing the file /etc/dphys-swapfile and changing the line CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024, then running:

 sudo vim /etc/dphys-swapfile

 sudo /etc/init.d/dphys-swapfile stop
 sudo /etc/init.d/dphys-swapfile start

Installing different models

We prepackaged different models to let users automatically install them via CK. You can see already available ones via:

$ ck list package:caffemodel*

You can then install any of them via

$ ck install package:{caffemodel name}

Installing different models

We prepackaged different models to let users automatically install them via CK. You can see already available ones via:

$ ck list package:caffemodel*

You can then install any of them via

$ ck install package:{caffemodel name}

Installing Python support via CK

First, you need to install all Python pre-requisites:

pip install jupyter pandas numpy scipy \
              matplotlib scikit-image scikit-learn pyyaml \
              protobuf

You can then build any of the above Caffe packages with Python support by setting flag --env.CAFFE_BUILD_PYTHON=ON (you should then use full Boost), i.e.

$ ck install package:lib-boost-1.65.1
$ ck install package:lib-caffe-bvlc-master-cpu-universal --env.CAFFE_BUILD_PYTHON=ON

You can then use Caffe from Python while setting up all necessary dependencies via CK as follows:

 $ ck virtual env --tags=lib,caffe
 $ python -c 'import caffe' && echo 'Caffe for Python seems to be healthy'

Installing Caffe packages with different dependencies via CK

CPU version (Linux, Windows, Android)

There is one universal CK package available to install CPU version across all OS:

$ ck install package:lib-caffe-bvlc-master-cpu-universal (--target_os={CK OS name})

OpenCL version

If your OpenCL device does not support unified memory but its driver claims it does (e.g. ARM Mali Midgard), you need to install packages with the following option:

$ ck install package:{CK package name} --env.DISABLE_DEVICE_HOST_UNIFIED_MEMORY=ON

For example, to install OpenCL Caffe for Samsung S7 use the following:

$ ck install package:lib-caffe-bvlc-opencl-clblast-universal --target_os=android21-arm64 --env.DISABLE_DEVICE_HOST_UNIFIED_MEMORY=ON

or with libdnn (sometimes doesn't compile due to latest changes in Caffe)

$ ck install package:lib-caffe-bvlc-opencl-libdnn-clblast-universal --target_os=android21-arm64 --env.DISABLE_DEVICE_HOST_UNIFIED_MEMORY=ON

On Odroid-XU3/4 you need to install package with the extra flag to avoid memory overflow:

$ ck install package:lib-caffe-bvlc-opencl-clblast-universal --env.DISABLE_DEVICE_HOST_UNIFIED_MEMORY=ON --env.CK_HOST_CPU_NUMBER_OF_PROCESSORS=2

When preparing Caffe to run on Intel GPU, you may want to turn on Intel Spatial engine by adding --env.USE_INTEL_SPATIAL=ON when installing related packages, i.e.

$ ck install package:lib-caffe-bvlc-opencl-libdnn-viennacl-universal --env.USE_INTEL_SPATIAL=ON

We plan to improve, automate and speed up OpenCL kernel caching in the future.

Caffe BVLC OpenCL+ViennaCL (Linux, Windows)

$ ck install package:lib-caffe-bvlc-opencl-viennacl-universal

Caffe BVLC OpenCL+clBLAS (Linux)

$ ck install package:lib-caffe-bvlc-opencl-clblas

TBD: should be converted to universal CK installer

Caffe BVLC OpenCL+CLBlast (Linux, Android)

$ ck install package:lib-caffe-bvlc-opencl-clblast-universal (--target_os={CK OS name})

TBD: currently has a few issues when compiling on Windows - help appreciated!

Caffe BVLC OpenCL+libDNN (Linux, Windows)

$ ck install package:lib-caffe-bvlc-opencl-libdnn-viennacl-universal

Caffe BVLC OpenCL+libDNN+clBLAS (Linux)

$ ck install package:lib-caffe-bvlc-opencl-libdnn-clblas

TBD: should be converted to universal CK installer

Caffe BVLC OpenCL+libDNN+CLBlast (Linux, Android)

$ ck install package:lib-caffe-bvlc-opencl-libdnn-clblast-universal (--target_os={CK OS name})

Caffe BVLC OpenCL+ACL (Linux)

You can install Caffe with ARM Compute Library and test it as follows:

$ ck install package --tags=armcl,vopencl --env.USE_EMBEDDED_KERNELS=ON --env.USE_NEON=ON --env.ASSERTS=ON --env.WERROR=ON
$ ck install package --tags=lib,caffe,varmcl
$ ck compile program:caffe-classification-opencl-armcl
$ ck run program:caffe-classification-opencl-armcl

CUDA version

Caffe BVLC CUDA (Linux)

$ ck install package:lib-caffe-bvlc-master-cuda

TBD: should be converted to universal CK installer

Caffe BVLC CUDA+cuDNN (Linux)

$ ck install package:lib-caffe-bvlc-master-cudnn

TBD: should be converted to universal CK installer

Caffe NVIDIA CUDA (Linux)

$ ck install package:lib-caffe-nvidia-0.15-cuda

TBD: should be converted to universal CK installer

Caffe NVIDIA cuDNN (Linux)

$ ck install package:lib-caffe-nvidia-0.15-cudnn

TBD: should be converted to universal CK installer

Caffe NVIDIA FP16 CUDA (Linux)

$ ck install package:lib-caffe-nvidia-fp16-cuda

TBD: should be converted to universal CK installer

Caffe NVIDIA FP16 cuDNN (Linux)

$ ck install package:lib-caffe-nvidia-fp16-cudnn

TBD: should be converted to universal CK installer

Caffe NVIDIA FP16 EMU CUDA (Linux)

$ ck install package:lib-caffe-nvidia-fp16-emu-cuda

TBD: should be converted to universal CK installer

Caffe NVIDIA FP16 EMU cuDNN (Linux)

$ ck install package:lib-caffe-nvidia-fp16-emu-cudnn

TBD: should be converted to universal CK installer

Packaging Caffe library and binaries for distribution

Windows

It is now possible to prepare Caffe package with pre-built library and binaries via CK as follows:

 $ ck distribution:lib-caffe-bvlc-master-cpu-universal
 $ ck distribution:lib-caffe-bvlc-opencl-libdnn-viennacl-universal

We prepared two Caffe packages (CPU and OpenCL) for Windows to let users participate in DNN crowd-benchmarking without installing compilers and many dependencies. You can install pre-compiled packages simply as follows:

 $ ck install package:lib-caffe-bvlc-master-cpu-bin-win
 $ ck install package:lib-caffe-bvlc-opencl-libdnn-viennacl-bin-win

Pre-built CK packages are available here.

You can then participate in DNN crowd-benchmarking using your machine as follows:

$ ck crowdbench caffe --user={any ID only if you want to identify your contributions} --env.CK_CAFFE_BATCH_SIZE=1

Troubleshooting

OpenBLAS

Installation of OpenBLAS can fail on some platforms if their CPU is not properly identified. In such cases you can force specific CPU (for example AMD BARCELONA) as follows:

 $ ck install package:lib-openblas-0.2.19-universal --env.OPENBLAS_TARGET=BARCELONA

Feedback

Note that it's an on-going and heavily evolving community project. Please send your questions, comments and any other feedback to http://groups.google.com/group/collective-knowledge .

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.