tvm
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions
tvm::sym Namespace Reference

namespace of symbolic analysis. More...

Namespaces

namespace  detail
 

Classes

class  AllowUIntAsIndex
 Scoped no-overflow assumption for unsigned index arithmetic. More...
 
class  Analyzer
 Managed reference to AnalyzerObj. More...
 
class  AnalyzerObj
 Coordinated symbolic analyses over an explicitly synchronized premise environment. More...
 
class  BindingConstraint
 Managed reference to BindingConstraintObj. More...
 
class  BindingConstraintObj
 The value captured when a variable is bound. A mutable-read RHS is retained as data; it must not be re-evaluated or treated as an enduring equality by a consumer. More...
 
class  CanonicalSimplifier
 Canonical-form based simplifier. More...
 
class  ConstIntBound
 Managed reference to ConstIntBoundObj. More...
 
class  ConstIntBoundAnalyzer
 Analyzer to get constant integer bound over expression. More...
 
class  ConstIntBoundObj
 Inclusive constant integer bounds, representing [min_value, max_value]. More...
 
class  Constraint
 A binding, range, or predicate, without inference or normalization. More...
 
class  ConstraintContext
 Managed reference to ConstraintContextObj. Copies share the same context. More...
 
class  ConstraintContextObj
 Tracks the constraints relevant to each point in a traversal. More...
 
class  ConstraintObj
 Base node for a symbolic premise; it owns no analyzer state. More...
 
class  IntSet
 Managed reference to IntSetObj. More...
 
class  IntSetAnalyzer
 Integer set analyzer. More...
 
class  IntSetObj
 Base class of all Integer set containers. represent a set of integers in one dimension. More...
 
class  IterMapExpr
 Managed reference to IterMapExprObj. More...
 
class  IterMapExprObj
 Base class of all iter map expressions. More...
 
class  IterMapResult
 Managed reference to IterMapResultObj. More...
 
class  IterMapResultObj
 Result of DetectIterMap. More...
 
class  IterMark
 Managed reference to IterMarkObj. More...
 
class  IterMarkObj
 Mark the source as an iterator in [0, extent). More...
 
class  IterSplitExpr
 Managed reference to IterSplitExprObj. More...
 
class  IterSplitExprObj
 Split of an iterator. More...
 
class  IterSumExpr
 Managed reference to IterSumExprObj. More...
 
class  IterSumExprObj
 Fuse multiple iterators by summing them with scaling. More...
 
class  ModularSet
 Managed reference to ModularSetObj. More...
 
class  ModularSetAnalyzer
 Analyzer to get modular information over expression. More...
 
class  ModularSetObj
 Integer congruence class {coeff * x + base | x in Z}. More...
 
class  PredicateConstraint
 Managed reference to PredicateConstraintObj. More...
 
class  PredicateConstraintObj
 A boolean premise. Its validity and lifetime are supplied by the collector. More...
 
class  RangeConstraint
 Managed reference to RangeConstraintObj. More...
 
class  RangeConstraintObj
 A variable lies in a half-open range. The range need not enumerate every attainable value. More...
 
class  RewriteSimplifier
 Rewrite-rule based simplifier. More...
 
class  Z3Prover
 Optional Z3-backed prover over the analyzer's accepted premises. More...
 

Typedefs

using ExprIntSetMap = std::unordered_map< PrimExpr, IntSet, ffi::ObjectPtrHash, ffi::ObjectPtrEqual >
 Map from Expr to IntSet.
 

Enumerations

enum  DivMode { kTruncDiv , kFloorDiv }
 Integer division semantics used by symbolic analysis. More...
 
enum class  ProofStrength : int { kDefault = 0 , kSymbolicBound = 1 }
 The strength used for top-level condition proofs. More...
 
enum class  CompareResult : int {
  kInconsistent = 0 , kEQ = 1 , kLT = 2 , kLE = 3 ,
  kGT = 4 , kGE = 5 , kNE = 6 , kUnknown = 7
}
 Possible orderings of two expressions, represented as a bit set. More...
 
enum  SignType { kPositive , kNegative , kZero , kUnknown }
 Sign type of an integer expression. More...
 
enum  IterMapLevel { Bijective = 0 , Surjective = 1 , NoCheck = 3 }
 Mapping level for iterators. More...
 

