tvm
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
tvm::relay Namespace Reference

Relay: a high level functional IR for TVM. More...

Namespaces

 attr
 namespace of the attributes that can be attached to a relay::Function.
 
 legalize
 
 qnn
 
 transform
 

Classes

class  PatternNode
 Base type for declaring relay pattern. More...
 
class  Pattern
 Pattern is the base type for an ADT match pattern in Relay. More...
 
class  PatternWildcardNode
 PatternWildcard container node. More...
 
class  PatternWildcard
 
class  PatternVarNode
 PatternVar container node. More...
 
class  PatternVar
 
class  PatternConstructorNode
 PatternVar container node. More...
 
class  PatternConstructor
 
class  PatternTupleNode
 PatternVar container node. More...
 
class  PatternTuple
 
class  ClauseNode
 Clause container node. More...
 
class  Clause
 
class  MatchNode
 Match container node. More...
 
class  Match
 
struct  ArgsortAttrs
 Attributes used in argsort operators. More...
 
struct  TopKAttrs
 
struct  SearchSortedAttrs
 
struct  CastHintAttrs
 Annotate an expression to be cast into specific data type. More...
 
struct  CompilerAttrs
 Options for the operators used to annotate a compiler. More...
 
struct  BitPackAttrs
 Attributes used in bitpack operators. More...
 
struct  BinaryConv2DAttrs
 Attribues used in bitserial convolution operators. More...
 
struct  BinaryDenseAttrs
 
struct  CallLoweredAttrs
 Metadata for calls to TIR functions, useful for program analysis crossing Relay and TIR. More...
 
struct  DebugAttrs
 Options for the debug operators. More...
 
struct  DeviceCopyAttrs
 Options for the device copy operators. More...
 
struct  Resize1DAttrs
 Attributes used in image resize1d operator. More...
 
struct  Resize2DAttrs
 Attributes used in image resize2d operator. More...
 
struct  Resize3DAttrs
 Attributes used in image resize3d operator. More...
 
struct  CropAndResizeAttrs
 Attributes used in image crop_and_resize operator. More...
 
struct  Dilation2DAttrs
 Attributes used in dilation operators. More...
 
struct  AffineGridAttrs
 Attributes used in image affine_grid operator. More...
 
struct  GridSampleAttrs
 Attributes used in image grid_sample operator. More...
 
struct  AllocStorageAttrs
 Options for allocating storage. More...
 
struct  AllocTensorAttrs
 Options for allocating tensors. More...
 
struct  BiasAddAttrs
 Add a 1D Tensor to an axis of a data. More...
 
struct  Conv1DAttrs
 Attributes used in 1D convolution operators. More...
 
struct  Conv2DAttrs
 Attributes used in convolution operators. More...
 
struct  ConvWinogradWeightTransformAttrs
 Attributes used in winograd weight transformation operators. More...
 
struct  ConvGemmWeightTransformAttrs
 Attributes used in gemm weight transformation operators. More...
 
struct  Conv2DWinogradAttrs
 Attributes used in convolution operators with winograd algorithm. More...
 
struct  Conv2DWinogradNNPACKWeightTransformAttrs
 Attributes used in winograd weight transformation operators. More...
 
struct  Conv3DAttrs
 Attributes used in convolution operators. More...
 
struct  Conv3DTransposeAttrs
 Attributes used in transposed convolution operator. More...
 
struct  Conv3DWinogradAttrs
 Attributes used in 3d winograd convolution operators. More...
 
struct  SoftmaxAttrs
 Attributes used in softmax operators. More...
 
struct  Conv2DTransposeAttrs
 Attributes used in transposed convolution operator. More...
 
struct  DilateAttrs
 Attributes used in dilate operator. More...
 
struct  Conv1DTransposeAttrs
 Attributes used in 1D transposed convolution operator. More...
 
struct  MaxPool2DAttrs
 Attributes for max pool operator. More...
 
struct  AvgPool2DAttrs
 Attributes for avg pool operator. More...
 
struct  GlobalPool2DAttrs
 Attributes for global pool 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  MaxPool1DAttrs
 Attributes for 1D max pool operator. More...
 
struct  AvgPool1DAttrs
 Attributes for 1D avg pool operator. More...
 
struct  MaxPool3DAttrs
 Attributes for 3D max pool operator. More...
 
struct  AvgPool3DAttrs
 Attributes for 3D avg pool operator. More...
 
struct  MatmulAttrs
 Attributes for matmul operator. More...
 
struct  DenseAttrs
 Attributes for dense operator. More...
 
struct  DensePackAttrs
 Attributes for dense_pack operator. More...
 
struct  BatchMatmulAttrs
 Attributes for batch matmul operator. More...
 
struct  SparseDenseAttrs
 Attributes for sparse_dense operator. More...
 
struct  SparseTransposeAttrs
 Attributes for sparse_transpose operator. More...
 
struct  SparseConv2DAttrs
 Attributes for sparse_dense operator. More...
 
struct  FIFOBufferAttrs
 Attributes for FIFO buffer operator. More...
 
struct  UpSamplingAttrs
 Attributes for upsampling operator. More...
 
struct  UpSampling3DAttrs
 Attributes for upsampling3d operator. More...
 
struct  PadAttrs
 Attributes used for the padding operator. More...
 
struct  MirrorPadAttrs
 Attributes used for the MirrorPadding operator. More...
 
struct  LeakyReluAttrs
 Attributes for leaky relu operator. More...
 
struct  PReluAttrs
 Attributes for prelu operator. More...
 
struct  DropoutAttrs
 Attributes used in dropout operator. More...
 
struct  BatchNormAttrs
 Attributes used in batch_norm operator. More...
 
struct  InstanceNormAttrs
 Attributes used in instance_norm operator. More...
 
struct  LayerNormAttrs
 Attributes used in layer_norm operator. More...
 
struct  GroupNormAttrs
 Attributes used in group_norm operator. More...
 
struct  LRNAttrs
 Attributes for LRN operator. More...
 
struct  L2NormalizeAttrs
 Attributes for L2Normalize operator. More...
 
struct  DeformableConv2DAttrs
 Attributes for DeformableConv2D operator. More...
 
struct  SubPixelAttrs
 Attributes used in subpixel operators. More...
 
struct  CorrelationAttrs
 Attributes used in correlation operators. More...
 
struct  SpaceToBatchNDAttrs
 Attributes used in SpaceToBatchND operator. More...
 
struct  BatchToSpaceNDAttrs
 Attributes used in BatchToSpaceND operator. More...
 
struct  NLLLossAttrs
 Attributes used in NLLLoss operator. More...
 
struct  OnDeviceAttrs
 Attributes for the "on_device" annotation (ie operator). More...
 
struct  ThreefryGenerateAttrs
 
struct  UniformAttrs
 
struct  NormalAttrs
 
struct  MultinomialAttrs
 
struct  ReduceAttrs
 Attributes for Reduce operators. More...
 
struct  ArgReduceAttrs
 Attributes for Reduce operators which reduce by finding a single element. E.g. argmin. More...
 
struct  VarianceAttrs
 
struct  SlidingWindowAttrs
 Attributes used for the sliding_window operator. More...
 
struct  CastAttrs
 data type cast More...
 
struct  ExpandDimsAttrs
 Attributes used in expand_dims operators. More...
 
struct  DynExpandDimsAttrs
 Attributes used in dynamic expand_dims operators. More...
 
struct  ConcatenateAttrs
 Attributes used in concatenate operators. More...
 
struct  TransposeAttrs
 Attributes used in transpose operators. More...
 
struct  ReshapeAttrs
 Attributes used in reshape operators. More...
 
struct  ReshapeLikeAttrs
 Attributes used in MXNet-style reshape_like operators. More...
 
struct  ScatterElementsAttrs
 
struct  ScatterNDAttrs
 
struct  GatherAttrs
 
struct  GatherNDAttrs
 
struct  TakeAttrs
 
struct  InitOpAttrs
 Attributes that specify a tensor. More...
 
struct  ArangeAttrs
 Attributes used in arange operators. More...
 
struct  MeshgridAttrs
 Attributes used in meshgrid operators. More...
 
struct  StackAttrs
 Attributes used in stack operators. More...
 
struct  RepeatAttrs
 Attributes used in repeat operators. More...
 
struct  TileAttrs
 Attributes used in tile operators. More...
 
struct  ReverseAttrs
 Attributes used in reverse operators. More...
 
struct  ReverseSequenceAttrs
 Attributes used in reverse_sequence operators. More...
 
