CMakeLists.txt 4.2 KB
Newer Older
1 2
configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)

3 4
# phi auto cmake utils
include(phi)
5

6 7 8 9 10 11 12 13 14
set(common_srcs CACHE INTERNAL "" FORCE)
set(api_srcs CACHE INTERNAL "" FORCE)
set(capi_srcs CACHE INTERNAL "" FORCE)
set(core_srcs CACHE INTERNAL "" FORCE)
set(backends_srcs CACHE INTERNAL "" FORCE)
set(kernels_srcs CACHE INTERNAL "" FORCE)
set(infermeta_srcs CACHE INTERNAL "" FORCE)
#set(excluded_srcs CACHE INTERNAL "" FORCE)

15 16 17
# paddle experimental common components
add_subdirectory(common)

18 19
# phi (low level) api headers: include
# phi (high level) api
20
add_subdirectory(api)
21
# phi core components
22
add_subdirectory(core)
23
# phi components of specific backends
C
Chen Weihang 已提交
24
add_subdirectory(backends)
25
# phi kernels for diff device
26
add_subdirectory(kernels)
27
# phi infermeta
C
Chen Weihang 已提交
28
add_subdirectory(infermeta)
29
# phi tools
30
add_subdirectory(tools)
31 32 33 34
# phi capi
if(WITH_CUSTOM_DEVICE)
  add_subdirectory(capi)
endif()
35

36
set(PHI_DEPS
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 171 172 173 174 175 176 177 178 179 180 181 182
    phi_profiler_proto
    auto_parallel_proto
    gflags
    glog
    warpctc
    warprnnt
    eigen3
    xxhash
    cblas
    utf8proc)

if(WITH_GPU)
  list(APPEND PHI_DEPS external_error_proto)
endif()

if(WITH_ASCEND_CL)
  list(APPEND PHI_DEPS npu_hccl)
endif()

if(WITH_FLASHATTN)
  list(APPEND PHI_DEPS flashattn)
endif()

if(WITH_XBYAK)
  list(APPEND PHI_DEPS xbyak)
endif()

if(WITH_MKLDNN)
  list(APPEND PHI_DEPS mkldnn)
endif()

if(WITH_GLOO)
  list(APPEND PHI_DEPS gloo)
endif()

if(WITH_CUDNN_FRONTEND)
  list(APPEND PHI_DEPS cudnn-frontend)
endif()

if(WITH_POCKETFFT)
  list(APPEND PHI_DEPS pocketfft)
endif()

if(WITH_MKLML)
  list(APPEND PHI_DEPS pocketfft dynload_mklml)
endif()

if(WITH_XPU)
  list(APPEND PHI_DEPS xpulib)
endif()

set(PHI_SRCS
    ${common_srcs}
    ${api_srcs}
    ${core_srcs}
    ${backends_srcs}
    ${kernels_srcs}
    ${infermeta_srcs}
    ${capi_srcs})

if(WITH_PHI_SHARED)
  set(PHI_BUILD_TYPE
      SHARED
      CACHE INTERNAL "" FORCE)
else()
  set(PHI_BUILD_TYPE
      STATIC
      CACHE INTERNAL "" FORCE)
endif()

if(WITH_GPU)
  add_definitions(-DCUDA_REAL_ARCHS=${NVCC_FLAGS_EXTRA_real_archs}
  )# for backends/gpu/gpu_resources.cc
  nv_library(
    phi ${PHI_BUILD_TYPE}
    SRCS ${PHI_SRCS}
    DEPS ${PHI_DEPS})
elseif(WITH_ROCM)
  hip_add_library(phi ${PHI_BUILD_TYPE} ${PHI_SRCS})
  target_link_libraries(phi ${PHI_DEPS})
elseif(WITH_XPU_KP)
  xpu_library(
    phi ${PHI_BUILD_TYPE}
    SRCS ${PHI_SRCS}
    DEPS ${PHI_DEPS})
else()
  cc_library(
    phi ${PHI_BUILD_TYPE}
    SRCS ${PHI_SRCS}
    DEPS ${PHI_DEPS})
endif()

if(WIN32)
  target_link_libraries(phi shlwapi.lib)
endif()

if(WIN32)
  if(WITH_PHI_SHARED)
    set_property(TARGET phi PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
    set(PHI_NAME
        phi.dll
        CACHE INTERNAL "" FORCE)
  else()
    set(PHI_NAME
        phi.lib
        CACHE INTERNAL "" FORCE)
  endif()
elseif(APPLE)
  if(WITH_PHI_SHARED)
    set(PHI_NAME
        libphi.dylib
        CACHE INTERNAL "" FORCE)
  else()
    set(PHI_NAME
        libphi.a
        CACHE INTERNAL "" FORCE)
  endif()
else()
  if(WITH_PHI_SHARED)
    set(PHI_NAME
        libphi.so
        CACHE INTERNAL "" FORCE)
  else()
    set(PHI_NAME
        libphi.a
        CACHE INTERNAL "" FORCE)
  endif()
endif()

set(PHI_LIB
    "${CMAKE_CURRENT_BINARY_DIR}/${PHI_NAME}"
    CACHE FILEPATH "PHI Library" FORCE)

if(MKL_FOUND AND WITH_ONEMKL)
  target_include_directories(phi PRIVATE ${MKL_INCLUDE})
endif()

add_dependencies(phi extern_lapack)
if(WITH_CUTLASS)
  add_dependencies(phi cutlass_codegen)
  add_definitions("-DPADDLE_WITH_MEMORY_EFFICIENT_ATTENTION"
  )# for memory_efficient_attention.h
endif()
if(WITH_FLASHATTN)
  add_dependencies(phi flashattn)
endif()
183

184 185 186 187 188 189 190
set(phi_extension_header_file
    ${CMAKE_CURRENT_SOURCE_DIR}/extension.h
    CACHE INTERNAL "phi/extension.h file")
file(
  WRITE ${phi_extension_header_file}
  "// Header file generated by paddle/phi/CMakeLists.txt for external users,\n// DO NOT edit or include it within paddle.\n\n#pragma once\n\n"
)
191

192
file(APPEND ${phi_extension_header_file} "#include \"paddle/phi/config.h\"\n\n")
193
# generate inner headers include dir for users
194
generate_unify_header(backends EXCLUDES context_pool_utils.h)
195
generate_unify_header(core EXCLUDES cuda_stream.h)
196 197
generate_unify_header(infermeta)
generate_unify_header(kernels SKIP_SUFFIX grad_kernel)