Skip to content

Commit 4ee28bc

Browse files
authored
update kineto to v2.7.0 (#7)
1 parent 7179419 commit 4ee28bc

58 files changed

Lines changed: 1115 additions & 870 deletions

Some content is hidden

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

libkineto/include/AbstractConfig.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <string>
1515
#include <vector>
1616

17-
namespace KINETO_NAMESPACE {
17+
namespace libkineto {
1818

1919
class AbstractConfig {
2020
public:
@@ -80,11 +80,15 @@ class AbstractConfig {
8080
// multiple options.
8181
// Throw std::invalid_argument if automatic correction can not be made.
8282
//
83-
// @param fallbackProfileStartTime Specify a fallback profile start timestamp in case it was never specified by the client
84-
virtual void validate(const std::chrono::time_point<std::chrono::system_clock>& fallbackProfileStartTime) = 0;
83+
// @param fallbackProfileStartTime Specify a fallback profile start timestamp
84+
// in case it was never specified by the client
85+
virtual void validate(
86+
const std::chrono::time_point<std::chrono::system_clock>&
87+
fallbackProfileStartTime) = 0;
8588

8689
// TODO: Separate out each profiler type into features?
8790
virtual void printActivityProfilerConfig(std::ostream& s) const;
91+
virtual void setActivityDependentConfig();
8892

8993
// Helpers for use in handleOption
9094
// Split a string by delimiter and remove external white space
@@ -116,4 +120,4 @@ class AbstractConfig {
116120
std::map<std::string, AbstractConfig*> featureConfigs_{};
117121
};
118122

119-
} // namespace KINETO_NAMESPACE
123+
} // namespace libkineto

libkineto/include/ActivityProfilerInterface.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <thread>
1414
#include <vector>
1515

16-
#include "ActivityType.h"
1716
#include "ActivityTraceInterface.h"
17+
#include "ActivityType.h"
1818
#include "IActivityProfiler.h"
1919

2020
namespace libkineto {
@@ -24,15 +24,14 @@ struct CpuTraceBuffer;
2424
class Config;
2525

2626
class ActivityProfilerInterface {
27-
2827
public:
29-
virtual ~ActivityProfilerInterface() {};
28+
virtual ~ActivityProfilerInterface() {}
3029

3130
virtual void init() {}
3231
virtual bool isInitialized() {
3332
return false;
3433
}
35-
virtual bool isActive(){
34+
virtual bool isActive() {
3635
return false;
3736
}
3837

@@ -41,10 +40,6 @@ class ActivityProfilerInterface {
4140
// and duration and / or iteration stop criterion.
4241
// Tracing terminates when either condition is met.
4342
virtual void scheduleTrace(const std::string& configStr) {}
44-
virtual bool isSyncProfilingRunning() {
45-
return false;
46-
}
47-
virtual void setSyncProfilingRunning(bool b) {}
4843

4944
// *** Synchronous API ***
5045
// These must be called in order:
@@ -78,22 +73,23 @@ class ActivityProfilerInterface {
7873

7974
// *** TraceActivity API ***
8075
// FIXME: Pass activityProfiler interface into clientInterface?
81-
virtual void pushCorrelationId(uint64_t id){}
82-
virtual void popCorrelationId(){}
83-
virtual void transferCpuTrace(
84-
std::unique_ptr<CpuTraceBuffer> traceBuffer){}
76+
virtual void pushCorrelationId(uint64_t id) {}
77+
virtual void popCorrelationId() {}
78+
virtual void transferCpuTrace(std::unique_ptr<CpuTraceBuffer> traceBuffer) {}
8579

8680
// Correlation ids for user defined spans
87-
virtual void pushUserCorrelationId(uint64_t){}
88-
virtual void popUserCorrelationId(){}
81+
virtual void pushUserCorrelationId(uint64_t) {}
82+
virtual void popUserCorrelationId() {}
8983

9084
// Saves information for the current thread to be used in profiler output
9185
// Client must record any new kernel thread where the activity has occured.
9286
virtual void recordThreadInfo() {}
9387

9488
// Record trace metadata, currently supporting only string key and values,
9589
// values with the same key are overwritten
96-
virtual void addMetadata(const std::string& key, const std::string& value) = 0;
90+
virtual void addMetadata(
91+
const std::string& key,
92+
const std::string& value) = 0;
9793

9894
// Add a child activity profiler, this enables frameworks in the application
9995
// to enable custom framework events.

libkineto/include/Config.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#include <string>
1919
#include <vector>
2020

21-
namespace KINETO_NAMESPACE {
22-
23-
using namespace libkineto;
21+
namespace libkineto {
2422

2523
class Config : public AbstractConfig {
2624
public:
@@ -47,7 +45,7 @@ class Config : public AbstractConfig {
4745

4846
bool activityProfilerEnabled() const {
4947
return activityProfilerEnabled_ ||
50-
activitiesOnDemandTimestamp_.time_since_epoch().count() > 0;
48+
activitiesOnDemandTimestamp_.time_since_epoch().count() > 0;
5149
}
5250

5351
// Log activitiy trace to this file
@@ -176,6 +174,11 @@ class Config : public AbstractConfig {
176174
return selectedActivityTypes_;
177175
}
178176

177+
// Set the types of activities to be traced
178+
bool perThreadBufferEnabled() const {
179+
return perThreadBufferEnabled_;
180+
}
181+
179182
void setSelectedActivityTypes(const std::set<ActivityType>& types) {
180183
selectedActivityTypes_ = types;
181184
}
@@ -352,9 +355,9 @@ class Config : public AbstractConfig {
352355
}
353356

354357
void updateActivityProfilerRequestReceivedTime();
355-
void updateActivityProfilerStartTime();
356358

357359
void printActivityProfilerConfig(std::ostream& s) const override;
360+
void setActivityDependentConfig() override;
358361

359362
void validate(const std::chrono::time_point<std::chrono::system_clock>&
360363
fallbackProfileStartTime) override;
@@ -371,6 +374,14 @@ class Config : public AbstractConfig {
371374
// correct destruction order can be ensured.
372375
static std::shared_ptr<void> getStaticObjectsLifetimeHandle();
373376

377+
bool getTSCTimestampFlag() const {
378+
return useTSCTimestamp_;
379+
}
380+
381+
void setTSCTimestampFlag(bool flag) {
382+
useTSCTimestamp_ = flag;
383+
}
384+
374385
private:
375386
explicit Config(const Config& other) = default;
376387

@@ -425,6 +436,9 @@ class Config : public AbstractConfig {
425436

426437
// Activity profiler
427438
bool activityProfilerEnabled_;
439+
440+
// Enable per-thread buffer
441+
bool perThreadBufferEnabled_;
428442
std::set<ActivityType> selectedActivityTypes_;
429443

430444
// The activity profiler settings are all on-demand
@@ -489,12 +503,13 @@ class Config : public AbstractConfig {
489503
// MUPTI Device Buffer
490504
size_t muptiDeviceBufferSize_;
491505
size_t muptiDeviceBufferPoolLimit_;
506+
507+
// MUPTI Timestamp Format
508+
bool useTSCTimestamp_{true};
492509
};
493510

494511
constexpr char kUseDaemonEnvVar[] = "KINETO_USE_DAEMON";
495512

496-
#if __linux__
497513
bool isDaemonEnvVarSet();
498-
#endif
499514

500515
} // namespace libkineto

libkineto/include/GenericTraceActivity.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#pragma once
1010

1111
#include <fmt/format.h>
12+
#include <sstream>
1213
#include <string>
1314
#include <thread>
1415
#include <unordered_map>
1516
#include <vector>
16-
#include <sstream>
1717

1818
#include "ITraceActivity.h"
1919
#include "ThreadUtil.h"
@@ -25,15 +25,18 @@ namespace libkineto {
2525
constexpr unsigned int kLinkFwdBwd = 1;
2626
constexpr unsigned int kLinkAsyncCpuGpu = 2;
2727

28-
// @lint-ignore-every CLANGTIDY cppcoreguidelines-non-private-member-variables-in-classes
28+
// @lint-ignore-every CLANGTIDY
29+
// cppcoreguidelines-non-private-member-variables-in-classes
2930
// @lint-ignore-every CLANGTIDY cppcoreguidelines-pro-type-member-init
3031
class GenericTraceActivity : public ITraceActivity {
3132
public:
3233
GenericTraceActivity()
3334
: activityType(ActivityType::ENUM_COUNT), traceSpan_(nullptr) {}
3435

3536
GenericTraceActivity(
36-
const TraceSpan& trace, ActivityType type, const std::string& name)
37+
const TraceSpan& trace,
38+
ActivityType type,
39+
const std::string& name)
3740
: activityType(type), activityName(name), traceSpan_(&trace) {}
3841

3942
int64_t deviceId() const override {
@@ -72,7 +75,7 @@ class GenericTraceActivity : public ITraceActivity {
7275
return flow.type;
7376
}
7477

75-
int flowId() const override {
78+
int64_t flowId() const override {
7679
return flow.id;
7780
}
7881

@@ -121,7 +124,7 @@ class GenericTraceActivity : public ITraceActivity {
121124
return json.str();
122125
}
123126

124-
virtual ~GenericTraceActivity() override {};
127+
virtual ~GenericTraceActivity() override {}
125128

126129
int64_t startTime{0};
127130
int64_t endTime{0};
@@ -132,7 +135,7 @@ class GenericTraceActivity : public ITraceActivity {
132135
ActivityType activityType;
133136
std::string activityName;
134137
struct Flow {
135-
Flow(): id(0), type(0), start(0) {}
138+
Flow() : id(0), type(0), start(0) {}
136139
// Ids must be unique within each type
137140
uint32_t id : 27;
138141
// Type will be used to connect flows between profilers, as

libkineto/include/IActivityProfiler.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
namespace libkineto {
2525

26-
using namespace KINETO_NAMESPACE;
2726
struct CpuTraceBuffer;
2827

2928
#ifdef _MSC_VER
@@ -52,10 +51,10 @@ struct DeviceInfo {
5251
const std::string& name,
5352
const std::string& label)
5453
: id(id), sortIndex(sortIndex), name(name), label(label) {}
55-
int64_t id; // process id
56-
int64_t sortIndex; // position in trace view
57-
const std::string name; // process name
58-
const std::string label; // device label
54+
int64_t id; // process id
55+
int64_t sortIndex; // position in trace view
56+
const std::string name; // process name
57+
const std::string label; // device label
5958
};
6059

6160
/* ResourceInfo:
@@ -68,21 +67,20 @@ struct ResourceInfo {
6867
int64_t sortIndex,
6968
const std::string& name)
7069
: id(id), sortIndex(sortIndex), deviceId(deviceId), name(name) {}
71-
int64_t id; // resource id
72-
int64_t sortIndex; // position in trace view
73-
int64_t deviceId; // id of device which owns this resource (specified in DeviceInfo.id)
70+
int64_t id; // resource id
71+
int64_t sortIndex; // position in trace view
72+
int64_t deviceId; // id of device which owns this resource (specified in
73+
// DeviceInfo.id)
7474
const std::string name; // resource name
7575
};
7676

77-
using getLinkedActivityCallback =
78-
std::function<const ITraceActivity*(int32_t)>;
77+
using getLinkedActivityCallback = std::function<const ITraceActivity*(int32_t)>;
7978

8079
/* IActivityProfilerSession:
8180
* an opaque object that can be used by a high level profiler to
8281
* start/stop and return trace events.
8382
*/
8483
class IActivityProfilerSession {
85-
8684
public:
8785
virtual ~IActivityProfilerSession() {}
8886

@@ -102,9 +100,11 @@ class IActivityProfilerSession {
102100
// processes trace activities using logger
103101
virtual void processTrace(ActivityLogger& logger) = 0;
104102

105-
virtual void processTrace(ActivityLogger& logger,
106-
getLinkedActivityCallback /*getLinkedActivity*/,
107-
int64_t /*startTime*/, int64_t /*endTime*/) {
103+
virtual void processTrace(
104+
ActivityLogger& logger,
105+
getLinkedActivityCallback /*getLinkedActivity*/,
106+
int64_t /*startTime*/,
107+
int64_t /*endTime*/) {
108108
processTrace(logger);
109109
}
110110

@@ -126,21 +126,22 @@ class IActivityProfilerSession {
126126
virtual void pushUserCorrelationId(uint64_t /*id*/) {}
127127
virtual void popUserCorrelationId() {}
128128

129+
virtual std::string getDeviceProperties() {
130+
return "";
131+
}
132+
129133
protected:
130134
TraceStatus status_ = TraceStatus::READY;
131135
};
132136

133-
134137
/* Activity Profiler Plugins:
135138
* These allow other frameworks to integrate into Kineto's primariy
136139
* activity profiler. While the primary activity profiler handles
137140
* timing the trace collections and correlating events the plugins
138141
* can become source of new trace activity types.
139142
*/
140143
class IActivityProfiler {
141-
142144
public:
143-
144145
virtual ~IActivityProfiler() {}
145146

146147
// name of profiler

libkineto/include/ILoggerObserver.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,39 @@ constexpr char kWarmUpStage[] = "Warm Up";
1515
constexpr char kCollectionStage[] = "Collection";
1616
constexpr char kPostProcessingStage[] = "Post Processing";
1717

18+
// Special string in UST for determining if traces are empty
19+
constexpr char kEmptyTrace[] =
20+
"No Valid Trace Events (CPU/GPU) found. Outputting empty trace.";
21+
1822
#if !USE_GOOGLE_LOG
1923

2024
#include <map>
2125
#include <vector>
2226

27+
#include <stdint.h>
28+
2329
namespace libkineto {
2430

2531
enum LoggerOutputType {
2632
VERBOSE = 0,
2733
INFO = 1,
2834
WARNING = 2,
29-
ERROR = 3,
30-
STAGE = 4,
35+
STAGE = 3,
36+
ERROR = 4,
3137
ENUM_COUNT = 5
3238
};
3339

3440
const char* toString(LoggerOutputType t);
3541
LoggerOutputType toLoggerOutputType(const std::string& str);
3642

37-
constexpr int LoggerTypeCount = (int) LoggerOutputType::ENUM_COUNT;
43+
constexpr int LoggerTypeCount = (int)LoggerOutputType::ENUM_COUNT;
3844

3945
class ILoggerObserver {
4046
public:
4147
virtual ~ILoggerObserver() = default;
4248
virtual void write(const std::string& message, LoggerOutputType ot) = 0;
43-
virtual const std::map<LoggerOutputType, std::vector<std::string>> extractCollectorMetadata() = 0;
49+
virtual const std::map<LoggerOutputType, std::vector<std::string>>
50+
extractCollectorMetadata() = 0;
4451
virtual void reset() = 0;
4552
virtual void addDevice(const int64_t device) = 0;
4653
virtual void setTraceDurationMS(const int64_t duration) = 0;
@@ -49,8 +56,9 @@ class ILoggerObserver {
4956
virtual void setGroupTraceID(const std::string&) {}
5057
virtual void addDestination(const std::string& dest) = 0;
5158
virtual void setTriggerOnDemand() {}
52-
virtual void addMetadata(const std::string& key, const std::string& value) = 0;
53-
59+
virtual void addMetadata(
60+
const std::string& key,
61+
const std::string& value) = 0;
5462
};
5563

5664
} // namespace libkineto

0 commit comments

Comments
 (0)