Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amir-saniyan/67ac5e78fbb2355e231ee2def8246264 to your computer and use it in GitHub Desktop.
Save amir-saniyan/67ac5e78fbb2355e231ee2def8246264 to your computer and use it in GitHub Desktop.
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_CUDA_HOST_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_FIND_ROOT_PATH "/usr/aarch64-linux-gnu;/usr/local/aarch64-linux-gnu;~/OpenBLAS/aarch64-linux-gnu")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "arm")
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_CUDA_HOST_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_FIND_ROOT_PATH "/usr/arm-linux-gnueabihf;/usr/local/arm-linux-gnueabihf;~/OpenBLAS/arm-linux-gnueabihf")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Cross-compiling MXNet on Ubuntu for Raspberry Pi

Obtaining the toolchain

$ sudo apt install crossbuild-essential-armhf
$ sudo apt install crossbuild-essential-arm64 

ARM hard-float (armhf)

Cross-compiling dependencies:

$ git clone --recursive https://github.com/xianyi/OpenBLAS.git
$ cd OpenBLAS
$ make NOFORTRAN=1 NO_SHARED=1 CC=arm-linux-gnueabihf-gcc HOSTCC=gcc TARGET=ARMV7
$ make NOFORTRAN=1 NO_SHARED=1 CC=arm-linux-gnueabihf-gcc HOSTCC=gcc TARGET=ARMV7 PREFIX=~/OpenBLAS/arm-linux-gnueabihf install

Cross-compiling MXNet:

$ cd apache-mxnet-src-x.y.z-incubating
$ mkdir build
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE=../arm-linux-gnueabihf-toolchain.cmake \
	-DUSE_CUDA=OFF \
	-DSUPPORT_F16C=OFF \
	-DUSE_OPENCV=OFF \
	-DUSE_OPENMP=ON \
	-DUSE_LAPACK=OFF \
	-DUSE_SIGNAL_HANDLER=ON \
	-DCMAKE_BUILD_TYPE=Release \
	-DUSE_MKL_IF_AVAILABLE=OFF \
	-G Ninja ..
$ ninja
$ cmake --install . --prefix ~/MXNet/arm-linux-gnueabihf
$ cd ../python
$ export MXNET_LIBRARY_PATH=$(pwd)/build/libmxnet.so
$ python3 setup.py bdist_wheel
$ cp dist/*.whl ~/MXNet/arm-linux-gnueabihf

64-bit ARM (arm64)

Cross-compiling dependencies:

$ git clone --recursive https://github.com/xianyi/OpenBLAS.git
$ cd OpenBLAS
$ make NOFORTRAN=1 NO_SHARED=1 CC=aarch64-linux-gnu-gcc HOSTCC=gcc TARGET=ARMV8
$ make NOFORTRAN=1 NO_SHARED=1 CC=aarch64-linux-gnu-gcc HOSTCC=gcc TARGET=ARMV8 PREFIX=~/OpenBLAS/aarch64-linux-gnu install

Cross-compiling MXNet:

$ cd apache-mxnet-src-x.y.z-incubating
$ mkdir build
$ cd build
$ cmake -DCMAKE_TOOLCHAIN_FILE=../aarch64-linux-gnu-toolchain.cmake \
	-DUSE_CUDA=OFF \
	-DSUPPORT_F16C=OFF \
	-DUSE_OPENCV=OFF \
	-DUSE_OPENMP=ON \
	-DUSE_LAPACK=OFF \
	-DUSE_SIGNAL_HANDLER=ON \
	-DCMAKE_BUILD_TYPE=Release \
	-DUSE_MKL_IF_AVAILABLE=OFF \
	-G Ninja ..
$ ninja
$ cmake --install . --prefix ~/MXNet/aarch64-linux-gnu
$ cd ../python
$ export MXNET_LIBRARY_PATH=$(pwd)/build/libmxnet.so
$ python3 setup.py bdist_wheel
$ cp dist/*.whl ~/MXNet/aarch64-linux-gnu

If you would like to compile MXNet with OpenCV support, enabling various image transformation related features, you also need to cross-compile OpenCV.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment