From bfaea54e1ef5d5c731bf7288e21d04e2b66c52e7 Mon Sep 17 00:00:00 2001 From: liu lili Date: Fri, 26 Aug 2022 16:15:00 +0800 Subject: [PATCH] mindspore lite: add graph_executor --- cmake/package_lite.cmake | 14 +++++++ mindspore/lite/src/CMakeLists.txt | 38 ++++++++++--------- mindspore/lite/src/extendrt/CMakeLists.txt | 4 ++ .../graph_executor/litert/CMakeLists.txt | 2 +- .../graph_executor/litert/converters.cc | 2 +- .../graph_executor/litert/converters.h | 2 +- .../graph_executor/litert/graph_executor.cc | 2 +- .../graph_executor/litert/graph_executor.h | 4 +- mindspore/lite/tools/converter/converter.cc | 5 +++ mindspore/lite/tools/converter/converter.h | 1 + 10 files changed, 50 insertions(+), 24 deletions(-) diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 6cfbe7e6bce..9fd91bcb51b 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -11,6 +11,7 @@ else() set(BUILD_DIR ${TOP_DIR}/mindspore/lite/build) endif() set(TEST_CASE_DIR ${TOP_DIR}/mindspore/lite/test/build) +set(EXTENDRT_BUILD_DIR ${TOP_DIR}/mindspore/lite/build/src/extendrt) set(RUNTIME_DIR ${RUNTIME_PKG_NAME}/runtime) set(RUNTIME_INC_DIR ${RUNTIME_PKG_NAME}/runtime/include) @@ -23,6 +24,7 @@ set(SECUREC_DIR ${RUNTIME_PKG_NAME}/runtime/third_party/securec) set(MINDSPORE_LITE_LIB_NAME libmindspore-lite) set(MINDSPORE_LITE_EXTENDRT_LIB_NAME libmindspore-lite) set(MINDSPORE_CORE_LIB_NAME libmindspore_core) +set(MINDSPORE_GE_LITERT_LIB_NAME libmsplugin-ge-litert) set(BENCHMARK_NAME benchmark) set(MSLITE_NNIE_LIB_NAME libmslite_nnie) set(MSLITE_PROPOSAL_LIB_NAME libmslite_proposal) @@ -407,6 +409,10 @@ if(PLATFORM_ARM64) if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) install(FILES ${TOP_DIR}/mindspore/lite/build/src/extendrt/${MINDSPORE_LITE_EXTENDRT_LIB_NAME}.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${EXTENDRT_BUILD_DIR}/delegate/graph_executor/litert/${MINDSPORE_GE_LITERT_LIB_NAME}.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${BUILD_DIR}/tools/converter/libmindspore_converter.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libmindspore_glog.so.0.4.0 DESTINATION ${RUNTIME_LIB_DIR} RENAME libmindspore_glog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) install(TARGETS mindspore_core DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) @@ -642,6 +648,10 @@ elseif(PLATFORM_ARM32) if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) install(FILES ${TOP_DIR}/mindspore/lite/build/src/extendrt/${MINDSPORE_LITE_EXTENDRT_LIB_NAME}.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${EXTENDRT_BUILD_DIR}/delegate/graph_executor/litert/${MINDSPORE_GE_LITERT_LIB_NAME}.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${BUILD_DIR}/tools/converter/libmindspore_converter.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libmindspore_glog.so.0.4.0 DESTINATION ${RUNTIME_LIB_DIR} RENAME libmindspore_glog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) install(TARGETS mindspore_core DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) @@ -828,6 +838,10 @@ else() if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) install(FILES ${TOP_DIR}/mindspore/lite/build/src/extendrt/${MINDSPORE_LITE_EXTENDRT_LIB_NAME}.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${EXTENDRT_BUILD_DIR}/delegate/graph_executor/litert/${MINDSPORE_GE_LITERT_LIB_NAME}.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${BUILD_DIR}/tools/converter/libmindspore_converter.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${glog_LIBPATH}/libmindspore_glog.so.0.4.0 DESTINATION ${RUNTIME_LIB_DIR} RENAME libmindspore_glog.so.0 COMPONENT ${RUNTIME_COMPONENT_NAME}) install(TARGETS mindspore_core DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index 0ff24e35751..a2026941e00 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -480,24 +480,26 @@ if(MSLITE_ENABLE_MINDRT) target_link_libraries(mindspore-lite_static mindrt_mid) endif() -if(SUPPORT_TENSORRT) - add_compile_definitions(GPU_TENSORRT) - set(TENSORRT_PATH $ENV{TENSORRT_PATH}) - set(CUDA_PATH $ENV{CUDA_HOME}) - set(TENSORRT_LIB_PATH ${TENSORRT_PATH}/lib) - set(CUDA_LIB_PATH ${CUDA_PATH}/lib64) - include_directories(${TENSORRT_PATH}/include) - include_directories(${CUDA_PATH}/include) - add_subdirectory(litert/delegate/tensorrt) - target_link_libraries(mindspore-lite tensorrt_kernel_mid cuda_kernel_mid gpu_distribution_collective) - target_link_libraries(mindspore-lite_static tensorrt_kernel_mid cuda_kernel_mid gpu_distribution_collective) -else() - set(TENSORRT_STUB - ${CMAKE_CURRENT_SOURCE_DIR}/litert/delegate/tensorrt/distribution/distribution_base.cc - ) - add_library(tensorrt_stub OBJECT ${TENSORRT_STUB}) - target_link_libraries(mindspore-lite tensorrt_stub) - target_link_libraries(mindspore-lite_static tensorrt_stub) +if(NOT MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) + if(SUPPORT_TENSORRT) + add_compile_definitions(GPU_TENSORRT) + set(TENSORRT_PATH $ENV{TENSORRT_PATH}) + set(CUDA_PATH $ENV{CUDA_HOME}) + set(TENSORRT_LIB_PATH ${TENSORRT_PATH}/lib) + set(CUDA_LIB_PATH ${CUDA_PATH}/lib64) + include_directories(${TENSORRT_PATH}/include) + include_directories(${CUDA_PATH}/include) + add_subdirectory(litert/delegate/tensorrt) + target_link_libraries(mindspore-lite tensorrt_kernel_mid cuda_kernel_mid gpu_distribution_collective) + target_link_libraries(mindspore-lite_static tensorrt_kernel_mid cuda_kernel_mid gpu_distribution_collective) + else() + set(TENSORRT_STUB + ${CMAKE_CURRENT_SOURCE_DIR}/litert/delegate/tensorrt/distribution/distribution_base.cc + ) + add_library(tensorrt_stub OBJECT ${TENSORRT_STUB}) + target_link_libraries(mindspore-lite tensorrt_stub) + target_link_libraries(mindspore-lite_static tensorrt_stub) + endif() endif() if(MSLITE_GPU_BACKEND STREQUAL opencl) diff --git a/mindspore/lite/src/extendrt/CMakeLists.txt b/mindspore/lite/src/extendrt/CMakeLists.txt index 53b6f145000..68c31d17cd1 100644 --- a/mindspore/lite/src/extendrt/CMakeLists.txt +++ b/mindspore/lite/src/extendrt/CMakeLists.txt @@ -7,6 +7,7 @@ set(MSLITE_EXTEND_RUNTIME_SRC ${MSLITE_EXTEND_RUNTIME_SRC} ${MODEL_LOADER_FRAMEWORK_SRC}) if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) set(ENABLE_CPU on) + set(LOAD_PLUGIN_STATIC on) add_compile_definitions(USE_GLOG) string(REPLACE "-fno-rtti" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) string(REPLACE "-fno-rtti" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) @@ -141,6 +142,7 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) add_dependencies(mindspore-extendrt mindspore-infer-anfalgo) add_dependencies(mindspore-extendrt mindspore-kernel-graph) add_subdirectory(cxx_api) + add_subdirectory(delegate/graph_executor/litert) # when cpu kernel is need #if(NOT MSLITE_ENABLE_ACL) @@ -156,6 +158,8 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) mindspore-kernel-graph _mindspore_backend_common_optimizer_obj _mindspore_backend_common_pass_obj) target_link_libraries(mindspore-extendrt mindspore_core mindspore::protobuf mindspore::pybind11_module) + add_dependencies(mindspore-extendrt msplugin-ge-litert) + target_link_libraries(mindspore-extendrt msplugin-ge-litert) if(NOT WIN32) target_link_libraries(mindspore-extendrt dl) diff --git a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt index ba236511530..b4ac74ea6e3 100644 --- a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt +++ b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/CMakeLists.txt @@ -30,7 +30,7 @@ set(LITE_SRC ${LITE_DIR}/src/litert/infer_manager.cc ${LITE_DIR}/src/litert/runtime_shape_fusion_pass.cc ${LITE_DIR}/src/litert/runtime_pass.cc - ${LITE_DIR}/src/litert/pass/runtime_ncx_pass.cc + # ${LITE_DIR}/src/litert/pass/runtime_ncx_pass.cc ${LITE_DIR}/src/litert/schema_tensor_wrapper.cc ${LITE_DIR}/src/tensor.cc ${LITE_DIR}/src/tensorlist.cc diff --git a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.cc b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.cc index dc2c72957c2..65c5aa5cfd6 100644 --- a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.cc +++ b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.cc @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright 2019-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.h b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.h index cccf4faf2ec..17acf905892 100644 --- a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.h +++ b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/converters.h @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright 2019-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.cc b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.cc index 602c0911a68..b920726204b 100644 --- a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.cc +++ b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2021 Huawei Technologies Co., Ltd + * Copyright 2019-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.h b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.h index e306c41636c..685ed677a73 100644 --- a/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.h +++ b/mindspore/lite/src/extendrt/delegate/graph_executor/litert/graph_executor.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2021 Huawei Technologies Co., Ltd + * Copyright 2019-2022 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ class LiteRTGraphExecutor : public GraphExecutor { bool CompileGraph(const FuncGraphPtr &graph, const std::map &compile_options) override; bool RunGraph(const FuncGraphPtr &graph, const std::vector &inputs, std::vector *outputs, const std::map &compile_options) override; - bool Resize(const std::vector &inputs, const std::vector> &dims) override; + bool Resize(const std::vector &inputs, const std::vector> &dims); std::vector GetInputs(); std::shared_ptr CreateLiteSession(lite::InnerContext *context); std::vector GetLiteSessionInputs(); diff --git a/mindspore/lite/tools/converter/converter.cc b/mindspore/lite/tools/converter/converter.cc index 0e0d6e83b7e..5289264de72 100644 --- a/mindspore/lite/tools/converter/converter.cc +++ b/mindspore/lite/tools/converter/converter.cc @@ -225,6 +225,11 @@ int ConverterImpl::Convert(const std::shared_ptr ¶m, schema:: return RET_OK; } +int ConverterImpl::Convert(const std::shared_ptr ¶m, schema::MetaGraphT **meta_graph, + FuncGraphPtr func_graph) { + return RET_OK; +} + schema::MetaGraphT *ConverterImpl::TransferFuncGraph(const std::shared_ptr ¶m, FuncGraphPtr func_graph) { MS_CHECK_TRUE_MSG(metagraph_transform_ != nullptr, nullptr, "metagraph_transform_ init failed"); diff --git a/mindspore/lite/tools/converter/converter.h b/mindspore/lite/tools/converter/converter.h index bcaf3e8db9f..2a6dad95d8c 100644 --- a/mindspore/lite/tools/converter/converter.h +++ b/mindspore/lite/tools/converter/converter.h @@ -55,6 +55,7 @@ class ConverterImpl { int Convert(const std::shared_ptr ¶m, schema::MetaGraphT **meta_graph); int Convert(const std::shared_ptr ¶m, schema::MetaGraphT **meta_graph, const void *buf, const size_t &size); + int Convert(const std::shared_ptr ¶m, schema::MetaGraphT **meta_graph, FuncGraphPtr func_graph); private: FuncGraphPtr BuildFuncGraph(const std::shared_ptr ¶m);