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

5 6 7 8
include(ExternalProject)
set(XPU_PROJECT "extern_xpu")
set(XPU_API_LIB_NAME "libxpuapi.so")
set(XPU_RT_LIB_NAME "libxpurt.so")
9
set(XPU_XFT_LIB_NAME "libxft.so")
10
set(XPU_XPTI_LIB_NAME "libxpti.so")
11

12
set(XPU_BASE_DATE "20230602")
13
set(XPU_XCCL_BASE_VERSION "1.0.49.2")
14
set(XPU_XFT_BASE_VERSION "latest")
15
set(XPU_XPTI_BASE_VERSION "0.0.1")
16

H
houj04 已提交
17
if(NOT DEFINED XPU_BASE_URL)
18
  set(XPU_BASE_URL_WITHOUT_DATE
H
houj04 已提交
19
      "https://baidu-kunlun-product.su.bcebos.com/KL-SDK/klsdk-dev")
20
  set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/${XPU_BASE_DATE}")
H
houj04 已提交
21
else()
22
  set(XPU_BASE_URL "${XPU_BASE_URL}")
H
houj04 已提交
23 24
endif()

25
set(XPU_XCCL_BASE_URL
26 27
    "https://klx-sdk-release-public.su.bcebos.com/xccl/release/${XPU_XCCL_BASE_VERSION}"
)
28

29 30 31 32 33 34
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()

35 36 37 38
set(XPU_XPTI_BASE_URL
    "https://klx-sdk-release-public.su.bcebos.com/xpti/dev/${XPU_XPTI_BASE_VERSION}"
)

39 40 41 42 43 44
if(WITH_XCCL_RDMA)
  set(XPU_XCCL_PREFIX "xccl_rdma")
else()
  set(XPU_XCCL_PREFIX "xccl_socket")
endif()

45 46
if(WITH_AARCH64)
  set(XPU_XRE_DIR_NAME "xre-kylin_aarch64")
47
  set(XPU_XDNN_DIR_NAME "xdnn-kylin_aarch64")
48
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-kylin_aarch64")
49
  set(XPU_XFT_DIR_NAME "") # TODO: xft has no kylin output at now.
50 51 52
elseif(WITH_SUNWAY)
  set(XPU_XRE_DIR_NAME "xre-deepin_sw6_64")
  set(XPU_XDNN_DIR_NAME "xdnn-deepin_sw6_64")
53
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-deepin_sw6_64")
54
  set(XPU_XFT_DIR_NAME "") # TODO: xft has no deepin output at now.
55 56
elseif(WITH_BDCENTOS)
  set(XPU_XRE_DIR_NAME "xre-bdcentos_x86_64")
57
  set(XPU_XDNN_DIR_NAME "xdnn-bdcentos_x86_64")
58
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-bdcentos_x86_64")
59
  set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82")
60 61
elseif(WITH_UBUNTU)
  set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
62
  set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64")
63
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-ubuntu_x86_64")
64
  set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64")
65 66
elseif(WITH_CENTOS)
  set(XPU_XRE_DIR_NAME "xre-centos7_x86_64")
67
  set(XPU_XDNN_DIR_NAME "xdnn-centos7_x86_64")
68
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-bdcentos_x86_64")
69
  set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82")
70 71
else()
  set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
72
  set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64")
73
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-ubuntu_x86_64")
74
  set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64")
75
endif()
76
set(XPU_XPTI_DIR_NAME "xpti")
T
TTerror 已提交
77

