tvm
|
Namespaces | |
attr | |
distributed | |
transform | |
Classes | |
struct | VarUsageInfo |
A utility struct returned by CollectVarUsage. More... | |
struct | AllReduceAttrs |
Attributes used in allreduce operators. More... | |
struct | AllGatherAttrs |
Attributes used in allgather operators. More... | |
struct | ScatterCollectiveAttrs |
Attributes used in scatter operators. More... | |
struct | InitAttrs |
Attributes used in full/full_like, ones/ones_like, and zeros/zeros_like operators. More... | |
struct | TriluAttrs |
Attributes used in tril and triu operator. More... | |
struct | AstypeAttrs |
Attributes used in astype operator. More... | |
struct | WrapParamAttrs |
Attributes used in wrap_param operator. More... | |
struct | DistributionAttrs |
Attributes for redistribute and annotate_sharding operator. More... | |
struct | Resize2DAttrs |
Attributes used in image resize2d operator. More... | |
struct | TakeAttrs |
Attributes used in take operator. More... | |
struct | StridedSliceAttrs |
Attributes used in strided_slice operator. More... | |
struct | MatmulAttrs |
Attributes for matmul operator. More... | |
struct | EinsumAttrs |
Attributes used in einsum operator. More... | |
struct | ConcatAttrs |
Attributes used in concat operators. More... | |
struct | ExpandDimsAttrs |
Attributes used in expand_dims operators. More... | |
struct | LayoutTransformAttrs |
Attributes used in layout_transform operator. More... | |
struct | PermuteDimsAttrs |
Attributes used in permute_dims operator. More... | |
struct | SplitAttrs |
Attributes used in split operator. More... | |
struct | SqueezeAttrs |
Attributes used in squeeze operators. More... | |
struct | RepeatAttrs |
Attributes used in repeat operators. More... | |
struct | TileAttrs |
Attributes used in tile operators. More... | |
struct | FlipAttrs |
Attributes used in flip operators. More... | |
struct | GatherElementsAttrs |
Attributes used in gather_elements operators. More... | |
struct | GatherNDAttrs |
Attributes used in gather_nd operators. More... | |
struct | ScatterElementsAttrs |
Attributes used in scatter_elements operators. More... | |
struct | ScatterNDAttrs |
Attributes used in scatter_nd operators. More... | |
struct | OneHotAttrs |
Attributes used in one_hot operator. More... | |
struct | Conv1DAttrs |
Attributes used in Conv1d operator. More... | |
struct | Conv2DAttrs |
Attributes used in Conv2d operator. More... | |
struct | Conv3DAttrs |
Attributes used in Conv3d operator. More... | |
struct | Conv1DTransposeAttrs |
Attributes used in Conv1DTranspose operator. More... | |
struct | Conv2DTransposeAttrs |
Attributes used in Conv2d operator. More... | |
struct | Pool1DAttrs |
Attributes used in max_pool1d and avg_pool1d operator. More... | |
struct | Pool2DAttrs |
Attributes used in max_pool2d and avg_pool2d operator. More... | |
struct | Pool3DAttrs |
Attributes used in max_pool3d and avg_pool3d operator. More... | |
struct | AdaptivePool1DAttrs |
Attributes for 1d adaptive pool operator. More... | |
struct | AdaptivePool2DAttrs |
Attributes for 2d adaptive pool operator. More... | |
struct | AdaptivePool3DAttrs |
Attributes for 3d adaptive pool operator. More... | |
struct | SoftmaxAttrs |
Attributes used in softmax operators. More... | |
struct | LeakyReluAttrs |
Attributes used in softmax operators. More... | |
struct | SoftplusAttrs |
Attributes used in softplus operators. More... | |
struct | BatchNormAttrs |
Attributes used in batch_norm operator. More... | |
struct | LayerNormAttrs |
Attributes used in layer_norm operator. More... | |
struct | GroupNormAttrs |
Attributes used in group_norm operator. More... | |
struct | RMSNormAttrs |
Attributes used in rms_norm operator. More... | |
struct | NLLLossAttrs |
Attributes used in nll_loss operator. More... | |
struct | DropoutAttrs |
Attributes used in dropout operator. More... | |
struct | AttentionAttrs |
Attributes used in Attention operator. More... | |
struct | PadAttrs |
Attributes used for the padding operator. More... | |
struct | CallTIRWithGradAttrs |
Attributes used in call_tir_with_grad. More... | |
struct | CallTIRInplaceAttrs |
Attributes used in call_tir_inplace. More... | |
struct | CallInplacePackedAttrs |
Attributes used in call_inplace_packed. More... | |
struct | ToVDeviceAttrs |
Attributes used in to_vdevice. More... | |
struct | HintOnDeviceAttrs |
Attributes used in hint_on_device. More... | |
struct | QuantizeAttrs |
Attributes for relax.quantize/relax.dequantize operator. More... | |
struct | MultinomialFromUniformAttrs |
Attributes used in multinomial_from_uniform operator. More... | |
struct | ArgmaxArgminAttrs |
Attributes for search operators. More... | |
struct | SortAttrs |
Attributes used in sort operator. More... | |
struct | ArgsortAttrs |
Attributes used in argsort operator. More... | |
struct | TopKAttrs |
Attributes used in topk operator. More... | |
struct | StatisticalAttrs |
Attributes for statistical operators. More... | |
struct | ScanopAttrs |
Attributes used in scan operators like cumsum, cumprod. More... | |
class | DataflowBlockRewriteNode |
Statement rewriter for relax.DataflowBlock. More... | |
class | DataflowBlockRewrite |
A statement rewriter for relax.DataflowBlock. More... | |
class | BlockBuilderNode |
A builder to build Relax binding blocks. More... | |
class | BlockBuilder |
class | DFPatternNode |
Base type of all dataflow patterns. More... | |
class | DFPattern |
Managed reference to dataflow patterns. More... | |
struct | PairCons |
Constraint of a DFPattern edge (producer -> consumer) in graph-level matching. More... | |
class | DFConstraintNode |
Additional constraints on the graph. More... | |
class | DFConstraint |
class | PatternSeqNode |
A sequence of DFPatterns that the previous DFPattern is connected to the next one. More... | |
class | PatternSeq |
Managed reference to pattern sequences. More... | |
class | PatternContextNode |
A context to manage the graph-level pattern matching. More... | |
class | PatternContext |
Managed reference to a pattern context. More... | |
class | ExprPatternNode |
Pattern for Relax Expression. More... | |
class | ExprPattern |
Managed reference to an ExprPattern. More... | |
class | VarPatternNode |
A Pattern to Match a Relax Variable. More... | |
class | VarPattern |
Managed reference to a VarPattern. More... | |
class | DataflowVarPatternNode |
A Pattern to Match a Relax Dataflow Variable. More... | |
class | DataflowVarPattern |
Managed reference to a DataflowVarPattern. More... | |
class | GlobalVarPatternNode |
A Pattern to Match a Relax Global Variable. More... | |
class | GlobalVarPattern |
Managed reference to a GlobalVarPattern. More... | |
class | ConstantPatternNode |
A Pattern to Match a Relax Constant. More... | |
class | ConstantPattern |
Managed reference to a ConstantPattern. More... | |
class | CallPatternNode |
A pattern to match a callable node in Relax. More... | |
class | CallPattern |
class | PrimArrPatternNode |
A pattern to match an array of PrimExpr. More... | |
class | PrimArrPattern |
Managed reference to a PrimArrPattern. More... | |
class | FunctionPatternNode |
A pattern to match a Relax Function. More... | |
class | FunctionPattern |
Managed reference to FunctionPatternNode. More... | |
class | TuplePatternNode |
Pattern to match a tuple of ordered expressions. More... | |
class | TuplePattern |
Managed reference to TuplePatternNode. More... | |
class | UnorderedTuplePatternNode |
A pattern to match multiple expressions unorderedly. More... | |
class | UnorderedTuplePattern |
Managed reference to UnorderedTuplePatternNode. More... | |
class | TupleGetItemPatternNode |
A pattern to match n'th indexing to a tuple. More... | |
class | TupleGetItemPattern |
Managed reference to TupleGetItemPatternNode. More... | |
class | AndPatternNode |
Match a conjunction of other patterns. More... | |
class | AndPattern |
Managed reference to AndPatternNode. More... | |
class | OrPatternNode |
Match a disjunction of other patterns. More... | |
class | OrPattern |
Managed reference to OrPatternNode. More... | |
class | NotPatternNode |
Pattern for rejecting a certain pattern. More... | |
class | NotPattern |
Managed reference to NotPatternNode. More... | |
class | WildcardPatternNode |
Wildcard Pattern is a pattern that can match anything. More... | |
class | WildcardPattern |
Managed reference to WildcardPatternNode. More... | |
class | TypePatternNode |
Pattern for matching a certain type. More... | |
class | TypePattern |
Managed reference to TypePatternNode. More... | |
class | StructInfoPatternNode |
Pattern for matching a certain struct info. More... | |
class | StructInfoPattern |
class | ShapePatternNode |
A pattern that asserting a root pattern has a certain shape. More... | |
class | ShapePattern |
Managed reference to ShapePatternNode. More... | |
class | SameShapeConstraintNode |
A pattern that asserting multiple root patterns have the same shape. More... | |
class | SameShapeConstraint |
Managed reference to SameShapePatternNode. More... | |
class | DataTypePatternNode |
A pattern that asserting a root pattern has a certain data type. More... | |
class | DataTypePattern |
Managed reference to DataTypePatternNode. More... | |
class | AttrPatternNode |
A pattern that asserting a root pattern has certain attributes. More... | |
class | AttrPattern |
Managed reference to AttrPatternNode. More... | |
class | ExternFuncPatternNode |
A pattern of external function. More... | |
class | ExternFuncPattern |
Managed reference to ExternFuncPatternNode. More... | |
class | DFPatternFunctor |
A dynamical functor that dispatches on in the first DFPattern argument. More... | |
class | DFPatternFunctor< R(const DFPattern &n, Args...)> |
class | DFPatternVisitor |
A simple visitor wrapper around DFPatternFunctor. Recursively visit the content. More... | |
class | ExecBuilderNode |
A builder provides api to build VM executable with instructions. More... | |
class | ExecBuilder |
class | IdNode |
The unique identifier of variables. More... | |
class | Id |
class | StructInfoNode |
Base type of all structure information. More... | |
class | StructInfo |
Managed reference to StructInfoNode. More... | |
class | CallNode |
Call corresponds to callable invocation. Corresponds to operation in computational graph terminology. More... | |
class | Call |
class | TupleNode |
Tuple container. More... | |
class | Tuple |
class | TupleGetItemNode |
Get index-th field out of a tuple. More... | |
class | TupleGetItem |
class | LeafExprNode |
Base type of all (non-function) leaf Exprs. More... | |
class | LeafExpr |
Managed reference to BaseExprNode. More... | |
class | ShapeExprNode |
A shape expression which allows users to construct a shape containing PrimExpr. More... | |
class | ShapeExpr |
class | VarNode |
The variable class for all Relax bindings. More... | |
class | Var |
class | DataflowVarNode |
A sub-type of the variable node used to mark dataflow variables from normal visible "function local" bindings. More... | |
class | DataflowVar |
class | ConstantNode |
Constant tensor. More... | |
class | Constant |
class | PrimValueNode |
PrimValue. More... | |
class | PrimValue |
Managed reference to PrimValueNode. More... | |
class | StringImmNode |
Represent a string literal constant. More... | |
class | StringImm |
Managed reference to StringImm. More... | |
class | DataTypeImmNode |
Represent a data type constant. More... | |
class | DataTypeImm |
Managed reference to DataTypeImm. More... | |
class | BindingNode |
The base class of a variable binding in Relax. More... | |
class | Binding |
class | MatchCastNode |
Runtime-match the value to the struct info. More... | |
class | MatchCast |
Managed reference to MatchCastNode. More... | |
class | VarBindingNode |
class | VarBinding |
class | BindingBlockNode |
class | BindingBlock |
class | DataflowBlockNode |
class | DataflowBlock |
class | SeqExprNode |
A sequence of blocks followed by an expression. More... | |
class | SeqExpr |
class | IfNode |
Condition expression. More... | |
class | If |
class | FunctionNode |
A Relax function. More... | |
class | Function |
class | ExternFuncNode |
The extern function, which can represent packed function. More... | |
class | ExternFunc |
class | ExprFunctor |
A dynamical functor that dispatches on in the first Expr argument. You can use this as a more powerful Visitor, since it allows you to define function signatures of Visit Function. More... | |
class | ExprFunctor< R(const Expr &n, Args...)> |
class | ExprVisitor |
A simple visitor wrapper around ExprFunctor. Recursively visit the content. More... | |
class | ExprMutatorBase |
A mutator works in unnormalized form. More... | |
class | ExprMutator |
A mutator works in normal form. More... | |
class | NestedMsg |
Container that stores possibly nested message with leaf message type T. More... | |
class | ObjectStructInfoNode |
Opaque object. More... | |
class | ObjectStructInfo |
Managed reference to ObjectStructInfoNode. More... | |
class | PrimStructInfoNode |
Primitive value. More... | |
class | PrimStructInfo |
Managed reference to PrimStructInfoNode. More... | |
class | ShapeStructInfoNode |
StructInfo of shape value. More... | |
class | ShapeStructInfo |
Managed reference to ShapeStructInfoNode. More... | |
class | TensorStructInfoNode |
StructInfo of Tensor. More... | |
class | TensorStructInfo |
Managed reference to TensorStructInfoNode. More... | |
class | TupleStructInfoNode |
StructInfo of Tuple. More... | |
class | TupleStructInfo |
Managed reference to TupleStructInfoNode. More... | |
class | FuncStructInfoNode |
Structure information about function. More... | |
class | FuncStructInfo |
Managed reference to FuncStructInfoNode. More... | |
class | StructInfoFunctor |
class | StructInfoFunctor< R(const StructInfo &n, Args...)> |
class | StructInfoVisitor |
A struct info visitor. More... | |
class | StructInfoMutator |
StructInfoMutator that mutates struct info. More... | |
class | MatchResultNode |
class | MatchResult |
Managed reference to MatchResultNode. More... | |
class | ChoiceNode |
Choice manages a set of keys for transformation and constraint functions. More... | |
class | Choice |
Managed reference to ChoiceNode. More... | |
class | KnobNode |
Knob manages a set of valid choices for an optimization. More... | |
class | Knob |
Managed reference to KnobNode. More... | |
class | TraceNode |
Trace manages history of optimization decisions. More... | |
class | Trace |
Managed reference to TraceNode. More... | |
class | TuningRecordNode |
The class of tuning records. More... | |
class | TuningRecord |
The managed reference of TuningRecordNode. More... | |
struct | WorkloadEqual |
The equality check for Workload. More... | |
class | DatabaseNode |
class | Database |
Managed reference to DatabaseNode. More... | |
class | ShapeTypeNode |
class | ShapeType |
class | TensorTypeNode |
Dynamic version of TensorType. More... | |
class | TensorType |
Managed reference to TensorTypeNode. More... | |
class | ObjectTypeNode |
class | ObjectType |
class | PackedFuncTypeNode |
class | PackedFuncType |
Typedefs | |
using | Expr = RelaxExpr |
using | ExprNode = RelaxExprNode |
using | FInferStructInfo = runtime::TypedPackedFunc< StructInfo(const Call &call, const BlockBuilder &ctx)> |
Infer output struct info given the call. More... | |
using | FCallPacked = String |
Packed function implementation for operators. The relax operator will be lowered to this packed function call during codegen. More... | |
using | FNormalize = runtime::TypedPackedFunc< Expr(const BlockBuilder &bb, Call call)> |
The function type of a normalization function. More... | |
using | FValidate = runtime::TypedPackedFunc< void(const Call &call)> |
The function type of a validation function. More... | |
using | FLegalize = runtime::TypedPackedFunc< Expr(const BlockBuilder &bb, const Call &call)> |
The function type of a legalization function. More... | |
using | FLowerBuiltin = runtime::TypedPackedFunc< Expr(const BlockBuilder &bb, const Call &call)> |
The function type of a function to lower the runtime builtin. More... | |
using | FPrimalGradient = runtime::TypedPackedFunc< tvm::Array< Expr >(const Var &orig_var, const Call &orig_call, const Var &output_grad, const BlockBuilder &ctx)> |
Gradient for a specific op. More... | |
using | StructInfoDeriveFunc = TypedEnvFunc< StructInfo(const Call &call, const BlockBuilder &ctx)> |
custom-defined StructInfo derivation function. More... | |
using | TIRPattern = tir::PrimFunc |
using | FCodegen = runtime::TypedPackedFunc< Array< ObjectRef >(Array< MatchResult > match_results)> |
using | TensorTypeNode = TensorTypeNode |
using | TensorType = TensorType |
Enumerations | |
enum class | BaseCheckResult { kFailL0 = 0 , kFailL1 = 1 , kFailL2 = 2 , kPass = 3 } |
Fine grained result of base check. More... | |
enum | OpPatternKind { kElemWise = 0 , kBroadcast = 1 , kInjective = 2 , kCommReduce = 3 , kOutEWiseFusable = 4 , kTuple = 7 , kOpaque = 8 } |
Functions | |
bool | CanProveShapeEqual (const Array< PrimExpr > &lhs, const Array< PrimExpr > &rhs, arith::Analyzer *ana) |
Can prove the two symbolic shape arrays equals to each other. More... | |
bool | CanProveShapeEqual (const Expr &lhs, const Expr &rhs, arith::Analyzer *ana) |
Can prove the two symbolic shape expressions equals to each other. More... | |
Type | GetStaticType (const StructInfo &info) |
Get the corresponding static type from a given struct info. More... | |
StructInfo | StructInfoFromType (const Type &type) |
Get the corresponding struct info from static type. More... | |
StructInfo | DeriveCallRetStructInfo (const FuncStructInfo &finfo, const Call &call, const BlockBuilder &ctx, arith::Analyzer *ana=nullptr) |
StructInfo | EraseToWellDefined (const StructInfo &info, std::function< Optional< PrimExpr >(const tir::Var &var)> f_shape_var_map=nullptr, std::function< Optional< Expr >(const Var &var)> f_var_map=nullptr, arith::Analyzer *ana=nullptr) |
Erase the info to a corresponding more coarse grained struct info that is still well-defined(with all the vars in scope). More... | |
StructInfo | EraseToWellDefined (const StructInfo &info, Map< tir::Var, PrimExpr > shape_var_map, Map< Var, Expr > var_map, arith::Analyzer *ana=nullptr) |
EraseToWellDefined variant with map. More... | |
BaseCheckResult | StructInfoBaseCheck (const StructInfo &base, const StructInfo &derived, arith::Analyzer *ana=nullptr) |
Run a base check to see if base subsumes derived. More... | |
bool | IsBaseOf (const StructInfo &base, const StructInfo &derived, arith::Analyzer *ana=nullptr) |
Check the relation of two struct info to see if one subsumes another one. More... | |
PrimExpr | StructInfoBaseCheckPrecondition (const StructInfo &base, const StructInfo &derived) |
Return the condition for which base is a superset of derived. More... | |
StructInfo | StructInfoLCA (const StructInfo &lhs, const StructInfo &rhs, arith::Analyzer *ana=nullptr) |
Unify the two struct info to their least common ancestor. More... | |
Array< tir::Var > | TIRVarsInStructInfo (const StructInfo &sinfo) |
Get the TIR variables that appear in the input struct info. The returned list is deduplicated - each TIR variable will appear at most once. More... | |
Array< tir::Var > | DefinableTIRVarsInStructInfo (const StructInfo &sinfo) |
Get the TIR variables that appear in the input struct info. More... | |
Array< PrimExpr > | CollectNonNegativeExpressions (const StructInfo &sinfo) |
Collect expressions whose usage requires them to be non-negative. More... | |
Array< tir::Var > | DefinedSymbolicVars (const Expr &expr) |
Get the TIR variables that defined in the input function. The returned list is deduplicated - each TIR variable will appear at most once. More... | |
Array< tir::Var > | FreeSymbolicVars (const Expr &expr) |
Get the TIR variables that are used but not defined in the input function. The returned list is deduplicated - each TIR variable will appear at most once. More... | |
tvm::Array< Var > | BoundVars (const Expr &expr) |
Get all bound variables from expression expr. More... | |
tvm::Array< Var > | FreeVars (const Expr &expr) |
Get free type parameters from expression expr. More... | |
tvm::Array< Var > | AllVars (const Expr &expr) |
Get all variables from expression expr. More... | |
tvm::Array< GlobalVar > | AllGlobalVars (const Expr &expr) |
Get all global variables from expression expr. More... | |
tvm::Array< tvm::Array< GlobalVar > > | DetectRecursion (const IRModule &m) |
Find all sets of recursive or mutually recursive functions in the module. More... | |
Map< Var, Expr > | AnalyzeVar2Value (const IRModule &m) |
Analyze var -> value mapping from VarBindings. More... | |
Map< Var, Expr > | AnalyzeVar2Value (const Expr &expr) |
Analyze var -> value mapping from VarBindings. More... | |
Map< Var, Expr > | AnalyzeVar2Value (const DataflowBlock &dfb) |
Analyze var -> value mapping from VarBindings. More... | |
Map< String, Array< Binding > > | NameToBinding (const Function &fn) |
Return a mapping from variable name to its Bindings. More... | |
Map< Var, Array< Var > > | DataflowBlockUseDef (const DataflowBlock &dfb) |
Get the use-def chain of variables inside a dataflow block. More... | |
std::pair< Map< Var, Array< Var > >, Array< Var > > | FunctionUseDef (const Expr &expr) |
Get the use-def chain of variables inside a function. More... | |
VarUsageInfo | CollectVarUsage (const Expr &expr) |
Collect variable bindings and usage. More... | |
Expr | RemoveAllUnused (Expr expr) |
Remove unused statements inside DataflowBlocks. More... | |
OpPatternKind | AnalyzeOpPatternKind (const tir::PrimFunc &func) |
Annotate Op Pattern Kind for PrimFunc, which is used in relax FuseOps. More... | |
bool | HasReshapePattern (const tir::PrimFunc &func) |
Check if the given PrimFunc is essentially doing a reshape operation. The reshape operation also includes expand_dims, squeeze, flatten, etc. More... | |
Optional< Expr > | FindImpureCall (const Expr &expr, const Optional< Expr > &own_name=Optional< Expr >(nullptr)) |
Check if the given expression (likely a function body) contains any impure calls. More... | |
bool | ContainsImpureCall (const Expr &expr, const Optional< Expr > &own_name=Optional< Expr >(nullptr)) |
Check if the given expression (likely a function body) contains any impure calls. More... | |
bool | WellFormed (Variant< IRModule, Function > obj, bool check_struct_info=true) |
Check if the IRModule is well formed. More... | |
Map< tir::Block, Map< ObjectRef, tir::IndexMap > > | SuggestLayoutTransforms (const Function &fn, Array< tir::IndexMap > write_buffer_transformations) |
Using the layout transforms on the outputs, suggest layout transformation on the blocks and buffers for the PrimFunc. More... | |
Array< Var > | ComputableAtCompileTime (const Function &func) |
bool | MatchExpr (DFPattern pattern, Expr expr, Optional< runtime::Map< Var, Expr >> bindings=NullOpt) |
Determine if a pattern matches an expression. More... | |
Optional< Map< DFPattern, Expr > > | ExtractMatchedExpr (DFPattern pattern, Expr expr, Optional< runtime::Map< Var, Expr >> bindings=NullOpt) |
Optional< Map< DFPattern, Var > > | MatchGraph (const PatternContext &ctx, const DataflowBlock &dfb) |
Match a sub-graph in a DataflowBlock with a graph of patterns and return the mapping. More... | |
Function | RewriteBindings (const PatternContext &ctx, runtime::TypedPackedFunc< Map< Var, Expr >(Map< DFPattern, Var >, Map< Var, Expr >)> rewriter, Function f) |
Rewrite a function with the given pattern and the rewriter function. More... | |
Function | RewriteCall (const DFPattern &pattern, runtime::TypedPackedFunc< Expr(Expr, Map< DFPattern, Expr >)> rewriter, Function func) |
Rewrite a function with the given pattern and the rewriter function. More... | |
PatternSeq | UsedBy (const PatternSeq &lhs, const PatternSeq &rhs, int index=-1) |
Create used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned. More... | |
PatternSeq | operator^ (const PatternSeq &lhs, const PatternSeq &rhs) |
Syntax sugar of UsedBy(lhs, rhs, -1). More... | |
PatternSeq | OnlyUsedBy (const PatternSeq &lhs, const PatternSeq &rhs, int index=-1) |
Create only-used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned. More... | |
PatternSeq | operator>> (const PatternSeq &lhs, const PatternSeq &rhs) |
Syntax sugar of OnlyUsedBy(lhs, rhs, -1). More... | |
VarPattern | IsVar (const String &name) |
Syntatic Sugar for creating a VarPattern with a name. More... | |
ConstantPattern | IsConst () |
Syntatic Sugar for creating a ConstantPattern. More... | |
WildcardPattern | Wildcard () |
Syntatic Sugar for creating a WildcardPattern. More... | |
ExprPattern | IsExpr (const Expr &expr) |
Syntatic Sugar for creating a ExprPattern. More... | |
ExprPattern | IsOp (const String &op_name) |
Syntatic Sugar for creating a ExprPattern base on an Op. More... | |
CallPattern | IsCallTIR (const String &name, Optional< TuplePattern > args=NullOpt) |
Syntatic Sugar for call_tir (return a tensor) More... | |
CallPattern | IsCallTIR (const String &name, TuplePattern var_args) |
Syntatic Sugar for call_tir (return a tuple of tensor) More... | |
CallPattern | IsCallDPSPacked (const String &name, Optional< TuplePattern > args=NullOpt) |
Syntatic Sugar for call_dps_packed (return a tensor) More... | |
CallPattern | IsCallDPSPacked (const String &name, TuplePattern var_args) |
Syntatic Sugar for call_dps_packed (return a tuple of tensor) More... | |
DFPattern | IsTuple (const Array< DFPattern > &fields, bool unordered=false) |
Syntatic Sugar for creating TuplePattern or UnorderedTuplePattern (unordered=true) More... | |
TupleGetItemPattern | IsTupleGetItem (const DFPattern tuple, int index=-1) |
Syntatic Sugar for creating a TupleGetItemPattern. More... | |
Call | WithFields (Call call, Optional< Expr > opt_op=Optional< Expr >(), Optional< Array< Expr >> opt_args=Optional< Array< Expr >>(), Optional< Attrs > opt_attrs=Optional< Attrs >(), Optional< Array< StructInfo >> opt_sinfo_args=Optional< Array< StructInfo >>(), Optional< Span > opt_span=Optional< Span >()) |
Returns call with the given properties. A null property denotes 'no change'. Returns call if all properties are unchanged. Otherwise, returns a copy with the new fields. More... | |
Tuple | WithFields (Tuple tuple, Optional< Array< Expr >> opt_fields=Optional< Array< Expr >>(), Optional< Span > opt_span=Optional< Span >()) |
Returns tuple with the given properties. A null property denotes 'no change'. Returns tuple if all properties are unchanged. Otherwise, returns a copy with the new fields. More... | |
TupleGetItem | WithFields (TupleGetItem tuple_get_item, Optional< Expr > opt_tuple=Optional< Expr >(), Optional< Integer > opt_index=Optional< Integer >(), Optional< Span > opt_span=Optional< Span >()) |
Returns tuple_get_item with the given properties. A null property denotes 'no change'. Returns tuple_get_item if all properties are unchanged. Otherwise, returns a copy with the new fields. More... | |
If | WithFields (If if_expr, Optional< Expr > opt_cond=Optional< Expr >(), Optional< Expr > opt_true_branch=Optional< Expr >(), Optional< Expr > opt_false_branch=Optional< Expr >(), Optional< Span > opt_span=Optional< Span >()) |
Returns if_expr with the given properties. A null property denotes 'no change'. Returns if_expr if all properties are unchanged. Otherwise, returns a copy with the new fields. More... | |
Expr | GetShapeOf (const Expr &expr) |
Get the shape of Expr. More... | |
void | PostOrderVisit (const Expr &node, std::function< void(const Expr &)> fvisit) |
template<typename T , typename FType > | |
void | ForEachLeaf (const NestedMsg< T > &msg, FType fvisit) |
Apply fvisit for each leaf elements in the nested message. More... | |
template<typename T , typename FType > | |
bool | Equal (const NestedMsg< T > &lhs, const NestedMsg< T > &rhs, FType fequal) |
Recursively compare two nested messages. More... | |
template<typename T , typename FType > | |
NestedMsg< T > | MapToNestedMsg (Expr expr, FType fmapleaf) |
Map expr with possible nested-tuple to nested message. More... | |
template<typename T , typename FType > | |
NestedMsg< T > | MapToNestedMsg (StructInfo sinfo, FType fmapleaf) |
Map structinfo with possible nested-sinfo to nested message. More... | |
template<typename T , typename FType > | |
NestedMsg< T > | MapToNestedMsgBySInfo (Expr expr, FType fmapleaf) |
Map expr with possible nested-tuple to nested message. More... | |
template<typename TargetType , typename T , typename FMapLeaf , typename FCombine > | |
TargetType | NestedMsgTo (NestedMsg< T > msg, FMapLeaf fmapleaf, FCombine fcombine) |
Map nested message back to TargetType. More... | |
template<typename T , typename FType > | |
Expr | NestedMsgToExpr (NestedMsg< T > msg, FType fmapleaf) |
Map nested message back to the expr. More... | |
template<typename T , typename FType > | |
NestedMsg< T > | CombineNestedMsg (NestedMsg< T > lhs, NestedMsg< T > rhs, FType fcombine) |
Recursively combine two nested message into one. More... | |
template<typename T , typename FType > | |
NestedMsg< T > | MapNestedMsg (NestedMsg< T > msg, FType fmapleaf) |
Recursively map a nested message to another one, with leaf mapped by the input fmapleaf. More... | |
template<typename T , typename FType > | |
void | DecomposeNestedMsg (Expr expr, NestedMsg< T > msg, FType fvisitleaf) |
Recursively decompose the tuple structure in expr and msg along with it. More... | |
template<typename T , std::size_t N, typename FType > | |
Expr | TransformTupleLeaf (Expr expr, std::array< NestedMsg< T >, N > msgs, FType ftransleaf) |
Recursively transform the tuple structure in expr and msgs along with it. More... | |
template<typename T , std::size_t N, typename FType > | |
StructInfo | TransformTupleLeaf (StructInfo sinfo, std::array< NestedMsg< T >, N > msgs, FType ftransleaf) |
Recursively transform the tuple structure in sinfo and msgs along with it. More... | |
template<typename T > | |
Optional< T > | MatchStructInfo (const Expr &expr) |
Match and check if expr have StructInfo T and return it. More... | |
template<typename T > | |
const T * | GetStructInfoAs (const Expr &expr) |
Get the structure info of a given expr and try to cast it as const T*. More... | |
StructInfo | GetStructInfo (const Expr &expr) |
Get the underlying structure info of expr. More... | |
bool | HasVoidStructInfo (const Expr &expr) |
Whether the expr has void struct info. More... | |
void | UpdateStructInfo (Expr expr, StructInfo struct_info) |
Update the struct info of an Expr. More... | |
TVM_ALWAYS_INLINE TVMRetValue | CallPackedWithArgsInArray (const runtime::PackedFunc f, const Array< ObjectRef > &args) |
Helper function to unpack arguments in the array as parameters for the given packed function. More... | |
Expr | Bind (const Expr &expr, const tvm::Map< Var, Expr > &binds, const tvm::Map< tir::Var, PrimExpr > &symbolic_var_map={}) |
Bind the variables to a Relax expression. This is a helper function usually called by other pass functions to help optimizations. If any free variables are introduced into a function, those are added to the function parameters. Additionally this may change the order of parameters if you map a variable to a variable. More... | |
StructInfo | Bind (const StructInfo &sinfo, const tvm::Map< tir::Var, PrimExpr > &symbolic_var_map) |
Bind the symbolic variables to a StructInfo. This is a helper function usually called by other pass functions to help optimizations. More... | |
tvm::Map< tir::Var, PrimExpr > | InferSymbolicVarMap (const tvm::Map< relax::Var, relax::Expr > &binds, arith::Analyzer *analyzer) |
Infer a binding map for symbolic variables. More... | |
bool | IsBoolStructInfo (const StructInfo &sinfo, bool permit_unknown_rank=true, bool permit_unknown_dtype=true) |
Check if the given StructInfo is for a boolean scalar (tensor of rank 0 with a boolean dtype). More... | |
bool | IsLeafOrTuple (const Expr &expr) |
Check if the given expression is a "leaf" node or tuple node for normalization purposes. More... | |
bool | IsImpureCall (const Call &call) |
Check if the given Call node is an impure operation. If the callee is a general expression, this simply requires checking the purity field of the FuncStructInfo. If it is an Op, then this checks the fPurity field. More... | |
Function | CopyWithNewVars (Function func) |
Copy the given function. All variables that are bound inside the original function would be copied to satisfy the restriction in the well-formed check: Variables in Relax must be bound exactly once. This also ensures that both the function and its copy can be inserted into the same IRModule, and be asserted on the structural equality agaisnt IRModule created by TVMScript. More... | |
Expr | ToNonDataflow (const Expr &e) |
Transform all dataflow structure to non-dataflow version. More... | |
Expr | GetBoundValue (const Binding &b) |
Get the value bound in the binding. More... | |
using tvm::relax::Expr = typedef RelaxExpr |
using tvm::relax::ExprNode = typedef RelaxExprNode |
using tvm::relax::FCallPacked = typedef String |
Packed function implementation for operators. The relax operator will be lowered to this packed function call during codegen.
using tvm::relax::FCodegen = typedef runtime::TypedPackedFunc<Array<ObjectRef>(Array<MatchResult> match_results)> |
using tvm::relax::FInferStructInfo = typedef runtime::TypedPackedFunc<StructInfo(const Call& call, const BlockBuilder& ctx)> |
Infer output struct info given the call.
call | The call expression to be derived. |
ctx | The builder context. |
using tvm::relax::FLegalize = typedef runtime::TypedPackedFunc<Expr(const BlockBuilder& bb, const Call& call)> |
The function type of a legalization function.
A legalization function is used to replace a relax::Call
with more concrete implementations. For example, the operation relax.op.add
may be replaced with a call to a TIR function implementing addition of two tensors.
The purpose of FLegalize
is to remove calls to the operator while lowering. Therefore, unlike FNormalize
, the resulting expression may not contain the original operator.
bb | The BlockBuilder context. |
call | The call to be legalized. |
using tvm::relax::FLowerBuiltin = typedef runtime::TypedPackedFunc<Expr(const BlockBuilder& bb, const Call& call)> |
The function type of a function to lower the runtime builtin.
A builtin function may be lowered to a lowered form in LowerRuntimeBuiltin
.
bb | The BlockBuilder context. |
call | The call to be lowered. |
using tvm::relax::FNormalize = typedef runtime::TypedPackedFunc<Expr(const BlockBuilder& bb, Call call)> |
The function type of a normalization function.
A normalization function is used when a relax::Call
may be expressed in multiple syntactically valid and semantically equivalent forms, to normalize to a single representation.
Note: FNormalize
is applied for each expression as part of the relax::BlockBuilder
. While operator-specific validation may be performed within the FNormalize
implementation, ensuring that errors are caught as early as possible, this should only be used when validation is fast to apply. If the validation logic may be slow, it should instead be implemented in FValidate
, which is only run as part of the well-formed checker.
bb | The BlockBuilder context. |
call | The call to be normalized. It is provided by-value, to avoid copies for the common case where the call is already normalized. |
using tvm::relax::FPrimalGradient = typedef runtime::TypedPackedFunc<tvm::Array<Expr>( const Var& orig_var, const Call& orig_call, const Var& output_grad, const BlockBuilder& ctx)> |
Gradient for a specific op.
orig_var | the original var corresponding to orig_call. |
orig_call | the original Call(op) expr. |
output_grad | the gradient of the Expr. |
ctx | the current block builder context. |
using tvm::relax::FValidate = typedef runtime::TypedPackedFunc<void(const Call& call)> |
The function type of a validation function.
A validation function is used to define constraints that should be verified for an operator as part of the well-formed checker.
Note: FValidate
is only applied as part of the well-formed checker. While this minimizes overhead while compiling Relax, this delay between generating an ill-formed relax::Call
and identifying the ill-formed call may complicate debugging. If the validation logic is very fast to check, and doing so would not introduce a significant overhead, consider validating as part of FNormalize
, which is applied by the block builder for each relax::Call
.
call | The call to be validated. |
using tvm::relax::StructInfoDeriveFunc = typedef TypedEnvFunc<StructInfo(const Call& call, const BlockBuilder& ctx)> |
custom-defined StructInfo derivation function.
call | The call expression to be derived. |
ctx | The builder context. |
using tvm::relax::TensorType = typedef TensorType |
using tvm::relax::TensorTypeNode = typedef TensorTypeNode |
using tvm::relax::TIRPattern = typedef tir::PrimFunc |
|
strong |
Fine grained result of base check.
This analysis comes with different levels of checking failures that can help to customize the compilation decisions.
For a given pair of lhs_struct_info, rhs_struct_info. We adopt the following terminology:
See the definition of each level below.
Enumerator | |
---|---|
kFailL0 | The two value sets have no intersection at all: Interset(LSet, RSet) = empty. |
kFailL1 | LSet is not superset of RSet by only looking at static information.
|
kFailL2 | WLSet is not superset of RSet because of mismatch in value information. L1-level mismatches in params of FuncStructInfo is categorized as If lhs is FuncStructInfo, then L1-level mismatch in its params is categorized as L2-level mismatch for lhs. Design considerations for functions:
|
kPass | LSet is superset of RSet. |
tvm::Array<GlobalVar> tvm::relax::AllGlobalVars | ( | const Expr & | expr | ) |
Get all global variables from expression expr.
AllVars is a superset of BoundVars and FreeVars. The union of BoundVars and FreeVars is Allvars.
expr | the expression. |
tvm::Array<Var> tvm::relax::AllVars | ( | const Expr & | expr | ) |
Get all variables from expression expr.
expr | the expression. |
OpPatternKind tvm::relax::AnalyzeOpPatternKind | ( | const tir::PrimFunc & | func | ) |
Map<Var, Expr> tvm::relax::AnalyzeVar2Value | ( | const DataflowBlock & | dfb | ) |
Analyze var -> value mapping from VarBindings.
dfb | The dataflow block to check. |
Analyze var -> value mapping from VarBindings.
expr | The expression to check. |
Expr tvm::relax::Bind | ( | const Expr & | expr, |
const tvm::Map< Var, Expr > & | binds, | ||
const tvm::Map< tir::Var, PrimExpr > & | symbolic_var_map = {} |
||
) |
Bind the variables to a Relax expression. This is a helper function usually called by other pass functions to help optimizations. If any free variables are introduced into a function, those are added to the function parameters. Additionally this may change the order of parameters if you map a variable to a variable.
expr | The input expression. |
binds | The variable to expression map that will be used to help the binding. |
symbolic_var_map | The map from symbolic var to the expr it binds to. |
StructInfo tvm::relax::Bind | ( | const StructInfo & | sinfo, |
const tvm::Map< tir::Var, PrimExpr > & | symbolic_var_map | ||
) |
Bind the symbolic variables to a StructInfo. This is a helper function usually called by other pass functions to help optimizations.
tvm::Array<Var> tvm::relax::BoundVars | ( | const Expr & | expr | ) |
Get all bound variables from expression expr.
Bound variables are all variables that are declared in the expr. They only have meaning inside that expr, and can only be used in it.
expr | the expression. |
TVM_ALWAYS_INLINE TVMRetValue tvm::relax::CallPackedWithArgsInArray | ( | const runtime::PackedFunc | f, |
const Array< ObjectRef > & | args | ||
) |
Helper function to unpack arguments in the array as parameters for the given packed function.
bool tvm::relax::CanProveShapeEqual | ( | const Array< PrimExpr > & | lhs, |
const Array< PrimExpr > & | rhs, | ||
arith::Analyzer * | ana | ||
) |
Can prove the two symbolic shape arrays equals to each other.
lhs | The left operand. |
rhs | The right operand. |
ana | The analyzer used for integer analysis. |
bool tvm::relax::CanProveShapeEqual | ( | const Expr & | lhs, |
const Expr & | rhs, | ||
arith::Analyzer * | ana | ||
) |
Can prove the two symbolic shape expressions equals to each other.
lhs | The left operand. |
rhs | The right operand. |
ana | The analyzer used for integer analysis. |
Array<PrimExpr> tvm::relax::CollectNonNegativeExpressions | ( | const StructInfo & | sinfo | ) |
Collect expressions whose usage requires them to be non-negative.
Any PrimExpr that is used as a tensor shape, or as an element in a ShapeExpr, may not be negative. This utility function can be used to generate assertions prior to calling a kernel, or to provide assumptions within a kernel that may be useful for simplification.
sinfo | The struct info to be analyzed |
VarUsageInfo tvm::relax::CollectVarUsage | ( | const Expr & | expr | ) |
Collect variable bindings and usage.
This function is equivalent to calling both FunctionUseDef and AnalyzeVar2Value, but requires only a single traversal of the expression.
expr | The expression to analyze |
NestedMsg<T> tvm::relax::CombineNestedMsg | ( | NestedMsg< T > | lhs, |
NestedMsg< T > | rhs, | ||
FType | fcombine | ||
) |
Recursively combine two nested message into one.
This function requires the two messages to be compatible with each other. The combination rule is as follows:
lhs | The left operand. |
rhs | The right operand. |
fcombine | with signature T fcombine(T lhs, T rhs) |
T | the content type of nested msg |
FType | combine function type. |
bool tvm::relax::ContainsImpureCall | ( | const Expr & | expr, |
const Optional< Expr > & | own_name = Optional< Expr >(nullptr) |
||
) |
Check if the given expression (likely a function body) contains any impure calls.
expr | The expression to be examined. If expr is a function, we check the body. |
own_name | (Optional.) If we are checking a recursive function body, the caller can pass the function's name so recursive calls can be ignored in the check (must be a Var or GlobalVar). |
Copy the given function. All variables that are bound inside the original function would be copied to satisfy the restriction in the well-formed check: Variables in Relax must be bound exactly once. This also ensures that both the function and its copy can be inserted into the same IRModule, and be asserted on the structural equality agaisnt IRModule created by TVMScript.
func | The relax function to copy. |
Map<Var, Array<Var> > tvm::relax::DataflowBlockUseDef | ( | const DataflowBlock & | dfb | ) |
Get the use-def chain of variables inside a dataflow block.
dfb | The dataflow block to be analyzed. |
void tvm::relax::DecomposeNestedMsg | ( | Expr | expr, |
NestedMsg< T > | msg, | ||
FType | fvisitleaf | ||
) |
Recursively decompose the tuple structure in expr and msg along with it.
This function will call fvisitleaf for each leaf expression in expr. This function will throw an error if the nesting structure in msg does not match the tuple nesting structure in expr.
expr | The input expression to be decomposed. |
msg | The input nested message. |
fvisitleaf | with signature fvisitleaf(Expr expr, NestedMsg<T> msg) |
T | the content type of nested msg |
FType | The visit function type. |
Array<tir::Var> tvm::relax::DefinableTIRVarsInStructInfo | ( | const StructInfo & | sinfo | ) |
Get the TIR variables that appear in the input struct info.
Returns all symbolic variables that are definable based on, and used within, the StructInfo.
sinfo | The struct info object to be analyzed. |
Get the TIR variables that defined in the input function. The returned list is deduplicated - each TIR variable will appear at most once.
expr | The relax expression (e.g. a Function) to be analyzed. |
StructInfo tvm::relax::DeriveCallRetStructInfo | ( | const FuncStructInfo & | finfo, |
const Call & | call, | ||
const BlockBuilder & | ctx, | ||
arith::Analyzer * | ana = nullptr |
||
) |
finfo | The function struct info. |
call | The call expression to be derived. |
ctx | The builder context. |
ana | Optional context analyzer to prove symbolic expression equality. |
tvm::Array<tvm::Array<GlobalVar> > tvm::relax::DetectRecursion | ( | const IRModule & | m | ) |
Find all sets of recursive or mutually recursive functions in the module.
Two or more functions are mutually recursive if there is some cycle of references among them. For example, if there are two functions A and B, they are mutually recursive if A calls B and B calls A. Another case would be with three functions A, B, and C, where A calls B, B calls C, and C calls A.
(Note that functions do not have to call each other to reference each other. For example, if a function returns another function, that is still a reference that could potentially be recursive, even without a call.)
If a function is simply recursive and not mutually recursive with any other, it will be reported as a group by itself.
m | The module |
bool tvm::relax::Equal | ( | const NestedMsg< T > & | lhs, |
const NestedMsg< T > & | rhs, | ||
FType | fequal | ||
) |
Recursively compare two nested messages.
lhs | The left operand. |
rhs | The right operand. |
fequal | The equal functor with signature bool fequal(T, T) |
T | the content type of nested msg |
FType | the equal comparator type |
StructInfo tvm::relax::EraseToWellDefined | ( | const StructInfo & | info, |
Map< tir::Var, PrimExpr > | shape_var_map, | ||
Map< Var, Expr > | var_map, | ||
arith::Analyzer * | ana = nullptr |
||
) |
EraseToWellDefined variant with map.
info | The struct info. |
shape_var_map | map to specify whether a symbolic shape var is defined and the value it maps to, return nullopt if var is undefined. |
var_map | map to specify whether a var is defined in the target scope and the value it maps to, return nullopt if var is undefined. |
ana | Optional context analyzer to prove symbolic expression equality. |
StructInfo tvm::relax::EraseToWellDefined | ( | const StructInfo & | info, |
std::function< Optional< PrimExpr >(const tir::Var &var)> | f_shape_var_map = nullptr , |
||
std::function< Optional< Expr >(const Var &var)> | f_var_map = nullptr , |
||
arith::Analyzer * | ana = nullptr |
||
) |
Erase the info to a corresponding more coarse grained struct info that is still well-defined(with all the vars in scope).
When we are returning a StructInfo to another scope, it is important to remember that StructInfo may carry dependencies on var that is not defined the other scope.
In such cases, it is important to call EraseToWellDefined to get another StructInfo that only contains the vars that are defined in the target scope.
For example, consider the following function
In the above code, the return value y have shape (n + 1, k + 2)
, However, at the level of function signature, only n, m are defined, k is undefined here.
When we call EraseToWellDefined(R.Tensor[(n + 1, k + 2)], fshape_var_map={n: n, m: m}), we will obtain R.Tensor(ndim=2), which is an erased info that does not depend on k(which is undefined from parameter signature).
However, if we call EraseToWellDefined(R.Tensor[(n + 1, m)], fshape_var_map={n: n, m: m}), Then the return value will be R.Tensor[(n + 1, m)], because both n and m are defined.
We can also make these var map to return a different expression. For example, EraseToWellDefined(R.Tensor[(n + 1, m)], fshape_var_map={n: 2, m: m}) will give us R.Tensor[(3, m)], where n get replaced by 2.
Use this function in the following scenarios:
info | The struct info. |
f_shape_var_map | callback function to specify whether a symbolic shape var is defined and the value it maps to, return nullopt if var is undefined. |
f_var_map | callback function to specify whether a var is defined in the target scope and the value it maps to, return nullopt if var is undefined. |
ana | Optional context analyzer to prove symbolic expression equality. |
Optional<Map<DFPattern, Expr> > tvm::relax::ExtractMatchedExpr | ( | DFPattern | pattern, |
Expr | expr, | ||
Optional< runtime::Map< Var, Expr >> | bindings = NullOpt |
||
) |
Optional<Expr> tvm::relax::FindImpureCall | ( | const Expr & | expr, |
const Optional< Expr > & | own_name = Optional< Expr >(nullptr) |
||
) |
Check if the given expression (likely a function body) contains any impure calls.
expr | The expression to be examined. If expr is a function, we check the body. |
own_name | (Optional.) If we are checking a recursive function body, the caller can pass the function's name so recursive calls can be ignored in the check (must be a Var or GlobalVar). |
void tvm::relax::ForEachLeaf | ( | const NestedMsg< T > & | msg, |
FType | fvisit | ||
) |
Apply fvisit for each leaf elements in the nested message.
fvisit | The visit callback. |
msg | The input nested message. |
T | the content type of nested msg |
FType | the visitor type with signature void fvisit(T) |
Get the TIR variables that are used but not defined in the input function. The returned list is deduplicated - each TIR variable will appear at most once.
expr | The relax expression (e.g. a Function) to be analyzed. |
tvm::Array<Var> tvm::relax::FreeVars | ( | const Expr & | expr | ) |
Get free type parameters from expression expr.
Free variables are variables that are not bound by a varbinding or a function parameter in the context.
expr | the expression. |
Get the use-def chain of variables inside a function.
expr | The expression to be analyzed. |
Get the shape of Expr.
expr | The input expr. |
Type tvm::relax::GetStaticType | ( | const StructInfo & | info | ) |
Get the corresponding static type from a given struct info.
info | The struct info. |
|
inline |
Get the underlying structure info of expr.
expr | The input expression. |
|
inline |
Get the structure info of a given expr and try to cast it as const T*.
expr | The input expression. |
T | the underlying structure info type |
bool tvm::relax::HasReshapePattern | ( | const tir::PrimFunc & | func | ) |
Check if the given PrimFunc is essentially doing a reshape operation. The reshape operation also includes expand_dims, squeeze, flatten, etc.
Here the allowed reshape pattern is: for example, assume the operation is B[l_0, l_1, ..., l_b] = A[r_0, r_1, ..., r_a]
, we check if we can prove that the flattened index of l_0, ..., l_b under buffer B equals to the flattened index of r_0, ..., r_a under buffer A.
func | The function to be examined. |
|
inline |
Whether the expr has void struct info.
expr | The input expression. |
tvm::Map<tir::Var, PrimExpr> tvm::relax::InferSymbolicVarMap | ( | const tvm::Map< relax::Var, relax::Expr > & | binds, |
arith::Analyzer * | analyzer | ||
) |
Infer a binding map for symbolic variables.
If a set of relax variables are replaced within an expression, this may result in removal of the definition site of a symbolic variable. This utility function determines the symbolic variable replacements that can be inferred based on the replaced relax variables, and can be used alongside the Bind
utility function to replace both the relax variables and the implied symbolic variables.
binds | A map of relax variables to relax expressions |
analyzer | The analyzer to use for simplifications |
bool tvm::relax::IsBaseOf | ( | const StructInfo & | base, |
const StructInfo & | derived, | ||
arith::Analyzer * | ana = nullptr |
||
) |
Check the relation of two struct info to see if one subsumes another one.
base | The base struct info. |
derived | The derived struct info. |
ana | Optional context analyzer to prove symbolic expression equality. |
bool tvm::relax::IsBoolStructInfo | ( | const StructInfo & | sinfo, |
bool | permit_unknown_rank = true , |
||
bool | permit_unknown_dtype = true |
||
) |
Check if the given StructInfo is for a boolean scalar (tensor of rank 0 with a boolean dtype).
sinfo | The input StructInfo. |
permit_unknown_rank | If true, it will permit the input type to have unknown rank (ndim of -1), which will require a dynamic check. |
permit_unknown_dtype | If true, it will permit the input type to have an unknown dtype (namely, void), which will require a dynamic check. |
CallPattern tvm::relax::IsCallDPSPacked | ( | const String & | name, |
Optional< TuplePattern > | args = NullOpt |
||
) |
Syntatic Sugar for call_dps_packed (return a tensor)
CallPattern tvm::relax::IsCallDPSPacked | ( | const String & | name, |
TuplePattern | var_args | ||
) |
Syntatic Sugar for call_dps_packed (return a tuple of tensor)
CallPattern tvm::relax::IsCallTIR | ( | const String & | name, |
Optional< TuplePattern > | args = NullOpt |
||
) |
Syntatic Sugar for call_tir (return a tensor)
CallPattern tvm::relax::IsCallTIR | ( | const String & | name, |
TuplePattern | var_args | ||
) |
Syntatic Sugar for call_tir (return a tuple of tensor)
ConstantPattern tvm::relax::IsConst | ( | ) |
Syntatic Sugar for creating a ConstantPattern.
ExprPattern tvm::relax::IsExpr | ( | const Expr & | expr | ) |
Syntatic Sugar for creating a ExprPattern.
bool tvm::relax::IsImpureCall | ( | const Call & | call | ) |
Check if the given Call node is an impure operation. If the callee is a general expression, this simply requires checking the purity field of the FuncStructInfo. If it is an Op, then this checks the fPurity
field.
call | The input call |
bool tvm::relax::IsLeafOrTuple | ( | const Expr & | expr | ) |
Check if the given expression is a "leaf" node or tuple node for normalization purposes.
The following expressions are defined as leaf nodes: Var, Constant, ShapeExpr, GlobalVar, Op, ExternFunc.
Tuples are included in this list mainly for convenience in grouping operator arguments. Note: Since tuples can contain nested expressions, it is necessary to ensure that values nested inside them are also leaves.
expr | The input expression |
ExprPattern tvm::relax::IsOp | ( | const String & | op_name | ) |
Syntatic Sugar for creating a ExprPattern base on an Op.
Syntatic Sugar for creating TuplePattern or UnorderedTuplePattern (unordered=true)
TupleGetItemPattern tvm::relax::IsTupleGetItem | ( | const DFPattern | tuple, |
int | index = -1 |
||
) |
Syntatic Sugar for creating a TupleGetItemPattern.
VarPattern tvm::relax::IsVar | ( | const String & | name | ) |
Syntatic Sugar for creating a VarPattern with a name.
NestedMsg<T> tvm::relax::MapNestedMsg | ( | NestedMsg< T > | msg, |
FType | fmapleaf | ||
) |
Recursively map a nested message to another one, with leaf mapped by the input fmapleaf.
msg | The nested message to be mapped. |
fmapleaf | The leaf map function, with signature NestedMsg<T> fmapleaf(T msg) |
T | The content type of nested message. |
FType | The leaf map function type. |
NestedMsg<T> tvm::relax::MapToNestedMsg | ( | Expr | expr, |
FType | fmapleaf | ||
) |
Map expr with possible nested-tuple to nested message.
This function will unpack recursive tuples and run fmapleaf for each leaf, then recursively combines the results together into a NestedMsg.
The nesting structure will corresponds to the tuple structure.
expr | The input expression. |
fmapleaf | The mapping function for each leaf with signature NestedMsg<T> fmap(Expr) |
T | the content type of nested msg |
FType | The mapping function type |
NestedMsg<T> tvm::relax::MapToNestedMsg | ( | StructInfo | sinfo, |
FType | fmapleaf | ||
) |
Map structinfo with possible nested-sinfo to nested message.
This function will unpack recursive sinfo and run fmapleaf for each leaf, then recursively combines the results together into a NestedMsg.
The nesting structure will corresponds to the tuple structure.
sinfo | The input struct info. |
fmapleaf | The mapping function for each leaf with signature NestedMsg<T> fmap(StructInfo) |
T | the content type of nested msg |
FType | The mapping function type |
NestedMsg<T> tvm::relax::MapToNestedMsgBySInfo | ( | Expr | expr, |
FType | fmapleaf | ||
) |
Map expr with possible nested-tuple to nested message.
This function will unpack recursive expr by its struct info and run fmapleaf for each leaf, then recursively combines the results together into a NestedMsg.
The nesting structure will corresponds to the struct info of expr.
expr | The input expression which should have struct info. |
fmapleaf | The mapping function for each leaf with signature NestedMsg<T> fmapleaf(Expr) |
T | the content type of nested msg |
FType | The mapping function type |
bool tvm::relax::MatchExpr | ( | DFPattern | pattern, |
Expr | expr, | ||
Optional< runtime::Map< Var, Expr >> | bindings = NullOpt |
||
) |
Determine if a pattern matches an expression.
expr
) syntactically through one given pattern (pattern
).pattern | The pattern to match |
expr | The expression to match |
bindings | The mapping from relax.Var to relax.Expr |
Optional<Map<DFPattern, Var> > tvm::relax::MatchGraph | ( | const PatternContext & | ctx, |
const DataflowBlock & | dfb | ||
) |
Match a sub-graph in a DataflowBlock with a graph of patterns and return the mapping.
ctx | The graph-wise patterns. |
dfb | The function to match. |
Match and check if expr have StructInfo T and return it.
expr | The input expression. |
T | the underlying structure info type |
Return a mapping from variable name to its Bindings.
fn | The function to be analyzed. |
TargetType tvm::relax::NestedMsgTo | ( | NestedMsg< T > | msg, |
FMapLeaf | fmapleaf, | ||
FCombine | fcombine | ||
) |
Map nested message back to TargetType.
This function will decompose the nested message and run fmapleaf for each leaf message and get the leaf value, then recursively combines the results by fcombine.
msg | The input nested message. |
fmapleaf | The mapping function for each leaf with signature TargetType fmapleaf(Optional<T>) . |
fcombine | The function for combining all childs of a node into TargetType with signature TargetType fmapleaf(Array<TargetType>) . |
TargetType | the target type to map nested msg to. |
T | the content type of nested msg. |
FMapLeaf | The leaf mapping function type. |
FCombine | The combining function type. |
Expr tvm::relax::NestedMsgToExpr | ( | NestedMsg< T > | msg, |
FType | fmapleaf | ||
) |
Map nested message back to the expr.
This function will decompose the nested message and run fmapleaf for each leaf message and get the leaf expr, then recursively combines the results as tuple expr.
msg | The input nested message. |
fmapleaf | The mapping function for each leaf with signature Expr fmapleaf(Optional<T>) . |
T | the content type of nested msg. |
FType | The mapping function type. |
PatternSeq tvm::relax::OnlyUsedBy | ( | const PatternSeq & | lhs, |
const PatternSeq & | rhs, | ||
int | index = -1 |
||
) |
Create only-used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned.
lhs | Left hand side of the used-by relationship. |
rhs | Right hand side of the used-by relationship. |
index | lhs[-1] is used as the index'th argument of rhs[0]. |
PatternSeq tvm::relax::operator>> | ( | const PatternSeq & | lhs, |
const PatternSeq & | rhs | ||
) |
Syntax sugar of OnlyUsedBy(lhs, rhs, -1).
PatternSeq tvm::relax::operator^ | ( | const PatternSeq & | lhs, |
const PatternSeq & | rhs | ||
) |
Syntax sugar of UsedBy(lhs, rhs, -1).
Remove unused statements inside DataflowBlocks.
expr | The expression (typically a relax::Function) from which to remove unused statements. |
Function tvm::relax::RewriteBindings | ( | const PatternContext & | ctx, |
runtime::TypedPackedFunc< Map< Var, Expr >(Map< DFPattern, Var >, Map< Var, Expr >)> | rewriter, | ||
Function | f | ||
) |
Rewrite a function with the given pattern and the rewriter function.
ctx | The pattern constraint context under which rewriting takes place. |
rewriter | The function to be called on a successful matching for rewriting. Given the map of patterns and corresponding variables (bound variables or parameters), it should return a map that specifies new values for matched bound variables. |
f | The function to rewrite |
Function tvm::relax::RewriteCall | ( | const DFPattern & | pattern, |
runtime::TypedPackedFunc< Expr(Expr, Map< DFPattern, Expr >)> | rewriter, | ||
Function | func | ||
) |
Rewrite a function with the given pattern and the rewriter function.
Pattern match and replace at an expression level. This level of granularity does not allow simultaneous replacement cannot be performed. In addition, removal of bindings cannot be performed explicitly, and is only done implicitly through RemoveAllUnused. See also RewriteBindings
, which performs replacement on a block-level, and does not have these restrictions.
pattern | The pattern to be replaced |
rewriter | The function to be called on a successful pattern matching. Given the matched expression and a map of sub-matches, it should return the replacement expression. If the expression doesn't require updating (e.g. replacement required checks beyond those expressed in the pattern), it should return the expression unmodified. |
func | The function to rewrite |
BaseCheckResult tvm::relax::StructInfoBaseCheck | ( | const StructInfo & | base, |
const StructInfo & | derived, | ||
arith::Analyzer * | ana = nullptr |
||
) |
Run a base check to see if base subsumes derived.
This function returns fine-grained base-check result on reasons of failure.
base | The base struct info. |
derived | The derived struct info. |
ana | Optional context analyzer to prove symbolic expression equality. |
PrimExpr tvm::relax::StructInfoBaseCheckPrecondition | ( | const StructInfo & | base, |
const StructInfo & | derived | ||
) |
Return the condition for which base is a superset of derived.
This function returns finer-grained conditions for kFailL2 than StructInfoBaseCheck
If the returned expression is true, or simplifies to true, then base is a superset of derived. If the returned expression is false, or simplifies to false, then base is not a superset of derived.
If the returned expression is neither true nor false, it is an expression in terms of the symbolic variables available in base
and derived
.
base | The base struct info. |
derived | The derived struct info. |
StructInfo tvm::relax::StructInfoFromType | ( | const Type & | type | ) |
Get the corresponding struct info from static type.
type | The input type |
StructInfo tvm::relax::StructInfoLCA | ( | const StructInfo & | lhs, |
const StructInfo & | rhs, | ||
arith::Analyzer * | ana = nullptr |
||
) |
Unify the two struct info to their least common ancestor.
lhs | The left operand. |
rhs | The right operand. |
ana | Optional context analyzer to prove symbolic expression equality. |
Map<tir::Block, Map<ObjectRef, tir::IndexMap> > tvm::relax::SuggestLayoutTransforms | ( | const Function & | fn, |
Array< tir::IndexMap > | write_buffer_transformations | ||
) |
Using the layout transforms on the outputs, suggest layout transformation on the blocks and buffers for the PrimFunc.
fn | The PrimFunc to be analyzed. |
write_buffer_transformations | Array of IndexMap transformations on PrimFunc outputs. |
fn
. For each block the returned value is a map from the object (block or buffer) to it's index map transformation. Array<tir::Var> tvm::relax::TIRVarsInStructInfo | ( | const StructInfo & | sinfo | ) |
Get the TIR variables that appear in the input struct info. The returned list is deduplicated - each TIR variable will appear at most once.
sinfo | The struct info object to be analyzed. |
Transform all dataflow structure to non-dataflow version.
Expr tvm::relax::TransformTupleLeaf | ( | Expr | expr, |
std::array< NestedMsg< T >, N > | msgs, | ||
FType | ftransleaf | ||
) |
Recursively transform the tuple structure in expr and msgs along with it.
This function will call ftransleaf for each leaf expression in expr. This function will throw an error if the nesting structure in msg does not match the tuple nesting structure in expr.
expr | The input expression to be transform. |
msgs | The input messages to guide the transformation. |
ftransleaf | with signature ftransleaf(Expr, Array<NestedMsg<T>>)->Expr |
T | the content type of nested msg |
N | the number of messages |
FType | The visit function type. |
StructInfo tvm::relax::TransformTupleLeaf | ( | StructInfo | sinfo, |
std::array< NestedMsg< T >, N > | msgs, | ||
FType | ftransleaf | ||
) |
Recursively transform the tuple structure in sinfo and msgs along with it.
This function will call ftransleaf for each leaf sinfo in sinfo. This function will throw an error if the nesting structure in msg does not match the tuple nesting structure in sinfo.
sinfo | The input sinfo to be transform. |
msgs | The input messages to guide the transformation. |
ftransleaf | with signature ftransleaf(StructInfo, Array<NestedMsg<T>>)->StructInfo |
T | the content type of nested msg |
N | the number of messages |
FType | The visit function type. |
void tvm::relax::UpdateStructInfo | ( | Expr | expr, |
StructInfo | struct_info | ||
) |
Update the struct info of an Expr.
expr | The Expr whose struct info to be updated. |
struct_info | The struct_info assigned. |
PatternSeq tvm::relax::UsedBy | ( | const PatternSeq & | lhs, |
const PatternSeq & | rhs, | ||
int | index = -1 |
||
) |
Create used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned.
lhs | Left hand side of the used-by relationship. |
rhs | Right hand side of the used-by relationship. |
index | lhs[-1] is used as the index'th argument of rhs[0]. |
Check if the IRModule is well formed.
obj | The IRModule or relax::Function to check. |
check_struct_info | A boolean flag indicating if the property "every Expr must have defined structure info" will be checked. |
check_struct_info
might be false, so that other well-formed requirements will be well tested and will not be blocked by not having structure info. WildcardPattern tvm::relax::Wildcard | ( | ) |
Syntatic Sugar for creating a WildcardPattern.
Call tvm::relax::WithFields | ( | Call | call, |
Optional< Expr > | opt_op = Optional< Expr >() , |
||
Optional< Array< Expr >> | opt_args = Optional< Array< Expr >>() , |
||
Optional< Attrs > | opt_attrs = Optional< Attrs >() , |
||
Optional< Array< StructInfo >> | opt_sinfo_args = Optional< Array< StructInfo >>() , |
||
Optional< Span > | opt_span = Optional< Span >() |
||
) |
Returns call
with the given properties. A null property denotes 'no change'. Returns call
if all properties are unchanged. Otherwise, returns a copy with the new fields.
If tvm::relax::WithFields | ( | If | if_expr, |
Optional< Expr > | opt_cond = Optional< Expr >() , |
||
Optional< Expr > | opt_true_branch = Optional< Expr >() , |
||
Optional< Expr > | opt_false_branch = Optional< Expr >() , |
||
Optional< Span > | opt_span = Optional< Span >() |
||
) |
Returns if_expr
with the given properties. A null property denotes 'no change'. Returns if_expr
if all properties are unchanged. Otherwise, returns a copy with the new fields.
Tuple tvm::relax::WithFields | ( | Tuple | tuple, |
Optional< Array< Expr >> | opt_fields = Optional< Array< Expr >>() , |
||
Optional< Span > | opt_span = Optional< Span >() |
||
) |
Returns tuple
with the given properties. A null property denotes 'no change'. Returns tuple
if all properties are unchanged. Otherwise, returns a copy with the new fields.
TupleGetItem tvm::relax::WithFields | ( | TupleGetItem | tuple_get_item, |
Optional< Expr > | opt_tuple = Optional< Expr >() , |
||
Optional< Integer > | opt_index = Optional< Integer >() , |
||
Optional< Span > | opt_span = Optional< Span >() |
||
) |
Returns tuple_get_item
with the given properties. A null property denotes 'no change'. Returns tuple_get_item
if all properties are unchanged. Otherwise, returns a copy with the new fields.