From 5fe5bac6b7de85bbe7ed4adf852fbfb81cb75e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=94=80?= Date: Thu, 24 Jul 2025 16:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=90=8C=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E5=85=A5mindspore=E4=B8=8Emindsporelite=E7=9A=84so=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.bat | 3 ++ build.sh | 1 + cmake/external_libs/glog.cmake | 3 ++ cmake/package_lite.cmake | 8 +-- .../com/mindspore/config/NativeLibrary.java | 11 ++-- mindspore-lite/src/extendrt/CMakeLists.txt | 15 ++++++ third_party/patch/glog/glog.patch002 | 53 +++++++++++++++++++ third_party/patch/mindspore/glog.patch | 22 ++++++++ 8 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 third_party/patch/glog/glog.patch002 create mode 100644 third_party/patch/mindspore/glog.patch diff --git a/build.bat b/build.bat index 1405ccd7..9e6a1ca5 100644 --- a/build.bat +++ b/build.bat @@ -34,6 +34,9 @@ set ENABLE_FFMPEG=ON set ENABLE_FFMPEG_DOWNLOAD=OFF for /f "tokens=1" %%a in (version.txt) do (set VERSION_STR=%%a) git submodule update --init --remote mindspore +cd "%BASEPATH%\mindspore" && ( + git apply "%BASEPATH%\third_party\patch\mindspore\glog.patch" +) ECHO %2%|FINDSTR "^[0-9][0-9]*$" IF %errorlevel% == 0 ( SET threads=%2% diff --git a/build.sh b/build.sh index 80bbf0f1..825b2c23 100755 --- a/build.sh +++ b/build.sh @@ -49,6 +49,7 @@ build_exit() } update_submodule +cd ${BASEPATH}/mindspore && git apply ${BASEPATH}/third_party/patch/mindspore/glog.patch && cd - echo "---------------- MindSpore-Lite: build start ----------------" init_default_options process_options "$@" diff --git a/cmake/external_libs/glog.cmake b/cmake/external_libs/glog.cmake index 6dd1d316..d3204d9d 100644 --- a/cmake/external_libs/glog.cmake +++ b/cmake/external_libs/glog.cmake @@ -12,6 +12,7 @@ if(BUILD_LITE) set(glog_LDFLAGS "${SECURE_SHARED_LINKER_FLAGS}") endif() set(glog_patch ${TOP_DIR}/third_party/patch/glog/glog.patch001) + set(glog_patch_2 ${TOP_DIR}/third_party/patch/glog/glog.patch002) set(glog_lib mindspore_glog) else() if(MSVC) @@ -25,6 +26,7 @@ else() endif() set(glog_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") set(glog_patch ${CMAKE_SOURCE_DIR}/third_party/patch/glog/glog.patch001) + set(glog_patch_2 ${CMAKE_SOURCE_DIR}/third_party/patch/glog/glog.patch002) set(glog_lib mindspore_glog) endif() @@ -73,6 +75,7 @@ mindspore_add_pkg(glog URL ${REQ_URL} SHA256 ${SHA256} PATCHES ${glog_patch} + PATCHES ${glog_patch_2} CMAKE_OPTION ${glog_option}) include_directories(${glog_INC}) add_library(mindspore::glog ALIAS glog::${glog_lib}) diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index ea62255a..8e33fc3d 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -543,9 +543,9 @@ if(PLATFORM_ARM64) endif() install(FILES ${LITE_ACL_DIR}/libascend_pass_plugin.so DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir.so DESTINATION + install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir_lite.so DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir.so DESTINATION + install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir_lite.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) endif() @@ -982,9 +982,9 @@ else() endif() install(FILES ${LITE_ACL_DIR}/libascend_pass_plugin.so DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir.so DESTINATION + install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir_lite.so DESTINATION ${CONVERTER_ROOT_DIR}/lib COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir.so DESTINATION + install(FILES ${LITE_ACL_DIR}/_mindspore_transform_graph_ir/libmindspore_graph_ir_lite.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) endif() diff --git a/mindspore-lite/java/src/main/java/com/mindspore/config/NativeLibrary.java b/mindspore-lite/java/src/main/java/com/mindspore/config/NativeLibrary.java index 23fa8d86..f90d8070 100644 --- a/mindspore-lite/java/src/main/java/com/mindspore/config/NativeLibrary.java +++ b/mindspore-lite/java/src/main/java/com/mindspore/config/NativeLibrary.java @@ -36,8 +36,8 @@ public class NativeLibrary { private static final Logger LOGGER = Logger.getLogger(NativeLibrary.class.toString()); private static final String GLOG_LIBNAME = "mindspore_glog"; - private static final String MINDSPORE_CORE_LIBNAME = "mindspore_core"; - private static final String MINDSPORE_OPS_LIBNAME = "mindspore_ops"; + private static final String MINDSPORE_CORE_LIBNAME = "mindspore_core_lite"; + private static final String MINDSPORE_OPS_LIBNAME = "mindspore_ops_lite"; private static final String OPENCV_CORE_LIBNAME = "opencv_core"; private static final String OPENCV_IMGCODECS_LIBNAME = "opencv_imgcodecs"; private static final String OPENCV_IMGPROC_LIBNAME = "opencv_imgproc"; @@ -56,7 +56,7 @@ public class NativeLibrary { private static final String TENSORRT_PLUGIN_LIBNAME = "tensorrt_plugin"; private static final String MSLITE_SHARED_LIB_LIBNAME = "mslite_shared_lib"; private static final String TRANSFORMER_SHARED_LIB_LIBNAME = "transformer-shared"; - private static final String MINDSPORE_GRAPH_IR_LIBNAME = "mindspore_graph_ir"; + private static final String MINDSPORE_GRAPH_IR_LIBNAME = "mindspore_graph_ir_lite"; private static Long timestamp = null; /** @@ -79,10 +79,11 @@ public class NativeLibrary { * libopencv_imgproc.so * libopencv_imgcodecs.so * libmslite_converter_plugin.so - * libmindspore_core.so - * libmindspore_ops.so + * libmindspore_core_lite.so + * libmindspore_ops_lite.so * libmindspore_converter.so * libmindspore-lite.so + * mindspore_graph_ir_lite.so * mindspore-lite-jni * * For cloud inference, dlopen library as follows: diff --git a/mindspore-lite/src/extendrt/CMakeLists.txt b/mindspore-lite/src/extendrt/CMakeLists.txt index 72c54233..df3668a2 100644 --- a/mindspore-lite/src/extendrt/CMakeLists.txt +++ b/mindspore-lite/src/extendrt/CMakeLists.txt @@ -236,6 +236,21 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE OR MSLITE_ENABLE_CLOUD_INFERENCE) target_link_libraries(mindspore-extendrt mindspore_lite_drawer) target_link_libraries(mindspore-extendrt_static mindspore_lite_drawer) endif() + set_target_properties(mindspore_core PROPERTIES + OUTPUT_NAME "libmindspore_core_lite" + PREFIX "" + SUFFIX ".so" + ) + set_target_properties(mindspore_ops PROPERTIES + OUTPUT_NAME "libmindspore_ops_lite" + PREFIX "" + SUFFIX ".so" + ) + set_target_properties(mindspore_graph_ir PROPERTIES + OUTPUT_NAME "libmindspore_graph_ir_lite" + PREFIX "" + SUFFIX ".so" + ) else() set(MSLITE_EXTEND_RUNTIME_SRC ${MODEL_LOADER_FRAMEWORK_SRC}) add_library(mindspore-extendrt OBJECT ${MSLITE_EXTEND_RUNTIME_SRC}) diff --git a/third_party/patch/glog/glog.patch002 b/third_party/patch/glog/glog.patch002 new file mode 100644 index 00000000..4c2142e4 --- /dev/null +++ b/third_party/patch/glog/glog.patch002 @@ -0,0 +1,53 @@ +diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in +index 9968b96..e405fc6 100644 +--- a/src/glog/logging.h.in ++++ b/src/glog/logging.h.in +@@ -516,6 +516,9 @@ DECLARE_bool(stop_logging_if_full_disk); + // specified by argv0 in log outputs. + GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0); + ++// Chcek if google's logging library has been initialized. ++GOOGLE_GLOG_DLL_DECL bool IsGoogleLoggingInitialized(); ++ + // Shutdown google's logging library. + GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging(); + +diff --git a/src/utilities.cc b/src/utilities.cc +index 25c4b76..18e8ba7 100644 +--- a/src/utilities.cc ++++ b/src/utilities.cc +@@ -63,6 +63,10 @@ _START_GOOGLE_NAMESPACE_ + static const char* g_program_invocation_short_name = NULL; + static pthread_t g_main_thread_id; + ++bool IsGoogleLoggingInitialized() { ++ return g_program_invocation_short_name != NULL; ++} ++ + _END_GOOGLE_NAMESPACE_ + + // The following APIs are all internal. +@@ -177,10 +181,6 @@ const char* ProgramInvocationShortName() { + } + } + +-bool IsGoogleLoggingInitialized() { +- return g_program_invocation_short_name != NULL; +-} +- + bool is_default_thread() { + if (g_program_invocation_short_name == NULL) { + // InitGoogleLogging() not yet called, so unlikely to be in a different +diff --git a/src/utilities.h b/src/utilities.h +index ca21cfb..f52cac0 100644 +--- a/src/utilities.h ++++ b/src/utilities.h +@@ -161,8 +161,6 @@ namespace glog_internal_namespace_ { + + const char* ProgramInvocationShortName(); + +-bool IsGoogleLoggingInitialized(); +- + bool is_default_thread(); + + int64 CycleClock_Now(); diff --git a/third_party/patch/mindspore/glog.patch b/third_party/patch/mindspore/glog.patch new file mode 100644 index 00000000..aed20270 --- /dev/null +++ b/third_party/patch/mindspore/glog.patch @@ -0,0 +1,22 @@ +diff --git a/mindspore/core/utils/log_adapter.cc b/mindspore/core/utils/log_adapter.cc +index 8985226ac86..35ab20cd170 100644 +--- a/mindspore/core/utils/log_adapter.cc ++++ b/mindspore/core/utils/log_adapter.cc +@@ -1014,8 +1014,7 @@ MS_CORE_API void mindspore_log_init(void) { + #endif + #ifdef USE_GLOG + #define google mindspore_private +- static bool is_glog_initialzed = false; +- if (!is_glog_initialzed) { ++ if (!google::IsGoogleLoggingInitialized()) { + std::string logtostderr = mindspore::GetEnv("GLOG_logtostderr"); + std::string log_dir = mindspore::GetEnv("GLOG_log_dir"); + if (logtostderr == "0" && !log_dir.empty()) { +@@ -1026,7 +1025,6 @@ MS_CORE_API void mindspore_log_init(void) { + } + + google::InitGoogleLogging("mindspore"); +- is_glog_initialzed = true; + } + #undef google + #endif -- Gitee