CMakeLists.txt 11.1 KB
Newer Older
1 2
add_subdirectory(utils)

3 4 5 6
if(WITH_GPU)
  nv_library(
    phi_tensor_raw
    SRCS tensor.cc
7
    DEPS tensor_base dense_tensor phi_api_utils phi_enforce context_pool)
8 9 10 11
elseif(WITH_ROCM)
  hip_library(
    phi_tensor_raw
    SRCS tensor.cc
12
    DEPS tensor_base dense_tensor phi_api_utils phi_enforce context_pool)
13
else()
14 15 16
  cc_library(
    phi_tensor_raw
    SRCS tensor.cc
17
    DEPS tensor_base dense_tensor phi_api_utils phi_enforce context_pool)
18 19
endif()

20
set(api_gen_base ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/api_base.py)
21

22
# forward api file
23
set(api_gen_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/api_gen.py)
C
Chen Weihang 已提交
24
set(api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/ops.yaml)
Z
zyfncg 已提交
25
set(legacy_api_yaml_file
C
Chen Weihang 已提交
26
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_ops.yaml)
27 28
set(api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/api.h)
set(api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/api.cc)
29 30 31
set(api_header_file_tmp ${api_header_file}.tmp)
set(api_source_file_tmp ${api_source_file}.tmp)

32
# backward api file
33
set(bw_api_gen_file
34 35
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/backward_api_gen.py)
set(bw_api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/backward.yaml)
Z
zyfncg 已提交
36
set(legacy_bw_api_yaml_file
37
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_backward.yaml)
38 39
set(bw_api_header_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/backward_api.h)
40
set(bw_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/backward_api.cc)
41 42 43
set(bw_api_header_file_tmp ${bw_api_header_file}.tmp)
set(bw_api_source_file_tmp ${bw_api_source_file}.tmp)

44
# dygraph(intermediate) api file
45
set(im_api_gen_file
46
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/intermediate_api_gen.py)
47 48 49 50
set(dygraph_api_header_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.h)
set(dygraph_api_source_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.cc)
51 52 53
set(dygraph_api_header_file_tmp ${dygraph_api_header_file}.tmp)
set(dygraph_api_source_file_tmp ${dygraph_api_source_file}.tmp)

54
# sparse api file
55
set(sparse_api_gen_file
56
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/sparse_api_gen.py)
57
set(sparse_api_yaml_file
C
Chen Weihang 已提交
58
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_ops.yaml)
59 60
set(sparse_api_header_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/sparse_api.h)
61
set(sparse_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_api.cc)
62 63 64 65
set(sparse_api_header_file_tmp ${sparse_api_header_file}.tmp)
set(sparse_api_source_file_tmp ${sparse_api_source_file}.tmp)

# sparse bw api file
66
set(sparse_bw_api_gen_file
67
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/sparse_bw_api_gen.py)
68
set(sparse_bw_api_yaml_file
C
Chen Weihang 已提交
69
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_backward.yaml)
70 71 72 73
set(sparse_bw_api_header_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/sparse_bw_api.h)
set(sparse_bw_api_source_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_bw_api.cc)
74 75
set(sparse_bw_api_header_file_tmp ${sparse_bw_api_header_file}.tmp)
set(sparse_bw_api_source_file_tmp ${sparse_bw_api_source_file}.tmp)
76

J
Jack Zhou 已提交
77
# strings api file
78
set(strings_api_gen_file
79
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/strings_api_gen.py)
80
set(strings_api_yaml_file
C
Chen Weihang 已提交
81
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/strings_ops.yaml)
82 83 84 85
set(strings_api_header_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/strings_api.h)
set(strings_api_source_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/strings_api.cc)
J
Jack Zhou 已提交
86 87 88
set(strings_api_header_file_tmp ${strings_api_header_file}.tmp)
set(strings_api_source_file_tmp ${strings_api_source_file}.tmp)

89
# wrapped infermeta file
90
set(wrapped_infermeta_gen_file
91
    ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/wrapped_infermeta_gen.py)