struct  SqueezeAttrs
 Attributes used in squeeze operators. More...
 
struct  SplitAttrs
 
struct  StridedSliceAttrs
 Attributes for StridedSlice operator. More...
 
struct  SliceLikeAttrs
 
struct  ClipAttrs
 Attributes for Clip operator. More...
 
struct  FixedPointMultiplyAttrs
 Attributes for FixedPointMultiply operator. More...
 
struct  FixedPointMultiplyPerAxisAttrs
 Attributes for per channel/per axes FixedPointMultiply operator. More...
 
struct  LayoutTransformAttrs
 Attributes for LayoutTransform operator. More...
 
struct  AutoSchedulerLayoutTransformAttrs
 Attributes for AutoSchedulerLayoutTransform operator. More...
 
struct  MetaScheduleLayoutTransformAttrs
 Attributes for MetaScheduleLayoutTransform operator. More...
 
struct  ShapeOfAttrs
 Attributes for ShapeOf operator. More...
 
struct  SequenceMaskAttrs
 
struct  SparseToDenseAttrs
 Attributes used in sparse_to_dense operator. More...
 
struct  NdarraySizeAttrs
 Attributes for ndarray_size operator. More...
 
struct  OneHotAttrs
 Attributes used in one-hot operator. More...
 
struct  MatrixSetDiagAttrs
 Attributes used in matrix_set_diag operator. More...
 
struct  ScanopAttrs
 Attributes used in cumsum and cumprod operator. More...
 
struct  UniqueAttrs
 Attributes used in unique operator. More...
 
struct  EinsumAttrs
 Attributes used in einsum operator. More...
 
struct  StftAttrs
 Attributes used in stft operator. More...
 
struct  DFTAttrs
 Attributes used in DFT operator. More...
 
struct  TriluAttrs
 
struct  MultiBoxPriorAttrs
 Attributes used in multibox_prior operators. More...
 
struct  MultiBoxTransformLocAttrs
 
struct  GetValidCountsAttrs
 Attributes used in get_valid_counts operator. More...
 
struct  NonMaximumSuppressionAttrs
 Attributes used in non_maximum_suppression operator. More...
 
struct  AllClassNonMaximumSuppressionAttrs
 Attributes used in all_class_non_maximum_suppression operator. More...
 
struct  RegularNonMaximumSuppressionAttrs
 Attributes used in regular_non_maximum_suppression operator. More...
 
struct  ROIAlignAttrs
 Attributes used in roi_align operators. More...
 
struct  ROIPoolAttrs
 Attributes used in roi_pool operators. More...
 
struct  YoloReorgAttrs
 Attributes used in yolo reorg operators. More...
 
struct  ProposalAttrs
 Attributes used in proposal operators. More...
 
struct  ShapeFuncAttrs
 Options for the shape function operator. More...
 
struct  ReshapeTensorAttrs
 Attributes for VM reshape_tensor operator. More...
 
class  RelayNode
 This is the base node container of all relay structures. More...
 
class  IdNode
 The unique identifier of variables. More...
 
class  Id
 
class  DFPatternCallbackNode
 Base type of all dataflow pattern callbacks. More...
 
class  DFPatternCallback
 Managed reference to dataflow pattern callbacks. More...
 
class  DFPatternNode
 Base type of all dataflow patterns. More...
 
class  DFPattern
 Managed reference to dataflow patterns. More...
 
class  ExprPatternNode
 Pattern for Relay Expression. More...
 
class  ExprPattern
 A pattern which matches a literal expression. More...
 
class  VarPatternNode
 Container for Var. More...
 
class  VarPattern
 
class  ConstantPatternNode
 Container for Constant. More...
 
class  ConstantPattern
 
class  CallPatternNode
 CallPattern container. More...
 
class  CallPattern
 
class  FunctionPatternNode
 Relay Function container. More...
 
class  FunctionPattern
 Managed reference to FunctionNode. More...
 
class  LetPatternNode
 A binding of a sub-network. More...
 
class  LetPattern
 Let binding that binds a local var. More...
 
class  TuplePatternNode
 Tuple container. More...
 
class  TuplePattern
 
class  TupleGetItemPatternNode
 
class  IfPatternNode
 
class  IfPattern
 
class  TupleGetItemPattern
 
class  AltPatternNode
 Pattern for Alternate Expressions. More...
 
class  AltPattern
 A pattern which matches either of two patterns. More...
 
class  WildcardPatternNode
 Wildcard Pattern. More...
 
class  WildcardPattern
 A pattern which matches anything. More...
 
class  TypePatternNode
 Pattern for Types. More...
 
class  TypePattern
 A pattern which matches a type in another pattern. More...
 
class  ShapePatternNode
 Pattern for Shapes. More...
 
class  ShapePattern
 A pattern which matches a type in another pattern. More...
 
class  DataTypePatternNode
 Pattern for Types. More...
 
class  DataTypePattern
 A pattern which matches a type in another pattern. More...
 
class  AttrPatternNode
 Pattern for Attributes. More...
 
class  AttrPattern
 A pattern which matches attributes in another pattern. More...
 
class  DominatorPatternNode
 Dominated Graph Pattern Pattern for fuzzy subgraphs where all outputs of the parent are used finally by the child, and every operation between the parent and the child matches the path. More...
 
class  DominatorPattern
 A pattern which matches a variable length dominator path. More...
 
class  DFPatternPrinter
 A printer class to print pattern. 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...
 
struct  ErrorBuilder
 A wrapper around std::stringstream to build error. include/tvm/ir/type.h Can be consumed by CompileError to construct an error. More...
 
class  CompileError
 Custom Error class to be thrown during compilation. More...
 
class  ErrorReporter
 An abstraction around how errors are stored and reported. Designed to be opaque to users, so we can support a robust and simpler error reporting mode, as well as a more complex mode. More...
 
class  ExecutorNode
 Executor information. More...
 
class  Executor
 Managed reference class to ExecutorNode. More...
 
class  ExecutorRegEntry
 Helper structure to register Executors. More...
 
class  ConstantNode
 Constant tensor type. More...
 
class  Constant
 
class  TupleNode
 Tuple container. More...
 
class  Tuple
 
class  VarNode
 Container for Var. More...
 
class  Var
 
class  CallNode
 Call container. More...
 
class  Call
 
class  LetNode
 A binding of a sub-network. More...
 
class  Let
 
class  IfNode
 container of If More...
 
class  If
 
class  TupleGetItemNode
 
class  TupleGetItem
 
class  RefCreateNode
 
class  RefCreate
 
class  RefReadNode
 
class  RefRead
 
class  RefWriteNode
 
class  RefWrite
 
class  TempExprNode
 Base class of the temporary expression. More...
 
class  TempExpr
 
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  ExprMutator
 A wrapper around ExprFunctor which functionally updates the AST. More...
 
class  MixedModeVisitor
 A wrapper around ExprVisitor which traverses the Dataflow Normal AST. More...
 
class  MixedModeMutator
 Non-recursive DFS Graph Traversal for Custom Rewriting Passes. More...
 
class  ExprRewriter
 A non-iterating Expression Rewriter. More...
 
struct  v_info
 A struct to keep info of traversed expr in ExpandDataflow function. More...
 
class  FeatureSet
 A finite set of Feature. More...
 
class  FunctionNode
 Relay Function container. More...
 
class  Function
 Managed reference to FunctionNode. More...
 
class  InterpreterClosureObj
 The container type of Closures used by the interpreter. More...
 
class  InterpreterClosure
 
class  RecClosureObj
 The container type of RecClosure. More...
 
class  RecClosure
 
struct  RefValueObj
 
class  RefValue
 
struct  ConstructorValueObj
 
class  ConstructorValue
 
class  OpImplementationNode
 Operator implementation that includes compute and schedule function. More...
 
class  OpImplementation
 Operator implementation class. More...
 
class  OpSpecializationNode
 Specialized implementations for operators under certain conditions. More...
 
class  OpSpecialization
 Operator specialization class. More...
 
class  OpStrategyNode
 Operator strategy to choose implementation. More...
 
class  OpStrategy
 Operator strategy class. More...
 
class  PatternFunctor
 A dynamical functor on ADT patterns that dispatches on its first argument. You can use this as a more powerful visitor, since it allows you to define the types of further arguments to VisitPattern. More...
 
class  PatternFunctor< R(const Pattern &n, Args...)>
 
class  PatternVisitor
 A simple visitor wrapper around PatternFunctor. More...
 
class  PatternMutator
 A wrapper around ExprFunctor which functionally updates the AST. More...
 
