Skip to content

Commit 086540c

Browse files
authored
strip inference.so and make link to mkldnn.so (#34895)
1 parent f609ca3 commit 086540c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

cmake/inference_lib.cmake

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ function(copy_part_of_thrid_party TARGET DST)
7272
copy(${TARGET}
7373
SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR}
7474
DSTS ${dst_dir}/lib ${dst_dir}/lib ${dst_dir})
75+
if(WITH_STRIP)
76+
add_custom_command(TARGET ${TARGET} POST_BUILD
77+
COMMAND strip -s ${dst_dir}/lib/libiomp5.so
78+
COMMAND strip -s ${dst_dir}/lib/libmklml_intel.so
79+
COMMENT "striping libiomp5.so\nstriping libmklml_intel.so")
80+
endif()
7581
endif()
7682
elseif(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS)
7783
set(dst_dir "${DST}/third_party/install/openblas")
@@ -94,8 +100,17 @@ function(copy_part_of_thrid_party TARGET DST)
94100
DSTS ${dst_dir} ${dst_dir}/lib ${dst_dir}/lib)
95101
else()
96102
copy(${TARGET}
97-
SRCS ${MKLDNN_INC_DIR} ${MKLDNN_SHARED_LIB} ${MKLDNN_SHARED_LIB_1} ${MKLDNN_SHARED_LIB_2}
98-
DSTS ${dst_dir} ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}/lib)
103+
SRCS ${MKLDNN_INC_DIR} ${MKLDNN_SHARED_LIB}
104+
DSTS ${dst_dir} ${dst_dir}/lib)
105+
if(WITH_STRIP)
106+
add_custom_command(TARGET ${TARGET} POST_BUILD
107+
COMMAND strip -s ${dst_dir}/lib/libmkldnn.so.0
108+
COMMENT "striping libmkldnn.so.0")
109+
endif()
110+
add_custom_command(TARGET ${TARGET} POST_BUILD
111+
COMMAND ${CMAKE_COMMAND} -E create_symlink libmkldnn.so.0 ${dst_dir}/lib/libdnnl.so.1
112+
COMMAND ${CMAKE_COMMAND} -E create_symlink libmkldnn.so.0 ${dst_dir}/lib/libdnnl.so.2
113+
COMMENT "Make a symbol link of libmkldnn.so.0")
99114
endif()
100115
endif()
101116

@@ -225,6 +240,13 @@ copy(inference_lib_dist
225240
SRCS ${src_dir}/inference/capi_exp/pd_*.h ${paddle_inference_c_lib}
226241
DSTS ${PADDLE_INFERENCE_C_INSTALL_DIR}/paddle/include ${PADDLE_INFERENCE_C_INSTALL_DIR}/paddle/lib)
227242

243+
if(WITH_STRIP AND NOT WIN32)
244+
add_custom_command(TARGET inference_lib_dist POST_BUILD
245+
COMMAND strip -s ${PADDLE_INFERENCE_C_INSTALL_DIR}/paddle/lib/libpaddle_inference_c.so
246+
COMMAND strip -s ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib/libpaddle_inference.so
247+
COMMENT "striping libpaddle_inference_c.so\nstriping libpaddle_inference.so")
248+
endif()
249+
228250
# fluid library for both train and inference
229251
set(fluid_lib_deps inference_lib_dist)
230252
add_custom_target(fluid_lib_dist ALL DEPENDS ${fluid_lib_deps})

0 commit comments

Comments
 (0)