paddlepaddle.cmake 8.0 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright (c) 2019 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)

W
wangguibao 已提交
17
SET(PADDLE_SOURCES_DIR ${THIRD_PARTY_PATH}/Paddle)
W
wangguibao 已提交
18
SET(PADDLE_DOWNLOAD_DIR ${PADDLE_SOURCES_DIR}/src/extern_paddle)
W
serving  
wangguibao 已提交
19
SET(PADDLE_INSTALL_DIR ${THIRD_PARTY_PATH}/install/Paddle/)
W
wangguibao 已提交
20
SET(PADDLE_INCLUDE_DIR "${PADDLE_INSTALL_DIR}/include" CACHE PATH "PaddlePaddle include directory." FORCE)
Z
zhangjun 已提交
21
SET(PADDLE_LIBRARIES "${PADDLE_INSTALL_DIR}/lib/libpaddle_inference.a" CACHE FILEPATH "Paddle library." FORCE)
W
wangguibao 已提交
22

G
guru4elephant 已提交
23
message("paddle install dir: " ${PADDLE_INSTALL_DIR})
W
wangguibao 已提交
24 25 26 27

# Reference https://stackoverflow.com/questions/45414507/pass-a-list-of-prefix-paths-to-externalproject-add-in-cmake-args
set(prefix_path "${THIRD_PARTY_PATH}/install/gflags|${THIRD_PARTY_PATH}/install/leveldb|${THIRD_PARTY_PATH}/install/snappy|${THIRD_PARTY_PATH}/install/gtest|${THIRD_PARTY_PATH}/install/protobuf|${THIRD_PARTY_PATH}/install/zlib|${THIRD_PARTY_PATH}/install/glog")

W
Wang Guibao 已提交
28 29
message( "WITH_GPU = ${WITH_GPU}")

W
wangguibao 已提交
30 31 32 33

# Paddle Version should be one of:
# latest: latest develop build
# version number like 1.5.2
H
HexToString 已提交
34
SET(PADDLE_VERSION "2.1.0")
W
wangjiawei04 已提交
35 36
if (WITH_GPU)
    if(CUDA_VERSION EQUAL 11.0)
H
HexToString 已提交
37
        set(CUDA_SUFFIX "cuda11.0-cudnn8-mkl-gcc8.2")
W
wangjiawei04 已提交
38 39
        set(WITH_TRT ON)
    elseif(CUDA_VERSION EQUAL 10.2)
H
HexToString 已提交
40
        set(CUDA_SUFFIX "cuda10.2-cudnn8-mkl-gcc8.2")
W
wangjiawei04 已提交
41 42
        set(WITH_TRT ON)
    elseif(CUDA_VERSION EQUAL 10.1)
H
HexToString 已提交
43
        set(CUDA_SUFFIX "cuda10.1-cudnn7-mkl-gcc8.2")
W
wangjiawei04 已提交
44 45 46 47 48 49 50 51
        set(WITH_TRT ON)
    elseif(CUDA_VERSION EQUAL 10.0)
        set(CUDA_SUFFIX "cuda10-cudnn7-avx-mkl")
    elseif(CUDA_VERSION EQUAL 9.0)
        set(CUDA_SUFFIX "cuda9-cudnn7-avx-mkl")
    endif()
else()
    set(WITH_TRT OFF)
W
wangjiawei04 已提交
52
endif()  
W
wangguibao 已提交
53 54

if (WITH_GPU)
W
wangjiawei04 已提交
55
    SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-gpu-${CUDA_SUFFIX}")
Z
zhangjun 已提交
56 57
elseif (WITH_LITE)
    if (WITH_XPU)
58
        SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}-xpu")
Z
zhangjun 已提交
59
    else()
60
        SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}")
Z
zhangjun 已提交
61
    endif()
W
wangguibao 已提交
62
else()
G
guru4elephant 已提交
63
    if (WITH_AVX)
W
wangguibao 已提交
64 65 66 67 68 69 70 71 72 73
        if (WITH_MKLML)
            SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-cpu-avx-mkl")
        else()
            SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-cpu-avx-openblas")
        endif()
    else()
        SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-cpu-noavx-openblas")
    endif()
endif()

Z
zhangjun 已提交
74
if(WITH_LITE)
75
    SET(PADDLE_LIB_PATH "http://paddle-serving.bj.bcebos.com/inferlib/${PADDLE_LIB_VERSION}/paddle_inference.tgz")
Z
zhangjun 已提交
76
else()
77
    SET(PADDLE_LIB_PATH "http://paddle-inference-lib.bj.bcebos.com/${PADDLE_LIB_VERSION}/paddle_inference.tgz")
Z
zhangjun 已提交
78 79
endif()

W
wangguibao 已提交
80
MESSAGE(STATUS "PADDLE_LIB_PATH=${PADDLE_LIB_PATH}")
M
MRXLT 已提交
81
if (WITH_GPU OR WITH_MKLML)
M
MRXLT 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94
    if (WITH_TRT)
        ExternalProject_Add(
            "extern_paddle"
            ${EXTERNAL_PROJECT_LOG_ARGS}
            URL                 "${PADDLE_LIB_PATH}"
            PREFIX              "${PADDLE_SOURCES_DIR}"
            DOWNLOAD_DIR        "${PADDLE_DOWNLOAD_DIR}"
            CONFIGURE_COMMAND   ""
            BUILD_COMMAND       ""
            UPDATE_COMMAND      ""
            INSTALL_COMMAND
                ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include &&
                ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib &&
W
wangjiawei04 已提交
95 96
                ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party &&
                ${CMAKE_COMMAND} -E copy ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libdnnl.so.1 ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libdnnl.so
M
MRXLT 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        )
    else()
        ExternalProject_Add(
            "extern_paddle"
            ${EXTERNAL_PROJECT_LOG_ARGS}
            URL                 "${PADDLE_LIB_PATH}"
            PREFIX              "${PADDLE_SOURCES_DIR}"
            DOWNLOAD_DIR        "${PADDLE_DOWNLOAD_DIR}"
            CONFIGURE_COMMAND   ""
            BUILD_COMMAND       ""
            UPDATE_COMMAND      ""
            INSTALL_COMMAND
                ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include &&
                ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib &&
                ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party &&
                ${CMAKE_COMMAND} -E copy ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so.0 ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so 
        )
    endif()
