CMakeLists.txt 4.2 KB
Newer Older
L
Leo Chen 已提交
1 2
include(ExternalProject)

3
set(ALLOCATOR_DEPS place stats profiler phi_backends device_context)
L
Leo Chen 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
set(ALLOCATOR_SRCS
    allocator.cc
    cpu_allocator.cc
    locked_allocator.cc
    aligned_allocator.cc
    buffered_allocator.cc
    best_fit_allocator.cc
    naive_best_fit_allocator.cc
    allocator_strategy.cc
    allocator_facade.cc
    auto_growth_best_fit_allocator.cc
    virtual_memory_auto_growth_best_fit_allocator.cc
    retry_allocator.cc
    memory_block.cc
    memory_block_desc.cc
    meta_cache.cc
    buddy_allocator.cc
    system_allocator.cc)
22

L
Leo Chen 已提交
23 24 25 26 27 28 29 30 31 32
if(WITH_GPU OR WITH_ROCM)
  list(
    APPEND
    ALLOCATOR_SRCS
    cuda_allocator.cc
    cuda_managed_allocator.cc
    pinned_allocator.cc
    stream_safe_cuda_allocator.cc
    thread_local_allocator.cc)
  list(APPEND ALLOCATOR_DEPS cuda_device_guard gpu_info dynload_cuda)
33 34
endif()

35
if(WITH_GPU)
L
Leo Chen 已提交
36 37
  list(APPEND ALLOCATOR_DEPS cuda_graph)
endif()
38

L
Leo Chen 已提交
39 40 41 42 43 44 45 46
if(CUDA_VERSION VERSION_GREATER_EQUAL 10.2)
  list(APPEND ALLOCATOR_SRCS cuda_virtual_mem_allocator.cc)
endif()

if(NOT WIN32)
  list(APPEND ALLOCATOR_SRCS mmap_allocator.cc)
  if(WITH_GPU)
    list(APPEND ALLOCATOR_SRCS cuda_ipc_allocator.cc)
47
  endif()
48 49
endif()

L
Leo Chen 已提交
50 51 52 53
if(WITH_ASCEND_CL)
  list(APPEND ALLOCATOR_SRCS npu_allocator.cc npu_pinned_allocator.cc)
  list(APPEND ALLOCATOR_DEPS npu_info)
endif()
54

L
Leo Chen 已提交
55 56
if(WITH_CUSTOM_DEVICE)
  list(APPEND ALLOCATOR_SRCS custom_allocator.cc)
S
sneaxiy 已提交
57
endif()
58

L
Leo Chen 已提交
59 60
if(WITH_XPU)
  list(APPEND ALLOCATOR_DEPS xpu_info)
61 62
endif()

L
Leo Chen 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
if(WITH_IPU)
  list(APPEND ALLOCATOR_DEPS ipu_info)
endif()

add_library(allocator "${ALLOCATOR_SRCS}")
target_link_libraries(allocator ${ALLOCATOR_DEPS})
# note: why only add dependency for framework_proto.
# Because it is needed to generate framework.pb.h used in some header files.
add_dependencies(allocator framework_proto)
set_property(GLOBAL PROPERTY FLUID_MODULES allocator)

cc_test(
  naive_best_fit_allocator_test
  SRCS naive_best_fit_allocator_test.cc
  DEPS allocator)
cc_test(
  buffered_allocator_test
  SRCS buffered_allocator_test.cc
81
  DEPS allocator)
S
sneaxiy 已提交
82

L
Leo Chen 已提交
83 84 85 86 87
if(WITH_GPU)
  nv_test(
    thread_local_allocator_test
    SRCS thread_local_allocator_test.cc
    DEPS allocator)
88
endif()
L
Leo Chen 已提交
89 90 91 92 93
if(WITH_ROCM)
  hip_test(
    thread_local_allocator_test
    SRCS thread_local_allocator_test.cc
    DEPS allocator)
94 95
endif()

96 97 98 99
if(WITH_GPU)
  nv_test(
    best_fit_allocator_test
    SRCS best_fit_allocator_test.cc best_fit_allocator_test.cu
L
Leo Chen 已提交
100
    DEPS allocator memcpy)
101 102 103 104
elseif(WITH_ROCM)
  hip_test(
    best_fit_allocator_test
    SRCS best_fit_allocator_test.cc best_fit_allocator_test.cu
L
Leo Chen 已提交
105
    DEPS allocator memcpy)
106
else()
107 108 109
  cc_test(
    best_fit_allocator_test
    SRCS best_fit_allocator_test.cc
L
Leo Chen 已提交
110
    DEPS allocator)
111 112
endif()

113 114 115
cc_test(
  test_aligned_allocator
  SRCS test_aligned_allocator.cc
L
Leo Chen 已提交
116
  DEPS allocator)
Y
Yu Yang 已提交
117

118 119 120
cc_test(
  retry_allocator_test
  SRCS retry_allocator_test.cc
L
Leo Chen 已提交
121 122 123 124
  DEPS allocator)
if(TEST retry_allocator_test)
  set_tests_properties(retry_allocator_test PROPERTIES LABELS
                                                       "RUN_TYPE=EXCLUSIVE")
Z
Zeng Jinle 已提交
125 126
endif()

127 128 129
cc_test(
  allocator_facade_abs_flags_test
  SRCS allocator_facade_abs_flags_test.cc
L
Leo Chen 已提交
130
  DEPS allocator)
S
sneaxiy 已提交
131

132 133 134
cc_test(
  allocator_facade_frac_flags_test
  SRCS allocator_facade_frac_flags_test.cc
L
Leo Chen 已提交
135
  DEPS allocator)
136

137 138 139
cc_test(
  auto_growth_best_fit_allocator_facade_test
  SRCS auto_growth_best_fit_allocator_facade_test.cc
L
Leo Chen 已提交
140
  DEPS allocator)
141 142 143
cc_test(
  auto_growth_best_fit_allocator_test
  SRCS auto_growth_best_fit_allocator_test.cc
L
Leo Chen 已提交
144
  DEPS allocator)
145

146
if(NOT WIN32)
147 148 149
  cc_test(
    mmap_allocator_test
    SRCS mmap_allocator_test.cc
L
Leo Chen 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    DEPS allocator)
endif()

cc_test(
  system_allocator_test
  SRCS system_allocator_test.cc
  DEPS allocator)

cc_test(
  buddy_allocator_test
  SRCS buddy_allocator_test.cc
  DEPS allocator)

if(WITH_TESTING)
  if(TEST buddy_allocator_test)
    set_tests_properties(buddy_allocator_test PROPERTIES LABELS
                                                         "RUN_TYPE=EXCLUSIVE")
  endif()

  # TODO(zhiqiu): why not win32? because wget is not found on windows
  if(NOT WIN32)
    add_custom_target(
      download_data
D
danleifeng 已提交
173
      COMMAND wget -nc --no-check-certificate
L
Leo Chen 已提交
174 175 176
              https://paddle-ci.cdn.bcebos.com/buddy_allocator_test_data.tar
      COMMAND tar -xf buddy_allocator_test_data.tar)
    add_dependencies(buddy_allocator_test download_data)
177
  endif()
W
Wilber 已提交
178
endif()