Skip to content

Commit cc27452

Browse files
committed
Update to v2.0.0
1 parent 2dde7d3 commit cc27452

42 files changed

Lines changed: 1057 additions & 351 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libkineto/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set(KINETO_LIBRARY_TYPE "default" CACHE STRING
3030
set_property(CACHE KINETO_LIBRARY_TYPE PROPERTY STRINGS default shared)
3131
option(KINETO_BUILD_TESTS "Build kineto unit tests" ON)
3232

33+
set(LIBKINETO_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
3334
set(LIBKINETO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
3435
set(LIBKINETO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
3536
set(LIBKINETO_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
@@ -181,8 +182,10 @@ elseif(KINETO_LIBRARY_TYPE STREQUAL "static")
181182
$<TARGET_OBJECTS:kineto_api>)
182183
elseif(KINETO_LIBRARY_TYPE STREQUAL "shared")
183184
add_library(kineto SHARED
184-
$<TARGET_OBJECTS:kineto_base>)
185+
$<TARGET_OBJECTS:kineto_base>
186+
$<TARGET_OBJECTS:kineto_api>)
185187
set_property(TARGET kineto_base PROPERTY POSITION_INDEPENDENT_CODE ON)
188+
set_property(TARGET kineto_api PROPERTY POSITION_INDEPENDENT_CODE ON)
186189
set_target_properties(kineto PROPERTIES
187190
CXX_VISIBILITY_PRESET hidden)
188191
else()
@@ -217,4 +220,5 @@ install(EXPORT kinetoLibraryConfig DESTINATION share/cmake/kineto
217220

218221
if(KINETO_BUILD_TESTS)
219222
add_subdirectory(test)
223+
add_subdirectory("${LIBKINETO_THIRDPARTY_DIR}/googletest")
220224
endif()

libkineto/include/ActivityProfilerInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class ActivityProfilerInterface {
5959
const std::set<ActivityType>& activityTypes,
6060
const std::string& configStr = "") {}
6161

62+
// Toggle GPU tracing as a trace is running to omit certain parts of a graph
63+
virtual void toggleCollectionDynamic(const bool enable) {}
64+
6265
// Start recording, potentially reusing any buffers allocated since
6366
// prepareTrace was called.
6467
virtual void startTrace() {}

libkineto/include/ActivityType.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <array>
1212
#include <string>
13+
#include <set>
1314

1415
namespace libkineto {
1516

@@ -24,23 +25,30 @@ enum class ActivityType {
2425
GPU_MEMSET,
2526
CONCURRENT_KERNEL, // on-device kernels
2627
EXTERNAL_CORRELATION,
27-
MUSA_RUNTIME, // host side musa runtime events
28-
MUSA_DRIVER, // host side musa driver events
28+
CUDA_RUNTIME, // host side cuda runtime events
29+
CUDA_DRIVER, // host side cuda driver events
2930
CPU_INSTANT_EVENT, // host side point-like events
3031
PYTHON_FUNCTION,
31-
OVERHEAD, // MUPTI induced overhead events sampled from its overhead API.
32+
OVERHEAD, // CUPTI induced overhead events sampled from its overhead API.
33+
MTIA_RUNTIME, // host side MTIA runtime events
34+
MTIA_CCP_EVENTS, // MTIA ondevice CCP events
35+
CUDA_SYNC, // synchronization events between runtime and kernels
3236

3337
// Optional Activity types
34-
MUSA_SYNC, // synchronization events between runtime and kernels
3538
GLOW_RUNTIME, // host side glow runtime events
36-
MTIA_RUNTIME, // host side MTIA runtime events
37-
MUSA_PROFILER_RANGE, // MUPTI Profiler range for performance metrics
38-
MTIA_CCP_EVENTS, // MTIA ondevice CCP events
39+
CUDA_PROFILER_RANGE, // MUPTI Profiler range for performance metrics
3940
HPU_OP, // HPU host side runtime event
4041
XPU_RUNTIME, // host side xpu runtime events
42+
COLLECTIVE_COMM, // collective communication
43+
MTIA_WORKLOADD, // MTIA workloadd events
44+
45+
// PRIVATEUSE1 Activity types are used for custom backends.
46+
// The corresponding device type is `DeviceType::PrivateUse1` in PyTorch.
47+
PRIVATEUSE1_RUNTIME, // host side privateUse1 runtime events
48+
PRIVATEUSE1_DRIVER, // host side privateUse1 driver events
4149

4250
ENUM_COUNT, // This is to add buffer and not used for any profiling logic. Add your new type before it.
43-
OPTIONAL_ACTIVITY_TYPE_START = MUSA_SYNC,
51+
OPTIONAL_ACTIVITY_TYPE_START = GLOW_RUNTIME,
4452
};
4553

4654
const char* toString(ActivityType t);

libkineto/include/Config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,8 @@ class Config : public AbstractConfig {
493493

494494
constexpr char kUseDaemonEnvVar[] = "KINETO_USE_DAEMON";
495495

496-
} // namespace KINETO_NAMESPACE
496+
#if __linux__
497+
bool isDaemonEnvVarSet();
498+
#endif
499+
500+
} // namespace libkineto

libkineto/include/GenericTraceActivity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ constexpr unsigned int kLinkAsyncCpuGpu = 2;
3030
class GenericTraceActivity : public ITraceActivity {
3131
public:
3232
GenericTraceActivity()
33-
: activityType(ActivityType::ENUM_COUNT), traceSpan_(NULL) {}
33+
: activityType(ActivityType::ENUM_COUNT), traceSpan_(nullptr) {}
3434

3535
GenericTraceActivity(
3636
const TraceSpan& trace, ActivityType type, const std::string& name)

libkineto/include/IActivityProfiler.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ enum class TraceStatus {
4141
};
4242

4343
/* DeviceInfo:
44-
* Can be used to specify process name, PID and device label
44+
* Can be used to specify process name, sort order, PID and device label.
45+
* The sort order is determined by the sortIndex field to handle ordering of
46+
* processes and gpu rows in the trace viewer.
4547
*/
4648
struct DeviceInfo {
47-
DeviceInfo(int64_t id, const std::string& name, const std::string& label)
48-
: id(id), name(name), label(label) {}
49+
DeviceInfo(
50+
int64_t id,
51+
int64_t sortIndex,
52+
const std::string& name,
53+
const std::string& label)
54+
: id(id), sortIndex(sortIndex), name(name), label(label) {}
4955
int64_t id; // process id
56+
int64_t sortIndex; // position in trace view
5057
const std::string name; // process name
5158
const std::string label; // device label
5259
};
@@ -66,6 +73,10 @@ struct ResourceInfo {
6673
int64_t deviceId; // id of device which owns this resource (specified in DeviceInfo.id)
6774
const std::string name; // resource name
6875
};
76+
77+
using getLinkedActivityCallback =
78+
std::function<const ITraceActivity*(int32_t)>;
79+
6980
/* IActivityProfilerSession:
7081
* an opaque object that can be used by a high level profiler to
7182
* start/stop and return trace events.
@@ -91,6 +102,12 @@ class IActivityProfilerSession {
91102
// processes trace activities using logger
92103
virtual void processTrace(ActivityLogger& logger) = 0;
93104

105+
virtual void processTrace(ActivityLogger& logger,
106+
getLinkedActivityCallback /*getLinkedActivity*/,
107+
int64_t /*startTime*/, int64_t /*endTime*/) {
108+
processTrace(logger);
109+
}
110+
94111
// returns device info used in this trace, could be nullptr
95112
virtual std::unique_ptr<DeviceInfo> getDeviceInfo() = 0;
96113

@@ -103,6 +120,12 @@ class IActivityProfilerSession {
103120
// XXX define trace formats
104121
// virtual save(string name, TraceFormat format)
105122

123+
virtual void pushCorrelationId(uint64_t /*id*/) {}
124+
virtual void popCorrelationId() {}
125+
126+
virtual void pushUserCorrelationId(uint64_t /*id*/) {}
127+
virtual void popUserCorrelationId() {}
128+
106129
protected:
107130
TraceStatus status_ = TraceStatus::READY;
108131
};

libkineto/include/ThreadUtil.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,3 @@ std::string processName(int32_t pid);
2828
std::vector<std::pair<int32_t, std::string>> pidCommandPairsOfAncestors();
2929

3030
} // namespace libkineto
31-
32-
#ifdef HAS_ROCTRACER
33-
using namespace libkineto;
34-
#endif

libkineto/include/output_base.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <fstream>
12+
#include <map>
13+
#include <ostream>
14+
#include <thread>
15+
#include <unordered_map>
16+
17+
// TODO(T90238193)
18+
// @lint-ignore-every CLANGTIDY facebook-hte-RelativeInclude
19+
#include "IActivityProfiler.h"
20+
#include "GenericTraceActivity.h"
21+
#include "ThreadUtil.h"
22+
#include "TraceSpan.h"
23+
24+
namespace KINETO_NAMESPACE {
25+
struct ActivityBuffers;
26+
}
27+
28+
namespace libkineto {
29+
30+
using namespace KINETO_NAMESPACE;
31+
32+
// Used by sortIndex to put GPU tracks at the bottom
33+
// of the trace timelines. The largest valid CPU PID is 4,194,304,
34+
// so 5000000 is enough to guarantee that GPU tracks are sorted after CPU.
35+
constexpr int64_t kExceedMaxPid = 5000000;
36+
37+
class ActivityLogger {
38+
public:
39+
40+
virtual ~ActivityLogger() = default;
41+
42+
struct OverheadInfo {
43+
explicit OverheadInfo(const std::string& name) : name(name) {}
44+
const std::string name;
45+
};
46+
47+
virtual void handleDeviceInfo(
48+
const DeviceInfo &info,
49+
uint64_t time) = 0;
50+
51+
virtual void handleResourceInfo(const ResourceInfo& info, int64_t time) = 0;
52+
53+
virtual void handleOverheadInfo(const OverheadInfo& info, int64_t time) = 0;
54+
55+
virtual void handleTraceSpan(const TraceSpan& span) = 0;
56+
57+
virtual void handleActivity(
58+
const libkineto::ITraceActivity& activity) = 0;
59+
virtual void handleGenericActivity(
60+
const libkineto::GenericTraceActivity& activity) = 0;
61+
62+
virtual void handleTraceStart(
63+
const std::unordered_map<std::string, std::string>& metadata) = 0;
64+
65+
void handleTraceStart() {
66+
handleTraceStart(std::unordered_map<std::string, std::string>());
67+
}
68+
69+
virtual void finalizeTrace(
70+
const Config& config,
71+
std::unique_ptr<ActivityBuffers> buffers,
72+
int64_t endTime,
73+
std::unordered_map<std::string, std::vector<std::string>>& metadata) = 0;
74+
75+
protected:
76+
ActivityLogger() = default;
77+
};
78+
79+
} // namespace libkineto

libkineto/libkineto_defs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def get_libkineto_public_headers():
7474
"include/ThreadUtil.h",
7575
"include/libkineto.h",
7676
"include/time_since_epoch.h",
77+
"include/output_base.h",
7778
]
7879

7980
# kineto code should be updated to not have to

libkineto/sample_programs/kineto_mupti_profiler.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ int main() {
3434
libkineto::ActivityType::GPU_MEMSET,
3535
libkineto::ActivityType::CONCURRENT_KERNEL,
3636
libkineto::ActivityType::EXTERNAL_CORRELATION,
37-
libkineto::ActivityType::MUSA_RUNTIME,
38-
libkineto::ActivityType::MUSA_DRIVER,
37+
libkineto::ActivityType::CUDA_RUNTIME,
38+
libkineto::ActivityType::CUDA_DRIVER,
3939
libkineto::ActivityType::CPU_INSTANT_EVENT,
4040
libkineto::ActivityType::PYTHON_FUNCTION,
4141
libkineto::ActivityType::OVERHEAD,
42-
libkineto::ActivityType::MUSA_SYNC,
43-
libkineto::ActivityType::GLOW_RUNTIME,
4442
libkineto::ActivityType::MTIA_RUNTIME,
45-
libkineto::ActivityType::MUSA_PROFILER_RANGE,
4643
libkineto::ActivityType::MTIA_CCP_EVENTS,
44+
libkineto::ActivityType::CUDA_SYNC,
45+
libkineto::ActivityType::GLOW_RUNTIME,
46+
libkineto::ActivityType::CUDA_PROFILER_RANGE,
4747
libkineto::ActivityType::HPU_OP,
4848
libkineto::ActivityType::XPU_RUNTIME,
49+
libkineto::ActivityType::COLLECTIVE_COMM,
50+
libkineto::ActivityType::MTIA_WORKLOADD,
51+
libkineto::ActivityType::PRIVATEUSE1_RUNTIME,
52+
libkineto::ActivityType::PRIVATEUSE1_DRIVER,
4953
};
5054

5155
libkineto_init(false, true);

0 commit comments

Comments
 (0)