92 93 94 95
set(wrapped_infermeta_header_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.h)
set(wrapped_infermeta_source_file
    ${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.cc)
96

97
if(NOT PYTHONINTERP_FOUND)
98 99 100
  find_package(PythonInterp REQUIRED)
endif()

101
# generate forward api
102
add_custom_command(
103
  OUTPUT ${api_header_file} ${api_source_file}
104
  COMMAND ${PYTHON_EXECUTABLE} -m pip install pyyaml
105 106
  COMMAND
    ${PYTHON_EXECUTABLE} ${api_gen_file} --api_yaml_path ${api_yaml_file}
Z
zyfncg 已提交
107
    ${legacy_api_yaml_file} --api_header_path ${api_header_file_tmp}
108 109 110 111 112 113
    --api_header_path ${api_header_file_tmp} --api_source_path
    ${api_source_file_tmp}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${api_header_file_tmp}
          ${api_header_file}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${api_source_file_tmp}
          ${api_source_file}
114
  COMMENT "copy_if_different ${api_header_file} ${api_source_file}"
115 116
  DEPENDS ${api_yaml_file} ${legacy_api_yaml_file} ${api_gen_file}
          ${api_gen_base}
117 118
  VERBATIM)

119 120
# generate backward api
add_custom_command(
121 122 123 124
  OUTPUT ${bw_api_header_file} ${bw_api_source_file} ${bw_api_header_file_tmp}
         ${bw_api_source_file_tmp}
  COMMAND
    ${PYTHON_EXECUTABLE} ${bw_api_gen_file} --backward_yaml_path
Z
zyfncg 已提交
125
    ${bw_api_yaml_file} ${legacy_bw_api_yaml_file} --backward_header_path
126 127 128 129 130
    ${bw_api_header_file_tmp} --backward_source_path ${bw_api_source_file_tmp}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${bw_api_header_file_tmp}
          ${bw_api_header_file}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${bw_api_source_file_tmp}
          ${bw_api_source_file}
131
  COMMENT "copy_if_different ${bw_api_header_file} ${bw_api_source_file}"
132 133
  DEPENDS ${bw_api_yaml_file} ${bw_api_gen_file} ${api_gen_base}
          ${legacy_bw_api_yaml_file}
134 135
  VERBATIM)

136 137 138
# generate sparse api
add_custom_command(
  OUTPUT ${sparse_api_header_file} ${sparse_api_source_file}
139 140 141 142 143 144 145 146 147 148 149 150
  COMMAND
    ${PYTHON_EXECUTABLE} ${sparse_api_gen_file} --api_yaml_path
    ${sparse_api_yaml_file} --api_header_path ${sparse_api_header_file_tmp}
    --api_source_path ${sparse_api_source_file_tmp}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_api_header_file_tmp}
          ${sparse_api_header_file}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_api_source_file_tmp}
          ${sparse_api_source_file}
  COMMENT
    "copy_if_different ${sparse_api_header_file} ${sparse_sparse_api_source_file}"
  DEPENDS ${sparse_api_yaml_file} ${sparse_api_gen_file} ${api_gen_base}
          ${api_gen_file}
151 152 153 154 155
  VERBATIM)

# generate backward sparse api
add_custom_command(
  OUTPUT ${sparse_bw_api_header_file} ${sparse_bw_api_source_file}
156 157 158 159 160 161 162 163 164 165 166 167 168
  COMMAND
    ${PYTHON_EXECUTABLE} ${sparse_bw_api_gen_file} --api_yaml_path
    ${sparse_bw_api_yaml_file} --api_header_path
    ${sparse_bw_api_header_file_tmp} --api_source_path
    ${sparse_bw_api_source_file_tmp}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_bw_api_header_file_tmp}
          ${sparse_bw_api_header_file}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sparse_bw_api_source_file_tmp}
          ${sparse_bw_api_source_file}
  COMMENT
    "copy_if_different ${sparse_bw_api_header_file} ${sparse_bw_sparse_api_source_file}"
  DEPENDS ${sparse_bw_api_yaml_file} ${sparse_bw_api_gen_file} ${api_gen_base}
          ${api_gen_file} ${sparse_api_gen_file} ${bw_api_gen_file}
169 170
  VERBATIM)

J
Jack Zhou 已提交
171 172 173
# generate strings api
add_custom_command(
  OUTPUT ${strings_api_header_file} ${strings_api_source_file}
174 175 176 177 178 179 180 181 182 183 184 185
  COMMAND
    ${PYTHON_EXECUTABLE} ${strings_api_gen_file} --api_yaml_path
    ${strings_api_yaml_file} --api_header_path ${strings_api_header_file_tmp}
    --api_source_path ${strings_api_source_file_tmp}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${strings_api_header_file_tmp}
          ${strings_api_header_file}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${strings_api_source_file_tmp}
          ${strings_api_source_file}
  COMMENT
    "copy_if_different ${strings_api_header_file} ${strings_strings_api_source_file}"
  DEPENDS ${strings_api_yaml_file} ${strings_api_gen_file} ${api_gen_base}
          ${api_gen_file}
J
Jack Zhou 已提交
186 187
  VERBATIM)

