-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[PROFILING] Profiling over RPC #8885
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| * \brief Runtime profiling including timers. | ||
| */ | ||
|
|
||
| #include <dmlc/json.h> | ||
| #include <tvm/ir/expr.h> | ||
| #include <tvm/runtime/c_backend_api.h> | ||
| #include <tvm/runtime/packed_func.h> | ||
|
|
@@ -231,7 +232,9 @@ String ReportNode::AsCSV() const { | |
| namespace { | ||
| void print_metric(std::ostream& os, ObjectRef o) { | ||
| if (o.as<StringObj>()) { | ||
| os << "\"" << Downcast<String>(o) << "\""; | ||
| os << "{\"string\":" | ||
| << "\"" << Downcast<String>(o) << "\"" | ||
| << "}"; | ||
| } else if (const CountNode* n = o.as<CountNode>()) { | ||
| os << "{\"count\":" << std::to_string(n->value) << "}"; | ||
| } else if (const DurationNode* n = o.as<DurationNode>()) { | ||
|
|
@@ -540,6 +543,72 @@ Report::Report(Array<Map<String, ObjectRef>> calls, | |
| data_ = std::move(node); | ||
| } | ||
|
|
||
| Map<String, ObjectRef> parse_metrics(dmlc::JSONReader* reader) { | ||
| reader->BeginObject(); | ||
| std::string metric_name, metric_value_name; | ||
| Map<String, ObjectRef> metrics; | ||
| while (reader->NextObjectItem(&metric_name)) { | ||
| ObjectRef o; | ||
| reader->BeginObject(); | ||
| reader->NextObjectItem(&metric_value_name); | ||
| if (metric_value_name == "microseconds") { | ||
| double microseconds; | ||
| reader->Read(µseconds); | ||
| o = ObjectRef(make_object<DurationNode>(microseconds)); | ||
| } else if (metric_value_name == "percent") { | ||
| double percent; | ||
| reader->Read(&percent); | ||
| o = ObjectRef(make_object<PercentNode>(percent)); | ||
| } else if (metric_value_name == "count") { | ||
| int64_t count; | ||
| reader->Read(&count); | ||
| o = ObjectRef(make_object<CountNode>(count)); | ||
| } else if (metric_value_name == "string") { | ||
| std::string s; | ||
| reader->Read(&s); | ||
| o = String(s); | ||
| } else { | ||
| LOG(FATAL) << "Cannot parse metric of type " << metric_value_name | ||
| << " valid types are microseconds, percent, count."; | ||
| } | ||
| metrics.Set(metric_name, o); | ||
| // Necessary to make sure that the parser hits the end of the object. | ||
| ICHECK(!reader->NextObjectItem(&metric_value_name)); | ||
| // EndObject does not exist, leaving this here for clarity | ||
| // reader.EndObject(); | ||
| } | ||
| // reader.EndObject(); | ||
| return metrics; | ||
| } | ||
|
|
||
| Report Report::FromJSON(String json) { | ||
| std::stringstream input(json.operator std::string()); | ||
| dmlc::JSONReader reader(&input); | ||
| std::string key; | ||
| Array<Map<String, ObjectRef>> calls; | ||
| Map<String, Map<String, ObjectRef>> device_metrics; | ||
|
|
||
| reader.BeginObject(); | ||
| while (reader.NextObjectItem(&key)) { | ||
| if (key == "calls") { | ||
| reader.BeginArray(); | ||
| while (reader.NextArrayItem()) { | ||
| calls.push_back(parse_metrics(&reader)); | ||
| } | ||
| // reader.EndArray(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should these commented out lines be removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like leaving these lines in as it makes it clear where the end of each Array/Object is. |
||
| } else if (key == "device_metrics") { | ||
| reader.BeginObject(); | ||
| std::string device_name; | ||
| while (reader.NextObjectItem(&device_name)) { | ||
| device_metrics.Set(device_name, parse_metrics(&reader)); | ||
| } | ||
| // reader.EndObject(); | ||
| } | ||
| } | ||
|
|
||
| return Report(calls, device_metrics); | ||
| } | ||
|
|
||
| TVM_REGISTER_OBJECT_TYPE(DurationNode); | ||
| TVM_REGISTER_OBJECT_TYPE(PercentNode); | ||
| TVM_REGISTER_OBJECT_TYPE(CountNode); | ||
|
|
@@ -551,6 +620,7 @@ TVM_REGISTER_GLOBAL("runtime.profiling.AsCSV").set_body_typed([](Report n) { ret | |
| TVM_REGISTER_GLOBAL("runtime.profiling.AsJSON").set_body_typed([](Report n) { | ||
| return n->AsJSON(); | ||
| }); | ||
| TVM_REGISTER_GLOBAL("runtime.profiling.FromJSON").set_body_typed(Report::FromJSON); | ||
| TVM_REGISTER_GLOBAL("runtime.profiling.DeviceWrapper").set_body_typed([](Device dev) { | ||
| return DeviceWrapper(dev); | ||
| }); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Checking device type using a
>=is kind of confusing. If there isn't a better way to check can you explain why the>=works in a comment.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.
done