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

[refactor] Decouple KernelProfilerBase::sync() from Program::synchronize() #3504

Merged
merged 7 commits into from
Nov 17, 2021
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
4 changes: 2 additions & 2 deletions python/taichi/profiler/kernelprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def clear_info(self):
if self._check_not_turned_on_with_warning_message():
return None
#sync first
impl.get_runtime().sync()
impl.get_runtime().prog.sync_kernel_profiler()
#then clear backend & frontend info
impl.get_runtime().prog.clear_kernel_profile_info()
self._clear_frontend()
Expand Down Expand Up @@ -186,7 +186,7 @@ def _clear_frontend(self):

def _update_records(self):
"""Acquires kernel records from a backend."""
impl.get_runtime().sync()
impl.get_runtime().prog.sync_kernel_profiler()
self._clear_frontend()
self._traced_records = impl.get_runtime(
).prog.get_kernel_profiler_records()
Expand Down
6 changes: 4 additions & 2 deletions taichi/backends/metal/kernel_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,13 @@ class KernelManager::Impl {
end_encoding(encoder.get());
}
// Sync
profiler_->start("metal_synchronize");
if (profiler_)
profiler_->start("metal_synchronize");
commit_command_buffer(cur_command_buffer_.get());
wait_until_completed(cur_command_buffer_.get());
create_new_command_buffer();
profiler_->stop();
if (profiler_)
profiler_->stop();

// print_runtime_debug();
}
Expand Down
2 changes: 2 additions & 0 deletions taichi/program/kernel_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class DefaultProfiler : public KernelProfilerBase {
} // namespace

std::unique_ptr<KernelProfilerBase> make_profiler(Arch arch, bool enable) {
if (!enable)
return nullptr;
if (arch == Arch::cuda) {
#if defined(TI_WITH_CUDA)
return std::make_unique<KernelProfilerCUDA>(enable);
Expand Down
3 changes: 0 additions & 3 deletions taichi/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ void Program::synchronize() {
if (config.async_mode) {
async_engine->synchronize();
}
if (profiler) {
profiler->sync();
}
if (arch_uses_llvm(config.arch) || config.arch == Arch::metal ||
config.arch == Arch::vulkan) {
program_impl_->synchronize();
Expand Down
2 changes: 2 additions & 0 deletions taichi/python/export_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ void export_lang(py::module &m) {
py::class_<Program>(m, "Program")
.def(py::init<>())
.def_readonly("config", &Program::config)
.def("sync_kernel_profiler",
[](Program *program) { program->profiler->sync(); })
.def("query_kernel_profile_info",
[](Program *program, const std::string &name) {
return program->query_kernel_profile_info(name);
Expand Down