From commits-return-15833-archive-asf-public=cust-asf.ponee.io@tvm.apache.org Fri Jun 19 18:09:01 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 2395E180647 for ; Fri, 19 Jun 2020 20:09:01 +0200 (CEST) Received: (qmail 36420 invoked by uid 500); 19 Jun 2020 18:09:00 -0000 Mailing-List: contact commits-help@tvm.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tvm.apache.org Delivered-To: mailing list commits@tvm.apache.org Received: (qmail 36409 invoked by uid 99); 19 Jun 2020 18:09:00 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jun 2020 18:09:00 +0000 From: =?utf-8?q?GitBox?= To: commits@tvm.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bincubator-tvm=5D_junrushao1994_commented_on_a_chan?= =?utf-8?q?ge_in_pull_request_=235838=3A_=5BTarget=5D_Introduce_Target_Id_Re?= =?utf-8?q?gistry?= Message-ID: <159259014041.8807.8464785858113426737.asfpy@gitbox.apache.org> Date: Fri, 19 Jun 2020 18:09:00 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-Reply-To: References: junrushao1994 commented on a change in pull request #5838: URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442980201 ########## File path: include/tvm/target/target_id.h ########## @@ -0,0 +1,298 @@ +/* + * 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. + */ + +/*! + * \file tvm/target/target_id.h + * \brief Target id registry + */ +#ifndef TVM_TARGET_TARGET_ID_H_ +#define TVM_TARGET_TARGET_ID_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace tvm { +namespace detail { +template +struct ValueTypeInfoMaker; +} + +template +class TargetIdAttrMap; + +/*! \brief Target Id, specifies the kind of the target */ +class TargetIdNode : public Object { + public: + /*! \brief Name of the target id */ + String name; + static constexpr const char* _type_key = "TargetId"; + TVM_DECLARE_FINAL_OBJECT_INFO(TargetIdNode, Object); + + private: + uint32_t AttrRegistryIndex() const { return index_; } + std::string AttrRegistryName() const { return name; } + /*! \brief Stores the required type_key and type_index of a specific attr of a target */ + struct ValueTypeInfo { + std::string type_key; + uint32_t type_index; + std::unique_ptr key; + std::unique_ptr val; + }; + /*! \brief A hash table that stores the type information of each attr of the target key */ + std::unordered_map key2vtype_; + /*! \brief Index used for internal lookup of attribute registry */ + uint32_t index_; + template + friend class AttrRegistry; + template + friend class AttrRegistryMapContainerMap; + friend class TargetIdRegEntry; + template + friend struct detail::ValueTypeInfoMaker; +}; + +/*! + * \brief Managed reference class to TargetIdNode + * \sa TargetIdNode + */ +class TargetId : public ObjectRef { + public: + /*! \brief Get the attribute map given the attribute name */ + template + static inline TargetIdAttrMap GetAttrMap(const String& attr_name); + /*! + * \brief Retrieve the TargetId given its name + * \param target_id_name Name of the target id + * \return The TargetId requested + */ + TVM_DLL static const TargetId& Get(const String& target_id_name); + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TargetId, ObjectRef, TargetIdNode); + + private: + /*! \brief Mutable access to the container class */ + TargetIdNode* operator->() { return static_cast(data_.get()); } + + TVM_DLL static const AttrRegistryMapContainerMap& GetAttrMapContainer( + const String& attr_name); + template + friend class AttrRegistry; + friend class TargetIdRegEntry; +}; + +/*! + * \brief Map used to store meta-information about TargetId + * \tparam ValueType The type of the value stored in map + */ +template +class TargetIdAttrMap : public AttrRegistryMap { + public: + using TParent = AttrRegistryMap; + using TParent::count; + using TParent::get; + using TParent::operator[]; + explicit TargetIdAttrMap(const AttrRegistryMapContainerMap& map) : TParent(map) {} +}; + +/*! + * \brief Helper structure to register TargetId + * \sa TVM_REGISTER_TARGET_ID + */ +class TargetIdRegEntry { + public: + /*! + * \brief Register additional attributes to target_id. + * \param attr_name The name of the attribute. + * \param value The value to be set. + * \param plevel The priority level of this set, + * an higher priority level attribute + * will replace lower priority level attribute. + * Must be bigger than 0. + * + * Cannot set with same plevel twice in the code. + * + * \tparam ValueType The type of the value to be set. + */ + template + inline TargetIdRegEntry& set_attr(const String& attr_name, const ValueType& value, + int plevel = 10); + /*! + * \brief Register a valid configuration option and its ValueType for validation + * \param key The configuration key + * \tparam ValueType The value type to be registered + */ + template + inline TargetIdRegEntry& add_attr_option(const std::string& key); + /*! \brief Set name of the TargetId to be the same as registry if it is empty */ + inline TargetIdRegEntry& set_name(); + /*! + * \brief Register or get a new entry. + * \param name The name of the TargetId. + * \return the corresponding entry. + */ + TVM_DLL static TargetIdRegEntry& RegisterOrGet(const String& name); + + private: + TargetId id_; Review comment: I agree with you. Maybe we should ask others opinion and change "name" => "name_" as well. Thank you! ---------------------------------------------------------------- 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: users@infra.apache.org