CMakeLists.txt 3.5 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
# phi functors and functions called by kernels
C
Chen Weihang 已提交
14
add_subdirectory(funcs)
C
Chen Weihang 已提交
15

16 17 18
# kernel autotune
add_subdirectory(autotune)

19 20
# phi depends all phi kernel targets
set_property(GLOBAL PROPERTY PHI_KERNELS "")
21

22
# [ 1. Common kernel compilation dependencies ]
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
set(COMMON_KERNEL_DEPS
    dense_tensor
    sparse_coo_tensor
    sparse_csr_tensor
    kernel_context
    kernel_factory
    arg_map_context
    convert_utils
    lod_utils
    custom_kernel)
set(COMMON_KERNEL_DEPS
    ${COMMON_KERNEL_DEPS}
    eigen_function
    blas
    math_function
    im2col
    vol2col
    concat_and_split_functor
    selected_rows_functor)
42
# remove this dep after removing fluid deps on tensor creation
43
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} phi_api_utils)
44 45
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} infermeta infermeta_utils)
set(COMMON_KERNEL_DEPS ${COMMON_KERNEL_DEPS} switch_autotune)
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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
    phi_dynload_warpctc
    sequence_padding
    sequence_scale)
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81
set(COMMON_KERNEL_DEPS
    ${COMMON_KERNEL_DEPS}
    dense_tensor
    string_tensor
    sparse_coo_tensor
    sparse_csr_tensor
    kernel_context
    kernel_factory
    arg_map_context
    convert_utils
    lod_utils
    custom_kernel
    string_infermeta
    utf8proc)
82 83

copy_if_different(${kernel_declare_file} ${kernel_declare_file_final})
J
Jack Zhou 已提交
84 85
# For strings kernels
add_subdirectory(strings)
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

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_cc
  "*.cc"
  "cpu/*.cc"
  "selected_rows/*.cc"
  "selected_rows/cpu/*.cc"
  "sparse/*.cc"
  "sparse/cpu/*.cc"
  "strings/*.cc"
  "strings/cpu/*.cc")

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

# file(GLOB kernel_cudnn "gpudnn/*.cu")
# file(GLOB kernel_kps "kps/*.cu")
file(GLOB kernel_xpu "xpu/*.cc")

add_library(phi_cpu ${kernel_cc})
kernel_declare("${kernel_cc}")
target_link_libraries(phi_cpu ${COMMON_KERNEL_DEPS})
set_property(GLOBAL PROPERTY PHI_KERNELS phi_cpu)

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})
  set_property(GLOBAL PROPERTY PHI_KERNELS phi_cpu phi_gpu)
endif()

if(WITH_XPU)
  if(WITH_XPU_KP)
    file(GLOB kernel_xpu_kps "kps/*.cu")
    xpu_add_library(phi_xpu STATIC ${kernel_xpu} ${kernel_xpu_kps})
  else()
    add_library(phi_xpu ${kernel_xpu})
  endif()
  kernel_declare(${kernel_xpu})
  target_link_libraries(phi_xpu ${COMMON_KERNEL_DEPS})
  set_property(GLOBAL PROPERTY PHI_KERNELS phi_cpu phi_xpu)
endif()