Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new-exec] lazy creating work queue (#43551) #43768

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions paddle/fluid/framework/new_executor/interpretercore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ InterpreterCore::InterpreterCore(const platform::Place& place,
stream_analyzer_(place) {
VLOG(4) << "InterpreterCore(): " << this << " on " << place_;
is_build_ = false;
async_work_queue_.reset(new interpreter::AsyncWorkQueue(
kHostNumThreads, kDeviceNumThreads, &main_thread_blocker_));

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if (IsInterpretercoreFastGCEnabled()) {
Expand Down Expand Up @@ -125,6 +123,17 @@ paddle::framework::FetchList InterpreterCore::Run(
// add listener before run and is_build=true
global_scope_->ResetListener();

// For the program that only run once, it is no need to
// create work_queue, so the async_work_queue_ is created
// until the second step run.
if (async_work_queue_ == nullptr) {
async_work_queue_ = std::make_unique<interpreter::AsyncWorkQueue>(
kHostNumThreads, kDeviceNumThreads, &main_thread_blocker_);
// prepare for the first time.
async_work_queue_->PrepareAtomicDeps(dependecy_count_);
async_work_queue_->PrepareAtomicVarRef(global_scope_->VecMetaInfo());
}

ExecuteInstructionList(vec_instruction_);
}

Expand Down Expand Up @@ -172,6 +181,17 @@ paddle::framework::FetchList InterpreterCore::Run(
// add listener before run and is_build=true
global_scope_->ResetListener();

// For the program that only run once, it is no need to
// create work_queue, so the async_work_queue_ is created
// until the second step run.
if (async_work_queue_ == nullptr) {
async_work_queue_ = std::make_unique<interpreter::AsyncWorkQueue>(
kHostNumThreads, kDeviceNumThreads, &main_thread_blocker_);
// prepare for the first time.
async_work_queue_->PrepareAtomicDeps(dependecy_count_);
async_work_queue_->PrepareAtomicVarRef(global_scope_->VecMetaInfo());
}

ExecuteInstructionList(vec_instruction_);
}

Expand Down Expand Up @@ -341,10 +361,6 @@ void InterpreterCore::Convert(
if (FLAGS_new_executor_use_inplace && !inplaced) {
BuildInplace();
}

// prepare for the first time.
async_work_queue_->PrepareAtomicDeps(dependecy_count_);
async_work_queue_->PrepareAtomicVarRef(vec_meta_info);
}

bool InterpreterCore::BuildInplaceCheckVarIsOnlyInput(size_t var_index) {
Expand Down Expand Up @@ -924,6 +940,18 @@ interpreter::CostInfo InterpreterCore::DryRun(
interpreter::CostInfo cost_info;
{
interpreter::ProfilerGuard(place_, &cost_info);

// For the program that only run once, it is no need to
// create work_queue, so the async_work_queue_ is created
// until the second step run.
if (async_work_queue_ == nullptr) {
async_work_queue_ = std::make_unique<interpreter::AsyncWorkQueue>(
kHostNumThreads, kDeviceNumThreads, &main_thread_blocker_);
// prepare for the first time.
async_work_queue_->PrepareAtomicDeps(dependecy_count_);
async_work_queue_->PrepareAtomicVarRef(global_scope_->VecMetaInfo());
}

ExecuteInstructionList(vec_instruction_);
platform::DeviceContextPool::Instance().Get(place_)->Wait();
}
Expand Down