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 2021/09/21 01:36:28 UTC

[GitHub] [tvm] junrushao1994 opened a new pull request #9059: [Meta Schedule][M3c] Argument Info

junrushao1994 opened a new pull request #9059:
URL: https://github.com/apache/tvm/pull/9059


   This PR is part of the meta schedule project (#8473) that adds metadata of each PrimFunc's argument. This feature is necessary for dynamic shape auto-tuning.
   
   @ZihengJiang @ArmageddonKnight @mbrookhart Would you guys help review this PR? Thanks a lot!
   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#discussion_r713560208



##########
File path: python/tvm/meta_schedule/arg_info.py
##########
@@ -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):

Review comment:
       Yes definitely! We can write a new subclass of ArgInfo for this :-)




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#issuecomment-925217443


   Thanks @mbrookhart :-)


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#discussion_r713641056



##########
File path: include/tvm/meta_schedule/arg_info.h
##########
@@ -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;

Review comment:
       This particular data structure is used in the tuning records where measurement is done, so the shape has been specialized




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#discussion_r713641287



##########
File path: include/tvm/meta_schedule/arg_info.h
##########
@@ -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;

Review comment:
       See #9061 




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 commented on a change in pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on a change in pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#discussion_r713641056



##########
File path: include/tvm/meta_schedule/arg_info.h
##########
@@ -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;

Review comment:
       This particular data structure is used in the tuning records where the shape has been specialized and the measurement is done




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] junrushao1994 merged pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
junrushao1994 merged pull request #9059:
URL: https://github.com/apache/tvm/pull/9059


   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mbrookhart commented on pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
mbrookhart commented on pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#issuecomment-925216501


   Running late to the party, but this looks good to me :D Thanks!


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] ZihengJiang commented on a change in pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
ZihengJiang commented on a change in pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#discussion_r713557792



##########
File path: python/tvm/meta_schedule/arg_info.py
##########
@@ -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):

Review comment:
       Should we support scalar argument?




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] jroesch commented on a change in pull request #9059: [Meta Schedule][M3c] Argument Info

Posted by GitBox <gi...@apache.org>.
jroesch commented on a change in pull request #9059:
URL: https://github.com/apache/tvm/pull/9059#discussion_r713639642



##########
File path: include/tvm/meta_schedule/arg_info.h
##########
@@ -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;

Review comment:
       Should this be a shape tuple? if these are ahead of time annotated there is no guarantee the shapes are static




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org