CMakeLists.txt 6.0 KB
Newer Older
X
Xin Pan 已提交
1
file(GLOB UTILS_PY_FILES . ./paddle/legacy/utils/*.py)
2
file(GLOB_RECURSE FLUID_PY_FILES ./paddle/fluid/*.py)
3
set(PY_FILES paddle/__init__.py ${UTILS_PY_FILES} ${FLUID_PY_FILES})
H
Helin Wang 已提交
4

T
typhoonzero 已提交
5
if(WITH_GPU)
6
  set(PACKAGE_NAME "paddlepaddle-gpu")
7
elseif(WITH_MLU)
8
  set(PACKAGE_NAME "paddlepaddle-mlu")
9
elseif(WITH_ROCM)
10
  set(PACKAGE_NAME "paddlepaddle-rocm")
11
elseif(WITH_ASCEND_CL)
12
  set(PACKAGE_NAME "paddlepaddle-npu")
13
elseif(WITH_XPU)
14
  set(PACKAGE_NAME "paddlepaddle-xpu")
15
elseif(WITH_IPU)
16
  set(PACKAGE_NAME "paddlepaddle-ipu")
T
typhoonzero 已提交
17
else()
18
  set(PACKAGE_NAME "paddlepaddle")
T
typhoonzero 已提交
19 20
endif()

21 22
set(SETUP_LOG_FILE "setup.py.log")

23
set(FLUID_CORE_NAME "libpaddle")
24

R
risemeup1 已提交
25 26 27 28 29 30 31
if(WITH_SETUP_INSTALL)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/env_dict.py.in
                 ${CMAKE_CURRENT_BINARY_DIR}/env_dict.py)
else()
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
                 ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
endif()
32 33 34

set(FLUID_DST_DIR ${PADDLE_BINARY_DIR}/python/paddle/fluid/)

35 36 37 38 39 40
if(WIN32)
  # Python would use the .pyd by default under Windows series platform
  set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd)
  set(FLUID_CORE_LIB ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.lib)
  add_custom_command(
    OUTPUT ${FLUID_CORE}
41 42 43
    COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE}
    COMMAND cmake -E copy $<TARGET_LINKER_FILE:libpaddle> ${FLUID_CORE_LIB}
    DEPENDS libpaddle)
44 45 46 47
else()
  set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so)
  add_custom_command(
    OUTPUT ${FLUID_CORE}
48 49
    COMMAND cmake -E copy $<TARGET_FILE:paddle> ${FLUID_CORE}
    DEPENDS paddle)
50
endif()
51 52 53

set(FLUID_CORE_DEPS ${FLUID_CORE})

54
add_custom_target(copy_libpaddle ALL DEPENDS ${FLUID_CORE_DEPS})
55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
# Standard op(phi op) description is defined in ops.yaml and legacy_ops.yaml.
# When users define composite rules of some nonbasic op, as for defination of args,
# they are supposed to refer to standard op description. However, there exists
# some gap of description between current op and standard ones. So special dictionary
# is needed to record such gap for execution of composite rules.
# Todo: this custom_target will be moved to other place.

set(ops_yaml_path "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/ops.yaml")

set(ops_legacy_yaml_path
    "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_ops.yaml")

set(ops_compat_yaml_path
    "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml")

set(phi_ops_map_path
    "${PADDLE_SOURCE_DIR}/python/paddle/incubate/autograd/phi_ops_map.py")

add_custom_target(
  op_map_codegen ALL
  COMMAND
    "${PYTHON_EXECUTABLE}"
    "${PADDLE_SOURCE_DIR}/python/paddle/incubate/autograd/generate_op_map.py"
    "--ops_yaml_path=${ops_yaml_path}"
    "--ops_legacy_yaml_path=${ops_legacy_yaml_path}"
    "--ops_compat_yaml_path=${ops_compat_yaml_path}"
    "--phi_ops_map_path=${phi_ops_map_path}"
  VERBATIM)

85 86 87 88 89 90 91 92 93 94
# NOTE(zhiqiu): WHY?
# In `setup.py.in`, some dynamic libraries (eg, libxpuapi.so) are modified using
# patchelf. In rare cases, if the a linker is linking that dynamic library for
# some executables at the same time, a `file not recognized, file truncated`
# error may occur, result in the compilation error.
# So, add dependency to force the cpp tests built before running `setup.py.in`.
if(WITH_TESTING)
  add_dependencies(copy_libpaddle build_tests)
endif()

95
if(WIN32)
R
risemeup1 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  if(WITH_SETUP_INSTALL)
    add_custom_command(
      OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
      COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/python/paddle
        ${PADDLE_BINARY_DIR}/python/paddle/
      COMMENT "Packing whl packages------>>>"
      DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
              pass_desc_py_proto ${PY_FILES})
  else()
    add_custom_command(
      OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
      COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/python/paddle
        ${PADDLE_BINARY_DIR}/python/paddle/
      COMMAND ${CMAKE_COMMAND} -E env ${py_env} ${PYTHON_EXECUTABLE} setup.py
              bdist_wheel
      COMMENT "Packing whl packages------>>>"
      DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
              pass_desc_py_proto ${PY_FILES})
  endif()
117
else()
R
risemeup1 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  if(WITH_SETUP_INSTALL)
    add_custom_command(
      OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
      COMMAND touch stub.cc
      COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle
              ${PADDLE_BINARY_DIR}/python
      COMMENT "Packing whl packages------>>>"
      DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
              pass_desc_py_proto ${PY_FILES})
  else()
    add_custom_command(
      OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
      COMMAND touch stub.cc
      COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle
              ${PADDLE_BINARY_DIR}/python
      COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
      COMMENT "Packing whl packages------>>>"
      DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
              pass_desc_py_proto ${PY_FILES})
  endif()
138
endif()
Z
zhangjinchao01 已提交
139

140 141
add_custom_target(paddle_python ALL
                  DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp)
Z
zhangjinchao01 已提交
142

Y
Yu Yang 已提交
143 144
set(PADDLE_PYTHON_PACKAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dist/)

145
if(WITH_TESTING)
146 147
  add_subdirectory(paddle/reader/tests)
  add_subdirectory(paddle/dataset/tests)
148
  add_subdirectory(paddle/tests)
L
Luo Tao 已提交
149
  add_subdirectory(paddle/fluid/tests)
150
  add_subdirectory(paddle/fluid/contrib/tests)
151
  add_subdirectory(paddle/static/quantization/tests)
152
endif()
R
risemeup1 已提交
153 154 155 156 157

if(NOT WITH_SETUP_INSTALL)
  install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR}
          DESTINATION opt/paddle/share/wheels)
endif()
158

159 160 161 162 163
if(APPLE)
  find_program(INSTALL_NAME_TOOL_EXECUTABLE install_name_tool)
  if(NOT INSTALL_NAME_TOOL_EXECUTABLE)
    message(FATAL_ERROR "install_name_tool not found, please check.\n")
  endif()
D
dzhwinter 已提交
164
endif()
165 166 167
if(LINUX
   AND NOT WITH_SW
   AND NOT WITH_ARM)
168 169
  find_program(PATCHELF_EXECUTABLE patchelf)
  if(NOT PATCHELF_EXECUTABLE)
170 171 172
    message(
      FATAL_ERROR "patchelf not found, please install it.\n"
                  "For Ubuntu, the command is: apt-get install -y patchelf.")
173
  endif()
W
Wilber 已提交
174
endif()