class  RuntimeNode
 Runtime information. More...
 
class  Runtime
 Managed reference class to RuntimeNode. More...
 
class  RuntimeRegEntry
 Helper structure to register Runtimes. More...
 

Typedefs

using Constructor = tvm::Constructor
 
using ConstructorNode = tvm::ConstructorNode
 
using TypeData = tvm::TypeData
 
using TypeDataNode = tvm::TypeDataNode
 
using IndexExpr = ::tvm::PrimExpr
 Symbolic expression for tensor shape. More...
 
using SourceName = tvm::SourceName
 
using Span = tvm::Span
 
using SpanNode = tvm::SpanNode
 
using Expr = tvm::RelayExpr
 
using ExprNode = tvm::RelayExprNode
 
using BaseFunc = tvm::BaseFunc
 
using BaseFuncNode = tvm::BaseFuncNode
 
using GlobalVar = tvm::GlobalVar
 
using GlobalVarNode = tvm::GlobalVarNode
 
using Op = tvm::Op
 
using OpNode = tvm::OpNode
 
using TOpPattern = int
 the operator pattern More...
 
using TOpIsStateful = bool
 Whether operator is stateful or contain internal state. More...
 
using TNonComputational = bool
 Mark the operator as non-computational. More...
 
using TReshapeOp = bool
 Mark the operator as reshape op of its first input and can be turned into a nop when the first input and output shares the same piece of memory. More...
 
using TShapeDataDependent = Array< Integer >
 Mark the operator whether output shape is data dependent. More...
 
using FTVMCompute = runtime::TypedPackedFunc< Array< te::Tensor >(const Attrs &attrs, const Array< te::Tensor > &inputs, const Type &out_type)>
 Computation description interface. More...
 
using FTVMSchedule = runtime::TypedPackedFunc< te::Schedule(const Attrs &attrs, const Array< te::Tensor > &outs, const Target &target)>
 Build the computation schedule for op whose root is at current op. More...
 
using FTVMStrategy = GenericFunc
 Generate the strategy of operators. This function is a generic function and can be re-defined for different targets. More...
 
using FTVMAlterOpLayout = runtime::TypedPackedFunc< Expr(const Attrs &attrs, const Array< Expr > &args, const Array< te::Tensor > &tinfos, const Type &out_type)>
 Alternate the layout of operators or replace the operator with other expressions. This function will be invoked in AlterOpLayout pass. More...
 
using FTVMConvertOpLayout = runtime::TypedPackedFunc< Expr(const Attrs &attrs, const Array< Expr > &args, const Array< te::Tensor > &tinfos, const Array< String > &desired_layouts)>
 Convert the layout of operators or replace the operator with other expressions. This function will be invoked in ConvertLayout pass. More...
 
using FTVMLegalize = runtime::TypedPackedFunc< Expr(const Attrs &attrs, const Array< Expr > &args, const Array< tvm::relay::Type > &arg_types)>
 Legalizes an expression with another expression. This function will be invoked in Legalize pass. It is a target-dependent pass. More...
 
using FTVMAnnotateTarget = runtime::TypedPackedFunc< bool(const Expr &expr)>
 Annotates an expression to indicate if an op should be compiled using the given compiler/target. More...
 
using FForwardRewrite = runtime::TypedPackedFunc< Expr(const Call &ref_call, const Array< Expr > &new_args, const ObjectRef &ctx)>
 Forward rewriting rule for a specific op. More...
 
using FPrimalGradient = runtime::TypedPackedFunc< tvm::Array< Expr >(const Expr &orig_call, const Expr &output_grad)>
 Gradient for a specific op. More...
 
using Shape = Array< IndexExpr >
 A runtime representation of shape. More...
 
using FShapeFunc = runtime::TypedPackedFunc< Array< te::Tensor >(const Attrs &attrs, const Array< te::Tensor > &inputs, const Array< IndexExpr > &out_ndims)>
 
using MetaTable = Map< String, Array< ObjectRef > >
 
using AnyNode = tvm::tir::AnyNode
 
using Any = tvm::tir::Any
 
using Kind = TypeKind
 
using Type = tvm::Type
 
using TypeNode = tvm::TypeNode
 
using TypeVar = tvm::TypeVar
 
using TypeVarNode = tvm::TypeVarNode
 
using GlobalTypeVar = tvm::GlobalTypeVar
 
using GlobalTypeVarNode = tvm::GlobalTypeVarNode
 
using TupleType = tvm::TupleType
 
using TupleTypeNode = tvm::TupleTypeNode
 
using TypeConstraint = tvm::TypeConstraint
 
using TypeConstraintNode = tvm::TypeConstraintNode
 
using FuncType = tvm::FuncType
 
using FuncTypeNode = tvm::FuncTypeNode
 
using IncompleteType = tvm::IncompleteType
 
using IncompleteTypeNode = tvm::IncompleteTypeNode
 
using RelayRefType = tvm::RelayRefType
 
using RelayRefTypeNode = tvm::RelayRefTypeNode
 
using TensorType = tvm::TensorType
 
using TensorTypeNode = tvm::TensorTypeNode
 
using TypeCall = tvm::TypeCall
 
using TypeCallNode = tvm::TypeCallNode
 
using TypeRelation = tvm::TypeRelation
 
using TypeRelationNode = tvm::TypeRelationNode
 
using TypeRelationFn = tvm::TypeRelationFn
 
using TypeReporter = tvm::TypeReporter
 
using TypeReporterNode = tvm::TypeReporterNode
 

Enumerations

enum  Feature : int {
  fVar = 0 , fGlobalVar = 1 , fConstant = 2 , fTuple = 3 ,
  fTupleGetItem = 4 , fFunction = 5 , fOp = 6 , fCall = 7 ,
  fLet = 8 , fIf = 9 , fRefCreate = 10 , fRefRead = 11 ,
  fRefWrite = 12 , fConstructor = 13 , fMatch = 14 , fGraph = 15 ,
  fLetRec = 16
}
 Different kinds of relay feature a program might use. More...
 
enum  OpPatternKind {
  kElemWise = 0 , kBroadcast = 1 , kInjective = 2 , kCommReduce = 3 ,
  kOutEWiseFusable = 4 , kTuple = 7 , kOpaque = 8
}
 operator pattern used in graph fusion More...
 
enum  AnyCodegenStrategy { kVariableDimensions }
 The codegeneration strategy for dynamic dimensions. More...
 

Functions

Clause WithFields (Clause clause, Optional< Pattern > opt_lhs=Optional< Pattern >(), Optional< Expr > opt_rhs=Optional< Expr >())
 Returns clause with the given properties. A null property denotes 'no change'. Returns clause if all properties are unchanged. Otherwise, returns a copy with the new fields. More...
 
Match WithFields (Match match, Optional< Expr > opt_data=Optional< Expr >(), Optional< Array< Clause >> opt_clauses=Optional< Array< Clause >>(), Optional< Bool > opt_complete=Optional< Bool >(), Optional< Span > opt_span=Optional< Span >())
 Returns match with the given properties. A null property denotes 'no change'. Returns match if all properties are unchanged. Otherwise, returns a copy with the new fields. More...
 
Kind KindCheck (const Type &t, const IRModule &mod, Optional< DiagnosticContext > diag_ctx=Optional< DiagnosticContext >())
 Check that types are well kinded by applying "kinding rules". More...
 
bool ConstantCheck (const Expr &e)
 Check whether an expression is constant. More...
 
bool BasicBlockNormalFormCheck (const Expr &e)
 Check whether an expression is in the basic block normal form. More...
 
bool WellFormed (const Expr &expr, Optional< DiagnosticContext > diag_ctx=Optional< DiagnosticContext >())
 Check that each Var is only bound once. More...
 
tvm::Array< VarBoundVars (const Expr &expr)
 Get all bound variables from expression expr. More...
 
tvm::Array< VarBoundVars (const Pattern &pat)
 Get all bound variables from pattern pat. More...
 
tvm::Array< VarFreeVars (const Expr &expr)
 Get free type parameters from expression expr. More...
 
tvm::Array< VarAllVars (const Expr &expr)
 Get all variables from expression expr. More...
 
tvm::Array< TypeVarFreeTypeVars (const Expr &expr, const IRModule &mod)
 Get free TypeVars from expression expr. More...
 
tvm::Array< TypeVarFreeTypeVars (const Type &t, const IRModule &mod)
 Get free TypeVars from type t. More...
 
