CMakeLists.txt 17.7 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 32 33 34 35 36 37 38 39
set(PYBIND_DEPS
    init
    pybind
    python
    proto_desc
    memory
    executor
    fleet_wrapper
    box_wrapper
    metrics
    prune
    feed_fetch_method
    pass
    generate_pass
    pass_builder
    parallel_executor
    profiler
    layer
    tracer
    engine
    scope_pool
    analysis_predictor
    imperative_profiler
    imperative_flag
    dlpack_tensor
    device_context
    gloo_wrapper
    infer_io_utils
    heter_wrapper
    generator
    op_version_registry
    ps_gpu_wrapper
    custom_operator
    cost_model
    cuda_graph_with_memory_pool
    fleet_executor
    global_utils
    phi_utils
    tcp_store
40
    comm_context_manager
41
    new_profiler
42
    auto_parallel
43
    jit_layer
J
Jiabin Yang 已提交
44 45
    jit_property
    prim_utils)
46 47

if(WITH_PSCORE)
S
seemingwang 已提交
48
  set(PYBIND_DEPS ${PYBIND_DEPS} ps_service)
49
  if(WITH_HETERPS)
50 51
    set(PYBIND_DEPS ${PYBIND_DEPS} graph_gpu_wrapper)
  endif()
S
seemingwang 已提交
52
endif()
X
Xinger 已提交
53
if(WITH_RPC)
54 55 56 57 58 59 60 61 62 63 64 65
  set(PYBIND_DEPS
      ${PYBIND_DEPS}
      paddle_rpc
      brpc
      ssl
      crypto
      protobuf
      zlib
      leveldb
      snappy
      gflags
      glog)
66
endif()
67
if(WITH_GPU OR WITH_ROCM)
68
  set(PYBIND_DEPS ${PYBIND_DEPS} dynload_cuda)
69
  set(PYBIND_DEPS ${PYBIND_DEPS} cuda_device_guard)
70 71
endif()

72
if(WITH_GPU)
73 74
  set(PYBIND_DEPS ${PYBIND_DEPS} cuda_profiler)
endif()
75
if(WITH_IPU)
J
jianghaicheng 已提交
76 77
  set(PYBIND_DEPS ${PYBIND_DEPS} ipu_info)
endif()
78

79
if(WITH_NCCL OR WITH_RCCL)
80
  set(PYBIND_DEPS ${PYBIND_DEPS} nccl_wrapper)
81
  set(PYBIND_DEPS ${PYBIND_DEPS} reducer)
82 83
endif()

84
if(WITH_XPU_BKCL)
85 86
  set(PYBIND_DEPS ${PYBIND_DEPS} reducer)
  set(PYBIND_DEPS ${PYBIND_DEPS} bkcl_context)
K
kuizhiqing 已提交
87 88 89
  set(PYBIND_DEPS ${PYBIND_DEPS} heter_ccl_context)
endif()

90
if(WITH_ASCEND_CL)
K
kuizhiqing 已提交
91 92 93
  set(PYBIND_DEPS ${PYBIND_DEPS} reducer)
  set(PYBIND_DEPS ${PYBIND_DEPS} hccl_context)
  set(PYBIND_DEPS ${PYBIND_DEPS} heter_ccl_context)
94 95
endif()

96
if(WITH_CNCL)
97
  set(PYBIND_DEPS ${PYBIND_DEPS} reducer)
98 99 100
  set(PYBIND_DEPS ${PYBIND_DEPS} cncl_context)
endif()

101
if(NOT WIN32)
102
  set(PYBIND_DEPS ${PYBIND_DEPS} data_loader)
103
  if(WITH_NCCL OR WITH_RCCL)
104
    set(PYBIND_DEPS ${PYBIND_DEPS} nccl_context)
K
kuizhiqing 已提交
105
    set(PYBIND_DEPS ${PYBIND_DEPS} heter_ccl_context)
106
  endif()
107
endif()
F
flame 已提交
108

S
sneaxiy 已提交
109 110 111
if(WITH_PYTHON)
  list(APPEND PYBIND_DEPS py_func_op)
endif()
112 113

