未验证 提交 9343782b 编写于 作者: 石晓伟 提交者: GitHub

support dynamic cuda libs, test=develop (#2780)

上级 9611e046
......@@ -75,7 +75,7 @@ lite_option(LITE_BUILD_EXTRA "Enable extra algorithm support in Lite, both kerne
lite_option(LITE_BUILD_TAILOR "Enable tailoring library according to model" OFF)
# cv build options
lite_option(LITE_WITH_CV "Enable build cv image in lite" OFF)
lite_option(LITE_WITH_STATIC_CUDA "Statically link cuda libraries." ON)
# TODO(Superjomn) Remove WITH_ANAKIN option if not needed latter.
if(ANDROID OR IOS OR ARMLINUX)
......
......@@ -174,27 +174,45 @@ if(NOT WITH_DSO)
endif(WIN32)
endif(NOT WITH_DSO)
function(add_cuda_static_lib alias cuda_lib_paths file_name)
unset(ABS_PATH CACHE)
find_library(ABS_PATH NAMES ${file_name} PATHS ${${cuda_lib_paths}} NO_DEFAULT_PATH)
add_library(${alias} STATIC IMPORTED GLOBAL)
set_property(TARGET ${alias} PROPERTY IMPORTED_LOCATION ${ABS_PATH})
set(CUDA_STATIC_MODULES ${CUDA_STATIC_MODULES} ${alias} PARENT_SCOPE)
if (NOT ABS_PATH)
message(FATAL_ERROR "Can not find CUDA static library: ${file_name}")
endif()
function(add_cuda_lib TARGET_NAME)
set(options STATIC SHARED)
set(oneValueArgs "NAME")
set(multiValueArgs "PATHS")
cmake_parse_arguments(add_cuda_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
unset(ABS_PATH CACHE)
if (NOT add_cuda_lib_PATHS)
set(add_cuda_lib_PATHS CUDNN_CHECK_LIBRARY_DIRS)
endif()
find_library(ABS_PATH NAMES ${add_cuda_lib_NAME} PATHS ${${add_cuda_lib_PATHS}} NO_DEFAULT_PATH)
add_library(${TARGET_NAME} SHARED IMPORTED GLOBAL)
set_property(TARGET ${TARGET_NAME} PROPERTY IMPORTED_LOCATION ${ABS_PATH})
set(CUDA_MODULES ${CUDA_MODULES} ${TARGET_NAME} PARENT_SCOPE)
if (NOT ABS_PATH)
message(FATAL_ERROR "Can not find CUDA library: ${add_cuda_lib_NAME}")
endif()
endfunction()
add_cuda_static_lib(cudart_static CUDNN_CHECK_LIBRARY_DIRS libcudart_static.a)
add_cuda_static_lib(cublas_static CUDNN_CHECK_LIBRARY_DIRS libcublas_static.a)
add_cuda_static_lib(curand_static CUDNN_CHECK_LIBRARY_DIRS libcurand_static.a)
add_cuda_static_lib(culibos_static CUDNN_CHECK_LIBRARY_DIRS libculibos.a)
if(NOT ${CUDA_VERSION} LESS 10.1)
add_cuda_static_lib(cublasLt_static CUDNN_CHECK_LIBRARY_DIRS libcublasLt_static.a)
if(LITE_WITH_STATIC_CUDA)
message(STATUS "Static link CUDA toolkit.")
add_cuda_lib(cudart_static STATIC NAME libcudart_static.a)
add_cuda_lib(cublas_static STATIC NAME libcublas_static.a)
add_cuda_lib(curand_static STATIC NAME libcurand_static.a)
add_cuda_lib(culibos_static STATIC NAME libculibos.a)
if(NOT ${CUDA_VERSION} LESS 10.1)
add_cuda_lib(cublasLt_static STATIC NAME libcublasLt_static.a)
endif()
set_property(GLOBAL PROPERTY CUDA_MODULES cudnn_static ${CUDA_MODULES})
else()
message(STATUS "Dynamic Link CUDA toolkit.")
add_cuda_lib(cudart SHARED NAME libcudart.so)
add_cuda_lib(cublas SHARED NAME libcublas.so)
add_cuda_lib(curand SHARED NAME libcurand.so)
if(NOT ${CUDA_VERSION} LESS 10.1)
add_cuda_lib(cublasLt SHARED NAME libcublasLt.so)
endif()
set_property(GLOBAL PROPERTY CUDA_MODULES cudnn ${CUDA_MODULES})
endif()
set_property(GLOBAL PROPERTY CUDA_STATIC_MODULES cudnn_static ${CUDA_STATIC_MODULES})
# setting nvcc arch flags
select_nvcc_arch_flags(NVCC_FLAGS_EXTRA)
list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA})
......
......@@ -69,9 +69,15 @@ if(CUDNN_FOUND)
file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_VERSION_FILE_CONTENTS)
get_filename_component(CUDNN_LIB_PATH ${CUDNN_LIBRARY} DIRECTORY)
add_library(cudnn_static STATIC IMPORTED GLOBAL)
set_property(TARGET cudnn_static PROPERTY IMPORTED_LOCATION
if(LITE_WITH_STATIC_CUDA)
add_library(cudnn_static STATIC IMPORTED GLOBAL)
set_property(TARGET cudnn_static PROPERTY IMPORTED_LOCATION
"${CUDNN_LIB_PATH}/libcudnn_static.a")
else()
add_library(cudnn SHARED IMPORTED GLOBAL)
set_property(TARGET cudnn PROPERTY IMPORTED_LOCATION
"${CUDNN_LIB_PATH}/libcudnn.so")
endif(LITE_WITH_STATIC_CUDA)
string(REGEX MATCH "define CUDNN_VERSION +([0-9]+)"
CUDNN_VERSION "${CUDNN_VERSION_FILE_CONTENTS}")
......
......@@ -35,13 +35,12 @@ if ((NOT LITE_ON_TINY_PUBLISH) AND (LITE_WITH_CUDA OR LITE_WITH_X86 OR ARM_TARGE
NPU_DEPS ${npu_kernels})
target_link_libraries(paddle_light_api_shared ${light_lib_DEPS} ${arm_kernels} ${npu_kernels})
if (LITE_WITH_NPU)
# Strips the symbols of our protobuf functions to fix the conflicts during
# loading HIAI builder libs (libhiai_ir.so and libhiai_ir_build.so)
set(LINK_FLAGS "-Wl,--version-script ${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set_target_properties(paddle_light_api_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
set(LINK_MAP_FILE "${PADDLE_SOURCE_DIR}/lite/core/lite.map")
set(LINK_FLAGS "-Wl,--version-script ${LINK_MAP_FILE}")
add_custom_command(OUTPUT ${LINK_MAP_FILE} COMMAND ...)
add_custom_target(custom_linker_map DEPENDS ${LINK_MAP_FILE})
set_target_properties(paddle_full_api_shared PROPERTIES LINK_FLAGS ${LINK_FLAGS})
add_dependencies(paddle_full_api_shared custom_linker_map)
else()
if ((ARM_TARGET_OS STREQUAL "android") OR (ARM_TARGET_OS STREQUAL "armlinux"))
add_library(paddle_light_api_shared SHARED "")
......@@ -106,7 +105,7 @@ endif()
set(light_api_deps
scope target_wrapper_host model_parser program)
if(LITE_WITH_CUDA)
get_property(cuda_static_deps GLOBAL PROPERTY CUDA_STATIC_MODULES)
get_property(cuda_deps GLOBAL PROPERTY CUDA_MODULES)
set(light_api_deps ${light_api_deps} target_wrapper_cuda)
endif()
lite_cc_library(light_api SRCS light_api.cc
......@@ -258,9 +257,10 @@ if (NOT LITE_ON_TINY_PUBLISH)
FPGA_DEPS ${fpga_kernels})
# The final inference library for just MobileConfig.
bundle_static_library(paddle_api_full paddle_api_full_bundled bundle_full_api)
target_link_libraries(paddle_api_full ${cuda_deps})
get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
cc_library(api_full_static SRCS DEPS paddle_api_full cxx_api paddle_api light_api ${cxx_api_deps} ${ops} ${host_kernels} ${cuda_kernels} program tensor memory naive_buffer types ${fluid_modules} protobuf ${cuda_static_deps})
endif()
bundle_static_library(paddle_api_light paddle_api_light_bundled bundle_light_api)
#-----------------------------------------------------------------------------------------------------
......
if(NOT LITE_WITH_CUDA)
return()
endif()
get_property(cuda_static_deps GLOBAL PROPERTY CUDA_STATIC_MODULES)
get_property(cuda_deps GLOBAL PROPERTY CUDA_MODULES)
nv_library(target_wrapper_cuda SRCS target_wrapper.cc DEPS ${cuda_static_deps})
nv_library(cuda_blas SRCS blas.cc DEPS ${cuda_static_deps})
nv_library(target_wrapper_cuda SRCS target_wrapper.cc DEPS ${cuda_deps})
nv_library(cuda_blas SRCS blas.cc DEPS ${cuda_deps})
add_subdirectory(math)
{
global:
*paddle*;
*touch_*;
*mir_pass_*;
local:
*;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册