CMakeLists.txt 10.0 KB
Newer Older
1 2
proto_library(profiler_proto SRCS profiler.proto DEPS framework_proto
              simple_threadpool)
3
if(WITH_GPU)
4
  proto_library(external_error_proto SRCS external_error.proto)
5
endif()
6
if(WITH_PYTHON)
7
  py_proto_compile(profiler_py_proto SRCS profiler.proto)
8 9
  add_custom_target(profiler_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E
                                                       touch __init__.py)
10 11
  add_dependencies(profiler_py_proto profiler_py_proto_init)

12 13 14 15 16 17 18 19 20 21
  if(NOT WIN32)
    add_custom_command(
      TARGET profiler_py_proto
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E make_directory
              ${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/profiler
      COMMAND cp *.py ${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/profiler
      COMMENT
        "Copy generated python proto into directory paddle/fluid/proto/profiler."
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
22
  else()
23 24 25 26 27 28 29 30 31 32 33
    string(REPLACE "/" "\\" proto_dstpath
                   "${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/profiler/")
    add_custom_command(
      TARGET profiler_py_proto
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E make_directory
              ${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/profiler
      COMMAND copy /Y *.py ${proto_dstpath}
      COMMENT
        "Copy generated python proto into directory paddle/fluid/proto/profiler."
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
34
  endif()
35
endif()
36

37 38 39
cc_library(
  flags
  SRCS flags.cc
R
Ruibiao Chen 已提交
40
  DEPS gflags)
41 42 43 44
cc_library(
  denormal
  SRCS denormal.cc
  DEPS)
45

46 47 48 49
cc_test(
  errors_test
  SRCS errors_test.cc
  DEPS errors enforce)
50

R
Ruibiao Chen 已提交
51
set(enforce_deps flags errors flags phi_enforce)
52
if(WITH_GPU)
53
  set(enforce_deps ${enforce_deps} external_error_proto)
54
endif()
F
fwenguang 已提交
55

56 57 58 59
cc_library(
  enforce INTERFACE
  SRCS enforce.cc
  DEPS ${enforce_deps})
H
hutuxian 已提交
60
cc_library(monitor SRCS monitor.cc)
61 62 63 64
cc_test(
  enforce_test
  SRCS enforce_test.cc
  DEPS stringpiece enforce)
Q
Qiao Longfei 已提交
65

T
tensor-tang 已提交
66
set(CPU_INFO_DEPS gflags glog enforce)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
if(WITH_XBYAK)
  list(APPEND CPU_INFO_DEPS xbyak)
endif()
cc_library(
  cpu_info
  SRCS cpu_info.cc
  DEPS ${CPU_INFO_DEPS})
cc_test(
  cpu_info_test
  SRCS cpu_info_test.cc
  DEPS cpu_info)
cc_library(
  os_info
  SRCS os_info.cc
  DEPS enforce)
cc_test(
  os_info_test
  SRCS os_info_test.cc
  DEPS os_info)

if(WITH_GPU)
  nv_library(
    cuda_graph_with_memory_pool
    SRCS cuda_graph_with_memory_pool.cc
L
Leo Chen 已提交
91
    DEPS device_context allocator cuda_graph)
92 93 94 95
else()
  cc_library(
    cuda_graph_with_memory_pool
    SRCS cuda_graph_with_memory_pool.cc
L
Leo Chen 已提交
96
    DEPS device_context allocator)
97 98 99 100 101
endif()

cc_library(
  place
  SRCS place.cc
R
Ruibiao Chen 已提交
102
  DEPS enforce phi_place)
103 104 105 106 107 108 109 110 111 112
cc_test(
  place_test
  SRCS place_test.cc
  DEPS place glog gflags)

if(WITH_MKLDNN)
  set(MKLDNN_CTX_DEPS mkldnn)
else()
  set(MKLDNN_CTX_DEPS)
endif()
113

114
add_subdirectory(device)
L
liaogang 已提交
115
add_subdirectory(dynload)
116
add_subdirectory(stream)
L
liaogang 已提交
117

118 119 120 121 122 123 124 125
cc_library(
  cpu_helper
  SRCS cpu_helper.cc
  DEPS cblas enforce)
cc_test(
  cpu_helper_test
  SRCS cpu_helper_test.cc
  DEPS cpu_helper)
T
tensor-tang 已提交
126

127
set(dgc_deps "")
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
if(WITH_DGC)
  set(dgc_deps dgc)
endif()

if(WITH_GPU OR WITH_ROCM)
  set(GPU_CTX_DEPS dynload_cuda dynamic_loader cuda_stream)
endif()

if(WITH_IPU)
  set(IPU_CTX_DEPS ipu_info)
else()
  set(IPU_CTX_DEPS)
endif(WITH_IPU)

if(WITH_ASCEND_CL)
  set(NPU_CTX_DEPS npu_stream npu_info)
endif()

if(WITH_MLU)
  set(MLU_CTX_DEPS mlu_device_context)
endif()

if(WITH_ASCEND_CL OR WITH_MLU)
  cc_library(
    stream_callback_manager
    SRCS stream_callback_manager.cc
    DEPS simple_threadpool enforce)
endif()

if(WITH_GPU)
  nv_library(
    stream_callback_manager
    SRCS stream_callback_manager.cc
    DEPS simple_threadpool enforce)
endif()
if(WITH_ROCM)
  hip_library(
    stream_callback_manager
    SRCS stream_callback_manager.cc
    DEPS simple_threadpool enforce)
endif()

if(WITH_GPU OR WITH_ROCM)
S
sneaxiy 已提交
171
  set(STREAM_CALLBACK_DEPS stream_callback_manager)
172
elseif(WITH_ASCEND_CL)
173
  set(STREAM_CALLBACK_DEPS stream_callback_manager)
174
else()
S
sneaxiy 已提交
175
  set(STREAM_CALLBACK_DEPS)
176
endif()
S
sneaxiy 已提交
177

178
if(WITH_GLOO)
179 180 181 182
  cc_library(
    gloo_context
    SRCS gloo_context.cc
    DEPS framework_proto gloo_wrapper enforce)
183 184
endif()

185 186 187
cc_library(
  cudnn_workspace_helper
  SRCS cudnn_workspace_helper.cc
R
Ruibiao Chen 已提交
188
  DEPS)
189

190
# separate init from device_context to avoid cycle dependencies
191 192 193 194
cc_library(
  init
  SRCS init.cc
  DEPS device_context custom_kernel context_pool)
195

196
# memcpy depends on device_context, here add deps individually for
Q
qijun 已提交
197
# avoiding cycle dependencies
198

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
cc_library(
  device_context
  SRCS device_context.cc
  DEPS simple_threadpool
       malloc
       xxhash
       ${STREAM_CALLBACK_DEPS}
       place
       phi_place
       eigen3
       stringpiece
       cpu_helper
       cpu_info
       framework_proto
       ${IPU_CTX_DEPS}
       ${GPU_CTX_DEPS}
       ${NPU_CTX_DEPS}
       ${MKLDNN_CTX_DEPS}
       ${dgc_deps}
       dlpack
       cudnn_workspace_helper
       ${XPU_CTX_DEPS}
       ${MLU_CTX_DEPS}
       eigen3
223 224
       phi_backends
       phi_device_context
225
       generator)
226

227 228 229 230
cc_library(
  collective_helper
  SRCS collective_helper.cc gen_comm_id_helper.cc
  DEPS framework_proto device_context enforce)
231
if(WITH_ASCEND_CL)
232
  target_link_libraries(collective_helper npu_collective_helper)
233
endif()
234

235
if(WITH_CNCL)
236
  target_link_libraries(collective_helper mlu_collective_helper)
237 238
endif()

239
if(WITH_GPU OR WITH_ROCM)
240
  target_link_libraries(device_context gpu_resource_pool)
241
endif()
242

243
if(WITH_ASCEND_CL)
244
  target_link_libraries(device_context npu_resource_pool)
245 246
endif()

247 248
if(WITH_XPU)
  target_link_libraries(device_context xpu_resource_pool)
249 250
endif()

251 252
if(WITH_MLU)
  target_link_libraries(device_context mlu_resource_pool)
253 254
endif()

255 256 257 258
cc_test(
  init_test
  SRCS init_test.cc
  DEPS device_context)
259

260 261
# Manage all device event library
set(DEVICE_EVENT_LIBS)
262 263 264 265 266 267 268
cc_library(
  device_event_base
  SRCS device_event_base.cc
  DEPS place enforce device_context op_registry)
set(DEVICE_EVENT_LIBS
    device_event_base
    CACHE INTERNAL "device event libs")
269 270 271 272 273 274 275 276 277
if(WITH_XPU)
  cc_library(
    device_event_xpu
    SRCS device_event_xpu.cc
    DEPS device_event_base xpu_info)
  set(DEVICE_EVENT_LIBS
      device_event_xpu
      CACHE INTERNAL "device event libs")
endif()
278

279 280 281 282 283 284 285 286 287 288
if(WITH_ASCEND_CL)
  cc_library(
    device_event_npu
    SRCS device_event_npu.cc
    DEPS device_event_base npu_resource_pool)
  set(DEVICE_EVENT_LIBS
      device_event_npu
      CACHE INTERNAL "device event libs")
endif()

289
if(WITH_GPU)
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
  nv_library(
    device_event_gpu
    SRCS device_event_gpu.cc
    DEPS device_event_base)
  set(DEVICE_EVENT_LIBS
      device_event_gpu
      CACHE INTERNAL "device event libs")
  nv_test(
    device_event_test
    SRCS device_event_test.cc
    DEPS device_event_gpu)

  nv_test(
    device_context_test
    SRCS device_context_test.cu
    DEPS device_context gpu_info)
Y
Yuang Liu 已提交
306 307 308 309
  nv_test(
    device_context_test_cuda_graph
    SRCS device_context_test_cuda_graph.cu
    DEPS device_context gpu_info cuda_graph_with_memory_pool)
310 311 312 313
  nv_test(
    transform_test
    SRCS transform_test.cu
    DEPS memory place device_context)
314 315 316
endif()

if(WITH_ROCM)
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
  hip_library(
    device_event_gpu
    SRCS device_event_gpu.cc
    DEPS device_event_base)
  set(DEVICE_EVENT_LIBS
      device_event_gpu
      CACHE INTERNAL "device event libs")
  hip_test(
    device_event_test
    SRCS device_event_test.cc
    DEPS device_event_gpu)

  hip_test(
    device_context_test
    SRCS device_context_test.cu
    DEPS device_context gpu_info)
  hip_test(
    transform_test
    SRCS transform_test.cu
    DEPS memory place device_context)
337
endif()
D
dangqingqing 已提交
338

339
cc_library(timer SRCS timer.cc)
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
cc_test(
  timer_test
  SRCS timer_test.cc
  DEPS timer)

cc_library(
  lodtensor_printer
  SRCS lodtensor_printer.cc
  DEPS ddim
       place
       tensor
       scope
       lod_tensor
       variable_helper
       framework_proto)
cc_test(
  lodtensor_printer_test
  SRCS lodtensor_printer_test.cc
  DEPS lodtensor_printer)
D
dongdaxiang 已提交
359

L
liutiexing 已提交
360 361
add_subdirectory(profiler)

362 363 364
cc_library(
  device_tracer
  SRCS device_tracer.cc
R
Ruibiao Chen 已提交
365
  DEPS profiler_proto framework_proto ${GPU_CTX_DEPS})
366
if(WITH_GPU)
367 368 369 370 371 372 373 374 375
  nv_library(
    profiler
    SRCS profiler.cc profiler.cu
    DEPS os_info
         device_tracer
         gpu_info
         enforce
         dynload_cuda
         new_profiler
376 377 378
         stats
         op_proto_maker
         shape_inference)
379 380 381 382
  nv_library(
    device_memory_aligment
    SRCS device_memory_aligment.cc
    DEPS cpu_info gpu_info place)
383
elseif(WITH_ROCM)
384 385 386
  hip_library(
    profiler
    SRCS profiler.cc profiler.cu
387 388 389 390 391 392 393 394
    DEPS os_info
         device_tracer
         gpu_info
         enforce
         new_profiler
         stats
         op_proto_maker
         shape_inference)
395 396 397 398
  hip_library(
    device_memory_aligment
    SRCS device_memory_aligment.cc
    DEPS cpu_info gpu_info place)
399
else()
400 401 402
  cc_library(
    profiler
    SRCS profiler.cc
403 404 405 406 407 408 409
    DEPS os_info
         device_tracer
         enforce
         new_profiler
         stats
         op_proto_maker
         shape_inference)
410 411 412 413
  cc_library(
    device_memory_aligment
    SRCS device_memory_aligment.cc
    DEPS cpu_info place)
414
endif()
415

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
cc_test(
  profiler_test
  SRCS profiler_test.cc
  DEPS profiler)
cc_test(
  float16_test
  SRCS float16_test.cc
  DEPS lod_tensor)
cc_test(
  bfloat16_test
  SRCS bfloat16_test.cc
  DEPS lod_tensor)
cc_test(
  complex_test
  SRCS complex_test.cc
  DEPS lod_tensor)
432

433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
if(WITH_GPU)
  nv_test(
    float16_gpu_test
    SRCS float16_test.cu
    DEPS lod_tensor)
  nv_test(
    bfloat16_gpu_test
    SRCS bfloat16_test.cu
    DEPS lod_tensor)
  nv_test(
    complex_gpu_test
    SRCS complex_test.cu
    DEPS lod_tensor)
  nv_test(
    test_limit_gpu_memory
    SRCS test_limit_gpu_memory.cu
    DEPS gpu_info flags)
  nv_library(
    cuda_device_guard
    SRCS cuda_device_guard.cc
    DEPS gpu_info)
endif()
455

456 457 458 459 460 461 462 463 464 465 466 467 468 469
if(WITH_ROCM)
  hip_test(
    float16_gpu_test
    SRCS float16_test.cu
    DEPS lod_tensor)
  hip_test(
    test_limit_gpu_memory
    SRCS test_limit_gpu_memory.cu
    DEPS gpu_info flags)
  hip_library(
    cuda_device_guard
    SRCS cuda_device_guard.cc
    DEPS gpu_info)
endif()
470

471
if(NOT APPLE AND NOT WIN32)
472 473 474 475
  cc_library(
    device_code
    SRCS device_code.cc
    DEPS device_context)
476
  if(WITH_GPU OR WITH_ROCM)
477 478 479 480
    cc_test(
      device_code_test
      SRCS device_code_test.cc
      DEPS device_code lod_tensor)
481
  endif()
482
endif()