set(PYBIND_SRCS
114
    pybind.cc
115 116 117 118 119
    imperative.cc
    inference_api.cc
    ir.cc
    bind_fleet_executor.cc
    reader_py.cc
120
    protobuf.cc
121
    exception.cc
122 123 124 125
    op_function_common.cc
    parallel_executor.cc
    tensor.cc
    place.cc
126 127 128 129 130 131 132 133 134 135 136 137 138 139
    const_value.cc
    global_value_getter_setter.cc
    fleet_wrapper_py.cc
    heter_wrapper_py.cc
    ps_gpu_wrapper_py.cc
    gloo_wrapper_py.cc
    box_helper_py.cc
    metrics_py.cc
    data_set_py.cc
    bind_cost_model.cc
    compatible.cc
    io.cc
    generator_py.cc
    communication.cc
140
    cuda_streams_py.cc
141
    custom_device_py.cc
J
james 已提交
142
    xpu_streams_py.cc
143
    jit.cc
姜永久 已提交
144
    auto_parallel_py.cc)
145

146 147
if(WITH_CUSTOM_DEVICE)
  set(PYBIND_DEPS ${PYBIND_DEPS} phi_capi)
148
  set(PYBIND_DEPS ${PYBIND_DEPS} custom_device_common_op_registry)
149 150
endif()

151
if(WITH_PYTHON)
W
Wen Sun 已提交
152
  set(PYBIND_DEPS ${PYBIND_DEPS} process_group eager_reducer)
153
  if(WITH_NCCL OR WITH_RCCL)
W
Wen Sun 已提交
154
    set(PYBIND_DEPS ${PYBIND_DEPS} process_group_nccl)
155
  endif()
J
james 已提交
156
  if(WITH_XPU_BKCL)
W
Wen Sun 已提交
157
    set(PYBIND_DEPS ${PYBIND_DEPS} process_group_bkcl)
J
james 已提交
158
  endif()
159
  if(WITH_GLOO)
W
Wen Sun 已提交
160
    set(PYBIND_DEPS ${PYBIND_DEPS} process_group_gloo)
161
  endif()
W
wuhuachaocoding 已提交
162
  if(WITH_MPI)
W
Wen Sun 已提交
163
    set(PYBIND_DEPS ${PYBIND_DEPS} process_group_mpi)
W
wuhuachaocoding 已提交
164
  endif()
165
  if(WITH_CUSTOM_DEVICE)
W
Wen Sun 已提交
166
    set(PYBIND_DEPS ${PYBIND_DEPS} process_group_custom)
167
  endif()
