third_party.cmake 7.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# 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.

# compile third party for fluid on both windows/linux/mac

set(THIRD_PARTY_PATH "${CMAKE_BINARY_DIR}/third_party" CACHE STRING
  "A path setting third party libraries download & build directories.")

set(THIRD_PARTY_BUILD_TYPE Release)

# Correction of flags on different Platform(WIN/MAC) and Print Warning Message
if (APPLE)
    if(WITH_MKL)
        MESSAGE(WARNING 
            "Mac is not supported with MKL in Paddle yet. Force WITH_MKL=OFF.")
        set(WITH_MKL OFF CACHE STRING "Disable MKL for building on mac" FORCE)
    endif()
endif()

if(WIN32 OR APPLE)
32 33 34
    MESSAGE(STATUS "Disable XBYAK in Windows and MacOS")
    SET(WITH_XBYAK OFF CACHE STRING "Disable XBYAK in Windows and MacOS" FORCE)

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    if(WITH_LIBXSMM)
        MESSAGE(WARNING 
            "Windows, Mac are not supported with libxsmm in Paddle yet."
            "Force WITH_LIBXSMM=OFF")
        SET(WITH_LIBXSMM OFF CACHE STRING "Disable LIBXSMM in Windows and MacOS" FORCE)
    endif()

    if(WITH_NGRAPH)
        MESSAGE(WARNING
            "Windows or Mac is not supported with nGraph in Paddle yet."
            "Force WITH_NGRAPH=OFF")
        SET(WITH_NGRAPH OFF CACHE STRING "Disable nGraph in Windows and MacOS" FORCE)
    endif()

    if(WITH_BOX_PS)
        MESSAGE(WARNING
            "Windows or Mac is not supported with BOX_PS in Paddle yet."
            "Force WITH_BOX_PS=OFF")
        SET(WITH_BOX_PS OFF CACHE STRING "Disable BOX_PS package in Windows and MacOS" FORCE)
    endif()
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

    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()
76 77
endif()

78
set(WITH_MKLML ${WITH_MKL})
79 80
if(NOT DEFINED WITH_MKLDNN)
    if(WITH_MKL AND AVX2_FOUND)
81 82 83 84 85 86 87
        set(WITH_MKLDNN ON)
    else()
        message(STATUS "Do not have AVX2 intrinsics and disabled MKL-DNN")
        set(WITH_MKLDNN OFF)
    endif()
endif()

88 89 90 91
if(WIN32 OR APPLE OR NOT WITH_GPU OR ON_INFER)
    set(WITH_DGC OFF)
endif()

92 93 94 95
if(${CMAKE_VERSION} VERSION_GREATER "3.5.2")
    set(SHALLOW_CLONE "GIT_SHALLOW TRUE") # adds --depth=1 arg to git clone of External_Projects
endif()

96 97 98 99 100 101 102 103 104 105 106
########################### include third_party accoring to flags ###############################
include(external/zlib)      # download, build, install zlib
include(external/gflags)    # download, build, install gflags
include(external/glog)      # download, build, install glog
include(external/boost)     # download boost
include(external/eigen)     # download eigen3
include(external/threadpool)# download threadpool
include(external/dlpack)    # download dlpack
include(external/xxhash)    # download, build, install xxhash
include(external/warpctc)   # download, build, install warpctc

107 108 109
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)
110 111

if(WITH_AMD_GPU)
112 113
    include(external/rocprim)   # download, build, install rocprim
    list(APPEND third_party_deps extern_rocprim)
114 115
endif()

116 117
include(cblas)              	# find first, then download, build, install openblas
if(${CBLAS_PROVIDER} STREQUAL MKLML)
118
    list(APPEND third_party_deps extern_mklml)
119
endif()
120
if(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS)
121 122 123 124 125
    list(APPEND third_party_deps extern_openblas)
endif()

if(WITH_MKLDNN)
    include(external/mkldnn)    # download, build, install mkldnn
126
    list(APPEND third_party_deps extern_mkldnn)
127 128
endif()

129
include(external/protobuf)  	# find first, then download, build, install protobuf
130 131 132 133 134 135 136
if(NOT PROTOBUF_FOUND OR WIN32)
    list(APPEND third_party_deps extern_protobuf)
endif()

if(WITH_PYTHON)
    include(external/python)    # find python and python_module
    include(external/pybind11)  # download pybind11
137
    list(APPEND third_party_deps extern_pybind)
138 139 140 141 142 143 144 145 146
endif()

IF(WITH_TESTING OR (WITH_DISTRIBUTE AND NOT WITH_GRPC))
    include(external/gtest)     # download, build, install gtest
    list(APPEND third_party_deps extern_gtest)
ENDIF()

if(WITH_GPU)
    include(external/cub)       # download cub
147
    list(APPEND third_party_deps extern_cub)
148 149 150
endif(WITH_GPU)

if(WITH_PSLIB)
151 152 153 154 155 156 157 158 159 160
    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()
161 162 163 164
endif(WITH_PSLIB)

if(WITH_BOX_PS)
    include(external/box_ps)
165
    list(APPEND third_party_deps extern_box_ps)
166 167 168
endif(WITH_BOX_PS)

if(WITH_DISTRIBUTE)
169
    list(APPEND third_party_deps extern_cares)
170
    if(WITH_GRPC)
171
        list(APPEND third_party_deps extern_grpc)
172
    else()
173 174
        list(APPEND third_party_deps extern_leveldb)
        list(APPEND third_party_deps extern_brpc)
175 176 177 178 179 180
    endif()
endif()

if(WITH_NGRAPH)
    if(WITH_MKLDNN)
        include(external/ngraph)    # download, build, install nGraph
181
        list(APPEND third_party_deps extern_ngraph)
182 183 184 185 186 187 188 189 190
    else()
        MESSAGE(WARNING
            "nGraph needs mkl-dnn to be enabled."
            "Force WITH_NGRAPH=OFF")
        SET(WITH_NGRAPH OFF CACHE STRING "Disable nGraph if mkl-dnn is disabled" FORCE)
    endif()
endif()

if(WITH_XBYAK)
191
    include(external/xbyak)         # download, build, install xbyak
192
    list(APPEND third_party_deps extern_xbyak)
193 194 195
endif()

if(WITH_LIBXSMM)
196
    include(external/libxsmm)       # download, build, install libxsmm
197
    list(APPEND third_party_deps extern_libxsmm)
198 199 200 201
endif()

if(WITH_DGC)
    message(STATUS "add dgc lib.")
202
    include(external/dgc)           # download, build, install dgc
203
    add_definitions(-DPADDLE_WITH_DGC)
204
    list(APPEND third_party_deps extern_dgc)
205 206
endif()

207
add_custom_target(third_party DEPENDS ${third_party_deps})