From 086540ccb4e8cde02176f3134adf09e92ac9d3fc Mon Sep 17 00:00:00 2001 From: Wilber Date: Wed, 25 Aug 2021 14:22:39 +0800 Subject: [PATCH] strip inference.so and make link to mkldnn.so (#34895) --- cmake/inference_lib.cmake | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index 669875d81df..cb2ed614d3d 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -72,6 +72,12 @@ function(copy_part_of_thrid_party TARGET DST) copy(${TARGET} SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR} DSTS ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}) + if(WITH_STRIP) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND strip -s ${dst_dir}/lib/libiomp5.so + COMMAND strip -s ${dst_dir}/lib/libmklml_intel.so + COMMENT "striping libiomp5.so\nstriping libmklml_intel.so") + endif() endif() elseif(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS) set(dst_dir "${DST}/third_party/install/openblas") @@ -94,8 +100,17 @@ function(copy_part_of_thrid_party TARGET DST) DSTS ${dst_dir} ${dst_dir}/lib ${dst_dir}/lib) else() copy(${TARGET} - SRCS ${MKLDNN_INC_DIR} ${MKLDNN_SHARED_LIB} ${MKLDNN_SHARED_LIB_1} ${MKLDNN_SHARED_LIB_2} - DSTS ${dst_dir} ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}/lib) + SRCS ${MKLDNN_INC_DIR} ${MKLDNN_SHARED_LIB} + DSTS ${dst_dir} ${dst_dir}/lib) + if(WITH_STRIP) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND strip -s ${dst_dir}/lib/libmkldnn.so.0 + COMMENT "striping libmkldnn.so.0") + endif() + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink libmkldnn.so.0 ${dst_dir}/lib/libdnnl.so.1 + COMMAND ${CMAKE_COMMAND} -E create_symlink libmkldnn.so.0 ${dst_dir}/lib/libdnnl.so.2 + COMMENT "Make a symbol link of libmkldnn.so.0") endif() endif() @@ -225,6 +240,13 @@ copy(inference_lib_dist SRCS ${src_dir}/inference/capi_exp/pd_*.h ${paddle_inference_c_lib} DSTS ${PADDLE_INFERENCE_C_INSTALL_DIR}/paddle/include ${PADDLE_INFERENCE_C_INSTALL_DIR}/paddle/lib) +if(WITH_STRIP AND NOT WIN32) + add_custom_command(TARGET inference_lib_dist POST_BUILD + COMMAND strip -s ${PADDLE_INFERENCE_C_INSTALL_DIR}/paddle/lib/libpaddle_inference_c.so + COMMAND strip -s ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib/libpaddle_inference.so + COMMENT "striping libpaddle_inference_c.so\nstriping libpaddle_inference.so") +endif() + # fluid library for both train and inference set(fluid_lib_deps inference_lib_dist) add_custom_target(fluid_lib_dist ALL DEPENDS ${fluid_lib_deps}) -- GitLab