From: Jegathesan Shanmugam Date: Thu, 26 Mar 2020 17:17:37 +0000 (+0530) Subject: Github #111 X-Git-Tag: submit/tizen/20210421.062230~522 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bdba27251490b971e60d79261e14225cc7bfedcf;p=platform%2Fupstream%2Farmnn.git Github #111 Added Dockerfile to build ArmNN under an x86_64 system to target an Arm64 system. Signed-off-by: Jegathesan Shanmugam Change-Id: I244bab37cc5fe7b38a22d4b530d42e593f223d79 --- diff --git a/docker/README.md b/docker/README.md index 85e5d28..beb2018 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,13 +1,34 @@ -# DOCKER IMAGES for ARMNN Compilation Environment +# ARMNN Docker Files + + +## [Android NDK to build ArmNN](https://github.com/ARM-software/armnn/blob/branches/armnn_20_02/BuildGuideAndroidNDK.md):
+ +armnn-android folder has the docker file to build a Android NDK container to build ARMNN. + +## [ArmNN on x86_64 for arm64](https://github.com/ARM-software/armnn/blob/branches/armnn_20_02/BuildGuideCrossCompilation.md) + +x86_64 folder has the docker file to build ArmNN under an x86_64 system to target an Arm64 system. # To build a docker images +```bash docker build --rm --build-arg proxy=$http_proxy --rm --tag armnn:v1 . +``` # To Run docker images +```bash docker run -v /etc/localtime:/etc/localtime:ro --rm -it -e http_proxy -e https_proxy -e ftp_proxy -v `pwd`:/work armnn:v1 bash +``` # To run a docker with X11 support for GUI Application +```bash docker run -v /etc/localtime:/etc/localtime:ro --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -e http_proxy -e https_proxy -e ftp_proxy -v `pwd`:/work armnn:v1 bash +``` # To mount the camera and access camera from docker env +```bash docker run -v /etc/localtime:/etc/localtime:ro --rm -it --device /dev/video0 -e http_proxy -e https_proxy -e ftp_proxy -v `pwd`:/work armnn:v1 bash +``` + + + + diff --git a/docker/x86_64/Dockerfile b/docker/x86_64/Dockerfile new file mode 100644 index 0000000..f961815 --- /dev/null +++ b/docker/x86_64/Dockerfile @@ -0,0 +1,164 @@ +FROM ubuntu:16.04 +ENV TERM linux +ENV DEBIAN_FRONTEND noninteractive + +# Forward system proxy setting +# ARG proxy +# ENV http_proxy $proxy +# ENV https_proxy $proxy + +# Basic apt update +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends locales ca-certificates && rm -rf /var/lib/apt/lists/* + +# Set the locale to en_US.UTF-8, because the Yocto build fails without any locale set. +RUN locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LC_ALL en_US.UTF-8 + +# Again, off the certificare +RUN echo "check_certificate = off" >> ~/.wgetrc +RUN echo "[global] \n\ +trusted-host = pypi.python.org \n \ +\t pypi.org \n \ +\t files.pythonhosted.org" >> /etc/pip.conf + +# Get basic packages +RUN apt-get update && apt-get install -y \ + apparmor \ + aufs-tools \ + automake \ + bash-completion \ + btrfs-tools \ + build-essential \ + cmake \ + createrepo \ + curl \ + dpkg-sig \ + g++ \ + gcc \ + git \ + iptables \ + jq \ + libapparmor-dev \ + libc6-dev \ + libcap-dev \ + libsystemd-dev \ + libyaml-dev \ + mercurial \ + net-tools \ + parallel \ + pkg-config \ + python-dev \ + python-mock \ + python-pip \ + python-setuptools \ + python-websocket \ + golang-go \ + iproute2 \ + iputils-ping \ + vim-common \ + vim \ + wget \ + libtool \ + unzip \ + scons \ + curl \ + autoconf \ + libtool \ + build-essential \ + g++ \ + cmake && rm -rf /var/lib/apt/lists/* + +# Install Cross-compiling ToolChain +RUN apt-get update && apt-get install -y crossbuild-essential-arm64 + +# Build and install Google's Protobuf library +# Download and Extract +RUN mkdir -p $HOME/google && \ + cd $HOME/google && \ + wget https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protobuf-all-3.5.1.tar.gz && \ + tar -zxvf protobuf-all-3.5.1.tar.gz + +# Build a native (x86_64) version +RUN cd $HOME/google/protobuf-3.5.1 && \ + mkdir x86_build && cd x86_build && \ + ../configure --prefix=$HOME/armnn-devenv/google/x86_64_pb_install && \ + make install -j16 + +# Build the arm64 version of the protobuf libraries +RUN cd $HOME/google/protobuf-3.5.1 && \ + mkdir arm64_build && cd arm64_build && \ + export CC=aarch64-linux-gnu-gcc && \ + export CXX=aarch64-linux-gnu-g++ && \ + ../configure --host=aarch64-linux \ + --prefix=$HOME/armnn-devenv/google/arm64_pb_install \ + --with-protoc=$HOME/armnn-devenv/google/x86_64_pb_install/bin/protoc && \ + make install -j16 + +# Build Caffe for x86_64 +# Dep Install +RUN apt-get update && apt-get install -y \ + libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev \ + --no-install-recommends libboost-all-dev \ + libgflags-dev libgoogle-glog-dev liblmdb-dev \ + libopenblas-dev \ + libatlas-base-dev + + +# Download +RUN cd $HOME && git clone https://github.com/BVLC/caffe.git + +# Makefile update +# To Do: Don't copy the Local Make file to docker +# RUN cd $HOME/caffe/ && rm Makefile.config.example +COPY Makefile.config /tmp +RUN mv /tmp/Makefile.config $HOME/caffe/ + +# Dep Error - Bug ARMNN +RUN apt-get update && apt-get install -y \ + python-numpy + +# Setup Env +# ENV PATH=$HOME/armnn-devenv/google/x86_64_pb_install/bin/:$PATH +# ENV LD_LIBRARY_PATH=$HOME/armnn-devenv/google/x86_64_pb_install/lib/:$LD_LIBRARY_PATH + +# Compile CAFFE +RUN cd $HOME/caffe/ && mkdir build && cd build && \ + export PATH=$HOME/armnn-devenv/google/x86_64_pb_install/bin/:$PATH && \ + export LD_LIBRARY_PATH=$HOME/armnn-devenv/google/x86_64_pb_install/lib/:$LD_LIBRARY_PATH && \ + ldconfig && \ + cmake ../ && \ + make all -j8 && \ + make test -j8 && \ + make runtest -j8 + +# Build Boost library for arm64 +RUN cd $HOME && wget http://downloads.sourceforge.net/project/boost/boost/1.64.0/boost_1_64_0.tar.gz && \ + tar xfz boost_1_64_0.tar.gz && \ + rm boost_1_64_0.tar.gz && \ + cd boost_1_64_0 && \ + echo "using gcc : arm : aarch64-linux-gnu-g++ ;" > user_config.jam && \ + ./bootstrap.sh --prefix=$HOME/armnn-devenv/boost_arm64_install && \ + ./b2 install toolset=gcc-arm link=static cxxflags=-fPIC --with-filesystem --with-test --with-log --with-program_options -j32 --user-config=user_config.jam + +# Build Compute Library +RUN cd $HOME/armnn-devenv/ && git clone https://github.com/ARM-software/ComputeLibrary.git && \ + cd ComputeLibrary && \ + scons arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags="-fPIC" -j8 internal_only=0 + +# Build ArmNN +RUN cd $HOME && git clone https://github.com/ARM-software/armnn.git && \ + cd armnn && mkdir build && cd build && \ + export CXX=aarch64-linux-gnu-g++ && \ + export CC=aarch64-linux-gnu-gcc && \ + cmake .. \ + -DARMCOMPUTE_ROOT=$HOME/armnn-devenv/ComputeLibrary \ + -DARMCOMPUTE_BUILD_DIR=$HOME/armnn-devenv/ComputeLibrary/build/ \ + -DBOOST_ROOT=$HOME/armnn-devenv/boost_arm64_install/ \ + -DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \ + -DCAFFE_GENERATED_SOURCES=$HOME/caffe/build/include \ + -DBUILD_CAFFE_PARSER=1 \ + -DPROTOBUF_ROOT=$HOME/armnn-devenv/google/x86_64_pb_install/ \ + -DPROTOBUF_LIBRARY_DEBUG=$HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so.15.0.1 \ + -DPROTOBUF_LIBRARY_RELEASE=$HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so.15.0.1 && \ + make -j8 diff --git a/docker/x86_64/Makefile.config b/docker/x86_64/Makefile.config new file mode 100644 index 0000000..7f9b196 --- /dev/null +++ b/docker/x86_64/Makefile.config @@ -0,0 +1,125 @@ +## Refer to http://caffe.berkeleyvision.org/installation.html +# Contributions simplifying and improving our build system are welcome! + +# cuDNN acceleration switch (uncomment to build with cuDNN). +# USE_CUDNN := 1 + +# CPU-only switch (uncomment to build without GPU support). +CPU_ONLY := 1 + +# uncomment to disable IO dependencies and corresponding data layers +# USE_OPENCV := 0 +# USE_LEVELDB := 0 +# USE_LMDB := 0 +# This code is taken from https://github.com/sh1r0/caffe-android-lib +# USE_HDF5 := 0 + +# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary) +# You should not set this flag if you will be reading LMDBs with any +# possibility of simultaneous read and write +# ALLOW_LMDB_NOLOCK := 1 + +# Uncomment if you're using OpenCV 3 +# OPENCV_VERSION := 3 + +# To customize your choice of compiler, uncomment and set the following. +# N.B. the default for Linux is g++ and the default for OSX is clang++ +# CUSTOM_CXX := g++ + +# CUDA directory contains bin/ and lib/ directories that we need. +CUDA_DIR := /usr/local/cuda +# On Ubuntu 14.04, if cuda tools are installed via +# "sudo apt-get install nvidia-cuda-toolkit" then use this instead: +# CUDA_DIR := /usr + +# CUDA architecture setting: going with all of them. +# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility. +# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility. +# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility. +CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \ + -gencode arch=compute_20,code=sm_21 \ + -gencode arch=compute_30,code=sm_30 \ + -gencode arch=compute_35,code=sm_35 \ + -gencode arch=compute_50,code=sm_50 \ + -gencode arch=compute_52,code=sm_52 \ + -gencode arch=compute_60,code=sm_60 \ + -gencode arch=compute_61,code=sm_61 \ + -gencode arch=compute_61,code=compute_61 + +# BLAS choice: +# atlas for ATLAS (default) +# mkl for MKL +# open for OpenBlas +BLAS := atlas +# Custom (MKL/ATLAS/OpenBLAS) include and lib directories. +# Leave commented to accept the defaults for your choice of BLAS +# (which should work)! +# BLAS_INCLUDE := /path/to/your/blas +# BLAS_LIB := /path/to/your/blas + +# Homebrew puts openblas in a directory that is not on the standard search path +# BLAS_INCLUDE := $(shell brew --prefix openblas)/include +# BLAS_LIB := $(shell brew --prefix openblas)/lib + +# This is required only if you will compile the matlab interface. +# MATLAB directory should contain the mex binary in /bin. +# MATLAB_DIR := /usr/local +# MATLAB_DIR := /Applications/MATLAB_R2012b.app + +# NOTE: this is required only if you will compile the python interface. +# We need to be able to find Python.h and numpy/arrayobject.h. +PYTHON_INCLUDE := /usr/include/python2.7 \ + /usr/lib/python2.7/dist-packages/numpy/core/include +# Anaconda Python distribution is quite popular. Include path: +# Verify anaconda location, sometimes it's in root. +# ANACONDA_HOME := $(HOME)/anaconda +# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ + # $(ANACONDA_HOME)/include/python2.7 \ + # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include + +# Uncomment to use Python 3 (default is Python 2) +# PYTHON_LIBRARIES := boost_python3 python3.5m +# PYTHON_INCLUDE := /usr/include/python3.5m \ +# /usr/lib/python3.5/dist-packages/numpy/core/include + +# We need to be able to find libpythonX.X.so or .dylib. +PYTHON_LIB := /usr/lib +# PYTHON_LIB := $(ANACONDA_HOME)/lib + +# Homebrew installs numpy in a non standard path (keg only) +# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include +# PYTHON_LIB += $(shell brew --prefix numpy)/lib + +# Uncomment to support layers written in Python (will link against Python libs) +# WITH_PYTHON_LAYER := 1 + +# Whatever else you find you need goes here. +INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/ \ + /root/armnn-devenv/google/x86_64_pb_install/include/ +LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/ \ + /root/armnn-devenv/google/x86_64_pb_install/lib/ + +# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies +# INCLUDE_DIRS += $(shell brew --prefix)/include +# LIBRARY_DIRS += $(shell brew --prefix)/lib + +# NCCL acceleration switch (uncomment to build with NCCL) +# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0) +# USE_NCCL := 1 + +# Uncomment to use `pkg-config` to specify OpenCV library paths. +# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.) +# USE_PKG_CONFIG := 1 + +# N.B. both build and distribute dirs are cleared on `make clean` +BUILD_DIR := build +DISTRIBUTE_DIR := distribute + +# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 +# DEBUG := 1 + +# The ID of the GPU that 'make runtest' will use to run unit tests. +TEST_GPUID := 0 + +# enable pretty build (comment to see full commands) +Q ?= @