CMakeLists.txt 4.8 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
copy_if_different(${kernel_declare_file} ${kernel_declare_file_final})
23 24 25 26 27

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")

28
# fusion ops would be included here
29
file(
30 31
  GLOB kernel_cu
  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
32 33 34 35
  "gpu/*.cu"
  "gpu/*.cu.cc"
  "gpudnn/*.cu"
  "kps/*.cu"
Z
zhangyuqin1998 已提交
36
  "legacy/kps/*.cu"
37
  "legacy/gpu/*.cu"
38 39
  "selected_rows/gpu/*.cu"
  "sparse/gpu/*.cu"
40 41
  "strings/gpu/*.cu"
  "fusion/gpu/*.cu")
42

43 44 45 46
if(APPLE OR WIN32)
  list(REMOVE_ITEM kernel_cu "fusion/gpu/fusion_group_kernel.cu")
endif()

47 48 49 50 51
if(DEFINED REDUCE_INFERENCE_LIB_SIZE)
  list(FILTER kernel_cu EXCLUDE REGEX ".*_grad_kernel\\.cc$")
  list(FILTER kernel_cu EXCLUDE REGEX ".*_grad_kernel\\.cu$")
endif()

52
if(WITH_CUTLASS)
53 54 55 56 57
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E make_directory
            "${CMAKE_CURRENT_SOURCE_DIR}/fusion/cutlass/conv2d/generated"
    COMMAND ${PYTHON_EXECUTABLE} "conv2d_bias_act.py"
    COMMAND ${PYTHON_EXECUTABLE} "conv2d_bias_residual.py"
58
    COMMAND ${PYTHON_EXECUTABLE} "conv2d_depthwise_bias_act.py"
59 60
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fusion/cutlass/conv2d")

61 62 63 64
  execute_process(
    COMMAND
      ${PYTHON_EXECUTABLE}
      ${PADDLE_SOURCE_DIR}/paddle/phi/kernels/fusion/cutlass/memory_efficient_attention/generate_kernels.py
65 66 67 68 69 70 71 72 73 74
      --cuda_arch "${NVCC_ARCH_BIN}"
    RESULT_VARIABLE memory_efficient_attention_gen_res)

  if(NOT memory_efficient_attention_gen_res EQUAL 0)
    message(
      FATAL_ERROR
        "The memory efficient attention kernel generation errors with NVCC_ARCH_BIN=${NVCC_ARCH_BIN}"
    )
  endif()

75 76 77 78 79 80
  file(
    GLOB cutlass_cu
    RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
    "fusion/cutlass/conv2d/generated/*.cu" "fusion/cutlass/conv2d/*.cu"
    "fusion/cutlass/*.cu"
    "fusion/cutlass/memory_efficient_attention/autogen/impl/*.cu")
81 82 83
  list(APPEND kernel_cu ${cutlass_cu})
endif()

Y
YuanRisheng 已提交
84
set(cc_search_pattern
85 86
    "*.cc"
    "cpu/*.cc"
Z
zhangyuqin1998 已提交
87 88
    "legacy/*.cc"
    "legacy/cpu/*.cc"
89 90 91 92
    "selected_rows/*.cc"
    "selected_rows/cpu/*.cc"
    "sparse/*.cc"
    "sparse/cpu/*.cc"
93 94
    "legacy/*.cc"
    "legacy/cpu/*.cc"
95
    "strings/*.cc"
96 97
    "strings/cpu/*.cc"
    "fusion/*.cc"
W
wanghuancoder 已提交
98
    "stride/*.cc"
99
    "fusion/cpu/*.cc")
Y
YuanRisheng 已提交
100 101 102 103

if(WITH_MKLDNN)
  set(cc_search_pattern ${cc_search_pattern} "legacy/onednn/*.cc" "onednn/*.cc"
                        "fusion/onednn/*.cc")
104 105
endif()

Y
YuanRisheng 已提交
106 107 108 109 110
file(
  GLOB kernel_cc
  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  ${cc_search_pattern})

111 112 113 114
if(DEFINED REDUCE_INFERENCE_LIB_SIZE)
  list(FILTER kernel_cc EXCLUDE REGEX ".*_grad_kernel\\.cc$")
endif()

115
file(
116 117 118
  GLOB kernel_xpu
  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
  "xpu/*.cc" "legacy/xpu/*.cc" "selected_rows/xpu/*.cc" "fusion/xpu/*.cc"
119
  "sparse/xpu/*.cc")
120 121

if(WITH_GPU OR WITH_ROCM)
122
  collect_srcs(kernels_srcs SRCS ${kernel_cu})
123
  kernel_declare("${kernel_cu}")
124 125 126
endif()

if(WITH_XPU)
127
  if(WITH_XPU_KP)
L
Leo Chen 已提交
128 129
    file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/kps/
         DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/kps/)
Z
zhangyuqin1998 已提交
130 131
    file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/legacy/kps/
         DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/kps/)
L
Leo Chen 已提交
132 133 134 135 136 137
    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")
Y
YuanRisheng 已提交
138
    collect_generated_srcs(kernels_srcs SRCS ${kernel_xpu_kps})
139 140

    foreach(kernel ${kernel_cc})
Y
YuanRisheng 已提交
141 142
      configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${kernel}
                     ${CMAKE_CURRENT_BINARY_DIR}/${kernel} COPYONLY)
Y
YuanRisheng 已提交
143 144
    endforeach()
    file(GLOB_RECURSE kernel_xpu_cc "${CMAKE_CURRENT_BINARY_DIR}/*.cc")
Y
YuanRisheng 已提交
145 146
    collect_generated_srcs(kernels_srcs SRCS ${kernel_xpu_cc})
    set(kernel_cc "")
147

148
  endif()
149
  collect_srcs(kernels_srcs SRCS ${kernel_xpu})
150 151
  kernel_declare("${kernel_xpu}")
  kernel_declare("${kernel_xpu_kps}")
Y
YuanRisheng 已提交
152
  kernel_declare("${kernel_xpu_cc}")
153 154
endif()

155 156
collect_srcs(kernels_srcs SRCS ${kernel_cc})
kernel_declare("${kernel_cc}")
157 158 159 160

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