xpu.cmake 4.5 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

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

18
set(XPU_XCCL_BASE_URL
R
Roc 已提交
19
    "https://klx-sdk-release-public.su.bcebos.com/xccl/release/1.0.6")
20

21 22
if(WITH_AARCH64)
  set(XPU_XRE_DIR_NAME "xre-kylin_aarch64")
23
  set(XPU_XDNN_DIR_NAME "xdnn-kylin_aarch64")
24 25 26 27 28 29 30
  set(XPU_XCCL_DIR_NAME "xccl-kylin_aarch64")
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")
elseif(WITH_BDCENTOS)
  set(XPU_XRE_DIR_NAME "xre-bdcentos_x86_64")
31
  set(XPU_XDNN_DIR_NAME "xdnn-bdcentos_x86_64")
32 33 34
  set(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64")
elseif(WITH_UBUNTU)
  set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
35
  set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64")
H
houj04 已提交
36
  set(XPU_XCCL_DIR_NAME "xccl-ubuntu_x86_64")
37 38
elseif(WITH_CENTOS)
  set(XPU_XRE_DIR_NAME "xre-centos7_x86_64")
39
  set(XPU_XDNN_DIR_NAME "xdnn-centos7_x86_64")
40 41 42
  set(XPU_XCCL_DIR_NAME "xccl-bdcentos_x86_64")
else()
  set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
43
  set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64")
H
houj04 已提交
44
  set(XPU_XCCL_DIR_NAME "xccl-ubuntu_x86_64")
45
endif()
T
TTerror 已提交
46

47 48 49
set(XPU_XRE_URL
    "${XPU_BASE_URL}/${XPU_XRE_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
50 51 52
set(XPU_XDNN_URL
    "${XPU_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
53
set(XPU_XCCL_URL
54
    "${XPU_XCCL_BASE_URL}/${XPU_XCCL_DIR_NAME}.tar.gz"
55 56 57 58
    CACHE STRING "" FORCE)
set(XPU_PACK_DEPENCE_URL
    "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/pack_paddle_depence.sh"
    CACHE STRING "" FORCE)
59 60 61
set(XPU_CHECK_DEPENCE_URL
    "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/check_xpu_dependence.sh"
    CACHE STRING "" FORCE)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

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 已提交
77 78 79 80
  "install(DIRECTORY xpu/include xpu/lib \n"
  "        DESTINATION ${XPU_INSTALL_DIR})\n")

ExternalProject_Add(
81 82 83 84 85
  ${XPU_PROJECT}
  ${EXTERNAL_PROJECT_LOG_ARGS}
  PREFIX ${SNAPPY_PREFIX_DIR}
  DOWNLOAD_DIR ${XPU_DOWNLOAD_DIR}
  DOWNLOAD_COMMAND
86 87 88 89
    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}
90 91 92 93 94 95 96 97 98
  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_RT_LIB})

include_directories(${XPU_INC_DIR})
add_library(shared_xpuapi SHARED IMPORTED GLOBAL)
99 100 101 102 103 104
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")

105
target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
106

107 108 109
if(WITH_XPU_BKCL)
  message(STATUS "Compile with XPU BKCL!")
  add_definitions(-DPADDLE_WITH_XPU_BKCL)
110

111 112 113 114 115
  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})
W
Wilber 已提交
116
else()
117
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
W
Wilber 已提交
118
endif()
119

120
add_dependencies(xpulib ${XPU_PROJECT})
121 122

# Ensure that xpu/api.h can be included without dependency errors.
123 124 125 126 127 128
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)
129 130
add_dependencies(xpu_headers_dummy extern_xpu)
link_libraries(xpu_headers_dummy)