configure.cmake 6.1 KB
Newer Older
1
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
2
#
L
liaogang 已提交
3 4 5
# 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
6
#
L
liaogang 已提交
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
L
liaogang 已提交
9 10 11 12 13 14
# 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.

15
if(NOT WITH_PYTHON)
16
  add_definitions(-DPADDLE_NO_PYTHON)
W
Wilber 已提交
17
endif()
18

19
if(WITH_TESTING)
20
  add_definitions(-DPADDLE_WITH_TESTING)
W
Wilber 已提交
21
endif()
22

23
if(WITH_INFERENCE_API_TEST)
24
  add_definitions(-DPADDLE_WITH_INFERENCE_API_TEST)
W
Wilber 已提交
25
endif()
26

L
liaogang 已提交
27
if(NOT WITH_PROFILER)
28
  add_definitions(-DPADDLE_DISABLE_PROFILER)
W
Wilber 已提交
29
endif()
L
liaogang 已提交
30

31
if(WITH_AVX AND AVX_FOUND)
32 33
  set(SIMD_FLAG ${AVX_FLAG})
  add_definitions(-DPADDLE_WITH_AVX)
34
elseif(SSE3_FOUND AND NOT WIN32)
35
  set(SIMD_FLAG ${SSE3_FLAG})
36 37
endif()

38 39 40
if(SSE3_FOUND)
  # TODO: Runtime detection should be used here.
  add_definitions(-DPADDLE_WITH_SSE3)
41 42
endif()

D
dzhwinter 已提交
43
if(WIN32)
D
dzhwinter 已提交
44
  # windows header option for all targets.
D
dzhwinter 已提交
45
  add_definitions(-D_XKEYCHECK_H)
46 47 48 49 50 51 52 53 54
  # Use symbols instead of absolute path, reduce the cmake link command length.
  set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
  set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
  set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
  set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
  set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1)
  set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1)
  set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@")
  set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@")
D
dzhwinter 已提交
55

56
  add_definitions(-DPADDLE_DLL_INFERENCE)
T
tianshuo78520a 已提交
57
  # set definition for the dll export
58 59 60 61 62
  if(NOT MSVC)
    message(
      FATAL
      "Windows build only support msvc. Which was binded by the nvcc compiler of NVIDIA."
    )
W
Wilber 已提交
63 64
  endif()
endif()
D
dzhwinter 已提交
65

chen.zhiyu's avatar
chen.zhiyu 已提交
66
if(WITH_MUSL)
67
  add_definitions(-DPADDLE_WITH_MUSL)
chen.zhiyu's avatar
chen.zhiyu 已提交
68

69 70
  message(STATUS, "Set compile option WITH_MKL=OFF when WITH_MUSL=ON")
  set(WITH_MKL OFF)
chen.zhiyu's avatar
chen.zhiyu 已提交
71

72 73
  message(STATUS, "Set compile option WITH_GPU=OFF when WITH_MUSL=ON")
  set(WITH_GPU OFF)
chen.zhiyu's avatar
chen.zhiyu 已提交
74 75
endif()

H
heqiaozhi 已提交
76
if(WITH_PSLIB)
77
  add_definitions(-DPADDLE_WITH_PSLIB)
H
heqiaozhi 已提交
78
endif()
79 80

if(WITH_ARM_BRPC)
81
  add_definitions(-DPADDLE_WITH_ARM_BRPC)
82
endif()
83

84 85
if(WITH_FLPS)
  add_definitions(-DPADDLE_WITH_FLPS)
86
endif()
H
heqiaozhi 已提交
87

88
if(WITH_GLOO)
89
  add_definitions(-DPADDLE_WITH_GLOO)
90 91
endif()

H
hutuxian 已提交
92
if(WITH_BOX_PS)
93
  add_definitions(-DPADDLE_WITH_BOX_PS)
H
hutuxian 已提交
94 95
endif()

96
if(WITH_ASCEND)
97
  add_definitions(-DPADDLE_WITH_ASCEND)
98 99
endif()

100
if(WITH_ASCEND_CL)
101
  add_definitions(-DPADDLE_WITH_ASCEND_CL)
102 103
endif()

104
if(WITH_ASCEND_INT64)
105
  add_definitions(-DPADDLE_WITH_ASCEND_INT64)
106 107
endif()

108
if(WITH_XPU)
109 110
  message(STATUS "Compile with XPU!")
  add_definitions(-DPADDLE_WITH_XPU)
111 112
endif()

L
Liu-xiandong 已提交
113
if(WITH_XPU_KP)
114 115
  message(STATUS "Compile with XPU_KP!")
  add_definitions(-DPADDLE_WITH_XPU_KP)
L
Liu-xiandong 已提交
116 117
endif()

J
jianghaicheng 已提交
118
if(WITH_IPU)
119 120
  message(STATUS "Compile with IPU!")
  add_definitions(-DPADDLE_WITH_IPU)
J
jianghaicheng 已提交
121 122
endif()

F
fwenguang 已提交
123
if(WITH_MLU)
124 125
  message(STATUS "Compile with MLU!")
  add_definitions(-DPADDLE_WITH_MLU)
