-
Notifications
You must be signed in to change notification settings - Fork 40
Installation
[ 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).
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'`).
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
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.
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.
Your latest GPU driver should normally support OpenCL. You just need to download and install the Intel OpenCL SDK.
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').
Download and install drivers and SDK from this page.
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).
See detailed Gentoo installation.
See detailed Yocto installation.
- 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
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:
- Perl: (needed for OpenBLAS)
- MinGW W64 GCC to compile OpenBLAS (we tested GCC 6.3 x64): link (you will need 7z to unzip this file)
Download and install or unzip to CK-TOOLS sub-directory in your home directory (CK will automatically detect them):
- Android command line tools.
- Android NDK - we compile Caffe for Android with GCC 4.9.x, however some packages can already be compiled with CLANG.
Note: we can build Caffe with standard GCC 4.9.x but LLVM still fails: see this note.
The minimal installation requires:
- Python 2.7 or 3.3+ (limitation is mainly due to unitests)
- Git command line client.
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
First you need to download and install a few dependencies from the following sites:
- Git: https://git-for-windows.github.io
- Minimal Python: https://www.python.org/downloads/windows
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.
You can now install CK-Caffe repository with all dependencies simply via
$ ck pull repo --url=https://github.com/dividiti/ck-caffe
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.
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
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.
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.
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
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}
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}
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'
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})
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.
$ ck install package:lib-caffe-bvlc-opencl-viennacl-universal
$ ck install package:lib-caffe-bvlc-opencl-clblas
TBD: should be converted to universal CK installer
$ 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!
$ ck install package:lib-caffe-bvlc-opencl-libdnn-viennacl-universal
$ ck install package:lib-caffe-bvlc-opencl-libdnn-clblas
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-bvlc-opencl-libdnn-clblast-universal (--target_os={CK OS name})
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
$ ck install package:lib-caffe-bvlc-master-cuda
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-bvlc-master-cudnn
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-nvidia-0.15-cuda
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-nvidia-0.15-cudnn
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-nvidia-fp16-cuda
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-nvidia-fp16-cudnn
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-nvidia-fp16-emu-cuda
TBD: should be converted to universal CK installer
$ ck install package:lib-caffe-nvidia-fp16-emu-cudnn
TBD: should be converted to universal CK installer
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
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
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 .