Skip to content

Commit d975313

Browse files
sraikund16facebook-github-bot
authored andcommitted
Add API for Dynamic Activity Toggling [1/n] (#972)
Summary: Pull Request resolved: #972 During PT2 there are many GPU/CPU events that are unneccessary to profile in between a given step. To remedy this, we can add an API that takes in a list of activities and an arg to toggle said activies or not. For this diff we are just adding the Kineto side to turn on/off the "CUDA" events which includes AMD/Roctracer. A follow up will be added for the generic profiler side. Subsequent diffs will be added for CPU toggling and e2e testing. Differential Revision: D60542040 fbshipit-source-id: 2608ec912812c9004cb87371bd8fca8145a95621
1 parent 0cded49 commit d975313

7 files changed

+36
-0
lines changed

libkineto/include/ActivityProfilerInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class ActivityProfilerInterface {
5555
const std::set<ActivityType>& activityTypes,
5656
const std::string& configStr = "") {}
5757

58+
// Toggle GPU tracing as a trace is running to omit certain parts of a graph
59+
virtual void toggleCollectionDynamic(
60+
const bool enable) {}
61+
5862
// Start recording, potentially reusing any buffers allocated since
5963
// prepareTrace was called.
6064
virtual void startTrace() {}

libkineto/src/ActivityProfilerController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ void ActivityProfilerController::prepareTrace(const Config& config) {
315315
profiler_->configure(config, now);
316316
}
317317

318+
void ActivityProfilerController::toggleCollectionDynamic(const bool enable) {
319+
profiler_->toggleCollectionDynamic(enable);
320+
}
321+
318322
void ActivityProfilerController::startTrace() {
319323
UST_LOGGER_MARK_COMPLETED(kWarmUpStage);
320324
profiler_->startTrace(std::chrono::system_clock::now());

libkineto/src/ActivityProfilerController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ActivityProfilerController : public ConfigLoader::ConfigHandler {
5858

5959
// These API are used for Synchronous Tracing.
6060
void prepareTrace(const Config& config);
61+
void toggleCollectionDynamic(const bool enable);
6162
void startTrace();
6263
void step();
6364
std::unique_ptr<ActivityTraceInterface> stopTrace();

libkineto/src/ActivityProfilerProxy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ void ActivityProfilerProxy::prepareTrace(
7070
controller_->prepareTrace(config);
7171
}
7272

73+
void ActivityProfilerProxy::toggleCollectionDynamic(const bool enable){
74+
controller_->toggleCollectionDynamic(enable);
75+
}
76+
7377
void ActivityProfilerProxy::startTrace() {
7478
controller_->startTrace();
7579
}

libkineto/src/ActivityProfilerProxy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class ActivityProfilerProxy : public ActivityProfilerInterface {
5252
const std::set<ActivityType>& activityTypes,
5353
const std::string& configStr = "") override;
5454

55+
void toggleCollectionDynamic(
56+
const bool enable) override;
57+
5558
void startTrace() override;
5659
void step() override;
5760
std::unique_ptr<ActivityTraceInterface> stopTrace() override;

libkineto/src/CuptiActivityProfiler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,23 @@ void CuptiActivityProfiler::configure(
10731073
currentRunloopState_ = RunloopState::Warmup;
10741074
}
10751075

1076+
void CuptiActivityProfiler::toggleCollectionDynamic(const bool enable){
1077+
#ifdef HAS_CUPTI
1078+
if (enable) {
1079+
cupti_.enableCuptiActivities(derivedConfig_->profileActivityTypes());
1080+
} else {
1081+
cupti_.disableCuptiActivities(derivedConfig_->profileActivityTypes());
1082+
}
1083+
#endif
1084+
#ifdef HAS_ROCTRACER
1085+
if (enable) {
1086+
cupti_.enableActivities(derivedConfig_->profileActivityTypes());
1087+
} else {
1088+
cupti_.disableActivities(derivedConfig_->profileActivityTypes());
1089+
}
1090+
#endif
1091+
}
1092+
10761093
void CuptiActivityProfiler::startTraceInternal(
10771094
const time_point<system_clock>& now) {
10781095
captureWindowStartTime_ = libkineto::timeSinceEpoch(now);

libkineto/src/CuptiActivityProfiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ class CuptiActivityProfiler {
179179
void configure(
180180
const Config& config,
181181
const std::chrono::time_point<std::chrono::system_clock>& now);
182+
183+
// Toggle GPU tracing during a profile instance
184+
void toggleCollectionDynamic(const bool enable);
182185

183186
// Registered with client API to pass CPU trace events over
184187
void transferCpuTrace(

0 commit comments

Comments
 (0)