Skip to content

Commit 1575c2c

Browse files
authored
Merge pull request #7572 from luotao1/fluid_infer
compile and install the shared library of fluid inference
2 parents bdf57a2 + 8b442e8 commit 1575c2c

File tree

10 files changed

+66
-11
lines changed

10 files changed

+66
-11
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ option(WITH_COVERAGE "Compile PaddlePaddle with code coverage" OFF)
5555
option(COVERALLS_UPLOAD "Package code coverage data to coveralls" OFF)
5656
option(ON_TRAVIS "Exclude special unit test on Travis CI" OFF)
5757
option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF)
58+
# TODO: Only compile PaddlePaddle fluid version by WITH_FLUID option.
59+
option(WITH_FLUID "Compile PaddlePaddle fluid only(TODO)" ON)
5860
option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF)
5961
option(GLIDE_INSTALL "Download and install go dependencies " ON)
6062
option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF)
@@ -107,6 +109,10 @@ if (WITH_C_API AND WITH_PYTHON)
107109
"different Python interpreter from compiling.")
108110
endif()
109111

112+
if (WITH_C_API)
113+
set(WITH_FLUID OFF CACHE STRING "Disable install fluid when compile the C_API" FORCE)
114+
endif()
115+
110116
if(MOBILE_INFERENCE)
111117
set(THIRD_PARTY_BUILD_TYPE MinSizeRel)
112118
else()

cmake/external/eigen.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
INCLUDE(ExternalProject)
22

33
SET(EIGEN_SOURCE_DIR ${THIRD_PARTY_PATH}/eigen3)
4-
5-
INCLUDE_DIRECTORIES(${EIGEN_SOURCE_DIR}/src/extern_eigen3)
4+
SET(EIGEN_INCLUDE_DIR ${EIGEN_SOURCE_DIR}/src/extern_eigen3)
5+
INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIR})
66

77
ExternalProject_Add(
88
extern_eigen3
@@ -28,3 +28,9 @@ endif()
2828
add_dependencies(eigen3 extern_eigen3)
2929

3030
LIST(APPEND external_project_dependencies eigen3)
31+
32+
IF(NOT WITH_C_API AND WITH_FLUID)
33+
INSTALL(FILES ${EIGEN_INCLUDE_DIR}/Eigen/Core DESTINATION third_party/eigen3/Eigen)
34+
INSTALL(DIRECTORY ${EIGEN_INCLUDE_DIR}/Eigen/src DESTINATION third_party/eigen3/Eigen)
35+
INSTALL(DIRECTORY ${EIGEN_INCLUDE_DIR}/unsupported/Eigen DESTINATION third_party/eigen3/unsupported)
36+
ENDIF()

cmake/external/gflags.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ADD_DEPENDENCIES(gflags extern_gflags)
5252

5353
LIST(APPEND external_project_dependencies gflags)
5454

55-
IF(WITH_C_API)
55+
IF(WITH_C_API OR WITH_FLUID)
5656
INSTALL(DIRECTORY ${GFLAGS_INCLUDE_DIR} DESTINATION third_party/gflags)
5757
IF(ANDROID)
5858
INSTALL(FILES ${GFLAGS_LIBRARIES} DESTINATION third_party/gflags/lib/${ANDROID_ABI})

cmake/external/glog.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LINK_LIBRARIES(glog gflags)
6868

6969
LIST(APPEND external_project_dependencies glog)
7070

71-
IF(WITH_C_API)
71+
IF(WITH_C_API OR WITH_FLUID)
7272
INSTALL(DIRECTORY ${GLOG_INCLUDE_DIR} DESTINATION third_party/glog)
7373
IF(ANDROID)
7474
INSTALL(FILES ${GLOG_LIBRARIES} DESTINATION third_party/glog/lib/${ANDROID_ABI})

cmake/external/protobuf.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ IF(NOT PROTOBUF_FOUND)
250250
SET(PROTOBUF_PROTOC_LIBRARY ${extern_protobuf_PROTOC_LIBRARY}
251251
CACHE FILEPATH "protoc library." FORCE)
252252

253-
IF(WITH_C_API)
253+
IF(WITH_C_API OR WITH_FLUID)
254254
INSTALL(DIRECTORY ${PROTOBUF_INCLUDE_DIR} DESTINATION third_party/protobuf)
255255
IF(ANDROID)
256256
INSTALL(FILES ${PROTOBUF_LITE_LIBRARY} DESTINATION third_party/protobuf/lib/${ANDROID_ABI})

paddle/framework/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,10 @@ cc_test(init_test SRCS init_test.cc DEPS init)
8888

8989
cc_test(op_kernel_type_test SRCS op_kernel_type_test.cc DEPS place device_context framework_proto)
9090
cc_test(cow_ptr_tests SRCS details/cow_ptr_test.cc)
91+
92+
if(NOT WITH_C_API AND WITH_FLUID)
93+
file(GLOB FRAMEWORK_HEADERS *.h)
94+
install(FILES ${FRAMEWORK_HEADERS} DESTINATION include/paddle/framework)
95+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/framework.pb.h DESTINATION include/paddle/framework)
96+
install(FILES details/cow_ptr.h details/op_registry.h DESTINATION include/paddle/framework/details)
97+
endif()

