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/05/24 12:58:25 UTC

[GitHub] [tvm] tqchen commented on a change in pull request #8114: [TensorIR][M2a] Verification of cached flags

tqchen commented on a change in pull request #8114:
URL: https://github.com/apache/tvm/pull/8114#discussion_r637925954



##########
File path: src/arith/int_set.cc
##########
@@ -635,6 +636,83 @@ IntSet Union(const Array<IntSet>& sets) {
   return IntervalSet(ana.Simplify(x->min_value), ana.Simplify(x->max_value));
 }
 
+Array<IntSet> UnionRegion(const Array<Array<IntSet>>& nd_int_sets) {
+  if (nd_int_sets.empty()) {
+    return {};
+  }
+  int n = nd_int_sets.size();
+  int ndim = nd_int_sets[0].size();
+  Array<IntSet> result;
+  result.reserve(ndim);
+  for (int i = 0; i < ndim; ++i) {
+    Array<IntSet> candidates;
+    candidates.reserve(n);
+    for (int j = 0; j < n; ++j) {
+      candidates.push_back(nd_int_sets[j][i]);
+    }
+    result.push_back(Union(candidates));
+  }
+  return result;
+}
+
+IntSet UnionLowerBound(const Array<IntSet>& sets) {
+  if (sets.size() == 0) return IntSet::Nothing();
+  if (sets.size() == 1) return sets[0];
+  Analyzer analyzer;
+  bool is_first_interval = true;
+  PrimExpr min_inclusive{nullptr};
+  PrimExpr max_exclusive(nullptr);
+  for (const IntSet& int_set : sets) {
+    if (const auto* interval_set = int_set.as<IntervalSetNode>()) {
+      PrimExpr new_min_inclusive = interval_set->min_value;
+      PrimExpr new_max_exclusive = interval_set->max_value;
+      if (!is_pos_inf(new_max_exclusive) && !is_neg_inf(new_max_exclusive)) {
+        new_max_exclusive = new_max_exclusive + 1;
+      }
+      if (is_first_interval) {
+        is_first_interval = false;
+        min_inclusive = std::move(new_min_inclusive);
+        max_exclusive = std::move(new_max_exclusive);
+        continue;
+      }
+      bool bound_1 = is_neg_inf(new_min_inclusive) || is_pos_inf(max_exclusive) ||
+                     analyzer.CanProve(new_min_inclusive <= max_exclusive);
+      bool bound_2 = is_neg_inf(min_inclusive) || is_pos_inf(new_max_exclusive) ||
+                     analyzer.CanProve(min_inclusive <= new_max_exclusive);
+      if (bound_1 && bound_2) {
+        min_inclusive = min(min_inclusive, new_min_inclusive);
+        max_exclusive = max(max_exclusive, new_max_exclusive);
+      }
+    }
+  }
+  if (is_first_interval) {
+    return IntSet::Nothing();
+  }
+  if (!is_neg_inf(max_exclusive) && !is_pos_inf(max_exclusive)) {
+    max_exclusive = max_exclusive - 1;

Review comment:
       consider two separate returns, `return IntSet::Interval(min_inclusive, max_exclusive-1);`




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