|
|
|
@@ -20,8 +20,8 @@ |
|
|
|
#include <utility> |
|
|
|
#include <cmath> |
|
|
|
|
|
|
|
#include "common/thread_pool.h" |
|
|
|
#include "utils/profile.h" |
|
|
|
#include "runtime/framework/actor/actor_common.h" |
|
|
|
|
|
|
|
namespace mindspore { |
|
|
|
namespace kernel { |
|
|
|
@@ -167,17 +167,10 @@ ActorThreadPool *GetActorMgrInnerThreadPool() { |
|
|
|
auto thread_pool = actor_manager->GetActorThreadPool(); |
|
|
|
// Init thread_pool if env is windows or ascend, in case that it won't be init in graph_scheduler. |
|
|
|
if (thread_pool == nullptr) { |
|
|
|
const size_t kMaxThreadNum = 23; |
|
|
|
size_t max_thread_num = std::thread::hardware_concurrency() - 1; |
|
|
|
#if ENABLE_D || ENABLE_GPU |
|
|
|
const size_t kDeviceNum = 8; |
|
|
|
max_thread_num /= kDeviceNum; |
|
|
|
#endif |
|
|
|
if (max_thread_num < 1) { |
|
|
|
max_thread_num = 1; |
|
|
|
} |
|
|
|
max_thread_num = max_thread_num < kMaxThreadNum ? max_thread_num : kMaxThreadNum; |
|
|
|
(void)actor_manager->Initialize(true, 0, max_thread_num); |
|
|
|
size_t actor_thread_num = 0; |
|
|
|
size_t actor_and_kernel_thread_num = 0; |
|
|
|
runtime::ComputeThreadNums(&actor_thread_num, &actor_and_kernel_thread_num); |
|
|
|
(void)actor_manager->Initialize(true, actor_thread_num, actor_and_kernel_thread_num); |
|
|
|
thread_pool = actor_manager->GetActorThreadPool(); |
|
|
|
MS_EXCEPTION_IF_NULL(thread_pool); |
|
|
|
} |
|
|
|
@@ -207,6 +200,21 @@ void ParallelLaunch(const CTask &task, size_t count, float block_size, Content c |
|
|
|
(void)thread_pool->ParallelLaunch(func, content, task_num); |
|
|
|
} |
|
|
|
|
|
|
|
void ParallelLaunch(const std::vector<common::Task> &tasks, Content content) { |
|
|
|
auto thread_pool = GetActorMgrInnerThreadPool(); |
|
|
|
size_t kernel_thread_num = thread_pool->GetKernelThreadNum(); |
|
|
|
if (kernel_thread_num == 0) { |
|
|
|
MS_LOG(EXCEPTION) << "Actor inner pool has been init, but kernel thread is 0!"; |
|
|
|
} |
|
|
|
|
|
|
|
size_t task_num = tasks.size(); |
|
|
|
auto func = [&](void *, int task_id, float, float) { |
|
|
|
tasks[task_id](); |
|
|
|
return common::SUCCESS; |
|
|
|
}; |
|
|
|
(void)thread_pool->ParallelLaunch(func, content, task_num); |
|
|
|
} |
|
|
|
|
|
|
|
void ParallelLaunchAutoSearch(const CTask &task, size_t count, Content content, |
|
|
|
ParallelSearchInfo *parallel_search_info) { |
|
|
|
const size_t MAX_POW = 6; |
|
|
|
|