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

[cuda] Decouple update from sync function in kernel profiler #5589

Merged
merged 1 commit into from
Aug 2, 2022
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
3 changes: 2 additions & 1 deletion python/taichi/profiler/kernel_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def clear_info(self):
#sync first
impl.get_runtime().prog.sync_kernel_profiler()
#then clear backend & frontend info
impl.get_runtime().prog.clear_kernel_profile_info()
impl.get_runtime().prog.clear_kernel_profiler()
self._clear_frontend()

return None
Expand Down Expand Up @@ -199,6 +199,7 @@ def _clear_frontend(self):
def _update_records(self):
"""Acquires kernel records from a backend."""
impl.get_runtime().prog.sync_kernel_profiler()
impl.get_runtime().prog.update_kernel_profiler()
qiao-bo marked this conversation as resolved.
Show resolved Hide resolved
self._clear_frontend()
self._traced_records = impl.get_runtime(
).prog.get_kernel_profiler_records()
Expand Down
3 changes: 3 additions & 0 deletions taichi/program/kernel_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class DefaultProfiler : public KernelProfilerBase {
void sync() override {
}

void update() override {
}

void clear() override {
// sync(); //decoupled: trigger from the foront end
total_time_ms_ = 0;
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 @@ -61,6 +61,8 @@ class KernelProfilerBase {

virtual void sync() = 0;

virtual void update() = 0;

virtual bool set_profiler_toolkit(std::string toolkit_name) {
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion taichi/python/export_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ void export_lang(py::module &m) {
.def_readonly("config", &Program::config)
.def("sync_kernel_profiler",
[](Program *program) { program->profiler->sync(); })
.def("update_kernel_profiler",
[](Program *program) { program->profiler->update(); })
.def("clear_kernel_profiler",
[](Program *program) { program->profiler->clear(); })
.def("query_kernel_profile_info",
[](Program *program, const std::string &name) {
return program->query_kernel_profile_info(name);
Expand Down Expand Up @@ -339,7 +343,6 @@ void export_lang(py::module &m) {
[](Program *program, const std::string toolkit_name) {
return program->profiler->set_profiler_toolkit(toolkit_name);
})
.def("clear_kernel_profile_info", &Program::clear_kernel_profile_info)
.def("timeline_clear",
[](Program *) { Timelines::get_instance().clear(); })
.def("timeline_save",
Expand Down
8 changes: 6 additions & 2 deletions taichi/rhi/cuda/cuda_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ bool KernelProfilerCUDA::statistics_on_traced_records() {
}

void KernelProfilerCUDA::sync() {
// sync
CUDADriver::get_instance().stream_synchronize(nullptr);
}

// update
void KernelProfilerCUDA::update() {
if (tool_ == ProfilingToolkit::event) {
event_toolkit_->update_record(records_size_after_sync_, traced_records_);
event_toolkit_->update_timeline(traced_records_);
Expand All @@ -173,6 +173,7 @@ void KernelProfilerCUDA::sync() {

void KernelProfilerCUDA::clear() {
// sync(); //decoupled: trigger from the foront end
update();
total_time_ms_ = 0;
records_size_after_sync_ = 0;
traced_records_.clear();
Expand Down Expand Up @@ -240,6 +241,9 @@ void KernelProfilerCUDA::stop(KernelProfilerBase::TaskHandle handle) {
void KernelProfilerCUDA::sync() {
TI_NOT_IMPLEMENTED;
}
void KernelProfilerCUDA::update() {
TI_NOT_IMPLEMENTED;
}
void KernelProfilerCUDA::clear() {
TI_NOT_IMPLEMENTED;
}
Expand Down
1 change: 1 addition & 0 deletions taichi/rhi/cuda/cuda_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class KernelProfilerCUDA : public KernelProfilerBase {
uint32_t block_size,
uint32_t dynamic_smem_size);
void sync() override;
void update() override;
void clear() override;
void stop(KernelProfilerBase::TaskHandle handle) override;

Expand Down