Skip to content

Add ARM64 toolchain for cross compilation#164

Closed
dkurt wants to merge 1 commit intoopenvinotoolkit:2019from
dkurt:aarch64
Closed

Add ARM64 toolchain for cross compilation#164
dkurt wants to merge 1 commit intoopenvinotoolkit:2019from
dkurt:aarch64

Conversation

@dkurt
Copy link
Copy Markdown
Contributor

@dkurt dkurt commented May 29, 2019

To Build IE for ARM64 (aarch64) you may follow the instructions at https://github.com/opencv/dldt/tree/2019/inference-engine#build-for-raspbian-stretch-os. In case of cross compilation using Docker, replace debian to target OS and armhf to arm64.

For Raspberry Pi 3 there are at least Ubuntu 18 and Debian 9.

Here is a Dockerfile to build IE and OpenCV with IE backend for Ubuntu OS on ARM64:

  1. Create a folder ie_cross_aarch64 with Dockerfile (see content below)
  2. Build: docker image build ie_cross_aarch64 -t ie_cross_aarch64
  3. Run container: docker run ie_cross_aarch64
  4. Check container's id:
$ docker container ls --all
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                         PORTS               NAMES
f1151f172d2e        ie_cross_aarch64        "/bin/bash"              24 seconds ago      Exited (0) 22 seconds ago 
  1. Copy binaries: docker cp f1151f172d2e:opencv_install.tar.xz .
  2. Copy to the board, unpack and set environment:
export LD_LIBRARY_PATH=/home/ubuntu/opencv_install/lib
export PYTHONPATH=/home/ubuntu/opencv_install/lib/python3.6/dist-packages/

Dockerfile:

FROM ubuntu:18.04

USER root

RUN sed -i -E 's|^deb ([^ ]+) (.*)$|deb [arch=amd64] \1 \2\ndeb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ \2|' /etc/apt/sources.list && \
    dpkg --add-architecture arm64 && apt-get update && \
    apt-get install -y --no-install-recommends \
        crossbuild-essential-arm64 \
        git \
        cmake \
        ca-certificates \
        libpython-dev:arm64 \
        libpython3-dev:arm64 \
        libusb-1.0-0-dev:arm64 \
        python-numpy \
        python3-numpy \
        libgstreamer1.0-dev:arm64 \
        libgstreamer-plugins-base1.0-dev:arm64

# Download OpenCV
RUN git clone https://github.com/opencv/opencv.git --depth 1

# Download DLDT
# TODO: fix when changes will be merged
RUN git clone https://github.com/dkurt/dldt && cd dldt && \
    git checkout aarch64 && git submodule init && git submodule update --recursive

# Download TBB
RUN git clone https://github.com/intel/tbb  --depth 1

# Build TBB
RUN cd tbb && \
    sed -i -E 's|CPLUS \?= g\+\+|CPLUS ?= aarch64-linux-gnu-g++|' build/linux.gcc.inc && \
    sed -i -E 's|CONLY \?= gcc|CPLUS ?= aarch64-linux-gnu-gcc|' build/linux.gcc.inc && \
    cat build/linux.gcc.inc && \
    make -j4 arch=aarch64

# Build DLDT
RUN cd /dldt/inference-engine && mkdir build && cd build && \
    cmake -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_TOOLCHAIN_FILE="../cmake/arm64.toolchain.cmake" \
          -DENABLE_SSE42=OFF \
          -DENABLE_GNA=OFF \
          -DENABLE_CLDNN=OFF \
          -DENABLE_OPENCV=OFF \
          -DTBB_INCLUDE_DIRS=/tbb/include \
          -DTBB_LIBRARIES_RELEASE=/tbb/build/linux_aarch64_gcc_cc_libc2.27_kernel4.15.0_release/libtbb.so \
          -DTBB_LIBRARIES_DEBUG=/tbb/build/linux_aarch64_gcc_cc_libc2.27_kernel4.15.0_debug/libtbb.so \
          -DCMAKE_CXX_FLAGS="-Wno-error=attributes" .. && make -j8

# Build OpenCV
RUN cd /opencv && mkdir build && cd build && \
    cmake -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_INSTALL_PREFIX="../opencv_install" \
          -DOPENCV_CONFIG_INSTALL_PATH="cmake" \
          -DCMAKE_TOOLCHAIN_FILE="../platforms/linux/aarch64-gnu.toolchain.cmake" \
          -DWITH_IPP=OFF \
          -DBUILD_TESTS=OFF \
          -DBUILD_PERF_TESTS=OFF \
          -DOPENCV_ENABLE_PKG_CONFIG=ON \
          -DPKG_CONFIG_EXECUTABLE="/usr/bin/aarch64-linux-gnu-pkg-config" \
          -DPYTHON2_INCLUDE_PATH="/usr/include/python2.7" \
          -DPYTHON2_NUMPY_INCLUDE_DIRS="/usr/local/lib/python2.7/dist-packages/numpy/core/include" \
          -DPYTHON3_INCLUDE_PATH="/usr/include/python3.6" \
          -DPYTHON3_NUMPY_INCLUDE_DIRS="/usr/local/lib/python3.6/dist-packages/numpy/core/include" \
          -DPYTHON3_CVPY_SUFFIX=".cpython-36m-aarch64-linux-gnu.so" \
          -DENABLE_NEON=ON \
          -DCPU_BASELINE="NEON" \
          -DWITH_INF_ENGINE=ON \
          -DInferenceEngine_DIR="/dldt/inference-engine/build" .. && make -j8 && make install

RUN cp /dldt/inference-engine/bin/aarch64/Release/lib/*.so /opencv/opencv_install/lib && \
    cp /tbb/build/linux_aarch64_gcc_cc_libc2.27_kernel4.15.0_release/libtbb.so /opencv/opencv_install/lib && \
    cp /tbb/build/linux_aarch64_gcc_cc_libc2.27_kernel4.15.0_release/libtbb.so.2 /opencv/opencv_install/lib && \
    tar -czf opencv_install.tar.xz -C /opencv/opencv_install .

@openvino-pushbot
Copy link
Copy Markdown
Contributor

Can one of the admins verify this patch?

@dkurt dkurt closed this Sep 21, 2019
@dkurt dkurt mentioned this pull request Oct 15, 2019
rolfmorel pushed a commit to rolfmorel/openvino that referenced this pull request Aug 8, 2024
Allows to build OV benchmarks with multiple layers, both baseline and pytorch.

---------

Co-authored-by: Adam Siemieniuk <adam.siemieniuk@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants