From 1a10422b645cbaccd7be663c56dc2d3cab3688a9 Mon Sep 17 00:00:00 2001 From: ling Date: Sat, 27 Feb 2021 09:09:30 +0800 Subject: [PATCH] [MSLITE]mindrt support windows and convertor --- .../core/mindrt/include/actor/op_actor.h | 7 ++++- mindspore/lite/CMakeLists.txt | 7 +++-- mindspore/lite/src/CMakeLists.txt | 9 ++++--- mindspore/lite/src/lite_mindrt.h | 17 +++++++----- mindspore/lite/src/mindrt_executor.cc | 2 +- mindspore/lite/test/CMakeLists.txt | 26 ++++++++++++------- mindspore/lite/tools/converter/CMakeLists.txt | 24 ++++++++++++----- 7 files changed, 61 insertions(+), 31 deletions(-) diff --git a/mindspore/core/mindrt/include/actor/op_actor.h b/mindspore/core/mindrt/include/actor/op_actor.h index 07f0d081eb..19b121a1ff 100644 --- a/mindspore/core/mindrt/include/actor/op_actor.h +++ b/mindspore/core/mindrt/include/actor/op_actor.h @@ -53,6 +53,8 @@ struct OpContext { uuids::uuid *sequential_num_; std::vector> *outputData_; std::vector> *results_; + const void *kernel_call_back_before_; + const void *kernel_call_back_after_; void SetFailed(int32_t code) { for (auto promise : *results_) { promise.SetFailed(code); @@ -89,13 +91,16 @@ Future> MindrtAsyncRun(const std::vector> &inputData } template -int MindrtRun(const std::vector> &inputData, std::vector> *outputData) { +int MindrtRun(const std::vector> &inputData, std::vector> *outputData, + const void *kernel_call_back_before, const void *kernel_call_back_after) { OpContext context; std::vector> promises(outputData->size()); uuids::uuid uid; context.sequential_num_ = &uid; context.results_ = &promises; context.outputData_ = outputData; + context.kernel_call_back_before_ = kernel_call_back_before; + context.kernel_call_back_after_ = kernel_call_back_after; auto collect = MindrtAsyncRun(inputData, &context); collect.Wait(); diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 65128f7fd3..3c04b09635 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -208,7 +208,10 @@ if(WIN32) add_compile_definitions(LITE_EXPORTS) add_compile_definitions(BUILDING_DLL) endif() -add_subdirectory(${CORE_DIR}/mindrt mindspore_mindrt) + +if(ENABLE_MINDRT) + include_directories(${CORE_DIR}/mindrt/include) +endif() if(ENABLE_CONVERTER) if(PLATFORM_ARM) @@ -222,10 +225,10 @@ if(ENABLE_CONVERTER) endif() if(ENABLE_MINDRT) - include_directories(${CORE_DIR}/mindrt/include) add_compile_definitions(ENABLE_MINDRT) endif() + if(PLATFORM_ARM32 OR PLATFORM_ARM64) if(NOT DEFINED ENV{ANDROID_NDK}) message(FATAL_ERROR "env ANDROID_NDK should be set for ARM compile") diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index 09f8139f67..2c5822306e 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -116,11 +116,12 @@ if(SUPPORT_TRAIN) endif() if(ENABLE_MINDRT) + add_subdirectory(${CORE_DIR}/mindrt mindspore_mindrt) set(LITE_SRC - ${LITE_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc - ${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc - ) + ${LITE_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc + ${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc + ) endif() add_subdirectory(ops) diff --git a/mindspore/lite/src/lite_mindrt.h b/mindspore/lite/src/lite_mindrt.h index dd52ae91a1..4bd71bda33 100644 --- a/mindspore/lite/src/lite_mindrt.h +++ b/mindspore/lite/src/lite_mindrt.h @@ -25,6 +25,7 @@ #include "actor/actor.h" #include "async/uuid_base.h" #include "async/future.h" +#include "src/sub_graph_kernel.h" namespace mindspore { namespace lite { @@ -36,18 +37,20 @@ class LiteOpActor : public OpActor { explicit LiteOpActor(kernel::LiteKernel *kernel) : OpActor(kernel->name()), kernel_(kernel) {} virtual ~LiteOpActor() = default; virtual void OpRun(OpDataPtr inputs, OpContext *context = nullptr) { - input_op_datas_[context->sequential_num_].push_back(inputs); - if (input_op_datas_[context->sequential_num_].size() < kernel_->in_tensors().size()) { + auto op_uuid = context->sequential_num_; + input_op_datas_[op_uuid].push_back(inputs); + if (input_op_datas_[op_uuid].size() < kernel_->in_tensors().size()) { return; } - auto ret = RunKernel(); + auto ret = RunKernel(*(reinterpret_cast(context->kernel_call_back_before_)), + *(reinterpret_cast(context->kernel_call_back_after_))); if (ret != RET_OK) { + input_op_datas_.erase(op_uuid); context->SetFailed(ret); - input_op_datas_.erase(context->sequential_num_); return; } + input_op_datas_.erase(op_uuid); SetOutputData(context); - input_op_datas_.erase(context->sequential_num_); } void Init() { auto ret = CompileArrow(); @@ -57,14 +60,14 @@ class LiteOpActor : public OpActor { } } int CompileArrow(); - int RunKernel() { + int RunKernel(const KernelCallBack &before, const KernelCallBack &after) { int ret; ret = kernel_->PreProcess(); if (RET_OK != ret) { MS_LOG(ERROR) << "PreProcess kernel failed, name: " << kernel_->name(); return ret; } - ret = kernel_->Run(); + ret = kernel_->Run(before, after); if (RET_OK != ret) { MS_LOG(ERROR) << "run kernel failed, name: " << kernel_->name(); return ret; diff --git a/mindspore/lite/src/mindrt_executor.cc b/mindspore/lite/src/mindrt_executor.cc index e4660f7a93..b2830e3ca5 100644 --- a/mindspore/lite/src/mindrt_executor.cc +++ b/mindspore/lite/src/mindrt_executor.cc @@ -75,7 +75,7 @@ int MindrtExecutor::Run(const std::vector &in_tensors, const std::vect } } - return MindrtRun(inputData_, &outputData_); + return MindrtRun(inputData_, &outputData_, &before, &after); } } // namespace mindspore::lite diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 0ff1decd2a..301b74e732 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -186,12 +186,22 @@ if(SUPPORT_GPU STREQUAL vulkan) endif() if(ENABLE_MINDRT) - set(TEST_LITE_SRC - ${TEST_LITE_SRC} - ${LITE_DIR}/src/lite_mindrt.cc - ${LITE_DIR}/src/mindrt_executor.cc - ) - include_directories(${TOP_DIR}/mindspore/core/mindrt/include) + include_directories(${CORE_DIR}/mindrt/) + include_directories(${CORE_DIR}/mindrt/src/) + set(TEST_LITE_SRC ${TEST_LITE_SRC} + ${LITE_DIR}/src/lite_mindrt.cc + ${LITE_DIR}/src/mindrt_executor.cc + ${CORE_DIR}/mindrt/src/litebus.cc + ${CORE_DIR}/mindrt/src/actor/actor.cc + ${CORE_DIR}/mindrt/src/actor/actormgr.cc + ${CORE_DIR}/mindrt/src/actor/actorpolicy.cc + ${CORE_DIR}/mindrt/src/actor/actorthread.cc + ${CORE_DIR}/mindrt/src/actor/aid.cc + ${CORE_DIR}/mindrt/src/async/async.cc + ${CORE_DIR}/mindrt/src/async/future.cc + ${CORE_DIR}/mindrt/src/async/uuid_base.cc + ${CORE_DIR}/mindrt/src/async/uuid_generator.cc + ) endif() @@ -353,10 +363,6 @@ add_dependencies(lite-test fbs_src) target_link_libraries(lite-test dl mindspore::gtest) -if(ENABLE_MINDRT) - target_link_libraries(lite-test mindrt_mid) -endif() - if(PLATFORM_ARM64 AND ENABLE_FP16) target_link_libraries(lite-test nnacl_fp16_mid nnacl_optimize_mid) endif() diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index b94e1aa8d4..db5d2b8df7 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -109,8 +109,22 @@ set(LITE_SRC set(ENABLE_MINDRT "off") if(ENABLE_MINDRT) - set(LITE_SRC ${LITE_SRC} ${SRC_DIR}/lite_mindrt.cc ${SRC_DIR}/mindrt_executor.cc) - include_directories(${CORE_DIR}/mindrt/include) + include_directories(${CORE_DIR}/mindrt/) + include_directories(${CORE_DIR}/mindrt/src/) + set(MINDRT_SRC + ${SRC_DIR}/lite_mindrt.cc + ${SRC_DIR}/mindrt_executor.cc + ${CORE_DIR}/mindrt/src/litebus.cc + ${CORE_DIR}/mindrt/src/actor/actor.cc + ${CORE_DIR}/mindrt/src/actor/actormgr.cc + ${CORE_DIR}/mindrt/src/actor/actorpolicy.cc + ${CORE_DIR}/mindrt/src/actor/actorthread.cc + ${CORE_DIR}/mindrt/src/actor/aid.cc + ${CORE_DIR}/mindrt/src/async/async.cc + ${CORE_DIR}/mindrt/src/async/future.cc + ${CORE_DIR}/mindrt/src/async/uuid_base.cc + ${CORE_DIR}/mindrt/src/async/uuid_generator.cc + ) endif() set(ARM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/kernel/arm) @@ -153,6 +167,7 @@ set_property(SOURCE ${CCSRC_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=minds set_property(SOURCE ${OPS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) set_property(SOURCE ${KERNEL_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) set_property(SOURCE ${LITE_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) +set_property(SOURCE ${MINDRT_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) add_executable(converter_lite main.cc ${CCSRC_SRC} @@ -160,14 +175,11 @@ add_executable(converter_lite ${OPS_SRC} ${KERNEL_SRC} ${LITE_SRC} + ${MINDRT_SRC} ) add_dependencies(converter_lite fbs_src) add_dependencies(converter_lite fbs_inner_src) -if(ENABLE_MINDRT) - target_link_libraries(converter_lite PRIVATE mindrt_mid) -endif() - target_link_libraries(converter_lite PRIVATE tflite_parser_mid tf_parser_mid