Skip to content

Commit 5a63478

Browse files
authored
Merge pull request #12312 from luotao1/unify
unify libpaddle_inference_api and libpaddle_fluid
2 parents e12b1d1 + 062556f commit 5a63478

File tree

11 files changed

+29
-60
lines changed

11 files changed

+29
-60
lines changed

cmake/inference_lib.cmake

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,11 @@ if (WITH_ANAKIN AND WITH_GPU)
148148
list(APPEND inference_deps anakin_inference_lib)
149149
endif()
150150

151-
copy(inference_api_lib DEPS paddle_inference_api paddle_inference_api_shared
152-
SRCS ${src_dir}/${module}/paddle_inference_api.h
153-
${src_dir}/${module}/demo_ci
154-
${PADDLE_BINARY_DIR}/paddle/fluid/inference/api/libpaddle_inference_api*
155-
DSTS ${dst_dir}/inference ${dst_dir}/inference ${dst_dir}/inference
156-
)
157-
list(APPEND inference_deps inference_api_lib)
158-
159151
set(module "inference")
160152
copy(inference_lib DEPS ${inference_deps}
161153
SRCS ${src_dir}/${module}/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/inference/libpaddle_fluid.*
162-
DSTS ${dst_dir}/${module} ${dst_dir}/${module}
154+
${src_dir}/${module}/api/paddle_inference_api.h ${src_dir}/${module}/api/demo_ci
155+
DSTS ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module}
163156
)
164157

165158
set(module "platform")

