diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d31e2db8e354..916b56751868d9 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ 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_XPU_PLUGIN "Compile PaddlePaddle with BAIDU XPU plugin" OFF) +option(WITH_XPU_XHPC "Compile PaddlePaddle with BAIDU XPU-HPC library" OFF) option(WITH_WIN_DUMP_DBG "Compile with windows core dump debug mode" OFF) option(WITH_ROCM "Compile PaddlePaddle with ROCM platform" OFF) option(WITH_IPU "Compile PaddlePaddle with Graphcore IPU" OFF) @@ -86,6 +87,9 @@ 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_XPU_XHPC) + message(FATAL_ERROR "Error when compile GPU and XPU-HPC at the same time") +endif() if(WITH_GPU AND WITH_ROCM) message(FATAL_ERROR "Error when compile CUDA and ROCM at the same time") endif() @@ -451,6 +455,14 @@ if(NOT WITH_XPU AND WITH_XPU_BKCL) CACHE STRING "Disable BKCL when compiling without XPU" FORCE) endif() +if(NOT WITH_XPU AND WITH_XPU_XHPC) + message( + WARNING "Disable XHPC when compiling without XPU. Force WITH_XPU_XHPC=OFF.") + set(WITH_XPU_XHPC + OFF + CACHE STRING "Disable XHPC when compiling without XPU" FORCE) +endif() + if(WITH_NCCL) add_definitions("-DPADDLE_WITH_NCCL") include(nccl) diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index 768d7eefd45f92..dc7f32f563d948 100644 --- a/cmake/external/xpu.cmake +++ b/cmake/external/xpu.cmake @@ -22,10 +22,15 @@ set(XPU_API_LIB_NAME "libxpuapi.so") set(XPU_RT_LIB_NAME "libxpurt.so") set(XPU_XFT_LIB_NAME "libxft.so") set(XPU_XPTI_LIB_NAME "libxpti.so") +set(XPU_XBLAS_LIB_NAME "libxpu_blas.so") +set(XPU_XFA_LIB_NAME "libxpu_flash_attention.so") if(NOT DEFINED XPU_BASE_DATE) set(XPU_BASE_DATE "20231203") endif() +if(NOT DEFINED XPU_XHPC_BASE_DATE) + set(XPU_XHPC_BASE_DATE "20231208") +endif() set(XPU_XCCL_BASE_VERSION "1.1.7.1") if(NOT DEFINED XPU_XFT_BASE_VERSION) set(XPU_XFT_BASE_VERSION "20230602") @@ -75,11 +80,13 @@ elseif(WITH_BDCENTOS) set(XPU_XDNN_DIR_NAME "xdnn-bdcentos_x86_64") set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-bdcentos_x86_64") set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82") + set(XPU_XHPC_DIR_NAME "xhpc-bdcentos_x86_64") 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 "${XPU_XCCL_PREFIX}-ubuntu_x86_64") set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64") + set(XPU_XHPC_DIR_NAME "xhpc-ubuntu_x86_64") elseif(WITH_CENTOS) set(XPU_XRE_DIR_NAME "xre-centos7_x86_64") set(XPU_XDNN_DIR_NAME "xdnn-centos7_x86_64") @@ -90,6 +97,7 @@ else() set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64") set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-ubuntu_x86_64") set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64") + set(XPU_XHPC_DIR_NAME "xhpc-ubuntu_x86_64") endif() set(XPU_XPTI_DIR_NAME "xpti") @@ -110,6 +118,12 @@ set(XPU_XFT_GET_DEPENCE_URL "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/get_xft_dependence.sh" CACHE STRING "" FORCE) +if(WITH_XPU_XHPC) + set(XPU_XHPC_URL + "https://klx-sdk-release-public.su.bcebos.com/xhpc/dev/${XPU_XHPC_BASE_DATE}/${XPU_XHPC_DIR_NAME}.tar.gz" + CACHE STRING "" FORCE) +endif() + set(SNAPPY_PREFIX_DIR "${THIRD_PARTY_PATH}/xpu") set(XPU_DOWNLOAD_DIR "${SNAPPY_PREFIX_DIR}/src/${XPU_PROJECT}") set(XPU_INSTALL_DIR "${THIRD_PARTY_PATH}/install/xpu") @@ -117,7 +131,9 @@ set(XPU_INC_DIR "${THIRD_PARTY_PATH}/install/xpu/include") set(XPU_LIB_DIR "${THIRD_PARTY_PATH}/install/xpu/lib") set(XPU_API_LIB "${XPU_LIB_DIR}/${XPU_API_LIB_NAME}") +set(XPU_XBLAS_LIB "${XPU_LIB_DIR}/${XPU_XBLAS_LIB_NAME}") set(XPU_RT_LIB "${XPU_LIB_DIR}/${XPU_RT_LIB_NAME}") +set(XPU_XFA_LIB "${XPU_LIB_DIR}/${XPU_XFA_LIB_NAME}") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${XPU_INSTALL_DIR}/lib") @@ -144,19 +160,20 @@ ExternalProject_Add( DOWNLOAD_DIR ${XPU_DOWNLOAD_DIR} DOWNLOAD_COMMAND bash ${CMAKE_SOURCE_DIR}/tools/xpu/check_xpu_dependence.sh ${XPU_BASE_URL} - ${XPU_XCCL_BASE_URL} && bash + ${XPU_XCCL_BASE_URL} && WITH_XPU_XHPC=${WITH_XPU_XHPC} bash ${CMAKE_SOURCE_DIR}/tools/xpu/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 ${XPU_XFT_GET_DEPENCE_URL} && bash - get_xft_dependence.sh ${XPU_XFT_URL} ${XPU_XFT_DIR_NAME} && - WITH_XPTI=${WITH_XPTI} bash + ${XPU_XCCL_DIR_NAME} ${XPU_XHPC_URL} ${XPU_XHPC_DIR_NAME} && wget + ${XPU_XFT_GET_DEPENCE_URL} && bash get_xft_dependence.sh ${XPU_XFT_URL} + ${XPU_XFT_DIR_NAME} && WITH_XPTI=${WITH_XPTI} bash ${CMAKE_SOURCE_DIR}/tools/xpu/get_xpti_dependence.sh ${XPU_XPTI_URL} ${XPU_XPTI_DIR_NAME} DOWNLOAD_NO_PROGRESS 1 UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${XPU_INSTALL_ROOT} CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${XPU_INSTALL_ROOT} - BUILD_BYPRODUCTS ${XPU_API_LIB} + BUILD_BYPRODUCTS ${XPU_API_LIB} BUILD_BYPORDUCTS ${XPU_XBLAS_LIB} + BUILD_BYPRODUCTS ${XPU_XFA_LIB} BUILD_BYPRODUCTS ${XPU_RT_LIB} BUILD_BYPRODUCTS ${XPU_BKCL_LIB}) @@ -179,6 +196,19 @@ if(WITH_XPU_XFT) set(XPU_XFT_LIB "${XPU_LIB_DIR}/${XPU_XFT_LIB_NAME}") endif() +if(WITH_XPU_XHPC) + message(STATUS "Compile with XPU XHPC!") + add_definitions(-DPADDLE_WITH_XPU_XHPC) + + set(XPU_XHPC_INC_DIR "${XPU_INC_DIR}/xhpc") + include_directories(${XPU_XHPC_INC_DIR}) + set(XPU_XBLAS_INC_DIR "${XPU_INC_DIR}/xhpc/xblas") + include_directories(${XPU_XBLAS_INC_DIR}) + + set(XPU_XFA_INC_DIR "${XPU_INC_DIR}/xhpc/xfa") + include_directories(${XPU_XFA_INC_DIR}) +endif() + if(WITH_XPTI) message(STATUS "Compile with XPU XPTI!") add_definitions(-DPADDLE_WITH_XPTI) @@ -191,21 +221,18 @@ if(WITH_XPU_PLUGIN) include_directories(${CMAKE_SOURCE_DIR}/paddle/phi/kernels/xpu/plugin/include) 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() +target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_BKCL_LIB} + ${XPU_XFT_LIB}) if(WITH_XPTI) target_link_libraries(xpulib ${XPU_XPTI_LIB}) endif() +if(WITH_XPU_XHPC) + target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_XBLAS_LIB} + ${XPU_XFA_LIB}) +endif() + add_dependencies(xpulib ${XPU_PROJECT}) # Ensure that xpu/api.h can be included without dependency errors. diff --git a/python/env_dict.py.in b/python/env_dict.py.in index 58900192743e47..ca157737661803 100644 --- a/python/env_dict.py.in +++ b/python/env_dict.py.in @@ -66,6 +66,11 @@ env_dict={ 'WITH_XPU_XFT':'@WITH_XPU_XFT@', 'XPU_XFT_LIB':'@XPU_XFT_LIB@', 'XPU_XFT_LIB_NAME':'@XPU_XFT_LIB_NAME@', + 'WITH_XPU_XHPC':'@WITH_XPU_XHPC@', + 'XPU_XBLAS_LIB':'@XPU_XBLAS_LIB@', + 'XPU_XBLAS_LIB_NAME':'@XPU_XBLAS_LIB_NAME@', + 'XPU_XFA_LIB':'@XPU_XFA_LIB@', + 'XPU_XFA_LIB_NAME':'@XPU_XFA_LIB_NAME@', 'THIRD_PARTY_PATH':'@THIRD_PARTY_PATH@', 'SETUP_LOG_FILE':'@SETUP_LOG_FILE@', 'WITH_STRIP':'@WITH_STRIP@', diff --git a/python/setup.py.in b/python/setup.py.in index df565f7ba352a8..38e58561baaa58 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -88,6 +88,12 @@ def get_xpu_xccl_version(): else: return 'False' +def get_xpu_xhpc_version(): + if '@WITH_XPU_XHPC@' == 'ON': + return '@XPU_XHPC_BASE_DATE@' + else: + return 'False' + def is_taged(): try: cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null'] @@ -118,12 +124,13 @@ cuda_version = '%(cuda)s' cudnn_version = '%(cudnn)s' xpu_version = '%(xpu)s' xpu_xccl_version = '%(xpu_xccl)s' +xpu_xhpc_version = '%(xpu_xhpc)s' istaged = %(istaged)s commit = '%(commit)s' with_mkl = '%(with_mkl)s' cinn_version = '%(cinn)s' -__all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl'] +__all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl', 'xpu_xhpc'] def show(): """Get the version of paddle if `paddle` package if tagged. Otherwise, output the corresponding commit id. @@ -150,6 +157,8 @@ def show(): xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed + xpu_xhpc: the xpu xhpc version of package. It will return `False` if non-XPU version paddle package is installed + cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN Examples: @@ -169,6 +178,7 @@ def show(): cudnn: '7.6.5' xpu: '20230114' xpu_xccl: '1.0.7' + xpu_xhpc: '20231208' cinn: False >>> # doctest: -SKIP @@ -180,6 +190,7 @@ def show(): cudnn: '7.6.5' xpu: '20230114' xpu_xccl: '1.0.7' + xpu_xhpc: '20231208' cinn: False >>> # doctest: -SKIP @@ -196,6 +207,7 @@ def show(): print('cudnn:', cudnn_version) print('xpu:', xpu_version) print('xpu_xccl:', xpu_xccl_version) + print('xpu_xhpc:', xpu_xhpc_version) print('cinn:', cinn_version) def mkl(): @@ -273,6 +285,24 @@ def xpu_xccl(): """ return xpu_xccl_version +def xpu_xhpc(): + """Get xpu xhpc version of paddle package. + + Returns: + string: Return the version information of xpu xhpc. If paddle package is non-XPU version, it will return False. + + Examples: + .. code-block:: python + + >>> import paddle + + >>> paddle.version.xpu_xhpc() + >>> # doctest: +SKIP('Different environments yield different output.') + '20231208' + + """ + return xpu_xhpc_version + def cinn(): """Get CINN version of paddle package. @@ -312,6 +342,7 @@ def cinn(): 'cudnn': get_cudnn_version(), 'xpu': get_xpu_version(), 'xpu_xccl': get_xpu_xccl_version(), + 'xpu_xhpc': get_xpu_xhpc_version(), 'commit': commit, 'istaged': is_taged(), 'with_mkl': '@WITH_MKL@', @@ -731,6 +762,12 @@ if '${WITH_XPTI}' == 'ON': shutil.copy('${XPU_XPTI_LIB}', libs_path) package_data['paddle.libs']+=['${XPU_XPTI_LIB_NAME}'] +if '${WITH_XPU_XHPC}' == 'ON': + shutil.copy('${XPU_XBLAS_LIB}', libs_path) + package_data['paddle.libs'] += ['${XPU_XBLAS_LIB_NAME}'] + shutil.copy('${XPU_XFA_LIB}', libs_path) + package_data['paddle.libs'] += ['${XPU_XFA_LIB_NAME}'] + # remove unused paddle/libs/__init__.py if os.path.isfile(libs_path+'/__init__.py'): os.remove(libs_path+'/__init__.py') diff --git a/setup.py b/setup.py index dc89e1f5434d9c..2af84e06c04864 100644 --- a/setup.py +++ b/setup.py @@ -399,6 +399,14 @@ def get_xpu_xccl_version(): return 'False' +def get_xpu_xhpc_version(): + with_xpu_xhpc = env_dict.get("WITH_XPU_XHPC") + if with_xpu_xhpc == 'ON': + return env_dict.get("XPU_XHPC_BASE_DATE") + else: + return 'False' + + def is_taged(): try: cmd = [ @@ -445,12 +453,13 @@ def write_version_py(filename='paddle/version/__init__.py'): cudnn_version = '%(cudnn)s' xpu_version = '%(xpu)s' xpu_xccl_version = '%(xpu_xccl)s' +xpu_xhpc_version = '%(xpu_xhpc)s' istaged = %(istaged)s commit = '%(commit)s' with_mkl = '%(with_mkl)s' cinn_version = '%(cinn)s' -__all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl'] +__all__ = ['cuda', 'cudnn', 'show', 'xpu', 'xpu_xccl', 'xpu_xhpc'] def show(): """Get the version of paddle if `paddle` package if tagged. Otherwise, output the corresponding commit id. @@ -477,6 +486,8 @@ def show(): xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed + xpu_xhpc: the xpu xhpc version of package. It will return `False` if non-XPU version paddle package is installed + cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN Examples: @@ -496,6 +507,7 @@ def show(): cudnn: '7.6.5' xpu: '20230114' xpu_xccl: '1.0.7' + xpu_xhpc: '20231208' cinn: False >>> # doctest: -SKIP @@ -507,6 +519,7 @@ def show(): cudnn: '7.6.5' xpu: '20230114' xpu_xccl: '1.0.7' + xpu_xhpc: '20231208' cinn: False >>> # doctest: -SKIP """ @@ -522,6 +535,7 @@ def show(): print('cudnn:', cudnn_version) print('xpu:', xpu_version) print('xpu_xccl:', xpu_xccl_version) + print('xpu_xhpc:', xpu_xhpc_version) print('cinn:', cinn_version) def mkl(): @@ -599,6 +613,24 @@ def xpu_xccl(): """ return xpu_xccl_version +def xpu_xhpc(): + """Get xpu xhpc version of paddle package. + + Returns: + string: Return the version information of xpu xhpc. If paddle package is non-XPU version, it will return False. + + Examples: + .. code-block:: python + + >>> import paddle + + >>> paddle.version.xpu_xhpc() + >>> # doctest: +SKIP('Different environments yield different output.') + '20231208' + + """ + return xpu_xhpc_version + def cinn(): """Get CINN version of paddle package. @@ -640,6 +672,7 @@ def cinn(): 'cudnn': get_cudnn_version(), 'xpu': get_xpu_version(), 'xpu_xccl': get_xpu_xccl_version(), + 'xpu_xhpc': get_xpu_xhpc_version(), 'commit': commit, 'istaged': is_taged(), 'with_mkl': env_dict.get("WITH_MKL"), @@ -1153,6 +1186,12 @@ def get_package_data_and_package_dir(): shutil.copy(env_dict.get("XPU_XPTI_LIB"), libs_path) package_data['paddle.libs'] += [env_dict.get("XPU_XPTI_LIB_NAME")] + if env_dict.get("WITH_XPU_XHPC") == 'ON': + shutil.copy(env_dict.get("XPU_XBLAS_LIB"), libs_path) + package_data['paddle.libs'] += [env_dict.get("XPU_XBLAS_LIB_NAME")] + shutil.copy(env_dict.get("XPU_XFA_LIB"), libs_path) + package_data['paddle.libs'] += [env_dict.get("XPU_XFA_LIB_NAME")] + # remove unused paddle/libs/__init__.py if os.path.isfile(libs_path + '/__init__.py'): os.remove(libs_path + '/__init__.py') diff --git a/tools/xpu/pack_paddle_depence.sh b/tools/xpu/pack_paddle_depence.sh index 0538bf192695bd..2df7c98cbf48ab 100644 --- a/tools/xpu/pack_paddle_depence.sh +++ b/tools/xpu/pack_paddle_depence.sh @@ -17,6 +17,12 @@ set -e set -x +if [[ $# -eq 8 ]]; then + echo "Compiling Paddle with XHPC" + XHPC_URL=$7 + XHPC_DIR_NAME=$8 +fi + XRE_URL=$1 XRE_DIR_NAME=$2 @@ -38,9 +44,29 @@ tar xvf xccl.tar.gz mkdir -p xpu/include/xpu mkdir -p xpu/lib +if ! [ -z ${XHPC_URL} ]; then + echo "Compiling Paddle with XHPC" + echo "XHPC_URL: ${XHPC_URL}" + wget --no-check-certificate ${XHPC_URL} -q -O xhpc.tar.gz + tar xvf xhpc.tar.gz + + mkdir -p xpu/include/xhpc/xblas + mkdir -p xpu/include/xhpc/xfa + + cp -r ${XHPC_DIR_NAME}/xblas/include/* xpu/include/xhpc/xblas + cp -r ${XHPC_DIR_NAME}/xblas/so/* xpu/lib/ + + cp -r ${XHPC_DIR_NAME}/xdnn/include/* xpu/include/ + cp -r ${XHPC_DIR_NAME}/xdnn/so/* xpu/lib + + cp -r ${XHPC_DIR_NAME}/xfa/include/* xpu/include/xhpc/xfa + cp -r ${XHPC_DIR_NAME}/xfa/so/* xpu/lib/ +else + cp -r $XDNN_DIR_NAME/include/xpu/* xpu/include/xpu/ + cp -r $XDNN_DIR_NAME/so/* xpu/lib/ +fi + cp -r $XRE_DIR_NAME/include/xpu/* xpu/include/xpu/ cp -r $XRE_DIR_NAME/so/libxpurt* xpu/lib/ -cp -r $XDNN_DIR_NAME/include/xpu/* xpu/include/xpu/ -cp -r $XDNN_DIR_NAME/so/libxpuapi.so xpu/lib/ cp -r $XCCL_DIR_NAME/include/* xpu/include/xpu/ cp -r $XCCL_DIR_NAME/so/* xpu/lib/