| @@ -53,6 +53,8 @@ struct OpContext { | |||
| uuids::uuid *sequential_num_; | |||
| std::vector<OpDataPtr<T>> *outputData_; | |||
| std::vector<Promise<int>> *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<std::list<int>> MindrtAsyncRun(const std::vector<OpDataPtr<T>> &inputData | |||
| } | |||
| template <typename T> | |||
| int MindrtRun(const std::vector<OpDataPtr<T>> &inputData, std::vector<OpDataPtr<T>> *outputData) { | |||
| int MindrtRun(const std::vector<OpDataPtr<T>> &inputData, std::vector<OpDataPtr<T>> *outputData, | |||
| const void *kernel_call_back_before, const void *kernel_call_back_after) { | |||
| OpContext<T> context; | |||
| std::vector<Promise<int>> 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<T>(inputData, &context); | |||
| collect.Wait(); | |||
| @@ -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") | |||
| @@ -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) | |||
| @@ -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<lite::Tensor> { | |||
| explicit LiteOpActor(kernel::LiteKernel *kernel) : OpActor<lite::Tensor>(kernel->name()), kernel_(kernel) {} | |||
| virtual ~LiteOpActor() = default; | |||
| virtual void OpRun(OpDataPtr<Tensor> inputs, OpContext<Tensor> *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<const KernelCallBack *>(context->kernel_call_back_before_)), | |||
| *(reinterpret_cast<const KernelCallBack *>(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<lite::Tensor> { | |||
| } | |||
| } | |||
| 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; | |||
| @@ -75,7 +75,7 @@ int MindrtExecutor::Run(const std::vector<Tensor *> &in_tensors, const std::vect | |||
| } | |||
| } | |||
| return MindrtRun<Tensor>(inputData_, &outputData_); | |||
| return MindrtRun<Tensor>(inputData_, &outputData_, &before, &after); | |||
| } | |||
| } // namespace mindspore::lite | |||
| @@ -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() | |||
| @@ -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 | |||