[MSLITE]mindrt support windows and convertor

pull/12561/head
ling 4 years ago
parent 79675d612e
commit 1a10422b64

@ -53,6 +53,8 @@ struct OpContext {
uuids::uuid *sequential_num_; uuids::uuid *sequential_num_;
std::vector<OpDataPtr<T>> *outputData_; std::vector<OpDataPtr<T>> *outputData_;
std::vector<Promise<int>> *results_; std::vector<Promise<int>> *results_;
const void *kernel_call_back_before_;
const void *kernel_call_back_after_;
void SetFailed(int32_t code) { void SetFailed(int32_t code) {
for (auto promise : *results_) { for (auto promise : *results_) {
promise.SetFailed(code); promise.SetFailed(code);
@ -89,13 +91,16 @@ Future<std::list<int>> MindrtAsyncRun(const std::vector<OpDataPtr<T>> &inputData
} }
template <typename T> 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; OpContext<T> context;
std::vector<Promise<int>> promises(outputData->size()); std::vector<Promise<int>> promises(outputData->size());
uuids::uuid uid; uuids::uuid uid;
context.sequential_num_ = &uid; context.sequential_num_ = &uid;
context.results_ = &promises; context.results_ = &promises;
context.outputData_ = outputData; 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); auto collect = MindrtAsyncRun<T>(inputData, &context);
collect.Wait(); collect.Wait();

@ -208,7 +208,10 @@ if(WIN32)
add_compile_definitions(LITE_EXPORTS) add_compile_definitions(LITE_EXPORTS)
add_compile_definitions(BUILDING_DLL) add_compile_definitions(BUILDING_DLL)
endif() endif()
add_subdirectory(${CORE_DIR}/mindrt mindspore_mindrt)
if(ENABLE_MINDRT)
include_directories(${CORE_DIR}/mindrt/include)
endif()
if(ENABLE_CONVERTER) if(ENABLE_CONVERTER)
if(PLATFORM_ARM) if(PLATFORM_ARM)
@ -222,10 +225,10 @@ if(ENABLE_CONVERTER)
endif() endif()
if(ENABLE_MINDRT) if(ENABLE_MINDRT)
include_directories(${CORE_DIR}/mindrt/include)
add_compile_definitions(ENABLE_MINDRT) add_compile_definitions(ENABLE_MINDRT)
endif() endif()
if(PLATFORM_ARM32 OR PLATFORM_ARM64) if(PLATFORM_ARM32 OR PLATFORM_ARM64)
if(NOT DEFINED ENV{ANDROID_NDK}) if(NOT DEFINED ENV{ANDROID_NDK})
message(FATAL_ERROR "env ANDROID_NDK should be set for ARM compile") message(FATAL_ERROR "env ANDROID_NDK should be set for ARM compile")

@ -116,11 +116,12 @@ if(SUPPORT_TRAIN)
endif() endif()
if(ENABLE_MINDRT) if(ENABLE_MINDRT)
add_subdirectory(${CORE_DIR}/mindrt mindspore_mindrt)
set(LITE_SRC set(LITE_SRC
${LITE_SRC} ${LITE_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc ${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc
${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc ${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc
) )
endif() endif()
add_subdirectory(ops) add_subdirectory(ops)

@ -25,6 +25,7 @@
#include "actor/actor.h" #include "actor/actor.h"
#include "async/uuid_base.h" #include "async/uuid_base.h"
#include "async/future.h" #include "async/future.h"
#include "src/sub_graph_kernel.h"
namespace mindspore { namespace mindspore {
namespace lite { namespace lite {
@ -36,18 +37,20 @@ class LiteOpActor : public OpActor<lite::Tensor> {
explicit LiteOpActor(kernel::LiteKernel *kernel) : OpActor<lite::Tensor>(kernel->name()), kernel_(kernel) {} explicit LiteOpActor(kernel::LiteKernel *kernel) : OpActor<lite::Tensor>(kernel->name()), kernel_(kernel) {}
virtual ~LiteOpActor() = default; virtual ~LiteOpActor() = default;
virtual void OpRun(OpDataPtr<Tensor> inputs, OpContext<Tensor> *context = nullptr) { virtual void OpRun(OpDataPtr<Tensor> inputs, OpContext<Tensor> *context = nullptr) {
input_op_datas_[context->sequential_num_].push_back(inputs); auto op_uuid = context->sequential_num_;
if (input_op_datas_[context->sequential_num_].size() < kernel_->in_tensors().size()) { input_op_datas_[op_uuid].push_back(inputs);
if (input_op_datas_[op_uuid].size() < kernel_->in_tensors().size()) {
return; 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) { if (ret != RET_OK) {
input_op_datas_.erase(op_uuid);
context->SetFailed(ret); context->SetFailed(ret);
input_op_datas_.erase(context->sequential_num_);
return; return;
} }
input_op_datas_.erase(op_uuid);
SetOutputData(context); SetOutputData(context);
input_op_datas_.erase(context->sequential_num_);
} }
void Init() { void Init() {
auto ret = CompileArrow(); auto ret = CompileArrow();
@ -57,14 +60,14 @@ class LiteOpActor : public OpActor<lite::Tensor> {
} }
} }
int CompileArrow(); int CompileArrow();
int RunKernel() { int RunKernel(const KernelCallBack &before, const KernelCallBack &after) {
int ret; int ret;
ret = kernel_->PreProcess(); ret = kernel_->PreProcess();
if (RET_OK != ret) { if (RET_OK != ret) {
MS_LOG(ERROR) << "PreProcess kernel failed, name: " << kernel_->name(); MS_LOG(ERROR) << "PreProcess kernel failed, name: " << kernel_->name();
return ret; return ret;
} }
ret = kernel_->Run(); ret = kernel_->Run(before, after);
if (RET_OK != ret) { if (RET_OK != ret) {
MS_LOG(ERROR) << "run kernel failed, name: " << kernel_->name(); MS_LOG(ERROR) << "run kernel failed, name: " << kernel_->name();
return ret; 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 } // namespace mindspore::lite

@ -186,12 +186,22 @@ if(SUPPORT_GPU STREQUAL vulkan)
endif() endif()
if(ENABLE_MINDRT) if(ENABLE_MINDRT)
set(TEST_LITE_SRC include_directories(${CORE_DIR}/mindrt/)
${TEST_LITE_SRC} include_directories(${CORE_DIR}/mindrt/src/)
${LITE_DIR}/src/lite_mindrt.cc set(TEST_LITE_SRC ${TEST_LITE_SRC}
${LITE_DIR}/src/mindrt_executor.cc ${LITE_DIR}/src/lite_mindrt.cc
) ${LITE_DIR}/src/mindrt_executor.cc
include_directories(${TOP_DIR}/mindspore/core/mindrt/include) ${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() endif()
@ -353,10 +363,6 @@ add_dependencies(lite-test fbs_src)
target_link_libraries(lite-test dl mindspore::gtest) 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) if(PLATFORM_ARM64 AND ENABLE_FP16)
target_link_libraries(lite-test nnacl_fp16_mid nnacl_optimize_mid) target_link_libraries(lite-test nnacl_fp16_mid nnacl_optimize_mid)
endif() endif()

@ -109,8 +109,22 @@ set(LITE_SRC
set(ENABLE_MINDRT "off") set(ENABLE_MINDRT "off")
if(ENABLE_MINDRT) if(ENABLE_MINDRT)
set(LITE_SRC ${LITE_SRC} ${SRC_DIR}/lite_mindrt.cc ${SRC_DIR}/mindrt_executor.cc) include_directories(${CORE_DIR}/mindrt/)
include_directories(${CORE_DIR}/mindrt/include) 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() endif()
set(ARM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/kernel/arm) 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 ${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 ${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 ${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 add_executable(converter_lite
main.cc main.cc
${CCSRC_SRC} ${CCSRC_SRC}
@ -160,14 +175,11 @@ add_executable(converter_lite
${OPS_SRC} ${OPS_SRC}
${KERNEL_SRC} ${KERNEL_SRC}
${LITE_SRC} ${LITE_SRC}
${MINDRT_SRC}
) )
add_dependencies(converter_lite fbs_src) add_dependencies(converter_lite fbs_src)
add_dependencies(converter_lite fbs_inner_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 target_link_libraries(converter_lite PRIVATE
tflite_parser_mid tflite_parser_mid
tf_parser_mid tf_parser_mid

Loading…
Cancel
Save