diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index 329a472ce0..2ac556bfcf 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -23,6 +23,9 @@ namespace mindspore::lite { int Executor::Run(const std::vector &in_tensors, const std::vector &out_tensors, const std::vector &kernels, mindspore::Allocator *allocator, 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); auto ret = CheckTensorsInvalid(in_tensors); if (RET_OK != ret) { @@ -66,6 +69,8 @@ int Executor::Run(const std::vector &in_tensors, const std::vectorthread_pool_, false, cpu_bind_mode); return RET_OK; } } // namespace mindspore::lite diff --git a/mindspore/lite/src/executor.h b/mindspore/lite/src/executor.h index 5ce626ed67..e4fb8f8525 100644 --- a/mindspore/lite/src/executor.h +++ b/mindspore/lite/src/executor.h @@ -28,11 +28,17 @@ class Executor { Executor() = default; virtual ~Executor() = default; - virtual int Prepare(const std::vector &kernels) { return RET_OK; } + virtual int Prepare(const std::vector &kernels) { + ctx_ = static_cast(kernels[0]->context()); + return RET_OK; + } virtual int Run(const std::vector &in_tensors, const std::vector &out_tensors, const std::vector &kernels, mindspore::Allocator *allocator = nullptr, const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); + + private: + const lite::InnerContext *ctx_ = nullptr; }; } // namespace mindspore::lite #endif diff --git a/mindspore/lite/src/lite_mindrt.h b/mindspore/lite/src/lite_mindrt.h index 5df38f7bff..422aaaeb95 100644 --- a/mindspore/lite/src/lite_mindrt.h +++ b/mindspore/lite/src/lite_mindrt.h @@ -42,10 +42,9 @@ class LiteOpActor : public OpActor { if (input_op_datas_[op_uuid].size() < kernel_->in_tensors().size()) { return; } - Context *ctx = const_cast(kernel_->context()); - if (kernel_->desc().arch == kernel::kCPU) { - BindThreads(static_cast(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(kernel_->context())->thread_pool_, true, cpu_bind_mode); + auto ret = RunKernel(*(reinterpret_cast(context->kernel_call_back_before_)), *(reinterpret_cast(context->kernel_call_back_after_))); if (ret != RET_OK) { @@ -55,9 +54,8 @@ class LiteOpActor : public OpActor { } input_op_datas_.erase(op_uuid); AsyncOutput(context); - if (kernel_->desc().arch == kernel::kCPU) { - BindThreads(static_cast(ctx)->thread_pool_, true, 2); - } + + BindThreads(static_cast(kernel_->context())->thread_pool_, false, cpu_bind_mode); SetOutputData(context); } void Init() { diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index ad979bcb08..c526d868a1 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -542,18 +542,9 @@ int LiteSession::Init(const Context *context) { } 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() {