Browse Source

!15357 cpu use higher bind mode default

From: @ling_qiao_min
Reviewed-by: @zhang_xue_tong,@zhanghaibo5
Signed-off-by: @zhang_xue_tong
pull/15357/MERGE
mindspore-ci-bot Gitee 4 years ago
parent
commit
ec2371a05b
4 changed files with 20 additions and 20 deletions
  1. +5
    -0
      mindspore/lite/src/executor.cc
  2. +7
    -1
      mindspore/lite/src/executor.h
  3. +5
    -7
      mindspore/lite/src/lite_mindrt.h
  4. +3
    -12
      mindspore/lite/src/lite_session.cc

+ 5
- 0
mindspore/lite/src/executor.cc View File

@@ -23,6 +23,9 @@ namespace mindspore::lite {
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 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<Tensor *> &in_tensors, const std::vector<Ten
}
}
}

BindThreads(ctx_->thread_pool_, false, cpu_bind_mode);
return RET_OK;
}
} // namespace mindspore::lite

+ 7
- 1
mindspore/lite/src/executor.h View File

@@ -28,11 +28,17 @@ class Executor {
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,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr,
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr);

private:
const lite::InnerContext *ctx_ = nullptr;
};
} // namespace mindspore::lite
#endif

+ 5
- 7
mindspore/lite/src/lite_mindrt.h View File

@@ -42,10 +42,9 @@ class LiteOpActor : public OpActor<lite::Tensor> {
if (input_op_datas_[op_uuid].size() < kernel_->in_tensors().size()) {
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_)),
*(reinterpret_cast<const KernelCallBack *>(context->kernel_call_back_after_)));
if (ret != RET_OK) {
@@ -55,9 +54,8 @@ class LiteOpActor : public OpActor<lite::Tensor> {
}
input_op_datas_.erase(op_uuid);
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);
}
void Init() {


+ 3
- 12
mindspore/lite/src/lite_session.cc View File

@@ -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() {


Loading…
Cancel
Save