Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
eae9a63
Reimplemented tracing in a session/client aware manner
Oct 29, 2022
037add4
Delete duplicated code
Oct 29, 2022
40fed8b
WIP
Oct 31, 2022
e06f9fc
Fixes
Oct 31, 2022
e908085
Fixes
Oct 31, 2022
41a973c
Fixes
Oct 31, 2022
b660fc7
Fixes
Oct 31, 2022
8dc917d
Delete unnecessary code
Oct 31, 2022
367fcfc
Minor fixes
Oct 31, 2022
2ae9dad
Fixes + startup
Oct 31, 2022
bd3e7a7
Fixes
Nov 1, 2022
f1f53b0
Fixes
Nov 1, 2022
4c8e468
Fixes
Nov 1, 2022
69c7c8e
Add tracking for hipExtModuleLaunchKernel
Nov 1, 2022
bd76703
Fixes + ts adjustments
Nov 1, 2022
22fefa5
Delete old code
Nov 1, 2022
4190935
Delete blank lines
Nov 1, 2022
8849335
Fixes
Nov 1, 2022
1eaaa8e
Fix re-entrancy deadlock
Nov 1, 2022
dd21a0c
Fixes
Nov 1, 2022
0646193
Minor fix
Nov 1, 2022
09b17a6
Cleanups
Nov 2, 2022
ce97928
Fix
Nov 2, 2022
b89bcd6
Minor fix
Nov 2, 2022
b95d470
Flush activity records on Consume
Nov 2, 2022
c706477
Implement unique correlation ids between sessions
Nov 2, 2022
589cecc
Bug
Nov 2, 2022
c767255
Bug fix
Nov 2, 2022
29a3aa7
Bug fix
Nov 2, 2022
a0e9a20
Remove unnecessary mute
Nov 2, 2022
25be99f
Ran clang-format on all changed source files
Nov 3, 2022
67a3508
Use ORT_UNUSED_PARAMETER
Nov 3, 2022
a2fd04d
review rework
Nov 7, 2022
2161b02
review rework
Nov 8, 2022
2971c9e
Review rework
Nov 8, 2022
2a44480
Minor fix
Nov 8, 2022
65578c3
Review rework
Nov 8, 2022
c04652d
Revert prev change
Nov 8, 2022
ac86163
Review rework
Nov 8, 2022
ab2d864
Review rework
Nov 8, 2022
5474c0a
Include typename in macro
Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions include/onnxruntime/core/common/profiler_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,49 @@ static constexpr const char* event_categor_names_[EVENT_CATEGORY_MAX] = {

// Timing record for all events.
struct EventRecord {
EventRecord() = default;
Comment thread
abudup marked this conversation as resolved.
EventRecord(EventCategory category,
int process_id,
int thread_id,
std::string event_name,
std::string&& event_name,
long long time_stamp,
long long duration,
std::unordered_map<std::string, std::string>&& event_args) : cat(category),
pid(process_id),
tid(thread_id),
name(std::move(event_name)),
ts(time_stamp),
dur(duration),
args(event_args) {}
EventCategory cat;
int pid;
int tid;
std::string name;
long long ts;
long long dur;
std::unordered_map<std::string, std::string> args;
std::unordered_map<std::string, std::string>&& event_args)
: cat(category),
pid(process_id),
tid(thread_id),
name(std::move(event_name)),
ts(time_stamp),
dur(duration),
args(std::move(event_args)) {}

EventRecord(EventCategory category,
int process_id,
int thread_id,
const std::string& event_name,
long long time_stamp,
long long duration,
const std::unordered_map<std::string, std::string>& event_args)
: cat(category),
pid(process_id),
tid(thread_id),
name(event_name),
ts(time_stamp),
dur(duration),
args(event_args) {}

EventRecord(const EventRecord& other) = default;
EventRecord(EventRecord&& other) = default;
EventRecord& operator=(const EventRecord& other) = default;
EventRecord& operator=(EventRecord&& other) = default;

EventCategory cat = EventCategory::API_EVENT;
int pid = -1;
int tid = -1;
std::string name{};
long long ts = 0;
long long dur = 0;
std::unordered_map<std::string, std::string> args{};
};

using Events = std::vector<EventRecord>;
Expand All @@ -55,7 +78,7 @@ using Events = std::vector<EventRecord>;
class EpProfiler {
public:
virtual ~EpProfiler() = default;
virtual bool StartProfiling() = 0; // called when profiling starts
virtual bool StartProfiling(TimePoint profiling_start_time) = 0; // called when profiling starts
virtual void EndProfiling(TimePoint start_time, Events& events) = 0; // called when profiling ends, save all captures numbers to "events"
virtual void Start(uint64_t){}; // called before op start, accept an id as argument to identify the op
virtual void Stop(uint64_t){}; // called after op stop, accept an id as argument to identify the op
Expand Down
8 changes: 4 additions & 4 deletions onnxruntime/core/common/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ::onnxruntime::TimePoint profiling::Profiler::Start() {
auto ts = TimeDiffMicroSeconds(profiling_start_time_, start_time);
for (const auto& ep_profiler : ep_profilers_) {
ep_profiler->Start(ts);
}
}
return start_time;
}