tvm::Array< TypeVarBoundTypeVars (const Expr &expr, const IRModule &mod)
 Get all bound type variables from expression expr. More...
 
tvm::Array< TypeVarBoundTypeVars (const Type &t, const IRModule &mod)
 Get all bound type variables from type t. More...
 
tvm::Array< TypeVarAllTypeVars (const Expr &expr, const IRModule &mod)
 Get all type variables in expression expr. More...
 
tvm::Array< TypeVarAllTypeVars (const Type &t, const IRModule &mod)
 Get all type variables in type t. More...
 
Array< PatternUnmatchedCases (const Match &match, const IRModule &mod)
 Finds cases that the given match expression does not catch, if any. More...
 
std::unordered_map< const Object *, size_t > GetExprRefCount (const Expr &body)
 Get reference counter of each internal ExprNode in body. More...
 
IRModule GetCalibrateModule (IRModule mod)
 Get the updated module for collecting calibration data. More...
 
Map< GlobalVar, Array< Integer > > GetCalibrateOutputMap (const IRModule &mod)
 Get the output map between subgrpahs and its inputs/output. More...
 
std::vector< TensorTypeFlattenTupleType (const Type &type)
 
std::vector< ExprFromTupleType (const Type &type, const Expr &expr)
 
Expr ToTupleType (const Type &t, const std::vector< Expr > &exprs)
 
String PrettyPrint (const ObjectRef &node)
 Pretty print a node for debug purposes. More...
 
String AsText (const ObjectRef &node, bool show_meta_data=true, runtime::TypedPackedFunc< String(ObjectRef)> annotate=nullptr)
 Render the node as a string in the text format. More...
 
bool MatchPattern (DFPattern pattern, Expr expr)
 Determine if a pattern matches an expression. More...
 
Expr RewritePatterns (Array< DFPatternCallback > callbacks, Expr expr, IRModule mod=IRModule())
 Rewrite an expression based on some number of DFPatternCallbacks. More...
 
Expr PartitionPattern (DFPattern pattern, Expr expr, Map< String, ObjectRef > attrs, PackedFunc check)
 Partition all matches of a DFPattern inside an Expr into separate Function calls. More...
 
Expr InferType (const Expr &expr)
 Infer the type of an expression. More...
 
DFPattern IsVar (const String &name)
 Syntatic Sugar for creating a VarPattern with a name. More...
 
DFPattern IsConstant ()
 Syntatic Sugar for creating a ConstantPattern. More...
 
DFPattern IsWildcard ()
 Syntatic Sugar for creating a WildcardPattern. More...
 
DFPattern IsExpr (const Expr &expr)
 Syntatic Sugar for creating a ExprPattern. More...
 
DFPattern IsOp (const String &op_name)
 Syntatic Sugar for creating a ExprPattern base on an Op. More...
 
DFPattern IsTuple (const Array< DFPattern > &fields)
 Syntatic Sugar for creating a TuplePattern. More...
 
DFPattern IsTupleGetItem (const DFPattern tuple, int index=-1)
 Syntatic Sugar for creating a TupleGetItemPattern. More...
 
std::ostream & operator<< (std::ostream &os, const DFPattern &n)
 
String PrettyPrint (const DFPattern &pattern)
 
Constant WithFields (Constant constant, Optional< runtime::NDArray > opt_data={}, Optional< VirtualDevice > opt_virtual_device={}, Optional< Span > opt_span={})
 Returns constant with the given properties. A null property denotes 'no change'. Returns constant 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< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), 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...
 
Var WithFields (Var var, Optional< Id > opt_vid=Optional< Id >(), Optional< Type > opt_type_annotation=Optional< Type >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), Optional< Span > opt_span=Optional< Span >())
 Returns var with the given properties. A null property denotes 'no change'. Returns var if all properties are unchanged. Otherwise, returns a copy with the new fields. 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< Type >> opt_type_args=Optional< Array< Type >>(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), 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...
 
Let WithFields (Let let, Optional< Var > opt_var=Optional< Var >(), Optional< Expr > opt_value=Optional< Expr >(), Optional< Expr > opt_body=Optional< Expr >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), Optional< Span > opt_span=Optional< Span >())
 Returns let with the given properties. A null property denotes 'no change'. Returns let 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< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), 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...
 
TupleGetItem WithFields (TupleGetItem tuple_get_item, Optional< Expr > opt_tuple=Optional< Expr >(), Optional< Integer > opt_index=Optional< Integer >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), 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...
 
RefCreate WithFields (RefCreate ref_create, Optional< Expr > opt_value=Optional< Expr >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), Optional< Span > opt_span=Optional< Span >())
 Returns ref_create with the given properties. A null property denotes 'no change'. Returns ref_crete if all properties are unchanged. Otherwise, returns a copy with the new fields. More...
 
RefRead WithFields (RefRead ref_read, Optional< Expr > opt_ref=Optional< Expr >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), Optional< Span > opt_span=Optional< Span >())
 Returns ref_read with the given properties. A null property denotes 'no change'. Returns ref_read if all properties are unchanged. Otherwise, returns a copy with the new fields. More...
 
RefWrite WithFields (RefWrite ref_write, Optional< Expr > opt_ref=Optional< Expr >(), Optional< Expr > opt_value=Optional< Expr >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), Optional< Span > opt_span=Optional< Span >())
 Returns ref_write with the given properties. A null property denotes 'no change'. Returns ref_write if all properties are unchanged. Otherwise, returns a copy with the new fields. More...
 
Expr PostOrderRewrite (const Expr &expr, ExprRewriter *rewriter)
 Non-recursive DFS Graph Traversal for Custom Rewriting Passes. More...
 
void PostOrderVisit (const Expr &node, std::function< void(const Expr &)> fvisit)
 recursively visit the ir in post DFS order node, apply fvisit Each node is guaranteed to be visited only once. More...
 
template<typename FCheckVisited , typename FVisitLeaf , typename FExpandExpr >
void ExpandDataflow (Expr expr, FCheckVisited fcheck_visited, FVisitLeaf fvisit_leaf, FExpandExpr fexpand_expr)
 A function to iteratively traverse dataflow regions of a graph. More...
 
template<typename FCheckVisited , typename FVisitLeaf >
void ExpandDataflow (Expr expr, FCheckVisited fcheck_visited, FVisitLeaf fvisit_leaf)
 
void ExpandANormalForm (const LetNode *op, std::function< void(const LetNode *)> pre_visit, std::function< void(const LetNode *)> post_visit)
 
FeatureSet DetectFeature (const RelayExpr &expr)
 Calculate the feature of the program. More...
 
FeatureSet DetectFeature (const IRModule &mod)
 Calculate the feature of the program. More...
 
FeatureSet DetectFeature (const Expr &expr, const IRModule &mod)
 Calculate the feature of the program. More...
 
void CheckFeature (const RelayExpr &expr, const FeatureSet &fs)
 Check the feature of the program. More...
 
void CheckFeature (const IRModule &mod, const FeatureSet &fs)
 Check the feature of the program. More...
 
void CheckFeature (const RelayExpr &expr, const IRModule &mod, const FeatureSet &fs)
 Check the feature of the program. More...
 
Function WithFields (Function function, Optional< Array< Var >> opt_params=Optional< Array< Var >>(), Optional< Expr > opt_body=Optional< Expr >(), Optional< Type > opt_ret_type=Optional< Type >(), Optional< Array< TypeVar >> opt_ty_params=Optional< Array< TypeVar >>(), Optional< DictAttrs > opt_attrs=Optional< DictAttrs >(), Optional< VirtualDevice > opt_virtual_device=Optional< VirtualDevice >(), Optional< Span > opt_span=Optional< Span >())
 Returns function with the given properties. A null property denotes 'no change'. Returns function if all properties are unchanged. Otherwise, returns a copy with the new fields. More...
 
const FunctionNodeAsOptimizableFunctionNode (const BaseFunc &base_func)
 
TypedPackedFunc< ObjectRef(Array< Expr >)> EvalFunction (IRModule mod, Expr expr, Device device, Target target)
 Returns a packed function over Relay expressions which will evaluate expr applied to those arguments, where expr is w.r.t. the definitions in mod. More...
 
ObjectRef Eval (Expr expr, Map< GlobalTypeVar, TypeData > type_definitions, std::unordered_set< String > import_set, Device device, Target target, Map< String, ObjectRef > attrs={})
 Evaluates expr and returns its result. More...
 
IRModule ParseModule (const std::string &file_name, const std::string &file_content, const Optional< IRModule > &init_module=Optional< IRModule >(), const MetaTable &init_meta_table=MetaTable())
 