78 79 80
set(XPU_XRE_URL
    "${XPU_BASE_URL}/${XPU_XRE_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
81 82 83
set(XPU_XDNN_URL
    "${XPU_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
84
set(XPU_XCCL_URL
85
    "${XPU_XCCL_BASE_URL}/${XPU_XCCL_DIR_NAME}.tar.gz"
86
    CACHE STRING "" FORCE)
87
set(XPU_XFT_URL "${XPU_XFT_BASE_URL}/${XPU_XFT_DIR_NAME}.tar.gz")
88 89 90
set(XPU_XPTI_URL
    "${XPU_XPTI_BASE_URL}/${XPU_XPTI_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
91 92 93
set(XPU_PACK_DEPENCE_URL
    "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/pack_paddle_depence.sh"
    CACHE STRING "" FORCE)
94 95 96
set(XPU_XFT_GET_DEPENCE_URL
    "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/get_xft_dependence.sh"
    CACHE STRING "" FORCE)
97 98 99
set(XPU_XPTI_GET_DEPENCE_URL
    "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/get_xpti_dependence.sh"
    CACHE STRING "" FORCE)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

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")
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"
T
TTerror 已提交
115 116 117
  "install(DIRECTORY xpu/include xpu/lib \n"
  "        DESTINATION ${XPU_INSTALL_DIR})\n")

R
risemeup1 已提交
118 119 120 121 122 123 124 125 126 127
if(WITH_XPU_BKCL)
  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})
endif()

T
TTerror 已提交
128
ExternalProject_Add(
129 130 131 132 133
  ${XPU_PROJECT}
  ${EXTERNAL_PROJECT_LOG_ARGS}
  PREFIX ${SNAPPY_PREFIX_DIR}
  DOWNLOAD_DIR ${XPU_DOWNLOAD_DIR}
  DOWNLOAD_COMMAND
134 135
    bash ${CMAKE_SOURCE_DIR}/tools/xpu/check_xpu_dependence.sh ${XPU_BASE_URL}
    ${XPU_XCCL_BASE_URL} && wget ${XPU_PACK_DEPENCE_URL} && bash
136
    pack_paddle_depence.sh ${XPU_XRE_URL} ${XPU_XRE_DIR_NAME} ${XPU_XDNN_URL}
137 138
    ${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}
139 140
    ${XPU_XFT_DIR_NAME} && wget ${XPU_XPTI_GET_DEPENCE_URL} && bash
    get_xpti_dependence.sh ${XPU_XPTI_URL} ${XPU_XPTI_DIR_NAME}
141 142 143 144 145
  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}
R
risemeup1 已提交
146 147
  BUILD_BYPRODUCTS ${XPU_RT_LIB}
  BUILD_BYPRODUCTS ${XPU_BKCL_LIB})
148 149 150

include_directories(${XPU_INC_DIR})
add_library(shared_xpuapi SHARED IMPORTED GLOBAL)
151 152 153 154 155 156
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")

157
target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
158

159 160 161 162
if(WITH_XPU_XFT)
  message(STATUS "Compile with XPU XFT!")
  add_definitions(-DPADDLE_WITH_XPU_XFT)

163 164
  set(XPU_XFT_INC_DIR "${XPU_INC_DIR}/xft")
  include_directories(${XPU_XFT_INC_DIR})
165 166 167
  set(XPU_XFT_LIB "${XPU_LIB_DIR}/${XPU_XFT_LIB_NAME}")
endif()

168 169 170 171 172 173
if(WITH_XPU_XPTI)
  message(STATUS "Compile with XPU XPTI!")
  add_definitions(-DPADDLE_WITH_XPU_XPTI)
  set(XPU_XPTI_LIB "${XPU_LIB_DIR}/${XPU_XPTI_LIB_NAME}")
endif()

174 175 176 177
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)
178
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_BKCL_LIB})
179 180
elseif(WITH_XPU_XFT)
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_XFT_LIB})
W
Wilber 已提交
181
else()
182
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
W
Wilber 已提交
183
endif()
184

185 186 187 188
if(WITH_XPU_XPTI)
  target_link_libraries(xpulib ${XPU_XPTI_LIB})
endif()

189
add_dependencies(xpulib ${XPU_PROJECT})
190 191

# Ensure that xpu/api.h can be included without dependency errors.
192 193 194 195 196 197
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)
198 199
add_dependencies(xpu_headers_dummy extern_xpu)
link_libraries(xpu_headers_dummy)