anirudh2290 closed pull request #11054: [MXNET-244] Fixed armv7 wheel (1.2.0 release) URL: https://github.com/apache/incubator-mxnet/pull/11054
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/CMakeLists.txt b/CMakeLists.txt index 05d8021c367..7f18e372e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -353,7 +353,11 @@ if(USE_OPENMP) find_package(OpenMP REQUIRED) # This should build on Windows, but there's some problem and I don't have a Windows box, so # could a Windows user please fix? - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp/CMakeLists.txt AND SYSTEM_ARCHITECTURE STREQUAL "x86_64" AND NOT MSVC) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp/CMakeLists.txt + AND SYSTEM_ARCHITECTURE STREQUAL "x86_64" + AND NOT MSVC + AND NOT CMAKE_CROSSCOMPILING) + # Intel/llvm OpenMP: https://github.com/llvm-mirror/openmp set(OPENMP_STANDALONE_BUILD TRUE) set(LIBOMP_ENABLE_SHARED TRUE) diff --git a/ci/docker/Dockerfile.build.arm64 b/ci/docker/Dockerfile.build.arm64 index ec949600f73..7a2e1723360 100755 --- a/ci/docker/Dockerfile.build.arm64 +++ b/ci/docker/Dockerfile.build.arm64 @@ -27,13 +27,16 @@ ENV FC /usr/bin/${CROSS_TRIPLE}-gfortran ENV HOSTCC gcc ENV TARGET ARMV8 -WORKDIR /work +WORKDIR /work/deps -# Build OpenBLAS -RUN git clone --recursive -b v0.2.20 https://github.com/xianyi/OpenBLAS.git && \ - cd OpenBLAS && \ - make -j$(nproc) && \ - PREFIX=${CROSS_ROOT} make install +COPY install/ubuntu_arm.sh /work/ +RUN /work/ubuntu_arm.sh + +COPY install/arm_openblas.sh /work/ +RUN /work/arm_openblas.sh + +ENV OpenBLAS_HOME=${CROSS_ROOT} +ENV OpenBLAS_DIR=${CROSS_ROOT} COPY runtime_functions.sh /work/ WORKDIR /work/mxnet diff --git a/ci/docker/Dockerfile.build.armv6 b/ci/docker/Dockerfile.build.armv6 index 20739dabe2e..f9ec0f56092 100755 --- a/ci/docker/Dockerfile.build.armv6 +++ b/ci/docker/Dockerfile.build.armv6 @@ -27,11 +27,14 @@ ENV TARGET ARMV6 WORKDIR /work/deps -# Build OpenBLAS -RUN git clone --recursive -b v0.2.20 https://github.com/xianyi/OpenBLAS.git && \ - cd OpenBLAS && \ - make -j$(nproc) && \ - make PREFIX=$CROSS_ROOT install +COPY install/ubuntu_arm.sh /work/ +RUN /work/ubuntu_arm.sh + +COPY install/arm_openblas.sh /work/ +RUN /work/arm_openblas.sh + +ENV OpenBLAS_HOME=${CROSS_ROOT} +ENV OpenBLAS_DIR=${CROSS_ROOT} COPY runtime_functions.sh /work/ WORKDIR /work/mxnet diff --git a/ci/docker/Dockerfile.build.armv7 b/ci/docker/Dockerfile.build.armv7 index c2493063518..04002dcb292 100755 --- a/ci/docker/Dockerfile.build.armv7 +++ b/ci/docker/Dockerfile.build.armv7 @@ -16,17 +16,25 @@ # specific language governing permissions and limitations # under the License. # -# Dockerfile to build MXNet for Android ARMv7 +# Dockerfile to build MXNet for ARMv7 (Android & RPi) FROM dockcross/linux-armv7 -ENV ARCH armv71 -ENV CC /usr/bin/arm-linux-gnueabihf-gcc -ENV CXX /usr/bin/arm-linux-gnueabihf-g++ +ENV ARCH armv7l +ENV HOSTCC gcc +ENV TARGET ARMV7 +ENV FC /usr/bin/${CROSS_TRIPLE}-gfortran -RUN apt-get update && \ - apt-get install -y libopenblas-dev:armhf && \ - rm -rf /var/lib/apt/lists/* +WORKDIR /work/deps + +COPY install/ubuntu_arm.sh /work/ +RUN /work/ubuntu_arm.sh + +COPY install/arm_openblas.sh /work/ +RUN /work/arm_openblas.sh + +ENV OpenBLAS_HOME=${CROSS_ROOT} +ENV OpenBLAS_DIR=${CROSS_ROOT} COPY runtime_functions.sh /work/ -WORKDIR /work/build +WORKDIR /work/mxnet diff --git a/ci/docker/Dockerfile.build.jetson b/ci/docker/Dockerfile.build.jetson index c358edb1fb0..5bbc5d4f4be 100755 --- a/ci/docker/Dockerfile.build.jetson +++ b/ci/docker/Dockerfile.build.jetson @@ -31,13 +31,16 @@ ENV FC /usr/bin/${CROSS_TRIPLE}-gfortran ENV HOSTCC gcc ENV TARGET ARMV8 -WORKDIR /work +WORKDIR /work/deps -# Build OpenBLAS -RUN git clone --recursive -b v0.2.20 https://github.com/xianyi/OpenBLAS.git && \ - cd OpenBLAS && \ - make -j$(nproc) && \ - PREFIX=${CROSS_ROOT} make install +COPY install/ubuntu_arm.sh /work/ +RUN /work/ubuntu_arm.sh + +COPY install/arm_openblas.sh /work/ +RUN /work/arm_openblas.sh + +ENV OpenBLAS_HOME=${CROSS_ROOT} +ENV OpenBLAS_DIR=${CROSS_ROOT} # Setup CUDA build env (including configuring and copying nvcc) COPY --from=cudabuilder /usr/local/cuda /usr/local/cuda diff --git a/ci/docker/install/arm_openblas.sh b/ci/docker/install/arm_openblas.sh new file mode 100755 index 00000000000..fa2e5cae9cb --- /dev/null +++ b/ci/docker/install/arm_openblas.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -ex + +git clone --recursive -b v0.2.20 https://github.com/xianyi/OpenBLAS.git + +cd OpenBLAS +make -j$(nproc) +PREFIX=${CROSS_ROOT} make install + +cd .. + +rm -rf OpenBLAS diff --git a/ci/docker/install/ubuntu_arm.sh b/ci/docker/install/ubuntu_arm.sh new file mode 100755 index 00000000000..becb012bd18 --- /dev/null +++ b/ci/docker/install/ubuntu_arm.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -ex + +apt update +apt install -y \ + unzip diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh index 44de137b6a8..7352bfd266f 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -31,31 +31,50 @@ clean_repo() { git submodule update --init --recursive } +build_wheel() { -# Build commands: Every platform in docker/Dockerfile.build.<platform> should have a corresponding -# function here with the same suffix: - -build_jetson() { set -ex pushd . - mv make/crosscompile.jetson.mk make/config.mk - make -j$(nproc) - export MXNET_LIBRARY_PATH=`pwd`/libmxnet.so - cd /work/mxnet/python + PYTHON_DIR=${1:-/work/mxnet/python} + BUILD_DIR=${2:-/work/build} + + # build + + export MXNET_LIBRARY_PATH=${BUILD_DIR}/libmxnet.so + + cd ${PYTHON_DIR} python setup.py bdist_wheel --universal + # repackage + # Fix pathing issues in the wheel. We need to move libmxnet.so from the data folder to the # mxnet folder, then repackage the wheel. WHEEL=`readlink -f dist/*.whl` TMPDIR=`mktemp -d` - unzip -d $TMPDIR $WHEEL - rm $WHEEL - cd $TMPDIR + unzip -d ${TMPDIR} ${WHEEL} + rm ${WHEEL} + cd ${TMPDIR} mv *.data/data/mxnet/libmxnet.so mxnet - zip -r $WHEEL . - cp $WHEEL /work/build - rm -rf $TMPDIR + zip -r ${WHEEL} . + cp ${WHEEL} ${BUILD_DIR} + rm -rf ${TMPDIR} + + popd +} + +# Build commands: Every platform in docker/Dockerfile.build.<platform> should have a corresponding +# function here with the same suffix: + +build_jetson() { + set -ex + pushd . + + cp make/crosscompile.jetson.mk ./config.mk + make -j$(nproc) + + build_wheel /work/mxnet/python /work/mxnet/lib + popd } @@ -72,7 +91,8 @@ build_armv6() { # We do not need OpenMP, since most armv6 systems have only 1 core cmake \ - -DCMAKE_TOOLCHAIN_FILE=$CROSS_ROOT/Toolchain.cmake \ + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \ + -DCMAKE_CROSSCOMPILING=ON \ -DUSE_CUDA=OFF \ -DUSE_OPENCV=OFF \ -DUSE_OPENMP=OFF \ @@ -83,31 +103,41 @@ build_armv6() { -DBUILD_CPP_EXAMPLES=OFF \ -Dmxnet_LINKER_LIBS=-lgfortran \ -G Ninja /work/mxnet + ninja - export MXNET_LIBRARY_PATH=`pwd`/libmxnet.so - cd /work/mxnet/python - python setup.py bdist_wheel --universal - cp dist/*.whl /work/build + build_wheel + popd } build_armv7() { set -ex pushd . + cd /work/build - cmake\ - -DUSE_CUDA=OFF\ - -DUSE_OPENCV=OFF\ - -DUSE_OPENMP=OFF\ - -DUSE_SIGNAL_HANDLER=ON\ - -DCMAKE_BUILD_TYPE=RelWithDebInfo\ - -DUSE_MKL_IF_AVAILABLE=OFF\ + + # Lapack functionality will be included and statically linked to openblas. + # But USE_LAPACK needs to be set to OFF, otherwise the main CMakeLists.txt + # file tries to add -llapack. Lapack functionality though, requires -lgfortran + # to be linked additionally. + + cmake \ + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \ + -DCMAKE_CROSSCOMPILING=ON \ + -DUSE_CUDA=OFF \ + -DUSE_OPENCV=OFF \ + -DUSE_OPENMP=ON \ + -DUSE_SIGNAL_HANDLER=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DUSE_MKL_IF_AVAILABLE=OFF \ + -DUSE_LAPACK=OFF \ + -DBUILD_CPP_EXAMPLES=OFF \ + -Dmxnet_LINKER_LIBS=-lgfortran \ -G Ninja /work/mxnet + ninja - export MXNET_LIBRARY_PATH=`pwd`/libmxnet.so - cd /work/mxnet/python - python setup.py bdist_wheel --universal - cp dist/*.whl /work/build + build_wheel + popd } diff --git a/cmake/Modules/FindOpenBLAS.cmake b/cmake/Modules/FindOpenBLAS.cmake index a3a79caae46..4c0289b866a 100644 --- a/cmake/Modules/FindOpenBLAS.cmake +++ b/cmake/Modules/FindOpenBLAS.cmake @@ -52,8 +52,13 @@ SET(Open_BLAS_LIB_SEARCH_PATHS ${OpenBLAS_HOME}/lib ) +# link statically for cross compilations +if(CMAKE_CROSSCOMPILING) + set(OpenBLAS_LIB_NAMES libopenblas.a) +endif() + FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS}) -FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS}) +FIND_LIBRARY(OpenBLAS_LIB NAMES ${OpenBLAS_LIB_NAMES} openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS}) IF(NOT OpenBLAS_LIB) FIND_FILE(OpenBLAS_LIB NAMES libopenblas.dll.a PATHS ${Open_BLAS_LIB_SEARCH_PATHS}) ENDIF() ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services