!28339 modify kernel thread spin count

Merge pull request !28339 from 范吉斌/spin
This commit is contained in:
i-robot 2021-12-31 07:09:53 +00:00 committed by Gitee
commit 4be4deb602
3 changed files with 14 additions and 2 deletions

View File

@ -25,6 +25,7 @@
namespace mindspore {
namespace kernel {
constexpr size_t kDefaultKernelSpinCount = 3000;
void CpuDynamicKernel::UpdateArgs() {
if (!is_input_dynamic_shape_ && is_output_dynamic_shape_ && !have_depends()) {
@ -74,8 +75,9 @@ void CPUKernel::Init(const CNodePtr &kernel_node) {
void CPUKernelUtils::ExpandDimsTo4(std::vector<size_t> *shape) {
MS_EXCEPTION_IF_NULL(shape);
auto len = shape->size();
if (len < 4) {
for (size_t i = 0; i < 4 - len; ++i) {
const size_t expect_dims = 4;
if (len < expect_dims) {
for (size_t i = 0; i < expect_dims - len; ++i) {
(void)shape->insert(shape->begin(), 1);
}
}
@ -174,6 +176,7 @@ ActorThreadPool *GetActorMgrInnerThreadPool() {
thread_pool = actor_manager->GetActorThreadPool();
MS_EXCEPTION_IF_NULL(thread_pool);
}
thread_pool->SetKernelThreadMaxSpinCount(kDefaultKernelSpinCount);
return thread_pool;
}

View File

@ -344,6 +344,14 @@ int ThreadPool::SetProcessAffinity(BindMode bind_mode) const {
return THREAD_OK;
}
void ThreadPool::SetKernelThreadMaxSpinCount(int spin_count) {
size_t num = workers_.size() - 1;
for (size_t i = num; i >= actor_thread_num_; i--) {
THREAD_RETURN_IF_NULL(workers_[i]);
workers_[i]->SetMaxSpinCount(spin_count);
}
}
void ThreadPool::SetSpinCountMaxValue() {
for (auto worker : workers_) {
THREAD_RETURN_IF_NULL(worker);

View File

@ -132,6 +132,7 @@ class ThreadPool {
void SetActorThreadNum(size_t actor_thread_num) { actor_thread_num_ = actor_thread_num; }
void SetKernelThreadNum(size_t kernel_thread_num) { kernel_thread_num_ = kernel_thread_num; }
size_t GetKernelThreadNum() const { return kernel_thread_num_; }
void SetKernelThreadMaxSpinCount(int spin_count);
void SetSpinCountMaxValue();
void SetSpinCountMinValue();
void SetMaxSpinCount(int spin_count);