Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amir-saniyan/b56afd1384e8975928221fe5ba4a9204 to your computer and use it in GitHub Desktop.
Save amir-saniyan/b56afd1384e8975928221fe5ba4a9204 to your computer and use it in GitHub Desktop.

Cross compiling ONNX Runtime on Ubuntu for Raspberry Pi

The following steps shows how to cross compiling ONNX Runtime on Ubuntu for Raspberry Pi with docker.

Install Docker Engine

Install qemu

$ sudo apt install qemu qemu-user-static binfmt-support

Download Source Code

$ git clone --recursive https://github.com/Microsoft/onnxruntime
$ cd onnxruntime
$ git checkout v1.10.0
$ git submodule update --init --recursive

Note: You can checkout another version of ONNX Runtime. For list of all tags, run git tag command on terminal.

Patch Source Code

If your build failed, you should patch the following lines in the source code.

File onnxruntime/cmake/external/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:

  • Line 1633: Change memcpy(res, from, sizeof(Packet4c)); to memcpy((void*)(&res), (const void*)from, sizeof(Packet4c));.
  • Line 1678: Change memcpy(res, from, sizeof(Packet4c)); to memcpy((void*)(&res), (const void*)from, sizeof(Packet4c));.

Build with Docker

Note: Make sure your current working directory ponits to the root directory of onnxruntime source code.

$ pwd
$ docker container run \
    --name onnxruntime \
    --tty \
    --interactive \
    --volume $(pwd):/src \
    arm32v7/fedora:34

Run the following commands in docker container terminal:

$ dnf install -y binutils
$ dnf install -y gcc
$ dnf install -y gcc-c++
$ dnf install -y git
$ dnf install -y cmake
$ dnf install -y aria2

$ cd /src

$ ./build.sh --help

$ ./build.sh \
    --config Release \
    --update \
    --build \
    --parallel \
    --skip_tests \
    --build_shared_lib \
    --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER)

$ exit

After successful build, build/Linux/Release directory contains onnxruntime shared libraries.

Resources

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