From: @ling_qiao_min Reviewed-by: @zhang_xue_tong,@zhanghaibo5 Signed-off-by: @zhang_xue_tongpull/15357/MERGE
| @@ -23,6 +23,9 @@ namespace mindspore::lite { | |||||
| int Executor::Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors, | int Executor::Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors, | ||||
| const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator, | const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator, | ||||
| const KernelCallBack &before, const KernelCallBack &after) { | const KernelCallBack &before, const KernelCallBack &after) { | ||||
| CpuBindMode cpu_bind_mode = ctx_->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_; | |||||
| BindThreads(ctx_->thread_pool_, true, cpu_bind_mode); | |||||
| MS_ASSERT(nullptr != allocator); | MS_ASSERT(nullptr != allocator); | ||||
| auto ret = CheckTensorsInvalid(in_tensors); | auto ret = CheckTensorsInvalid(in_tensors); | ||||
| if (RET_OK != ret) { | if (RET_OK != ret) { | ||||
| @@ -66,6 +69,8 @@ int Executor::Run(const std::vector<Tensor *> &in_tensors, const std::vector<Ten | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| BindThreads(ctx_->thread_pool_, false, cpu_bind_mode); | |||||
| return RET_OK; | return RET_OK; | ||||
| } | } | ||||
| } // namespace mindspore::lite | } // namespace mindspore::lite | ||||
| @@ -28,11 +28,17 @@ class Executor { | |||||
| Executor() = default; | Executor() = default; | ||||
| virtual ~Executor() = default; | virtual ~Executor() = default; | ||||
| virtual int Prepare(const std::vector<kernel::LiteKernel *> &kernels) { return RET_OK; } | |||||
| virtual int Prepare(const std::vector<kernel::LiteKernel *> &kernels) { | |||||
| ctx_ = static_cast<const lite::InnerContext *>(kernels[0]->context()); | |||||
| return RET_OK; | |||||
| } | |||||
| virtual int Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors, | virtual int Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors, | ||||
| const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr, | const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr, | ||||
| const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); | const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); | ||||
| private: | |||||
| const lite::InnerContext *ctx_ = nullptr; | |||||
| }; | }; | ||||
| } // namespace mindspore::lite | } // namespace mindspore::lite | ||||
| #endif | #endif | ||||
| @@ -42,10 +42,9 @@ class LiteOpActor : public OpActor<lite::Tensor> { | |||||
| if (input_op_datas_[op_uuid].size() < kernel_->in_tensors().size()) { | if (input_op_datas_[op_uuid].size() < kernel_->in_tensors().size()) { | ||||
| return; | return; | ||||
| } | } | ||||
| Context *ctx = const_cast<Context *>(kernel_->context()); | |||||
| if (kernel_->desc().arch == kernel::kCPU) { | |||||
| BindThreads(static_cast<lite::InnerContext *>(ctx)->thread_pool_, true, 2); | |||||
| } | |||||
| CpuBindMode cpu_bind_mode = kernel_->context()->device_list_.front().device_info_.cpu_device_info_.cpu_bind_mode_; | |||||
| BindThreads(static_cast<const lite::InnerContext *>(kernel_->context())->thread_pool_, true, cpu_bind_mode); | |||||
| auto ret = RunKernel(*(reinterpret_cast<const KernelCallBack *>(context->kernel_call_back_before_)), | auto ret = RunKernel(*(reinterpret_cast<const KernelCallBack *>(context->kernel_call_back_before_)), | ||||
| *(reinterpret_cast<const KernelCallBack *>(context->kernel_call_back_after_))); | *(reinterpret_cast<const KernelCallBack *>(context->kernel_call_back_after_))); | ||||
| if (ret != RET_OK) { | if (ret != RET_OK) { | ||||
| @@ -55,9 +54,8 @@ class LiteOpActor : public OpActor<lite::Tensor> { | |||||
| } | } | ||||
| input_op_datas_.erase(op_uuid); | input_op_datas_.erase(op_uuid); | ||||
| AsyncOutput(context); | AsyncOutput(context); | ||||
| if (kernel_->desc().arch == kernel::kCPU) { | |||||
| BindThreads(static_cast<lite::InnerContext *>(ctx)->thread_pool_, true, 2); | |||||
| } | |||||
| BindThreads(static_cast<const lite::InnerContext *>(kernel_->context())->thread_pool_, false, cpu_bind_mode); | |||||
| SetOutputData(context); | SetOutputData(context); | ||||
| } | } | ||||
| void Init() { | void Init() { | ||||
| @@ -542,18 +542,9 @@ int LiteSession::Init(const Context *context) { | |||||
| } | } | ||||
| void LiteSession::BindThread(bool if_bind) { | void LiteSession::BindThread(bool if_bind) { | ||||
| if (this->context_->device_list_.empty()) { | |||||
| MS_LOG(ERROR) << "Device list is empty."; | |||||
| return; | |||||
| } | |||||
| if (!this->context_->IsCpuEnabled()) { | |||||
| return; | |||||
| } | |||||
| auto cpu_device_info = this->context_->GetCpuInfo(); | |||||
| if (cpu_device_info.cpu_bind_mode_ != NO_BIND) { | |||||
| MS_ASSERT(this->context_->thread_pool_ != NULL); | |||||
| BindThreads(this->context_->thread_pool_, if_bind, cpu_device_info.cpu_bind_mode_); | |||||
| } | |||||
| // Abandoned code | |||||
| // Bind thread in executor | |||||
| return; | |||||
| } | } | ||||
| LiteSession::~LiteSession() { | LiteSession::~LiteSession() { | ||||