Skip to content

Commit

Permalink
cherry-pick from (PaddlePaddle#58338)
Browse files Browse the repository at this point in the history
Fix nccl trace

* fix nccl_async_trace destruct problem when train finished

* update

* format code style
  • Loading branch information
wentaoyu committed Nov 14, 2023
1 parent 3d44f57 commit cfefaa1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions paddle/fluid/distributed/collective/process_group_nccl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ ProcessGroupNCCL::ProcessGroupNCCL(
pg_timeout_(timeout) {
LOG(INFO) << "ProcessGroupNCCL pg_timeout_ " << pg_timeout_;
}
ProcessGroupNCCL::~ProcessGroupNCCL() {
LOG(INFO) << "ProcessGroupNCCL destruct ";
auto& comm_task_manager = phi::distributed::CommTaskManager::GetInstance();
comm_task_manager.Stop();
}

void ProcessGroupNCCL::GroupStart() {
NCCL_CHECK(phi::dynload::ncclGroupStart());
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/distributed/collective/process_group_nccl.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class ProcessGroupNCCL final : public ProcessGroupWithStream {
int rank,
int size,
int gid,
int64_t timeout = 30 * 60 * 1000);
int64_t timeout = 20 * 1000);
~ProcessGroupNCCL();

std::string GetBackendName() const override { return "NCCL"; }

Expand Down
19 changes: 18 additions & 1 deletion paddle/phi/core/distributed/comm_task_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ void CommTaskManager::CommTaskEnqueue(std::shared_ptr<CommTask> comm_task) {
}
}

void CommTaskManager::Stop() {
terminated_.store(true);

LOG(INFO) << "CommTaskManager stopped begin.";
if (comm_task_loop_thread_.joinable()) {
comm_task_loop_thread_.join();
comm_task_list_cv_.notify_one();
}
LOG(INFO) << "CommTaskManager stopped.";
}

void CommTaskManager::CommTaskLoop() {
bool done = false;
while (!terminated_.load() || !done) {
Expand All @@ -100,7 +111,11 @@ void CommTaskManager::CommTaskLoop() {
}
iter = comm_task_list_.erase(iter);
} else {
++iter;
if (task->IsStarted() && task->IsCompleted()) {
iter = comm_task_list_.erase(iter);
} else {
++iter;
}
}
}

Expand Down Expand Up @@ -131,6 +146,8 @@ void CommTaskManager::CommTaskLoop() {
if (comm_task_list_.empty() && init_comm_task_map_.empty() &&
start_comm_task_map_.empty()) {
done = true;
} else {
done = false;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/core/distributed/comm_task_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CommTaskManager {
}

void CommTaskEnqueue(std::shared_ptr<CommTask> comm_task);
void Stop();

private:
void CommTaskLoop();
Expand Down

0 comments on commit cfefaa1

Please sign in to comment.