M
MRXLT 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128
else()
ExternalProject_Add(
    "extern_paddle"
    ${EXTERNAL_PROJECT_LOG_ARGS}
    URL                 "${PADDLE_LIB_PATH}"
    PREFIX              "${PADDLE_SOURCES_DIR}"
    DOWNLOAD_DIR        "${PADDLE_DOWNLOAD_DIR}"
    CONFIGURE_COMMAND   ""
    BUILD_COMMAND       ""
    UPDATE_COMMAND      ""
    INSTALL_COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include &&
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib &&
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party
W
wangguibao 已提交
129
)
G
guru4elephant 已提交
130 131
endif()

W
wangguibao 已提交
132
INCLUDE_DIRECTORIES(${PADDLE_INCLUDE_DIR})
W
wangguibao 已提交
133 134
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${PADDLE_INSTALL_DIR}/third_party/install/mklml/lib")
LINK_DIRECTORIES(${PADDLE_INSTALL_DIR}/third_party/install/mklml/lib)
W
wangguibao 已提交
135

W
wangguibao 已提交
136 137
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib")
LINK_DIRECTORIES(${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib)
W
wangguibao 已提交
138

Z
zhangjun 已提交
139 140 141 142
if (NOT WITH_MKLML)
    ADD_LIBRARY(openblas STATIC IMPORTED GLOBAL)
    SET_PROPERTY(TARGET openblas PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/openblas/lib/libopenblas.a)
endif()
G
guru4elephant 已提交
143

Z
zhangjun 已提交
144 145
ADD_LIBRARY(paddle_inference STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET paddle_inference PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/lib/libpaddle_inference.a)
M
MRXLT 已提交
146

M
MRXLT 已提交
147
if (WITH_TRT)
Z
update  
zhangjun 已提交
148 149 150 151 152
    ADD_LIBRARY(nvinfer SHARED IMPORTED GLOBAL)
    SET_PROPERTY(TARGET nvinfer PROPERTY IMPORTED_LOCATION ${TENSORRT_ROOT}/lib/libnvinfer.so)
    
    ADD_LIBRARY(nvinfer_plugin SHARED IMPORTED GLOBAL)
    SET_PROPERTY(TARGET nvinfer_plugin PROPERTY IMPORTED_LOCATION ${TENSORRT_ROOT}/lib/libnvinfer_plugin.so)
M
MRXLT 已提交
153
endif()
M
MRXLT 已提交
154

Z
zhangjun 已提交
155
if (WITH_LITE)
Z
zhangjun 已提交
156 157
    ADD_LIBRARY(paddle_full_api_shared STATIC IMPORTED GLOBAL)
    SET_PROPERTY(TARGET paddle_full_api_shared PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/lite/cxx/lib/libpaddle_full_api_shared.so)
Z
update  
zhangjun 已提交
158 159 160 161 162 163 164 165
    
    if (WITH_XPU)
        ADD_LIBRARY(xpuapi SHARED IMPORTED GLOBAL)
        SET_PROPERTY(TARGET xpuapi PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/xpu/lib/libxpuapi.so)
    
        ADD_LIBRARY(xpurt SHARED IMPORTED GLOBAL)
        SET_PROPERTY(TARGET xpurt PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/xpu/lib/libxpurt.so)
    endif()
M
MRXLT 已提交
166
endif()
W
wangguibao 已提交
167

W
serving  
wangguibao 已提交
168
ADD_LIBRARY(xxhash STATIC IMPORTED GLOBAL)
W
wangguibao 已提交
169
SET_PROPERTY(TARGET xxhash PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/xxhash/lib/libxxhash.a)
W
serving  
wangguibao 已提交
170

H
HexToString 已提交
171 172 173
ADD_LIBRARY(cryptopp STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET cryptopp PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/cryptopp/lib/libcryptopp.a)

W
wangguibao 已提交
174
LIST(APPEND external_project_dependencies paddle)
W
wangguibao 已提交
175

W
serving  
wangguibao 已提交
176
LIST(APPEND paddle_depend_libs
H
HexToString 已提交
177
        xxhash cryptopp)
M
MRXLT 已提交
178

Z
zhangjun 已提交
179
if(WITH_LITE)
Z
zhangjun 已提交
180
    LIST(APPEND paddle_depend_libs paddle_full_api_shared)
Z
update  
zhangjun 已提交
181 182 183
    if(WITH_XPU)
        LIST(APPEND paddle_depend_libs xpuapi xpurt)
    endif()
Z
zhangjun 已提交
184 185
endif()

M
MRXLT 已提交
186
if(WITH_TRT)
Z
update  
zhangjun 已提交
187 188
    LIST(APPEND paddle_depend_libs
        nvinfer nvinfer_plugin)
M
MRXLT 已提交
189
endif()