You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "MasterJH5574 (via GitHub)" <gi...@apache.org> on 2023/04/05 14:13:42 UTC

[GitHub] [tvm] MasterJH5574 opened a new pull request, #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

MasterJH5574 opened a new pull request, #14509:
URL: https://github.com/apache/tvm/pull/14509

   This PR adds an analysis function which helps to fetch all the TIR variables that appear in a given struct info object. This is helpful for passes that need to be aware of symbolic shape dynamism.


-- 
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] tqchen commented on a diff in pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #14509:
URL: https://github.com/apache/tvm/pull/14509#discussion_r1158594508


##########
include/tvm/relax/analysis.h:
##########
@@ -260,6 +260,14 @@ TVM_DLL bool IsBaseOf(const StructInfo& base, const StructInfo& derived,
 TVM_DLL StructInfo StructInfoLCA(const StructInfo& lhs, const StructInfo& rhs,
                                  arith::Analyzer* ana = nullptr);
 
+/*!
+ * \brief Get the symbolic TIR variables that appear in the input struct info.
+ * The returned list is deduplicated - each TIR variable will appear at most once.
+ * \param sinfo The struct info object to be analyzed.
+ * \return The list of TIR variables that appear in the input struct info.
+ */
+TVM_DLL Array<tir::Var> SymVarInStructInfo(const StructInfo& sinfo);

Review Comment:
   TIRVarInStructInfo , so we don't need to learn a new terminology



-- 
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] tvm-bot commented on pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14509:
URL: https://github.com/apache/tvm/pull/14509#issuecomment-1497563529

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-ccs-start-->
    * cc @quic-sanirudh <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


-- 
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] MasterJH5574 commented on a diff in pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 commented on code in PR #14509:
URL: https://github.com/apache/tvm/pull/14509#discussion_r1158641797


##########
python/tvm/relax/analysis/analysis.py:
##########
@@ -167,6 +167,23 @@ def struct_info_lca(lhs: StructInfo, rhs: StructInfo) -> StructInfo:
     return _ffi_api.StructInfoLCA(lhs, rhs)  # type: ignore
 
 
+def tir_var_in_struct_info(sinfo: StructInfo) -> List[tir.Var]:

Review Comment:
   Okay updated.



-- 
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] MasterJH5574 commented on pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 commented on PR #14509:
URL: https://github.com/apache/tvm/pull/14509#issuecomment-1497709150

   @yongwww Thanks for catching. Updated.


-- 
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] MasterJH5574 commented on a diff in pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 commented on code in PR #14509:
URL: https://github.com/apache/tvm/pull/14509#discussion_r1158598202


##########
include/tvm/relax/analysis.h:
##########
@@ -260,6 +260,14 @@ TVM_DLL bool IsBaseOf(const StructInfo& base, const StructInfo& derived,
 TVM_DLL StructInfo StructInfoLCA(const StructInfo& lhs, const StructInfo& rhs,
                                  arith::Analyzer* ana = nullptr);
 
+/*!
+ * \brief Get the symbolic TIR variables that appear in the input struct info.
+ * The returned list is deduplicated - each TIR variable will appear at most once.
+ * \param sinfo The struct info object to be analyzed.
+ * \return The list of TIR variables that appear in the input struct info.
+ */
+TVM_DLL Array<tir::Var> SymVarInStructInfo(const StructInfo& sinfo);

Review Comment:
   Updated.



-- 
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] tvm-bot commented on pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14509:
URL: https://github.com/apache/tvm/pull/14509#issuecomment-1497563549

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-ccs-start-->
    * cc @quic-sanirudh <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


-- 
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] tqchen commented on a diff in pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #14509:
URL: https://github.com/apache/tvm/pull/14509#discussion_r1158632398


##########
python/tvm/relax/analysis/analysis.py:
##########
@@ -167,6 +167,23 @@ def struct_info_lca(lhs: StructInfo, rhs: StructInfo) -> StructInfo:
     return _ffi_api.StructInfoLCA(lhs, rhs)  # type: ignore
 
 
+def tir_var_in_struct_info(sinfo: StructInfo) -> List[tir.Var]:

Review Comment:
   nit: tir_vars



-- 
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] yongwww commented on a diff in pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on code in PR #14509:
URL: https://github.com/apache/tvm/pull/14509#discussion_r1158674574


##########
src/relax/analysis/struct_info_analysis.cc:
##########
@@ -861,5 +862,47 @@ TVM_REGISTER_GLOBAL("relax.analysis.StructInfoLCA")
       return StructInfoLCA(lhs, rhs);
     });
 
