From 3f907e0f1aea2477393a240c7d1b74ac98938aba Mon Sep 17 00:00:00 2001 From: mayang02 Date: Wed, 1 Mar 2023 19:08:33 +0800 Subject: [PATCH 1/5] [xpu] support paddle compile with XFT --- CMakeLists.txt | 13 +++++++++++++ cmake/external/xpu.cmake | 41 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b8caf7addd16..2cdaa25a2f871 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ option(WITH_MPI "Compile PaddlePaddle with MPI" OFF) option(WITH_TENSORRT "Compile PaddlePaddle with NVIDIA TensorRT" OFF) option(WITH_XPU "Compile PaddlePaddle with BAIDU KUNLUN XPU" OFF) option(WITH_XPU_KP "Compile PaddlePaddle with BAIDU XPU compiler " OFF) +option(WITH_XPU_XFT "Compile PaddlePaddle with BAIDU XPU-XFT" OFF) option(WITH_MLU "Compile PaddlePaddle with CAMBRICON MLU" OFF) option(WITH_WIN_DUMP_DBG "Compile with windows core dump debug mode" OFF) option(WITH_ASCEND "Compile PaddlePaddle with ASCEND" OFF) @@ -74,6 +75,9 @@ endif() if(WITH_GPU AND WITH_XPU_KP) message(FATAL_ERROR "Error when compile GPU and XPU2 at the same time") endif() +if(WITH_GPU AND WITH_XPU_XFT) + message(FATAL_ERROR "Error when compile GPU and XPU-XFT at the same time") +endif() if(WITH_GPU AND WITH_ASCEND) message(FATAL_ERROR "Error when compile GPU and ASCEND at the same time") endif() @@ -419,6 +423,15 @@ if(WITH_XPU_KP AND NOT WITH_XPU) CACHE STRING "Enable WITH_XPU when compiling with WITH_XPU_KP" FORCE) endif() +if(NOT WITH_XPU AND WITH_XPU_XFT) + message( + WARNING + "Enable WITH_XPU when compiling with WITH_XPU_XFT. Force WITH_XPU=ON.") + set(WITH_XPU + ON + CACHE STRING "Enable WITH_XPU when compiling with WITH_XPU_XFT" FORCE) +endif() + if(NOT WITH_XPU AND WITH_XPU_BKCL) message( WARNING "Disable BKCL when compiling without XPU. Force WITH_XPU_BKCL=OFF.") diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index 6276630a09eb0..7fb905bf91bd9 100644 --- a/cmake/external/xpu.cmake +++ b/cmake/external/xpu.cmake @@ -6,9 +6,11 @@ include(ExternalProject) set(XPU_PROJECT "extern_xpu") set(XPU_API_LIB_NAME "libxpuapi.so") set(XPU_RT_LIB_NAME "libxpurt.so") +set(XPU_XFT_LIB_NAME "libxft.so") set(XPU_BASE_DATE "20230227") set(XPU_XCCL_BASE_VERSION "1.0.10") +set(XPU_XFT_BASE_VERSION "latest") if(NOT DEFINED XPU_BASE_URL) set(XPU_BASE_URL_WITHOUT_DATE @@ -22,30 +24,42 @@ set(XPU_XCCL_BASE_URL "https://klx-sdk-release-public.su.bcebos.com/xccl/release/${XPU_XCCL_BASE_VERSION}" ) +if(NOT XPU_XFT_BASE_URL) + set(XPU_XFT_BASE_URL + "https://klx-sdk-release-public.su.bcebos.com/xft/dev/${XPU_XFT_BASE_VERSION}" + ) +endif() + if(WITH_AARCH64) set(XPU_XRE_DIR_NAME "xre-kylin_aarch64") set(XPU_XDNN_DIR_NAME "xdnn-kylin_aarch64") set(XPU_XCCL_DIR_NAME "xccl-kylin_aarch64") + set(XPU_XFT_DIR_NAME "") # TODO: xft has no kylin output at now. elseif(WITH_SUNWAY) set(XPU_XRE_DIR_NAME "xre-deepin_sw6_64") set(XPU_XDNN_DIR_NAME "xdnn-deepin_sw6_64") set(XPU_XCCL_DIR_NAME "xccl-deepin_sw6_64") + set(XPU_XFT_DIR_NAME "") # TODO: xft has no deepin output at now. elseif(WITH_BDCENTOS) set(XPU_XRE_DIR_NAME "xre-bdcentos_x86_64") set(XPU_XDNN_DIR_NAME "xdnn-bdcentos_x86_64") set(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64") + set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82") elseif(WITH_UBUNTU) set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64") set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64") set(XPU_XCCL_DIR_NAME "xccl-ubuntu_x86_64") + set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64") elseif(WITH_CENTOS) set(XPU_XRE_DIR_NAME "xre-centos7_x86_64") set(XPU_XDNN_DIR_NAME "xdnn-centos7_x86_64") set(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64") + set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82") else() set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64") set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64") set(XPU_XCCL_DIR_NAME "xccl-ubuntu_x86_64") + set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64") endif() set(XPU_XRE_URL @@ -57,6 +71,7 @@ set(XPU_XDNN_URL set(XPU_XCCL_URL "${XPU_XCCL_BASE_URL}/${XPU_XCCL_DIR_NAME}.tar.gz" CACHE STRING "" FORCE) +set(XPU_XFT_URL "${XPU_XFT_BASE_URL}/${XPU_XFT_DIR_NAME}.tar.gz") set(XPU_PACK_DEPENCE_URL "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/pack_paddle_depence.sh" CACHE STRING "" FORCE) @@ -78,9 +93,10 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${XPU_INSTALL_DIR}/lib") file( WRITE ${XPU_DOWNLOAD_DIR}/CMakeLists.txt "PROJECT(XPU)\n" "cmake_minimum_required(VERSION 3.0)\n" - "install(DIRECTORY xpu/include xpu/lib \n" + "install(DIRECTORY xpu/include xpu/lib xpu/xft\n" " DESTINATION ${XPU_INSTALL_DIR})\n") +set(XPU_XFT_LIB_RPATH "${XPU_XFT_DIR_NAME}/so/${XPU_XFT_LIB_NAME}") ExternalProject_Add( ${XPU_PROJECT} ${EXTERNAL_PROJECT_LOG_ARGS} @@ -90,7 +106,10 @@ ExternalProject_Add( wget ${XPU_CHECK_DEPENCE_URL} && bash check_xpu_dependence.sh ${XPU_BASE_URL} ${XPU_XCCL_BASE_URL} && wget ${XPU_PACK_DEPENCE_URL} && bash pack_paddle_depence.sh ${XPU_XRE_URL} ${XPU_XRE_DIR_NAME} ${XPU_XDNN_URL} - ${XPU_XDNN_DIR_NAME} ${XPU_XCCL_URL} ${XPU_XCCL_DIR_NAME} + ${XPU_XDNN_DIR_NAME} ${XPU_XCCL_URL} ${XPU_XCCL_DIR_NAME} && wget + --no-check-certificate -c -q ${XPU_XFT_URL} -O xft.tar.gz && tar xvf + xft.tar.gz && cp -r ${XPU_XFT_DIR_NAME} xpu/xft && cp ${XPU_XFT_LIB_RPATH} + xpu/lib DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${XPU_INSTALL_ROOT} @@ -116,7 +135,25 @@ if(WITH_XPU_BKCL) set(XPU_BKCL_LIB "${XPU_LIB_DIR}/${XPU_BKCL_LIB_NAME}") set(XPU_BKCL_INC_DIR "${THIRD_PARTY_PATH}/install/xpu/include") include_directories(${XPU_BKCL_INC_DIR}) +endif() + +if(WITH_XPU_XFT) + message(STATUS "Compile with XPU XFT!") + add_definitions(-DPADDLE_WITH_XPU_XFT) + + set(XPU_XFT_INC_DIR "${THIRD_PARTY_PATH}/install/xpu/xft/include") + set(XPU_XFT_LIB_DIR "${THIRD_PARTY_PATH}/install/xpu/xft/so") + set(XPU_XFT_LIB "${XPU_XFT_LIB_DIR}/${XPU_XFT_LIB_NAME}") + include_directories(${XPU_XFT_INC_DIR}) +endif() + +if(WITH_XPU_BKCL AND WITH_XPU_XFT) + target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_BKCL_LIB} + ${XPU_XFT_LIB}) +elseif(WITH_XPU_BKCL) target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_BKCL_LIB}) +elseif(WITH_XPU_XFT) + target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_XFT_LIB}) else() target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB}) endif() From 4157799379967e393bf8d757e3ab02ecf7498d2a Mon Sep 17 00:00:00 2001 From: mayang02 Date: Wed, 1 Mar 2023 21:22:07 +0800 Subject: [PATCH 2/5] [xpu] support paddle compile with XFT --- python/setup.py.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/setup.py.in b/python/setup.py.in index 198599cb01965..f881c404159fb 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -642,6 +642,10 @@ if '${WITH_XPU_BKCL}' == 'ON': shutil.copy('${XPU_BKCL_LIB}', libs_path) package_data['paddle.libs']+=['${XPU_BKCL_LIB_NAME}'] +if '${WITH_XPU_XFT}' == 'ON': + shutil.copy('${XPU_XFT_LIB}', libs_path) + package_data['paddle.libs']+=['${XPU_XFT_LIB_NAME}'] + # remove unused paddle/libs/__init__.py if os.path.isfile(libs_path+'/__init__.py'): os.remove(libs_path+'/__init__.py') From a4730c5b28aa2786f0b0dc00b365fe032d7008ab Mon Sep 17 00:00:00 2001 From: mayang02 Date: Wed, 1 Mar 2023 21:55:19 +0800 Subject: [PATCH 3/5] [xpu] support paddle compile with XFT --- cmake/external/xpu.cmake | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index 7fb905bf91bd9..214d8360dfa64 100644 --- a/cmake/external/xpu.cmake +++ b/cmake/external/xpu.cmake @@ -78,6 +78,9 @@ set(XPU_PACK_DEPENCE_URL set(XPU_CHECK_DEPENCE_URL "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/check_xpu_dependence.sh" CACHE STRING "" FORCE) +set(XPU_XFT_GET_DEPENCE_URL + "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/get_xft_dependence.sh" + CACHE STRING "" FORCE) set(SNAPPY_PREFIX_DIR "${THIRD_PARTY_PATH}/xpu") set(XPU_DOWNLOAD_DIR "${SNAPPY_PREFIX_DIR}/src/${XPU_PROJECT}") @@ -93,10 +96,9 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${XPU_INSTALL_DIR}/lib") file( WRITE ${XPU_DOWNLOAD_DIR}/CMakeLists.txt "PROJECT(XPU)\n" "cmake_minimum_required(VERSION 3.0)\n" - "install(DIRECTORY xpu/include xpu/lib xpu/xft\n" + "install(DIRECTORY xpu/include xpu/lib \n" " DESTINATION ${XPU_INSTALL_DIR})\n") -set(XPU_XFT_LIB_RPATH "${XPU_XFT_DIR_NAME}/so/${XPU_XFT_LIB_NAME}") ExternalProject_Add( ${XPU_PROJECT} ${EXTERNAL_PROJECT_LOG_ARGS} @@ -107,9 +109,8 @@ ExternalProject_Add( ${XPU_BASE_URL} ${XPU_XCCL_BASE_URL} && wget ${XPU_PACK_DEPENCE_URL} && bash pack_paddle_depence.sh ${XPU_XRE_URL} ${XPU_XRE_DIR_NAME} ${XPU_XDNN_URL} ${XPU_XDNN_DIR_NAME} ${XPU_XCCL_URL} ${XPU_XCCL_DIR_NAME} && wget - --no-check-certificate -c -q ${XPU_XFT_URL} -O xft.tar.gz && tar xvf - xft.tar.gz && cp -r ${XPU_XFT_DIR_NAME} xpu/xft && cp ${XPU_XFT_LIB_RPATH} - xpu/lib + ${XPU_XFT_GET_DEPENCE_URL} && bash get_xft_dependence.sh ${XPU_XFT_URL} + ${XPU_XFT_DIR_NAME} DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${XPU_INSTALL_ROOT} @@ -141,10 +142,8 @@ if(WITH_XPU_XFT) message(STATUS "Compile with XPU XFT!") add_definitions(-DPADDLE_WITH_XPU_XFT) - set(XPU_XFT_INC_DIR "${THIRD_PARTY_PATH}/install/xpu/xft/include") - set(XPU_XFT_LIB_DIR "${THIRD_PARTY_PATH}/install/xpu/xft/so") + set(XPU_XFT_LIB_DIR "${XPU_INSTALL_DIR}/lib") set(XPU_XFT_LIB "${XPU_XFT_LIB_DIR}/${XPU_XFT_LIB_NAME}") - include_directories(${XPU_XFT_INC_DIR}) endif() if(WITH_XPU_BKCL AND WITH_XPU_XFT) From 27ba73ac2555adc6bb0ca768afb0f375ce1732f8 Mon Sep 17 00:00:00 2001 From: mayang002 <77949147+mayang002@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:11:21 +0800 Subject: [PATCH 4/5] Update cmake/external/xpu.cmake Co-authored-by: zhupengyang <1165938320@qq.com> --- cmake/external/xpu.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index 214d8360dfa64..c7b9aa157ebb9 100644 --- a/cmake/external/xpu.cmake +++ b/cmake/external/xpu.cmake @@ -142,8 +142,7 @@ if(WITH_XPU_XFT) message(STATUS "Compile with XPU XFT!") add_definitions(-DPADDLE_WITH_XPU_XFT) - set(XPU_XFT_LIB_DIR "${XPU_INSTALL_DIR}/lib") - set(XPU_XFT_LIB "${XPU_XFT_LIB_DIR}/${XPU_XFT_LIB_NAME}") + set(XPU_XFT_LIB "${XPU_LIB_DIR}/${XPU_XFT_LIB_NAME}") endif() if(WITH_XPU_BKCL AND WITH_XPU_XFT) From 2162facc331a1db03b81fa28908c6e41c0a23a17 Mon Sep 17 00:00:00 2001 From: mayang02 Date: Fri, 3 Mar 2023 15:01:15 +0800 Subject: [PATCH 5/5] [xpu] support paddle compile with XFT: add WITH_XPU_XFT into env_dict.py.in and setup.py --- python/env_dict.py.in | 3 +++ setup.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/python/env_dict.py.in b/python/env_dict.py.in index 1e3a2b18114de..acd6d5f8dc285 100644 --- a/python/env_dict.py.in +++ b/python/env_dict.py.in @@ -55,6 +55,9 @@ env_dict={ 'WITH_XPU_BKCL':'@WITH_XPU_BKCL@', 'XPU_BKCL_LIB':'@XPU_BKCL_LIB@', 'XPU_BKCL_LIB_NAME':'@XPU_BKCL_LIB_NAME@', + 'WITH_XPU_XFT':'@WITH_XPU_XFT@', + 'XPU_XFT_LIB':'@XPU_XFT_LIB@', + 'XPU_XFT_LIB_NAME':'@XPU_XFT_LIB_NAME@', 'THIRD_PARTY_PATH':'@THIRD_PARTY_PATH@', 'SETUP_LOG_FILE':'@SETUP_LOG_FILE@', 'WITH_STRIP':'@WITH_STRIP@', diff --git a/setup.py b/setup.py index 429db65282ed1..a878fe52720c7 100644 --- a/setup.py +++ b/setup.py @@ -1047,6 +1047,9 @@ def get_package_data_and_package_dir(): shutil.copy(env_dict.get("XPU_BKCL_LIB"), libs_path) package_data['paddle.libs'] += [env_dict.get("XPU_BKCL_LIB_NAME")] + if env_dict.get("WITH_XPU_XFT") == 'ON': + shutil.copy(env_dict.get("XPU_XFT_LIB"), libs_path) + package_data['paddle.libs'] += [env_dict.get("XPU_XFT_LIB_NAME")] # remove unused paddle/libs/__init__.py if os.path.isfile(libs_path + '/__init__.py'): os.remove(libs_path + '/__init__.py')