xpu.cmake 5.4 KB
Newer Older
1 2 3 4 5 6
if (NOT WITH_XPU)
    return()
endif()

INCLUDE(ExternalProject)
SET(XPU_PROJECT                 "extern_xpu")
7 8
SET(XPU_API_LIB_NAME            "libxpuapi.so")
SET(XPU_RT_LIB_NAME             "libxpurt.so")
9

H
houj04 已提交
10 11
if(NOT DEFINED XPU_BASE_URL)
  SET(XPU_BASE_URL_WITHOUT_DATE "https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev")
12
  SET(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220511")
H
houj04 已提交
13 14 15 16 17 18 19
else()
  SET(XPU_BASE_URL "${XPU_BASE_URL}")
endif()

# ubuntu and centos: use output by XDNN API team
if(NOT DEFINED XPU_XDNN_BASE_URL)
  SET(XPU_XDNN_BASE_URL_WITHOUT_DATE "https://klx-sdk-release-public.su.bcebos.com/xdnn/dev")
20
  SET(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20220520")
H
houj04 已提交
21 22 23 24
else()
  SET(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL}")
endif()

T
TTerror 已提交
25 26
IF(WITH_AARCH64)
  SET(XPU_XRE_DIR_NAME "xre-kylin_aarch64")
27
  SET(XPU_XDNN_DIR_NAME "XDNN-kylin_aarch64")
T
TTerror 已提交
28
  SET(XPU_XCCL_DIR_NAME "xccl-kylin_aarch64")
29
  SET(XPU_XDNN_URL "${XPU_XDNN_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
T
TTerror 已提交
30 31 32 33
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")
H
houj04 已提交
34
  SET(XPU_XDNN_URL "${XPU_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
T
TTerror 已提交
35 36
ELSEIF(WITH_BDCENTOS)
  SET(XPU_XRE_DIR_NAME "xre-bdcentos_x86_64")
H
houj04 已提交
37
  SET(XPU_XDNN_DIR_NAME "XDNN-bdcentos_x86_64")
T
TTerror 已提交
38
  SET(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64")
H
houj04 已提交
39 40
  # ubuntu and centos: use output by XDNN API team
  SET(XPU_XDNN_URL "${XPU_XDNN_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
T
TTerror 已提交
41 42
ELSEIF(WITH_UBUNTU)
  SET(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
H
houj04 已提交
43
  SET(XPU_XDNN_DIR_NAME "XDNN-ubuntu_x86_64")
T
TTerror 已提交
44
  SET(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64")
H
houj04 已提交
45 46
  # ubuntu and centos: use output by XDNN API team
  SET(XPU_XDNN_URL "${XPU_XDNN_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
T
TTerror 已提交
47 48
ELSEIF(WITH_CENTOS)
  SET(XPU_XRE_DIR_NAME "xre-centos7_x86_64")
H
houj04 已提交
49
  SET(XPU_XDNN_DIR_NAME "XDNN-bdcentos_x86_64")
T
TTerror 已提交
50
  SET(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64")
H
houj04 已提交
51 52 53
  # ubuntu and centos: use output by XDNN API team
  SET(XPU_XDNN_URL "${XPU_XDNN_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
ELSE()
T
TTerror 已提交
54
  SET(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
55
  SET(XPU_XDNN_DIR_NAME "XDNN-ubuntu_x86_64")
T
TTerror 已提交
56
  SET(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64")
H
houj04 已提交
57 58
  # default: use output by XDNN API team
  SET(XPU_XDNN_URL "${XPU_XDNN_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
T
TTerror 已提交
59 60
ENDIF()

T
TTerror 已提交
61
SET(XPU_XRE_URL  "${XPU_BASE_URL}/${XPU_XRE_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
Q
QingshuChen 已提交
62
SET(XPU_XCCL_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220411/${XPU_XCCL_DIR_NAME}.tar.gz" CACHE STRING "" FORCE)
T
TTerror 已提交
63 64
SET(XPU_PACK_DEPENCE_URL "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/pack_paddle_depence.sh" CACHE STRING "" FORCE)

H
houj04 已提交
65
SET(SNAPPY_PREFIX_DIR           "${THIRD_PARTY_PATH}/xpu")
66
SET(XPU_DOWNLOAD_DIR            "${SNAPPY_PREFIX_DIR}/src/${XPU_PROJECT}")
T
TTerror 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
SET(XPU_INSTALL_DIR             "${THIRD_PARTY_PATH}/install/xpu")
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_RT_LIB                  "${XPU_LIB_DIR}/${XPU_RT_LIB_NAME}")

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"
  "        DESTINATION ${XPU_INSTALL_DIR})\n")

ExternalProject_Add(
    ${XPU_PROJECT}
    ${EXTERNAL_PROJECT_LOG_ARGS}
85
    PREFIX                ${SNAPPY_PREFIX_DIR}
T
TTerror 已提交
86 87 88 89 90 91 92 93
    DOWNLOAD_DIR          ${XPU_DOWNLOAD_DIR}
    DOWNLOAD_COMMAND      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}

    DOWNLOAD_NO_PROGRESS  1
    UPDATE_COMMAND        ""
    CMAKE_ARGS            -DCMAKE_INSTALL_PREFIX=${XPU_INSTALL_ROOT}
    CMAKE_CACHE_ARGS      -DCMAKE_INSTALL_PREFIX:PATH=${XPU_INSTALL_ROOT}
94 95
    BUILD_BYPRODUCTS      ${XPU_API_LIB}
    BUILD_BYPRODUCTS      ${XPU_RT_LIB}
T
TTerror 已提交
96
)
97

T
TTerror 已提交
98
INCLUDE_DIRECTORIES(${XPU_INC_DIR})
99 100 101 102 103 104 105
ADD_LIBRARY(shared_xpuapi SHARED IMPORTED GLOBAL)
set_property(TARGET shared_xpuapi PROPERTY IMPORTED_LOCATION "${XPU_API_LIB}")

# generate a static dummy target to track xpulib dependencies
# for cc_library(xxx SRCS xxx.c DEPS xpulib)
generate_dummy_static_lib(LIB_NAME "xpulib" GENERATOR "xpu.cmake")

106
TARGET_LINK_LIBRARIES(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
107

T
TTerror 已提交
108
IF(WITH_XPU_BKCL)
109 110 111 112 113 114 115 116
  MESSAGE(STATUS "Compile with XPU BKCL!")
  ADD_DEFINITIONS(-DPADDLE_WITH_XPU_BKCL)

  SET(XPU_BKCL_LIB_NAME         "libbkcl.so")
  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})
  TARGET_LINK_LIBRARIES(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_BKCL_LIB})
T
TTerror 已提交
117 118 119
ELSE(WITH_XPU_BKCL)
  TARGET_LINK_LIBRARIES(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
ENDIF(WITH_XPU_BKCL)
120

121
ADD_DEPENDENCIES(xpulib ${XPU_PROJECT})
122 123 124 125 126 127

# Ensure that xpu/api.h can be included without dependency errors.
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/.xpu_headers_dummy.cc CONTENT "")
add_library(xpu_headers_dummy STATIC ${CMAKE_CURRENT_BINARY_DIR}/.xpu_headers_dummy.cc)
add_dependencies(xpu_headers_dummy extern_xpu)
link_libraries(xpu_headers_dummy)