diff --git a/CMakeLists.txt b/CMakeLists.txt index a1aef6635119..eff4acc6ef22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,14 @@ else() execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE SYSTEM_ARCHITECTURE) endif() +if(CMAKE_BUILD_TYPE STREQUAL "Distribution" AND UNIX AND NOT APPLE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) + set(CMAKE_INSTALL_RPATH $\{ORIGIN\}) + # Enforce DT_PATH instead of DT_RUNPATH + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--disable-new-dtags") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags") +endif() + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules;${CMAKE_MODULE_PATH}") SET(EXTRA_OPERATORS "" CACHE PATH "EXTRA OPERATORS PATH") @@ -435,11 +443,11 @@ if(USE_OPENMP) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/openmp) endfunction() - 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 CMAKE_BUILD_TYPE STREQUAL "Distribution" AND NOT MSVC AND NOT CMAKE_CROSSCOMPILING) load_omp() @@ -452,6 +460,7 @@ if(USE_OPENMP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") add_definitions(-DMXNET_USE_OPENMP=1) else() + find_package(OpenMP REQUIRED) if(OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") @@ -469,7 +478,9 @@ endif() if(USE_LAPACK) message("USE_LAPACK is ON") add_definitions(-DMXNET_USE_LAPACK=1) - if (NOT MSVC) + # In the CMAKE_BUILD_TYPE="Distribution" case, we link against Blas libraries + # that already provide lapack symbols. Thus -llapack would be wrong. + if (NOT MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL "Distribution") list(APPEND mxnet_LINKER_LIBS lapack) endif() endif() diff --git a/ci/docker/install/ubuntu_publish.sh b/ci/docker/install/ubuntu_publish.sh index 6bc5a8ceb331..306a1a3143fd 100755 --- a/ci/docker/install/ubuntu_publish.sh +++ b/ci/docker/install/ubuntu_publish.sh @@ -27,6 +27,7 @@ add-apt-repository ppa:openjdk-r/ppa -y # Java lib apt-get update apt-get install -y git \ cmake3 \ + ninja-build \ libcurl4-openssl-dev \ unzip \ gcc-4.8 \ @@ -57,6 +58,18 @@ mv apache-maven-3.3.9/ /usr/local/maven/ update-alternatives --install /usr/bin/mvn mvn /usr/local/maven/apache-maven-3.3.9/bin/mvn 1 update-ca-certificates -f +# patchelf available starting Ubuntu 16.04; compile from source for Ubuntu 14.04 +mkdir /usr/local/patchelf +cd /usr/local/patchelf +curl -L -o patchelf-0.10.tar.gz https://github.com/NixOS/patchelf/archive/0.10.tar.gz +tar xzf patchelf-0.10.tar.gz +cd /usr/local/patchelf/patchelf-0.10 +./bootstrap.sh +./configure +make +sudo make install +cd / + apt-get install -y python python-pip python3 python3-pip # the version of the pip shipped with ubuntu may be too lower, install a recent version here @@ -64,4 +77,12 @@ apt-get install -y python python-pip python3 python3-pip python3 -m pip install --upgrade 'pip<19' # Restrict numpy version to <1.18 due to use of Python 3.4 on Ubuntu 14.04 -python3 -m pip install --upgrade --ignore-installed nose cpplint==1.3.0 pylint==2.3.1 'numpy>1.16.0,<1.18' nose-timer 'requests<2.19.0,>=2.18.4' h5py==2.8.0rc1 scipy==1.0.1 boto3 \ No newline at end of file +python3 -m pip install --upgrade --ignore-installed nose cpplint==1.3.0 pylint==2.3.1 'numpy>1.16.0,<1.18' nose-timer 'requests<2.19.0,>=2.18.4' h5py==2.8.0rc1 scipy==1.0.1 boto3 + +# CMake 3.13.2+ is required +mkdir /opt/cmake && cd /opt/cmake +wget -nv https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.sh +sh cmake-3.13.5-Linux-x86_64.sh --prefix=/opt/cmake --skip-license +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake +rm cmake-3.13.5-Linux-x86_64.sh +cmake --version diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh index 3baa2cfb9acc..e0be19e33214 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -2005,6 +2005,24 @@ build_static_python_cu101mkl() { popd } +build_static_python_cpu_cmake() { + set -ex + pushd . + export mxnet_variant=cpu + export CMAKE_STATICBUILD=1 + ./ci/publish/python/build.sh + popd +} + +build_static_python_cu101_cmake() { + set -ex + pushd . + export mxnet_variant=cu101 + export CMAKE_STATICBUILD=1 + ./ci/publish/python/build.sh + popd +} + publish_scala_build() { set -ex pushd . diff --git a/ci/jenkins/Jenkins_steps.groovy b/ci/jenkins/Jenkins_steps.groovy index 61fae5259faa..7a37826ed981 100644 --- a/ci/jenkins/Jenkins_steps.groovy +++ b/ci/jenkins/Jenkins_steps.groovy @@ -663,6 +663,19 @@ def test_static_python_cpu() { }] } +def test_static_python_cpu_cmake() { + return ['Static build CPU 14.04 Python with CMake' : { + node(NODE_LINUX_CPU) { + ws('workspace/ut-publish-python-cpu') { + timeout(time: max_time, unit: 'MINUTES') { + utils.init_git() + utils.docker_run("publish.ubuntu1404_cpu", 'build_static_python_cpu_cmake', false) + } + } + } + }] +} + def test_static_python_gpu() { return ['Static build GPU 14.04 Python' : { node(NODE_LINUX_GPU) { @@ -676,6 +689,19 @@ def test_static_python_gpu() { }] } +def test_static_python_gpu_cmake() { + return ['Static build GPU 14.04 Python' : { + node(NODE_LINUX_GPU) { + ws('workspace/ut-publish-python-gpu') { + timeout(time: max_time, unit: 'MINUTES') { + utils.init_git() + utils.docker_run("publish.ubuntu1404_gpu", 'build_static_python_cu101_cmake', true) + } + } + } + }] +} + def test_unix_python3_cpu() { return ['Python3: CPU': { node(NODE_LINUX_CPU) { diff --git a/ci/jenkins/Jenkinsfile_unix_cpu b/ci/jenkins/Jenkinsfile_unix_cpu index 0b6ad661a3eb..71917de58e82 100644 --- a/ci/jenkins/Jenkinsfile_unix_cpu +++ b/ci/jenkins/Jenkinsfile_unix_cpu @@ -62,6 +62,7 @@ core_logic: { custom_steps.test_unix_cpp_cpu(), custom_steps.test_static_scala_cpu(), custom_steps.test_static_python_cpu(), + custom_steps.test_static_python_cpu_cmake(), /* Disabled due to master build failure: * http://jenkins.mxnet-ci.amazon-ml.com/blue/organizations/jenkins/incubator-mxnet/detail/master/1221/pipeline/ * https://github.com/apache/incubator-mxnet/issues/11801 diff --git a/ci/jenkins/Jenkinsfile_unix_gpu b/ci/jenkins/Jenkinsfile_unix_gpu index 8c07ee89798a..f3ed638f21fa 100644 --- a/ci/jenkins/Jenkinsfile_unix_gpu +++ b/ci/jenkins/Jenkinsfile_unix_gpu @@ -61,6 +61,7 @@ core_logic: { custom_steps.test_unix_scala_gpu(), custom_steps.test_unix_distributed_kvstore_gpu(), custom_steps.test_static_python_gpu(), + custom_steps.test_static_python_gpu_cmake(), custom_steps.test_unix_python3_gpu_no_tvm_op(), custom_steps.test_unix_capi_cpp_package(), diff --git a/config/distribution/linux_cpu.cmake b/config/distribution/linux_cpu.cmake new file mode 100644 index 000000000000..cad348578454 --- /dev/null +++ b/config/distribution/linux_cpu.cmake @@ -0,0 +1,30 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA OFF CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") diff --git a/config/distribution/linux_cu100.cmake b/config/distribution/linux_cu100.cmake new file mode 100644 index 000000000000..d26b4d73eee7 --- /dev/null +++ b/config/distribution/linux_cu100.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-10.0/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0;7.5" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu101.cmake b/config/distribution/linux_cu101.cmake new file mode 100644 index 000000000000..aaf76cc10df1 --- /dev/null +++ b/config/distribution/linux_cu101.cmake @@ -0,0 +1,36 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-10.1/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0;7.5" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu102.cmake b/config/distribution/linux_cu102.cmake new file mode 100644 index 000000000000..6b575683e919 --- /dev/null +++ b/config/distribution/linux_cu102.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-10.2/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0;7.5" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu75.cmake b/config/distribution/linux_cu75.cmake new file mode 100644 index 000000000000..45ba2b9de5d7 --- /dev/null +++ b/config/distribution/linux_cu75.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-7.5/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;3.5;5.0;5.2" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu80.cmake b/config/distribution/linux_cu80.cmake new file mode 100644 index 000000000000..ce8e0083bcad --- /dev/null +++ b/config/distribution/linux_cu80.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-8.0/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;6.2" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu90.cmake b/config/distribution/linux_cu90.cmake new file mode 100644 index 000000000000..01097cb882e4 --- /dev/null +++ b/config/distribution/linux_cu90.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-9.0/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0;7.2" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu91.cmake b/config/distribution/linux_cu91.cmake new file mode 100644 index 000000000000..f6301fa9f720 --- /dev/null +++ b/config/distribution/linux_cu91.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-9.1/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0;7.2" CACHE STRING "Cuda architectures") diff --git a/config/distribution/linux_cu92.cmake b/config/distribution/linux_cu92.cmake new file mode 100644 index 000000000000..63ab9fce20d8 --- /dev/null +++ b/config/distribution/linux_cu92.cmake @@ -0,0 +1,34 @@ +# 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(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "Build type") +set(CFLAGS "-mno-avx" CACHE STRING "CFLAGS") +set(CXXFLAGS "-mno-avx" CACHE STRING "CXXFLAGS") + +set(USE_CUDA ON CACHE BOOL "Build with CUDA support") +set(USE_CUDNN ON CACHE BOOL "Build with CUDA support") +set(USE_OPENCV ON CACHE BOOL "Build with OpenCV support") +set(USE_OPENMP ON CACHE BOOL "Build with Openmp support") +set(USE_MKL_IF_AVAILABLE OFF CACHE BOOL "Use Intel MKL if found") +set(USE_MKLDNN ON CACHE BOOL "Build with MKL-DNN support") +set(USE_LAPACK ON CACHE BOOL "Build with lapack support") +set(USE_TVM_OP OFF CACHE BOOL "Enable use of TVM operator build system.") +set(USE_SSE ON CACHE BOOL "Build with x86 SSE instruction support") +set(USE_F16C OFF CACHE BOOL "Build with x86 F16C instruction support") + +set(CUDACXX "/usr/local/cuda-9.2/bin/nvcc" CACHE STRING "Cuda compiler") +set(MXNET_CUDA_ARCH "3.0;5.0;6.0;7.0;7.2" CACHE STRING "Cuda architectures") diff --git a/tools/dependencies/openblas.sh b/tools/dependencies/openblas.sh index 05a500da3147..cdc63b6a8355 100755 --- a/tools/dependencies/openblas.sh +++ b/tools/dependencies/openblas.sh @@ -20,7 +20,8 @@ # This script builds the static library of openblas that can be used as dependency of mxnet. set -ex OPENBLAS_VERSION=0.3.7 -if [[ ! -e $DEPS_PATH/lib/libopenblas.a ]]; then +if [[ ((! -e $DEPS_PATH/lib/libopenblas.a) && -z "$CMAKE_STATICBUILD") || + ((! -e $DEPS_PATH/lib/libopenblas.so) && -v CMAKE_STATICBUILD) ]]; then # download and build openblas >&2 echo "Building openblas..." @@ -32,13 +33,25 @@ if [[ ! -e $DEPS_PATH/lib/libopenblas.a ]]; then cd $DEPS_PATH/OpenBLAS-$OPENBLAS_VERSION # Adding NO_DYNAMIC=1 flag causes make install to fail - $MAKE DYNAMIC_ARCH=1 USE_OPENMP=1 + CXX="g++ -fPIC" CC="gcc -fPIC" $MAKE DYNAMIC_ARCH=1 USE_OPENMP=1 + + if [[ -v CMAKE_STATICBUILD ]]; then + # We link and redistribute libopenblas.so for cmake staticbuild + # cf https://gitlab.kitware.com/cmake/cmake/issues/16221#note_143330 + patchelf --set-rpath '$ORIGIN' --force-rpath libopenblas.so + fi + $MAKE PREFIX=$DEPS_PATH install - # Manually removing .so to avoid linking against it - rm $DEPS_PATH/lib/libopenblasp-r${OPENBLAS_VERSION}.so + + if [[ -z "$CMAKE_STATICBUILD" ]]; then + # Manually removing .so to avoid linking against it + rm $DEPS_PATH/lib/libopenblasp-r${OPENBLAS_VERSION}.so + fi popd - ln -s libopenblas.a $DEPS_PATH/lib/libcblas.a - ln -s libopenblas.a $DEPS_PATH/lib/liblapack.a + if [[ -z "$CMAKE_STATICBUILD" ]]; then + ln -s libopenblas.a $DEPS_PATH/lib/libcblas.a + ln -s libopenblas.a $DEPS_PATH/lib/liblapack.a + fi fi diff --git a/tools/dependencies/opencv.sh b/tools/dependencies/opencv.sh index 4b85f018b0d3..139b68c5bef0 100755 --- a/tools/dependencies/opencv.sh +++ b/tools/dependencies/opencv.sh @@ -46,7 +46,7 @@ if [[ ! -f $DEPS_PATH/lib/libopencv_core.a ]] || [[ ! -f $DEPS_PATH/lib/libopenc mkdir -p $DEPS_PATH/opencv-$OPENCV_VERSION/build pushd . cd $DEPS_PATH/opencv-$OPENCV_VERSION/build - cmake \ + CXX="g++ -fPIC" CC="gcc -fPIC" cmake \ -D OPENCV_ENABLE_NONFREE=OFF \ -D WITH_1394=OFF \ -D WITH_ARAVIS=OFF \ @@ -161,7 +161,7 @@ if [[ ! -f $DEPS_PATH/lib/libopencv_core.a ]] || [[ ! -f $DEPS_PATH/lib/libopenc -D BUILD_opencv_gpuoptflow=OFF \ -D BUILD_opencv_gpustereo=OFF \ -D BUILD_opencv_gpuwarping=OFF \ - -D BUILD_opencv_highgui=OFF \ + -D BUILD_opencv_highgui=ON \ -D BUILD_opencv_java=OFF \ -D BUILD_opencv_js=OFF \ -D BUILD_opencv_ml=OFF \ diff --git a/tools/pip/setup.py b/tools/pip/setup.py index 36934a80761b..a0b63cc866f9 100644 --- a/tools/pip/setup.py +++ b/tools/pip/setup.py @@ -154,10 +154,18 @@ def has_ext_modules(self): shutil.copytree(os.path.join(CURRENT_DIR, 'mxnet-build/3rdparty/mkldnn/build/install/include'), os.path.join(CURRENT_DIR, 'mxnet/include/mkldnn')) if platform.system() == 'Linux': - shutil.copy(os.path.join(os.path.dirname(LIB_PATH[0]), 'libgfortran.so.3'), os.path.join(CURRENT_DIR, 'mxnet')) - package_data['mxnet'].append('mxnet/libgfortran.so.3') - shutil.copy(os.path.join(os.path.dirname(LIB_PATH[0]), 'libquadmath.so.0'), os.path.join(CURRENT_DIR, 'mxnet')) + libdir, mxdir = os.path.dirname(LIB_PATH[0]), os.path.join(CURRENT_DIR, 'mxnet') + if os.path.exists(os.path.join(libdir, 'libgfortran.so.3')): + shutil.copy(os.path.join(libdir, 'libgfortran.so.3'), mxdir) + package_data['mxnet'].append('mxnet/libgfortran.so.4') + else: + shutil.copy(os.path.join(libdir, 'libgfortran.so.4'), mxdir) + package_data['mxnet'].append('mxnet/libgfortran.so.4') + shutil.copy(os.path.join(libdir, 'libquadmath.so.0'), mxdir) package_data['mxnet'].append('mxnet/libquadmath.so.0') + if os.path.exists(os.path.join(libdir, 'libopenblas.so.0')): + shutil.copy(os.path.join(libdir, 'libopenblas.so.0'), mxdir) + package_data['mxnet'].append('mxnet/libquadmath.so.0') # Copy licenses and notice for f in os.listdir('mxnet/licenses'): diff --git a/tools/staticbuild/README.md b/tools/staticbuild/README.md index b48043b1ef87..201bf76276f5 100644 --- a/tools/staticbuild/README.md +++ b/tools/staticbuild/README.md @@ -20,16 +20,31 @@ This folder contains the core script used to build the static library. This README provides information on how to use the scripts in this folder. Please be aware, all of the scripts are designed to be run under the root folder. ## `build.sh` -This script is a wrapper around `build_lib.sh. It simplifies the things by automatically identifing the system version, number of cores, and all environment variable settings. Here are examples you can run with this script: +This script is a wrapper around `build_lib.sh. It simplifies the build by +automatically identifing the system version, number of cores, and all +environment variable settings. Here are examples you can run with this script: ``` -tools/staticbuild/build.sh cu92 +tools/staticbuild/build.sh cu102 ``` -This would build the mxnet package based on CUDA9.2. + +This would build the mxnet package based on CUDA 10.2. + +``` +tools/staticbuild/build.sh cpu +``` + +This would build the mxnet package based on MKLDNN. + +To use CMake to build the `libmxnet.so` instead of the deprecated Makefile based +build logic, set the `CMAKE_STATICBUILD` environment variable. For example + ``` -tools/staticbuild/build.sh mkl +CMAKE_STATICBUILD=1 tools/staticbuild/build.sh cpu ``` -This would build the mxnet package based on MKLDNN and and pypi configuration settings. + +For the CMake build, you need to install `patchelf` first, for example via `apt +install patchelf` on Ubuntu systems. As the result, users would have a complete static dependencies in `/staticdeps` in the root folder as well as a static-linked `libmxnet.so` file lives in `lib`. You can build your language binding by using the `libmxnet.so`. diff --git a/tools/staticbuild/build.sh b/tools/staticbuild/build.sh index ad08e63483b8..f33ce9d711bc 100755 --- a/tools/staticbuild/build.sh +++ b/tools/staticbuild/build.sh @@ -48,8 +48,8 @@ else fi export MAKE="make $ADD_MAKE_FLAG" -export CC="gcc -fPIC" -export CXX="g++ -fPIC" +export CC="gcc -fPIC -mno-avx" +export CXX="g++ -fPIC -mno-avx" export FC="gfortran" export PKG_CONFIG_PATH=$DEPS_PATH/lib/pkgconfig:$DEPS_PATH/lib64/pkgconfig:$DEPS_PATH/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH export CPATH=$DEPS_PATH/include:$CPATH @@ -72,4 +72,8 @@ cp DISCLAIMER-WIP licenses/ # Build mxnet -source tools/staticbuild/build_lib.sh +if [[ -z "$CMAKE_STATICBUILD" ]]; then + source tools/staticbuild/build_lib.sh +else + source tools/staticbuild/build_lib_cmake.sh +fi diff --git a/tools/staticbuild/build_lib.sh b/tools/staticbuild/build_lib.sh index f4fbf399ce86..111c907db863 100755 --- a/tools/staticbuild/build_lib.sh +++ b/tools/staticbuild/build_lib.sh @@ -17,6 +17,8 @@ # specific language governing permissions and limitations # under the License. +set -eo pipefail + # This script builds the libraries of mxnet. make_config=make/staticbuild/${PLATFORM}_${VARIANT}.mk if [[ ! -f $make_config ]]; then @@ -41,7 +43,13 @@ fi $MAKE DEPS_PATH=$DEPS_PATH if [[ $PLATFORM == 'linux' ]]; then - cp -L /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so lib/libgfortran.so.3 + if [[ -f /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so ]]; then + cp -L /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so lib/libgfortran.so.3 + elif [[ -f /usr/lib/x86_64-linux-gnu/libgfortran.so.3 ]]; then + cp -L /usr/lib/x86_64-linux-gnu/libgfortran.so.3 lib/libgfortran.so.3 + else + cp -L /usr/lib/x86_64-linux-gnu/libgfortran.so.4 lib/libgfortran.so.4 + fi cp -L /usr/lib/x86_64-linux-gnu/libquadmath.so.0 lib/libquadmath.so.0 fi @@ -57,4 +65,6 @@ else >&2 echo "Not available" fi -ln -s staticdeps/ deps +if [[ ! -L deps ]]; then + ln -s staticdeps deps +fi diff --git a/tools/staticbuild/build_lib_cmake.sh b/tools/staticbuild/build_lib_cmake.sh new file mode 100755 index 000000000000..78718eab5e67 --- /dev/null +++ b/tools/staticbuild/build_lib_cmake.sh @@ -0,0 +1,66 @@ +#!/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 -eo pipefail + +# This script builds the libraries of mxnet. +cmake_config=${CURDIR}/config/distribution/${PLATFORM}_${VARIANT}.cmake +if [[ ! -f $cmake_config ]]; then + >&2 echo "Couldn't find cmake config $make_config for the current settings." + exit 1 +fi + +git submodule update --init --recursive || true + +# Build libmxnet.so +rm -rf build; mkdir build; cd build +cmake -GNinja -C $cmake_config -DCMAKE_PREFIX_PATH=${DEPS_PATH} -DCMAKE_FIND_ROOT_PATH=${DEPS_PATH} .. +ninja +cd - + +# Move to lib +rm -rf lib; mkdir lib; cp -L build/libmxnet.so lib/libmxnet.so + +if [[ $PLATFORM == 'linux' ]]; then + cp -L staticdeps/lib/libopenblas.so lib/libopenblas.so.0 + if [[ -f /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so ]]; then + cp -L /usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so lib/libgfortran.so.3 + elif [[ -f /usr/lib/x86_64-linux-gnu/libgfortran.so.3 ]]; then + cp -L /usr/lib/x86_64-linux-gnu/libgfortran.so.3 lib/libgfortran.so.3 + else + cp -L /usr/lib/x86_64-linux-gnu/libgfortran.so.4 lib/libgfortran.so.4 + fi + cp -L /usr/lib/x86_64-linux-gnu/libquadmath.so.0 lib/libquadmath.so.0 +fi + +# Print the linked objects on libmxnet.so +>&2 echo "Checking linked objects on libmxnet.so..." +if [[ ! -z $(command -v readelf) ]]; then + readelf -d lib/libmxnet.so + strip --strip-unneeded lib/libmxnet.so +elif [[ ! -z $(command -v otool) ]]; then + otool -L lib/libmxnet.so + strip -u -r -x lib/libmxnet.so +else + >&2 echo "Not available" +fi + +if [[ ! -L deps ]]; then + ln -s staticdeps deps +fi