168 169 170 171 172
  if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
    set(DISTRIBUTE_COMPILE_FLAGS "${DISTRIBUTE_COMPILE_FLAGS} -faligned-new")
    set_source_files_properties(
      distributed_py.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
  endif()
173 174
  set(PYBIND_SRCS ${PYBIND_SRCS} distributed_py.cc)
endif()
175
set(PYBIND_DEPS ${PYBIND_DEPS} processgroup_comm_utils)
176

177
if(WITH_ASCEND)
178 179
  set(PYBIND_DEPS ${PYBIND_DEPS} ascend_wrapper)
  set(PYBIND_SRCS ${PYBIND_SRCS} ascend_wrapper_py.cc)
180
endif()
181

182 183 184
if(WITH_GLOO)
  set(PYBIND_DEPS ${PYBIND_DEPS} gloo_context)
  set(PYBIND_SRCS ${PYBIND_SRCS} gloo_context_py.cc)
185 186
  set(PYBIND_DEPS ${PYBIND_DEPS} imperative_gloo_context)
  set(PYBIND_DEPS ${PYBIND_DEPS} reducer)
187
endif()
188

189
if(WITH_CRYPTO)
Y
Yanghello 已提交
190 191
  set(PYBIND_DEPS ${PYBIND_DEPS} paddle_crypto)
  set(PYBIND_SRCS ${PYBIND_SRCS} crypto.cc)
192
endif()
193 194 195

if(WITH_PSLIB)
  set(DISTRIBUTE_COMPILE_FLAGS
196
      "-Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor -Wno-error=return-type -Wno-error=unused-but-set-variable -Wno-error=type-limits -Wno-error=unknown-pragmas -Wno-error=parentheses -Wno-error=unused-result"
197 198 199
  )
  if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
    set(DISTRIBUTE_COMPILE_FLAGS "${DISTRIBUTE_COMPILE_FLAGS} -faligned-new")
T
Thunderbrook 已提交
200
  endif()
201 202
  set_source_files_properties(
    heter_wrapper_py.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
203
endif()
204 205 206
if(WITH_PSCORE)
  if(WITH_ARM_BRPC)
    set(DISTRIBUTE_COMPILE_FLAGS
207
        "-faligned-new -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor -Wno-error=return-type -Wno-error=unused-but-set-variable -Wno-error=unknown-pragmas -Wno-error=parentheses -Wno-error=unused-result"
208
    )
209
  else()
210
    set(DISTRIBUTE_COMPILE_FLAGS
211
        "-Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor -Wno-error=return-type -Wno-error=unused-but-set-variable -Wno-error=unknown-pragmas -Wno-error=parentheses -Wno-error=unused-result"
212
    )
213 214 215
    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
      set(DISTRIBUTE_COMPILE_FLAGS "${DISTRIBUTE_COMPILE_FLAGS} -faligned-new")
    endif()
216
  endif()
217 218
  set_source_files_properties(
    fleet_py.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
Z
zhaocaibei123 已提交
219
  list(APPEND PYBIND_DEPS fleet index_wrapper index_sampler)
220 221
  list(APPEND PYBIND_SRCS)
  set(PYBIND_SRCS fleet_py.cc ${PYBIND_SRCS})
222
endif()
223

X
Xinger 已提交
224
if(WITH_RPC)
225 226
  if(WITH_ARM_BRPC)
    set(DISTRIBUTE_COMPILE_FLAGS
227
        "-faligned-new -Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor -Wno-error=return-type -Wno-error=unused-but-set-variable -Wno-error=unknown-pragmas -Wno-error=parentheses -Wno-error=unused-result"
228 229 230
    )
  else()
    set(DISTRIBUTE_COMPILE_FLAGS
231
        "-Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor -Wno-error=return-type -Wno-error=unused-but-set-variable -Wno-error=unknown-pragmas -Wno-error=parentheses -Wno-error=unused-result"
232 233 234 235 236 237 238 239 240 241
    )
    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
      set(DISTRIBUTE_COMPILE_FLAGS "${DISTRIBUTE_COMPILE_FLAGS} -faligned-new")
    endif()
  endif()
  set_source_files_properties(rpc.cc PROPERTIES COMPILE_FLAGS
                                                ${DISTRIBUTE_COMPILE_FLAGS})
  set(PYBIND_SRCS rpc.cc ${PYBIND_SRCS})
endif()

242
if(WITH_NCCL OR WITH_RCCL)
243 244 245
  list(APPEND PYBIND_SRCS nccl_wrapper_py.cc)
endif()

L
Leo Chen 已提交
246 247
if(WITH_PYTHON)
  # generate op pybind functions automatically for dygraph.
248 249 250 251 252 253 254 255 256 257 258
  if(WITH_ASCEND_CL)
    set(OP_FUNCTION_GENERETOR_DEPS
        pybind
        proto_desc
        executor
        layer
        tracer
        engine
        imperative_profiler
        imperative_flag
        ascend_wrapper)
259
  else()
260 261 262 263 264 265 266 267 268
    set(OP_FUNCTION_GENERETOR_DEPS
        pybind
        proto_desc
        executor
        layer
        tracer
        engine
        imperative_profiler
        imperative_flag)
269
  endif()
L
Leo Chen 已提交
270 271 272
  list(APPEND OP_FUNCTION_GENERETOR_DEPS ${GLOB_OP_LIB})
  list(APPEND OP_FUNCTION_GENERETOR_DEPS ${GLOB_OPERATOR_DEPS})

273
  if(WITH_NCCL OR WITH_RCCL)
L
Leo Chen 已提交
274
    list(APPEND OP_FUNCTION_GENERETOR_DEPS nccl_context)
275
  endif()
L
Leo Chen 已提交
276

277 278
  if(WITH_XPU_BKCL)
    list(APPEND OP_FUNCTION_GENERETOR_DEPS bkcl_context)
279
  endif()
280

281 282
  if(WITH_ASCEND_CL)
    list(APPEND OP_FUNCTION_GENERETOR_DEPS hccl_context)
283
  endif()
284

285 286
  if(WITH_CNCL)
    list(APPEND OP_FUNCTION_GENERETOR_DEPS cncl_context)
287
  endif()
288

289 290 291 292
  if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
    list(APPEND OP_FUNCTION_GENERETOR_DEPS ${PYTHON_LIBRARIES})
  endif()

293 294 295
  add_executable(eager_legacy_op_function_generator
                 eager_legacy_op_function_generator.cc)
  target_link_libraries(eager_legacy_op_function_generator
296
                        ${OP_FUNCTION_GENERETOR_DEPS})
297 298
  if(NOT WIN32)
    add_executable(kernel_signature_generator kernel_signature_generator.cc)
299 300
    target_link_libraries(kernel_signature_generator
                          ${OP_FUNCTION_GENERETOR_DEPS})
301
  endif()
302

303
  get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
304 305
  target_link_libraries(eager_legacy_op_function_generator
                        ${os_dependency_modules})
306
  if(WITH_ROCM)
307
    target_link_libraries(eager_legacy_op_function_generator ${ROCM_HIPRTC_LIB})
308
    target_link_libraries(kernel_signature_generator ${ROCM_HIPRTC_LIB})
309
  endif()
L
Leo Chen 已提交
310

311 312
  set(op_function_output_path ${CMAKE_SOURCE_DIR}/paddle/fluid/pybind/)
  set(CODE_GEN_SPLIT_FILE_COUNT "8")
313
  set(eager_impl_file
314
      ${CMAKE_SOURCE_DIR}/paddle/fluid/pybind/eager_legacy_op_function.cc)
315
  set(tmp_eager_impl_file ${eager_impl_file}.tmp)
316

317 318 319 320 321 322 323
  execute_process(
    COMMAND
      "${PYTHON_EXECUTABLE}"
      "${PADDLE_SOURCE_DIR}/paddle/fluid/pybind/generate_file_structures.py"
      "${PADDLE_SOURCE_DIR}/paddle/fluid/pybind/"
      "${CODE_GEN_SPLIT_FILE_COUNT}")

324 325
  set(EAGER_OP_IMPL_DEPS eager_legacy_op_function_generator
                         eager_python_c_codegen)
326

327
  if(WIN32)
328
    if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
329
      set(op_impl_path "${CMAKE_CURRENT_BINARY_DIR}")
330
    else()
331
      set(op_impl_path "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
332
    endif()
333

334 335
    file(
      WRITE
336
      ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/eager_legacy_op_function_generator_retry.bat
337 338 339
      ""
      "set build_times=1\n"
      ":retry\n"
340 341 342
      "ECHO eager_legacy_op_function_generator run %build_times% time\n"
      "taskkill /f /im eager_legacy_op_function_generator.exe 2>NUL\n"
      "${op_impl_path}/eager_legacy_op_function_generator.exe ${tmp_eager_impl_file}\n"
343 344 345 346 347 348 349 350 351
      "if %ERRORLEVEL% NEQ 0 (\n"
      "    set /a build_times=%build_times%+1\n"
      "    if %build_times% GEQ 10 (\n"
      "        exit /b 1\n"
      "    ) else (\n"
      "        goto :retry\n"
      "    )\n"
      ")\n"
      "exit /b 0")
352

353
    if(${CBLAS_PROVIDER} STREQUAL MKLML)
354 355 356 357
      add_custom_command(
        OUTPUT ${op_impl_path}/libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_IOMP_LIB}
                ${op_impl_path}
358 359
        DEPENDS mklml)
      list(APPEND OP_IMPL_DEPS ${op_impl_path}/libiomp5md.dll)
360
      list(APPEND EAGER_OP_IMPL_DEPS ${op_impl_path}/libiomp5md.dll)
361
    else()
362 363
      add_custom_command(
        OUTPUT ${op_impl_path}/openblas.dll
364 365 366
        COMMAND ${CMAKE_COMMAND} -E copy ${OPENBLAS_SHARED_LIB} ${op_impl_path}
        DEPENDS extern_openblas)
      list(APPEND OP_IMPL_DEPS ${op_impl_path}/openblas.dll)
367
      list(APPEND EAGER_OP_IMPL_DEPS ${op_impl_path}/openblas.dll)
368
    endif()
L
Leo Chen 已提交
369
    if(WITH_MKLDNN)
370 371
      add_custom_command(
        OUTPUT ${op_impl_path}/mkldnn.dll
372 373
        COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_SHARED_LIB} ${op_impl_path}
        DEPENDS mkldnn)
374 375
      list(APPEND OP_IMPL_DEPS ${op_impl_path}/mkldnn.dll)
      list(APPEND EAGER_OP_IMPL_DEPS ${op_impl_path}/mkldnn.dll)
376
    endif()
377
    if(WITH_ONNXRUNTIME)
378 379
      add_custom_command(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/paddle2onnx.dll
380
        COMMAND ${CMAKE_COMMAND} -E copy ${PADDLE2ONNX_LIB}
381
                ${CMAKE_CURRENT_BINARY_DIR}
382 383
        DEPENDS paddle2onnx)
      list(APPEND OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/paddle2onnx.dll)
384 385
      list(APPEND EAGER_OP_IMPL_DEPS
           ${CMAKE_CURRENT_BINARY_DIR}/paddle2onnx.dll)
386

387 388 389 390
      add_custom_command(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.dll
        COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_SHARED_LIB}
                ${CMAKE_CURRENT_BINARY_DIR}
391 392
        DEPENDS onnxruntime)
      list(APPEND OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.dll)
393 394
      list(APPEND EAGER_OP_IMPL_DEPS
           ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.dll)
395
    endif()
396

397
    if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
398 399 400
      add_custom_command(
        OUTPUT ${eager_impl_file}
        COMMAND
401
          ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/eager_legacy_op_function_generator_retry.bat
402 403
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_eager_impl_file}
                ${eager_impl_file}
404 405 406
        COMMENT "copy_if_different ${tmp_eager_impl_file} to ${eager_impl_file}"
        DEPENDS ${EAGER_OP_IMPL_DEPS})
    endif()
