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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]