-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Target] Target Tags, Composite Target and Unified Interface #6369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tqchen
merged 1 commit into
apache:master
from
junrushao:feature/2020-08-31/unified-target-creation
Sep 10, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * 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/tag.h | ||
| * \brief Target tag registry | ||
| */ | ||
| #ifndef TVM_TARGET_TAG_H_ | ||
| #define TVM_TARGET_TAG_H_ | ||
|
|
||
| #include <tvm/node/attr_registry_map.h> | ||
| #include <tvm/node/node.h> | ||
| #include <tvm/target/target.h> | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace tvm { | ||
|
|
||
| /*! \brief A target tag */ | ||
| class TargetTagNode : public Object { | ||
| public: | ||
| /*! \brief Name of the target */ | ||
| String name; | ||
| /*! \brief Config map to generate the target */ | ||
| Map<String, ObjectRef> config; | ||
|
|
||
| void VisitAttrs(AttrVisitor* v) { | ||
| v->Visit("name", &name); | ||
| v->Visit("config", &config); | ||
| } | ||
|
|
||
| static constexpr const char* _type_key = "TargetTag"; | ||
| TVM_DECLARE_FINAL_OBJECT_INFO(TargetTagNode, Object); | ||
|
|
||
| private: | ||
| /*! \brief Return the index stored in attr registry */ | ||
| uint32_t AttrRegistryIndex() const { return index_; } | ||
| /*! \brief Return the name stored in attr registry */ | ||
| String AttrRegistryName() const { return name; } | ||
| /*! \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 TargetTagRegEntry; | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Managed reference class to TargetTagNode | ||
| * \sa TargetTagNode | ||
| */ | ||
| class TargetTag : public ObjectRef { | ||
| public: | ||
| /*! | ||
| * \brief Retrieve the Target given it the name of target tag | ||
| * \param target_tag_name Name of the target tag | ||
| * \return The Target requested | ||
| */ | ||
| TVM_DLL static Optional<Target> Get(const String& target_tag_name); | ||
| /*! | ||
| * \brief List all names of the existing target tags | ||
| * \return A dictionary that maps tag name to the concrete target it corresponds to | ||
| */ | ||
| TVM_DLL static Map<String, Target> ListTags(); | ||
| /*! | ||
| * \brief Add a tag into the registry | ||
| * \param name Name of the tag | ||
| * \param config The target config corresponding to the tag | ||
| * \param override Allow overriding existing tags | ||
| * \return Target created with the tag | ||
| */ | ||
| TVM_DLL static Target AddTag(String name, Map<String, ObjectRef> config, bool override); | ||
|
|
||
| TVM_DEFINE_OBJECT_REF_METHODS(TargetTag, ObjectRef, TargetTagNode); | ||
|
|
||
| private: | ||
| /*! \brief Mutable access to the container class */ | ||
| TargetTagNode* operator->() { return static_cast<TargetTagNode*>(data_.get()); } | ||
| friend class TargetTagRegEntry; | ||
| }; | ||
|
|
||
| class TargetTagRegEntry { | ||
| public: | ||
| /*! | ||
| * \brief Set the config dict corresponding to the target tag | ||
| * \param config The config dict for target creation | ||
| */ | ||
| inline TargetTagRegEntry& set_config(Map<String, ObjectRef> config); | ||
| /*! \brief Set name of the TargetTag to be the same as registry if it is empty */ | ||
| inline TargetTagRegEntry& set_name(); | ||
| /*! | ||
| * \brief Register or get a new entry. | ||
| * \param target_tag_name The name of the TargetTag. | ||
| * \return the corresponding entry. | ||
| */ | ||
| TVM_DLL static TargetTagRegEntry& RegisterOrGet(const String& target_tag_name); | ||
|
|
||
| private: | ||
| TargetTag tag_; | ||
| String name; | ||
junrushao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /*! \brief private constructor */ | ||
| explicit TargetTagRegEntry(uint32_t reg_index) : tag_(make_object<TargetTagNode>()) { | ||
| tag_->index_ = reg_index; | ||
| } | ||
| template <typename, typename> | ||
| friend class AttrRegistry; | ||
| friend class TargetTag; | ||
| }; | ||
|
|
||
| inline TargetTagRegEntry& TargetTagRegEntry::set_config(Map<String, ObjectRef> config) { | ||
| tag_->config = std::move(config); | ||
| return *this; | ||
| } | ||
|
|
||
| inline TargetTagRegEntry& TargetTagRegEntry::set_name() { | ||
| if (tag_->name.empty()) { | ||
| tag_->name = name; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| #define TVM_TARGET_TAG_REGISTER_VAR_DEF \ | ||
| static DMLC_ATTRIBUTE_UNUSED ::tvm::TargetTagRegEntry& __make_##TargetTag | ||
|
|
||
| /*! | ||
| * \def TVM_REGISTER_TARGET_TAG | ||
| * \brief Register a new target tag, or set attribute of the corresponding target tag. | ||
| * \param TargetTagName The name of target tag | ||
| */ | ||
| #define TVM_REGISTER_TARGET_TAG(TargetTagName) \ | ||
| TVM_STR_CONCAT(TVM_TARGET_TAG_REGISTER_VAR_DEF, __COUNTER__) = \ | ||
| ::tvm::TargetTagRegEntry::RegisterOrGet(TargetTagName).set_name() | ||
|
|
||
| } // namespace tvm | ||
|
|
||
| #endif // TVM_TARGET_TAG_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.