407
  else()
408
    # If there are no *.so in /usr/lib or LD_LIBRARY_PATH,
L
Leo Chen 已提交
409
    # copy these *.so to current directory and append current directory to
410
    # LD_LIBRARY_PATH. This is different with Windows platformm, which search
L
Leo Chen 已提交
411
    # *.dll in current directory automatically.
412
    if(WITH_ONNXRUNTIME)
H
heliqi 已提交
413 414 415 416
      set(PADDLE2ONNX_PYBIND_OUT
          ${CMAKE_CURRENT_BINARY_DIR}/${PADDLE2ONNX_LIB_NAME})
      set(ONNXRUNTIME_PYBIND_OUT
          ${CMAKE_CURRENT_BINARY_DIR}/${ONNXRUNTIME_LIB_NAME})
417

418 419 420 421
      add_custom_command(
        OUTPUT ${PADDLE2ONNX_PYBIND_OUT}
        COMMAND ${CMAKE_COMMAND} -E copy ${PADDLE2ONNX_LIB}
                ${CMAKE_CURRENT_BINARY_DIR}
422 423 424 425
        DEPENDS paddle2onnx)
      list(APPEND OP_IMPL_DEPS ${PADDLE2ONNX_PYBIND_OUT})
      list(APPEND EAGER_OP_IMPL_DEPS ${PADDLE2ONNX_PYBIND_OUT})

