!49517 [MS]{Lite][Task] solve compile problems for new infer framework

Merge pull request !49517 from 刘力力/feature_new_infer
This commit is contained in:
i-robot 2023-03-01 02:13:42 +00:00 committed by Gitee
commit 011210061e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 658 additions and 68 deletions

View File

@ -12,6 +12,7 @@ else()
endif()
set(TEST_CASE_DIR ${TOP_DIR}/mindspore/lite/test/build)
set(EXTENDRT_BUILD_DIR ${TOP_DIR}/mindspore/lite/build/src/extendrt)
set(EXECUTOR_BUILD_DIR ${TOP_DIR}/mindspore/lite/build/src/extendrt/unified_executor)
set(RUNTIME_DIR ${RUNTIME_PKG_NAME}/runtime)
set(RUNTIME_INC_DIR ${RUNTIME_PKG_NAME}/runtime/include)
@ -26,6 +27,7 @@ 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(MINDSPORE_LITE_EXECUTOR_LIB_NAME liblite-unified-executor)
set(BENCHMARK_NAME benchmark)
set(MSLITE_NNIE_LIB_NAME libmslite_nnie)
set(MSLITE_PROPOSAL_LIB_NAME libmslite_proposal)
@ -424,6 +426,8 @@ if(PLATFORM_ARM64)
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 ${EXECUTOR_BUILD_DIR}/${MINDSPORE_LITE_EXECUTOR_LIB_NAME}.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})
@ -649,6 +653,8 @@ elseif(PLATFORM_ARM32)
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 ${EXECUTOR_BUILD_DIR}/${MINDSPORE_LITE_EXECUTOR_LIB_NAME}.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})
@ -843,6 +849,8 @@ else()
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 ${EXECUTOR_BUILD_DIR}/${MINDSPORE_LITE_EXECUTOR_LIB_NAME}.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(FILES ${onednn_LIBPATH}/libdnnl.so.2.2 DESTINATION ${DNNL_DIR}

View File

@ -213,6 +213,7 @@ build_python_wheel_package() {
if [[ ("${MSLITE_ENABLE_CLOUD_FUSION_INFERENCE}" == "on") || ("${MSLITE_ENABLE_CLOUD_INFERENCE}" == "on") ]]; then
cp src/extendrt/*.so package/mindspore_lite/lib/
find src/extendrt/delegate/graph_executor/litert/ -name "*.so" -exec cp '{}' package/mindspore_lite/lib/ \;
find src/extendrt/unified_executor/ -name "*.so" -exec cp '{}' package/mindspore_lite/lib/ \;
find src/extendrt/convert/ -name "*.so" -exec cp '{}' package/mindspore_lite/lib/ \;
if [[ "${MSLITE_ENABLE_ACL}" ]]; then
cp src/extendrt/kernel/ascend/*.so package/mindspore_lite/lib/

View File

@ -0,0 +1,388 @@
set(API_SRC "")
set(LITE_SRC "")
add_compile_definitions(ENABLE_LITE_HELPER)
set(MOCK_SRC
${MOCK_SRC}
${LITE_DIR}/src/extendrt/mock/lite_runtime/converters.cc
${LITE_DIR}/src/extendrt/mock/lite_runtime/populate/base_operator_populate_register.cc
${LITE_DIR}/src/extendrt/mock/lite_runtime/populate/arithmetic_populate.cc
)
set(LITE_SRC
${LITE_SRC}
${API_SRC}
${MOCK_SRC}
${LITE_DIR}/src/common/context_util.cc
${LITE_DIR}/src/common/file_utils.cc
${LITE_DIR}/src/common/utils.cc
${LITE_DIR}/src/common/graph_util.cc
${LITE_DIR}/src/common/log.cc
${LITE_DIR}/src/common/prim_util.cc
${LITE_DIR}/src/common/tensor_util.cc
${LITE_DIR}/src/common/config_infos.cc
${LITE_DIR}/src/litert/allocator.cc
${LITE_DIR}/src/litert/inner_allocator.cc
${LITE_DIR}/src/litert/runtime_allocator.cc
${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/schema_tensor_wrapper.cc
${LITE_DIR}/src/tensor.cc
${LITE_DIR}/src/tensorlist.cc
${LITE_DIR}/src/litert/tensor_category.cc
${LITE_DIR}/src/litert/executor.cc
${LITE_DIR}/src/litert/inner_context.cc
${LITE_DIR}/src/litert/lite_model.cc
${LITE_DIR}/src/litert/kernel_registry.cc
${LITE_DIR}/src/litert/lite_kernel.cc
${LITE_DIR}/src/litert/kernel_exec.cc
${LITE_DIR}/src/litert/kernel_exec_util.cc
${LITE_DIR}/src/litert/sub_graph_kernel.cc
${LITE_DIR}/src/litert/scheduler.cc
${LITE_DIR}/src/litert/lite_session.cc
${LITE_DIR}/src/errorcode.cc
${LITE_DIR}/src/litert/cpu_info.cc
${LITE_DIR}/src/litert/pack_weight_manager.cc
${LITE_DIR}/src/control_flow/control_flow_scheduler.cc
${LITE_DIR}/src/control_flow/control_subgraph_creator.cc
${LITE_DIR}/src/extendrt/utils/tensor_utils.cc
)
set(MODEL_LOADER_FRAMEWORK_SRC
${LITE_DIR}/src/extendrt/mindir_loader/model_loader.cc
)
set(MINDIR_MODEL_SRC
${MINDIR_MODEL_SRC}
${LITE_DIR}/src/extendrt/mindir_loader/mindir_model/mindir_model.cc
${LITE_DIR}/src/extendrt/mindir_loader/mindir_model/mindir_model_util.cc
${LITE_DIR}/src/extendrt/mindir_loader/mindir_model/mindir_model_convertor.cc
${LITE_DIR}/src/extendrt/mindir_loader/mindir_model/mindir_model_loader.cc
${LITE_DIR}/src/extendrt/mindir_loader/mindir_model/kernel_mod_util.cc
)
set(MINDIR_KERNEL_SRC
${MINDIR_KERNEL_SRC}
${LITE_DIR}/src/extendrt/mindir_loader/mindir_model/inner_kernel.cc)
set(LITE_SRC
${LITE_SRC}
${MODEL_LOADER_FRAMEWORK_SRC}
${MINDIR_MODEL_SRC}
${MINDIR_KERNEL_SRC}
)
set(INFER_HELPER_SRC
${INFER_HELPER_SRC}
${LITE_DIR}/src/common/helper/external_tensor/file_helper.cc
${LITE_DIR}/src/common/helper/external_tensor/memory_helper.cc
)
set(LITE_SRC
${LITE_SRC}
${INFER_HELPER_SRC}
)
if(MSLITE_ENABLE_MODEL_ENCRYPTION)
set(LITE_SRC
${LITE_SRC}
${LITE_DIR}/src/common/decrypt.cc
${LITE_DIR}/src/common/dynamic_library_loader.cc
)
endif()
if(MSLITE_ENABLE_BFC_MEMORY)
set(LITE_SRC
${LITE_SRC}
${LITE_DIR}/src/extendrt/dynamic_mem_allocator.cc
${LITE_DIR}/src/extendrt/dynamic_mem_manager.cc
${LITE_DIR}/src/extendrt/numa_adapter.cc
)
endif()
if(MSLITE_ENABLE_SHARING_MODEL_WEIGHT)
set(LITE_SRC
${LITE_SRC}
${LITE_DIR}/src/litert/pack_weight.cc
)
endif()
if(MSLITE_ENABLE_DYNAMIC_THREAD_DISTRIBUTE)
set(LITE_SRC
${LITE_SRC}
${LITE_DIR}/src/litert/thread_cost_model.cc
)
endif()
if(MSLITE_ENABLE_CONTROLFLOW)
file(GLOB CONTROL_FLOW_KERNEL_SRC
${LITE_DIR}/src/control_flow/kernel/*.cc
)
set(LITE_SRC ${LITE_SRC} ${CONTROL_FLOW_KERNEL_SRC})
endif()
if(MSLITE_ENABLE_RUNTIME_GLOG)
if(NOT MSLITE_ENABLE_RUNTIME_CONVERT AND NOT MSLITE_ENABLE_KERNEL_EXECUTOR
AND NOT (MSLITE_ENABLE_CLOUD_FUSION_INFERENCE OR MSLITE_ENABLE_CLOUD_INFERENCE))
set(LITE_SRC ${LITE_SRC}
${CORE_DIR}/utils/log_adapter.cc)
endif()
endif()
if(MSLITE_ENABLE_RUNTIME_CONVERT)
file(GLOB RUNTIME_CONVERT_SRC
${LITE_DIR}/src/common/ops/ops_def.cc
${LITE_DIR}/src/common/ops/ops_utils.cc
${LITE_DIR}/src/common/ops/anf_utils.cc
${LITE_DIR}/src/litert/runtime_convert.cc)
set(LITE_SRC ${LITE_SRC} ${RUNTIME_CONVERT_SRC})
endif()
if(MSLITE_ENABLE_STRING_KERNEL)
set(LITE_SRC
${LITE_SRC}
${LITE_DIR}/src/common/string_util.cc
)
endif()
if(ENABLE_RUNTIME_NCX_PASS)
file(GLOB RUNTIME_NCX_PASS_SRC
${LITE_DIR}/src/litert/pass/decrease_transpose_algo.cc
${LITE_DIR}/src/litert/pass/delete_isolated_kernel.cc
${LITE_DIR}/src/litert/pass/infershape_pass.cc
${LITE_DIR}/src/litert/pass/pass_utils.cc
${LITE_DIR}/src/litert/pass/runtime_optimizer.cc
${LITE_DIR}/src/litert/pass/to_nchw_format.cc
${LITE_DIR}/src/litert/pass/transpose_strategy.cc
)
set(LITE_SRC ${LITE_SRC} ${RUNTIME_NCX_PASS_SRC})
endif()
if(MSLITE_ENABLE_WEIGHT_DECODE)
set(LITE_SRC ${LITE_SRC}
${LITE_DIR}/src/litert/huffman_decode.cc)
if(NOT MSLITE_ENABLE_RUNTIME_CONVERT)
set(LITE_SRC ${LITE_SRC}
${TOOLS_DIR}/converter/quantizer/fse_decoder.cc
${TOOLS_DIR}/converter/quantizer/fse_bit_stream.cc)
endif()
endif()
if(MSLITE_ENABLE_RUNTIME_PASS)
file(GLOB KERNEL_ONLINE_FUSION_SRC ${LITE_DIR}/src/litert/pass/online_fusion/*.cc)
set(LITE_SRC
${LITE_SRC}
${KERNEL_ONLINE_FUSION_SRC}
${LITE_DIR}/src/litert/sub_graph_split.cc
)
endif()
if(MSLITE_ENABLE_AUTO_PARALLEL)
set(LITE_SRC
${LITE_SRC}
${LITE_DIR}/src/litert/sub_graph_split.cc
)
endif()
if(MSLITE_ENABLE_CUSTOM_KERNEL)
file(GLOB KERNEL_REG_SRC ${LITE_DIR}/src/registry/*.cc)
endif()
set(LITE_SRC
${LITE_SRC}
${KERNEL_REG_SRC}
${LITE_DIR}/src/litert/weight_decoder.cc
)
if(MSLITE_GPU_BACKEND STREQUAL opencl)
file(GLOB_RECURSE OPENCL_RUNTIME_SRC
${LITE_DIR}/src/litert/kernel/gpu/opencl/*.cc
)
set(LITE_SRC
${LITE_SRC}
${OPENCL_RUNTIME_SRC}
)
endif()
if(MSLITE_GPU_BACKEND STREQUAL cuda)
file(GLOB CUDA_RUNTIME_SRC
${LITE_DIR}/src/litert/gpu/*.cc
${LITE_DIR}/src/litert/gpu/cuda/*.cc
)
set(LITE_SRC
${LITE_SRC}
${CUDA_RUNTIME_SRC}
)
endif()
if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "full")
set(TRAIN_SRC_WITH_MD
${LITE_DIR}/src/train/train_loop.cc
)
endif()
file(GLOB CXX_API_EXPRESSION
${LITE_DIR}/src/litert/cxx_api/expression/*.cc
)
file(GLOB EXPRESSION_OPS
${LITE_DIR}/src/expression/ops/*.cc
)
set(EXPRESSION_SRC
${CXX_API_EXPRESSION}
${LITE_DIR}/src/expression/export.cc
${LITE_DIR}/src/expression/expr.cc
${LITE_DIR}/src/expression/import.cc
${LITE_DIR}/src/expression/net.cc
${LITE_DIR}/src/expression/node.cc
${LITE_DIR}/src/expression/ops.cc
${LITE_DIR}/src/expression/ops_utils.cc
${LITE_DIR}/src/expression/param.cc
${LITE_DIR}/src/expression/sequential.cc
${EXPRESSION_OPS}
)
set(TRAIN_SRC
${API_TRAIN_SRC}
${TRAIN_SRC_WITH_MD}
${EXPRESSION_SRC}
${LITE_DIR}/src/common/quant_utils.cc
${LITE_DIR}/src/litert/cxx_api/metrics/accuracy.cc
${LITE_DIR}/src/litert/cxx_api/train/model_build.cc
${LITE_DIR}/src/litert/cxx_api/train/model_build_impl.cc
${LITE_DIR}/src/litert/cxx_api/train/converters.cc
${LITE_DIR}/src/litert/cxx_api/train/train_support.cc
${LITE_DIR}/src/train/train_populate_parameter.cc
${LITE_DIR}/src/train/train_session.cc
${LITE_DIR}/src/train/graph_fusion.cc
${LITE_DIR}/src/train/graph_dropout.cc
${LITE_DIR}/src/train/transfer_session.cc
${LITE_DIR}/src/train/train_utils.cc
${LITE_DIR}/src/train/loss_monitor.cc
${LITE_DIR}/src/train/lr_scheduler.cc
${LITE_DIR}/src/train/accuracy_metrics.cc
${LITE_DIR}/src/train/accuracy_monitor.cc
${LITE_DIR}/src/train/classification_train_accuracy_monitor.cc
${LITE_DIR}/src/train/train_export.cc
${LITE_DIR}/src/train/opt_allocator.cc
${LITE_DIR}/src/common/storage.cc
${TOOLS_DIR}/converter/optimizer.cc
${TOOLS_DIR}/converter/legacy_optimizer/fusion/fusion_pass.cc
${TOOLS_DIR}/converter/legacy_optimizer/fusion/fusion_pattern.cc
${TOOLS_DIR}/common/meta_graph_utils.cc
${TOOLS_DIR}/converter/legacy_optimizer/fusion/matmul_biasadd_fusion_pass.cc
${TOOLS_DIR}/converter/legacy_optimizer/graph/dropout_node_remove_pass.cc
${TOOLS_DIR}/converter/legacy_optimizer/graph/isolated_node_remove_pass.cc
${TOOLS_DIR}/converter/legacy_optimizer/graph/subgraph_node_pass.cc
)
if(MSLITE_ENABLE_MINDRT)
set(LITE_SRC ${LITE_SRC}
${LITE_DIR}/src/litert/lite_mindrt.cc
${LITE_DIR}/src/litert/mindrt_executor.cc
${LITE_DIR}/src/control_flow/control_actor_creator.cc
)
if(MSLITE_ENABLE_CONTROLFLOW)
file(GLOB CONTROL_FLOW_ACTOR_SRC
${LITE_DIR}/src/control_flow/actor/*.cc
)
set(LITE_SRC ${LITE_SRC} ${CONTROL_FLOW_ACTOR_SRC})
endif()
else()
set(LITE_SRC ${LITE_SRC}
${CORE_DIR}/mindrt/src/thread/core_affinity.cc
${CORE_DIR}/mindrt/src/thread/threadpool.cc
)
endif()
if(MSLITE_ENABLE_GRAPH_KERNEL)
file(GLOB_RECURSE GRAPH_KERNEL_SRC
${TOOLS_DIR}/graph_kernel/common/*.cc
${TOOLS_DIR}/graph_kernel/runtime/*.cc
)
set(LITE_SRC ${LITE_SRC} ${GRAPH_KERNEL_SRC})
endif()
if(NOT MSLITE_ENABLE_COREML)
set(LITE_SRC ${LITE_SRC}
${LITE_DIR}/src/litert/delegate/coreml/stub/coreml_delegate_stub.cc)
endif()
set(MSLITE_GE_LITERT_SRC
${MSLITE_GE_LITERT_SRC}
${LITE_DIR}/src/extendrt/delegate/graph_executor/litert/graph_executor.cc
${LITE_DIR}/src/extendrt/delegate/graph_executor/litert/litert_plugin_impl.cc
)
set(LITE_SRC ${LITE_SRC} ${MSLITE_GE_LITERT_SRC})
add_library(unified_runtime_lite_src_mid OBJECT ${LITE_SRC})
add_dependencies(unified_runtime_lite_src_mid fbs_src)
add_library(lite-unified-executor SHARED $<TARGET_OBJECTS:unified_runtime_lite_src_mid>)
add_dependencies(lite-unified-executor mindspore_converter)
target_link_libraries(lite-unified-executor mindspore_converter)
if(MSVC)
set_target_properties(lite-unified-executor PROPERTIES PREFIX lib)
set_target_properties(lite-unified-executor PROPERTIES IMPORT_PREFIX lib)
set_target_properties(lite-unified-executor PROPERTIES IMPORT_SUFFIX .dll.lib)
endif()
target_link_libraries(lite-unified-executor cpu_kernel_mid nnacl_mid cpu_ops_mid)
if(SUPPORT_TRAIN)
target_link_libraries(lite-unified-executor train_cpu_kernel_mid)
endif()
if(MSLITE_ENABLE_MINDRT)
target_link_libraries(lite-unified-executor mindrt_mid)
endif()
if(PLATFORM_ARM32 OR PLATFORM_ARM64 AND NOT TARGET_HIMIX
AND NOT TARGET_MIX210 AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64)
target_link_libraries(lite-unified-executor log)
endif()
if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "lite")
target_link_libraries(lite-unified-executor minddata_eager_mid minddata-lite)
endif()
########################## build optimize and float16 library #################################
if(PLATFORM_ARM)
if(PLATFORM_ARM64 AND NOT TARGET_HIMIX AND NOT TARGET_MIX210 AND NOT MACHINE_LINUX_ARM64)
target_link_libraries(lite-unified-executor cpu_opt_kernel_mid nnacl_optimize_mid)
endif()
if(MSLITE_ENABLE_FP16)
target_link_libraries(lite-unified-executor cpu_fp16_kernel_mid nnacl_fp16_mid)
endif()
endif()
if(MSLITE_ENABLE_RUNTIME_CONVERT)
target_link_libraries(lite-unified-executor
quantizer_mid fusion_mid proto_mid graph_pass_mid preprocess_mid
cpu_kernel_mid ccsrc_src_mid converter_src_mid lite_exporter_mid
config_parser_mid mslite_converter_plugin mindspore_core coder_mid
mindir_serializer_mid mindspore::protobuf ${SECUREC_LIBRARY})
target_link_libraries(lite-unified-executor
ccsrc_debug_common_mid_ mindir_proto_mid _mindspore_transform_express_ir_obj)
endif()
target_link_libraries(lite-unified-executor mindspore::protobuf)
if(MSLITE_ENABLE_RUNTIME_GLOG)
target_link_libraries(lite-unified-executor mindspore::glog)
endif()
if(NOT WIN32)
target_link_libraries(lite-unified-executor dl)
endif()
if(ENABLE_MODEL_OBF)
target_link_libraries(lite-unified-executor ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
endif()

View File

@ -35,7 +35,7 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE OR MSLITE_ENABLE_CLOUD_INFERENCE)
${CMAKE_CURRENT_SOURCE_DIR}/infer_session.cc
${CMAKE_CURRENT_SOURCE_DIR}/session/single_op_session.cc
${CMAKE_CURRENT_SOURCE_DIR}/session/delegate_session.cc
# ${CMAKE_CURRENT_SOURCE_DIR}/session/default_session.cc
${CMAKE_CURRENT_SOURCE_DIR}/session/default_session.cc
${CMAKE_CURRENT_SOURCE_DIR}/session/factory.cc
${CMAKE_CURRENT_SOURCE_DIR}/infer_device_address.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/kernel_build_utils.cc
@ -52,8 +52,14 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE OR MSLITE_ENABLE_CLOUD_INFERENCE)
${CMAKE_CURRENT_SOURCE_DIR}/delegate_graph_executor.cc
${CMAKE_CURRENT_SOURCE_DIR}/session/optimizer/tensorrt_optimizer.cc
${CMAKE_CURRENT_SOURCE_DIR}/delegate/graph_executor/litert/func_graph_reuse_manager.cc
# ${CMAKE_CURRENT_SOURCE_DIR}/graph_compiler/factory.cc
# ${CMAKE_CURRENT_SOURCE_DIR}/graph_runtime/factory.cc
${CMAKE_CURRENT_SOURCE_DIR}/graph_compiler/factory.cc
${CMAKE_CURRENT_SOURCE_DIR}/graph_compiler/default_graph_compiler.cc
${CMAKE_CURRENT_SOURCE_DIR}/graph_runtime/factory.cc
${CMAKE_CURRENT_SOURCE_DIR}/graph_runtime/default_graph_runtime.cc
${CMAKE_CURRENT_SOURCE_DIR}/graph_executor/factory.cc
${CMAKE_CURRENT_SOURCE_DIR}/graph_executor/mindrt_graph_executor.cc
${CMAKE_CURRENT_SOURCE_DIR}/execution_flow.cc
${CMAKE_CURRENT_SOURCE_DIR}/execution_plan.cc
)
if(MSLITE_ENABLE_BFC_MEMORY)
set(MSLITE_EXTEND_RUNTIME_SRC ${MSLITE_EXTEND_RUNTIME_SRC}
@ -163,6 +169,12 @@ if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE OR MSLITE_ENABLE_CLOUD_INFERENCE)
add_dependencies(mindspore-extendrt_static msplugin-ge-litert)
target_link_libraries(mindspore-extendrt_static msplugin-ge-litert)
add_subdirectory(${LITE_DIR}/src/executor unified_executor)
add_dependencies(mindspore-extendrt lite-unified-executor)
target_link_libraries(mindspore-extendrt lite-unified-executor)
target_link_libraries(mindspore-extendrt_static lite-unified-executor)
if(NOT PLATFORM_ARM)
set(KERNEL_MOD_DEPEND_SRC
${CCSRC_DIR}/kernel/environ_manager.cc

View File

@ -42,22 +42,25 @@ ExecutionFlow::~ExecutionFlow() {
}
abstract::Kernel *ExecutionFlow::ConstructFusionKernel() {
auto lite_kernel = new (std::nothrow) mindspore::kernel::LiteKernel(nullptr, inputs_, outputs_, context_);
auto lite_kernel = new (std::nothrow) mindspore::kernel::LiteKernel(nullptr, inputs_, outputs_, context_.get());
if (lite_kernel == nullptr) {
MS_LOG(ERROR) << "ExecutionFlow::ConstructFusionKernel create lite kernel failed, may be memory is not enough";
return nullptr;
}
std::vector<KernelExec *> input_kernels = mindspore::kernel::KernelExecUtil::SubgraphInputNodes(kernels_);
std::vector<KernelExec *> output_kernels = mindspore::kernel::KernelExecUtil::SubgraphOutputNodes(kernels_);
std::vector<mindspore::kernel::KernelExec *> input_kernels =
mindspore::kernel::KernelExecUtil::SubgraphInputNodes(kernels_);
std::vector<mindspore::kernel::KernelExec *> output_kernels =
mindspore::kernel::KernelExecUtil::SubgraphOutputNodes(kernels_);
mindspore::kernel::SubGraphKernel *sub_graph_kernel =
new CpuFp32SubGraph(input_kernels, output_kernels, kernels_, lite_kernel);
new mindspore::kernel::CpuFp32SubGraph(input_kernels, output_kernels, kernels_, lite_kernel);
if (sub_graph_kernel == nullptr) {
MS_LOG(ERROR) << "ExecutionFlow::ConstructFusionKernel create sub graph kernel failed, may be memory is not enough";
delete lite_kernel return nullptr;
delete lite_kernel;
return nullptr;
}
sub_graph_kernel->set_context(context_);
sub_graph_kernel->set_context(context_.get());
return sub_graph_kernel;
}
} // namespace mindspore::infer

View File

@ -67,13 +67,13 @@ class ExecutionPlan : public abstract::ExecutionPlan {
input_isolate_map_ = input_isolate_map;
}
std::unordered_map<abstract::Tensor *, abstract::Tensor *> *GetInputMap() { return input_isolate_map_; }
std::unordered_map<abstract::Tensor *, abstract::Tensor *> *GetInputsMap() { return input_isolate_map_; }
void SetOutputsMap(std::unordered_map<abstract::Tensor *, abstract::Tensor *> *output_isolate_map) {
output_isolate_map_ = output_isolate_map;
}
std::unordered_map<abstract::Tensor *, abstract::Tensor *> *GetOutputMap() { return output_isolate_map_; }
std::unordered_map<abstract::Tensor *, abstract::Tensor *> *GetOutputsMap() { return output_isolate_map_; }
std::vector<abstract::Kernel *> ToKernelList() override;

View File

@ -16,14 +16,15 @@
#include <unordered_map>
#include <algorithm>
#include <utility>
#include "extendrt/graph_compiler/default_graph_compiler.h"
#include "extendrt/graph_compiler/factory.h"
#include "extendrt/execution_plan.h"
#include "extendrt/mock/lite_runtime/converters.h"
#include "backend/graph_compiler/graph_partition.h"
#include "backend/graph_compiler/segment_runner.h"
#include "common/log.h"
#include "ops/core_ops.h"
#include "include/common/utils/utils.h"
namespace mindspore {
static const std::vector<PrimitivePtr> ms_infer_cut_list = {prim::kPrimReturn, prim::kPrimPartial,
@ -31,7 +32,7 @@ static const std::vector<PrimitivePtr> ms_infer_cut_list = {prim::kPrimReturn,
prim::kPrimBpropCut, prim::kPrimSwitchLayer};
static constexpr auto ms_infer_backend_name = "mindspore_lite_backend";
std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Compile(FuncGraphPtr graph) {
std::shared_ptr<infer::abstract::ExecutionPlan> DefaultGraphCompiler::Compile(FuncGraphPtr graph) {
MS_LOG(INFO) << "DefaultGraphCompiler::Compile";
inner_context_ = ContextUtils::Convert(context_.get());
@ -45,7 +46,7 @@ std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Compile(FuncGraph
MS_LOG(DEBUG) << "DefaultGraphCompiler::Partition Partition FunctionGraph End";
MS_LOG(DEBUG) << "DefaultGraphCompiler::Compile Schedule Graph Execute Plan Begin";
auto execution_plan = Schedule(graph_segments);
auto execution_plan = Schedule(graph_segments, graph);
if (execution_plan == nullptr) {
MS_LOG(ERROR) << "DefaultGraphCompiler::Partition partition graph failed";
return nullptr;
@ -55,7 +56,7 @@ std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Compile(FuncGraph
}
std::vector<GraphSegmentPtr> DefaultGraphCompiler::Partition(const FuncGraphPtr &graph) {
auto partition = std::make_shared<GraphPartition>(ms_infer_cut_list, ms_infer_backend_name);
auto partition = std::make_shared<compile::GraphPartition>(ms_infer_cut_list, ms_infer_backend_name);
if (partition == nullptr) {
MS_LOG(ERROR) << "DefaultGraphCompiler::Partition create graph partition failed, maybe not enough memory";
return std::vector<GraphSegmentPtr>();
@ -64,25 +65,29 @@ std::vector<GraphSegmentPtr> DefaultGraphCompiler::Partition(const FuncGraphPtr
// if the context target is cpu, graph should convert to NHWC, call related pass
// multi_target set false
return partition->Partition(graph, false);
bool is_multi_target;
return partition->Partition(graph, &is_multi_target);
}
std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Schedule(
std::shared_ptr<infer::abstract::ExecutionPlan> DefaultGraphCompiler::Schedule(
const std::vector<GraphSegmentPtr> &graph_segments, FuncGraphPtr func_graph) {
auto execution_plan = std::make_shared<infer::ExecutionPlan>();
anf_tensor_map_.clear();
std::unordered_map<Tensor *, Tensor *> *input_isolate_map = new std::unordered_map<Tensor *, Tensor *>();
std::unordered_map<Tensor *, Tensor *> *output_isolate_map = new std::unordered_map<Tensor *, Tensor *>();
std::unordered_map<infer::abstract::Tensor *, infer::abstract::Tensor *> *input_isolate_map =
new std::unordered_map<infer::abstract::Tensor *, infer::abstract::Tensor *>();
std::unordered_map<infer::abstract::Tensor *, infer::abstract::Tensor *> *output_isolate_map =
new std::unordered_map<infer::abstract::Tensor *, infer::abstract::Tensor *>();
// Convert FuncGraph Input and Output AnfNode to Tensor and save in Execution Plan
auto graph_inputs = func_grapn->get_inputs();
auto graph_inputs = func_graph->get_inputs();
if (graph_inputs.empty()) {
MS_LOG(ERROR) << "DefaultGraphCompiler::Schedule get graph inputs node failed";
delete input_isolate_map;
delete output_isolate_map;
return nullptr;
}
std::vector<AnfNodePtr> graph_outputs;
auto graph_output = func_graph->output();
if (graph_output == nullptr) {
MS_LOG(ERROR) << "DefaultGraphCompiler::Schedule get graph output node failed";
@ -90,6 +95,7 @@ std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Schedule(
delete output_isolate_map;
return nullptr;
}
graph_outputs.emplace_back(graph_output);
auto graph_input_tensors = CreateTensors(graph_inputs);
if (graph_input_tensors.size() != graph_inputs.size()) {
MS_LOG(ERROR) << "DefaultGraphCompiler::Schedule create graph input tensors failed";
@ -98,14 +104,14 @@ std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Schedule(
return nullptr;
}
execution_plan->SetInputs(graph_input_tensors);
auto graph_output_tensor = CreateTensor(graph_output);
if (graph_output_tensor == nullptr) {
auto graph_output_tensors = CreateTensors(graph_outputs);
if (graph_output_tensors.size() != graph_outputs.size()) {
MS_LOG(ERROR) << "DefaultGraphCompiler::Schedule create graph output tensor failed";
delete input_isolate_map;
delete output_isolate_map;
return nullptr;
}
execution_plan->SetOutputs(graph_output_tensor);
execution_plan->SetOutputs(graph_output_tensors);
execution_plan->SetContext(inner_context_);
for (auto graph_segment : graph_segments) {
@ -122,25 +128,25 @@ std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Schedule(
}
execution_flow->SetContext(inner_context_);
for (auto i = 0; i < execution_flow->GetInputs().size(); i++) {
for (size_t i = 0; i < execution_flow->GetInputs().size(); i++) {
auto input_tensor = execution_flow->GetInputs()[i];
auto input_node = inputs[i];
auto it = anf_tensor_map_.find(input_node);
if (it != anf_tensor_map_.end()) {
auto outter_tensor = it->second;
input_isolate_map[input_tensor] = outter_tensor;
(*input_isolate_map)[input_tensor] = outter_tensor;
} else {
anf_tensor_map_[input_node] = input_tensor;
}
}
for (auto i = 0; i < execution_flow->GetOutputs().size(); i++) {
for (size_t i = 0; i < execution_flow->GetOutputs().size(); i++) {
auto output_tensor = execution_flow->GetOutputs()[i];
auto output_node = outputs[i];
auto it = anf_tensor_map_.find(output_node);
if (it != anf_tensor_map_.end()) {
auto outter_tensor = it->second;
output_isolate_map[output_tensor] = outter_tensor;
(*output_isolate_map)[output_tensor] = outter_tensor;
} else {
anf_tensor_map_[output_node] = output_tensor;
}
@ -148,15 +154,15 @@ std::shared_ptr<abstract::ExecutionPlan> DefaultGraphCompiler::Schedule(
execution_plan->AddExecutionFlow(execution_flow);
}
execution_plan->SetInputMap(input_isolate_map);
execution_plan->SetOutputMap(output_isolate_map);
execution_plan->SetInputsMap(input_isolate_map);
execution_plan->SetOutputsMap(output_isolate_map);
return execution_plan;
}
infer::abstract::Tensor *DefaultGraphCompiler::CreateTensor(AnfNodePtr node) {
if (node->isa<CNode>) {
} else if (node->isa<Parameter>) {
if (node->isa<CNode>()) {
} else if (node->isa<Parameter>()) {
auto parameter_node = node->cast<ParameterPtr>();
if (parameter_node == nullptr) {
MS_LOG(ERROR) << "parameter node is nullptr";
@ -227,18 +233,142 @@ Status DefaultGraphCompiler::GetDTAndShapeFromAbTensor(const abstract::AbstractT
std::vector<infer::abstract::Tensor *> DefaultGraphCompiler::CreateTensors(const std::vector<AnfNodePtr> &nodes) {
std::vector<infer::abstract::Tensor *> tensors;
std::transform(nodes.begin(), nodes.end(), std::back_inserter(tensors),
[](AnfNodePtr node) { return CreateTensor(node); });
[this](AnfNodePtr node) { return this->CreateTensor(node); });
return tensors;
}
std::shared_ptr<abstract::ExecutionFlow> DefaultGraphCompiler::Schedule(const GraphSegmentPtr &graph_segment,
const std::vector<AnfNodePtr> &inputs,
const std::vector<AnfNodePtr> &outputs) {
std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> DefaultGraphCompiler::TransformSegmentToAnfGraph(
const AnfNodePtrList &lst) {
if (lst.empty()) {
MS_LOG(EXCEPTION) << "Input anf node list is empty";
}
FuncGraphPtr fg = nullptr;
{
// limit the lifetime of guard.
MS_EXCEPTION_IF_NULL(lst[0]->cast<CNodePtr>());
MS_EXCEPTION_IF_NULL(lst[0]->cast<CNodePtr>()->func_graph());
TraceGuard guard(std::make_shared<TraceSegmentTransform>(lst[0]->cast<CNodePtr>()->func_graph()->debug_info()));
fg = std::make_shared<FuncGraph>();
}
AnfNodePtrList inputs;
mindspore::HashMap<AnfNodePtr, AnfNodePtr> eqv;
// Merge CNodes into a AnfGraph that represents a linear instruction segment
for (auto n : lst) {
MS_EXCEPTION_IF_NULL(n);
if (!n->isa<CNode>()) {
MS_LOG(EXCEPTION) << "Inst is not CNode";
}
auto &inps = n->cast<CNodePtr>()->inputs();
if (inps.empty()) {
MS_LOG(EXCEPTION) << "Input is empty";
}
if (!IsValueNode<Primitive>(inps[0]) &&
!(IsValueNode<FuncGraph>(inps[0]) &&
inps[0]->cast<ValueNodePtr>()->value()->cast<FuncGraphPtr>()->has_attr(FUNC_GRAPH_ATTR_GRAPH_KERNEL))) {
MS_LOG(EXCEPTION) << "Input[0] must be a Primitive ValueNode";
}
auto fn = inps[0];
std::vector<AnfNodePtr> args{fn};
if (IsPrimitive(fn, prim::kPrimDepend) && inps.size() >= kDependInputSize &&
eqv.find(inps[kDependAttachNodeIndex]) == eqv.end()) {
args.emplace_back(RefSubGraphNode(fg, inps[kRealInputIndexInDepend], &inputs, &eqv));
const size_t value_start_index = 2;
for (size_t i = value_start_index; i < inps.size(); ++i) {
args.emplace_back(NewValueNode(MakeValue(0)));
}
} else {
(void)std::transform(
std::begin(inps) + 1, std::end(inps), std::back_inserter(args),
[&fg, &inputs, &eqv, this](const AnfNodePtr &a) { return this->RefSubGraphNode(fg, a, &inputs, &eqv); });
}
TraceGuard tg(std::make_shared<TraceSegmentTransform>(n->debug_info()));
MS_EXCEPTION_IF_NULL(fg);
eqv[n] = fg->NewCNode(args);
eqv[n]->set_abstract(n->abstract());
eqv[n]->set_kernel_info(n->kernel_info_ptr());
}
mindspore::HashSet<AnfNodePtr> eqv_keys;
for (auto &e : eqv) {
(void)eqv_keys.emplace(e.first);
}
auto mgr = lst[0]->func_graph()->manager();
MS_EXCEPTION_IF_NULL(mgr);
auto outputs = GetOutput(lst, mgr->node_users(), eqv_keys);
AnfNodePtr fg_output;
if (outputs.size() > 1) {
std::vector<AnfNodePtr> output_args;
output_args.push_back(NewValueNode(prim::kPrimMakeTuple));
(void)std::transform(std::begin(outputs), std::end(outputs), std::back_inserter(output_args),
[&eqv](const AnfNodePtr &o) -> AnfNodePtr { return eqv[o]; });
// Set output for AnfGraph
fg_output = fg->NewCNode(output_args);
} else {
if (outputs.empty()) {
MS_LOG(EXCEPTION) << "Output is empty.";
}
fg_output = eqv[outputs[0]];
}
fg->set_output(fg_output);
return std::make_tuple(fg, inputs, outputs);
}
AnfNodePtrList DefaultGraphCompiler::GetOutput(const AnfNodePtrList &nodes, const NodeUsersMap &users,
const mindspore::HashSet<AnfNodePtr> &seen) {
AnfNodePtrList output;
if (users.size() == 0) {
return output;
}
for (auto &node : nodes) {
MS_EXCEPTION_IF_NULL(node);
if (!node->isa<CNode>()) {
continue;
}
auto iter = users.find(node);
if (iter == users.end()) {
continue;
}
auto &node_users = iter->second;
const bool has_outer_user = std::any_of(std::begin(node_users), std::end(node_users),
[&seen](const std::pair<AnfNodePtr, int64_t> &u) -> bool {
const bool is_outer_user = (seen.find(u.first) == seen.end());
return is_outer_user;
});
if (has_outer_user) {
output.emplace_back(node);
}
}
return output;
}
AnfNodePtr DefaultGraphCompiler::RefSubGraphNode(const FuncGraphPtr &fg, const AnfNodePtr &node,
AnfNodePtrList *inputs_ptr,
mindspore::HashMap<AnfNodePtr, AnfNodePtr> *eqv_ptr) {
MS_EXCEPTION_IF_NULL(fg);
MS_EXCEPTION_IF_NULL(inputs_ptr);
MS_EXCEPTION_IF_NULL(eqv_ptr);
MS_EXCEPTION_IF_NULL(node);
auto &inputs = *inputs_ptr;
auto &eqv = *eqv_ptr;
if (node->isa<ValueNode>() && !IsValueNode<FuncGraph>(node)) {
eqv[node] = node;
} else if (eqv.find(node) == eqv.end()) {
inputs.push_back(node);
eqv[node] = fg->add_parameter();
eqv[node]->set_abstract(node->abstract());
eqv[node]->set_kernel_info(node->kernel_info_ptr());
}
return eqv[node];
}
std::shared_ptr<infer::abstract::ExecutionFlow> DefaultGraphCompiler::Schedule(const GraphSegmentPtr &graph_segment,
const std::vector<AnfNodePtr> &inputs,
const std::vector<AnfNodePtr> &outputs) {
// implementation by hangangqiang
return nullptr;
}
static std::shared_ptr<InferSession> DefaultGraphCompilerCreator(const std::shared_ptr<Context> &ctx) {
static std::shared_ptr<infer::abstract::GraphCompiler> DefaultGraphCompilerCreator(
const std::shared_ptr<Context> &ctx) {
auto graph_compiler = std::make_shared<DefaultGraphCompiler>(ctx);
return graph_compiler;
}

View File

@ -18,6 +18,7 @@
#include <memory>
#include <vector>
#include <tuple>
#include "infer/graph_compiler.h"
#include "infer/context.h"
@ -30,15 +31,15 @@ class DefaultGraphCompiler : public mindspore::infer::abstract::GraphCompiler {
}
virtual ~DefaultGraphCompiler() = default;
std::shared_ptr<abstract::ExecutionPlan> Compile(FuncGraphPtr graph) override;
std::shared_ptr<infer::abstract::ExecutionPlan> Compile(FuncGraphPtr graph) override;
protected:
virtual std::vector<GraphSegmentPtr> Partition(const FuncGraphPtr &graph);
virtual std::shared_ptr<abstract::ExecutionPlan> Schedule(const std::vector<GraphSegmentPtr> &graph_segments,
virtual std::shared_ptr<infer::abstract::ExecutionPlan> Schedule(const std::vector<GraphSegmentPtr> &graph_segments,
FuncGraphPtr func_graph);
virtual std::shared_ptr<abstract::ExecutionFlow> Schedule(const GraphSegmentPtr &graph_segment,
virtual std::shared_ptr<infer::abstract::ExecutionFlow> Schedule(const GraphSegmentPtr &graph_segment,
const std::vector<AnfNodePtr> &inputs,
const std::vector<AnfNodePtr> &outputs);
@ -49,11 +50,17 @@ class DefaultGraphCompiler : public mindspore::infer::abstract::GraphCompiler {
Status GetDTAndShapeFromAbTensor(const abstract::AbstractTensorPtr &abstract, TypeId *data_type,
ShapeVector *shape_vector);
std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> TransformSegmentToAnfGraph(const AnfNodePtrList &lst);
AnfNodePtrList GetOutput(const AnfNodePtrList &nodes, const NodeUsersMap &users,
const mindspore::HashSet<AnfNodePtr> &seen);
AnfNodePtr RefSubGraphNode(const FuncGraphPtr &fg, const AnfNodePtr &node, AnfNodePtrList *inputs_ptr,
mindspore::HashMap<AnfNodePtr, AnfNodePtr> *eqv_ptr);
private:
mindspore::HashMap<AnfNodePtr, infer::abstract::Tensor *> anf_tensor_map_;
const std::shared_ptr<Context> &context_;
std::shared_ptr<mindspore::infer::abstract::Context> inner_context_;
}
};
} // namespace mindspore
#endif // MINDSPORE_LITE_EXTENDRT_GRAPH_COMPILER_DEFAULT_GRAPH_COMPILER_H_

View File

@ -17,6 +17,6 @@
#define MINDSPORE_LITE_EXTENDRT_GRAPH_COMIPLER_TYPE_H_
namespace mindspore {
enum GraphCompilerType { kDefaultCompiler = 0, kSingleOpSession, kLiteInferSession, kDelegateSession, kNoneCompiler };
enum GraphCompilerType { kDefaultCompiler = 0, kNoneCompiler };
} // namespace mindspore
#endif // MINDSPORE_LITE_EXTENDRT_GRAPH_COMIPLER_TYPE_H_

View File

@ -27,11 +27,13 @@ void GraphExecutorRegistry::RegExecutor(const mindspore::GraphExecutorType &type
graph_executor_map_[type] = creator;
}
std::shared_ptr<infer::GraphExecutor> GraphExecutorRegistry::GetExecutor(const mindspore::GraphExecutorType &type) {
std::shared_ptr<infer::abstract::Executor> GraphExecutorRegistry::GetExecutor(
const mindspore::GraphExecutorType &type, const std::string &name,
std::shared_ptr<infer::abstract::ExecutionPlan> execution_plan) {
auto it = graph_executor_map_.find(type);
if (it == graph_executor_map_.end()) {
return nullptr;
}
return it->second();
return it->second(name, execution_plan);
}
} // namespace mindspore

View File

@ -15,7 +15,8 @@
*/
#include "extendrt/graph_executor/mindrt_graph_executor.h"
#include "src/common/log.h"
#include <algorithm>
#include "extendrt/graph_executor/factory.h"
#include "litert/mindrt_executor.h"
#include "extendrt/execution_plan.h"
@ -34,8 +35,8 @@ MindRTGraphExecutor::MindRTGraphExecutor(const std::string &name,
if (infer_execution_plan == nullptr) {
MS_LOG(ERROR) << "MindRTGraphExecutor::MindRTGraphExecutor Not Supported execution plan is passed";
} else {
mindrt_executor_ = std::make_shared<mindspore::lite::MindrtExecutor>(infer_execution_plan->GetInputMap(),
infer_execution_plan->GetOutputMap());
mindrt_executor_ = std::make_shared<mindspore::lite::MindrtExecutor>(infer_execution_plan->GetInputsMap(),
infer_execution_plan->GetOutputsMap());
}
}
@ -48,8 +49,13 @@ Status MindRTGraphExecutor::Prepare() {
MS_LOG(ERROR) << "FlowExecutor::Prepare execution plan is nullptr";
return kLiteError;
}
return mindrt_executor_->Prepare(execution_plan_->ToKernelList(), execution_plan_->GetInputs(),
execution_plan_->GetOutputs(), execution_plan_->GetContext().get());
auto ret = mindrt_executor_->Prepare(execution_plan_->ToKernelList(), execution_plan_->GetInputs(),
execution_plan_->GetOutputs(), execution_plan_->GetContext().get());
if (ret != 0) {
MS_LOG(ERROR) << "FlowExecutor::Prepare prepare execution plan failed with code " << ret;
return kLiteError;
}
return kSuccess;
}
Status MindRTGraphExecutor::Execute() {
@ -61,18 +67,30 @@ Status MindRTGraphExecutor::Execute() {
MS_LOG(ERROR) << "FlowExecutor::Execute execution plan is nullptr";
return kLiteError;
}
return mindrt_executor_->Run(execution_plan_->GetInputs(), execution_plan_->GetOutputs(),
execution_plan_->ToKernelList(), execution_plan_->GetKernelBeforeCallBack(),
execution_plan_->GetKernelAfterCallBack());
auto ret =
mindrt_executor_->Run(execution_plan_->GetInputs(), execution_plan_->GetOutputs(), execution_plan_->ToKernelList(),
execution_plan_->GetKernelBeforeCallBack(), execution_plan_->GetKernelAfterCallBack());
if (ret != 0) {
MS_LOG(ERROR) << "FlowExecutor::Execute run execution plan failed with code " << ret;
return kLiteError;
}
return kSuccess;
}
int MindRTGraphExecutor::Resize(const std::vector<infer::abstract::Tensor *> &inputs,
const std::vector<std::vector<int>> &dims) {
const std::vector<std::vector<int64_t>> &dims) {
if (mindrt_executor_ == nullptr) {
MS_LOG(ERROR) << "FlowExecutor::Resize executor is nullptr";
return kLiteError;
}
return mindrt_executor_->Resize(inputs, dims);
std::vector<std::vector<int>> dims32;
std::transform(dims.begin(), dims.end(), std::back_inserter(dims32), [](std::vector<int64_t> shape) {
std::vector<int> shape32;
std::transform(shape.begin(), shape.end(), std::back_inserter(shape32),
[](int64_t dim) { return static_cast<int>(dim); });
return shape32;
});
return mindrt_executor_->Resize(inputs, dims32);
}
static std::shared_ptr<infer::abstract::Executor> MindRTGraphExecutorCreator(

View File

@ -37,7 +37,8 @@ class MindRTGraphExecutor : public mindspore::infer::abstract::Executor {
Status Execute() override;
int Resize(const std::vector<infer::abstract::Tensor *> &inputs, const std::vector<std::vector<int>> &dims) override;
int Resize(const std::vector<infer::abstract::Tensor *> &inputs,
const std::vector<std::vector<int64_t>> &dims) override;
private:
std::string name_;

View File

@ -15,9 +15,8 @@
*/
#include "extendrt/graph_runtime/default_graph_runtime.h"
#include "extendrt/graph_executor/plan_executor.h"
#include "src/common/log.h"
#include "extendrt/graph_runtime/factory.h"
#include "extendrt/graph_executor/factory.h"
namespace mindspore {
using ExecutionPlan = mindspore::infer::abstract::ExecutionPlan;
@ -38,7 +37,7 @@ Status DefaultGraphRuntime::Prepare(std::shared_ptr<ExecutionPlan> execution_pla
}
MS_LOG(DEBUG) << "DefaultGraphRuntime::Prepare Prepare Execution Plan Begin of Executor " << executor->Name();
auto status = executor->Prepare(nullptr);
auto status = executor->Prepare();
if (status != kSuccess) {
MS_LOG(ERROR) << "DefaultGraphRuntime::Prepare Prepare Execution Plan Failed in Executor " << executor->Name();
return kLiteError;
@ -107,7 +106,7 @@ Status DefaultGraphRuntime::Execute(const std::vector<infer::abstract::Tensor *>
return kSuccess;
}
Status DefaultGraphRuntime::Resize(const std::vector<infer::abstract::Tensor *> *inputs,
Status DefaultGraphRuntime::Resize(const std::vector<infer::abstract::Tensor *> &inputs,
const std::vector<std::vector<int64_t>> &dims) {
MS_LOG(INFO) << "DefaultGraphRuntime::Resize Begin";
@ -134,14 +133,31 @@ Status DefaultGraphRuntime::Resize(const std::vector<infer::abstract::Tensor *>
return kSuccess;
}
std::vector<infer::abstract::Tensor *> DefaultGraphRuntime::GetInputs() {
if (execution_plan_ == nullptr) {
MS_LOG(ERROR) << "DefaultGraphRuntime::Execute Execution Plan is nullptr.";
return std::vector<infer::abstract::Tensor *>{};
}
return execution_plan_->GetInputs();
}
std::vector<infer::abstract::Tensor *> DefaultGraphRuntime::GetOutputs() {
if (execution_plan_ == nullptr) {
MS_LOG(ERROR) << "DefaultGraphRuntime::Execute Execution Plan is nullptr.";
return std::vector<infer::abstract::Tensor *>{};
}
return execution_plan_->GetOutputs();
}
std::shared_ptr<infer::abstract::Executor> DefaultGraphRuntime::SelectExecutor() {
if (default_executor_ == nullptr) {
default_executor_ = std::make_shared<infer::PlanExecutor>("plan-executor");
default_executor_ =
GraphExecutorRegistry::GetInstance().GetExecutor(kMindRTExecutor, "mindrt-executor", execution_plan_);
}
return default_executor_;
}
static std::shared_ptr<InferSession> DefaultGraphRuntimeCreator() {
static std::shared_ptr<infer::abstract::GraphRuntime> DefaultGraphRuntimeCreator() {
auto graph_runtime = std::make_shared<DefaultGraphRuntime>();
return graph_runtime;
}

View File

@ -36,9 +36,13 @@ class DefaultGraphRuntime : public mindspore::infer::abstract::GraphRuntime {
infer::abstract::KernelCallBack before = nullptr,
infer::abstract::KernelCallBack after = nullptr) override;
Status Resize(const std::vector<infer::abstract::Tensor *> *inputs,
Status Resize(const std::vector<infer::abstract::Tensor *> &inputs,
const std::vector<std::vector<int64_t>> &dims) override;
std::vector<infer::abstract::Tensor *> GetInputs() override;
std::vector<infer::abstract::Tensor *> GetOutputs() override;
private:
std::shared_ptr<infer::abstract::Executor> SelectExecutor();

View File

@ -17,6 +17,6 @@
#define MINDSPORE_LITE_EXTENDRT_GRAPH_RUNTIME_TYPE_H_
namespace mindspore {
enum GraphRuntimeType { kDefaultRuntime = 0, kSingleOpSession, kLiteInferSession, kDelegateSession, kNoneRuntime };
enum GraphRuntimeType { kDefaultRuntime = 0, kNoneRuntime };
} // namespace mindspore
#endif // MINDSPORE_LITE_EXTENDRT_GRAPH_RUNTIME_TYPE_H_

View File

@ -30,7 +30,7 @@ namespace mindspore {
/// \brief Default Infer Session Implementation, using kernelmod, not implemented now.
class DefaultInferSession : public InferSession {
public:
explicit DefaultInferSession(const std::shared_ptr<Context> &context) { context_ = context; }
explicit DefaultInferSession(const std::shared_ptr<Context> &context) : context_(context) {}
virtual ~DefaultInferSession() = default;
Status Init(const std::shared_ptr<Context> &context) override;
Status CompileGraph(FuncGraphPtr graph, const void *data = nullptr, size_t size = 0) override;

View File

@ -48,10 +48,10 @@ class Executor : public std::enable_shared_from_this<Executor> {
/// \brief Resize Executor Kernels.
///
/// \param[in] inputs, inputs need resize
/// \param[in] dim, target shapes for resize inputs
/// \param[in] dims, target shapes for resize inputs
///
/// \return Status.
virtual int Resize(const std::vector<Tensor *> &inputs, const std::vector<std::vector<int>> &dims) = 0;
virtual int Resize(const std::vector<Tensor *> &inputs, const std::vector<std::vector<int64_t>> &dims) = 0;
};
} // namespace mindspore::infer::abstract

View File

@ -56,7 +56,7 @@ class GraphRuntime : public std::enable_shared_from_this<GraphRuntime> {
/// \param[in] dims, targe dim shape to resize
///
/// \return Status.
virtual Status Resize(const std::vector<Tensor *> *inputs, const std::vector<std::vector<int64_t>> &dims) = 0;
virtual Status Resize(const std::vector<Tensor *> &inputs, const std::vector<std::vector<int64_t>> &dims) = 0;
/// \brief Get list of inputs for the model.
///