diff --git a/CMakeLists.txt b/CMakeLists.txt index e57c00b69e92..962c73834222 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,7 +340,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 a1f752bbf64a..d88b3805fb29 100755 --- a/ci/docker/Dockerfile.build.arm64 +++ b/ci/docker/Dockerfile.build.arm64 @@ -37,13 +37,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 c073992406fb..93be54025f42 100755 --- a/ci/docker/Dockerfile.build.armv6 +++ b/ci/docker/Dockerfile.build.armv6 @@ -36,11 +36,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 627486c0537d..17df945893f7 100755 --- a/ci/docker/Dockerfile.build.armv7 +++ b/ci/docker/Dockerfile.build.armv7 @@ -16,7 +16,7 @@ # 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 ubuntu:16.04 as ccachebuilder @@ -30,13 +30,21 @@ FROM dockcross/linux-armv7 # extract ccache binary into latest context COPY --from=ccachebuilder /usr/local/bin/ccache /usr/local/bin/ccache -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 8a8bb97aa156..4867bb5421de 100755 --- a/ci/docker/Dockerfile.build.jetson +++ b/ci/docker/Dockerfile.build.jetson @@ -41,13 +41,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} ENV OpenBLAS_HOME=${CROSS_ROOT} ENV OpenBLAS_DIR=${CROSS_ROOT} diff --git a/ci/docker/install/arm_openblas.sh b/ci/docker/install/arm_openblas.sh new file mode 100755 index 000000000000..fa2e5cae9cba --- /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 000000000000..becb012bd180 --- /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 36e238797059..227805d2acb7 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -63,34 +63,52 @@ build_ccache_wrappers() { export CXX=`pwd`/cxx } -# Build commands: Every platform in docker/Dockerfile.build. should have a corresponding -# function here with the same suffix: +build_wheel() { -build_jetson() { set -ex pushd . - build_ccache_wrappers + PYTHON_DIR=${1:-/work/mxnet/python} + BUILD_DIR=${2:-/work/build} - cp -f make/crosscompile.jetson.mk ./config.mk + # build - make -j$(nproc) + export MXNET_LIBRARY_PATH=${BUILD_DIR}/libmxnet.so - export MXNET_LIBRARY_PATH=`pwd`/libmxnet.so - cd /work/mxnet/python + 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. should have a corresponding +# function here with the same suffix: + +build_jetson() { + set -ex + pushd . + + build_ccache_wrappers + + cp -f make/crosscompile.jetson.mk ./config.mk + make -j$(nproc) + + build_wheel /work/mxnet/python /work/mxnet/lib + popd } @@ -107,7 +125,7 @@ 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_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DUSE_CUDA=OFF \ @@ -120,33 +138,43 @@ 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 + + # 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 \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DUSE_CUDA=OFF\ - -DUSE_OPENCV=OFF\ - -DUSE_OPENMP=OFF\ - -DUSE_SIGNAL_HANDLER=ON\ - -DCMAKE_BUILD_TYPE=RelWithDebInfo\ - -DUSE_MKL_IF_AVAILABLE=OFF\ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -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 }