提交 d00d0985 编写于 作者: C Chunwei

Merge branch 'chunwei/publish-library' into 'incubate/lite'

refine inference publishing

See merge request inference/paddlelite!72
# Bundle several static libraries into one.
function(bundle_static_library tgt_name bundled_tgt_name fake_target)
list(APPEND static_libs ${tgt_name})
function(_recursively_collect_dependencies input_target)
set(_input_link_libraries LINK_LIBRARIES)
get_target_property(_input_type ${input_target} TYPE)
if (${_input_type} STREQUAL "INTERFACE_LIBRARY")
set(_input_link_libraries INTERFACE_LINK_LIBRARIES)
endif()
get_target_property(public_dependencies ${input_target} ${_input_link_libraries})
foreach(dependency IN LISTS public_dependencies)
if(TARGET ${dependency})
get_target_property(alias ${dependency} ALIASED_TARGET)
if (TARGET ${alias})
set(dependency ${alias})
endif()
get_target_property(_type ${dependency} TYPE)
if (${_type} STREQUAL "STATIC_LIBRARY")
list(APPEND static_libs ${dependency})
endif()
get_property(library_already_added
GLOBAL PROPERTY _${tgt_name}_static_bundle_${dependency})
if (NOT library_already_added)
set_property(GLOBAL PROPERTY _${tgt_name}_static_bundle_${dependency} ON)
_recursively_collect_dependencies(${dependency})
endif()
endif()
endforeach()
set(static_libs ${static_libs} PARENT_SCOPE)
endfunction()
_recursively_collect_dependencies(${tgt_name})
list(REMOVE_DUPLICATES static_libs)
set(bundled_tgt_full_name
${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${bundled_tgt_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "+++++ bundled_tgt_full_name: ${bundled_tgt_full_name}")
file(WRITE ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in
"CREATE ${bundled_tgt_full_name}\n" )
foreach(tgt IN LISTS static_libs)
file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in
"ADDLIB $<TARGET_FILE:${tgt}>\n")
endforeach()
file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in "SAVE\n")
file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in "END\n")
file(GENERATE
OUTPUT ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar
INPUT ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in)
set(ar_tool ${CMAKE_AR})
if (CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(ar_tool ${CMAKE_CXX_COMPILER_AR})
endif()
add_custom_command(
COMMAND ${ar_tool} -M < ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar
OUTPUT ${bundled_tgt_full_name}
COMMENT "Bundling ${bundled_tgt_name}"
VERBATIM)
add_custom_target(${fake_target} ALL DEPENDS ${bundled_tgt_full_name})
add_dependencies(${fake_target} ${tgt_name})
add_library(${bundled_tgt_name} STATIC IMPORTED)
set_target_properties(${bundled_tgt_name}
PROPERTIES
IMPORTED_LOCATION ${bundled_tgt_full_name}
INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${tgt_name},INTERFACE_INCLUDE_DIRECTORIES>)
add_dependencies(${bundled_tgt_name} ${fake_target})
endfunction()
...@@ -2,6 +2,8 @@ if (NOT WITH_LITE) ...@@ -2,6 +2,8 @@ if (NOT WITH_LITE)
return() return()
endif() endif()
include(lite)
message(WARNING "Lite enabled!") message(WARNING "Lite enabled!")
message(STATUS "LIGHT_FRAMEWORK:\t${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK}") message(STATUS "LIGHT_FRAMEWORK:\t${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK}")
message(STATUS "LITE_WITH_CUDA:\t${LITE_WITH_CUDA}") message(STATUS "LITE_WITH_CUDA:\t${LITE_WITH_CUDA}")
...@@ -85,9 +87,9 @@ function (lite_deps TARGET) ...@@ -85,9 +87,9 @@ function (lite_deps TARGET)
endif() endif()
set(${TARGET} ${deps} PARENT_SCOPE) set(${TARGET} ${deps} PARENT_SCOPE)
endfunction() endfunction()
# A fake target to include all the libraries and tests the lite module depends. # A fake target to include all the libraries and tests the lite module depends.
add_custom_target(lite_compile_deps COMMAND echo 1) add_custom_target(lite_compile_deps COMMAND echo 1)
...@@ -95,6 +97,10 @@ add_custom_target(lite_compile_deps COMMAND echo 1) ...@@ -95,6 +97,10 @@ add_custom_target(lite_compile_deps COMMAND echo 1)
# the whole fluid project to accelerate the compile speed. # the whole fluid project to accelerate the compile speed.
set(offline_lib_registry_file "${CMAKE_BINARY_DIR}/lite_libs.txt") set(offline_lib_registry_file "${CMAKE_BINARY_DIR}/lite_libs.txt")
file(WRITE ${offline_lib_registry_file} "") # clean file(WRITE ${offline_lib_registry_file} "") # clean
set(__lite_cc_files "";"")
set(__lite_cc_files "${CMAKE_BINARY_DIR}/lite_cc_files.txt")
file(WRITE ${__lite_cc_files} "") # clean
# cc_library with branch support. # cc_library with branch support.
# The branches: # The branches:
# X86_DEPS: works only when LITE_WITH_X86 is ON. # X86_DEPS: works only when LITE_WITH_X86 is ON.
...@@ -126,8 +132,14 @@ function(lite_cc_library TARGET) ...@@ -126,8 +132,14 @@ function(lite_cc_library TARGET)
cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS}) cc_library(${TARGET} SRCS ${args_SRCS} DEPS ${deps} ${args_DEPS})
endif() endif()
foreach(cc_file ${args_SRCS})
file(APPEND ${__lite_cc_files} "${cc_file}\n")
endforeach()
# collect targets need to compile for lite # collect targets need to compile for lite
if (args_SRCS)
add_dependencies(lite_compile_deps ${TARGET}) add_dependencies(lite_compile_deps ${TARGET})
endif()
# register a library name. # register a library name.
file(APPEND ${offline_lib_registry_file} "${TARGET}\n") file(APPEND ${offline_lib_registry_file} "${TARGET}\n")
...@@ -224,9 +236,9 @@ add_custom_target(publish_inference_cxx_lib ${TARGET} ...@@ -224,9 +236,9 @@ add_custom_target(publish_inference_cxx_lib ${TARGET}
COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/lib" COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/include" COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include" COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include"
COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/libpaddle_api_full.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib" COMMAND cp "${CMAKE_BINARY_DIR}/libpaddle_api_full_bundled.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib"
) )
add_dependencies(publish_inference_cxx_lib paddle_api_full) add_dependencies(publish_inference_cxx_lib bundle_full_api)
add_dependencies(publish_inference_lite publish_inference_cxx_lib) add_dependencies(publish_inference_lite publish_inference_cxx_lib)
if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
...@@ -235,9 +247,9 @@ if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) ...@@ -235,9 +247,9 @@ if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
add_custom_target(publish_inference_mobile_lib ${TARGET} add_custom_target(publish_inference_mobile_lib ${TARGET}
COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/mobile/lib" COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/mobile/lib"
COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/mobile/include" COMMAND mkdir -p "${INFER_LITE_PUBLISH_ROOT}/mobile/include"
COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/cxx/include" COMMAND cp "${CMAKE_SOURCE_DIR}/paddle/fluid/lite/api/paddle_*.h" "${INFER_LITE_PUBLISH_ROOT}/mobile/include"
COMMAND cp "${CMAKE_BINARY_DIR}/paddle/fluid/lite/api/libpaddle_api_light.a" "${INFER_LITE_PUBLISH_ROOT}/cxx/lib" COMMAND cp "${CMAKE_BINARY_DIR}/libpaddle_api_light_bundled.a" "${INFER_LITE_PUBLISH_ROOT}/mobile/lib"
) )
add_dependencies(publish_inference_mobile_lib paddle_api_light) add_dependencies(publish_inference_mobile_lib paddle_api_light bundle_light_api)
add_dependencies(publish_inference_lite publish_inference_mobile_lib) add_dependencies(publish_inference_lite publish_inference_mobile_lib)
endif() endif()
...@@ -102,9 +102,20 @@ lite_cc_test(test_apis_lite SRCS apis_test.cc ...@@ -102,9 +102,20 @@ lite_cc_test(test_apis_lite SRCS apis_test.cc
lite_cc_library(paddle_api_lite SRCS paddle_api.cc DEPS op_params_lite) lite_cc_library(paddle_api_lite SRCS paddle_api.cc DEPS op_params_lite)
lite_cc_library(paddle_api_full SRCS cxx_api_impl.cc DEPS cxx_api_lite paddle_api_lite light_api_lite) #-----------------------------------------------------------------------------------------------------
# The final inference library for both CxxConfig and MobileConfig.
lite_cc_library(paddle_api_full SRCS cxx_api_impl.cc DEPS cxx_api_lite paddle_api_lite light_api_lite
${ops_lite}
ARM_DEPS ${arm_kernels}
)
# The final inference library for just MobileConfig.
lite_cc_library(paddle_api_light SRCS light_api_impl.cc DEPS light_api_lite paddle_api_lite) lite_cc_library(paddle_api_light SRCS light_api_impl.cc DEPS light_api_lite paddle_api_lite)
bundle_static_library(paddle_api_full paddle_api_full_bundled bundle_full_api)
bundle_static_library(paddle_api_light paddle_api_light_bundled bundle_light_api)
#-----------------------------------------------------------------------------------------------------
lite_cc_test(test_paddle_api_lite SRCS paddle_api_test.cc DEPS paddle_api_full paddle_api_light lite_cc_test(test_paddle_api_lite SRCS paddle_api_test.cc DEPS paddle_api_full paddle_api_light
${ops_lite} ${ops_lite}
ARM_DEPS ${arm_kernels} ARM_DEPS ${arm_kernels}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册