You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/06/19 16:45:09 UTC

[GitHub] [incubator-tvm] ANSHUMAN87 commented on a change in pull request #5838: [Target] Introduce Target Id Registry

ANSHUMAN87 commented on a change in pull request #5838:
URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442940997



##########
File path: tests/cpp/target_test.cc
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+#include <dmlc/logging.h>
+#include <gtest/gtest.h>
+#include <tvm/target/target_id.h>
+
+#include <cmath>
+#include <string>
+
+TVM_REGISTER_TARGET_ID("TestTargetId").set_attr<std::string>("Attr1", "Value1");

Review comment:
       We can have some tests for attr_option as well.

##########
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 <tvm/ir/expr.h>
+#include <tvm/ir/transform.h>
+#include <tvm/node/attr_registry_map.h>
+#include <tvm/runtime/container.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/support/with.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+namespace tvm {
+namespace detail {
+template <typename, typename, typename>
+struct ValueTypeInfoMaker;
+}
+
+template <typename>
+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<ValueTypeInfo> key;
+    std::unique_ptr<ValueTypeInfo> val;
+  };
+  /*! \brief A hash table that stores the type information of each attr of the target key */
+  std::unordered_map<std::string, ValueTypeInfo> key2vtype_;
+  /*! \brief Index used for internal lookup of attribute registry */
+  uint32_t index_;
+  template <typename, typename>
+  friend class AttrRegistry;
+  template <typename>
+  friend class AttrRegistryMapContainerMap;
+  friend class TargetIdRegEntry;
+  template <typename, typename, typename>
+  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 <typename ValueType>
+  static inline TargetIdAttrMap<ValueType> 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<TargetIdNode*>(data_.get()); }
+
+  TVM_DLL static const AttrRegistryMapContainerMap<TargetId>& GetAttrMapContainer(
+      const String& attr_name);
+  template <typename, typename>
+  friend class AttrRegistry;
+  friend class TargetIdRegEntry;
+};
+
+/*!
+ * \brief Map<TargetId, ValueType> used to store meta-information about TargetId
+ * \tparam ValueType The type of the value stored in map
+ */
+template <typename ValueType>
+class TargetIdAttrMap : public AttrRegistryMap<TargetId, ValueType> {
+ public:
+  using TParent = AttrRegistryMap<TargetId, ValueType>;
+  using TParent::count;
+  using TParent::get;
+  using TParent::operator[];
+  explicit TargetIdAttrMap(const AttrRegistryMapContainerMap<TargetId>& map) : TParent(map) {}
+};
+
+/*!
+ * \brief Helper structure to register TargetId
+ * \sa TVM_REGISTER_TARGET_ID
+ */
+class TargetIdRegEntry {

Review comment:
       Just a thought, may be we can keep the target registration in a separate source files?

##########
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 <tvm/ir/expr.h>
+#include <tvm/ir/transform.h>
+#include <tvm/node/attr_registry_map.h>
+#include <tvm/runtime/container.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/support/with.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+namespace tvm {
+namespace detail {
+template <typename, typename, typename>
+struct ValueTypeInfoMaker;
+}
+
+template <typename>
+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; }

Review comment:
       May be String ? I understand it is private, but hiding through such overloading becomes burden at later point to refactor :). 
   As i believe with @zhiics recent work on overloading, it can be easily used based on user need.

