tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] tqchen commented on a change in pull request #5367: Improve IntervalSet's floormod
Date Thu, 23 Apr 2020 22:18:41 GMT

tqchen commented on a change in pull request #5367:
URL: https://github.com/apache/incubator-tvm/pull/5367#discussion_r414159969



##########
File path: include/tvm/arith/int_set.h
##########
@@ -152,6 +152,22 @@ class IntSet : public ObjectRef {
 //-----------------------------------------------
 // Integer set legacy API.
 //------------------------------------------------
+    /*!
+     * \brief Convert std::unordered_map<const VarNode*, IntSet> to Map<Var, IntSet>
+     *
+     * \param dom_map The domain map to convert.
+     * \return The converted map.
+     */
+Map<Var, IntSet> ConvertDomMap(const std::unordered_map<const VarNode*, IntSet>&
dom_map);
+// /*!
+//  * \brief Find an symbolic integer set that contains all possible values of
+//  *  e given the domain of each iteration variables.
+//  *
+//  * \param e The expression to be evaluated.
+//  * \param dom_map The domain of each variable.
+//  * \return An integer set that can cover all the possible values of e.
+//  */
+// IntSet EvalSet(PrimExpr e, const Map<Var, IntSet>& dom_map);

Review comment:
       keep the commented region?

##########
File path: src/arith/int_set.cc
##########
@@ -311,6 +311,21 @@ inline IntervalSet Combine<tir::FloorModNode>(Analyzer* analyzer,
       LOG(FATAL) << "Modular by zero in CombineInterval Mod";
     }
     if (analyzer->CanProveGreaterEqual(divisor, 0)) {
+      if (const auto* ptr = b->min_value.as<tir::IntImmNode>()) {
+        // a mod b = a - b * (a/b) if
+        // (i) a_max - a_min < b, i.e. that before mod, a's range doesn't cover [0, b)
+        // and (ii) a_min mod b <= a_max mod b, i.e. that a's range is still continuous
after mod
+        auto tmax = a->max_value - b->min_value * floordiv(a->max_value, b->min_value);
+        tmax = analyzer->Simplify(tmax);
+        auto tmin = a->min_value - b->min_value * floordiv(a->min_value, b->min_value);
+        tmin = analyzer->Simplify(tmin);
+        auto tset = IntervalSet(tmin, tmax);
+        bool within_range = analyzer->CanProveLess(a->max_value - a->min_value,
ptr->value);
+        bool wrap_around = analyzer->CanProve(tset->max_value < tset->min_value);
+        if (within_range && !wrap_around) {
+          return tset;

Review comment:
       Consider move the tset construction after the within range check.

##########
File path: src/arith/int_set.cc
##########
@@ -311,6 +311,21 @@ inline IntervalSet Combine<tir::FloorModNode>(Analyzer* analyzer,
       LOG(FATAL) << "Modular by zero in CombineInterval Mod";
     }
     if (analyzer->CanProveGreaterEqual(divisor, 0)) {
+      if (const auto* ptr = b->min_value.as<tir::IntImmNode>()) {
+        // a mod b = a - b * (a/b) if
+        // (i) a_max - a_min < b, i.e. that before mod, a's range doesn't cover [0, b)
+        // and (ii) a_min mod b <= a_max mod b, i.e. that a's range is still continuous
after mod
+        auto tmax = a->max_value - b->min_value * floordiv(a->max_value, b->min_value);
+        tmax = analyzer->Simplify(tmax);
+        auto tmin = a->min_value - b->min_value * floordiv(a->min_value, b->min_value);
+        tmin = analyzer->Simplify(tmin);
+        auto tset = IntervalSet(tmin, tmax);
+        bool within_range = analyzer->CanProveLess(a->max_value - a->min_value,
ptr->value);
+        bool wrap_around = analyzer->CanProve(tset->max_value < tset->min_value);

Review comment:
       This can be dangerious, since CanProve returns true if it can be proven, but if it
is false, it does not mean that the condition won't hold. 




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



Mime
View raw message