From e47c3f040f3ff6a2866fe3675b19e657ef3c3115 Mon Sep 17 00:00:00 2001 From: Wilber Date: Tue, 15 Jun 2021 21:07:47 +0800 Subject: [PATCH] [XPU] Update cmake options for xpu. (#33450) --- cmake/external/lite.cmake | 30 ++++++++++++++++++++++-------- cmake/external/xpu.cmake | 11 +++++------ python/setup.py.in | 12 ------------ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cmake/external/lite.cmake b/cmake/external/lite.cmake index 6e2157e3087..c48f2cb0467 100644 --- a/cmake/external/lite.cmake +++ b/cmake/external/lite.cmake @@ -18,13 +18,21 @@ if(NOT LINUX) return() endif() -if(XPU_SDK_ROOT) - set(LITE_WITH_XPU ON) - include_directories("${XPU_SDK_ROOT}/XTDK/include") - include_directories("${XPU_SDK_ROOT}/XTCL/include") +if (LITE_WITH_XPU) add_definitions(-DLITE_SUBGRAPH_WITH_XPU) - LINK_DIRECTORIES("${XPU_SDK_ROOT}/XTDK/shlib/") - LINK_DIRECTORIES("${XPU_SDK_ROOT}/XTDK/runtime/shlib/") + IF(WITH_AARCH64) + SET(XPU_SDK_ENV "kylin_aarch64") + ELSEIF(WITH_SUNWAY) + SET(XPU_SDK_ENV "deepin_sw6_64") + ELSEIF(WITH_BDCENTOS) + SET(XPU_SDK_ENV "bdcentos_x86_64") + ELSEIF(WITH_UBUNTU) + SET(XPU_SDK_ENV "ubuntu_x86_64") + ELSEIF(WITH_CENTOS) + SET(XPU_SDK_ENV "centos7_x86_64") + ELSE () + SET(XPU_SDK_ENV "ubuntu_x86_64") + ENDIF() endif() if (NOT LITE_SOURCE_DIR OR NOT LITE_BINARY_DIR) @@ -57,7 +65,8 @@ if (NOT LITE_SOURCE_DIR OR NOT LITE_BINARY_DIR) -DWITH_TESTING=OFF -DLITE_BUILD_EXTRA=ON -DLITE_WITH_XPU=${LITE_WITH_XPU} - -DXPU_SDK_ROOT=${XPU_SDK_ROOT} + -DXPU_SDK_URL=${XPU_BASE_URL} + -DXPU_SDK_ENV=${XPU_SDK_ENV} -DLITE_WITH_CODE_META_INFO=OFF -DLITE_WITH_ARM=ON) ExternalProject_Add( @@ -99,7 +108,8 @@ if (NOT LITE_SOURCE_DIR OR NOT LITE_BINARY_DIR) -DLITE_WITH_STATIC_CUDA=OFF -DCUDA_ARCH_NAME=${CUDA_ARCH_NAME} -DLITE_WITH_XPU=${LITE_WITH_XPU} - -DXPU_SDK_ROOT=${XPU_SDK_ROOT} + -DXPU_SDK_URL=${XPU_SDK_URL} + -DXPU_SDK_ENV=${XPU_SDK_ENV} -DLITE_WITH_CODE_META_INFO=OFF -DLITE_WITH_ARM=OFF) @@ -147,6 +157,10 @@ message(STATUS "Paddle-lite BINARY_DIR: ${LITE_BINARY_DIR}") message(STATUS "Paddle-lite SOURCE_DIR: ${LITE_SOURCE_DIR}") include_directories(${LITE_SOURCE_DIR}) include_directories(${LITE_BINARY_DIR}) +if(LITE_WITH_XPU) + include_directories(${LITE_BINARY_DIR}/third_party/install/xpu/xdnn/include/) + include_directories(${LITE_BINARY_DIR}/third_party/install/xpu/xre/include/) +endif() function(external_lite_libs alias path) add_library(${alias} SHARED IMPORTED GLOBAL) diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index 5d1f1776f88..a8c33618a61 100644 --- a/cmake/external/xpu.cmake +++ b/cmake/external/xpu.cmake @@ -33,7 +33,10 @@ ELSE () SET(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64") ENDIF() -SET(XPU_BASE_URL "https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev/20210527") +IF(NOT XPU_BASE_URL) + SET(XPU_BASE_URL "https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev/20210527") +ENDIF() + SET(XPU_XRE_URL "${XPU_BASE_URL}/${XPU_XRE_DIR_NAME}.tar.gz" CACHE STRING "" FORCE) SET(XPU_XDNN_URL "${XPU_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE) SET(XPU_XCCL_URL "${XPU_BASE_URL}/${XPU_XCCL_DIR_NAME}.tar.gz" CACHE STRING "" FORCE) @@ -93,11 +96,7 @@ ELSE(WITH_XPU_BKCL) TARGET_LINK_LIBRARIES(xpulib ${XPU_API_LIB} ${XPU_RT_LIB}) ENDIF(WITH_XPU_BKCL) -if(NOT XPU_SDK_ROOT) - ADD_DEPENDENCIES(xpulib ${XPU_PROJECT}) -else() - ADD_CUSTOM_TARGET(extern_xpu DEPENDS xpulib) -endif() +ADD_DEPENDENCIES(xpulib ${XPU_PROJECT}) # Ensure that xpu/api.h can be included without dependency errors. file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/.xpu_headers_dummy.cc CONTENT "") diff --git a/python/setup.py.in b/python/setup.py.in index 866c2b400d5..787317acb6d 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -347,18 +347,6 @@ if '${WITH_XPU_BKCL}' == 'ON': shutil.copy('${XPU_BKCL_LIB}', libs_path) package_data['paddle.libs']+=['${XPU_BKCL_LIB_NAME}'] -# Only for lite xpu inference. -if '${WITH_XPU}' == 'OFF' and '${XPU_SDK_ROOT}' != '': - xpu_api_lib = os.path.join('${XPU_SDK_ROOT}', 'XTDK/shlib/', 'libxpuapi.so') - xpu_rt_lib = os.path.join('${XPU_SDK_ROOT}', 'XTDK/runtime/shlib/', 'libxpurt.so') - if os.path.exists(xpu_api_lib): - shutil.copy(xpu_api_lib, libs_path) - package_data['paddle.libs']+=['libxpuapi.so'] - if os.path.exists(xpu_rt_lib): - shutil.copy(xpu_rt_lib, libs_path) - package_data['paddle.libs']+=['libxpurt.so'] - - # remove unused paddle/libs/__init__.py if os.path.isfile(libs_path+'/__init__.py'): os.remove(libs_path+'/__init__.py') -- GitLab