xpu.cmake 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15 16
if(NOT WITH_XPU)
  return()
17 18
endif()

19 20 21 22
include(ExternalProject)
set(XPU_PROJECT "extern_xpu")
set(XPU_API_LIB_NAME "libxpuapi.so")
set(XPU_RT_LIB_NAME "libxpurt.so")
23
set(XPU_XFT_LIB_NAME "libxft.so")
24
set(XPU_XPTI_LIB_NAME "libxpti.so")
25

26
if(NOT DEFINED XPU_BASE_DATE)
27
  set(XPU_BASE_DATE "20230810")
28
endif()
29
set(XPU_XCCL_BASE_VERSION "1.0.53.6")
30 31 32
if(NOT DEFINED XPU_XFT_BASE_VERSION)
  set(XPU_XFT_BASE_VERSION "20230602")
endif()
33
set(XPU_XPTI_BASE_VERSION "0.0.1")
34

H
houj04 已提交
35
if(NOT DEFINED XPU_BASE_URL)
36
  set(XPU_BASE_URL_WITHOUT_DATE
H
houj04 已提交
37
      "https://baidu-kunlun-product.su.bcebos.com/KL-SDK/klsdk-dev")
38
  set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/${XPU_BASE_DATE}")
H
houj04 已提交
39
else()
40
  set(XPU_BASE_URL "${XPU_BASE_URL}")
H
houj04 已提交
41 42
endif()

43
set(XPU_XCCL_BASE_URL
44 45
    "https://klx-sdk-release-public.su.bcebos.com/xccl/release/${XPU_XCCL_BASE_VERSION}"
)
46

47 48 49 50 51 52
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()

53 54 55 56
set(XPU_XPTI_BASE_URL
    "https://klx-sdk-release-public.su.bcebos.com/xpti/dev/${XPU_XPTI_BASE_VERSION}"
)

57 58 59 60 61 62
if(WITH_XCCL_RDMA)
  set(XPU_XCCL_PREFIX "xccl_rdma")
else()
  set(XPU_XCCL_PREFIX "xccl_socket")
endif()

63 64
if(WITH_AARCH64)
  set(XPU_XRE_DIR_NAME "xre-kylin_aarch64")
65
  set(XPU_XDNN_DIR_NAME "xdnn-kylin_aarch64")
66
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-kylin_aarch64")
67
  set(XPU_XFT_DIR_NAME "") # TODO: xft has no kylin output at now.
68 69 70
elseif(WITH_SUNWAY)
  set(XPU_XRE_DIR_NAME "xre-deepin_sw6_64")
  set(XPU_XDNN_DIR_NAME "xdnn-deepin_sw6_64")
71
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-deepin_sw6_64")
72
  set(XPU_XFT_DIR_NAME "") # TODO: xft has no deepin output at now.
73 74
elseif(WITH_BDCENTOS)
  set(XPU_XRE_DIR_NAME "xre-bdcentos_x86_64")
75
  set(XPU_XDNN_DIR_NAME "xdnn-bdcentos_x86_64")
76
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-bdcentos_x86_64")
77
  set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82")
78 79
elseif(WITH_UBUNTU)
  set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
80
  set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64")
81
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-ubuntu_x86_64")
82
  set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64")
83 84
elseif(WITH_CENTOS)
  set(XPU_XRE_DIR_NAME "xre-centos7_x86_64")
85
  set(XPU_XDNN_DIR_NAME "xdnn-centos7_x86_64")
86
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-bdcentos_x86_64")
87
  set(XPU_XFT_DIR_NAME "xft_bdcentos6u3_x86_64_gcc82")
88 89
else()
  set(XPU_XRE_DIR_NAME "xre-ubuntu_x86_64")
90
  set(XPU_XDNN_DIR_NAME "xdnn-ubuntu_x86_64")
91
  set(XPU_XCCL_DIR_NAME "${XPU_XCCL_PREFIX}-ubuntu_x86_64")
92
  set(XPU_XFT_DIR_NAME "xft_ubuntu1604_x86_64")
93
endif()
94
set(XPU_XPTI_DIR_NAME "xpti")
T
TTerror 已提交
95