paddle/fluid/inference/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ cc_library(paddle_fluid_api
1414

1515
get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
1616

17+
# paddle_fluid_origin exclude inference api interface
18+
cc_library(paddle_fluid_origin DEPS ${fluid_modules} paddle_fluid_api)
19+
20+
if(NOT APPLE)
21+
add_subdirectory(api)
22+
endif()
23+
1724
# Create static library
18-
cc_library(paddle_fluid DEPS ${fluid_modules} paddle_fluid_api)
25+
cc_library(paddle_fluid DEPS ${fluid_modules} paddle_fluid_api paddle_inference_api)
1926
if(NOT APPLE)
2027
# TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac.
2128
set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.sym")
@@ -24,20 +31,29 @@ endif()
2431

2532
# Create shared library
2633
cc_library(paddle_fluid_shared SHARED
27-
SRCS io.cc
34+
SRCS io.cc ${CMAKE_CURRENT_SOURCE_DIR}/api/api.cc ${CMAKE_CURRENT_SOURCE_DIR}/api/api_impl.cc
2835
DEPS ${fluid_modules} paddle_fluid_api)
2936

3037
set_target_properties(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid)
3138
if(NOT APPLE)
3239
# TODO(liuyiqun): Temporarily disable the link flag because it is not support on Mac.
3340
set(LINK_FLAGS "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.map")
3441
set_target_properties(paddle_fluid_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
42+
# check symbol hidden
43+
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/check_symbol.cmake
44+
"execute_process(COMMAND bash -c \"${CMAKE_CURRENT_SOURCE_DIR}/check_symbol.sh"
45+
" ${CMAKE_CURRENT_BINARY_DIR}/libpaddle_fluid.so\" RESULT_VARIABLE symbol_res)\n"
46+
"if(NOT \"\${symbol_res}\" STREQUAL \"0\")\n"
47+
" message(FATAL_ERROR \"Check symbol failed.\")\n"
48+
"endif()\n")
49+
add_custom_command(
50+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.check_symbol"
51+
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/check_symbol.cmake"
52+
DEPENDS paddle_fluid_shared)
53+
add_custom_target(check_symbol ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/.check_symbol")
3554
endif()
3655

3756
if(WITH_TESTING)
3857
# both tests/book and analysis depends the models that generated by python/paddle/fluid/tests/book
3958
add_subdirectory(tests/book)
4059
endif()
41-
if(NOT APPLE)
42-
add_subdirectory(api)
43-
endif()

paddle/fluid/inference/api/CMakeLists.txt

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,8 @@ function(inference_api_test TARGET_NAME)
4242
endif(WITH_TESTING)
4343
endfunction(inference_api_test)
4444

45-
cc_library(paddle_inference_api
46-
SRCS api.cc api_impl.cc
47-
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
48-
if(NOT APPLE)
49-
set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/api.sym")
50-
set_target_properties(paddle_inference_api PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
51-
endif()
52-
53-
# Here the shared library doesn't depend on other fluid libraries, or double free will occur.
54-
cc_library(paddle_inference_api_shared SHARED
55-
SRCS api.cc api_impl.cc)
56-
add_dependencies(paddle_inference_api_shared ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
57-
set_target_properties(paddle_inference_api_shared PROPERTIES OUTPUT_NAME paddle_inference_api)
45+
cc_library(paddle_inference_api SRCS api.cc api_impl.cc)
5846

59-
if(NOT APPLE)
60-
set(LINK_FLAGS "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/api.map")
61-
set_target_properties(paddle_inference_api_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
62-
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/check_symbol.cmake
63-
"execute_process(COMMAND bash -c \"${CMAKE_CURRENT_SOURCE_DIR}/check_symbol.sh"
64-
" ${CMAKE_CURRENT_BINARY_DIR}/libpaddle_inference_api.so\" RESULT_VARIABLE symbol_res)\n"
65-
"if(NOT \"\${symbol_res}\" STREQUAL \"0\")\n"
66-
" message(FATAL_ERROR \"Check symbol failed.\")\n"
67-
"endif()\n")
68-
add_custom_command(
69-
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.check_symbol"
70-
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/check_symbol.cmake"
71-
DEPENDS paddle_inference_api_shared)
72-
add_custom_target(check_symbol ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/.check_symbol")
73-
endif()
7447

7548
cc_test(test_paddle_inference_api
7649
SRCS api_tester.cc

paddle/fluid/inference/api/api.map

Lines changed: 0 additions & 6 deletions
This file was deleted.

paddle/fluid/inference/api/api.sym

Lines changed: 0 additions & 1 deletion
This file was deleted.

paddle/fluid/inference/api/demo_ci/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ endif()
5555
# Note: libpaddle_inference_api.so/a must put before libpaddle_fluid.so/a
5656
if(WITH_STATIC_LIB)
5757
set(DEPS
58-
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_inference_api.a
5958
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.a)
6059
else()
6160
set(DEPS
62-
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_inference_api.so
6361
${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.so)
6462
endif()
6563
set(EXTERNAL_LIB "-lrt -ldl -lpthread")

paddle/fluid/inference/api/check_symbol.sh renamed to paddle/fluid/inference/check_symbol.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
lib=$1
44
if [ $# -ne 1 ]; then echo "No input library"; exit -1 ; fi
55

6-
num_paddle_syms=$(nm -D --defined-only ${lib} | grep paddle | wc -l)
7-
num_google_syms=$(nm -D --defined-only ${lib} | grep google | wc -l)
6+
num_paddle_syms=$(nm -D ${lib} | grep paddle | wc -l)
7+
num_google_syms=$(nm -D ${lib} | grep google | grep -v paddle | grep T | wc -l)
88

99
if [ $num_paddle_syms -le 0 ]; then echo "Have no paddle symbols"; exit -1 ; fi
1010
if [ $num_google_syms -ge 1 ]; then echo "Have some google symbols"; exit -1 ; fi

paddle/fluid/inference/tensorrt/convert/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Add TRT tests
22
nv_library(tensorrt_converter
33
SRCS mul_op.cc conv2d_op.cc fc_op.cc pool2d_op.cc
4-
DEPS tensorrt_engine mul_op)
4+
DEPS tensorrt_engine operator scope framework_proto op_registry)
55

66
nv_test(test_op_converter SRCS test_op_converter.cc DEPS
77
${FLUID_CORE_MODULES} tensorrt_engine tensorrt_converter)

paddle/fluid/inference/tensorrt/convert/mul_op.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,4 @@ class MulOpConverter : public OpConverter {
4949
} // namespace inference
5050
} // namespace paddle
5151

52-
USE_OP(mul);
5352
REGISTER_TRT_OP_CONVERTER(mul, MulOpConverter);

paddle/fluid/inference/tests/book/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function(inference_test TARGET_NAME)
1717
string(REGEX REPLACE "^_$" "" arg "${arg}")
1818
cc_test(test_inference_${TARGET_NAME}${arg}
1919
SRCS test_inference_${TARGET_NAME}.cc
20-
DEPS paddle_fluid
20+
DEPS paddle_fluid_origin
2121
ARGS --dirname=${PYTHON_TESTS_DIR}/book/${TARGET_NAME}${arg}.inference.model)
2222
set_tests_properties(test_inference_${TARGET_NAME}${arg}
2323
PROPERTIES DEPENDS test_${TARGET_NAME})
@@ -43,6 +43,6 @@ inference_test(word2vec)
4343
# TODO(TJ): clean me up
4444
cc_test(test_inference_nlp
4545
SRCS test_inference_nlp.cc
46-
DEPS paddle_fluid
46+
DEPS paddle_fluid_origin
4747
ARGS
4848
--model_path=${PADDLE_BINARY_DIR}/python/paddle/fluid/tests/book/recognize_digits_mlp.inference.model)

0 commit comments

Comments
 (0)