426 427 428 429
      add_custom_command(
        OUTPUT ${ONNXRUNTIME_PYBIND_OUT}
        COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_LIB}
                ${CMAKE_CURRENT_BINARY_DIR}
430 431 432 433 434
        DEPENDS onnxruntime)
      list(APPEND OP_IMPL_DEPS ${ONNXRUNTIME_PYBIND_OUT})
      list(APPEND EAGER_OP_IMPL_DEPS ${ONNXRUNTIME_PYBIND_OUT})
    endif()

435
    if(WITH_MKLML)
436 437 438 439
      add_custom_command(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libiomp5.so
        COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_IOMP_LIB}
                ${CMAKE_CURRENT_BINARY_DIR}
440 441
        DEPENDS mklml)
      list(APPEND OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libiomp5.so)
442
      list(APPEND EAGER_OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libiomp5.so)
443 444
    endif()
    if(WITH_MKLDNN)
445 446 447 448
      add_custom_command(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libdnnl.so.0
        COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_SHARED_LIB}
                ${CMAKE_CURRENT_BINARY_DIR}
449 450
        DEPENDS mkldnn)
      list(APPEND OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libdnnl.so.0)
451
      list(APPEND EAGER_OP_IMPL_DEPS ${CMAKE_CURRENT_BINARY_DIR}/libdnnl.so.0)
452
    endif()
453
    if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
454 455 456 457
      add_custom_command(
        OUTPUT ${eager_impl_file}
        COMMAND
          ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:."
458
          "${CMAKE_CURRENT_BINARY_DIR}/eager_legacy_op_function_generator"
459 460 461 462 463 464 465
          "${tmp_eager_impl_file}"
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_eager_impl_file}
                ${eager_impl_file}
        COMMENT "copy_if_different ${tmp_eager_impl_file} to ${eager_impl_file}"
        DEPENDS ${EAGER_OP_IMPL_DEPS}
        VERBATIM)
    endif()
466
  endif()
