Skip to content

Commit

Permalink
add function ensureCollectTraceDone to wait and cleanup collectTraceT…
Browse files Browse the repository at this point in the history
…hread
  • Loading branch information
staugust committed Aug 6, 2024
1 parent 0f27758 commit 1732581
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions libkineto/src/CuptiActivityProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,13 @@ void CuptiActivityProfiler::collectTrace(bool collection_done,
UST_LOGGER_MARK_COMPLETED(kCollectionStage);
}

void CuptiActivityProfiler::ensureCollectTraceDone() {
if (collectTraceThread && collectTraceThread->joinable()) {
std::lock_guard<std::mutex> guard(mutex_);
collectTraceThread->join();
collectTraceThread.reset(nullptr);
}
}
void CuptiActivityProfiler::startTraceInternal(
const time_point<system_clock>& now) {
captureWindowStartTime_ = libkineto::timeSinceEpoch(now);
Expand Down Expand Up @@ -1251,11 +1258,7 @@ const time_point<system_clock> CuptiActivityProfiler::performRunLoopStep(
}

// Before processing, we should wait for collectTrace thread to be done.
if (collectTraceThread && collectTraceThread->joinable()) {
std::lock_guard<std::mutex> guard(mutex_);
collectTraceThread->join();
collectTraceThread.reset(nullptr);
}
ensureCollectTraceDone();

// FIXME: Probably want to allow interruption here
// for quickly handling trace request via synchronous API
Expand Down
2 changes: 2 additions & 0 deletions libkineto/src/CuptiActivityProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class CuptiActivityProfiler {
// Collect CPU and GPU traces
void collectTrace(bool collectionDone, const std::chrono::time_point<std::chrono::system_clock>& now );

// Ensure collectTrace is done
void ensureCollectTraceDone();
// Process CPU and GPU traces
void processTrace(ActivityLogger& logger) {
std::lock_guard<std::mutex> guard(mutex_);
Expand Down

0 comments on commit 1732581

Please sign in to comment.