tvm::transform::Pass AnnotateSpans ()
 This pass pretty-prints mod then parses it back so as to establish spans and sources for all Relay sub-expressions. This improves error and debugging diagnostics downstream for modules constructed programaticaly rather than textually. More...
 
Expr Bind (const Expr &expr, const tvm::Map< Var, Expr > &binds)
 Bind the free variables to a Relay 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 functoin parameters. Additionally this may change the order of parameters if you map a variable to a variable. More...
 
Function SubstituteBoundVars (const Function &func, const tvm::Map< Var, Expr > &binds)
 Substitute variables with new variables (including function parameters) in a function. This is a helper function usually called by other pass functions to help optimizations. Expects all values in the bind map to be Vars. More...
 
Expr ForwardRewrite (const Expr &expr, const String &rewrite_map_attr_name, std::function< ObjectRef(const Call &)> fcontext=nullptr, std::function< Expr(const Expr &)> fmulti_ref_trigger=nullptr)
 Apply rewrite rules to rewrite the expr in post DFS order. This function is used as a helper function to rewrtie an expression in a pass. More...
 
Expr ForwardRewrite (const Expr &expr, const FForwardRewrite &rewrite_func, std::function< ObjectRef(const Call &)> fcontext=nullptr, std::function< Expr(const Expr &)> fmulti_ref_trigger=nullptr)
 Apply rewrite rules to rewrite the expr in post DFS order. This function is used as a helper function to rewrtie an expression in a pass. More...
 
Expr RewriteAnnotatedOps (const Expr &expr, int fallback_device)
 Rewrite the annotated program. More...
 
Function ToCPS (const Function &f, const IRModule &mod)
 Turn an expression into continuation passing style(CPS). More...
 
Function UnCPS (const Function &f)
 Remove the continuation argument of a CPS function. More...
 
Expr DeDup (const Expr &e)
 Deduplicate the bound variables and type variables in the expression. More...
 

Variables

constexpr size_t feature_count = 17
 

Detailed Description

Relay: a high level functional IR for TVM.

This namespace contains the abstract syntax tree, and other essential data structures for the Relay IR.

You can find more about Relay by reading the language reference.

Typedef Documentation

◆ Any

using tvm::relay::Any = typedef tvm::tir::Any

◆ AnyNode

◆ BaseFunc

◆ BaseFuncNode

◆ Constructor

◆ ConstructorNode

◆ Expr

◆ ExprNode

◆ FForwardRewrite

using tvm::relay::FForwardRewrite = typedef runtime::TypedPackedFunc<Expr( const Call& ref_call, const Array<Expr>& new_args, const ObjectRef& ctx)>

Forward rewriting rule for a specific op.

Parameters
ref_callThe reference old call type to be rewritten. We can make use of the op and type information.
new_argsThe new arguments (some of them could be TempExpr).
ctxOptional context information about ref_call.
Returns
The rewriten result call, can also return nullptr, which indicate the rewriter should use the default fallback rule that realizes all its input and compose the call.
Note
When we register the function, we can register a different signature with ctx to be a specific node type.

◆ FPrimalGradient

using tvm::relay::FPrimalGradient = typedef runtime::TypedPackedFunc<tvm::Array<Expr>(const Expr& orig_call, const Expr& output_grad)>

Gradient for a specific op.

Parameters
orig_callthe original Expr.
output_gradthe gradient of the Expr.
Returns
the gradient for each parameters.

◆ FShapeFunc

using tvm::relay::FShapeFunc = typedef runtime::TypedPackedFunc<Array<te::Tensor>( const Attrs& attrs, const Array<te::Tensor>& inputs, const Array<IndexExpr>& out_ndims)>

◆ FTVMAlterOpLayout

using tvm::relay::FTVMAlterOpLayout = typedef runtime::TypedPackedFunc<Expr(const Attrs& attrs, const Array<Expr>& args, const Array<te::Tensor>& tinfos, const Type& out_type)>

Alternate the layout of operators or replace the operator with other expressions. This function will be invoked in AlterOpLayout pass.

Parameters
attrsThe attribute of the original node.
argsThe input symbols of the original node.
tinfosAn array of placeholders, use for getting the inferred shape and dtype of the inputs.
Returns
new_expr The modified expression.

◆ FTVMAnnotateTarget

using tvm::relay::FTVMAnnotateTarget = typedef runtime::TypedPackedFunc<bool(const Expr& expr)>

Annotates an expression to indicate if an op should be compiled using the given compiler/target.

Parameters
exprThe original expr.
Returns
true if this op should be registered to invoke a specific compiler for codegen, otherwise, false.

◆ FTVMCompute

using tvm::relay::FTVMCompute = typedef runtime::TypedPackedFunc<Array<te::Tensor>( const Attrs& attrs, const Array<te::Tensor>& inputs, const Type& out_type)>

Computation description interface.

Note
This function have a special convention for functions with tuple input/output.

So far we restrict tuple support to the following case:

  • Function which takes a single tuple as input.
  • Function which outputs a single tuple.

In both cases, the tuple is flattened as array.

Parameters
attrsThe attribute of the primitive
inputsThe input tensors.
out_typeThe output type information & these are always placeholders.
Returns
The output compute description of the operator.

◆ FTVMConvertOpLayout

using tvm::relay::FTVMConvertOpLayout = typedef runtime::TypedPackedFunc<Expr( const Attrs& attrs, const Array<Expr>& args, const Array<te::Tensor>& tinfos, const Array<String>& desired_layouts)>

Convert the layout of operators or replace the operator with other expressions. This function will be invoked in ConvertLayout pass.

Parameters
attrsThe attribute of the original node.
inputsThe input symbols of the original node.
tinfosAn array of placeholders, use for getting the inferred shape and dtype of the inputs.
desired_layoutsSpecify an array of desired layouts for each input. For example a conv2d op: Array("NHWC", "OHWI"), this specifies the desired layout for data then kernel.
Returns
new_expr The modified expression.

◆ FTVMLegalize

using tvm::relay::FTVMLegalize = typedef runtime::TypedPackedFunc<Expr(const Attrs& attrs, const Array<Expr>& args, const Array<tvm::relay::Type>& arg_types)>

Legalizes an expression with another expression. This function will be invoked in Legalize pass. It is a target-dependent pass.

Parameters
attrsThe attribute of the original node.
argsThe input symbols of the original node.
arg_typesAn array of placeholders, use for getting the inferred shape and dtype of the inputs.
Returns
new_expr The modified expression.

◆ FTVMSchedule

using tvm::relay::FTVMSchedule = typedef runtime::TypedPackedFunc<te::Schedule( const Attrs& attrs, const Array<te::Tensor>& outs, const Target& target)>

Build the computation schedule for op whose root is at current op.

Parameters
attrsThe attribute of the node.
outsThe output tensors.
targetThe build target.
Returns
schedule The computation schedule.

◆ FTVMStrategy

Generate the strategy of operators. This function is a generic function and can be re-defined for different targets.

The function signature of generic function is: OpStrategy(const Attrs& attrs, const Array<Tensor>& inputs, const Type& out_type, const Target& target)

◆ FuncType

◆ FuncTypeNode

◆ GlobalTypeVar

◆ GlobalTypeVarNode

◆ GlobalVar

◆ GlobalVarNode

◆ IncompleteType

◆ IncompleteTypeNode

◆ IndexExpr

Symbolic expression for tensor shape.

◆ Kind

using tvm::relay::Kind = typedef TypeKind

◆ MetaTable

◆ Op

using tvm::relay::Op = typedef tvm::Op

◆ OpNode

◆ RelayRefType

◆ RelayRefTypeNode

◆ Shape

using tvm::relay::Shape = typedef Array<IndexExpr>

A runtime representation of shape.

◆ SourceName

◆ Span

using tvm::relay::Span = typedef tvm::Span

◆ SpanNode

◆ TensorType

◆ TensorTypeNode

◆ TNonComputational

using tvm::relay::TNonComputational = typedef bool

Mark the operator as non-computational.

◆ TOpIsStateful

using tvm::relay::TOpIsStateful = typedef bool

Whether operator is stateful or contain internal state.

All the primitive ops we registered so far are pure. This attribute is left for potential future compatible reasons. We can always work around the stateful ops by adding an additional handle argument and return it.

◆ TOpPattern

using tvm::relay::TOpPattern = typedef int

the operator pattern

◆ TReshapeOp

using tvm::relay::TReshapeOp = typedef bool