467
  if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
468
    add_custom_target(eager_legacy_op_function_generator_cmd ALL
469
                      DEPENDS ${eager_impl_file})
470
  endif()
L
Leo Chen 已提交
471

472
  list(APPEND PYBIND_DEPS standalone_executor staticgraph_executor_statistics)
473

474
  if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
475 476 477 478 479 480
    set(PYBIND_SRCS eager.cc ${PYBIND_SRCS})
    set(PYBIND_SRCS eager_functions.cc ${PYBIND_SRCS})
    set(PYBIND_SRCS eager_method.cc ${PYBIND_SRCS})
    set(PYBIND_SRCS eager_properties.cc ${PYBIND_SRCS})
    set(PYBIND_SRCS eager_utils.cc ${PYBIND_SRCS})
    set(PYBIND_SRCS eager_py_layer.cc ${PYBIND_SRCS})
481
    set(PYBIND_SRCS eager_legacy_op_function.cc ${PYBIND_SRCS})
482
    set(PYBIND_SRCS eager_op_function.cc ${PYBIND_SRCS})
483
    set(PYBIND_SRCS eager_math_op_patch.cc ${PYBIND_SRCS})
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
    list(APPEND PYBIND_DEPS eager_api)
    list(APPEND PYBIND_DEPS autograd_meta)
    list(APPEND PYBIND_DEPS backward)
    list(APPEND PYBIND_DEPS grad_node_info)
    list(APPEND PYBIND_DEPS phi)
    list(APPEND PYBIND_DEPS final_dygraph_function)
    list(APPEND PYBIND_DEPS final_dygraph_node)
    list(APPEND PYBIND_DEPS dygraph_function)
    list(APPEND PYBIND_DEPS dygraph_node)
    list(APPEND PYBIND_DEPS accumulation_node)
    list(APPEND PYBIND_DEPS py_layer_node)
    list(APPEND PYBIND_DEPS global_utils)
    list(APPEND PYBIND_DEPS utils)
    list(APPEND PYBIND_DEPS python)
    list(APPEND PYBIND_DEPS custom_operator)
    list(APPEND PYBIND_DEPS custom_operator_node)
500 501 502 503
    list(APPEND PYBIND_DEPS operants_manager)
    list(APPEND PYBIND_DEPS eager_tensor_operants)
    list(APPEND PYBIND_DEPS static_tensor_operants)
    list(APPEND PYBIND_DEPS phi_tensor_operants)
504
  endif()
505

506 507 508 509 510 511 512 513
  # On Linux, cc_library(paddle SHARED ..) will generate the libpaddle.so,
  # add a prefix `lib` by default, but on Windows, cc_library(paddle SHARED ..)
  # will not add prefix, so it generate paddle.lib and paddle.pyd,
  # we need to pay attention to the difference
  set(SHARD_LIB_NAME paddle)
  if(WIN32)
    set(SHARD_LIB_NAME libpaddle)
  endif()
514
  set_property(GLOBAL PROPERTY PADDLE_LIB_NAME ${SHARD_LIB_NAME})
515
  cc_library(
516
    ${SHARD_LIB_NAME} SHARED
517
    SRCS ${PYBIND_SRCS}
518
    DEPS ${PYBIND_DEPS} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})
519

520 521 522 523 524 525 526 527
  # TODO(zhiqiu): some symbols not exported even setting the following
  # property. Need to find a better way.

  # if(WIN32)
  #   set_property(TARGET ${SHARD_LIB_NAME}
  #                PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
  # endif()

528
  if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
529 530
    add_dependencies(${SHARD_LIB_NAME} legacy_eager_codegen)
    add_dependencies(${SHARD_LIB_NAME} eager_legacy_op_function_generator_cmd)
531 532
  endif()

533
  if(NOT APPLE AND NOT WIN32)
534
    target_link_libraries(${SHARD_LIB_NAME} rt)
535
  endif()
536 537

  if(WITH_ROCM)
538
    target_link_libraries(${SHARD_LIB_NAME} ${ROCM_HIPRTC_LIB})
539
  endif()
540

W
wuhuachaocoding 已提交
541
  if(WITH_MPI)
542
    target_link_libraries(${SHARD_LIB_NAME} ${MPI_CXX_LIBRARIES})
W
wuhuachaocoding 已提交
543 544
  endif()

545
  get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
546
  target_link_libraries(${SHARD_LIB_NAME} ${os_dependency_modules})
547

548
endif()