-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Target] Add target_parser to TargetKind #12119
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ class TargetInternal { | |
| static ObjectPtr<Object> FromString(const String& tag_or_config_or_target_str); | ||
| static ObjectPtr<Object> FromConfigString(const String& config_str); | ||
| static ObjectPtr<Object> FromRawString(const String& target_str); | ||
| static ObjectPtr<Object> FromConfig(std::unordered_map<String, ObjectRef> config); | ||
| static ObjectPtr<Object> FromConfig(Map<String, ObjectRef> config); | ||
| static void ConstructorDispatcher(TVMArgs args, TVMRetValue* rv); | ||
| static Target WithHost(const Target& target, const Target& target_host) { | ||
| ObjectPtr<TargetNode> n = make_object<TargetNode>(*target.get()); | ||
|
|
@@ -716,17 +716,27 @@ ObjectPtr<Object> TargetInternal::FromRawString(const String& target_str) { | |
| return TargetInternal::FromConfig(config); | ||
| } | ||
|
|
||
| ObjectPtr<Object> TargetInternal::FromConfig(std::unordered_map<String, ObjectRef> config) { | ||
| ObjectPtr<Object> TargetInternal::FromConfig(Map<String, ObjectRef> config) { | ||
| const String kKind = "kind"; | ||
| const String kTag = "tag"; | ||
| const String kKeys = "keys"; | ||
| const String kDeviceName = "device"; | ||
| const String kHost = "host"; | ||
| ObjectPtr<TargetNode> target = make_object<TargetNode>(); | ||
|
|
||
| // parse 'kind' | ||
| if (config.count(kKind)) { | ||
| if (const auto* kind = config[kKind].as<StringObj>()) { | ||
| target->kind = GetTargetKind(GetRef<String>(kind)); | ||
| ICHECK(!(target->kind->preprocessor != nullptr && target->kind->target_parser != nullptr)) | ||
| << "Cannot use both set_attrs_preprocessor and set_target_parser"; | ||
|
|
||
| // Run JSON Parser over JSON input | ||
| if (target->kind->target_parser != nullptr) { | ||
| VLOG(9) << "TargetInternal::FromConfig - Running target_parser"; | ||
| config = target->kind->target_parser(config); | ||
| } | ||
|
Comment on lines
+734
to
+738
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. Could this be executed at the end, so that the parser "has the last word" on what the returned target will look like?
Member
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. As the parser goes from |
||
|
|
||
| config.erase(kKind); | ||
| } else { | ||
| throw Error(": Expect type of field \"kind\" is String, but get type: " + | ||
|
|
@@ -828,8 +838,9 @@ ObjectPtr<Object> TargetInternal::FromConfig(std::unordered_map<String, ObjectRe | |
| } else { | ||
| target->attrs = attrs; | ||
| } | ||
|
|
||
| return target; | ||
| } | ||
| } // namespace tvm | ||
|
|
||
| std::unordered_map<String, ObjectRef> TargetInternal::QueryDevice(int device_id, | ||
| const TargetNode* target) { | ||
|
|
||
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.
Given that this takes
Map<>explicitly instead ofTargetJSON, are there any conditions that a config map must meet before it can be considered a target JSON?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.
@kparzysz-quic not that I know of, I made an internal assumption here that
configis another name for the JSON - maybe @areusch or @junrushao1994 knows more?