From 89bc18eec00227e6d5853085d048f6603c657b79 Mon Sep 17 00:00:00 2001 From: zhouwei25 <52485244+zhouwei25@users.noreply.github.com> Date: Fri, 8 Nov 2019 10:57:57 +0800 Subject: [PATCH] move more third party library related logic to third_party.cmake (#20927) --- CMakeLists.txt | 1 + cmake/external/cares.cmake | 7 +--- cmake/external/cub.cmake | 16 ++++++-- cmake/external/dlpack.cmake | 14 +++++++ cmake/external/eigen.cmake | 14 +++++++ cmake/external/grpc.cmake | 6 +-- cmake/external/libmct.cmake | 12 ------ cmake/external/mkldnn.cmake | 7 +--- cmake/external/pslib.cmake | 14 +------ cmake/external/pslib_brpc.cmake | 14 +------ cmake/external/rocprim.cmake | 16 ++++++-- cmake/external/threadpool.cmake | 14 +++++++ cmake/external/xbyak.cmake | 8 +--- cmake/external/xxhash.cmake | 14 +++++++ cmake/third_party.cmake | 73 ++++++++++++++++++++++++--------- 15 files changed, 143 insertions(+), 87 deletions(-) mode change 100755 => 100644 cmake/third_party.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 215cba1925..0632ada400 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ OPTION(WITH_LIBXSMM "Compile with libxsmm" OFF) option(COVERALLS_UPLOAD "Package code coverage data to coveralls" OFF) option(WITH_PSLIB "Compile with pslib support" OFF) option(WITH_BOX_PS "Compile with box_ps support" OFF) +option(WITH_XBYAK "Compile with xbyak support" ON) option(WITH_CONTRIB "Compile the third-party contributation" OFF) option(REPLACE_ENFORCE_GLOG "Replace PADDLE_ENFORCE with glog/CHECK for better debug." OFF) option(WITH_GRPC "Use grpc as the default rpc framework" ${WITH_DISTRIBUTE}) diff --git a/cmake/external/cares.cmake b/cmake/external/cares.cmake index d37b22fa2d..52b634a075 100644 --- a/cmake/external/cares.cmake +++ b/cmake/external/cares.cmake @@ -11,16 +11,11 @@ # 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. -# -IF(NOT WITH_DISTRIBUTE) - return() -ENDIF() +# NOTE: c-ares is needed when linking with grpc. include (ExternalProject) -# NOTE: c-ares is needed when linking with grpc. - SET(CARES_SOURCES_DIR ${THIRD_PARTY_PATH}/cares) SET(CARES_INSTALL_DIR ${THIRD_PARTY_PATH}/install/cares) SET(CARES_INCLUDE_DIR "${CARES_INSTALL_DIR}/include/" CACHE PATH "cares include directory." FORCE) diff --git a/cmake/external/cub.cmake b/cmake/external/cub.cmake index 41ad820774..a4d63295d7 100644 --- a/cmake/external/cub.cmake +++ b/cmake/external/cub.cmake @@ -1,6 +1,16 @@ -if(NOT WITH_GPU) - return() -endif() +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed 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. include(ExternalProject) diff --git a/cmake/external/dlpack.cmake b/cmake/external/dlpack.cmake index 63dd16b28e..a7284a96ea 100644 --- a/cmake/external/dlpack.cmake +++ b/cmake/external/dlpack.cmake @@ -1,3 +1,17 @@ +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed 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. + include(ExternalProject) set(DLPACK_SOURCE_DIR ${THIRD_PARTY_PATH}/dlpack) diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake index bea65d2d27..c186f6d4f4 100644 --- a/cmake/external/eigen.cmake +++ b/cmake/external/eigen.cmake @@ -1,3 +1,17 @@ +# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed 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. + INCLUDE(ExternalProject) SET(EIGEN_SOURCE_DIR ${THIRD_PARTY_PATH}/eigen3) diff --git a/cmake/external/grpc.cmake b/cmake/external/grpc.cmake index a9a9de88d6..eb1bcdfce0 100644 --- a/cmake/external/grpc.cmake +++ b/cmake/external/grpc.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,10 +13,6 @@ # limitations under the License. # -IF(NOT WITH_DISTRIBUTE) - return() -ENDIF() - include (ExternalProject) SET(GRPC_SOURCES_DIR ${THIRD_PARTY_PATH}/grpc) diff --git a/cmake/external/libmct.cmake b/cmake/external/libmct.cmake index 717e021387..e81810e6c4 100644 --- a/cmake/external/libmct.cmake +++ b/cmake/external/libmct.cmake @@ -12,18 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -IF(NOT ${WITH_LIBMCT}) - return() -ENDIF(NOT ${WITH_LIBMCT}) - -IF(WIN32 OR APPLE) - MESSAGE(WARNING - "Windows or Mac is not supported with LIBMCT in Paddle yet." - "Force WITH_LIBMCT=OFF") - SET(WITH_LIBMCT OFF CACHE STRING "Disable LIBMCT package in Windows and MacOS" FORCE) - return() -ENDIF() - INCLUDE(ExternalProject) SET(LIBMCT_PROJECT "extern_libmct") diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake index 03d59889d7..acab897458 100644 --- a/cmake/external/mkldnn.cmake +++ b/cmake/external/mkldnn.cmake @@ -100,9 +100,6 @@ if(WIN32) SET(MKLDNN_SHARED_LIB ${MKLDNN_INSTALL_DIR}/bin/mkldnn.dll) else(WIN32) SET(MKLDNN_SHARED_LIB ${MKLDNN_INSTALL_DIR}/libmkldnn.so.0) - ADD_CUSTOM_COMMAND(OUTPUT ${MKLDNN_SHARED_LIB} - COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_LIB} ${MKLDNN_SHARED_LIB} - DEPENDS mkldnn shared_mkldnn) + ADD_CUSTOM_COMMAND(TARGET ${MKLDNN_PROJECT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_LIB} ${MKLDNN_SHARED_LIB}) endif(WIN32) -ADD_CUSTOM_TARGET(mkldnn_shared_lib ALL DEPENDS ${MKLDNN_SHARED_LIB}) -ADD_DEPENDENCIES(mkldnn_shared_lib ${MKLDNN_PROJECT} mkldnn) diff --git a/cmake/external/pslib.cmake b/cmake/external/pslib.cmake index 99a1c23be3..532255bc29 100644 --- a/cmake/external/pslib.cmake +++ b/cmake/external/pslib.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,18 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -IF(NOT ${WITH_PSLIB}) - return() -ENDIF(NOT ${WITH_PSLIB}) - -IF(WIN32 OR APPLE) - MESSAGE(WARNING - "Windows or Mac is not supported with PSLIB in Paddle yet." - "Force WITH_PSLIB=OFF") - SET(WITH_PSLIB OFF CACHE STRING "Disable PSLIB package in Windows and MacOS" FORCE) - return() -ENDIF() - INCLUDE(ExternalProject) SET(PSLIB_PROJECT "extern_pslib") diff --git a/cmake/external/pslib_brpc.cmake b/cmake/external/pslib_brpc.cmake index c1d63089bb..7b00474a65 100644 --- a/cmake/external/pslib_brpc.cmake +++ b/cmake/external/pslib_brpc.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,18 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -IF(NOT ${WITH_PSLIB_BRPC}) - return() -ENDIF(NOT ${WITH_PSLIB_BRPC}) - -IF(WIN32 OR APPLE) - MESSAGE(WARNING - "Windows or Mac is not supported with PSLIB_BRPC in Paddle yet." - "Force WITH_PSLIB_BRPC=OFF") - SET(WITH_PSLIB_BRPC OFF CACHE STRING "Disable PSLIB_BRPC package in Windows and MacOS" FORCE) - return() -ENDIF() - INCLUDE(ExternalProject) SET(PSLIB_BRPC_PROJECT "extern_pslib_brpc") diff --git a/cmake/external/rocprim.cmake b/cmake/external/rocprim.cmake index 914c064918..b7e13c529e 100644 --- a/cmake/external/rocprim.cmake +++ b/cmake/external/rocprim.cmake @@ -1,6 +1,16 @@ -if (NOT WITH_AMD_GPU) - return() -endif() +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed 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. # rocprim is "ROCm Parallel Primitives" for short. # It is a header-only library providing HIP and HC parallel primitives diff --git a/cmake/external/threadpool.cmake b/cmake/external/threadpool.cmake index 1f56bc7ab0..d87a818ba8 100644 --- a/cmake/external/threadpool.cmake +++ b/cmake/external/threadpool.cmake @@ -1,3 +1,17 @@ +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed 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. + INCLUDE(ExternalProject) SET(THREADPOOL_SOURCE_DIR ${THIRD_PARTY_PATH}/threadpool) diff --git a/cmake/external/xbyak.cmake b/cmake/external/xbyak.cmake index 1d61154c0d..245ecf8bb1 100644 --- a/cmake/external/xbyak.cmake +++ b/cmake/external/xbyak.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,12 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(WITH_XBYAK ON) -if(WIN32 OR APPLE) - SET(WITH_XBYAK OFF CACHE STRING "Disable XBYAK in Windows and MacOS" FORCE) - return() -endif() - include(ExternalProject) set(XBYAK_PROJECT extern_xbyak) diff --git a/cmake/external/xxhash.cmake b/cmake/external/xxhash.cmake index 511701c386..4b3f9726f2 100644 --- a/cmake/external/xxhash.cmake +++ b/cmake/external/xxhash.cmake @@ -1,3 +1,17 @@ +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed 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. + INCLUDE(ExternalProject) set(XXHASH_SOURCE_DIR ${THIRD_PARTY_PATH}/xxhash) diff --git a/cmake/third_party.cmake b/cmake/third_party.cmake old mode 100755 new mode 100644 index eb1fc7048b..a7c8661bba --- a/cmake/third_party.cmake +++ b/cmake/third_party.cmake @@ -29,6 +29,9 @@ if (APPLE) endif() if(WIN32 OR APPLE) + MESSAGE(STATUS "Disable XBYAK in Windows and MacOS") + SET(WITH_XBYAK OFF CACHE STRING "Disable XBYAK in Windows and MacOS" FORCE) + if(WITH_LIBXSMM) MESSAGE(WARNING "Windows, Mac are not supported with libxsmm in Paddle yet." @@ -49,6 +52,27 @@ if(WIN32 OR APPLE) "Force WITH_BOX_PS=OFF") SET(WITH_BOX_PS OFF CACHE STRING "Disable BOX_PS package in Windows and MacOS" FORCE) endif() + + if(WITH_PSLIB) + MESSAGE(WARNING + "Windows or Mac is not supported with PSLIB in Paddle yet." + "Force WITH_PSLIB=OFF") + SET(WITH_PSLIB OFF CACHE STRING "Disable PSLIB package in Windows and MacOS" FORCE) + endif() + + if(WITH_LIBMCT) + MESSAGE(WARNING + "Windows or Mac is not supported with LIBMCT in Paddle yet." + "Force WITH_LIBMCT=OFF") + SET(WITH_LIBMCT OFF CACHE STRING "Disable LIBMCT package in Windows and MacOS" FORCE) + endif() + + if(WITH_PSLIB_BRPC) + MESSAGE(WARNING + "Windows or Mac is not supported with PSLIB_BRPC in Paddle yet." + "Force WITH_PSLIB_BRPC=OFF") + SET(WITH_PSLIB_BRPC OFF CACHE STRING "Disable PSLIB_BRPC package in Windows and MacOS" FORCE) + endif() endif() set(WITH_MKLML ${WITH_MKL}) @@ -75,18 +99,19 @@ include(external/threadpool)# download threadpool include(external/dlpack) # download dlpack include(external/xxhash) # download, build, install xxhash include(external/warpctc) # download, build, install warpctc -include(external/rocprim) # download, build, install rocprim -include(external/xbyak) # download, build, install xbyak -set(third_party_deps eigen3 gflags glog boost xxhash zlib dlpack warpctc simple_threadpool) +set(third_party_deps) +list(APPEND third_party_deps extern_eigen3 extern_gflags extern_glog extern_boost extern_xxhash) +list(APPEND third_party_deps extern_zlib extern_dlpack extern_warpctc extern_threadpool) if(WITH_AMD_GPU) - list(APPEND third_party_deps rocprim) + include(external/rocprim) # download, build, install rocprim + list(APPEND third_party_deps extern_rocprim) endif() if(WITH_MKLML) include(external/mklml) # download, install mklml package - list(APPEND third_party_deps mklml) + list(APPEND third_party_deps extern_mklml) endif() include(external/openblas) # find first, then download, build, install openblas if(NOT CBLAS_FOUND) @@ -95,7 +120,7 @@ endif() if(WITH_MKLDNN) include(external/mkldnn) # download, build, install mkldnn - list(APPEND third_party_deps mkldnn_shared_lib) + list(APPEND third_party_deps extern_mkldnn) endif() include(external/protobuf) # find first, then download, build, install protobuf @@ -106,7 +131,7 @@ endif() if(WITH_PYTHON) include(external/python) # find python and python_module include(external/pybind11) # download pybind11 - list(APPEND third_party_deps pybind) + list(APPEND third_party_deps extern_pybind) endif() IF(WITH_TESTING OR (WITH_DISTRIBUTE AND NOT WITH_GRPC)) @@ -116,34 +141,41 @@ ENDIF() if(WITH_GPU) include(external/cub) # download cub - list(APPEND third_party_deps cub) + list(APPEND third_party_deps extern_cub) endif(WITH_GPU) if(WITH_PSLIB) - include(external/libmct) - include(external/pslib) - include(external/pslib_brpc) + include(external/pslib) # download, build, install pslib + list(APPEND third_party_deps extern_pslib) + if(WITH_LIBMCT) + include(external/libmct) # download, build, install libmct + list(APPEND third_party_deps extern_libxsmm) + endif() + if(WITH_PSLIB_BRPC) + include(external/pslib_brpc) # download, build, install pslib_brpc + list(APPEND third_party_deps extern_pslib_brpc) + endif() endif(WITH_PSLIB) if(WITH_BOX_PS) include(external/box_ps) - list(APPEND third_party_deps box_ps) + list(APPEND third_party_deps extern_box_ps) endif(WITH_BOX_PS) if(WITH_DISTRIBUTE) - list(APPEND third_party_deps cares) + list(APPEND third_party_deps extern_cares) if(WITH_GRPC) - list(APPEND third_party_deps grpc++_unsecure) + list(APPEND third_party_deps extern_grpc) else() - list(APPEND third_party_deps leveldb) - list(APPEND third_party_deps brpc) + list(APPEND third_party_deps extern_leveldb) + list(APPEND third_party_deps extern_brpc) endif() endif() if(WITH_NGRAPH) if(WITH_MKLDNN) include(external/ngraph) # download, build, install nGraph - list(APPEND third_party_deps ngraph) + list(APPEND third_party_deps extern_ngraph) else() MESSAGE(WARNING "nGraph needs mkl-dnn to be enabled." @@ -153,19 +185,20 @@ if(WITH_NGRAPH) endif() if(WITH_XBYAK) - list(APPEND third_party_deps xbyak) + include(external/xbyak) # download, build, install xbyak + list(APPEND third_party_deps extern_xbyak) endif() if(WITH_LIBXSMM) include(external/libxsmm) # download, build, install libxsmm - list(APPEND third_party_deps libxsmm) + list(APPEND third_party_deps extern_libxsmm) endif() if(WITH_DGC) message(STATUS "add dgc lib.") include(external/dgc) # download, build, install dgc add_definitions(-DPADDLE_WITH_DGC) - list(APPEND third_party_deps dgc) + list(APPEND third_party_deps extern_dgc) endif() add_custom_target(third_party DEPENDS ${third_party_deps}) \ No newline at end of file -- GitLab