+//--------------------------
+// TIRVarsInStructInfo
+//--------------------------
+
+Array<tir::Var> TIRVarsInStructInfo(const StructInfo& sinfo) {
+  struct SymVarDetector : public StructInfoVisitor {
+    void VisitShape(Array<PrimExpr> shape) {
+      for (const PrimExpr& value : shape) {
+        Array<tir::Var> vars = tir::UndefinedVars(value);
+        for (const tir::Var& var : vars) {
+          auto insert_res = sym_var_dedup_set.insert(var.get());
+          if (insert_res.second) {
+            sym_vars.push_back(var);
+          }
+        }
+      }
+    }
+
+    void VisitStructInfo_(const ShapeStructInfoNode* shape_sinfo) final {
+      if (shape_sinfo->values.defined()) {
+        VisitShape(shape_sinfo->values.value());
+      }
+    }
+
+    void VisitStructInfo_(const TensorStructInfoNode* tensor_sinfo) final {
+      if (tensor_sinfo->shape.defined()) {
+        VisitStructInfo(GetStructInfo(tensor_sinfo->shape.value()));
+      }
+    }
+
+    Array<tir::Var> sym_vars;
+    std::unordered_set<const tir::VarNode*> sym_var_dedup_set;

Review Comment:
   tir_var_dedup_set



##########
src/relax/analysis/struct_info_analysis.cc:
##########
@@ -861,5 +862,47 @@ TVM_REGISTER_GLOBAL("relax.analysis.StructInfoLCA")
       return StructInfoLCA(lhs, rhs);
     });
 
+//--------------------------
+// TIRVarsInStructInfo
+//--------------------------
+
+Array<tir::Var> TIRVarsInStructInfo(const StructInfo& sinfo) {
+  struct SymVarDetector : public StructInfoVisitor {
+    void VisitShape(Array<PrimExpr> shape) {
+      for (const PrimExpr& value : shape) {
+        Array<tir::Var> vars = tir::UndefinedVars(value);
+        for (const tir::Var& var : vars) {
+          auto insert_res = sym_var_dedup_set.insert(var.get());
+          if (insert_res.second) {
+            sym_vars.push_back(var);
+          }
+        }
+      }
+    }
+
+    void VisitStructInfo_(const ShapeStructInfoNode* shape_sinfo) final {
+      if (shape_sinfo->values.defined()) {
+        VisitShape(shape_sinfo->values.value());
+      }
+    }
+
+    void VisitStructInfo_(const TensorStructInfoNode* tensor_sinfo) final {
+      if (tensor_sinfo->shape.defined()) {
+        VisitStructInfo(GetStructInfo(tensor_sinfo->shape.value()));
+      }
+    }
+
+    Array<tir::Var> sym_vars;

Review Comment:
   tir_vars



##########
src/relax/analysis/struct_info_analysis.cc:
##########
@@ -861,5 +862,47 @@ TVM_REGISTER_GLOBAL("relax.analysis.StructInfoLCA")
       return StructInfoLCA(lhs, rhs);
     });
 
+//--------------------------
+// TIRVarsInStructInfo
+//--------------------------
+
+Array<tir::Var> TIRVarsInStructInfo(const StructInfo& sinfo) {
+  struct SymVarDetector : public StructInfoVisitor {
+    void VisitShape(Array<PrimExpr> shape) {
+      for (const PrimExpr& value : shape) {
+        Array<tir::Var> vars = tir::UndefinedVars(value);
+        for (const tir::Var& var : vars) {
+          auto insert_res = sym_var_dedup_set.insert(var.get());
+          if (insert_res.second) {
+            sym_vars.push_back(var);
+          }
+        }
+      }
+    }
+
+    void VisitStructInfo_(const ShapeStructInfoNode* shape_sinfo) final {
+      if (shape_sinfo->values.defined()) {
+        VisitShape(shape_sinfo->values.value());
+      }
+    }
+
+    void VisitStructInfo_(const TensorStructInfoNode* tensor_sinfo) final {
+      if (tensor_sinfo->shape.defined()) {
+        VisitStructInfo(GetStructInfo(tensor_sinfo->shape.value()));
+      }
+    }
+
+    Array<tir::Var> sym_vars;
+    std::unordered_set<const tir::VarNode*> sym_var_dedup_set;
+  };
+
+  SymVarDetector detector;
+  detector(sinfo);
+  return detector.sym_vars;

Review Comment:
   tir_vars



-- 
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] yongwww commented on a diff in pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on code in PR #14509:
URL: https://github.com/apache/tvm/pull/14509#discussion_r1158673213


##########
src/relax/analysis/struct_info_analysis.cc:
##########
@@ -861,5 +862,47 @@ TVM_REGISTER_GLOBAL("relax.analysis.StructInfoLCA")
       return StructInfoLCA(lhs, rhs);
     });
 
+//--------------------------
+// TIRVarsInStructInfo
+//--------------------------
+
+Array<tir::Var> TIRVarsInStructInfo(const StructInfo& sinfo) {
+  struct SymVarDetector : public StructInfoVisitor {

Review Comment:
   -> TIRVar then



-- 
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] tqchen merged pull request #14509: [Unity][Analysis] Get symbolic TIR vars from struct info

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #14509:
URL: https://github.com/apache/tvm/pull/14509


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