-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
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 |
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. |
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. |
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. |
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. |
@siju-samuel Do you think you could review this? |
include/tvm/runtime/profiling.h
Outdated
class DurationNode : public Object { | ||
public: | ||
/* The duration as a floating point number of microseconds. */ | ||
double value; |
There was a problem hiding this comment.
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
op_timers_.clear(); | ||
op_invokes_.clear(); | ||
|
||
prof_ = profiling::Profiler(); // reset profiler |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 reset
ing will throw an error now). Should I just get rid of the old API?
src/runtime/vm/profiler/vm.cc
Outdated
@@ -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") { |
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove it
@icemelon9 Could you re-review? |
…e frame sorting optional.
@icemelon9 just wanted to ping you on this again, its come a long way since you last reviewed it. |
Overall LGTM. You can just remove the |
I've removed the reset api. The profiler still needs to be a field because it is used in multiple member functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Could you fix the CI? @tkonolige |
Thanks @tkonolige |
) * [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
) * [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
) * [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
) * [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
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