96 97 98
set(XPU_XRE_URL
    "${XPU_BASE_URL}/${XPU_XRE_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
99 100 101
set(XPU_XDNN_URL
    "${XPU_BASE_URL}/${XPU_XDNN_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
102
set(XPU_XCCL_URL
103
    "${XPU_XCCL_BASE_URL}/${XPU_XCCL_DIR_NAME}.tar.gz"
104
    CACHE STRING "" FORCE)
105
set(XPU_XFT_URL "${XPU_XFT_BASE_URL}/${XPU_XFT_DIR_NAME}.tar.gz")
106 107 108
set(XPU_XPTI_URL
    "${XPU_XPTI_BASE_URL}/${XPU_XPTI_DIR_NAME}.tar.gz"
    CACHE STRING "" FORCE)
109 110 111
set(XPU_XFT_GET_DEPENCE_URL
    "https://baidu-kunlun-public.su.bcebos.com/paddle_depence/get_xft_dependence.sh"
    CACHE STRING "" FORCE)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

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 已提交
127 128 129
  "install(DIRECTORY xpu/include xpu/lib \n"
  "        DESTINATION ${XPU_INSTALL_DIR})\n")

R
risemeup1 已提交
130 131 132 133 134 135 136 137 138 139
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 已提交
140
ExternalProject_Add(
141 142 143 144 145
  ${XPU_PROJECT}
  ${EXTERNAL_PROJECT_LOG_ARGS}
  PREFIX ${SNAPPY_PREFIX_DIR}
  DOWNLOAD_DIR ${XPU_DOWNLOAD_DIR}
  DOWNLOAD_COMMAND
146
    bash ${CMAKE_SOURCE_DIR}/tools/xpu/check_xpu_dependence.sh ${XPU_BASE_URL}
H
houj04 已提交
147 148 149 150
    ${XPU_XCCL_BASE_URL} && 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
151 152
    get_xft_dependence.sh ${XPU_XFT_URL} ${XPU_XFT_DIR_NAME} &&
    WITH_XPTI=${WITH_XPTI} bash
153 154
    ${CMAKE_SOURCE_DIR}/tools/xpu/get_xpti_dependence.sh ${XPU_XPTI_URL}
    ${XPU_XPTI_DIR_NAME}
155 156 157 158 159
  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 已提交
160 161
  BUILD_BYPRODUCTS ${XPU_RT_LIB}
  BUILD_BYPRODUCTS ${XPU_BKCL_LIB})
162 163 164

include_directories(${XPU_INC_DIR})
add_library(shared_xpuapi SHARED IMPORTED GLOBAL)
165 166 167 168 169 170
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")

171
target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
172

173 174 175 176
if(WITH_XPU_XFT)
  message(STATUS "Compile with XPU XFT!")
  add_definitions(-DPADDLE_WITH_XPU_XFT)

177 178
  set(XPU_XFT_INC_DIR "${XPU_INC_DIR}/xft")
  include_directories(${XPU_XFT_INC_DIR})
179 180 181
  set(XPU_XFT_LIB "${XPU_LIB_DIR}/${XPU_XFT_LIB_NAME}")
endif()

182
if(WITH_XPTI)
183
  message(STATUS "Compile with XPU XPTI!")
184
  add_definitions(-DPADDLE_WITH_XPTI)
185 186 187
  set(XPU_XPTI_LIB "${XPU_LIB_DIR}/${XPU_XPTI_LIB_NAME}")
endif()

188 189 190 191 192 193
if(WITH_XPU_PLUGIN)
  message(STATUS "Compile with XPU PLUGIN!")
  add_definitions(-DPADDLE_WITH_XPU_PLUGIN)
  include_directories(${CMAKE_SOURCE_DIR}/paddle/phi/kernels/xpu/plugin/include)
endif()

194 195 196 197
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)
198
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_BKCL_LIB})
199 200
elseif(WITH_XPU_XFT)
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB} ${XPU_XFT_LIB})
W
Wilber 已提交
201
else()
202
  target_link_libraries(xpulib ${XPU_API_LIB} ${XPU_RT_LIB})
W
Wilber 已提交
203
endif()
204

205
if(WITH_XPTI)
206 207 208
  target_link_libraries(xpulib ${XPU_XPTI_LIB})
endif()

209
add_dependencies(xpulib ${XPU_PROJECT})
210 211

# Ensure that xpu/api.h can be included without dependency errors.
212 213 214 215 216 217
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)
218 219
add_dependencies(xpu_headers_dummy extern_xpu)
link_libraries(xpu_headers_dummy)