Functions

constexpr CompareResult operator& (CompareResult lhs, CompareResult rhs)
 Intersect the possible orderings.
 
constexpr CompareResult operator| (CompareResult lhs, CompareResult rhs)
 Unite the possible orderings.
 
TVM_TIRX_DLL IntSet EvalSet (PrimExpr e, const ffi::Map< Var, IntSet > &dom_map)
 Find an symbolic integer set that contains all possible values of e given the domain of each variables.
 
TVM_TIRX_DLL IntSet EvalSet (IntSet s, const ffi::Map< Var, IntSet > &dom_map)
 Find an symbolic integer set that contains is union over all the possible conditional values in dom_map.
 
TVM_TIRX_DLL IntSet EvalSet (Range r, const ffi::Map< Var, IntSet > &dom_map)
 Evaluate the range over the domain of each variable.
 
TVM_TIRX_DLL ffi::Array< IntSet > EvalSet (const ffi::Array< Range > &region, const ffi::Map< Var, IntSet > &dom_map)
 Same as EvalSet, but takes ffi::Array<Range>
 
TVM_TIRX_DLL ExprIntSetMap EvalSetForEachSubExpr (PrimExpr e, const ffi::Map< Var, IntSet > &dom_map)
 Find the integer set of every sub-expression, given the domain of each iteration variables.
 
TVM_TIRX_DLL IntSet Union (const ffi::Array< IntSet > &sets)
 Create a union set of all sets, possibly relaxed.
 
TVM_TIRX_DLL ffi::Array< IntSet > UnionRegion (const ffi::Array< ffi::Array< IntSet > > &nd_int_sets)
 The union of N-dimensional integer sets.
 
TVM_TIRX_DLL IntSet UnionLowerBound (const ffi::Array< IntSet > &sets)
 Create a lower-bound of union set, where some of the segments may be dropped.
 
TVM_TIRX_DLL ffi::Array< IntSet > UnionRegionLowerBound (const ffi::Array< ffi::Array< IntSet > > &nd_int_sets)
 The union of N-dimensional integer sets.
 
TVM_TIRX_DLL IntSet Intersect (const ffi::Array< IntSet > &sets)
 Create an intersected set of all sets.
 
TVM_TIRX_DLL IntSet Intersect (const IntSet &lhs, const IntSet &rhs, const Analyzer &analyzer)
 Intersect two integer sets using the analyzer's bindings and constraints.
 
TVM_TIRX_DLL ffi::Map< Var, sym::IntSet > AsIntSet (const ffi::Map< Var, Range > &var_dom)
 Converts the Ranges to IntSets.
 
TVM_TIRX_DLL ffi::Optional< ffi::Array< IntSet > > EstimateRegionStrictBound (const ffi::Array< Range > &region, const ffi::Map< Var, Range > &var_dom, const PrimExpr &predicate, const sym::Analyzer &analyzer)
 Analyze the region with affine map, given the domain of variables and their predicate. The result should be strict, i.e. no region is discarded or relaxed.
 
TVM_TIRX_DLL ffi::Optional< ffi::Array< IntSet > > EstimateRegionLowerBound (const ffi::Array< Range > &region, const ffi::Map< Var, Range > &var_dom, const PrimExpr &predicate, const sym::Analyzer &analyzer)
 Analyze the region with affine map, given the domain of variables and their predicate. Some subregion may be discarded during the lower-bound analysis.
 
TVM_TIRX_DLL ffi::Array< IntSet > EstimateRegionUpperBound (const ffi::Array< Range > &region, const ffi::Map< Var, Range > &var_dom, const PrimExpr &predicate, const sym::Analyzer &analyzer)
 Analyze the region with affine map, given the domain of variables and their predicate Relaxation of the region may be used in upper-bound analysis, i.e. some extra region may be added to the result.
 
TVM_TIRX_DLL IntSet DeduceBound (PrimExpr v, PrimExpr cond, const ffi::Map< Var, IntSet > &hint_map, const ffi::Map< Var, IntSet > &relax_map)
 Deduce the bound of the target variable in an expression, given the domain of each variable. Return IntSet::Nothing() to represent failure.
 
TVM_TIRX_DLL IterMapResult DetectIterMap (const ffi::Array< PrimExpr > &indices, const ffi::Map< PrimVar, Range > &input_iters, const PrimExpr &predicate, IterMapLevel check_level, const sym::Analyzer &analyzer, bool simplify_trivial_iterators=true)
 Detect if indices can be written as [y_0 + c_0, y_1 + c_1, ..., y_n + c_n].
 
TVM_TIRX_DLL ffi::Array< PrimExpr > IterMapSimplify (const ffi::Array< PrimExpr > &indices, const ffi::Map< PrimVar, Range > &input_iters, const PrimExpr &input_pred, IterMapLevel check_level, const sym::Analyzer &analyzer, bool simplify_trivial_iterators=true)
 Use IterVarMap detector to rewrite and simplify the indices.
 
TVM_TIRX_DLL ffi::Map< Var, PrimExpr > InverseAffineIterMap (const ffi::Array< IterSumExpr > &iter_map, const ffi::Array< PrimExpr > outputs)
 Apply the inverse of the affine transformation to the outputs.
 
TVM_TIRX_DLL ffi::Array< ffi::Array< IterMark > > SubspaceDivide (const ffi::Array< PrimExpr > &bindings, const ffi::Map< PrimVar, Range > &input_iters, const ffi::Array< PrimVar > &sub_iters, const PrimExpr &predicate, IterMapLevel check_level, const sym::Analyzer &analyzer, bool simplify_trivial_iterators=true)
 Detect if bindings can be written as [a_0*e_0 + b_0 + c_0, a_1*e_1 + b_1, ..., a_n*e_n + b_n].
 
TVM_TIRX_DLL PrimExpr NormalizeIterMapToExpr (const PrimExpr &expr)
 Given an expression that may contain IterMapExpr, transform it to normal PrimExpr.
 
TVM_TIRX_DLL IterSumExpr NormalizeToIterSum (PrimExpr index, const ffi::Map< PrimVar, Range > &input_iters, const sym::Analyzer &analyzer)
 Rewrite index as IterSumExpr.
 

Detailed Description

namespace of symbolic analysis.

Typedef Documentation

◆ ExprIntSetMap

using tvm::sym::ExprIntSetMap = typedef std::unordered_map<PrimExpr, IntSet, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>

Map from Expr to IntSet.

Enumeration Type Documentation

◆ CompareResult

enum class tvm::sym::CompareResult : int
strong

Possible orderings of two expressions, represented as a bit set.

EQ, LT, and GT are independent bits. Intersection combines facts that all hold; union combines alternative possibilities. Zero indicates inconsistency.

Enumerator
kInconsistent 

No ordering is possible under the known facts.

kEQ 

Equal.

kLT 

Strictly less.

kLE 

Less than or equal.

kGT 

Strictly greater.

kGE 

Greater than or equal.

kNE 

Unequal.

kUnknown 

Any ordering is possible.

◆ DivMode

Integer division semantics used by symbolic analysis.

Enumerator
kTruncDiv 

Truncated division.

kFloorDiv 

Floor division.

◆ IterMapLevel

Mapping level for iterators.

Enumerator
Bijective 
Surjective 
NoCheck 

◆ ProofStrength

enum class tvm::sym::ProofStrength : int
strong

The strength used for top-level condition proofs.

Note
The higher, the more time consuming it can be.

Do not use level beyond kDefault in internal recursive rewriting in sym analysis and only use it at top-level simplification to avoid speed issues.

Enumerator
kDefault 

Default analysis followed by the optional Z3 fallback.

kSymbolicBound 

Prove using symbolic bound analysis.

◆ SignType

Sign type of an integer expression.

Enumerator
kPositive 
kNegative 
kZero 
kUnknown 

Function Documentation

◆ AsIntSet()

TVM_TIRX_DLL ffi::Map< Var, sym::IntSet > tvm::sym::AsIntSet ( const ffi::Map< Var, Range > &  var_dom)

Converts the Ranges to IntSets.

Parameters
var_domThe ranges of variables
Returns
The integer sets of the variables

◆ DeduceBound()

TVM_TIRX_DLL IntSet tvm::sym::DeduceBound ( PrimExpr  v,
PrimExpr  cond,
const ffi::Map< Var, IntSet > &  hint_map,
const ffi::Map< Var, IntSet > &  relax_map 
)

Deduce the bound of the target variable in an expression, given the domain of each variable. Return IntSet::Nothing() to represent failure.

Note
The returned set may be smaller than set that contains all possible values of v that satisfies the bound.
Parameters
vThe target variable to be deduced.
condThe conditional expression.
hint_mapThe domain of variable, used to help deduce.
relax_mapThe domain of each variable, used to relax the domain, The deduce bound must imply e for all value in relax_map
Returns
An integer set that always satisfies the condition.

◆ DetectIterMap()

TVM_TIRX_DLL IterMapResult tvm::sym::DetectIterMap ( const ffi::Array< PrimExpr > &  indices,
const ffi::Map< PrimVar, Range > &  input_iters,
const PrimExpr &  predicate,
IterMapLevel  check_level,
const sym::Analyzer &  analyzer,
bool  simplify_trivial_iterators = true 
)

Detect if indices can be written as [y_0 + c_0, y_1 + c_1, ..., y_n + c_n].

Here y = some-quasi-affine-iter-map(input_iters) and c are symbolic constants.

We also requires that y_i and y_j to be independent for i != j.

For returned value rv, the following is always true:

  • rv[i]->args.size() <=1: only one iterator per element.
Parameters
indicesThe indices to detect pattern for.
input_itersMap from variable to iterator's range.
predicateThe predicate constraints on the input iterators
check_levelThe iter mapping checking level.
analyzerAnalyzer used to get context information.
simplify_trivial_iteratorsIf true, iterators with extent of 1 will be replaced with a constant value.
Returns
The detected iteration result. The return object's .indices is empty on failure.

◆ EstimateRegionLowerBound()

TVM_TIRX_DLL ffi::Optional< ffi::Array< IntSet > > tvm::sym::EstimateRegionLowerBound ( const ffi::Array< Range > &  region,
const ffi::Map< Var, Range > &  var_dom,
const PrimExpr &  predicate,
const sym::Analyzer &  analyzer 
)

Analyze the region with affine map, given the domain of variables and their predicate. Some subregion may be discarded during the lower-bound analysis.

Parameters
regionThe region to be analyzed
var_domThe ranges of the variables
predicateThe predicate for the affine map
analyzerThe analyzer used
Returns
std::nullopt if the detection fails, or an array of sym::IntSet as the result of analysis

◆ EstimateRegionStrictBound()

TVM_TIRX_DLL ffi::Optional< ffi::Array< IntSet > > tvm::sym::EstimateRegionStrictBound ( const ffi::Array< Range > &  region,
const ffi::Map< Var, Range > &  var_dom,
const PrimExpr &  predicate,
const sym::Analyzer &  analyzer 
)

Analyze the region with affine map, given the domain of variables and their predicate. The result should be strict, i.e. no region is discarded or relaxed.

Parameters
regionThe region to be analyzed
var_domThe ranges of the variables
predicateThe predicate for the affine map
analyzerThe analyzer used
Returns
std::nullopt if the detection fails, or an array of sym::IntSet as the result of analysis

◆ EstimateRegionUpperBound()

TVM_TIRX_DLL ffi::Array< IntSet > tvm::sym::EstimateRegionUpperBound ( const ffi::Array< Range > &  region,
const ffi::Map< Var, Range > &  var_dom,
const PrimExpr &  predicate,
const sym::Analyzer &  analyzer 
)

Analyze the region with affine map, given the domain of variables and their predicate Relaxation of the region may be used in upper-bound analysis, i.e. some extra region may be added to the result.

Parameters
regionThe region to be analyzed
var_domThe ranges of the variables
predicateThe predicate for the affine map
analyzerThe analyzer used
Returns
an array of sym::IntSet as the result of analysis

◆ EvalSet() [1/4]

TVM_TIRX_DLL ffi::Array< IntSet > tvm::sym::EvalSet ( const ffi::Array< Range > &  region,
const ffi::Map< Var, IntSet > &  dom_map 
)

Same as EvalSet, but takes ffi::Array<Range>

Parameters
regionThe range to be evaluated.
dom_mapThe domain of each variable.
Returns
An array of integer sets that can cover all the possible values.

◆ EvalSet() [2/4]

TVM_TIRX_DLL IntSet tvm::sym::EvalSet ( IntSet  s,
const ffi::Map< Var, IntSet > &  dom_map 
)

Find an symbolic integer set that contains is union over all the possible conditional values in dom_map.

Parameters
sThe initial set.
dom_mapThe domain of each variable.
Returns
An integer set that can cover all the possible values.

◆ EvalSet() [3/4]

TVM_TIRX_DLL IntSet tvm::sym::EvalSet ( PrimExpr  e,
const ffi::Map< Var, IntSet > &  dom_map 
)

Find an symbolic integer set that contains all possible values of e given the domain of each variables.

Parameters
eThe expression to be evaluated.
dom_mapThe domain of each variable.
Returns
An integer set that can cover all the possible values of e.

◆ EvalSet() [4/4]

TVM_TIRX_DLL IntSet tvm::sym::EvalSet ( Range  r,
const ffi::Map< Var, IntSet > &  dom_map 
)

Evaluate the range over the domain of each variable.

Parameters
rThe range to be evaluated.
dom_mapThe domain of each variable.
Returns
An integer set that can cover all the possible values of e.

◆ EvalSetForEachSubExpr()

TVM_TIRX_DLL ExprIntSetMap tvm::sym::EvalSetForEachSubExpr ( PrimExpr  e,
const ffi::Map< Var, IntSet > &  dom_map 
)

Find the integer set of every sub-expression, given the domain of each iteration variables.

Parameters
eThe expression to be evaluated.
dom_mapThe domain of each variable.
Returns
the map from the expression to its possible value.

◆ Intersect() [1/2]

TVM_TIRX_DLL IntSet tvm::sym::Intersect ( const ffi::Array< IntSet > &  sets)

Create an intersected set of all sets.

Parameters
setsThe sets to be intersected
Returns
the set after intersected

◆ Intersect() [2/2]

TVM_TIRX_DLL IntSet tvm::sym::Intersect ( const IntSet &  lhs,
const IntSet &  rhs,
const Analyzer &  analyzer 
)

Intersect two integer sets using the analyzer's bindings and constraints.

Parameters
lhsThe first set.
rhsThe second set.
analyzerThe analyzer used to prove whether the intersection is empty.
Returns
Nothing if emptiness is proved, or the intersected bounds otherwise.

◆ InverseAffineIterMap()

TVM_TIRX_DLL ffi::Map< Var, PrimExpr > tvm::sym::InverseAffineIterMap ( const ffi::Array< IterSumExpr > &  iter_map,
const ffi::Array< PrimExpr >  outputs 
)

Apply the inverse of the affine transformation to the outputs.

Similar to the back-propagation, starting from the outputs, it visits the DAG of the expressions in reverse topology order and applies the inverse of the affine transformation until it reaches the input. The affine iter map is required to be bijective.

For example, iter_map = [l0 // 16, l0 % 16], outputs = [output_0, output_1], the affine transformation specified by iter_map will be applied to outputs and the result will be {l0: ((output_0*16) + output_1)}.

The range of outputs should be the same as the output range of the affine transmation.

See also
DetectIterMap
Parameters
iter_mapThe bijective affine iter map.
outputsThe outputs of the affine transformation.
Returns
The map from the input to the transformed result.

◆ IterMapSimplify()

TVM_TIRX_DLL ffi::Array< PrimExpr > tvm::sym::IterMapSimplify ( const ffi::Array< PrimExpr > &  indices,
const ffi::Map< PrimVar, Range > &  input_iters,
const PrimExpr &  input_pred,
IterMapLevel  check_level,
const sym::Analyzer &  analyzer,
bool  simplify_trivial_iterators = true 
)

Use IterVarMap detector to rewrite and simplify the indices.

Parameters
indicesThe indices to detect pattern for.
input_itersMap from variable to iterator's range.
input_predThe predicate constraints on the input iterators
check_levelThe iter mapping checking level.
analyzerAnalyzer used to get context information.
simplify_trivial_iteratorsIf true, iterators with unit extents are simplified
Returns
The indices after rewrite

◆ NormalizeIterMapToExpr()

TVM_TIRX_DLL PrimExpr tvm::sym::NormalizeIterMapToExpr ( const PrimExpr &  expr)

Given an expression that may contain IterMapExpr, transform it to normal PrimExpr.

Parameters
exprThe input expression, which may contain IterMapExpr.
Returns
The corresponding normal PrimExpr.

◆ NormalizeToIterSum()

TVM_TIRX_DLL IterSumExpr tvm::sym::NormalizeToIterSum ( PrimExpr  index,
const ffi::Map< PrimVar, Range > &  input_iters,
const sym::Analyzer &  analyzer 
)

Rewrite index as IterSumExpr.

((i0 // b0) % a0) * s0 + ((i0 // b1) % a1) * s1 ... + base

The iterators are ordered such that s0 > s1 ... if we can prove the relation.

Note that base may contain expressions that cannot be detected as the right pattern.

Parameters
indexThe input index
input_itersThe input iterators.
analyzerThe input analyzer.
Note
This function is useful to detect iterator stride patterns.

◆ operator&()

constexpr CompareResult tvm::sym::operator& ( CompareResult  lhs,
CompareResult  rhs 
)
inlineconstexpr

Intersect the possible orderings.

Parameters
lhsFirst set of orderings.
rhsSecond set of orderings.
Returns
The combined set of orderings.

◆ operator|()

constexpr CompareResult tvm::sym::operator| ( CompareResult  lhs,
CompareResult  rhs 
)
inlineconstexpr

Unite the possible orderings.

Parameters
lhsFirst set of orderings.
rhsSecond set of orderings.
Returns
The combined set of orderings.

◆ SubspaceDivide()

TVM_TIRX_DLL ffi::Array< ffi::Array< IterMark > > tvm::sym::SubspaceDivide ( const ffi::Array< PrimExpr > &  bindings,
const ffi::Map< PrimVar, Range > &  input_iters,
const ffi::Array< PrimVar > &  sub_iters,
const PrimExpr &  predicate,
IterMapLevel  check_level,
const sym::Analyzer &  analyzer,
bool  simplify_trivial_iterators = true 
)

Detect if bindings can be written as [a_0*e_0 + b_0 + c_0, a_1*e_1 + b_1, ..., a_n*e_n + b_n].

where a = some-quasi-affine-iter-map(input_iters set_minus sub_iters) b = some-quasi-affine-iter-map(sub_iters) c is constant symbols e is the extent of b

For example, z*12 + y*3 + x + c = (z*4+y)*3 + x, if sub_iters={x}

Parameters
bindingsThe input bindings
input_itersMap from variable to iterator's range.
sub_itersIterators of subspace.
predicateThe predicate constraints on the input iterators
check_levelThe iter mapping checking level.
analyzerAnalyzer used to get context information.
simplify_trivial_iteratorsIf true, iterators with extent of 1 will be replaced with a constant value.
Returns
The result list has length len(bindings) + 1 [0, len(bindings)): The iter map matching result. The inner list is of length 2. The first expr is the basis of the quotient space. The second expr is the basis of the subspace. len(bindings): the predicate of outer space and inner space Empty array if no match can be found.

◆ Union()

TVM_TIRX_DLL IntSet tvm::sym::Union ( const ffi::Array< IntSet > &  sets)

Create a union set of all sets, possibly relaxed.

Parameters
setsThe sets to be combined
Returns
the set after union

◆ UnionLowerBound()

TVM_TIRX_DLL IntSet tvm::sym::UnionLowerBound ( const ffi::Array< IntSet > &  sets)

Create a lower-bound of union set, where some of the segments may be dropped.

Parameters
setsThe sets to be combined
Returns
the set after union

◆ UnionRegion()

TVM_TIRX_DLL ffi::Array< IntSet > tvm::sym::UnionRegion ( const ffi::Array< ffi::Array< IntSet > > &  nd_int_sets)

The union of N-dimensional integer sets.

Parameters
nd_int_setsA list of N-dimensional integer sets
Returns
An N-dimensional integer set as the result of union

◆ UnionRegionLowerBound()

TVM_TIRX_DLL ffi::Array< IntSet > tvm::sym::UnionRegionLowerBound ( const ffi::Array< ffi::Array< IntSet > > &  nd_int_sets)

The union of N-dimensional integer sets.

Parameters
nd_int_setsA list of N-dimensional integer sets
Returns
An N-dimensional integer set as the result of union