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/01/06 01:09:39 UTC

[GitHub] [incubator-tvm] tqchen opened a new pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

tqchen opened a new pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627
 
 
   ir::Block was used to represent a sequence of Stmts in the original low-level IR.
   The nested ir::Block structure is not really friendly for recursive visits,
   especially when the statements are unrolled.
   
   This PR introduce a SeqStmt that directly stores a sequence of statements in an Array container.
   The new SeqStmt will be used as a replacement of the original Block structure.

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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627#discussion_r363150477
 
 

 ##########
 File path: include/tvm/ir.h
 ##########
 @@ -1022,25 +1022,102 @@ class Realize : public StmtNode {
 };
 
 /*!
- * \brief A sequence of statements.
+ * \brief The container of seq statement.
+ *        Represent a sequence of statements.
  */
-class Block : public StmtNode {
+class SeqStmtNode : public StmtNode {
  public:
-  /*! \brief The first statement. */
-  Stmt first;
-  /*! \brief The restof statments. */
-  Stmt rest;
+  /*! \brief internal sequence content. */
+  Array<Stmt> seq;
+
+  /*! \return get the size of the sequence */
+  size_t size() const {
+    return seq.size();
+  }
+  /*!
+   * \brief Get the index-th element in the sequence.
+   */
+  Stmt operator[](size_t index) const {
+    return seq[index];
+  }
 
   void VisitAttrs(AttrVisitor* v) {
-    v->Visit("first", &first);
-    v->Visit("rest", &rest);
+    v->Visit("seq", &seq);
   }
 
-  TVM_DLL static Stmt make(Stmt first, Stmt rest);
-  TVM_DLL static Stmt make(const std::vector<Stmt> &stmts);
+  static constexpr const char* _type_key = "SeqStmt";
+  TVM_DECLARE_FINAL_OBJECT_INFO(SeqStmtNode, StmtNode);
+};
+
+/*! \brief Sequence statement. */
+class SeqStmt : public Stmt {
+ public:
+  /*!
+   * \brief Construct SeqStmt.
+   * \param seq The sequence.
+   */
+  TVM_DLL explicit SeqStmt(Array<Stmt> seq);
+
+  /*! \return get the size of the sequence */
+  size_t size() const {
+    return operator->()->size();
+  }
+  /*!
+   * \brief Get the index-th element in the sequence.
+   */
+  Stmt operator[](size_t index) const {
+    return (*(operator->()))[index];
+  }
+  /*!
+   * \brief Construct a flattened sequence statement.
 
 Review comment:
   I added more comment

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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] yzhliu commented on a change in pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

Posted by GitBox <gi...@apache.org>.
yzhliu commented on a change in pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627#discussion_r363145229
 
 

 ##########
 File path: include/tvm/ir.h
 ##########
 @@ -1022,25 +1022,102 @@ class Realize : public StmtNode {
 };
 
 /*!
- * \brief A sequence of statements.
+ * \brief The container of seq statement.
+ *        Represent a sequence of statements.
  */
-class Block : public StmtNode {
+class SeqStmtNode : public StmtNode {
  public:
-  /*! \brief The first statement. */
-  Stmt first;
-  /*! \brief The restof statments. */
-  Stmt rest;
+  /*! \brief internal sequence content. */
+  Array<Stmt> seq;
+
+  /*! \return get the size of the sequence */
+  size_t size() const {
+    return seq.size();
+  }
+  /*!
+   * \brief Get the index-th element in the sequence.
+   */
+  Stmt operator[](size_t index) const {
+    return seq[index];
+  }
 
   void VisitAttrs(AttrVisitor* v) {
-    v->Visit("first", &first);
-    v->Visit("rest", &rest);
+    v->Visit("seq", &seq);
   }
 
-  TVM_DLL static Stmt make(Stmt first, Stmt rest);
-  TVM_DLL static Stmt make(const std::vector<Stmt> &stmts);
+  static constexpr const char* _type_key = "SeqStmt";
+  TVM_DECLARE_FINAL_OBJECT_INFO(SeqStmtNode, StmtNode);
+};
+
+/*! \brief Sequence statement. */
+class SeqStmt : public Stmt {
+ public:
+  /*!
+   * \brief Construct SeqStmt.
+   * \param seq The sequence.
+   */
+  TVM_DLL explicit SeqStmt(Array<Stmt> seq);
+
+  /*! \return get the size of the sequence */
+  size_t size() const {
+    return operator->()->size();
+  }
+  /*!
+   * \brief Get the index-th element in the sequence.
+   */
+  Stmt operator[](size_t index) const {
+    return (*(operator->()))[index];
+  }
+  /*!
+   * \brief Construct a flattened sequence statement.
 
 Review comment:
   more specifically, it is to flatten a consumer? can we elaborate a bit in the comment why this is useful?

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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627#issuecomment-571011349
 
 
   Thanks @yzhliu @Hzfengsy @ZihengJiang 

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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen merged pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627
 
 
   

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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627#issuecomment-570969214
 
 
   cc @icemelon9 @yzhliu @Hzfengsy 

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


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #4627: [REFACTOR][IR] Introduce SeqStmt to replace ir::Block
URL: https://github.com/apache/incubator-tvm/pull/4627#discussion_r363149644
 
 

 ##########
 File path: include/tvm/ir.h
 ##########
 @@ -1022,25 +1022,102 @@ class Realize : public StmtNode {
 };
 
 /*!
- * \brief A sequence of statements.
+ * \brief The container of seq statement.
+ *        Represent a sequence of statements.
  */
-class Block : public StmtNode {
+class SeqStmtNode : public StmtNode {
  public:
-  /*! \brief The first statement. */
-  Stmt first;
-  /*! \brief The restof statments. */
-  Stmt rest;
+  /*! \brief internal sequence content. */
+  Array<Stmt> seq;
+
+  /*! \return get the size of the sequence */
+  size_t size() const {
+    return seq.size();
+  }
+  /*!
+   * \brief Get the index-th element in the sequence.
+   */
+  Stmt operator[](size_t index) const {
+    return seq[index];
+  }
 
   void VisitAttrs(AttrVisitor* v) {
-    v->Visit("first", &first);
-    v->Visit("rest", &rest);
+    v->Visit("seq", &seq);
   }
 
-  TVM_DLL static Stmt make(Stmt first, Stmt rest);
-  TVM_DLL static Stmt make(const std::vector<Stmt> &stmts);
+  static constexpr const char* _type_key = "SeqStmt";
+  TVM_DECLARE_FINAL_OBJECT_INFO(SeqStmtNode, StmtNode);
+};
+
+/*! \brief Sequence statement. */
+class SeqStmt : public Stmt {
+ public:
+  /*!
+   * \brief Construct SeqStmt.
+   * \param seq The sequence.
+   */
+  TVM_DLL explicit SeqStmt(Array<Stmt> seq);
+
+  /*! \return get the size of the sequence */
+  size_t size() const {
+    return operator->()->size();
+  }
+  /*!
+   * \brief Get the index-th element in the sequence.
+   */
+  Stmt operator[](size_t index) const {
+    return (*(operator->()))[index];
+  }
+  /*!
+   * \brief Construct a flattened sequence statement.
 
 Review comment:
   The consumer tag was not as useful as producers and can in general be dropped. This was the original behavior that we used to had in Flattening sequences. Once we uprgade to the versions the Producer consumer markup may cease to be useful, so we can safely remove that part 

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


With regards,
Apache Git Services