##########
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 <tvm/ir/expr.h>
+#include <tvm/ir/transform.h>
+#include <tvm/node/attr_registry_map.h>
+#include <tvm/runtime/container.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/support/with.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+namespace tvm {
+namespace detail {
+template <typename, typename, typename>
+struct ValueTypeInfoMaker;
+}
+
+template <typename>
+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<ValueTypeInfo> key;
+    std::unique_ptr<ValueTypeInfo> val;
+  };
+  /*! \brief A hash table that stores the type information of each attr of the target key */
+  std::unordered_map<std::string, ValueTypeInfo> key2vtype_;
+  /*! \brief Index used for internal lookup of attribute registry */
+  uint32_t index_;
+  template <typename, typename>
+  friend class AttrRegistry;
+  template <typename>
+  friend class AttrRegistryMapContainerMap;
+  friend class TargetIdRegEntry;
+  template <typename, typename, typename>
+  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 <typename ValueType>
+  static inline TargetIdAttrMap<ValueType> 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<TargetIdNode*>(data_.get()); }
+
+  TVM_DLL static const AttrRegistryMapContainerMap<TargetId>& GetAttrMapContainer(
+      const String& attr_name);
+  template <typename, typename>
+  friend class AttrRegistry;
+  friend class TargetIdRegEntry;
+};
+
+/*!
+ * \brief Map<TargetId, ValueType> used to store meta-information about TargetId
+ * \tparam ValueType The type of the value stored in map
+ */
+template <typename ValueType>
+class TargetIdAttrMap : public AttrRegistryMap<TargetId, ValueType> {
+ public:
+  using TParent = AttrRegistryMap<TargetId, ValueType>;
+  using TParent::count;
+  using TParent::get;
+  using TParent::operator[];
+  explicit TargetIdAttrMap(const AttrRegistryMapContainerMap<TargetId>& 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 <typename ValueType>
+  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 <typename ValueType>
+  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 am not sure! Should we follow this naming convention ?

##########
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 <tvm/ir/expr.h>
+#include <tvm/ir/transform.h>
+#include <tvm/node/attr_registry_map.h>
+#include <tvm/runtime/container.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/support/with.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+namespace tvm {
+namespace detail {
+template <typename, typename, typename>
+struct ValueTypeInfoMaker;
+}
+
+template <typename>
+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<ValueTypeInfo> key;
+    std::unique_ptr<ValueTypeInfo> val;
+  };
+  /*! \brief A hash table that stores the type information of each attr of the target key */
+  std::unordered_map<std::string, ValueTypeInfo> key2vtype_;
+  /*! \brief Index used for internal lookup of attribute registry */
+  uint32_t index_;
+  template <typename, typename>
+  friend class AttrRegistry;
+  template <typename>
+  friend class AttrRegistryMapContainerMap;
+  friend class TargetIdRegEntry;
+  template <typename, typename, typename>
+  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 <typename ValueType>
+  static inline TargetIdAttrMap<ValueType> 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<TargetIdNode*>(data_.get()); }
+
+  TVM_DLL static const AttrRegistryMapContainerMap<TargetId>& GetAttrMapContainer(
+      const String& attr_name);
+  template <typename, typename>
+  friend class AttrRegistry;
+  friend class TargetIdRegEntry;
+};
+
+/*!
+ * \brief Map<TargetId, ValueType> used to store meta-information about TargetId
+ * \tparam ValueType The type of the value stored in map
+ */
+template <typename ValueType>
+class TargetIdAttrMap : public AttrRegistryMap<TargetId, ValueType> {
+ public:
+  using TParent = AttrRegistryMap<TargetId, ValueType>;
+  using TParent::count;
+  using TParent::get;
+  using TParent::operator[];
+  explicit TargetIdAttrMap(const AttrRegistryMapContainerMap<TargetId>& 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 <typename ValueType>
+  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 <typename ValueType>
+  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_;
+  String name;
+
+  /*! \brief private constructor */
+  explicit TargetIdRegEntry(uint32_t reg_index) : id_(make_object<TargetIdNode>()) {
+    id_->index_ = reg_index;
+  }
+  /*!
+   * \brief update the attribute TargetIdAttrMap
+   * \param key The name of the attribute
+   * \param value The value to be set
+   * \param plevel The priority level
+   */
+  TVM_DLL void UpdateAttr(const String& key, TVMRetValue value, int plevel);

Review comment:
       Should be public?

##########
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 <tvm/ir/expr.h>
+#include <tvm/ir/transform.h>
+#include <tvm/node/attr_registry_map.h>
+#include <tvm/runtime/container.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/support/with.h>
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+namespace tvm {
+namespace detail {
+template <typename, typename, typename>
+struct ValueTypeInfoMaker;
+}
+
+template <typename>
+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<ValueTypeInfo> key;
+    std::unique_ptr<ValueTypeInfo> val;
+  };
+  /*! \brief A hash table that stores the type information of each attr of the target key */
+  std::unordered_map<std::string, ValueTypeInfo> key2vtype_;
+  /*! \brief Index used for internal lookup of attribute registry */
+  uint32_t index_;
+  template <typename, typename>
+  friend class AttrRegistry;
+  template <typename>
+  friend class AttrRegistryMapContainerMap;
+  friend class TargetIdRegEntry;
+  template <typename, typename, typename>
+  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 <typename ValueType>
+  static inline TargetIdAttrMap<ValueType> 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<TargetIdNode*>(data_.get()); }
+
+  TVM_DLL static const AttrRegistryMapContainerMap<TargetId>& GetAttrMapContainer(
+      const String& attr_name);
+  template <typename, typename>
+  friend class AttrRegistry;
+  friend class TargetIdRegEntry;
+};
+
+/*!
+ * \brief Map<TargetId, ValueType> used to store meta-information about TargetId
+ * \tparam ValueType The type of the value stored in map
+ */
+template <typename ValueType>
+class TargetIdAttrMap : public AttrRegistryMap<TargetId, ValueType> {
+ public:
+  using TParent = AttrRegistryMap<TargetId, ValueType>;
+  using TParent::count;
+  using TParent::get;
+  using TParent::operator[];
+  explicit TargetIdAttrMap(const AttrRegistryMapContainerMap<TargetId>& 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,

Review comment:
       May be "this set" -> "this attribute" ?

##########
File path: src/target/target_id.cc
##########
@@ -0,0 +1,51 @@
+/*
+ * 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 src/target/target_id.cc
+ * \brief Target id registry
+ */
+#include <tvm/target/target_id.h>
+
+#include "../node/attr_registry.h"
+
+namespace tvm {
+
+using TargetIdRegistry = AttrRegistry<TargetIdRegEntry, TargetId>;
+
+TVM_DLL TargetIdRegEntry& TargetIdRegEntry::RegisterOrGet(const String& name) {

Review comment:
       May be name -> target_id_name  ?




----------------------------------------------------------------
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