Skip to content

Commit 9c446b4

Browse files
authored
[PROTON] Show metadata and graph scopes in the trace (#9930)
We differentiate CPU and GPU events using three different trace lines per process, including: 1. CPU scopes 2. GPU Graph scopes 3. GPU events ## CPU scopes Timestamps are recorded when a scope is entered and exited. Metrics are shown in the CPU scope names. ## GPU graph scopes Timestamps are aligned with the underlying GPU events. Metrics are shown in the GPU scope names. ## GPU events ### Non-graph GPU kernels Each GPU event has a dependency on the CPU scope where it was launched. ### Graph-based GPU kernels Only the first kernel of each graph has a dependency on the CPU scope where it was launched. We show all kernels launched by either proton or the application in the traces, including metadata kernels (e.g., data type conversion), metric recording kernels, and application kernels.
1 parent ce92c3f commit 9c446b4

9 files changed

Lines changed: 1203 additions & 360 deletions

File tree

third_party/proton/csrc/include/Data/Metric.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ class KernelMetric : public Metric {
194194
DeviceId,
195195
DeviceType,
196196
StreamId,
197+
IsMetricKernel,
197198
Count,
198199
};
199200

200201
KernelMetric() : Metric(MetricKind::Kernel, kernelMetricKind::Count) {}
201202

202203
KernelMetric(uint64_t startTime, uint64_t endTime, uint64_t invocations,
203-
uint64_t deviceId, uint64_t deviceType, uint64_t streamId)
204+
uint64_t deviceId, uint64_t deviceType, uint64_t streamId,
205+
uint64_t isMetricKernel = 0)
204206
: KernelMetric() {
205207
this->values[StartTime] = startTime;
206208
this->values[EndTime] = endTime;
@@ -209,6 +211,7 @@ class KernelMetric : public Metric {
209211
this->values[DeviceId] = deviceId;
210212
this->values[DeviceType] = deviceType;
211213
this->values[StreamId] = streamId;
214+
this->values[IsMetricKernel] = isMetricKernel;
212215
}
213216

214217
const std::string &getName() const override { return name; }
@@ -223,12 +226,12 @@ class KernelMetric : public Metric {
223226

224227
private:
225228
const static inline bool PROPERTY[kernelMetricKind::Count] = {
226-
true, true, false, false, true, true, true};
229+
true, true, false, false, true, true, true, true};
227230
const static inline bool EXCLUSIVE[kernelMetricKind::Count] = {
228-
false, false, false, false, true, true, true};
231+
false, false, false, false, true, true, true, true};
229232
const static inline std::string VALUE_NAMES[kernelMetricKind::Count] = {
230233
"start_time (ns)", "end_time (ns)", "count", "time (ns)",
231-
"device_id", "device_type", "stream_id",
234+
"device_id", "device_type", "stream_id", "is_metric_kernel",
232235
};
233236
const static inline std::string name = "KernelMetric";
234237
};

third_party/proton/csrc/include/Data/TraceData.h

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

44
#include "Data.h"
55
#include <memory>
6+
#include <thread>
67
#include <unordered_map>
78

89
namespace proton {
@@ -41,10 +42,14 @@ class TraceData : public Data {
4142
}
4243

4344
void dumpChromeTrace(std::ostream &os, size_t phase) const;
45+
size_t getCurrentThreadTraceId();
4446

4547
PhaseStore<Trace> tracePhases;
4648
// ScopeId -> EventId
4749
std::unordered_map<size_t, size_t> scopeIdToEventId;
50+
// ThreadId -> TraceId
51+
std::unordered_map<std::thread::id, uint64_t> threadIdToTraceId;
52+
uint64_t nextThreadTraceId = 0;
4853
};
4954

5055
} // namespace proton

third_party/proton/csrc/include/Profiler/Graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ struct NodeStatus {
4545
struct GraphState {
4646
// Capture tag to identify captured call paths
4747
static constexpr const char *captureTag = "<captured_at>";
48+
static constexpr const char *metricTag = "<metric>";
49+
static constexpr const char *metadataTag = "__proton_launch_metadata";
4850
struct NodeState {
4951
// The graph node id for this node
5052
uint64_t nodeId{};

0 commit comments

Comments
 (0)