tvm
analyzer.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_ARITH_ANALYZER_H_
25 #define TVM_ARITH_ANALYZER_H_
26 
27 #include <tvm/arith/int_set.h>
28 #include <tvm/ffi/cast.h>
29 #include <tvm/ffi/reflection/registry.h>
30 #include <tvm/ffi/string.h>
31 #include <tvm/ir/expr.h>
32 #include <tvm/ir/with_context.h>
33 
34 #include <limits>
35 #include <memory>
36 #include <unordered_map>
37 #include <utility>
38 #include <vector>
39 
40 namespace tvm {
42 namespace arith {
43 //-------------------------------------------------------
44 // Base integer analysis API.
45 //
46 // We have multiple type of analyzers to do relaxed
47 // integer set analysis(bound analysis, modulo) and
48 // equivalence checking and simplification.
49 //
50 // Importantly, each analyzer may need result from
51 // another analyzer.
52 //-------------------------------------------------------
53 
54 // Forward declare the analyzer object and its reference handle.
55 class AnalyzerObj;
56 class Analyzer;
57 class ConstraintContext;
58 
59 using tirx::Var;
60 
61 enum DivMode {
65  kFloorDiv
66 };
67 
75 enum class ProofStrength : int {
77  kDefault = 0,
81  kSymbolicBound = 1,
82 };
83 
90 class ConstIntBoundNode : public ffi::Object {
91  public:
92  int64_t min_value;
93  int64_t max_value;
94 
95  static void RegisterReflection() {
96  namespace refl = tvm::ffi::reflection;
97  refl::ObjectDef<ConstIntBoundNode>()
98  .def_ro("min_value", &ConstIntBoundNode::min_value)
99  .def_ro("max_value", &ConstIntBoundNode::max_value);
100  }
101 
103  static const constexpr int64_t kPosInf = std::numeric_limits<int64_t>::max();
108  static const constexpr int64_t kNegInf = -kPosInf;
109 
110  static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
111  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("arith.ConstIntBound", ConstIntBoundNode, ffi::Object);
112 };
113 
118 class ConstIntBound : public ffi::ObjectRef {
119  public:
125  TVM_DLL ConstIntBound(int64_t min_value, int64_t max_value);
126 
127  static const constexpr int64_t kPosInf = ConstIntBoundNode::kPosInf;
128  static const constexpr int64_t kNegInf = ConstIntBoundNode::kNegInf;
130 };
131 
136  public:
137  using BoundMapType =
138  std::unordered_map<PrimExpr, ConstIntBound, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>;
144  TVM_DLL ConstIntBound operator()(const PrimExpr& expr) const;
145 
152  TVM_DLL ConstIntBound operator()(const PrimExpr& expr, BoundMapType* bound);
153 
161  TVM_DLL void Update(const Var& var, const ConstIntBound& info, bool allow_override = false);
162 
170  TVM_DLL void Bind(const Var& var, const Range& range, bool allow_override = false);
171 
177  TVM_DLL bool IsBound(const Var& var) const;
178 
179  private:
180  friend class AnalyzerObj;
181  friend class ConstraintContext;
182  explicit ConstIntBoundAnalyzer(AnalyzerObj* parent);
183  TVM_DLL ~ConstIntBoundAnalyzer();
184  void CopyFrom(const ConstIntBoundAnalyzer& other);
191  std::function<void()> EnterConstraint(const PrimExpr& constraint);
192  struct Entry;
193  class Impl;
195  Impl* impl_;
196 };
197 
210 class ModularSetNode : public ffi::Object {
211  public:
213  int64_t coeff;
215  int64_t base;
216 
217  static void RegisterReflection() {
218  namespace refl = tvm::ffi::reflection;
219  refl::ObjectDef<ModularSetNode>()
220  .def_ro("coeff", &ModularSetNode::coeff)
221  .def_ro("base", &ModularSetNode::base);
222  }
223 
224  static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
225  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("arith.ModularSet", ModularSetNode, ffi::Object);
226 };
227 
232 class ModularSet : public ffi::ObjectRef {
233  public:
234  TVM_DLL ModularSet(int64_t coeff, int64_t base);
235 
237 };
238 
243  public:
249  TVM_DLL ModularSet operator()(const PrimExpr& expr);
257  TVM_DLL void Update(const Var& var, const ModularSet& info, bool allow_override = false);
258 
259  private:
260  friend class AnalyzerObj;
261  friend class ConstraintContext;
262  explicit ModularSetAnalyzer(AnalyzerObj* parent);
263  TVM_DLL ~ModularSetAnalyzer();
264  void CopyFrom(const ModularSetAnalyzer& other);
271  std::function<void()> EnterConstraint(const PrimExpr& constraint);
272  struct Entry;
273  class Impl;
275  Impl* impl_;
276 };
277 
282  public:
288  TVM_DLL PrimExpr operator()(const PrimExpr& expr);
289 
297  TVM_DLL void Update(const Var& var, const PrimExpr& new_expr, bool allow_override = false);
298 
305  TVM_DLL std::function<void()> EnterConstraint(const PrimExpr& constraint);
306 
319  enum Extension {
320  // No extensions enabled
321  kNone = 0,
322 
323  /* When simplifying an inequality, attempt to use scope-based knowns.
324  *
325  * Example:
326  * if_then_else(i<j && j<k, i<k, false) => if_then_else(i<j && j<k, true, false)
327  */
329 
330  /* When simplifying a boolean expression, convert to an AND of ORs
331  * (conjunctive normal form).
332  *
333  * Example:
334  * (a && b) || c => (a || c) && (b || c)
335  */
337 
338  /* When simplifying a boolean AND or a boolean OR, simplify each
339  * branch under the assumption that the other branch does not
340  * already dominate the result. That is, simplify each branch of
341  * (A && B) under the assumption that the other branch is true,
342  * and simplify each branch of (A || B) under the assumption that
343  * the other branch is false.
344  *
345  * Example:
346  * (n < 10) && (n < 5) => (n < 10)
347  * (n < 10) || (n < 5) => (n < 5)
348  */
350 
351  /* Special handling for expressions `(A+B)*C < (A*B)*D`
352  *
353  * Expressions of the form `(A+B)*C < (A*B)*D` can occur occur
354  * when comparing the number of operations required for two
355  * different orderings in which matrix multiplications can be
356  * performed. Proving or disproving this conditional allows an
357  * optimal order of execution to be selected, even for dynamic
358  * argument shapes.
359  *
360  * The default behavior of `ConstIntBounds` assumes that each term
361  * in an expression is independent, and is insufficient to prove
362  * these inequalities. For example, the maximum value of `(A+B)*C
363  * - (A*B)*D` is determined by taking the maximum value of
364  * `(A+B)*C` and subtracting the minimum value of `(A*B)*D`.
365  * While this algorithm can be applied in all cases, the bound it
366  * provides is looser than strictly required.
367  *
368  * This extension adds a check for this case. When `A`, `B`, `C`,
369  * and `D` are all positive values, as is the case for tensor
370  * shapes, the inequality can be written as `1/A + 1/B < D/C`. If
371  * this inequality holds for the minimum values of `A`, `B`, and
372  * `D`, along with the maximum value of `C`, then the inequality
373  * holds for all values.
374  *
375  * This extension requires little to no performance overhead, and
376  * may be enabled by default in future releases.
377  */
379  };
380 
386  TVM_DLL void SetEnabledExtensions(Extension flags);
387 
390 
392  TVM_DLL ffi::ObjectRef GetStatsCounters() const;
393 
395  TVM_DLL void ResetStatsCounters();
396 
411  TVM_DLL void SetMaximumRewriteSteps(int64_t maximum);
412 
413  private:
414  friend class AnalyzerObj;
415  friend class ConstraintContext;
416  friend class CanonicalSimplifier;
417  explicit RewriteSimplifier(AnalyzerObj* parent);
418  TVM_DLL ~RewriteSimplifier();
419  void CopyFrom(const RewriteSimplifier& other);
420  class Impl;
422  Impl* impl_;
423 };
424 
429  public:
435  TVM_DLL PrimExpr operator()(const PrimExpr& expr);
436 
444  TVM_DLL void Update(const Var& var, const PrimExpr& new_expr, bool allow_override = false);
445 
446  private:
447  friend class AnalyzerObj;
448  friend class ConstraintContext;
449  explicit CanonicalSimplifier(AnalyzerObj* parent);
450  TVM_DLL ~CanonicalSimplifier();
451  void CopyFrom(const CanonicalSimplifier& other);
452  class Impl;
454  Impl* impl_;
455 };
456 
462 enum class CompareResult : int {
463  kInconsistent = 0,
464  kEQ = 1,
465  kLT = 2,
466  kLE = 3,
467  kGT = 4,
468  kGE = 5,
469  kNE = 6,
470  kUnknown = 7
471 };
472 
474  return CompareResult(static_cast<int>(lhs) & static_cast<int>(rhs));
475 }
477  return CompareResult(static_cast<int>(lhs) | static_cast<int>(rhs));
478 }
479 
487  public:
488  /* \brief Using previously specified knowns, compare the expressions provided
489  *
490  * \param lhs The left-hand side of the comparison
491  *
492  * \param rhs The right-hand side of the comparison
493  *
494  * \param propagate_inequalities If true, attempt to find a sequence
495  * of transitive inequalities that allow the lhs and rhs to be
496  * compared. If false, only use the known comparison that have been
497  * directly provided. Using `propagate_inequalities = false` is
498  * roughly equivalent to comparing against all known inequality
499  * expressions using `ExprDeepEqual`, but also allows for constant
500  * offsets on either side of the inequality.
501  *
502  * \return The most specific result that can be proven about the
503  * comparison. If nothing can be proven, returns kUnknown.
504  */
505  TVM_DLL CompareResult TryCompare(const PrimExpr& lhs, const PrimExpr& rhs,
506  bool propagate_inequalities = true);
507 
514  TVM_DLL void Bind(const Var& var, const PrimExpr& expr, bool allow_override = false);
515 
522  TVM_DLL void Bind(const Var& var, const Range& range, bool allow_override = false);
523 
530  TVM_DLL std::function<void()> EnterConstraint(const PrimExpr& constraint);
531 
532  private:
533  friend class AnalyzerObj;
534  friend class ConstraintContext;
536  TVM_DLL ~TransitiveComparisonAnalyzer();
537  void CopyFrom(const TransitiveComparisonAnalyzer& other);
538  class Impl;
540  std::unique_ptr<Impl> impl_;
541 };
542 
547  public:
556  TVM_DLL IntSet operator()(const PrimExpr& expr, const ffi::Map<Var, IntSet>& dom_map);
557 
566  TVM_DLL IntSet operator()(const PrimExpr& expr);
567 
575  TVM_DLL void Update(const Var& var, const IntSet& new_interval_set, bool allow_override = false);
576 
584  TVM_DLL void Bind(const Var& var, const Range& new_range, bool allow_override = false);
585 
586  std::function<void()> EnterConstraint(const PrimExpr& constraint);
587 
588  private:
589  friend class AnalyzerObj;
590  explicit IntSetAnalyzer(AnalyzerObj* parent);
591  TVM_DLL ~IntSetAnalyzer();
592  void CopyFrom(const IntSetAnalyzer& other);
593  class Impl;
595  Impl* impl_;
596 };
597 
598 class Z3Prover {
599  public:
607  TVM_DLL void Bind(const Var& var, const Range& new_range, bool allow_override = false);
608 
616  TVM_DLL void Bind(const Var& var, const PrimExpr& expr, bool allow_override = false);
617 
623  TVM_DLL bool IsEnabled() const;
624 
631  TVM_DLL bool CanProve(const PrimExpr& expr);
632 
639  std::function<void()> EnterConstraint(const PrimExpr& constraint);
640 
647  ffi::String GetSMTLIB2(const ffi::Optional<PrimExpr> expr);
648 
654  ffi::String GetStats();
655 
661  void SetTimeoutMs(unsigned timeout_ms);
662 
668  void SetRLimit(unsigned rlimit);
669 
676  ffi::String GetModel(const PrimExpr& expr);
677 
689  TVM_DLL int64_t CountSatisfyingValues(const Var& var, int64_t max_count = 2048,
690  int64_t min_consecutive = 1);
691 
692  private:
693  friend class AnalyzerObj;
694  friend class Analyzer;
695  explicit Z3Prover(AnalyzerObj* parent);
696  TVM_DLL ~Z3Prover();
697  void CopyFrom(const Z3Prover& other);
698  class Impl;
699  Impl* impl_;
700 };
701 
712 class TVM_DLL AnalyzerObj : public ffi::Object {
713  public:
749  void MarkGlobalNonNegValue(const PrimExpr& value);
762  void Bind(const Var& var, const PrimExpr& expr, bool allow_override = false);
775  void Bind(const Var& var, const Range& range, bool allow_override = false);
784  void Bind(const ffi::Map<Var, Range>& variables, bool allow_override = false);
797  bool CanProveGreaterEqual(const PrimExpr& expr, int64_t lower_bound);
810  bool CanProveLess(const PrimExpr& expr, int64_t upper_bound);
820  bool CanProveEqual(const PrimExpr& lhs, const PrimExpr& rhs);
851 
865  PrimExpr Simplify(const PrimExpr& expr, int steps = 2);
866 
885  Analyzer Clone() const;
886 
896  static constexpr bool _type_mutable = true;
897  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("arith.Analyzer", AnalyzerObj, ffi::Object);
898 };
899 
913 class Analyzer : public ffi::ObjectRef {
914  public:
916  Analyzer() : Analyzer(ffi::make_object<AnalyzerObj>()) {}
917  explicit Analyzer(ffi::ObjectPtr<AnalyzerObj> n) : ffi::ObjectRef(std::move(n)) {
918  TVM_FFI_ICHECK(this->get() != nullptr);
919  }
921 };
922 
940  private:
941  // declare friend to enable with.
942  friend class With<ConstraintContext>;
949  ConstraintContext(const Analyzer& analyzer, PrimExpr constraint)
950  : ConstraintContext(analyzer, std::move(constraint), false) {}
958  ConstraintContext(const Analyzer& analyzer, PrimExpr constraint, bool is_assume)
959  : analyzer_(analyzer), constraint_(std::move(constraint)), is_assume_(is_assume) {}
967  ConstraintContext(AnalyzerObj* analyzer, PrimExpr constraint)
968  : ConstraintContext(ffi::GetRef<Analyzer>(analyzer), std::move(constraint), false) {}
975  ConstraintContext(AnalyzerObj* analyzer, PrimExpr constraint, bool is_assume)
976  : ConstraintContext(ffi::GetRef<Analyzer>(analyzer), std::move(constraint), is_assume) {}
977  // enter the scope.
978  void EnterWithScope();
979  // exit the scope.
980  void ExitWithScope();
982  Analyzer analyzer_;
984  PrimExpr constraint_;
986  std::vector<std::function<void()>> recovery_functions_;
988  bool is_assume_;
989 };
990 
991 } // namespace arith
992 } // namespace tvm
993 #endif // TVM_ARITH_ANALYZER_H_
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition: base_expr.h:354
Range container
Definition: expr.h:484
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with_context.h:59
Analyzer that contains bunch of sub-analyzers.
Definition: analyzer.h:712
PrimExpr Simplify(const PrimExpr &expr, int steps=2)
Simplify expr.
bool CanProveGreaterEqual(const PrimExpr &expr, int64_t lower_bound)
Whether can we prove expr >= val.
bool CanProveLessEqualThanSymbolicShapeValue(const PrimExpr &lhs, const PrimExpr &shape)
Whether we can prove lhs is smaller than possibly symbolic shape.
Analyzer Clone() const
Deep-copy this analyzer into a new, independent Analyzer.
bool CanProveLess(const PrimExpr &expr, int64_t upper_bound)
Whether can we prove expr < val.
AnalyzerObj()
constructor
bool CanProve(const PrimExpr &cond, ProofStrength strength=ProofStrength::kDefault)
Whether can we prove condition.
ConstIntBoundAnalyzer const_int_bound
sub-analyzer: const integer bound
Definition: analyzer.h:715
Z3Prover z3_prover
sub-analyzer using Z3
Definition: analyzer.h:727
void Bind(const ffi::Map< Var, Range > &variables, bool allow_override=false)
Bind all the vars in the Map.
void Bind(const Var &var, const Range &range, bool allow_override=false)
Notify all the sub-analyzers that var is created and bound to a range.
void MarkGlobalNonNegValue(const PrimExpr &value)
Mark the value as non-negative value globally in analyzer.
RewriteSimplifier rewrite_simplify
sub-analyzer rewrite simplify
Definition: analyzer.h:719
IntSetAnalyzer int_set
sub-analyzer: int set
Definition: analyzer.h:723
void Bind(const Var &var, const PrimExpr &expr, bool allow_override=false)
Notify all the sub-analyzers that var is created and binded to expr.
TransitiveComparisonAnalyzer transitive_comparisons
sub-analyzer transitive comparisons
Definition: analyzer.h:725
bool CanProveEqual(const PrimExpr &lhs, const PrimExpr &rhs)
Whether can we prove lhs == rhs.
ModularSetAnalyzer modular_set
sub-analyzer: modular set
Definition: analyzer.h:717
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("arith.Analyzer", AnalyzerObj, ffi::Object)
CanonicalSimplifier canonical_simplify
sub-analyzer canonical simplify
Definition: analyzer.h:721
Managed reference to AnalyzerObj.
Definition: analyzer.h:913
Analyzer(ffi::ObjectPtr< AnalyzerObj > n)
Definition: analyzer.h:917
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Analyzer, ffi::ObjectRef, AnalyzerObj)
Analyzer()
Default-construct a fresh analyzer (allocates an AnalyzerObj).
Definition: analyzer.h:916
Canonical-form based simplifier.
Definition: analyzer.h:428
PrimExpr operator()(const PrimExpr &expr)
analyze the expr
void Update(const Var &var, const PrimExpr &new_expr, bool allow_override=false)
Update binding of var to a new expression.
Analyzer to get constant integer bound over expression.
Definition: analyzer.h:135
bool IsBound(const Var &var) const
Check if a variable is bound to a range.
void Update(const Var &var, const ConstIntBound &info, bool allow_override=false)
Update constant int bound information of var.
std::unordered_map< PrimExpr, ConstIntBound, ffi::ObjectPtrHash, ffi::ObjectPtrEqual > BoundMapType
Definition: analyzer.h:138
void Bind(const Var &var, const Range &range, bool allow_override=false)
Bind variable to a range.
ConstIntBound operator()(const PrimExpr &expr, BoundMapType *bound)
analyze the expr with the intermediate memorized to avoid redundant computation
ConstIntBound operator()(const PrimExpr &expr) const
analyze the expr
Constant integer up and lower bound(inclusive). Useful for value bound analysis.
Definition: analyzer.h:90
int64_t min_value
Definition: analyzer.h:92
static constexpr const int64_t kNegInf
Number to represent -inf.
Definition: analyzer.h:108
int64_t max_value
Definition: analyzer.h:93
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: analyzer.h:110
static constexpr const int64_t kPosInf
Number to represent +inf.
Definition: analyzer.h:103
static void RegisterReflection()
Definition: analyzer.h:95
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("arith.ConstIntBound", ConstIntBoundNode, ffi::Object)
reference class to ConstIntBoundNode
Definition: analyzer.h:118
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ConstIntBound, ffi::ObjectRef, ConstIntBoundNode)
static constexpr const int64_t kNegInf
Definition: analyzer.h:128
ConstIntBound(int64_t min_value, int64_t max_value)
constructor by fields.
static constexpr const int64_t kPosInf
Definition: analyzer.h:127
Constraint context.
Definition: analyzer.h:939
Integer set analyzer.
Definition: analyzer.h:546
std::function< void()> EnterConstraint(const PrimExpr &constraint)
void Update(const Var &var, const IntSet &new_interval_set, bool allow_override=false)
Update binding of var to a new expression.
void Bind(const Var &var, const Range &new_range, bool allow_override=false)
Update binding of var to a new expression.
IntSet operator()(const PrimExpr &expr, const ffi::Map< Var, IntSet > &dom_map)
Find a symbolic integer set that contains all possible values of expr given the domain of each variab...
IntSet operator()(const PrimExpr &expr)
Find a symbolic integer set that contains all possible values of expr given the domain of each variab...
Managed reference to IntSetNode.
Definition: int_set.h:67
Analyzer to get modular information over expression.
Definition: analyzer.h:242
void Update(const Var &var, const ModularSet &info, bool allow_override=false)
Update constant int bound information of var.
ModularSet operator()(const PrimExpr &expr)
analyze the expr
Range of a linear integer function. Use to do specify the possible index values.
Definition: analyzer.h:210
int64_t coeff
linear co-efficient
Definition: analyzer.h:213
static void RegisterReflection()
Definition: analyzer.h:217
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("arith.ModularSet", ModularSetNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: analyzer.h:224
int64_t base
The base.
Definition: analyzer.h:215
reference of ModularSetNode
Definition: analyzer.h:232
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ModularSet, ffi::ObjectRef, ModularSetNode)
ModularSet(int64_t coeff, int64_t base)
Rewrite-rule based simplifier.
Definition: analyzer.h:281
std::function< void()> EnterConstraint(const PrimExpr &constraint)
Update the internal state to enter constraint.
Extension GetEnabledExtensions() const
Return the currently enabled extensions.
ffi::ObjectRef GetStatsCounters() const
Return the statistics counters.
void SetEnabledExtensions(Extension flags)
Enable an optional extension or extensions.
void Update(const Var &var, const PrimExpr &new_expr, bool allow_override=false)
Update binding of var to a new expression.
Extension
Flags to enable more computationally-intensive simplifications.
Definition: analyzer.h:319
@ kNone
Definition: analyzer.h:321
@ kApplyConstraintsToBooleanBranches
Definition: analyzer.h:349
@ kTransitivelyProveInequalities
Definition: analyzer.h:328
@ kComparisonOfProductAndSum
Definition: analyzer.h:378
@ kConvertBooleanToAndOfOrs
Definition: analyzer.h:336
void SetMaximumRewriteSteps(int64_t maximum)
Set the maximum allowed number of rewrite steps.
void ResetStatsCounters()
Reset the statistics counters.
PrimExpr operator()(const PrimExpr &expr)
analyze the expr
Using previously specified knowns, compare the expressions provided.
Definition: analyzer.h:486
void Bind(const Var &var, const Range &range, bool allow_override=false)
Bind a variable as being within a specified range.
std::function< void()> EnterConstraint(const PrimExpr &constraint)
Update the internal state to enter constraint.
void Bind(const Var &var, const PrimExpr &expr, bool allow_override=false)
Bind a variable as being equal to a known expression.
CompareResult TryCompare(const PrimExpr &lhs, const PrimExpr &rhs, bool propagate_inequalities=true)
Definition: analyzer.h:598
ffi::String GetModel(const PrimExpr &expr)
Get the Z3 model for the given expression if satisfiable.
void SetTimeoutMs(unsigned timeout_ms)
Set timeout in milliseconds for Z3 prover.
void Bind(const Var &var, const Range &new_range, bool allow_override=false)
Update binding of var to a new expression.
bool CanProve(const PrimExpr &expr)
Whether can we prove expr is always true.
bool IsEnabled() const
Whether the Z3 backend is compiled into this build (USE_Z3=ON).
ffi::String GetStats()
Get statistics about Z3 prover.
int64_t CountSatisfyingValues(const Var &var, int64_t max_count=2048, int64_t min_consecutive=1)
Count the number of integer values that satisfy the current constraints.
ffi::String GetSMTLIB2(const ffi::Optional< PrimExpr > expr)
Get the SMTLIB2 representation of the current context.
void Bind(const Var &var, const PrimExpr &expr, bool allow_override=false)
Update binding of var to a new expression.
std::function< void()> EnterConstraint(const PrimExpr &constraint)
Update the internal state to enter constraint.
void SetRLimit(unsigned rlimit)
Set resource limitation for Z3 prover.
a named variable in TIR
Definition: var.h:68
Integer set.
Base expr nodes in TVM.
ProofStrength
The strength used in top-level condition proves.
Definition: analyzer.h:75
@ kSymbolicBound
Prove using symbolic bound analysis.
@ kDefault
default strength, can be used in.
CompareResult
Structure for representing result of known.
Definition: analyzer.h:462
constexpr CompareResult operator|(CompareResult lhs, CompareResult rhs)
Definition: analyzer.h:476
DivMode
Definition: analyzer.h:61
@ kTruncDiv
Truncated division.
Definition: analyzer.h:63
@ kFloorDiv
Floor division.
Definition: analyzer.h:65
@ kUnknown
Definition: int_set.h:51
constexpr CompareResult operator&(CompareResult lhs, CompareResult rhs)
Definition: analyzer.h:473
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
const Op & maximum()
Tensor shape(const Tensor &src, PrimType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:2010
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
PrimExpr max_value(PrimType dtype, Span span=Span())
PrimExpr min_value(PrimType dtype, Span span=Span())
RAII wrapper function to enter and exit a context object similar to python's with syntax.