Skip to content

Commit 3cf5ebf

Browse files
chaekitfacebook-github-bot
authored andcommitted
deprecate pthreadid (#56209)
Summary: Pull Request resolved: pytorch/pytorch#56209 Pull Request resolved: #172 in this diff of the stack, we remove the threadId field from the ClientTraceActivity as our step towards the deprecation Reviewed By: ilia-cher Differential Revision: D27662747 fbshipit-source-id: 040ba040390680a0fc63ddc8149c6fad940439fc
1 parent b0872a0 commit 3cf5ebf

File tree

8 files changed

+29
-13
lines changed

8 files changed

+29
-13
lines changed

libkineto/include/ActivityProfilerInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <memory>
1111
#include <set>
12+
#include <thread>
1213
#include <vector>
1314

1415
#include "ActivityType.h"
@@ -76,6 +77,10 @@ class ActivityProfilerInterface {
7677
virtual bool enableForRegion(const std::string& match) {
7778
return true;
7879
}
80+
81+
// Maps kernel thread id -> pthread id for CPU ops.
82+
// Client must record any new kernel thread where the activity has occured.
83+
virtual void recordThreadInfo(pid_t tid, pthread_t pthreadId) {}
7984
};
8085

8186
} // namespace libkineto

libkineto/include/ClientTraceActivity.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct ClientTraceActivity : TraceActivity {
7373
int64_t correlation{0};
7474
int device{-1};
7575
// TODO: Add OS abstraction
76-
pthread_t pthreadId{};
7776
int32_t sysThreadId{0};
7877
std::string opType;
7978

libkineto/src/ActivityProfiler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ void ActivityProfiler::processCpuTrace(
183183
CpuGpuSpanPair& span_pair = recordTraceSpan(cpuTrace.span, cpuTrace.gpuOpCount);
184184
TraceSpan& cpu_span = span_pair.first;
185185
for (auto const& act : cpuTrace.activities) {
186-
VLOG(2) << act.correlationId() << ": OP " << act.opType
187-
<< " tid: " << act.pthreadId;
186+
VLOG(2) << act.correlationId() << ": OP " << act.opType;
188187
if (logTrace) {
189188
logger.handleCpuActivity(act, cpu_span);
190-
recordThreadInfo(act.sysThreadId, act.pthreadId);
191189
}
192190
// Stash event so we can look it up later when processing GPU trace
193191
externalEvents_.insertEvent(&act);

libkineto/src/ActivityProfiler.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ class ActivityProfiler {
102102
return *config_;
103103
}
104104

105+
inline void recordThreadInfo(pid_t tid, pthread_t pthreadId) {
106+
std::lock_guard<std::mutex> guard(mutex_);
107+
if (threadInfo_.find((int32_t)pthreadId) == threadInfo_.end()) {
108+
threadInfo_.emplace(
109+
(int32_t)pthreadId,
110+
ThreadInfo((int32_t) tid, getThreadName(tid)));
111+
}
112+
}
113+
105114
private:
106115
class ExternalEventMap {
107116
public:
@@ -256,14 +265,6 @@ class ActivityProfiler {
256265
disabledTraceSpans_.end();
257266
}
258267

259-
inline void recordThreadInfo(pid_t tid, pthread_t pthreadId) {
260-
if (threadInfo_.find((int32_t)pthreadId) == threadInfo_.end()) {
261-
threadInfo_.emplace(
262-
(int32_t)pthreadId,
263-
ThreadInfo((int32_t) tid, getThreadName(tid)));
264-
}
265-
}
266-
267268
void resetTraceData();
268269

269270
void addOverheadSample(profilerOverhead& counter, int64_t overhead) {

libkineto/src/ActivityProfilerController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class ActivityProfilerController {
5757
return profiler_->transferCpuTrace(std::move(cpuTrace));
5858
}
5959

60+
void recordThreadInfo(pid_t tid, pthread_t pthreadId) {
61+
profiler_->recordThreadInfo(tid, pthreadId);
62+
}
63+
6064
private:
6165
void profilerLoop();
6266

libkineto/src/ActivityProfilerProxy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,8 @@ bool ActivityProfilerProxy::enableForRegion(const std::string& match) {
8484
return controller_->traceInclusionFilter(match);
8585
}
8686

87+
void ActivityProfilerProxy::recordThreadInfo(pid_t tid, pthread_t pthreadId) {
88+
controller_->recordThreadInfo(tid, pthreadId);
89+
}
90+
8791
} // namespace libkineto

libkineto/src/ActivityProfilerProxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class ActivityProfilerProxy : public ActivityProfilerInterface {
4040

4141
bool isActive() override;
4242

43+
void recordThreadInfo(pid_t tid, pthread_t pthreadId) override;
44+
4345
void scheduleTrace(const std::string& configStr) override;
4446
void scheduleTrace(const Config& config);
4547

libkineto/test/ActivityProfilerTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct MockCpuActivityBuffer : public CpuTraceBuffer {
4545
op.startTime = startTime;
4646
op.endTime = endTime;
4747
op.device = 0;
48-
op.pthreadId = pthread_self();
4948
op.sysThreadId = 123;
5049
op.correlation = correlation;
5150
activities.push_back(std::move(op));
@@ -253,6 +252,8 @@ TEST_F(ActivityProfilerTest, SyncTrace) {
253252
profiler.startTrace(start_time);
254253
profiler.stopTrace(start_time + microseconds(duration_us));
255254

255+
profiler.recordThreadInfo(123, pthread_self());
256+
256257
// Log some cpu ops
257258
auto cpuOps = std::make_unique<MockCpuActivityBuffer>(
258259
start_time_us, start_time_us + duration_us);
@@ -338,6 +339,8 @@ TEST_F(ActivityProfilerTest, CorrelatedTimestampTest) {
338339
// When launching kernel, the CPU event should always precede the GPU event.
339340
int64_t kernelLaunchTime = 120;
340341

342+
profiler.recordThreadInfo(123, pthread_self());
343+
341344
// set up CPU event
342345
auto cpuOps = std::make_unique<MockCpuActivityBuffer>(
343346
start_time_us, start_time_us + duration_us);

0 commit comments

Comments
 (0)