Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[misc] Prettify KernelProfiler outputs #1525

Merged
merged 1 commit into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 26 additions & 6 deletions taichi/program/kernel_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ void KernelProfileRecord::insert_sample(double t) {
total += t;
}

bool KernelProfileRecord::operator<(const KernelProfileRecord &o) const {
return total > o.total;
}

void KernelProfilerBase::profiler_start(KernelProfilerBase *profiler,
const char *kernel_name) {
TI_ASSERT(profiler);
Expand All @@ -29,14 +33,30 @@ void KernelProfilerBase::profiler_stop(KernelProfilerBase *profiler) {

void KernelProfilerBase::print() {
sync();
printf("%s\n", title().c_str());
fmt::print("{}\n", title());
fmt::print(
"========================================================================"
"=\n");
fmt::print(
"[ % total count | min avg max ] Kernel "
"name\n");
std::sort(records.begin(), records.end());
for (auto &rec : records) {
printf(
"[%6.2f%%] %-40s min %7.3f ms avg %7.3f ms max %7.3f ms "
"total %7.3f s [%7dx]\n",
rec.total / total_time * 100.0f, rec.name.c_str(), rec.min,
rec.total / rec.counter, rec.max, rec.total / 1000.0f, rec.counter);
auto fraction = rec.total / total_time * 100.0f;
fmt::print("[{:6.2f}% {:7.3f} s {:6d}x |{:9.3f} {:9.3f} {:9.3f} ms] {}\n",
fraction, rec.total / 1000.0f, rec.counter, rec.min,
rec.total / rec.counter, rec.max, rec.name);
}
fmt::print(
"------------------------------------------------------------------------"
"-\n");
fmt::print(
"[100.00%] Total kernel execution time: {:7.3f} s number of records: "
"{}\n",
total_time / 1000.0f, records.size());
fmt::print(
"========================================================================"
"=\n");
}

namespace {
Expand Down
2 changes: 2 additions & 0 deletions taichi/program/kernel_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct KernelProfileRecord {
}

void insert_sample(double t);

bool operator<(const KernelProfileRecord &o) const;
};

class KernelProfilerBase {
Expand Down