junrushao1994 commented on a change in pull request #6369: URL: https://github.com/apache/incubator-tvm/pull/6369#discussion_r485277714
########## 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: Review comment: 1. In the doc, we describe "override" as "A boolean flag indicating if overriding existing tags are allowed." I will add the following sentences too: "If the flag is False, an exception will be throw when the tag has been added previously." 2. I agree that it is not necessary, but on C++ side, we are doing a target creation to verify the correctness of the given config dict. Although most of time the return value is discarded, let's just keep it returned in case it is useful somewhere. > It makes more sense for this function to accept a Target directly I had some thoughts about this too, after all it seems straightforward. However, I found it is better to use dict due to the following reasons 1. It mimics the JSON-like style used to describe Targets, without having to type Target creation code. 2. We intentionally do not store target in the tag registry, because it is possible that user can mutate the target forcefully with something like const cast. In that case, it just interferes with the Target stored in the registry, which is not desirable. That is the reason why we do target creation every time. ---------------------------------------------------------------- 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]
