Skip to content

Commit c7b91e5

Browse files
committed
Lint
1 parent 743cb89 commit c7b91e5

7 files changed

Lines changed: 83 additions & 47 deletions

File tree

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
sudo apt-get update
25-
sudo apt-get install -y clang-format
25+
sudo apt-get install -y clang-format-18
2626
pip install lintrunner
2727
2828
- name: Initialize lintrunner

.lintrunner.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude_patterns = [
1313
command = [
1414
'python3',
1515
'tools/linter/adapters/clangformat_linter.py',
16-
'--binary=clang-format',
16+
'--binary=clang-format-18',
1717
'@{{PATHSFILE}}'
1818
]
1919
is_formatter = true

libkineto/include/Config.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class Config : public AbstractConfig {
4545
}
4646

4747
[[nodiscard]] bool activityProfilerEnabled() const {
48-
return activityProfilerEnabled_ || activitiesOnDemandTimestamp_.time_since_epoch().count() > 0;
48+
return activityProfilerEnabled_ ||
49+
activitiesOnDemandTimestamp_.time_since_epoch().count() > 0;
4950
}
5051

5152
// Log activitiy trace to this file
@@ -165,7 +166,8 @@ class Config : public AbstractConfig {
165166
// Monitor profiling threads and report when a thread is not responding
166167
// for a given number of seconds.
167168
// A period of 0 means disable.
168-
[[nodiscard]] std::chrono::seconds eventProfilerHeartbeatMonitorPeriod() const {
169+
[[nodiscard]] std::chrono::seconds eventProfilerHeartbeatMonitorPeriod()
170+
const {
169171
return eventProfilerHeartbeatMonitorPeriod_;
170172
}
171173

@@ -235,7 +237,8 @@ class Config : public AbstractConfig {
235237
}
236238

237239
// Timestamp at which the profiling to start, requested by the user.
238-
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock> requestTimestamp() const {
240+
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock>
241+
requestTimestamp() const {
239242
if (profileStartTime_.time_since_epoch().count()) {
240243
return profileStartTime_;
241244
}
@@ -249,7 +252,8 @@ class Config : public AbstractConfig {
249252
}
250253

251254
[[nodiscard]] bool hasProfileStartTime() const {
252-
return requestTimestamp_.time_since_epoch().count() > 0 || profileStartTime_.time_since_epoch().count() > 0;
255+
return requestTimestamp_.time_since_epoch().count() > 0 ||
256+
profileStartTime_.time_since_epoch().count() > 0;
253257
}
254258

255259
[[nodiscard]] int profileStartIteration() const {
@@ -303,20 +307,25 @@ class Config : public AbstractConfig {
303307
return onDemandConfigUpdateIntervalSecs_;
304308
}
305309

306-
static std::chrono::milliseconds alignUp(std::chrono::milliseconds duration, std::chrono::milliseconds alignment) {
310+
static std::chrono::milliseconds alignUp(
311+
std::chrono::milliseconds duration,
312+
std::chrono::milliseconds alignment) {
307313
duration += alignment;
308314
return duration - (duration % alignment);
309315
}
310316

311-
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock> eventProfilerOnDemandStartTime() const {
317+
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock>
318+
eventProfilerOnDemandStartTime() const {
312319
return eventProfilerOnDemandTimestamp_;
313320
}
314321

315-
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock> eventProfilerOnDemandEndTime() const {
322+
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock>
323+
eventProfilerOnDemandEndTime() const {
316324
return eventProfilerOnDemandTimestamp_ + eventProfilerOnDemandDuration_;
317325
}
318326

319-
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock> activityProfilerRequestReceivedTime() const {
327+
[[nodiscard]] std::chrono::time_point<std::chrono::system_clock>
328+
activityProfilerRequestReceivedTime() const {
320329
return activitiesOnDemandTimestamp_;
321330
}
322331

@@ -359,9 +368,12 @@ class Config : public AbstractConfig {
359368
void printActivityProfilerConfig(std::ostream& s) const override;
360369
void setActivityDependentConfig() override;
361370

362-
void validate(const std::chrono::time_point<std::chrono::system_clock>& fallbackProfileStartTime) override;
371+
void validate(const std::chrono::time_point<std::chrono::system_clock>&
372+
fallbackProfileStartTime) override;
363373

364-
static void addConfigFactory(std::string name, std::function<AbstractConfig*(Config&)> factory);
374+
static void addConfigFactory(
375+
std::string name,
376+
std::function<AbstractConfig*(Config&)> factory);
365377

366378
void print(std::ostream& s) const;
367379

@@ -390,7 +402,8 @@ class Config : public AbstractConfig {
390402
private:
391403
explicit Config(const Config& other) = default;
392404

393-
AbstractConfig* cloneDerived([[maybe_unused]] AbstractConfig& parent) const override {
405+
AbstractConfig* cloneDerived(
406+
[[maybe_unused]] AbstractConfig& parent) const override {
394407
// Clone from AbstractConfig not supported
395408
assert(false);
396409
return nullptr;
@@ -424,7 +437,8 @@ class Config : public AbstractConfig {
424437
// On-demand duration
425438
std::chrono::seconds eventProfilerOnDemandDuration_;
426439
// Last on-demand request
427-
std::chrono::time_point<std::chrono::system_clock> eventProfilerOnDemandTimestamp_;
440+
std::chrono::time_point<std::chrono::system_clock>
441+
eventProfilerOnDemandTimestamp_;
428442

429443
int eventProfilerMaxInstancesPerGpu_;
430444

@@ -481,7 +495,8 @@ class Config : public AbstractConfig {
481495
// Only profile nets with at least this many GPU operators
482496
int activitiesExternalAPIGpuOpCountThreshold_;
483497
// Last activity profiler request
484-
std::chrono::time_point<std::chrono::system_clock> activitiesOnDemandTimestamp_;
498+
std::chrono::time_point<std::chrono::system_clock>
499+
activitiesOnDemandTimestamp_;
485500

486501
// ActivityProfilers are triggered by either:
487502
// Synchronized start timestamps

libkineto/src/AbstractConfig.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ int64_t AbstractConfig::toIntRange(const string& val, int64_t min, int64_t max)
102102
if (val.empty() || *invalid) {
103103
throw std::invalid_argument(fmt::format("Invalid integer: {}", val));
104104
} else if (res < min || res > max) {
105-
throw std::invalid_argument(
106-
fmt::format(
107-
"Invalid argument: {} - expected range [{}, {}]", res, min, max));
105+
throw std::invalid_argument(fmt::format(
106+
"Invalid argument: {} - expected range [{}, {}]", res, min, max));
108107
}
109108
return res;
110109
}

libkineto/src/ApproximateClock.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,26 @@
4343
namespace libkineto {
4444

4545
using time_t = int64_t;
46-
using steady_clock_t = std::conditional_t<std::chrono::high_resolution_clock::is_steady,
47-
std::chrono::high_resolution_clock,
48-
std::chrono::steady_clock>;
46+
using steady_clock_t = std::conditional_t<
47+
std::chrono::high_resolution_clock::is_steady,
48+
std::chrono::high_resolution_clock,
49+
std::chrono::steady_clock>;
4950

5051
inline time_t getTime([[maybe_unused]] bool allow_monotonic = false) {
5152
#if defined(_WIN32) || defined(__MACH__)
52-
return std::chrono::duration_cast<std::chrono::nanoseconds>(steady_clock_t::now().time_since_epoch()).count();
53+
return std::chrono::duration_cast<std::chrono::nanoseconds>(
54+
steady_clock_t::now().time_since_epoch())
55+
.count();
5356
#else
5457
// clock_gettime is *much* faster than std::chrono implementation on Linux
55-
struct timespec t{};
58+
struct timespec t {};
5659
auto mode = CLOCK_REALTIME;
5760
if (allow_monotonic) {
5861
mode = CLOCK_MONOTONIC;
5962
}
6063
clock_gettime(mode, &t);
61-
return (static_cast<time_t>(t.tv_sec) * 1000000000) + static_cast<time_t>(t.tv_nsec);
64+
return (static_cast<time_t>(t.tv_sec) * 1000000000) +
65+
static_cast<time_t>(t.tv_nsec);
6266
#endif
6367
}
6468

@@ -79,8 +83,10 @@ inline auto getApproximateTime() {
7983
}
8084

8185
using approx_time_t = decltype(getApproximateTime());
82-
static_assert(std::is_same_v<approx_time_t, int64_t> || std::is_same_v<approx_time_t, uint64_t>,
83-
"Expected either int64_t (`getTime`) or uint64_t (some TSC reads).");
86+
static_assert(
87+
std::is_same_v<approx_time_t, int64_t> ||
88+
std::is_same_v<approx_time_t, uint64_t>,
89+
"Expected either int64_t (`getTime`) or uint64_t (some TSC reads).");
8490

8591
std::function<time_t(approx_time_t)>& get_time_converter();
8692

libkineto/src/EventProfiler.h

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class Event {
7070
Event(Event&&) = default;
7171
Event& operator=(Event&&) = default;
7272

73-
void addSample(std::chrono::time_point<std::chrono::system_clock> timestamp, const std::vector<int64_t>& values) {
73+
void addSample(
74+
std::chrono::time_point<std::chrono::system_clock> timestamp,
75+
const std::vector<int64_t>& values) {
7476
assert(values.size() == static_cast<size_t>(instanceCount));
7577
samples_.emplace_back(timestamp, values);
7678
}
@@ -82,7 +84,8 @@ class Event {
8284
[[nodiscard]] int64_t sumAll(const SampleSlice& slice) const;
8385

8486
// Create list of percentiles
85-
PercentileList& percentiles(PercentileList& pcs, const SampleSlice& slice) const;
87+
PercentileList& percentiles(PercentileList& pcs, const SampleSlice& slice)
88+
const;
8689

8790
void eraseSamples(int count) {
8891
auto end = samples_.begin();
@@ -114,26 +117,30 @@ class Event {
114117

115118
// List of collected samples, where each sample has values for
116119
// one or more domain instances
117-
using Sample = std::pair<std::chrono::time_point<std::chrono::system_clock>, std::vector<int64_t>>;
120+
using Sample = std::pair<
121+
std::chrono::time_point<std::chrono::system_clock>,
122+
std::vector<int64_t>>;
118123
std::list<Sample> samples_;
119124
};
120125

121126
class Metric {
122127
public:
123-
Metric(std::string name,
124-
CUpti_MetricID id,
125-
std::vector<CUpti_EventID> events,
126-
CUpti_MetricEvaluationMode eval_mode,
127-
CuptiMetricApi& cupti_metrics);
128+
Metric(
129+
std::string name,
130+
CUpti_MetricID id,
131+
std::vector<CUpti_EventID> events,
132+
CUpti_MetricEvaluationMode eval_mode,
133+
CuptiMetricApi& cupti_metrics);
128134

129135
struct CalculatedValues {
130136
std::vector<SampleValue> perInstance;
131137
SampleValue total;
132138
};
133139

134-
struct CalculatedValues calculate(std::map<CUpti_EventID, Event>& events,
135-
std::chrono::nanoseconds sample_duration,
136-
const SampleSlice& slice);
140+
struct CalculatedValues calculate(
141+
std::map<CUpti_EventID, Event>& events,
142+
std::chrono::nanoseconds sample_duration,
143+
const SampleSlice& slice);
137144

138145
int instanceCount(std::map<CUpti_EventID, Event>& events) {
139146
return events[events_[0]].instanceCount;
@@ -160,7 +167,10 @@ class Metric {
160167
*/
161168
class EventGroupSet {
162169
public:
163-
EventGroupSet(CUpti_EventGroupSet& set, std::map<CUpti_EventID, Event>& events, CuptiEventApi& cupti);
170+
EventGroupSet(
171+
CUpti_EventGroupSet& set,
172+
std::map<CUpti_EventID, Event>& events,
173+
CuptiEventApi& cupti);
164174
~EventGroupSet();
165175

166176
EventGroupSet(const EventGroupSet&) = delete;
@@ -189,10 +199,11 @@ class EventGroupSet {
189199
// The sampler
190200
class EventProfiler {
191201
public:
192-
explicit EventProfiler(std::unique_ptr<CuptiEventApi> cupti_events,
193-
std::unique_ptr<CuptiMetricApi> cupti_metrics,
194-
std::vector<std::unique_ptr<SampleListener>>& loggers,
195-
std::vector<std::unique_ptr<SampleListener>>& onDemandLoggers);
202+
explicit EventProfiler(
203+
std::unique_ptr<CuptiEventApi> cupti_events,
204+
std::unique_ptr<CuptiMetricApi> cupti_metrics,
205+
std::vector<std::unique_ptr<SampleListener>>& loggers,
206+
std::vector<std::unique_ptr<SampleListener>>& onDemandLoggers);
196207
EventProfiler(const EventProfiler&) = delete;
197208
EventProfiler& operator=(const EventProfiler&) = delete;
198209
~EventProfiler();
@@ -254,7 +265,8 @@ class EventProfiler {
254265

255266
void eraseReportedSamples() {
256267
int erase_count = baseSamples_;
257-
if (onDemandConfig_ && onDemandConfig_->eventProfilerOnDemandDuration().count() > 0) {
268+
if (onDemandConfig_ &&
269+
onDemandConfig_->eventProfilerOnDemandDuration().count() > 0) {
258270
erase_count = std::min(baseSamples_, onDemandSamples_);
259271
}
260272
eraseSamples(erase_count);
@@ -288,9 +300,10 @@ class EventProfiler {
288300
}
289301

290302
// Notify listeners of collected samples
291-
void dispatchSamples(const Config& config,
292-
const std::vector<std::unique_ptr<SampleListener>>& loggers,
293-
int report_nr);
303+
void dispatchSamples(
304+
const Config& config,
305+
const std::vector<std::unique_ptr<SampleListener>>& loggers,
306+
int report_nr);
294307

295308
void eraseSamples(int count) {
296309
for (auto& pair : events_) {

libkineto/src/SampleListener.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ class SampleListener {
142142
virtual ~SampleListener() = default;
143143

144144
// Report bucketed & aggregated values for event
145-
virtual void handleSample(int device, const Sample& sample, bool from_new_version) = 0;
145+
virtual void handleSample(
146+
int device,
147+
const Sample& sample,
148+
bool from_new_version) = 0;
146149

147150
virtual void update(const Config& config) = 0;
148151

0 commit comments

Comments
 (0)