You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ju...@apache.org on 2021/12/06 19:28:41 UTC

[tvm] branch bugfix/2021-12-06/no-dummy-target-creation created (now a2cf1ba)

This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a change to branch bugfix/2021-12-06/no-dummy-target-creation
in repository https://gitbox.apache.org/repos/asf/tvm.git.


      at a2cf1ba  [Target][TVMC][UX] Avoid creation of dummy Target objects in TVMC

This branch includes the following new commits:

     new a2cf1ba  [Target][TVMC][UX] Avoid creation of dummy Target objects in TVMC

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[tvm] 01/01: [Target][TVMC][UX] Avoid creation of dummy Target objects in TVMC

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a commit to branch bugfix/2021-12-06/no-dummy-target-creation
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit a2cf1baaef3f7398b9222a02ba04a6aa47abf43e
Author: Junru Shao <ju...@gmail.com>
AuthorDate: Mon Dec 6 11:28:10 2021 -0800

    [Target][TVMC][UX] Avoid creation of dummy Target objects in TVMC
---
 python/tvm/driver/tvmc/target.py | 26 ++++++++++++--------------
 python/tvm/target/target.py      |  5 +++++
 src/target/target_kind.cc        |  6 +++++-
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/python/tvm/driver/tvmc/target.py b/python/tvm/driver/tvmc/target.py
index a551293..067a361 100644
--- a/python/tvm/driver/tvmc/target.py
+++ b/python/tvm/driver/tvmc/target.py
@@ -19,7 +19,7 @@ This file contains functions for processing target inputs for the TVMC CLI
 """
 
 from tvm.driver import tvmc
-from tvm.target import Target
+from tvm.target import Target, TargetKind
 
 # We can't tell the type inside an Array but all current options are strings so
 # it can default to that. Bool is used alongside Integer but aren't distinguished
@@ -33,14 +33,14 @@ def _valid_target_kinds():
     return filter(lambda target: target not in codegen_names, Target.list_kinds())
 
 
-def _generate_target_kind_args(parser, kind):
-    target_group = parser.add_argument_group(f"target {kind.name}")
-    for target_option, target_type in kind.options.items():
+def _generate_target_kind_args(parser, kind_name):
+    target_group = parser.add_argument_group(f"target {kind_name}")
+    for target_option, target_type in TargetKind.options_from_name(kind_name).items():
         if target_type in INTERNAL_TO_NATIVE_TYPE:
             target_group.add_argument(
-                f"--target-{kind.name}-{target_option}",
+                f"--target-{kind_name}-{target_option}",
                 type=INTERNAL_TO_NATIVE_TYPE[target_type],
-                help=f"target {kind.name} {target_option}{INTERNAL_TO_HELP[target_type]}",
+                help=f"target {kind_name} {target_option}{INTERNAL_TO_HELP[target_type]}",
             )
 
 
@@ -52,15 +52,14 @@ def generate_target_args(parser):
         required=True,
     )
     for target_kind in _valid_target_kinds():
-        target = Target(target_kind)
-        _generate_target_kind_args(parser, target.kind)
+        _generate_target_kind_args(parser, target_kind)
 
 
-def _reconstruct_target_kind_args(args, kind):
+def _reconstruct_target_kind_args(args, kind_name):
     kind_options = {}
-    for target_option, target_type in kind.options.items():
+    for target_option, target_type in TargetKind.options_from_name(kind_name).items():
         if target_type in INTERNAL_TO_NATIVE_TYPE:
-            var_name = f"target_{kind.name.replace('-', '_')}_{target_option.replace('-', '_')}"
+            var_name = f"target_{kind_name.replace('-', '_')}_{target_option.replace('-', '_')}"
             option_value = getattr(args, var_name)
             if option_value is not None:
                 kind_options[target_option] = getattr(args, var_name)
@@ -71,8 +70,7 @@ def reconstruct_target_args(args):
     """Reconstructs the target options from the arguments"""
     reconstructed = {}
     for target_kind in _valid_target_kinds():
-        target = Target(target_kind)
-        kind_options = _reconstruct_target_kind_args(args, target.kind)
+        kind_options = _reconstruct_target_kind_args(args, target_kind)
         if kind_options:
-            reconstructed[target.kind.name] = kind_options
+            reconstructed[target_kind] = kind_options
     return reconstructed
diff --git a/python/tvm/target/target.py b/python/tvm/target/target.py
index e49791e..1c418e5 100644
--- a/python/tvm/target/target.py
+++ b/python/tvm/target/target.py
@@ -36,6 +36,11 @@ class TargetKind(Object):
         """Returns the dict of available option names and types"""
         return dict(_ffi_api.ListTargetKindOptions(self))
 
+    @staticmethod
+    def options_from_name(kind_name: str):
+        """Returns the dict of available option names and types from a name of TargetKind"""
+        return dict(_ffi_api.ListTargetKindOptionsFromName(kind_name))
+
 
 @tvm._ffi.register_object
 class Target(Object):
diff --git a/src/target/target_kind.cc b/src/target/target_kind.cc
index 5540c35..59efc8c 100644
--- a/src/target/target_kind.cc
+++ b/src/target/target_kind.cc
@@ -402,11 +402,15 @@ TVM_REGISTER_TARGET_KIND("hybrid", kDLCPU)  // line break
 
 TVM_REGISTER_TARGET_KIND("composite", kDLCPU).add_attr_option<Array<Target>>("devices");
 
-
 /**********  Registry  **********/
 
 TVM_REGISTER_GLOBAL("target.ListTargetKinds").set_body_typed(TargetKindRegEntry::ListTargetKinds);
 TVM_REGISTER_GLOBAL("target.ListTargetKindOptions")
     .set_body_typed(TargetKindRegEntry::ListTargetKindOptions);
+TVM_REGISTER_GLOBAL("target.ListTargetKindOptionsFromName")
+    .set_body_typed([](String target_kind_name) {
+      TargetKind kind = TargetKind::Get(target_kind_name).value();
+      return TargetKindRegEntry::ListTargetKindOptions(kind);
+    });
 
 }  // namespace tvm