Mark the operator as reshape op of its first input and can be turned into a nop when the first input and output shares the same piece of memory.

◆ TShapeDataDependent

Mark the operator whether output shape is data dependent.

◆ TupleType

◆ TupleTypeNode

◆ Type

using tvm::relay::Type = typedef tvm::Type

◆ TypeCall

◆ TypeCallNode

◆ TypeConstraint

◆ TypeConstraintNode

◆ TypeData

◆ TypeDataNode

◆ TypeNode

◆ TypeRelation

◆ TypeRelationFn

◆ TypeRelationNode

◆ TypeReporter

◆ TypeReporterNode

◆ TypeVar

◆ TypeVarNode

Enumeration Type Documentation

◆ AnyCodegenStrategy

The codegeneration strategy for dynamic dimensions.

Enumerator
kVariableDimensions 

The default strategy of using completely variable dimensions.

◆ Feature

enum tvm::relay::Feature : int

Different kinds of relay feature a program might use.

Enumerator
fVar 
fGlobalVar 
fConstant 
fTuple 
fTupleGetItem 
fFunction 
fOp 
fCall 
fLet 
fIf 
fRefCreate 
fRefRead 
fRefWrite 
fConstructor 
fMatch 
fGraph 

Whether any non-atom fragment of the program is shared, making the program a graph.

fLetRec 

Whether there is local fixpoint in the program.

◆ OpPatternKind

operator pattern used in graph fusion

Enumerator
kElemWise 
kBroadcast 
kInjective 
kCommReduce 
kOutEWiseFusable 
kTuple 
kOpaque 

Function Documentation

◆ AllTypeVars() [1/2]

tvm::Array<TypeVar> tvm::relay::AllTypeVars ( const Expr expr,
const IRModule mod 
)

Get all type variables in expression expr.

Parameters
exprthe expression.
modthe module.
Returns
List of type vars, in the PostDFS order in the expression.

◆ AllTypeVars() [2/2]

tvm::Array<TypeVar> tvm::relay::AllTypeVars ( const Type t,
const IRModule mod 
)

Get all type variables in type t.

Parameters
tthe type.
modthe module.
Returns
List of type vars, in the PostDFS order visited by type.

◆ AllVars()

tvm::Array<Var> tvm::relay::AllVars ( const Expr expr)

Get all variables from expression expr.

Parameters
exprthe expression.
Returns
List of all vars, in the PostDFS order in the expression.

◆ AnnotateSpans()

tvm::transform::Pass tvm::relay::AnnotateSpans ( )

This pass pretty-prints mod then parses it back so as to establish spans and sources for all Relay sub-expressions. This improves error and debugging diagnostics downstream for modules constructed programaticaly rather than textually.

◆ AsOptimizableFunctionNode()

const FunctionNode* tvm::relay::AsOptimizableFunctionNode ( const BaseFunc base_func)

◆ AsText()

String tvm::relay::AsText ( const ObjectRef node,
bool  show_meta_data = true,
runtime::TypedPackedFunc< String(ObjectRef)>  annotate = nullptr 
)

Render the node as a string in the text format.

Parameters
nodeThe node to be rendered.
show_meta_dataWhether to print meta data section.
annotateAn optional callback function for attaching additional comment block to an expr.
Note
We support a limited set of IR nodes that are part of relay IR and
See also
PrettyPrint.
Returns
The text representation.

◆ BasicBlockNormalFormCheck()

bool tvm::relay::BasicBlockNormalFormCheck ( const Expr e)

Check whether an expression is in the basic block normal form.

Parameters
ethe expression.
Returns
whether the expression is in the basic block normal form.

◆ Bind()

Expr tvm::relay::Bind ( const Expr expr,
const tvm::Map< Var, Expr > &  binds 
)

Bind the free variables to a Relay 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 functoin parameters. Additionally this may change the order of parameters if you map a variable to a variable.

Parameters
exprThe input expression.
bindsThe variable to expression map that will be used to help the binding.
Returns
The updated expression.

◆ BoundTypeVars() [1/2]

tvm::Array<TypeVar> tvm::relay::BoundTypeVars ( const Expr expr,
const IRModule mod 
)

Get all bound type variables from expression expr.

Bound variables are all type variables that are declared in the expr. They only have meaning inside that expr, and can only be used in it.

Parameters
exprthe expression.
modthe module.
Returns
List of bound type vars, in the PostDFS order in the expression.

◆ BoundTypeVars() [2/2]

tvm::Array<TypeVar> tvm::relay::BoundTypeVars ( const Type t,
const IRModule mod 
)

Get all bound type variables from type t.

Bound variables are all type variables that are declared in the type. They only have meaning inside that type, and can only be used in it.

Parameters
tthe type
modthe module.
Returns
List of bound type vars, in the PostDFS order visited by type.

◆ BoundVars() [1/2]

tvm::Array<Var> tvm::relay::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.

Parameters
exprthe expression.
Returns
List of bound vars, in the PostDFS order in the expression.

◆ BoundVars() [2/2]

tvm::Array<Var> tvm::relay::BoundVars ( const Pattern pat)

Get all bound variables from pattern pat.

Bound variables are all variables that got bound by the pat. They only have meaning inside that expr, and can only be used in it.

Parameters
patthe Pattern.
Returns
List of bound vars, in the PostDFS order in the expression.

◆ CheckFeature() [1/3]

void tvm::relay::CheckFeature ( const IRModule mod,
const FeatureSet fs 
)

Check the feature of the program.

Parameters
modThe module.
fsThe feature set of the program.

◆ CheckFeature() [2/3]

void tvm::relay::CheckFeature ( const RelayExpr expr,
const FeatureSet fs 
)

Check the feature of the program.

Parameters
exprThe expression.
fsThe feature set of the program.

◆ CheckFeature() [3/3]

void tvm::relay::CheckFeature ( const RelayExpr expr,
const IRModule mod,
const FeatureSet fs 
)
inline

Check the feature of the program.

Parameters
exprThe expression.
modThe module.
fsThe feature set of the program.

◆ ConstantCheck()

bool tvm::relay::ConstantCheck ( const Expr e)

Check whether an expression is constant.

If the inputs of an expression are all constant, it means the expression itself is constant also.

Parameters
ethe expression.
Returns
whether the expression is constant.

◆ DeDup()

Expr tvm::relay::DeDup ( const Expr e)

Deduplicate the bound variables and type variables in the expression.

Parameters
ethe expression.
Returns
the deduplicated expression.

◆ DetectFeature() [1/3]

FeatureSet tvm::relay::DetectFeature ( const Expr expr,
const IRModule mod 
)
inline

Calculate the feature of the program.

Parameters
exprThe expression.
modThe module.
Returns
The FeatureSet.

◆ DetectFeature() [2/3]

FeatureSet tvm::relay::DetectFeature ( const IRModule mod)

Calculate the feature of the program.

Parameters
modThe module.
Returns
The FeatureSet.

◆ DetectFeature() [3/3]

FeatureSet tvm::relay::DetectFeature ( const RelayExpr expr)

Calculate the feature of the program.

Parameters
exprThe expression.
Returns
The FeatureSet.

◆ Eval()

ObjectRef tvm::relay::Eval ( Expr  expr,
Map< GlobalTypeVar, TypeData type_definitions,
std::unordered_set< String import_set,
Device  device,
Target  target,
Map< String, ObjectRef attrs = {} 
)

Evaluates expr and returns its result.

This function is intended to support TVM constant evaluation.

Parameters
exprAn expression to evaluate.
type_definitionsGlobal type definitions which expr may references.
import_setAlready imported external modules.
deviceThe device on which all primitives will be executed.
targetThe compiler target flag for compiling primitives.
attrsAttributes for the expression to be evaluated with
Returns
The object representing the result.

◆ EvalFunction()

TypedPackedFunc<ObjectRef(Array<Expr>)> tvm::relay::EvalFunction ( IRModule  mod,
Expr  expr,
Device  device,
Target  target 
)

Returns a packed function over Relay expressions which will evaluate expr applied to those arguments, where expr is w.r.t. the definitions in mod.

This function is intended to support the Python 'debug' executor.

The given expr should have function type. The given mod may be empty or undefined if expr is self-contained. Relay arguments passed to the result packed function must be constants, references, or constructors/tuples over such. As much work as possible is done while constructing the result packed function, and that function may be reasonably efficiently applied multiple times without redoing unnecessary work.

Primitives are lowered and compiled to packed functions for execution on device with properties given by target. All other Relay constructs are interpreted.

