Skip to content

Commit a0bd295

Browse files
add: max_executor_thread_num
1 parent e2a7464 commit a0bd295

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/libmodelbox/base/include/modelbox/base/executor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class Executor {
3333

3434
virtual ~Executor();
3535

36+
void SetThreadCount(int thread_count);
37+
3638
template <typename func, typename... ts>
3739
auto Run(func &&fun, int32_t priority, ts &&...params)
3840
-> std::future<typename std::result_of<func(ts...)>::type> {

src/libmodelbox/engine/flowunit_data_executor.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Executor::Executor(int thread_count) {
3434

3535
Executor::~Executor() { thread_pool_ = nullptr; }
3636

37+
void Executor::SetThreadCount(int thread_count){
38+
thread_pool_->SetThreadSize(thread_count);
39+
}
40+
3741
FlowUnitExecContext::FlowUnitExecContext(
3842
std::shared_ptr<FlowUnitDataContext> data_ctx)
3943
: data_ctx_(std::move(data_ctx)) {}

src/libmodelbox/engine/flowunit_manager.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ Status FlowUnitManager::Initialize(
5959
SetDeviceManager(std::move(device_mgr));
6060
Status status;
6161
status = InitFlowUnitFactory(driver);
62+
63+
if (config != nullptr){
64+
max_executor_thread_num = config->GetUint32("graph.max_executor_thread_num", 0);
65+
} else {
66+
max_executor_thread_num = 0;
67+
}
68+
6269
if (status != STATUS_SUCCESS) {
6370
return status;
6471
}
@@ -407,6 +414,9 @@ std::shared_ptr<FlowUnit> FlowUnitManager::CreateSingleFlowUnit(
407414
return nullptr;
408415
}
409416

417+
MBLOG_INFO << "max_executor_thread_num: " << max_executor_thread_num;
418+
device->GetDeviceExecutor()->SetThreadCount(max_executor_thread_num);
419+
410420
flowunit->SetBindDevice(device);
411421
std::vector<FlowUnitInput> &in_list = flowunit_desc->GetFlowUnitInput();
412422
for (auto &in_item : in_list) {

src/libmodelbox/include/modelbox/flowunit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ class FlowUnitManager {
612612

613613
std::shared_ptr<DeviceManager> GetDeviceManager();
614614

615+
int max_executor_thread_num;
616+
615617
private:
616618
Status CheckParams(const std::string &unit_name, const std::string &unit_type,
617619
const std::string &unit_device_id);

0 commit comments

Comments
 (0)