Expand All @@ -49,7 +49,7 @@ void Profiler::StartProfiling(const logging::Logger* custom_logger) {
custom_logger_ = custom_logger;
profiling_start_time_ = std::chrono::high_resolution_clock::now();
for (const auto& ep_profiler : ep_profilers_) {
ep_profiler->StartProfiling();
ep_profiler->StartProfiling(profiling_start_time_);
}
}

Expand All @@ -62,7 +62,7 @@ void Profiler::StartProfiling(const std::basic_string<T>& file_name) {
profile_stream_file_ = ToUTF8String(file_name);
profiling_start_time_ = std::chrono::high_resolution_clock::now();
for (const auto& ep_profiler : ep_profilers_) {
ep_profiler->StartProfiling();
ep_profiler->StartProfiling(profiling_start_time_);
}
}

Expand All @@ -87,7 +87,7 @@ void Profiler::EndTimeAndRecordEvent(EventCategory category,
//TODO: sync_gpu if needed.
std::lock_guard<OrtMutex> lock(mutex_);
if (events_.size() < max_num_events_) {
events_.emplace_back(event);
events_.emplace_back(std::move(event));
} else {
if (session_logger_ && !max_events_reached) {
LOGS(*session_logger_, ERROR)
Expand Down
7 changes: 4 additions & 3 deletions onnxruntime/core/common/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class Profiler {
*/
uint64_t GetStartTimeNs() const {
return std::chrono::duration_cast<std::chrono::nanoseconds>(
profiling_start_time_.time_since_epoch()).count();
profiling_start_time_.time_since_epoch())
.count();
}
/*
Record a single event. Time is measured till the call of this function from
Expand Down Expand Up @@ -108,12 +109,12 @@ class Profiler {
static void SetGlobalMaxNumEvents(size_t new_max_num_events) {
global_max_num_events_.store(new_max_num_events);
}

void AddEpProfilers(std::unique_ptr<EpProfiler> ep_profiler) {
if (ep_profiler) {
ep_profilers_.push_back(std::move(ep_profiler));
if (enabled_) {
ep_profilers_.back()->StartProfiling();
ep_profilers_.back()->StartProfiling(profiling_start_time_);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion onnxruntime/core/common/profiler_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ std::string demangle(const std::string& name) {

} // namespace profiling
} // namespace onnxruntime
Comment thread
abudup marked this conversation as resolved.

6 changes: 3 additions & 3 deletions onnxruntime/core/providers/cuda/cuda_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void CUPTIAPI CudaProfiler::BufferCompleted(CUcontext, uint32_t, uint8_t* buffer
free(buffer);
}

bool CudaProfiler::StartProfiling() {
bool CudaProfiler::StartProfiling(TimePoint /* profiling_start_time */) {
if (!enabled.test_and_set()) {
if (cuptiActivityEnable(CUPTI_ACTIVITY_KIND_RUNTIME) == CUPTI_SUCCESS &&
cuptiActivityEnable(CUPTI_ACTIVITY_KIND_DRIVER) == CUPTI_SUCCESS &&
Expand Down Expand Up @@ -146,7 +146,7 @@ void CudaProfiler::EndProfiling(TimePoint start_time, Events& events) {
for (auto& evt_iter : map_iter.second) {
evt_iter.args["op_name"] = insert_iter->args["op_name"];
}
insert_iter = events.insert(insert_iter+1, map_iter.second.begin(), map_iter.second.end());
insert_iter = events.insert(insert_iter + 1, map_iter.second.begin(), map_iter.second.end());
} else {
insert_iter = events.insert(insert_iter, map_iter.second.begin(), map_iter.second.end());
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void CudaProfiler::Clear() {
}
}

#else // for cuda 10.x, no profiling
#else // for cuda 10.x, no profiling

void CUPTIAPI CudaProfiler::BufferRequested(uint8_t**, size_t*, size_t*) {}
void CUPTIAPI CudaProfiler::BufferCompleted(CUcontext, uint32_t, uint8_t*, size_t, size_t) {}
Expand Down
8 changes: 4 additions & 4 deletions onnxruntime/core/providers/cuda/cuda_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CudaProfiler final : public EpProfiler {
return *this;
}
~CudaProfiler();
bool StartProfiling() override;
bool StartProfiling(TimePoint profiling_start_time) override;
void EndProfiling(TimePoint start_time, Events& events) override;
void Start(uint64_t) override;
void Stop(uint64_t) override;
Expand Down Expand Up @@ -72,13 +72,13 @@ namespace profiling {

class CudaProfiler final : public EpProfiler {
public:
bool StartProfiling() override { return true; }
bool StartProfiling(TimePoint) override { return true; }
void EndProfiling(TimePoint, Events&) override{};
void Start(uint64_t) override{};
void Stop(uint64_t) override{};
};

}
}
} // namespace profiling
} // namespace onnxruntime

#endif
Loading