CMakeLists.txt 4.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
set(kernel_declare_file
    ${PADDLE_BINARY_DIR}/paddle/phi/kernels/declarations.h.tmp
    CACHE INTERNAL "declarations.h file")
set(kernel_declare_file_final
    ${PADDLE_BINARY_DIR}/paddle/phi/kernels/declarations.h)
file(
  WRITE ${kernel_declare_file}
  "// Generated by the paddle/phi/kernels/CMakeLists.txt.  DO NOT EDIT!\n\n#pragma once\n\n"
)
file(APPEND ${kernel_declare_file}
     "#include \"paddle/phi/core/kernel_registry.h\"\n\n")
12 13 14
set(kernel_declare_file_prune
    ${PADDLE_BINARY_DIR}/paddle/phi/kernels/declarations.h.prune
    CACHE INTERNAL "declarations.h file")
15

16
# phi functors and functions called by kernels
C
Chen Weihang 已提交
17
add_subdirectory(funcs)
C
Chen Weihang 已提交
18

19 20 21
# kernel autotune
add_subdirectory(autotune)

22 23
# phi depends all phi kernel targets
set_property(GLOBAL PROPERTY PHI_KERNELS "")
24

25
# [ 1. Common kernel compilation dependencies ]
26 27
set(COMMON_KERNEL_DEPS
    dense_tensor
28
    string_tensor
29 30
    sparse_coo_tensor
    sparse_csr_tensor
31
    tensor_array
32 33 34 35 36
    kernel_context
    kernel_factory
    arg_map_context
    convert_utils
    lod_utils
37
    custom_kernel
38
    string_infermeta
39
    phi_tensor_utils)
40 41 42 43 44 45 46 47 48
set(COMMON_KERNEL_DEPS
    ${COMMON_KERNEL_DEPS}
    eigen_function
    blas
    math_function
    im2col
    vol2col
    concat_and_split_functor
    selected_rows_functor)
49
# remove this dep after removing fluid deps on tensor creation
50
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} phi_api_utils)
Z
zhangkaihuo 已提交
51 52
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} infermeta infermeta_utils
                       sparse_infermeta)
53
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} switch_autotune)
54

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
set(COMMON_KERNEL_DEPS
    ${COMMON_KERNEL_DEPS}
    threadpool
    jit_kernel_helper
    softmax
    cross_entropy
    matrix_bit_code
    lapack_function
    lstm_compute
    gru_compute
    deformable_conv_functor
    matrix_reduce
    segment_pooling
    gather_scatter_kernel
    pooling
    maxouting
    matrix_inverse
72
    matrix_solve
73 74
    phi_dynload_warpctc
    sequence_padding
F
Feiyu Chan 已提交
75
    sequence_scale
76
    fft
77
    phi_data_layout_transform
78
    gpc
79
    utf8proc)
80

W
Wen Sun 已提交
81
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} process_group)
L
LiYuRio 已提交
82
if(WITH_NCCL OR WITH_RCCL)
W
Wen Sun 已提交
83
  set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} process_group_nccl)
L
LiYuRio 已提交
84
endif()
85
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} processgroup_comm_utils)
86 87 88
if(WITH_CUDNN_FRONTEND)
  set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} cudnn-frontend)
endif()
89
copy_if_different(${kernel_declare_file} ${kernel_declare_file_final})
90 91 92 93 94 95 96 97 98 99 100 101 102 103

file(GLOB kernel_h "*.h" "selected_rows/*.h" "sparse/*.h" "strings/*.h")
file(GLOB kernel_impl_h "impl/*.h" "selected_rows/impl/*.h")
file(GLOB kernel_primitive_h "primitive/*.h")

file(
  GLOB
  kernel_cu
  "gpu/*.cu"
  "gpu/*.cu.cc"
  "gpudnn/*.cu"
  "kps/*.cu"
  "selected_rows/gpu/*.cu"
  "sparse/gpu/*.cu"
104 105
  "strings/gpu/*.cu"
  "fusion/gpu/*.cu")
106

107 108 109 110 111 112 113 114 115 116 117 118
if(WITH_MKLDNN)
  file(
    GLOB
    kernel_cc
    "*.cc"
    "cpu/*.cc"
    "selected_rows/*.cc"
    "selected_rows/cpu/*.cc"
    "sparse/*.cc"
    "sparse/cpu/*.cc"
    "strings/*.cc"
    "strings/cpu/*.cc"
119 120
    "onednn/*.cc"
    "fusion/*.cc"
121
    "fusion/onednn/*.cc"
122
    "fusion/cpu/*.cc")
123 124 125 126 127 128 129 130 131 132 133
else()
  file(
    GLOB
    kernel_cc
    "*.cc"
    "cpu/*.cc"
    "selected_rows/*.cc"
    "selected_rows/cpu/*.cc"
    "sparse/*.cc"
    "sparse/cpu/*.cc"
    "strings/*.cc"
134 135 136
    "strings/cpu/*.cc"
    "fusion/*.cc"
    "fusion/cpu/*.cc")
137 138
endif()

139
file(GLOB kernel_xpu "xpu/*.cc" "selected_rows/xpu/*.cc" "fusion/xpu/*.cc")
140 141 142 143

add_library(phi_cpu ${kernel_cc})
kernel_declare("${kernel_cc}")
target_link_libraries(phi_cpu ${COMMON_KERNEL_DEPS})
144 145

set(ADD_PHI_KERNELS phi_cpu)
146 147 148 149 150 151 152 153 154

if(WITH_GPU OR WITH_ROCM)
  if(WITH_GPU)
    add_library(phi_gpu ${kernel_cu})
  elseif(WITH_ROCM)
    hip_add_library(phi_gpu STATIC ${kernel_cu})
  endif()
  kernel_declare("${kernel_cu}")
  target_link_libraries(phi_gpu ${COMMON_KERNEL_DEPS})
155
  set(ADD_PHI_KERNELS ${ADD_PHI_KERNELS} phi_gpu)
156 157 158 159
endif()

if(WITH_XPU)
  if(WITH_XPU_KP)
L
Leo Chen 已提交
160 161 162 163 164 165 166 167 168 169
    file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/kps/
         DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/kps/)
    file(GLOB kernel_xpu_kps "${CMAKE_CURRENT_BINARY_DIR}/kps/*.cu")
    foreach(kernel ${kernel_xpu_kps})
      get_filename_component(name ${kernel} NAME_WE)
      file(RENAME ${kernel} "${CMAKE_CURRENT_BINARY_DIR}/kps/${name}.kps")
    endforeach()
    file(GLOB kernel_xpu_kps "${CMAKE_CURRENT_BINARY_DIR}/kps/*.kps")
    xpu_add_library(phi_xpu STATIC ${kernel_xpu} ${kernel_xpu_kps} DEPENDS
                    ${COMMON_KERNEL_DEPS})
170 171 172
  else()
    add_library(phi_xpu ${kernel_xpu})
  endif()
173 174
  kernel_declare("${kernel_xpu}")
  kernel_declare("${kernel_xpu_kps}")
175
  target_link_libraries(phi_xpu ${COMMON_KERNEL_DEPS})
176 177 178 179
  set(ADD_PHI_KERNELS ${ADD_PHI_KERNELS} phi_xpu)
endif()

set_property(GLOBAL PROPERTY PHI_KERNELS ${ADD_PHI_KERNELS})
180 181 182 183

if(NOT "${KERNEL_LIST}" STREQUAL "")
  prune_declaration_h()
endif()