How to build Caffe2 - t-kuha/zynq-library GitHub Wiki
Environment
- Host: Ubuntu 16.04 (x64)
- CMake: 3.12.2
- Caffe2: Pytorch 0.4.1
- PetaLinux: 2018.2
Get source code
# Clone PyTorch repo
$ git clone --recursive https://github.com/pytorch/pytorch.git
$ cd pytorch
$ git checkout v0.4.1
$ git submodule update
Build protoc for host
$ scripts/build_host_protoc.sh
# Copy js_embed
$ cp ./build_host_protoc/build/js_embed ./build_host_protoc/bin/
Build caffe2
# Create output directory
# This directory does not have to be in root of PyTorch source
$ mkdir _caffe2
$ cd _caffe2
# -DCAFFE2_CUSTOM_PROTOC_EXECUTABLE is the crucial part
# Specify it by the absolute path.
# You may want to enable ARM compute library (i.e. -DUSE_ACL=ON)
$ cmake <Root of PyTorch source> \
-G"Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE=<Path to toolchain.make> \
-DCMAKE_CROSSCOMPILING=1 \
-DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=<Root of PyTorch source>/build_host_protoc/bin/protoc \
-DCMAKE_INSTALL_PREFIX=`pwd`/_install \
-DUSE_CUDA=OFF \
-DUSE_METAL=OFF \
-DUSE_MOBILE_OPENGL=OFF \
-DUSE_NCCL=OFF \
-DUSE_GFLAGS=OFF \
-DUSE_GLOG=OFF \
-DUSE_LEVELDB=OFF \
-DUSE_LMDB=OFF \
-DUSE_MPI=OFF \
-DBUILD_PYTHON=OFF
# Set path to js_embed for host
$ PATH=${PATH}:<Root of PyTorch source>/build_host_protoc/bin make -j`nproc`
$ make install