F
fwenguang 已提交
126 127
endif()

128
if(WITH_GPU)
129 130
  add_definitions(-DPADDLE_WITH_CUDA)
  add_definitions(-DEIGEN_USE_GPU)
131

132
  find_package(CUDA REQUIRED)
L
liaogang 已提交
133

134 135 136
  if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_LESS 10.1)
    message(FATAL_ERROR "Paddle needs CUDA >= 10.1 to compile")
  endif()
L
liaogang 已提交
137

138 139 140
  if(NOT CUDNN_FOUND)
    message(FATAL_ERROR "Paddle needs cudnn to compile")
  endif()
T
tianshuo78520a 已提交
141

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  if(${CUDNN_MAJOR_VERSION} VERSION_LESS 7)
    message(FATAL_ERROR "Paddle needs CUDNN >= 7.0 to compile")
  endif()

  if(CUPTI_FOUND)
    include_directories(${CUPTI_INCLUDE_DIR})
    add_definitions(-DPADDLE_WITH_CUPTI)
  else()
    message(STATUS "Cannot find CUPTI, GPU Profiling is incorrect.")
  endif()
  set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=\"${SIMD_FLAG}\"")

  # Include cuda and cudnn
  include_directories(${CUDNN_INCLUDE_DIR})
  include_directories(${CUDA_TOOLKIT_INCLUDE})
T
tianshuo78520a 已提交
157

158 159 160 161 162
  if(TENSORRT_FOUND)
    if(WIN32)
      if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_LESS 9)
        message(FATAL_ERROR "TensorRT needs CUDA >= 9.0 to compile on Windows")
      endif()
163
    else()
164 165 166 167 168 169 170 171 172
      if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_LESS 8)
        message(FATAL_ERROR "TensorRT needs CUDA >= 8.0 to compile")
      endif()
      if(${CUDNN_MAJOR_VERSION} VERSION_LESS 7)
        message(FATAL_ERROR "TensorRT needs CUDNN >= 7.0 to compile")
      endif()
      if(${TENSORRT_MAJOR_VERSION} VERSION_LESS 4)
        message(FATAL_ERROR "Paddle needs TensorRT >= 4.0 to compile")
      endif()
L
Luo Tao 已提交
173
    endif()
174 175
    include_directories(${TENSORRT_INCLUDE_DIR})
  endif()
176
elseif(WITH_ROCM)
177 178 179
  add_definitions(-DPADDLE_WITH_HIP)
  add_definitions(-DEIGEN_USE_GPU)
  add_definitions(-DEIGEN_USE_HIP)
180

181 182 183
  if(NOT MIOPEN_FOUND)
    message(FATAL_ERROR "Paddle needs MIOpen to compile")
  endif()
184

185 186 187
  if(${MIOPEN_VERSION} VERSION_LESS 2090)
    message(FATAL_ERROR "Paddle needs MIOPEN >= 2.9 to compile")
  endif()
188
else()
189 190
  add_definitions(-DHPPL_STUB_FUNC)
  list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS cu)
191
endif()
L
liaogang 已提交
192

193 194 195 196 197
if(WITH_MKLML AND MKLML_IOMP_LIB)
  message(STATUS "Enable Intel OpenMP with ${MKLML_IOMP_LIB}")
  if(WIN32)
    # openmp not support well for now on windows
    set(OPENMP_FLAGS "")
W
Wilber 已提交
198
  else()
199
    set(OPENMP_FLAGS "-fopenmp")
W
Wilber 已提交
200
  endif()
201 202 203 204
  set(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
  set(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS ${OPENMP_FLAGS})
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENMP_FLAGS}")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENMP_FLAGS}")
205
endif()
206

207 208
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SIMD_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAG}")
H
Helin Wang 已提交
209

W
Wu Yi 已提交
210 211 212 213
if(WITH_DISTRIBUTE)
  add_definitions(-DPADDLE_WITH_DISTRIBUTE)
endif()

T
tangwei12 已提交
214
if(WITH_PSCORE)
215
  add_definitions(-DPADDLE_WITH_PSCORE)
T
tangwei12 已提交
216 217
endif()

T
Thunderbrook 已提交
218
if(WITH_HETERPS)
219
  add_definitions(-DPADDLE_WITH_HETERPS)
T
Thunderbrook 已提交
220
endif()
T
tangwei12 已提交
221

G
gongweibao 已提交
222
if(WITH_BRPC_RDMA)
223
  add_definitions(-DPADDLE_WITH_BRPC_RDMA)
W
Wilber 已提交
224
endif()
225 226

if(ON_INFER)
227
  add_definitions(-DPADDLE_ON_INFERENCE)
W
Wilber 已提交
228
endif()
Y
Yanghello 已提交
229 230

if(WITH_CRYPTO)
231
  add_definitions(-DPADDLE_WITH_CRYPTO)
W
Wilber 已提交
232
endif()
233 234

if(WITH_CUSTOM_DEVICE AND NOT WIN32)
235
  add_definitions(-DPADDLE_WITH_CUSTOM_DEVICE)
236
endif()