The interpreter is intended to be a 'reference' implementation of the Relay semantics for testing and interactive use. It is not intended to be particularly efficient.

Parameters
modA module containing definitions which can be referenced from expr. May be empty or undefined.
exprAn expression of function type to evaluate. May reference definitions from mod.
deviceThe device on which all primitives will be executed.
targetThe compiler target flag for compiling primitives.
Returns
A packed function that takes an array of Relay expressions and returns the result of applying expr to those arguments.

◆ ExpandANormalForm()

void tvm::relay::ExpandANormalForm ( const LetNode op,
std::function< void(const LetNode *)>  pre_visit,
std::function< void(const LetNode *)>  post_visit 
)

◆ ExpandDataflow() [1/2]

template<typename FCheckVisited , typename FVisitLeaf >
void tvm::relay::ExpandDataflow ( Expr  expr,
FCheckVisited  fcheck_visited,
FVisitLeaf  fvisit_leaf 
)

◆ ExpandDataflow() [2/2]

template<typename FCheckVisited , typename FVisitLeaf , typename FExpandExpr >
void tvm::relay::ExpandDataflow ( Expr  expr,
FCheckVisited  fcheck_visited,
FVisitLeaf  fvisit_leaf,
FExpandExpr  fexpand_expr 
)

A function to iteratively traverse dataflow regions of a graph.

ExpandDataflow manually manages a stack and performs DFS to determine the processing order of nodes in an input graph.

By default fexpand_expr implemented in a way that if it finds a dataflow node (Call, Tuple, TupleGetItem), it checks if the arguments to that node need to be processed via fcheck_visited. If so, the function pushes those arguments to the stack and continues iteratively to process the top of the stack. When it finds a node that doesn't match the dataflow types, or a node who's inputs have all been processed, it visits the current leaf via fvisit_leaf.

This function should be used internally to other classes to implement mixed-mode traversals. The expectation is that fvisit_leaf will perform recursive analysis within mixed-mode traversal if it hits a non-dataflow node.

fcheck_visited, fvisit_leaf and fexpand_expr are templated to encourage reusing.

◆ FlattenTupleType()

std::vector<TensorType> tvm::relay::FlattenTupleType ( const Type type)

◆ ForwardRewrite() [1/2]

Expr tvm::relay::ForwardRewrite ( const Expr expr,
const FForwardRewrite rewrite_func,
std::function< ObjectRef(const Call &)>  fcontext = nullptr,
std::function< Expr(const Expr &)>  fmulti_ref_trigger = nullptr 
)

Apply rewrite rules to rewrite the expr in post DFS order. This function is used as a helper function to rewrtie an expression in a pass.

Parameters
exprThe expression.
rewrite_funcThe rewrite func that will apply to all operators.
fcontextAdditional callback to provide context argument for each call node.
fmulti_ref_triggerTransformation function to be called when an Expr consumed by multiple callers.
Returns
The rewritten expression.

◆ ForwardRewrite() [2/2]

Expr tvm::relay::ForwardRewrite ( const Expr expr,
const String rewrite_map_attr_name,
std::function< ObjectRef(const Call &)>  fcontext = nullptr,
std::function< Expr(const Expr &)>  fmulti_ref_trigger = nullptr 
)

Apply rewrite rules to rewrite the expr in post DFS order. This function is used as a helper function to rewrtie an expression in a pass.

Parameters
exprThe expression.
rewrite_map_attr_nameThe Op's attr name which corresponds to the rewrite rule function.
fcontextAdditional callback to provide context argument for each call node.
fmulti_ref_triggerTransformation function to be called when an Expr consumed by multiple callers.
Returns
The rewritten expression.

◆ FreeTypeVars() [1/2]

tvm::Array<TypeVar> tvm::relay::FreeTypeVars ( const Expr expr,
const IRModule mod 
)

Get free TypeVars from expression expr.

Free type parameters are type parameters that are not bound by a function type in the context.

Parameters
exprthe expression.
modthe module.
Returns
List of free vars, in the PostDFS order visited by expr.

◆ FreeTypeVars() [2/2]

tvm::Array<TypeVar> tvm::relay::FreeTypeVars ( const Type t,
const IRModule mod 
)

Get free TypeVars from type t.

Free type parameters are type parameters that are not bound by a function type in the context.

Parameters
tthe type.
modthe module.
Returns
List of free type vars, in the PostDFS order visited by type.

◆ FreeVars()

tvm::Array<Var> tvm::relay::FreeVars ( const Expr expr)

Get free type parameters from expression expr.

Free variables are variables that are not bound by a let or a function parameter in the context.

Parameters
exprthe expression.
Returns
List of free vars, in the PostDFS order in the expression.

◆ FromTupleType()

std::vector<Expr> tvm::relay::FromTupleType ( const Type type,
const Expr expr 
)

◆ GetCalibrateModule()

IRModule tvm::relay::GetCalibrateModule ( IRModule  mod)

Get the updated module for collecting calibration data.

Parameters
modThe module to be updated.
Returns
The updated module.

◆ GetCalibrateOutputMap()

Map<GlobalVar, Array<Integer> > tvm::relay::GetCalibrateOutputMap ( const IRModule mod)

Get the output map between subgrpahs and its inputs/output.

Parameters
modThe module for running calibration.
Returns
The mapping between a subgraph name and its postition in the output tuple.

◆ GetExprRefCount()

std::unordered_map<const Object*, size_t> tvm::relay::GetExprRefCount ( const Expr body)

Get reference counter of each internal ExprNode in body.

Parameters
bodyThe body expression.
Returns
The reference count mapping.

◆ InferType()

Expr tvm::relay::InferType ( const Expr expr)

Infer the type of an expression.

Parameters
exprThe expression to rewrite
Returns
Return An Expr with unambiguous type information filled in, as well as it's checked type field populated with the result type.

◆ IsConstant()

DFPattern tvm::relay::IsConstant ( )

Syntatic Sugar for creating a ConstantPattern.

◆ IsExpr()

DFPattern tvm::relay::IsExpr ( const Expr expr)

Syntatic Sugar for creating a ExprPattern.

◆ IsOp()

DFPattern tvm::relay::IsOp ( const String op_name)

Syntatic Sugar for creating a ExprPattern base on an Op.

◆ IsTuple()

DFPattern tvm::relay::IsTuple ( const Array< DFPattern > &  fields)

Syntatic Sugar for creating a TuplePattern.

◆ IsTupleGetItem()

DFPattern tvm::relay::IsTupleGetItem ( const DFPattern  tuple,
int  index = -1 
)

Syntatic Sugar for creating a TupleGetItemPattern.

◆ IsVar()

DFPattern tvm::relay::IsVar ( const String name)

Syntatic Sugar for creating a VarPattern with a name.

◆ IsWildcard()

DFPattern tvm::relay::IsWildcard ( )

Syntatic Sugar for creating a WildcardPattern.

◆ KindCheck()

Kind tvm::relay::KindCheck ( const Type t,
const IRModule mod,
Optional< DiagnosticContext diag_ctx = OptionalDiagnosticContext >() 
)

Check that types are well kinded by applying "kinding rules".

This pass ensures we do not do things that violate the design of the type system when writing down types.

For example tensors are not allowed to contain functions in Relay.

We check this by ensuring the dtype field of a Tensor always contains a data type such as int, float, uint.

Parameters
tThe type to check.
modThe global module.
diag_ctxThe Diagnostic context.
Returns
The kind of the passed type.

◆ MatchPattern()

bool tvm::relay::MatchPattern ( DFPattern  pattern,
Expr  expr 
)

Determine if a pattern matches an expression.

Parameters
patternThe pattern to match
exprThe expression to match
Returns
Return true if the pattern and the expression match, return false otherwise.

◆ operator<<()

std::ostream& tvm::relay::operator<< ( std::ostream &  os,
const DFPattern n 
)
inline

◆ ParseModule()

IRModule tvm::relay::ParseModule ( const std::string &  file_name,
const std::string &  file_content,
const Optional< IRModule > &  init_module = OptionalIRModule >(),
const MetaTable init_meta_table = MetaTable() 
)

◆ PartitionPattern()

Expr tvm::relay::PartitionPattern ( DFPattern  pattern,
Expr  expr,
Map< String, ObjectRef attrs,
PackedFunc  check 
)

Partition all matches of a DFPattern inside an Expr into separate Function calls.

Parameters
patternThe pattern to match
exprThe expression to patition
attrsA set of parameter names and values to apply to the partitioned function
checkA callback function for checking more complicated properties of the matched expressions, returns true if the match is accepted and false otherwise
Returns
Return the paritioned Expr.

