diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 82e9d04e7d..ef0f7e1e08 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -578,6 +578,10 @@ else() list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS} Threads::Threads) endif() +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + list(APPEND onnxruntime_EXTERNAL_LIBRARIES log) +endif() + #The following files may use the 'onnxruntime_libs' and 'onnxruntime_EXTERNAL_LIBRARIES' vars if (onnxruntime_BUILD_SHARED_LIB) diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake index d0b8828e6f..1bb72d14b5 100644 --- a/cmake/onnxruntime_mlas.cmake +++ b/cmake/onnxruntime_mlas.cmake @@ -69,6 +69,18 @@ if (MSVC) endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + if(CMAKE_ANDROID_ARCH_ABI MATCHES "^arm.*") + if (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon") + endif() + + set(mlas_platform_srcs + ${ONNXRUNTIME_ROOT}/core/mlas/lib/arm/sgemmc.cpp + ) + else() + message(FATAL_ERROR "Android build is not supported on non-ARM platform now") + endif() else() execute_process( diff --git a/tools/ci_build/github/azure-pipelines/android-arm64-crosscompile-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/android-arm64-crosscompile-ci-pipeline.yml new file mode 100644 index 0000000000..0243752fbb --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/android-arm64-crosscompile-ci-pipeline.yml @@ -0,0 +1,15 @@ +jobs: +- job: Linux_CI_Dev + pool: Linux-CPU + steps: + - template: templates/set-test-data-variables-step.yml + + - script: 'tools/ci_build/github/linux/run_dockerbuild.sh -o android -r $(Build.BinariesDirectory) -d cpu' + displayName: 'Command Line Script' + + - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0 + displayName: 'Component Detection' + condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI')) + + - template: templates/clean-agent-build-directory-step.yml + diff --git a/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_for_android b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_for_android new file mode 100644 index 0000000000..822e4c39ac --- /dev/null +++ b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_for_android @@ -0,0 +1,35 @@ +ARG OS_VERSION=16.04 +FROM ubuntu:${OS_VERSION} + +ARG PYTHON_VERSION=3.5 + +ADD scripts /tmp/scripts +ENV PATH="/opt/cmake/bin:${PATH}" +RUN /tmp/scripts/install_ubuntu_for_android.sh -p ${PYTHON_VERSION} && /tmp/scripts/install_deps_android.sh && rm -rf /tmp/scripts + +WORKDIR /root + +# Build and Install LLVM +# ARG LLVM_VERSION=6.0.1 +# RUN cd /tmp && \ +# wget --no-verbose http://releases.llvm.org/$LLVM_VERSION/llvm-$LLVM_VERSION.src.tar.xz && \ +# xz -d llvm-$LLVM_VERSION.src.tar.xz && \ +# tar xvf llvm-$LLVM_VERSION.src.tar && \ +# cd llvm-$LLVM_VERSION.src && \ +# mkdir -p build && \ +# cd build && \ +# cmake .. -DCMAKE_BUILD_TYPE=Release && \ +# cmake --build . -- -j$(nproc) && \ +# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/llvm-$LLVM_VERSION -DBUILD_TYPE=Release -P cmake_install.cmake && \ +# cd /tmp && \ +# rm -rf llvm* + +ENV LD_LIBRARY_PATH /usr/local/openblas/lib:$LD_LIBRARY_PATH + +ARG BUILD_UID=1000 +ARG BUILD_USER=onnxruntimedev +WORKDIR /home/$BUILD_USER +RUN adduser --gecos 'onnxruntime Build User' --disabled-password $BUILD_USER --uid $BUILD_UID +USER $BUILD_USER + + diff --git a/tools/ci_build/github/linux/docker/scripts/install_deps_android.sh b/tools/ci_build/github/linux/docker/scripts/install_deps_android.sh new file mode 100755 index 0000000000..79d680e49b --- /dev/null +++ b/tools/ci_build/github/linux/docker/scripts/install_deps_android.sh @@ -0,0 +1,45 @@ +#!/bin/bash +set -e +#download Android NDK r19c +aria2c -q -d /tmp https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip +unzip -oq /tmp/android-ndk-r19c-linux-x86_64.zip -d /tmp/android-ndk && mv /tmp/android-ndk/* /android-ndk +#install ninja +aria2c -q -d /tmp https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip +unzip -oq /tmp/ninja-linux.zip -d /usr/bin +rm -f /tmp/ninja-linux.zip +#install protobuf +mkdir -p /tmp/src +mkdir -p /opt/cmake +aria2c -q -d /tmp/src https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2-Linux-x86_64.tar.gz +tar -xf /tmp/src/cmake-3.13.2-Linux-x86_64.tar.gz --strip 1 -C /opt/cmake +aria2c -q -d /tmp/src https://github.com/protocolbuffers/protobuf/archive/v3.6.1.tar.gz +tar -xf /tmp/src/protobuf-3.6.1.tar.gz -C /tmp/src +cd /tmp/src/protobuf-3.6.1 +if [ -f /etc/redhat-release ] ; then + PB_LIBDIR=lib64 +else + PB_LIBDIR=lib +fi +for build_type in 'Debug' 'Relwithdebinfo'; do + pushd . + mkdir build_$build_type + cd build_$build_type + /opt/cmake/bin/cmake -G Ninja ../cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=$PB_LIBDIR -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=$build_type + ninja + ninja install + popd +done +export ONNX_ML=1 + +#The last onnx version will be kept + +aria2c -q -d /tmp/src http://bitbucket.org/eigen/eigen/get/3.3.7.tar.bz2 +tar -jxf /tmp/src/eigen-eigen-323c052e1731.tar.bz2 -C /usr/include +mv /usr/include/eigen-eigen-323c052e1731 /usr/include/eigen3 + +rm -rf /tmp/src +rm -rf /usr/include/google +rm -rf /usr/lib/libproto* + + + diff --git a/tools/ci_build/github/linux/docker/scripts/install_ubuntu_for_android.sh b/tools/ci_build/github/linux/docker/scripts/install_ubuntu_for_android.sh new file mode 100755 index 0000000000..95499794d3 --- /dev/null +++ b/tools/ci_build/github/linux/docker/scripts/install_ubuntu_for_android.sh @@ -0,0 +1,45 @@ +#!/bin/bash +set -e +while getopts p: parameter_Option +do case "${parameter_Option}" +in +p) PYTHON_VER=${OPTARG};; +esac +done + +PYTHON_VER=${PYTHON_VER:=3.5} +DEBIAN_FRONTEND=noninteractive + +apt-get update && apt-get install -y software-properties-common +add-apt-repository ppa:deadsnakes/ppa +apt-get update && apt-get install -y --no-install-recommends \ + autotools-dev \ + build-essential \ + git apt-transport-https \ + ca-certificates \ + pkg-config \ + wget \ + zlib1g \ + zlib1g-dev \ + libssl-dev \ + curl \ + autoconf \ + sudo \ + gfortran \ + language-pack-en \ + libopenblas-dev \ + liblttng-ust0 \ + libcurl3 \ + libssl1.0.0 \ + libkrb5-3 \ + libicu55 \ + aria2 \ + bzip2 \ + unzip \ + zip \ + rsync libunwind8 libpng16-dev + +locale-gen en_US.UTF-8 +update-locale LANG=en_US.UTF-8 + +rm -rf /var/lib/apt/lists/* diff --git a/tools/ci_build/github/linux/run_build.sh b/tools/ci_build/github/linux/run_build.sh index c948d90d33..a57cfb58e7 100755 --- a/tools/ci_build/github/linux/run_build.sh +++ b/tools/ci_build/github/linux/run_build.sh @@ -5,37 +5,45 @@ id SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}" )" -while getopts c:d:x: parameter_Option +while getopts d:x:o: parameter_Option do case "${parameter_Option}" in d) BUILD_DEVICE=${OPTARG};; x) BUILD_EXTR_PAR=${OPTARG};; +o) BUILD_OS=${OPTARG};; esac done -if [ $BUILD_DEVICE = "gpu" ]; then - _CUDNN_VERSION=$(echo $CUDNN_VERSION | cut -d. -f1-2) - python3 $SCRIPT_DIR/../../build.py --build_dir /build \ - --config Debug Release \ - --skip_submodule_sync --enable_onnx_tests \ - --parallel --build_shared_lib \ - --use_cuda --use_openmp \ - --cuda_home /usr/local/cuda \ - --cudnn_home /usr/local/cudnn-$_CUDNN_VERSION/cuda --build_shared_lib $BUILD_EXTR_PAR -elif [ $BUILD_DEVICE = "tensorrt" ]; then - _CUDNN_VERSION=$(echo $CUDNN_VERSION | cut -d. -f1-2) - python3 $SCRIPT_DIR/../../build.py --build_dir /build \ - --config Release \ - --enable_onnx_tests \ - --parallel --build_shared_lib \ - --use_tensorrt --tensorrt_home /workspace/tensorrt \ - --use_openmp \ - --cuda_home /usr/local/cuda \ - --cudnn_home /usr/local/cuda --build_shared_lib $BUILD_EXTR_PAR +if [ $BUILD_OS = "android" ]; then + pushd /onnxruntime_src + mkdir build-android && cd build-android + /opt/cmake/bin/cmake -DCMAKE_TOOLCHAIN_FILE=/android-ndk/build/cmake/android.toolchain.cmake -DANDROID_CPP_FEATURES=exceptions -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -Donnxruntime_CROSS_COMPILING=ON -Donnxruntime_BUILD_x86=OFF -DONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc ../cmake + /opt/cmake/bin/cmake --build . -- -j$(nproc) else - python3 $SCRIPT_DIR/../../build.py --build_dir /build \ - --config Debug Release --build_shared_lib \ - --skip_submodule_sync --enable_onnx_tests \ - --build_wheel \ - --parallel --use_openmp --build_shared_lib $BUILD_EXTR_PAR + if [ $BUILD_DEVICE = "gpu" ]; then + _CUDNN_VERSION=$(echo $CUDNN_VERSION | cut -d. -f1-2) + python3 $SCRIPT_DIR/../../build.py --build_dir /build \ + --config Debug Release \ + --skip_submodule_sync --enable_onnx_tests \ + --parallel --build_shared_lib \ + --use_cuda --use_openmp \ + --cuda_home /usr/local/cuda \ + --cudnn_home /usr/local/cudnn-$_CUDNN_VERSION/cuda --build_shared_lib $BUILD_EXTR_PAR + elif [ $BUILD_DEVICE = "tensorrt" ]; then + _CUDNN_VERSION=$(echo $CUDNN_VERSION | cut -d. -f1-2) + python3 $SCRIPT_DIR/../../build.py --build_dir /build \ + --config Release \ + --enable_onnx_tests \ + --parallel --build_shared_lib \ + --use_tensorrt --tensorrt_home /workspace/tensorrt \ + --use_openmp \ + --cuda_home /usr/local/cuda \ + --cudnn_home /usr/local/cuda --build_shared_lib $BUILD_EXTR_PAR + else + python3 $SCRIPT_DIR/../../build.py --build_dir /build \ + --config Debug Release --build_shared_lib \ + --skip_submodule_sync --enable_onnx_tests \ + --build_wheel \ + --parallel --use_openmp --build_shared_lib $BUILD_EXTR_PAR + fi fi diff --git a/tools/ci_build/github/linux/run_dockerbuild.sh b/tools/ci_build/github/linux/run_dockerbuild.sh index 1830858091..d600f85963 100755 --- a/tools/ci_build/github/linux/run_dockerbuild.sh +++ b/tools/ci_build/github/linux/run_dockerbuild.sh @@ -8,7 +8,7 @@ CUDA_VER=cuda10.0-cudnn7.3 while getopts c:o:d:r:p:x:a: parameter_Option do case "${parameter_Option}" in -#ubuntu16.04 +#android, ubuntu16.04 o) BUILD_OS=${OPTARG};; #cpu, gpu, tensorrt d) BUILD_DEVICE=${OPTARG};; @@ -19,6 +19,7 @@ p) PYTHON_VER=${OPTARG};; x) BUILD_EXTR_PAR=${OPTARG};; # "cuda10.0-cudnn7.3, cuda9.1-cudnn7.1" c) CUDA_VER=${OPTARG};; +# x86 or other, only for ubuntu16.04 os a) BUILD_ARCH=${OPTARG};; esac done @@ -28,23 +29,29 @@ EXIT_CODE=1 echo "bo=$BUILD_OS bd=$BUILD_DEVICE bdir=$BUILD_DIR pv=$PYTHON_VER bex=$BUILD_EXTR_PAR" cd $SCRIPT_DIR/docker -if [ $BUILD_DEVICE = "gpu" ]; then - IMAGE="ubuntu16.04-$CUDA_VER" - DOCKER_FILE=Dockerfile.ubuntu_gpu - if [ $CUDA_VER = "cuda9.1-cudnn7.1" ]; then - DOCKER_FILE=Dockerfile.ubuntu_gpu_cuda9 - fi - docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg PYTHON_VERSION=${PYTHON_VER} -f $DOCKER_FILE . -elif [ $BUILD_DEVICE = "tensorrt" ]; then - IMAGE="ubuntu16.04-cuda10.0-cudnn7.4-tensorrt5.0" - DOCKER_FILE=Dockerfile.ubuntu_tensorrt +if [ $BUILD_OS = "android" ]; then + IMAGE="android" + DOCKER_FILE=Dockerfile.ubuntu_for_android docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg PYTHON_VERSION=${PYTHON_VER} -f $DOCKER_FILE . else - IMAGE="ubuntu16.04" - if [ $BUILD_ARCH = "x86" ]; then - docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg OS_VERSION=16.04 --build-arg PYTHON_VERSION=${PYTHON_VER} -f Dockerfile.ubuntu_x86 . + if [ $BUILD_DEVICE = "gpu" ]; then + IMAGE="ubuntu16.04-$CUDA_VER" + DOCKER_FILE=Dockerfile.ubuntu_gpu + if [ $CUDA_VER = "cuda9.1-cudnn7.1" ]; then + DOCKER_FILE=Dockerfile.ubuntu_gpu_cuda9 + fi + docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg PYTHON_VERSION=${PYTHON_VER} -f $DOCKER_FILE . + elif [ $BUILD_DEVICE = "tensorrt" ]; then + IMAGE="ubuntu16.04-cuda10.0-cudnn7.4-tensorrt5.0" + DOCKER_FILE=Dockerfile.ubuntu_tensorrt + docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg PYTHON_VERSION=${PYTHON_VER} -f $DOCKER_FILE . else - docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg OS_VERSION=16.04 --build-arg PYTHON_VERSION=${PYTHON_VER} -f Dockerfile.ubuntu . + IMAGE="ubuntu16.04" + if [ $BUILD_ARCH = "x86" ]; then + docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg OS_VERSION=16.04 --build-arg PYTHON_VERSION=${PYTHON_VER} -f Dockerfile.ubuntu_x86 . + else + docker build -t "onnxruntime-$IMAGE" --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg OS_VERSION=16.04 --build-arg PYTHON_VERSION=${PYTHON_VER} -f Dockerfile.ubuntu . + fi fi fi @@ -67,7 +74,7 @@ if [ $BUILD_DEVICE = "cpu" ]; then -e NIGHTLY_BUILD \ "onnxruntime-$IMAGE" \ /bin/bash /onnxruntime_src/tools/ci_build/github/linux/run_build.sh \ - -d $BUILD_DEVICE -x "$BUILD_EXTR_PAR" & + -d $BUILD_DEVICE -x "$BUILD_EXTR_PAR" -o $BUILD_OS & else docker rm -f "onnxruntime-$BUILD_DEVICE" || true nvidia-docker run --rm -h $HOSTNAME \ @@ -80,7 +87,7 @@ else -e NIGHTLY_BUILD \ "onnxruntime-$IMAGE" \ /bin/bash /onnxruntime_src/tools/ci_build/github/linux/run_build.sh \ - -d $BUILD_DEVICE -x "$BUILD_EXTR_PAR" & + -d $BUILD_DEVICE -x "$BUILD_EXTR_PAR" -o $BUILD_OS & fi wait -n