188 189 190
# generate dygraph(intermediate) api
add_custom_command(
  OUTPUT ${dygraph_api_header_file} ${dygraph_api_source_file}
191 192
  COMMAND
    ${PYTHON_EXECUTABLE} ${im_api_gen_file} --api_yaml_path ${api_yaml_file}
Z
zyfncg 已提交
193
    ${legacy_api_yaml_file} --sparse_api_yaml_path ${sparse_api_yaml_file}
194 195 196 197 198 199
    --dygraph_api_header_path ${dygraph_api_header_file_tmp}
    --dygraph_api_source_path ${dygraph_api_source_file_tmp}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dygraph_api_header_file_tmp}
          ${dygraph_api_header_file}
  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${dygraph_api_source_file_tmp}
          ${dygraph_api_source_file}
200 201
  DEPENDS ${api_yaml_file} ${legacy_api_yaml_file} ${sparse_api_yaml_file}
          ${im_api_gen_file} ${api_gen_base} ${api_gen_file}
202 203
  VERBATIM)

204 205 206
# generate wrapped infermeta
add_custom_command(
  OUTPUT ${wrapped_infermeta_header_file} ${wrapped_infermeta_source_file}
207 208
  COMMAND
    ${PYTHON_EXECUTABLE} ${wrapped_infermeta_gen_file} --api_yaml_path
Z
zyfncg 已提交
209
    ${api_yaml_file} ${legacy_api_yaml_file} --wrapped_infermeta_header_path
210 211
    ${wrapped_infermeta_header_file} --wrapped_infermeta_source_path
    ${wrapped_infermeta_source_file}
Z
zyfncg 已提交
212 213
  DEPENDS ${api_yaml_file} ${legacy_api_yaml_file} ${wrapped_infermeta_gen_file}
          ${api_gen_base}
214 215
  VERBATIM)

216 217 218 219 220 221 222 223 224 225 226
cc_library(
  op_meta_info
  SRCS op_meta_info.cc
  DEPS phi_tensor_raw)
cc_library(
  wrapped_infermeta
  SRCS ${wrapped_infermeta_source_file}
  DEPS phi)
cc_library(
  context_pool
  SRCS context_pool.cc
227
  DEPS phi_backends phi_enforce place init)
228

229 230 231
cc_library(
  kernel_dispatch
  SRCS kernel_dispatch.cc
232
  DEPS phi_tensor_raw phi_backends kernel_factory context_pool)
233 234 235
cc_library(
  api_gen_utils
  SRCS api_gen_utils.cc
236 237
  DEPS phi_tensor_raw selected_rows sparse_csr_tensor sparse_coo_tensor
       infermeta_utils)
238 239 240
cc_library(
  phi_data_transform
  SRCS data_transform.cc
241
  DEPS phi_tensor_raw phi tensor)
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
cc_library(
  api_custom_impl
  SRCS api_custom_impl.cc
  DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils backward_infermeta
       phi_data_transform)
cc_library(
  phi_function_api
  SRCS ${api_source_file}
  DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils phi_data_transform
       api_custom_impl)
cc_library(
  phi_bw_function_api
  SRCS ${bw_api_source_file}
  DEPS phi_tensor_raw
       phi
       kernel_dispatch
       api_gen_utils
       backward_infermeta
Z
zhangkaihuo 已提交
260
       sparse_backward_infermeta
261 262 263 264 265 266 267
       phi_data_transform
       phi_function_api
       api_custom_impl
       global_utils)
cc_library(
  sparse_api
  SRCS ${sparse_api_source_file}
268
  DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils)
269 270 271
cc_library(
  sparse_bw_api
  SRCS ${sparse_bw_api_source_file}
Z
zhangkaihuo 已提交
272 273
  DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils sparse_api
       sparse_backward_infermeta)
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
cc_library(
  phi_dygraph_api
  SRCS ${dygraph_api_source_file}
  DEPS phi_tensor_raw
       phi
       kernel_dispatch
       api_gen_utils
       phi_data_transform
       phi_function_api
       sparse_api)
cc_library(
  strings_api
  SRCS ${strings_api_source_file}
  DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils)
cc_library(
  phi_tensor
  SRCS tensor_method.cc
  DEPS phi_tensor_raw
       phi_function_api
       api_gen_utils
       kernel_dispatch
       infermeta
Z
zhangkaihuo 已提交
296
       sparse_infermeta
297 298 299 300 301
       sparse_api
       strings_api)
cc_library(
  tensor_copy
  SRCS tensor_copy.cc
302
  DEPS phi_tensor_raw phi kernel_dispatch api_gen_utils)
303 304 305 306 307 308 309 310
cc_library(
  api_scalar
  SRCS scalar.cc
  DEPS tensor_copy)
cc_library(
  api_int_array
  SRCS int_array.cc
  DEPS tensor_copy)