junrushao1994 commented on a change in pull request #6369:
URL: https://github.com/apache/incubator-tvm/pull/6369#discussion_r485278032



##########
File path: python/tvm/target/tag.py
##########
@@ -0,0 +1,70 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Target tags"""
+from typing import Any, Dict
+from . import _ffi_api
+from .target import Target
+
+
+def list_tags() -> Dict[str, Target]:
+    """Returns a dict of tags, which maps each tag name to its corresponding 
target.
+
+    Returns
+    -------
+    tag_dict : Dict[str, Target]
+        The dict of tags mapping each tag name to to its corresponding target
+    """
+    return _ffi_api.TargetTagListTags()
+
+
+def register_tag(name: str, config: Dict[str, Any], override: bool = False) -> 
Target:
+    """Add a user-defined tag into the target tag registry.
+
+    Parameters
+    ----------
+    name: str
+        Name of the target, e.g. "nvidia/gtx1080ti"
+    config : Dict[str, Any]
+        The config dict used to create the target
+    override: bool
+        A boolean flag indicating if overriding existing tags are allowed
+
+    Returns
+    -------
+    target : Target
+        The target corresponding to the tag
+
+    Examples
+    --------
+    .. code-block:: python
+
+        register_tag("nvidia/gtx1080ti", config={
+            "kind": "cuda",
+            "arch": "sm_61",
+        })
+    """
+    return _ffi_api.TargetTagAddTag(name, config, override)
+
+
+# We do a round of tag listing on loading time to verify all tag information
+if hasattr(_ffi_api, "TargetTagAddTag"):
+    list_tags()
+
+    register_tag("nvidia/gtx1080ti", config={
+        "kind": "cuda",
+        "arch": "sm_61",
+    })

Review comment:
       If TVM is built with runtime-only mode., the global function 
"TargetTagAddTag" will not exist, so we guard it with the if conditional. I 
just moved the if into functions to make it loop better.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to