-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[MetaSchedule][M3b] Argument Info #9059
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| #ifndef TVM_META_SCHEDULE_ARG_INFO_H_ | ||
| #define TVM_META_SCHEDULE_ARG_INFO_H_ | ||
|
|
||
| #include <tvm/node/node.h> | ||
| #include <tvm/runtime/container/shape_tuple.h> | ||
| #include <tvm/tir/function.h> | ||
|
|
||
| namespace tvm { | ||
| namespace meta_schedule { | ||
|
|
||
| /*! \brief The argument information. */ | ||
| class ArgInfoNode : public runtime::Object { | ||
| public: | ||
| static constexpr const char* _type_key = "meta_schedule.ArgInfo"; | ||
| TVM_DECLARE_BASE_OBJECT_INFO(ArgInfoNode, runtime::Object); | ||
|
|
||
| public: | ||
| /*! \brief Default destructor. */ | ||
| virtual ~ArgInfoNode() = default; | ||
| /*! \brief Converts the ArgInfo to its corresponding JSON representation. */ | ||
| virtual ObjectRef AsJSON() const = 0; | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Managed reference to ArgInfoNode | ||
| * \sa ArgInfoNode | ||
| */ | ||
| class ArgInfo : public runtime::ObjectRef { | ||
| public: | ||
| /*! | ||
| * \brief Parse the argument information from a JSON object. | ||
| * \param json_obj The json object to parse. | ||
| * \return The argument information parsed. | ||
| */ | ||
| TVM_DLL static ArgInfo FromJSON(const ObjectRef& json_obj); | ||
| /*! | ||
| * \brief Extract a list of the argument information from PrimFunc. | ||
| * \param func The PrimFunc to get argument information from. | ||
| * \return An array of the argument information derived. | ||
| */ | ||
| TVM_DLL static Array<ArgInfo, void> FromPrimFunc(const tir::PrimFunc& func); | ||
|
|
||
| TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(ArgInfo, runtime::ObjectRef, ArgInfoNode); | ||
|
|
||
| protected: | ||
| ArgInfo() = default; | ||
| }; | ||
|
|
||
| /*! \brief The tensor argument information. */ | ||
| class TensorInfoNode : public ArgInfoNode { | ||
| public: | ||
| /*! \brief The data type of the tensor. */ | ||
| runtime::DataType dtype; | ||
| /*! \brief The shape of the tensor. */ | ||
| runtime::ShapeTuple shape; | ||
|
|
||
| void VisitAttrs(tvm::AttrVisitor* v) { | ||
| v->Visit("dtype", &dtype); | ||
| v->Visit("shape", &shape); | ||
| } | ||
|
|
||
| static constexpr const char* _type_key = "meta_schedule.TensorInfo"; | ||
| TVM_DECLARE_FINAL_OBJECT_INFO(TensorInfoNode, ArgInfoNode); | ||
|
|
||
| public: | ||
| ObjectRef AsJSON() const; | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Managed reference to TensorInfoNode | ||
| * \sa TensorInfoNode | ||
| */ | ||
| class TensorInfo : public ArgInfo { | ||
| public: | ||
| /*! | ||
| * \brief Constructor of TensorInfo. | ||
| * \param dtype The data type of the tensor argument. | ||
| * \param shape The shape tuple of the tensor argument. | ||
| */ | ||
| TVM_DLL explicit TensorInfo(runtime::DataType dtype, runtime::ShapeTuple shape); | ||
| /*! | ||
| * \brief Parse the argument information from a JSON object. | ||
| * \param json_obj The json object to parse. | ||
| * \return The argument information parsed. | ||
| */ | ||
| TVM_DLL static TensorInfo FromJSON(const ObjectRef& json_obj); | ||
| TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TensorInfo, ArgInfo, TensorInfoNode); | ||
| }; | ||
|
|
||
| } // namespace meta_schedule | ||
| } // namespace tvm | ||
|
|
||
| #endif // TVM_META_SCHEDULE_ARG_INFO_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
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,106 @@ | ||
| # 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. | ||
| """The argument information""" | ||
| from typing import Any, List, Union | ||
|
|
||
| from tvm._ffi import register_object | ||
| from tvm.runtime import DataType, Object, ShapeTuple | ||
| from tvm.tir import PrimFunc | ||
|
|
||
| from . import _ffi_api | ||
| from .utils import _json_de_tvm | ||
|
|
||
|
|
||
| @register_object("meta_schedule.ArgInfo") | ||
| class ArgInfo(Object): | ||
| """Argument information""" | ||
|
|
||
| def as_json(self) -> Any: | ||
| """Converts the ArgInfo to its corresponding JSON representation.""" | ||
| return _json_de_tvm(_ffi_api.ArgInfoAsJSON(self)) # type: ignore # pylint: disable=no-member | ||
|
|
||
| @staticmethod | ||
| def from_json(json_obj: Any) -> "ArgInfo": | ||
| """Parse the argument information from a JSON object. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| json_obj : Any | ||
| The json object to parse. | ||
|
|
||
| Returns | ||
| ------- | ||
| parsed : ArgInfo | ||
| The argument information parsed. | ||
| """ | ||
| return _ffi_api.ArgInfoFromJSON(json_obj) # type: ignore # pylint: disable=no-member | ||
|
|
||
| @staticmethod | ||
| def from_prim_func(func: PrimFunc) -> List["ArgInfo"]: | ||
| """Extract a list of the argument information from PrimFunc. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| func : PrimFunc | ||
| The PrimFunc to get argument information from. | ||
|
|
||
| Returns | ||
| ------- | ||
| extracted : List[ArgInfo] | ||
| An array of the argument information derived. | ||
| """ | ||
| return _ffi_api.ArgInfoFromPrimFunc(func) # type: ignore # pylint: disable=no-member | ||
|
|
||
|
|
||
| @register_object("meta_schedule.TensorInfo") | ||
| class TensorInfo(ArgInfo): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we support scalar argument?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes definitely! We can write a new subclass of ArgInfo for this :-) |
||
| """Tensor argument information | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dtype : DataType | ||
| The data type of the tensor. | ||
| shape : ShapeTuple | ||
| The shape of the tensor. | ||
| """ | ||
|
|
||
| dtype: DataType | ||
| shape: ShapeTuple | ||
|
|
||
| def __init__( | ||
| self, | ||
| dtype: DataType, | ||
| shape: Union[ShapeTuple, List[int]], | ||
| ) -> None: | ||
| """Constructor | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dtype : DataType | ||
| The data type of the tensor. | ||
| shape : ShapeTuple | ||
| The shape of the tensor. | ||
| """ | ||
| if isinstance(shape, ShapeTuple): | ||
| shape_tuple = shape | ||
| else: | ||
| shape_tuple = ShapeTuple(shape) | ||
| self.__init_handle_by_constructor__( | ||
| _ffi_api.TensorInfo, # type: ignore # pylint: disable=no-member | ||
| dtype, | ||
| shape_tuple, | ||
| ) | ||
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
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.