◆ PostOrderRewrite()

Expr tvm::relay::PostOrderRewrite ( const Expr expr,
ExprRewriter rewriter 
)

Non-recursive DFS Graph Traversal for Custom Rewriting Passes.

PostOrderRewrite does a non-recursive traversal of the graph in Post-DFS order and calls the ExprRewriter's Rewrite functions on nodes once their inputs are rewritten. At each rewrite call, PostOrderRewrite provides the original node and the node with altered inputs for use by the ExprRewriter.

◆ PostOrderVisit()

void tvm::relay::PostOrderVisit ( const Expr node,
std::function< void(const Expr &)>  fvisit 
)

recursively visit the ir in post DFS order node, apply fvisit Each node is guaranteed to be visited only once.

Parameters
nodeThe ir to be visited.
fvisitThe visitor function to be applied.

◆ PrettyPrint() [1/2]

String tvm::relay::PrettyPrint ( const DFPattern pattern)

◆ PrettyPrint() [2/2]

String tvm::relay::PrettyPrint ( const ObjectRef node)

Pretty print a node for debug purposes.

Parameters
nodeThe node to be printed.
Returns
The text reperesentation.
Note
This function does not show version or meta-data. Use AsText if you want to store the text.
See also
AsText.

◆ RewriteAnnotatedOps()

Expr tvm::relay::RewriteAnnotatedOps ( const Expr expr,
int  fallback_device 
)

Rewrite the annotated program.

Parameters
exprThe expression.
fallback_deviceThe fallback device which is the default device for operators without annotation.
Returns
The updated program.

◆ RewritePatterns()

Expr tvm::relay::RewritePatterns ( Array< DFPatternCallback callbacks,
Expr  expr,
IRModule  mod = IRModule() 
)

Rewrite an expression based on some number of DFPatternCallbacks.

Parameters
callbacksAn array of DFPatternCallback Nodes
exprThe expression to rewrite
modThe module that associates with the expr
Returns
Return An Expr with every match of the pattern inside the callbacks rewritten by the functions inside the callbacks

◆ SubstituteBoundVars()

Function tvm::relay::SubstituteBoundVars ( const Function func,
const tvm::Map< Var, Expr > &  binds 
)

Substitute variables with new variables (including function parameters) in a function. This is a helper function usually called by other pass functions to help optimizations. Expects all values in the bind map to be Vars.

Parameters
funcThe input function.
bindsThe variable to expression map that will be used to help the binding.
Returns
The updated expression.

◆ ToCPS()

Function tvm::relay::ToCPS ( const Function f,
const IRModule mod 
)

Turn an expression into continuation passing style(CPS).

CPS mean that every function will, instead of returning the result directly, be passed down an extra function (called the continuation) as argument, and pass the result to the continuation instead.

Thus, every function call has to be passed an extra argument that represent the rest of the computation (Hence the name of continuation).

Similarly, all other compute will be wrapped and call the continuation as well.

Parameters
fthe function.
modthe module.
Returns
the converted Function.

◆ ToTupleType()

Expr tvm::relay::ToTupleType ( const Type t,
const std::vector< Expr > &  exprs 
)

◆ UnCPS()

Function tvm::relay::UnCPS ( const Function f)

Remove the continuation argument of a CPS function.

Note that this only transform the type back into un-CPS form when there is no higher order input/output.

Parameters
fthe function.
Returns
the converted Function.

◆ UnmatchedCases()

Array<Pattern> tvm::relay::UnmatchedCases ( const Match match,
const IRModule mod 
)

Finds cases that the given match expression does not catch, if any.

Parameters
matchthe match expression to test
modThe module used for accessing global type var definitions, can be None.
Returns
Returns a list of cases (as patterns) that are not handled by the match expression.

◆ WellFormed()

bool tvm::relay::WellFormed ( const Expr expr,
Optional< DiagnosticContext diag_ctx = OptionalDiagnosticContext >() 
)

Check that each Var is only bound once.

For example, the expression let x = 1 in let x = 2 in 3 bound x twice.

let f = (x -> x) in let g = (x -> x + 1) in f(g(2)) also bound x twice, although x is not shadowed.

Parameters
exprthe expression to check.
diag_ctxthe diagnostic context
Returns
true iff all Var in expr is bound at most once.

◆ WithFields() [1/13]

Call tvm::relay::WithFields ( Call  call,
Optional< Expr opt_op = OptionalExpr >(),
Optional< Array< Expr >>  opt_args = OptionalArrayExpr >>(),
Optional< Attrs opt_attrs = OptionalAttrs >(),
Optional< Array< Type >>  opt_type_args = OptionalArrayType >>(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

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.

◆ WithFields() [2/13]

Clause tvm::relay::WithFields ( Clause  clause,
Optional< Pattern opt_lhs = OptionalPattern >(),
Optional< Expr opt_rhs = OptionalExpr >() 
)

Returns clause with the given properties. A null property denotes 'no change'. Returns clause if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [3/13]

Constant tvm::relay::WithFields ( Constant  constant,
Optional< runtime::NDArray opt_data = {},
Optional< VirtualDevice opt_virtual_device = {},
Optional< Span opt_span = {} 
)

Returns constant with the given properties. A null property denotes 'no change'. Returns constant if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [4/13]

Function tvm::relay::WithFields ( Function  function,
Optional< Array< Var >>  opt_params = OptionalArrayVar >>(),
Optional< Expr opt_body = OptionalExpr >(),
Optional< Type opt_ret_type = OptionalType >(),
Optional< Array< TypeVar >>  opt_ty_params = OptionalArrayTypeVar >>(),
Optional< DictAttrs opt_attrs = OptionalDictAttrs >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns function with the given properties. A null property denotes 'no change'. Returns function if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [5/13]

If tvm::relay::WithFields ( If  if_expr,
Optional< Expr opt_cond = OptionalExpr >(),
Optional< Expr opt_true_branch = OptionalExpr >(),
Optional< Expr opt_false_branch = OptionalExpr >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

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.

◆ WithFields() [6/13]

Let tvm::relay::WithFields ( Let  let,
Optional< Var opt_var = OptionalVar >(),
Optional< Expr opt_value = OptionalExpr >(),
Optional< Expr opt_body = OptionalExpr >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns let with the given properties. A null property denotes 'no change'. Returns let if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [7/13]

Match tvm::relay::WithFields ( Match  match,
Optional< Expr opt_data = OptionalExpr >(),
Optional< Array< Clause >>  opt_clauses = OptionalArrayClause >>(),
Optional< Bool opt_complete = OptionalBool >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns match with the given properties. A null property denotes 'no change'. Returns match if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [8/13]

RefCreate tvm::relay::WithFields ( RefCreate  ref_create,
Optional< Expr opt_value = OptionalExpr >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns ref_create with the given properties. A null property denotes 'no change'. Returns ref_crete if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [9/13]

RefRead tvm::relay::WithFields ( RefRead  ref_read,
Optional< Expr opt_ref = OptionalExpr >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns ref_read with the given properties. A null property denotes 'no change'. Returns ref_read if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [10/13]

RefWrite tvm::relay::WithFields ( RefWrite  ref_write,
Optional< Expr opt_ref = OptionalExpr >(),
Optional< Expr opt_value = OptionalExpr >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns ref_write with the given properties. A null property denotes 'no change'. Returns ref_write if all properties are unchanged. Otherwise, returns a copy with the new fields.

◆ WithFields() [11/13]

Tuple tvm::relay::WithFields ( Tuple  tuple,
Optional< Array< Expr >>  opt_fields = OptionalArrayExpr >>(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

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.

◆ WithFields() [12/13]

TupleGetItem tvm::relay::WithFields ( TupleGetItem  tuple_get_item,
Optional< Expr opt_tuple = OptionalExpr >(),
Optional< Integer opt_index = OptionalInteger >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

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.

◆ WithFields() [13/13]

Var tvm::relay::WithFields ( Var  var,
Optional< Id opt_vid = OptionalId >(),
Optional< Type opt_type_annotation = OptionalType >(),
Optional< VirtualDevice opt_virtual_device = OptionalVirtualDevice >(),
Optional< Span opt_span = OptionalSpan >() 
)

Returns var with the given properties. A null property denotes 'no change'. Returns var if all properties are unchanged. Otherwise, returns a copy with the new fields.

Variable Documentation

◆ feature_count

constexpr size_t tvm::relay::feature_count = 17
constexpr