paddle/inference/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
set(FLUID_CORE_MODULES
2-
backward proto_desc paddle_memory executor prune init ${GLOB_OP_LIB})
1+
set(FLUID_CORE_MODULES proto_desc paddle_memory executor prune init)
32

43
cc_library(paddle_fluid_api
54
SRCS inference.cc
6-
DEPS ${FLUID_CORE_MODULES})
5+
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
76

8-
# Merge all modules into a simgle static library
9-
cc_library(paddle_fluid DEPS paddle_fluid_api ${FLUID_CORE_MODULES})
7+
# Merge all modules into a single static library
8+
cc_library(paddle_fluid DEPS paddle_fluid_api ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
9+
10+
# Create shared library
11+
add_library(paddle_fluid_shared SHARED inference.cc)
12+
13+
target_circle_link_libraries(paddle_fluid_shared
14+
ARCHIVE_START
15+
${GLOB_OP_LIB}
16+
ARCHIVE_END
17+
${FLUID_CORE_MODULES})
18+
19+
SET_TARGET_PROPERTIES(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid)
20+
21+
# install library & headers
22+
if(NOT WITH_C_API AND WITH_FLUID)
23+
install(FILES inference.h DESTINATION include/paddle/inference)
24+
install(TARGETS paddle_fluid_shared DESTINATION lib)
25+
endif()
1026

1127
add_executable(example example.cc)
1228
if(APPLE)

paddle/memory/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ cc_library(paddle_memory
1414
system_allocator)
1515

1616
cc_test(memory_test SRCS memory_test.cc DEPS place paddle_memory)
17+
18+
if(NOT WITH_C_API AND WITH_FLUID)
19+
file(GLOB MEMORY_HEADERS *.h)
20+
file(GLOB MEMORY_DETAIL_HEADERS detail/*.h)
21+
install(FILES ${MEMORY_HEADERS} DESTINATION include/paddle/memory)
22+
install(FILES ${MEMORY_DETAIL_HEADERS} DESTINATION include/paddle/memory/detail)
23+
endif()

paddle/platform/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ nv_test(nccl_test SRCS nccl_test.cu DEPS dynload_cuda gpu_info device_context)
3939

4040
cc_library(profiler SRCS profiler.cc DEPS device_context)
4141
cc_test(profiler_test SRCS profiler_test.cc DEPS profiler)
42+
43+
if(NOT WITH_C_API AND WITH_FLUID)
44+
file(GLOB PLATFORM_HEADERS *.h)
45+
file(GLOB PLATFORM_dynload_HEADERS dynload/*.h)
46+
install(FILES ${PLATFORM_HEADERS} DESTINATION include/paddle/platform)
47+
install(FILES ${PLATFORM_HEADERS} DESTINATION include/paddle/platform/dynload)
48+
install(FILES details/device_ptr_cast.h DESTINATION include/paddle/platform/details)
49+
endif()

paddle/string/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
cc_library(stringpiece SRCS piece.cc)
22
cc_test(stringpiece_test SRCS piece_test.cc DEPS stringpiece glog gflags)
3-
43
cc_test(stringprintf_test SRCS printf_test.cc DEPS glog gflags)
54
cc_test(to_string_test SRCS to_string_test.cc)
5+
6+
if(NOT WITH_C_API AND WITH_FLUID)
7+
file(GLOB STRING_HEADERS *.h)
8+
install(FILES ${STRING_HEADERS} DESTINATION include/paddle/string)
9+
install(FILES tinyformat/tinyformat.h DESTINATION include/paddle/string/tinyformat)
10+
endif()

0 commit comments

Comments
 (0)