|
| 1 | +cmake_minimum_required(VERSION 3.10) |
| 2 | + |
| 3 | +project(paddle-custom-sdaa CXX C) |
| 4 | +add_definitions(-std=c++14) |
| 5 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") |
| 6 | + |
| 7 | +option(WITH_TESTING "compile with unit testing" ON) |
| 8 | +option(NATIVE_SDAA "use native sdaa lib" ON) |
| 9 | +option(WITH_MKLDNN "compile with MKLDNN support" ON) |
| 10 | +option(WITH_SW "compile with sw arch support" OFF) |
| 11 | +option(WITH_GIT_COMMIT "compile with git commit print" ON) |
| 12 | +option(WITH_PADDLE_INFO "compile with paddle commit/version print" ON) |
| 13 | + |
| 14 | +set(PLUGIN_NAME "paddle-custom-sdaa") |
| 15 | +if(DEFINED ENV{PLUGIN_VERSION}) |
| 16 | + set(PLUGIN_VERSION $ENV{PLUGIN_VERSION}) |
| 17 | +else() |
| 18 | + set(PLUGIN_VERSION "0.0.1") |
| 19 | +endif() |
| 20 | + |
| 21 | +include(paddle) |
| 22 | +include(generic) |
| 23 | +include(teco) |
| 24 | +include(third_party) |
| 25 | + |
| 26 | +include_directories( |
| 27 | + ${PADDLE_INC_DIR} |
| 28 | + ${TECODNN_INC} |
| 29 | + ${CMAKE_SOURCE_DIR} |
| 30 | + ${EXTEND_OP_INC} |
| 31 | + ${SDPTI_INC} |
| 32 | + ${TBLAS_INC} |
| 33 | + ${TECODNN_CUSTOM_INC} |
| 34 | + ${TCCL_INC} |
| 35 | + ${CLANG_INC}) |
| 36 | + |
| 37 | +if(NATIVE_SDAA) |
| 38 | + add_definitions(-DNATIVE_SDAA) |
| 39 | + include_directories(${SDAA_INC}) |
| 40 | +endif() |
| 41 | + |
| 42 | +add_definitions(-DPADDLE_WITH_CUSTOM_DEVICE) |
| 43 | +# TODO(Aganlengzi): avoid compile error, to be removed |
| 44 | +add_definitions(-DPADDLE_WITH_CUSTOM_KERNEL) |
| 45 | +if(WITH_SW) |
| 46 | + add_definitions(-DPADDLE_WITH_SW) |
| 47 | +endif() |
| 48 | + |
| 49 | +if(WITH_GIT_COMMIT) |
| 50 | + execute_process( |
| 51 | + COMMAND git rev-parse --short HEAD |
| 52 | + OUTPUT_VARIABLE GIT_COMMIT_ID |
| 53 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 54 | + add_definitions(-DGIT_COMMIT_ID=\"${GIT_COMMIT_ID}\") |
| 55 | +endif() |
| 56 | + |
| 57 | +if(WITH_PADDLE_INFO) |
| 58 | + get_paddle_info(PADDLE_COMMIT_ID PADDLE_FULL_VERSION PADDLE_BUILD_ENV_PATH) |
| 59 | + add_definitions(-DPADDLE_COMMIT_ID=\"${PADDLE_COMMIT_ID}\") |
| 60 | + add_definitions(-DPADDLE_FULL_VERSION=\"${PADDLE_FULL_VERSION}\") |
| 61 | +endif() |
| 62 | + |
| 63 | +file( |
| 64 | + GLOB_RECURSE PLUGIN_SRCS |
| 65 | + RELATIVE ${CMAKE_SOURCE_DIR} |
| 66 | + kernels/*.cc) |
| 67 | +set(DYNLOAD_SRCS dynload/sdpti.cc dynload/dynamic_loader.cc) |
| 68 | +list(APPEND PLUGIN_SRCS ${DYNLOAD_SRCS}) |
| 69 | +file( |
| 70 | + GLOB_RECURSE PLUGIN_RUNTIME_SRCS |
| 71 | + RELATIVE ${CMAKE_SOURCE_DIR} |
| 72 | + runtime/*.cc) |
| 73 | +list(APPEND PLUGIN_SRCS ${PLUGIN_RUNTIME_SRCS}) |
| 74 | + |
| 75 | +# version dump |
| 76 | +set(VERSION_DUMP_TARGET version_dump) |
| 77 | +set(PADDLE_SDAA_TOOLS_DIR ${CMAKE_SOURCE_DIR}/tools) |
| 78 | +set(VERSION_QUERY_DIR ${PADDLE_SDAA_TOOLS_DIR}/version) |
| 79 | +list(APPEND PLUGIN_SRCS ${VERSION_QUERY_DIR}/query.cc) |
| 80 | +configure_file( |
| 81 | + ${CMAKE_CURRENT_SOURCE_DIR}/tools/version/minimum_supported_version.h.in |
| 82 | + ${CMAKE_CURRENT_BINARY_DIR}/tools/version/minimum_supported_version.h @ONLY) |
| 83 | +add_executable(${VERSION_DUMP_TARGET} ${VERSION_QUERY_DIR}/query.cc |
| 84 | + ${VERSION_QUERY_DIR}/dump.cc) |
| 85 | +target_include_directories(${VERSION_DUMP_TARGET} |
| 86 | + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 87 | +target_link_libraries(${VERSION_DUMP_TARGET} PRIVATE ${TCCL_LIB}) |
| 88 | +target_link_libraries(${VERSION_DUMP_TARGET} PRIVATE ${SDAA_LIB}) |
| 89 | +target_link_libraries(${VERSION_DUMP_TARGET} PRIVATE ${TECODNN_LIB}) |
| 90 | +target_link_libraries(${VERSION_DUMP_TARGET} PRIVATE ${TBLAS_LIB}) |
| 91 | +target_link_libraries(${VERSION_DUMP_TARGET} PRIVATE ${TECODNN_CUSTOM_LIB}) |
| 92 | + |
| 93 | +add_custom_command( |
| 94 | + TARGET ${VERSION_DUMP_TARGET} |
| 95 | + POST_BUILD |
| 96 | + COMMAND ${CMAKE_COMMAND} -E echo "Run version_dump to generate version.py" |
| 97 | + COMMAND ./${VERSION_DUMP_TARGET}) |
| 98 | + |
| 99 | +# build shared library |
| 100 | +add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS}) |
| 101 | +set_target_properties( |
| 102 | + ${PLUGIN_NAME} PROPERTIES LINK_FLAGS |
| 103 | + "-Wl,-rpath,$ORIGIN/lib/,--enable-new-dtags") |
| 104 | +target_include_directories(${PLUGIN_NAME} PRIVATE ${PADDLE_SDAA_TOOLS_DIR}) |
| 105 | + |
| 106 | +# link third_party |
| 107 | +add_dependencies(${PLUGIN_NAME} third_party) |
| 108 | +target_link_libraries(${PLUGIN_NAME} PRIVATE gflags glog) |
| 109 | + |
| 110 | +# sdaa |
| 111 | +if(NATIVE_SDAA) |
| 112 | + target_link_libraries(${PLUGIN_NAME} PRIVATE ${SDAA_LIB}) |
| 113 | +endif() |
| 114 | +target_link_libraries(${PLUGIN_NAME} PRIVATE ${EXTEND_OP_LIB}) |
| 115 | +target_link_libraries(${PLUGIN_NAME} PRIVATE ${TECODNN_LIB}) |
| 116 | +target_link_libraries(${PLUGIN_NAME} PRIVATE ${PADDLE_CORE_LIB}) |
| 117 | +target_link_libraries(${PLUGIN_NAME} PRIVATE ${TBLAS_LIB}) |
| 118 | +target_link_libraries(${PLUGIN_NAME} PRIVATE stdc++fs) |
| 119 | +target_link_libraries(${PLUGIN_NAME} PRIVATE ${TCCL_LIB}) |
| 120 | +target_link_libraries(${PLUGIN_NAME} PRIVATE ${TECODNN_CUSTOM_LIB}) |
| 121 | + |
| 122 | +# testing |
| 123 | +if(WITH_TESTING) |
| 124 | + set(TEST_CUSTOM_DEVICE_ROOT |
| 125 | + CUSTOM_DEVICE_ROOT=${CMAKE_BINARY_DIR}/python/paddle_custom_device) |
| 126 | + add_subdirectory(tests) |
| 127 | +endif() |
| 128 | + |
| 129 | +# packing wheel package |
| 130 | +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in |
| 131 | + ${CMAKE_CURRENT_BINARY_DIR}/setup.py) |
| 132 | + |
| 133 | +add_custom_command( |
| 134 | + TARGET ${PLUGIN_NAME} |
| 135 | + POST_BUILD |
| 136 | + COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/python/ |
| 137 | + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/python/ |
| 138 | + COMMAND ${CMAKE_COMMAND} -E make_directory |
| 139 | + ${CMAKE_CURRENT_BINARY_DIR}/python/sdaa-ext |
| 140 | + COMMAND ${CMAKE_COMMAND} -E make_directory |
| 141 | + ${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/ |
| 142 | + COMMAND ${CMAKE_COMMAND} -E make_directory |
| 143 | + ${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/lib/ |
| 144 | + COMMAND |
| 145 | + ${CMAKE_COMMAND} -E copy_if_different |
| 146 | + ${CMAKE_CURRENT_BINARY_DIR}/lib${PLUGIN_NAME}.so |
| 147 | + ${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device/ |
| 148 | + COMMENT "Creating plugin dirrectories------>>>") |
| 149 | + |
| 150 | +add_custom_command( |
| 151 | + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python/.timestamp |
| 152 | + COMMAND |
| 153 | + ${CMAKE_COMMAND} -E copy_if_different |
| 154 | + ${CMAKE_SOURCE_DIR}/sdaa_ext/python/__init__.py |
| 155 | + ${CMAKE_CURRENT_BINARY_DIR}/python/paddle_custom_device |
| 156 | + COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py bdist_wheel |
| 157 | + DEPENDS ${PLUGIN_NAME} |
| 158 | + COMMENT "Packing paddle-custom-sdaa whl packages------>>>") |
| 159 | + |
| 160 | +add_custom_target(python_package ALL |
| 161 | + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/.timestamp) |
0 commit comments