19#ifndef TVM_RELAX_EXPR_H_
20#define TVM_RELAX_EXPR_H_
22#include <tvm/ffi/container/array.h>
23#include <tvm/ffi/container/map.h>
24#include <tvm/ffi/reflection/registry.h>
41using ::tvm::TupleGetItem;
42using ::tvm::TupleGetItemNode;
43using ::tvm::TupleNode;
53 namespace refl = tvm::ffi::reflection;
72 namespace refl = tvm::ffi::reflection;
73 refl::ObjectDef<DataflowVarNode>();
105 namespace refl = tvm::ffi::reflection;
136 namespace refl = tvm::ffi::reflection;
168 namespace refl = tvm::ffi::reflection;
199 namespace refl = tvm::ffi::reflection;
200 refl::ObjectDef<BindingNode>()
203 .def_ro(
"var", &
BindingNode::var, refl::AttachFieldFlag::SEqHashDefRecursive());
216 explicit Binding(ffi::ObjectPtr<BindingNode>
n) : ffi::ObjectRef(
n) {}
217 explicit Binding(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
242 namespace refl = tvm::ffi::reflection;
243 refl::ObjectDef<MatchCastNode>()
269 namespace refl = tvm::ffi::reflection;
272 refl::TypeAttrDef<VarBindingNode>()
296 namespace refl = tvm::ffi::reflection;
297 refl::ObjectDef<BindingBlockNode>()
300 refl::DefaultValue(
Span()));
318 namespace refl = tvm::ffi::reflection;
319 refl::ObjectDef<DataflowBlockNode>();
342 namespace refl = tvm::ffi::reflection;
343 refl::ObjectDef<SeqExprNode>()
346 refl::TypeAttrDef<SeqExprNode>()
410 namespace refl = tvm::ffi::reflection;
411 refl::ObjectDef<IfNode>()
459 namespace refl = tvm::ffi::reflection;
460 refl::ObjectDef<FunctionNode>()
546 namespace refl = tvm::ffi::reflection;
Base node of all functions.
Definition function.h:156
Managed reference to BaseFuncNode.
Definition function.h:250
Managed reference to DictAttrsNode.
Definition attrs.h:102
Base type of all the expressions.
Definition base_expr.h:300
Type ty
The deduced or annotated type of the expression.
Definition base_expr.h:314
Managed reference to ExprNode.
Definition base_expr.h:335
Definition source_map.h:111
Managed reference to TypeNode.
Definition base_expr.h:77
static Type Missing()
Sentinel for a type that has not been populated yet.
A local variable in the IR.
Definition expr.h:355
Managed reference to VarNode.
Definition expr.h:372
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:303
ffi::Array< Binding > bindings
Definition expr.h:292
Span span
Definition expr.h:293
static void RegisterReflection()
Definition expr.h:295
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.BindingBlock", BindingBlockNode, ffi::Object)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(BindingBlock, ffi::ObjectRef, BindingBlockNode)
BindingBlock(ffi::Array< Binding > bindings, Span span=Span())
BindingBlockNode * CopyOnWrite()
The base class of a variable binding in Relax.
Definition expr.h:192
Var var
The return variable to bound to.
Definition expr.h:196
static void RegisterReflection()
Definition expr.h:198
Span span
Definition expr.h:194
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.Binding", BindingNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:206
Binding(const Binding &)=default
const BindingNode * operator->() const
Definition expr.h:222
Binding(Binding &&)=default
Binding & operator=(Binding &&)=default
const BindingNode * get() const
Definition expr.h:223
Binding(ffi::ObjectPtr< BindingNode > n)
Definition expr.h:216
Binding(ffi::UnsafeInit tag)
Definition expr.h:217
Binding & operator=(const Binding &)=default
Constant tensor.
Definition expr.h:93
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.Constant", ConstantNode, ExprNode)
static void RegisterReflection()
Definition expr.h:104
bool is_scalar() const
Definition expr.h:102
runtime::Tensor data
The data of the tensor.
Definition expr.h:96
TensorType tensor_type() const
TVM_DEFINE_OBJECT_REF_COW_METHOD(ConstantNode)
Constant(runtime::Tensor data, ffi::Optional< Type > ty_annotation=std::nullopt, Span span=Span())
The constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Constant, Expr, ConstantNode)
Represent a data type constant.
Definition expr.h:162
DLDataType value
The data value.
Definition expr.h:165
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataTypeImm", DataTypeImmNode, ExprNode)
static void RegisterReflection()
Definition expr.h:167
Managed reference to DataTypeImm.
Definition expr.h:178
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(DataTypeImm, Expr, DataTypeImmNode)
DataTypeImm(DLDataType value, Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_COW_METHOD(DataTypeImmNode)
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowBlock", DataflowBlockNode, BindingBlockNode)
static void RegisterReflection()
Definition expr.h:317
DataflowBlock(ffi::Array< Binding > bindings, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(DataflowBlockNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(DataflowBlock, BindingBlock, DataflowBlockNode)
A sub-type of the variable node used to mark dataflow variables from normal visible "function local" ...
Definition expr.h:69
static void RegisterReflection()
Definition expr.h:71
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowVar", DataflowVarNode, VarNode)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:76
DataflowVar(ffi::String name, ffi::Optional< Type > ty_annotation, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(DataflowVar, Var, DataflowVarNode)
The extern function, which can represent packed function.
Definition expr.h:540
static void RegisterReflection()
Definition expr.h:545
ffi::String global_symbol
The name of global symbol.
Definition expr.h:543
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ExternFunc", ExternFuncNode, BaseFuncNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ExternFunc, BaseFunc, ExternFuncNode)
ExternFunc(ffi::String global_symbol, Type ty, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ExternFuncNode)
ExternFunc(ffi::String global_symbol, Span span=Span())
A Relax function.
Definition expr.h:447
static void RegisterReflection()
Definition expr.h:458
SeqExpr body
The body of the function.
Definition expr.h:452
ffi::Array< Var > params
The parameters to the function.
Definition expr.h:450
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.Function", FunctionNode, BaseFuncNode)
Type ret_ty
The return type of the function.
Definition expr.h:454
bool is_pure
Whether the function is annotated as pure or not.
Definition expr.h:456
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:467
static Function CreateEmpty(ffi::Array< Var > params, Type ret_ty, bool is_pure=true, DictAttrs attrs=DictAttrs(), Span span=Span())
Mimics the constructor but without body Expr.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Function, BaseFunc, FunctionNode)
Function(ffi::Array< Var > params, Expr body, ffi::Optional< Type > ret_ty, bool is_pure=true, DictAttrs attrs=DictAttrs(), Span span=Span())
Construct a Relax Function.
TVM_DEFINE_OBJECT_REF_COW_METHOD(FunctionNode)
Condition expression.
Definition expr.h:400
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:417
static void RegisterReflection()
Definition expr.h:409
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.If", IfNode, ExprNode)
SeqExpr true_branch
The expression evaluated when condition is true.
Definition expr.h:405
Expr cond
The condition.
Definition expr.h:403
SeqExpr false_branch
The expression evaluated when condition is false.
Definition expr.h:407
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(If, Expr, IfNode)
If(Expr cond, Expr true_branch, Expr false_branch, Span span=Span())
The constructor.
Runtime-match the value to the type.
Definition expr.h:234
Expr value
The input value to match cast.
Definition expr.h:237
Type ty
The type pattern to match to.
Definition expr.h:239
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.MatchCast", MatchCastNode, BindingNode)
static void RegisterReflection()
Definition expr.h:241
Managed reference to MatchCastNode.
Definition expr.h:255
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(MatchCast, Binding, MatchCastNode)
MatchCast(Var var, Expr value, Type ty, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(MatchCastNode)
A sequence of blocks followed by an expression.
Definition expr.h:336
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.SeqExpr", SeqExprNode, ExprNode)
Expr body
Definition expr.h:339
bool SEqual(const SeqExprNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition expr.h:351
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition expr.h:359
static void RegisterReflection()
Definition expr.h:341
ffi::Array< BindingBlock > blocks
Definition expr.h:338
SeqExpr(ffi::Array< BindingBlock > blocks, Expr body, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(SeqExpr, Expr, SeqExprNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqExprNode)
A shape expression which allows users to construct a shape containing PrimExpr.
Definition expr.h:47
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ShapeExpr", ShapeExprNode, ExprNode)
ffi::Array< PrimExpr > values
Definition expr.h:50
static void RegisterReflection()
Definition expr.h:52
ShapeExpr(ffi::Array< PrimExpr > values, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ShapeExprNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ShapeExpr, Expr, ShapeExprNode)
Represent a string literal constant.
Definition expr.h:130
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.StringImm", StringImmNode, ExprNode)
ffi::String value
The data value.
Definition expr.h:133
static void RegisterReflection()
Definition expr.h:135
Managed reference to StringImm.
Definition expr.h:146
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(StringImm, Expr, StringImmNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(StringImmNode)
StringImm(ffi::String value, Span span=Span())
The constructor.
Managed reference to TensorTypeNode.
Definition type.h:220
static void RegisterReflection()
Definition expr.h:268
Expr value
The binding value.
Definition expr.h:266
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
bool SEqual(const VarBindingNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.VarBinding", VarBindingNode, BindingNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(VarBindingNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(VarBinding, Binding, VarBindingNode)
VarBinding(Var var, Expr value, Span span=Span())
Managed Tensor. The array is backed by reference counted blocks.
Definition tensor.h:49
Copy-on-write helper macro for IR ffi::ObjectRef types.
constexpr const char * kForcePure
Override checking purity for this function and treat as pure (is_pure must be set to true)
Definition expr.h:529
constexpr const char * kWorkspaceSize
The required workspace for an external function.
Definition expr.h:523
constexpr const char * kNumInput
The number of inputs of a function. If a function has the num_input attribute, the last func->params....
Definition expr.h:536
constexpr const char * kComposite
Treat the function as a composite operator.
Definition expr.h:519
constexpr const char * kCodegen
Indicate the codegen that should be used for building this function. When this is unset or set to "de...
Definition expr.h:517
constexpr const char * kPrimitive
Mark the function as a primitive function.
Definition expr.h:512
constexpr const char * kPartitionedFromPattern
Indicate the function was created by the Pattern Partitioning Pass.
Definition expr.h:521
Expr GetShapeOf(const Expr &expr)
Get the shape of Expr.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Relax types, including the richer dependent Relax type nodes.
A device-independent managed Tensor abstraction.
A map from source names to source code.
Common operators defined for Expr.