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

[Profiling,VM] Profiling interface for VM and Graph Runtime #7624

Merged
merged 11 commits into from
Apr 1, 2021

Conversation

tkonolige
Copy link
Contributor

This PR introduces a unified interface for profiling between the graph runtime and VM. It replaces the VM profiler, but adds a separate function to the graph runtime (because the debug graph runtime has more features than just profiling).

Right now profiling reports are just textual, but there should be a straight forward route from the PR to generating structured reports if users want them.

@jroesch @junrushao1994 @comaniac

@tqchen
Copy link
Member

tqchen commented Mar 10, 2021

Thanks @tkonolige , it would be good to think about introducing src/runtime/profiler and have options to optionally turn off the profiler for resource constrained cases

@tkonolige
Copy link
Contributor Author

I talked to @areusch and he said it wouldn't have any effect on embed environments. Furthermore, it should be dead code eliminated if neither the debug graph runtime or VM profiler is enabled. Also, the amount of code introduced here is minimal.

@tqchen
Copy link
Member

tqchen commented Mar 10, 2021

Because of the nature of the shared library (things get linked together) the code won't be dead code eliminated, having an explicit option is still desirable. We are also still using the c++ runtime for android iOS and raspberry pi. Having clear isolation could be a net positive.

@tkonolige
Copy link
Contributor Author

There are already a two flags to enable/disable profiling. Adding a third is even more confusing, so I'm in favor for leaving this as is. Also, the code size here is minimal. On my machine, the code size increase is 80216 bytes.

@tqchen
Copy link
Member

tqchen commented Mar 11, 2021

can we unify the profiling flag into a single one perhaps? Since in the most time we just need an option to switch all profiling off.

@tkonolige
Copy link
Contributor Author

@siju-samuel Do you think you could review this?

@tqchen
Copy link
Member

tqchen commented Mar 18, 2021

cc @trevor-m @icemelon9 @yzhliu would be great if you can take a look as well

include/tvm/runtime/profiling.h Outdated Show resolved Hide resolved
class DurationNode : public Object {
public:
/* The duration as a floating point number of microseconds. */
double value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest changing the name to microseconds to be more specific

src/runtime/profiling.cc Outdated Show resolved Hide resolved
op_timers_.clear();
op_invokes_.clear();

prof_ = profiling::Profiler(); // reset profiler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we create the profiler each time, we should just remove it from the class field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually initialized each time we call reset. The old API is to call invoke and then get_stat to return the profiling information. I wanted to still support old api (though calling invoke twice without reseting will throw an error now). Should I just get rid of the old API?

@@ -42,59 +42,44 @@ namespace vm {
PackedFunc VirtualMachineDebug::GetFunction(const std::string& name,
const ObjectPtr<Object>& sptr_to_self) {
if (name == "get_stat") {
return PackedFunc(
[sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = prof_.Report(); });
} else if (name == "reset") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for reset.

@@ -52,8 +52,7 @@ class VirtualMachineDebug : public VirtualMachine {
const std::vector<ObjectRef>& args) final;

std::unordered_map<Index, std::string> packed_index_map_;
std::unordered_map<Index, std::vector<Timer>> op_timers_;
std::unordered_map<Index, int> op_invokes_;
profiling::Profiler prof_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove it

@tkonolige
Copy link
Contributor Author

@icemelon9 Could you re-review?

@jwfromm
Copy link
Contributor

jwfromm commented Mar 31, 2021

@icemelon9 just wanted to ping you on this again, its come a long way since you last reviewed it.

@icemelon
Copy link
Member

Overall LGTM. You can just remove the reset API in the profiler VM.

@tkonolige
Copy link
Contributor Author

I've removed the reset api. The profiler still needs to be a field because it is used in multiple member functions.

Copy link
Member

@icemelon icemelon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@icemelon
Copy link
Member

Could you fix the CI? @tkonolige

@icemelon icemelon merged commit b95803f into apache:main Apr 1, 2021
@icemelon
Copy link
Member

icemelon commented Apr 1, 2021

Thanks @tkonolige

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
)

* [Profiling,VM] Profiling interface for VM and Graph Runtime

* lint

* fix test

* make profiling test actually run

* Try to better match the graph runtime function names to vm

* formatting

* DurationNode.value -> microseconds; PercentNode.value -> percent; make frame sorting optional.

* renaming for the tvmcontext -> device change

* formatting

* remove old vm profiler get_stat api

* fix tests
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
)

* [Profiling,VM] Profiling interface for VM and Graph Runtime

* lint

* fix test

* make profiling test actually run

* Try to better match the graph runtime function names to vm

* formatting

* DurationNode.value -> microseconds; PercentNode.value -> percent; make frame sorting optional.

* renaming for the tvmcontext -> device change

* formatting

* remove old vm profiler get_stat api

* fix tests
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
)

* [Profiling,VM] Profiling interface for VM and Graph Runtime

* lint

* fix test

* make profiling test actually run

* Try to better match the graph runtime function names to vm

* formatting

* DurationNode.value -> microseconds; PercentNode.value -> percent; make frame sorting optional.

* renaming for the tvmcontext -> device change

* formatting

* remove old vm profiler get_stat api

* fix tests
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
)

* [Profiling,VM] Profiling interface for VM and Graph Runtime

* lint

* fix test

* make profiling test actually run

* Try to better match the graph runtime function names to vm

* formatting

* DurationNode.value -> microseconds; PercentNode.value -> percent; make frame sorting optional.

* renaming for the tvmcontext -> device change

* formatting

* remove old vm profiler get_stat api

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants