tvm
Loading...
Searching...
No Matches
int_set.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_SYM_INT_SET_H_
25#define TVM_SYM_INT_SET_H_
26
27#include <tvm/ir/expr.h>
28#include <tvm/ir/prim/expr.h>
29
30#include <unordered_map>
31
32namespace tvm {
33namespace sym {
34
35class AnalyzerObj;
36class Analyzer;
37
38//-----------------------------------------------
39// Integer set data structure.
40//
41// This is a API build on top of the base
42// integer analysis API to provide set analysis.
43//------------------------------------------------
48
54class IntSetObj : public ffi::Object {
55 public:
56 TVM_FFI_DECLARE_OBJECT_INFO("sym.IntSet", IntSetObj, ffi::Object);
57};
58
63class IntSet : public ffi::ObjectRef {
64 public:
70 TVM_TIRX_DLL ffi::Optional<Range> CoverRange(ffi::Optional<Range> max_range) const;
78 TVM_TIRX_DLL bool IsNothing() const;
97 // TODO(tvm-team): update all CanProve to explicitly take
98 // analyzer to encourage more analyzer reuse
111
123 TVM_TIRX_DLL bool MatchRange(const tvm::Range& r) const;
160
162};
163
172TVM_TIRX_DLL IntSet EvalSet(PrimExpr e, const ffi::Map<Var, IntSet>& dom_map);
181TVM_TIRX_DLL IntSet EvalSet(IntSet s, const ffi::Map<Var, IntSet>& dom_map);
189TVM_TIRX_DLL IntSet EvalSet(Range r, const ffi::Map<Var, IntSet>& dom_map);
197TVM_TIRX_DLL ffi::Array<IntSet> EvalSet(const ffi::Array<Range>& region,
198 const ffi::Map<Var, IntSet>& dom_map);
200using ExprIntSetMap = std::unordered_map<PrimExpr, IntSet, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>;
209TVM_TIRX_DLL ExprIntSetMap EvalSetForEachSubExpr(PrimExpr e, const ffi::Map<Var, IntSet>& dom_map);
210
216TVM_TIRX_DLL IntSet Union(const ffi::Array<IntSet>& sets);
217
223TVM_TIRX_DLL ffi::Array<IntSet> UnionRegion(const ffi::Array<ffi::Array<IntSet>>& nd_int_sets);
224
230TVM_TIRX_DLL IntSet UnionLowerBound(const ffi::Array<IntSet>& sets);
231
238 const ffi::Array<ffi::Array<IntSet>>& nd_int_sets);
239
245TVM_TIRX_DLL IntSet Intersect(const ffi::Array<IntSet>& sets);
246
254TVM_TIRX_DLL IntSet Intersect(const IntSet& lhs, const IntSet& rhs, const Analyzer& analyzer);
255
261TVM_TIRX_DLL ffi::Map<Var, sym::IntSet> AsIntSet(const ffi::Map<Var, Range>& var_dom);
262
273TVM_TIRX_DLL ffi::Optional<ffi::Array<IntSet>> EstimateRegionStrictBound(
274 const ffi::Array<Range>& region, const ffi::Map<Var, Range>& var_dom, const PrimExpr& predicate,
275 const sym::Analyzer& analyzer);
276
287TVM_TIRX_DLL ffi::Optional<ffi::Array<IntSet>> EstimateRegionLowerBound(
288 const ffi::Array<Range>& region, const ffi::Map<Var, Range>& var_dom, const PrimExpr& predicate,
289 const sym::Analyzer& analyzer);
290
301TVM_TIRX_DLL ffi::Array<IntSet> EstimateRegionUpperBound(const ffi::Array<Range>& region,
302 const ffi::Map<Var, Range>& var_dom,
303 const PrimExpr& predicate,
304 const sym::Analyzer& analyzer);
305
321TVM_TIRX_DLL IntSet DeduceBound(PrimExpr v, PrimExpr cond, const ffi::Map<Var, IntSet>& hint_map,
322 const ffi::Map<Var, IntSet>& relax_map);
323
324} // namespace sym
325} // namespace tvm
326#endif // TVM_SYM_INT_SET_H_
Base expr nodes in TVM.
TIR expressions.
#define TVM_TIRX_DLL
Definition base.h:55
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
Range container
Definition expr.h:883
Managed reference to AnalyzerObj.
Definition analyzer.h:750
Base class of all Integer set containers. represent a set of integers in one dimension.
Definition int_set.h:54
TVM_FFI_DECLARE_OBJECT_INFO("sym.IntSet", IntSetObj, ffi::Object)
Managed reference to IntSetObj.
Definition int_set.h:63
TVM_TIRX_DLL PrimExpr max() const
static TVM_TIRX_DLL IntSet Nothing()
TVM_TIRX_DLL bool CanProveNegative() const
static TVM_TIRX_DLL IntSet Vector(PrimExpr vec)
construct a integer set from vector expression.
TVM_TIRX_DLL bool CanProvePositive() const
TVM_TIRX_DLL bool CanProveNonPositive() const
TVM_TIRX_DLL bool IsEverything() const
TVM_TIRX_DLL bool IsNothing() const
TVM_TIRX_DLL bool IsSinglePoint() const
TVM_TIRX_DLL bool HasUpperBound() const
TVM_TIRX_DLL ffi::Optional< Range > CoverRange(ffi::Optional< Range > max_range) const
Find a range that covers the region.
TVM_TIRX_DLL SignType GetSignType() const
TVM_TIRX_DLL PrimExpr min() const
TVM_TIRX_DLL PrimExpr PointValue() const
The single point value, call only if IsSinglePoint is true.
static TVM_TIRX_DLL IntSet FromRange(tvm::Range r)
Construct a set representing a range.
TVM_TIRX_DLL bool CanProveSinglePoint(const Analyzer &ana) const
Check if we can prove it is a single point.
static TVM_TIRX_DLL IntSet SinglePoint(PrimExpr point)
construct a point set.
static TVM_TIRX_DLL IntSet Interval(PrimExpr min, PrimExpr max)
Construct a set representing a interval.
TVM_TIRX_DLL bool HasLowerBound() const
TVM_TIRX_DLL bool MatchRange(const tvm::Range &r) const
Try to match IntSet with range r.
static TVM_TIRX_DLL IntSet Everything()
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IntSet, ffi::ObjectRef, IntSetObj)
TVM_TIRX_DLL bool CanProveNonNegative() const
static TVM_TIRX_DLL IntSet FromMinExtent(PrimExpr min, PrimExpr extent)
Construct a set representing a range [min, min + extent).
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 variable...
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....
TVM_TIRX_DLL IntSet Union(const ffi::Array< IntSet > &sets)
Create a union set of all sets, possibly relaxed.
SignType
Sign type of an integer expression.
Definition int_set.h:47
@ kUnknown
Definition int_set.h:47
@ kZero
Definition int_set.h:47
@ kPositive
Definition int_set.h:47
@ kNegative
Definition int_set.h:47
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::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 t...
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....
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 ffi::Array< IntSet > UnionRegion(const ffi::Array< ffi::Array< IntSet > > &nd_int_sets)
The union of N-dimensional integer sets.
std::unordered_map< PrimExpr, IntSet, ffi::ObjectPtrHash, ffi::ObjectPtrEqual > ExprIntSetMap
Map from Expr to IntSet.
Definition int_set.h:200
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 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....
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41