tvm
Loading...
Searching...
No Matches
expr.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19#ifndef TVM_RELAX_EXPR_H_
20#define TVM_RELAX_EXPR_H_
21
22#include <tvm/ffi/container/array.h>
23#include <tvm/ffi/container/map.h>
24#include <tvm/ffi/reflection/registry.h>
25#include <tvm/ir/cow.h>
26#include <tvm/ir/expr.h>
27#include <tvm/ir/function.h>
28#include <tvm/ir/location.h>
29#include <tvm/ir/prim/expr.h>
30#include <tvm/ir/prim/op.h>
31#include <tvm/relax/type.h>
32#include <tvm/runtime/tensor.h>
33
34#include <functional>
35
36namespace tvm {
37namespace relax {
38
39// Compatibility aliases. Tuple expressions are defined in the common IR.
40using ::tvm::Tuple;
41using ::tvm::TupleGetItem;
42using ::tvm::TupleGetItemNode;
43using ::tvm::TupleNode;
44
47class ShapeExprNode : public ExprNode {
48 public:
50 ffi::Array<PrimExpr> values;
51
52 static void RegisterReflection() {
53 namespace refl = tvm::ffi::reflection;
54 refl::ObjectDef<ShapeExprNode>().def_ro("values", &ShapeExprNode::values);
55 }
57};
58
59class ShapeExpr : public Expr {
60 public:
61 TVM_DLL explicit ShapeExpr(ffi::Array<PrimExpr> values, Location loc = UnknownLoc());
62 explicit ShapeExpr(ffi::ObjectPtr<ShapeExprNode> node) : Expr(std::move(node)) {}
63
66};
67
71class DataflowVarNode : public VarNode {
72 public:
73 static void RegisterReflection() {
74 namespace refl = tvm::ffi::reflection;
75 refl::ObjectDef<DataflowVarNode>();
76 }
77
78 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindFreeVar;
80};
81
82class DataflowVar : public Var {
83 public:
84 TVM_DLL explicit DataflowVar(ffi::String name, ffi::Optional<Type> ty_annotation,
85 Location loc = UnknownLoc());
86
87 explicit DataflowVar(ffi::ObjectPtr<DataflowVarNode> node) : Var(std::move(node)) {}
88
90};
91
93TVM_DLL GenericConst MakeTensorConst(ffi::Tensor data,
94 ffi::Optional<Type> ty_annotation = std::nullopt,
95 Location loc = UnknownLoc());
96
98class BindingNode : public ffi::Object {
99 public:
100 explicit BindingNode(Var var) : var(std::move(var)) {}
101 explicit BindingNode(ffi::UnsafeInit) : var(ffi::UnsafeInit{}) {}
102
106
107 static void RegisterReflection() {
108 namespace refl = tvm::ffi::reflection;
109 refl::ObjectDef<BindingNode>()
110 .def_ro("loc", &BindingNode::loc, refl::AttachFieldFlag::SEqHashIgnore())
111 // TODO(tqchen): use SEqHashDefSimple after the next pypi tvm-ffi release
112 .def_ro("var", &BindingNode::var, refl::AttachFieldFlag::SEqHashDefPattern());
113 }
114
115 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
116
117 TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.Binding", BindingNode, ffi::Object);
118};
119
120class Binding : public ffi::ObjectRef {
121 protected:
122 Binding() = default;
123
124 public:
125 explicit Binding(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
126 Binding(const Binding&) = default;
127 Binding(Binding&&) = default;
128 Binding& operator=(const Binding&) = default;
129 Binding& operator=(Binding&&) = default;
130 const BindingNode* operator->() const { return static_cast<const BindingNode*>(data_.get()); }
131 const BindingNode* get() const { return operator->(); }
132 static constexpr bool _type_is_nullable = false;
134};
135
144 public:
146 : BindingNode(std::move(var)), value(std::move(value)) {}
147 explicit MatchCastNode(ffi::UnsafeInit)
148 : BindingNode(ffi::UnsafeInit{}), value(ffi::UnsafeInit{}) {}
149
154
155 static void RegisterReflection() {
156 namespace refl = tvm::ffi::reflection;
157 refl::ObjectDef<MatchCastNode>()
158 .def_ro("value", &MatchCastNode::value)
159 // TODO(tqchen): use SEqHashDefSimple after the next pypi tvm-ffi release
160 .def_ro("ty", &MatchCastNode::ty, refl::AttachFieldFlag::SEqHashDefPattern());
161 }
163};
164
176
178 public:
180 : BindingNode(std::move(var)), value(std::move(value)) {}
181 explicit VarBindingNode(ffi::UnsafeInit)
182 : BindingNode(ffi::UnsafeInit{}), value(ffi::UnsafeInit{}) {}
183
186
187 static void RegisterReflection() {
188 namespace refl = tvm::ffi::reflection;
189 refl::ObjectDef<VarBindingNode>().def_ro("value", &VarBindingNode::value);
190 // customize the SEqual and SHash methods for better error messages
191 refl::TypeAttrDef<VarBindingNode>()
192 .def(tvm::ffi::reflection::type_attr::kSEqual, &VarBindingNode::SEqual)
193 .def(tvm::ffi::reflection::type_attr::kSHash, &VarBindingNode::SHash);
194 }
195
196 bool SEqual(const VarBindingNode* other,
197 ffi::TypedFunction<bool(AnyView, AnyView, bool, AnyView)> equal) const;
198 int64_t SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t, bool)> hash) const;
200};
201
208
209class BindingBlockNode : public ffi::Object {
210 public:
211 ffi::Array<Binding> bindings;
213
214 static void RegisterReflection() {
215 namespace refl = tvm::ffi::reflection;
216 refl::ObjectDef<BindingBlockNode>()
217 .def_ro("bindings", &BindingBlockNode::bindings)
218 .def_ro("loc", &BindingBlockNode::loc, refl::AttachFieldFlag::SEqHashIgnore(),
219 refl::DefaultValue(UnknownLoc()));
220 }
221
222 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
223 TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.BindingBlock", BindingBlockNode, ffi::Object);
224};
225
226class BindingBlock : public ffi::ObjectRef {
227 public:
228 TVM_DLL explicit BindingBlock(ffi::Array<Binding> bindings, Location loc = UnknownLoc());
229 explicit BindingBlock(ffi::UnsafeInit tag, ffi::ObjectPtr<BindingBlockNode> n)
230 : ffi::ObjectRef(tag) {
231 data_ = std::move(n);
232 }
234
236};
237
239 public:
240 static void RegisterReflection() {
241 namespace refl = tvm::ffi::reflection;
242 refl::ObjectDef<DataflowBlockNode>();
243 }
246};
247
249 public:
250 TVM_DLL explicit DataflowBlock(ffi::Array<Binding> bindings, Location loc = UnknownLoc());
251 explicit DataflowBlock(ffi::UnsafeInit tag, ffi::ObjectPtr<DataflowBlockNode> n)
252 : BindingBlock(tag) {
253 data_ = std::move(n);
254 }
257};
258
263class SeqExprNode : public ExprNode {
264 public:
265 explicit SeqExprNode(Expr body) : body(std::move(body)) {}
266 explicit SeqExprNode(ffi::UnsafeInit) : body(ffi::UnsafeInit{}) {}
267
268 ffi::Array<BindingBlock> blocks;
270
271 static void RegisterReflection() {
272 namespace refl = tvm::ffi::reflection;
273 refl::ObjectDef<SeqExprNode>()
274 .def_ro("blocks", &SeqExprNode::blocks)
275 .def_ro("body", &SeqExprNode::body);
276 refl::TypeAttrDef<SeqExprNode>()
277 .def(tvm::ffi::reflection::type_attr::kSEqual, &SeqExprNode::SEqual)
278 .def(tvm::ffi::reflection::type_attr::kSHash, &SeqExprNode::SHash);
279 }
280
281 bool SEqual(const SeqExprNode* other,
282 ffi::TypedFunction<bool(AnyView, AnyView, bool, AnyView)> equal) const {
283 // Establish mappings for symbolic variables defined by bindings before
284 // comparing their uses in the SeqExpr result type and body.
285 return equal(blocks, other->blocks, false, "blocks") && equal(ty, other->ty, false, "ty") &&
286 equal(body, other->body, false, "body");
287 }
288
289 int64_t SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t, bool)> hash) const {
290 int64_t hash_value = init_hash;
291 hash_value = hash(blocks, hash_value, false);
292 hash_value = hash(ty, hash_value, false);
293 hash_value = hash(body, hash_value, false);
294 return hash_value;
295 }
297};
298
299class SeqExpr : public Expr {
300 public:
301 /* \brief Implicit conversion constructor
302 *
303 * Relax nodes that introduce a new scope (e.g. `relax::Function`)
304 * are required to be held as SeqExpr. This implicit conversion
305 * provides allows callsites to use these member variables when the
306 * C++ compile-time type is a `relax::Expr`. For example,
307 * a transform may use `func.CopyOnWrite()->body = expr;`.
308 *
309 * If the expression is already a `relax::SeqExpr`, the same
310 * underlying `relax::SeqExprNode` is used, and no copies are made.
311 */
312 TVM_DLL SeqExpr(Expr body); // NOLINT(*)
313
314 TVM_DLL explicit SeqExpr(ffi::Array<BindingBlock> blocks, Expr body, Location loc = UnknownLoc());
315 explicit SeqExpr(ffi::ObjectPtr<SeqExprNode> node) : Expr(std::move(node)) {}
316
319};
320
332class IfExprNode : public ExprNode {
333 public:
335 : cond(std::move(cond)),
336 true_branch(std::move(true_branch)),
337 false_branch(std::move(false_branch)) {}
338 explicit IfExprNode(ffi::UnsafeInit)
339 : cond(ffi::UnsafeInit{}), true_branch(ffi::UnsafeInit{}), false_branch(ffi::UnsafeInit{}) {}
340
347
348 static void RegisterReflection() {
349 namespace refl = tvm::ffi::reflection;
350 refl::ObjectDef<IfExprNode>()
351 .def_ro("cond", &IfExprNode::cond)
352 .def_ro("true_branch", &IfExprNode::true_branch)
353 .def_ro("false_branch", &IfExprNode::false_branch);
354 }
355
356 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindDAGNode;
358};
359
360class IfExpr : public Expr {
361 public:
379 TVM_DLL IfExpr(Expr cond, Expr true_branch, Expr false_branch, Location loc = UnknownLoc());
380
381 explicit IfExpr(ffi::ObjectPtr<IfExprNode> node) : Expr(std::move(node)) {}
382
385};
386
389 public:
390 explicit FunctionNode(SeqExpr body) : body(std::move(body)) {}
391 explicit FunctionNode(ffi::UnsafeInit) : body(ffi::UnsafeInit{}) {}
392
394 ffi::Array<Var> params;
401
402 static void RegisterReflection() {
403 namespace refl = tvm::ffi::reflection;
404 refl::ObjectDef<FunctionNode>()
405 .def_ro("params", &FunctionNode::params, refl::AttachFieldFlag::SEqHashDefPattern())
406 .def_ro("body", &FunctionNode::body)
407 .def_ro("ret_ty", &FunctionNode::ret_ty)
408 .def_ro("is_pure", &FunctionNode::is_pure);
409 }
410
413};
414
415class Function : public BaseFunc {
416 public:
438 TVM_DLL explicit Function(ffi::Array<Var> params, Expr body, ffi::Optional<Type> ret_ty,
439 bool is_pure = true, DictAttrs attrs = DictAttrs(),
440 Location loc = UnknownLoc());
441
446 TVM_DLL static Function CreateEmpty(ffi::Array<Var> params, Type ret_ty, bool is_pure = true,
447 DictAttrs attrs = DictAttrs(), Location loc = UnknownLoc());
448
449 explicit Function(ffi::ObjectPtr<FunctionNode> node) : BaseFunc(std::move(node)) {}
450
453};
454
457 public:
459 ffi::String global_symbol;
460
461 static void RegisterReflection() {
462 namespace refl = tvm::ffi::reflection;
463 refl::ObjectDef<ExternFuncNode>().def_ro("global_symbol", &ExternFuncNode::global_symbol);
464 }
466};
467
468class ExternFunc : public BaseFunc {
469 public:
470 TVM_DLL ExternFunc(ffi::String global_symbol, Location loc = UnknownLoc());
471 TVM_DLL ExternFunc(ffi::String global_symbol, Type ty, Location loc = UnknownLoc());
472
473 explicit ExternFunc(ffi::ObjectPtr<ExternFuncNode> node) : BaseFunc(std::move(node)) {}
474
477};
478
490TVM_DLL Expr GetShapeOf(const Expr& expr);
491
492// TODO(@sunggg): Investigate the exact usage of kComposite, kPartitionedFromPattern, and
493// kPrimitive.
494namespace attr {
496constexpr const char* kPrimitive = "Primitive";
501constexpr const char* kCodegen = "Codegen";
503constexpr const char* kComposite = "Composite";
505constexpr const char* kPartitionedFromPattern = "PartitionedFromPattern";
507constexpr const char* kWorkspaceSize = "WorkspaceSize";
508
509// Note: in the future, we prefer snake_case instead of CamelCase for attributes.
510// Past ones will be kept for backwards compatibility.
513constexpr const char* kForcePure = "relax.force_pure";
514
520constexpr const char* kNumInput = "num_input";
521constexpr const char* kOpPattern = "op_pattern";
522
523constexpr const char* kOpAttrs = "op_attrs";
524
525constexpr const char* kOperatorName = "operator_name";
526
527constexpr const char* kLibraryKernel = "library_kernel";
528
529constexpr const char* kCSource = "c_source";
530
531constexpr const char* kCSourceFmt = "c_source_fmt";
532
533constexpr const char* kTirVarUpperBound = "tir_var_upper_bound";
534
535constexpr const char* kTirVarLowerBound = "tir_var_lower_bound";
536
537constexpr const char* kTirNonNegativeVar = "tir_non_negative_var";
538
539constexpr const char* kMemoryPlanDynamicFuncOutput = "relax.memory_plan_dynamic_func_output";
540
541constexpr const char* kCaptureSymbolicVars = "relax.rewrite_cuda_graph.capture_symbolic_vars";
542
543constexpr const char* kScoped = "scoped";
544
545} // namespace attr
546
547} // namespace relax
548} // namespace tvm
549
550#endif // TVM_RELAX_EXPR_H_
Base node of all functions.
Definition function.h:92
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, ffi::Optional< TObjectRef > default_value=std::nullopt) const
Get a function attribute.
Definition function.h:117
Managed reference to BaseFuncNode.
Definition function.h:181
Managed reference to DictAttrsNode.
Definition attrs.h:108
Base type of all the expressions.
Definition base_expr.h:324
Type ty
The deduced or annotated type of the expression.
Definition base_expr.h:338
Managed reference to ExprNode.
Definition base_expr.h:359
Managed reference to a generic constant.
Definition expr.h:77
Non-nullable source-location metadata.
Definition location.h:91
Managed reference to TypeNode.
Definition base_expr.h:80
static TVM_TIRX_DLL Type Missing()
Construct a MissingType for type information not yet populated.
Reference to the shared immutable unknown location.
Definition location.h:105
A local variable in the IR.
Definition expr.h:694
Managed reference to VarNode.
Definition expr.h:714
Definition expr.h:209
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:222
ffi::Array< Binding > bindings
Definition expr.h:211
Location loc
Definition expr.h:212
static void RegisterReflection()
Definition expr.h:214
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.BindingBlock", BindingBlockNode, ffi::Object)
Definition expr.h:226
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BindingBlock, ffi::ObjectRef, BindingBlockNode)
BindingBlock(ffi::UnsafeInit tag, ffi::ObjectPtr< BindingBlockNode > n)
Definition expr.h:229
BindingBlock(ffi::Array< Binding > bindings, Location loc=UnknownLoc())
BindingBlockNode * CopyOnWrite()
The base class of a variable binding in Relax.
Definition expr.h:98
Location loc
Definition expr.h:103
Var var
The return variable to bound to.
Definition expr.h:105
static void RegisterReflection()
Definition expr.h:107
BindingNode(ffi::UnsafeInit)
Definition expr.h:101
BindingNode(Var var)
Definition expr.h:100
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.Binding", BindingNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:115
Definition expr.h:120
Binding(const Binding &)=default
static constexpr bool _type_is_nullable
Definition expr.h:132
const BindingNode * operator->() const
Definition expr.h:130
Binding(Binding &&)=default
Binding & operator=(Binding &&)=default
const BindingNode * get() const
Definition expr.h:131
Binding(ffi::UnsafeInit tag)
Definition expr.h:125
Binding & operator=(const Binding &)=default
Definition expr.h:238
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowBlock", DataflowBlockNode, BindingBlockNode)
static void RegisterReflection()
Definition expr.h:240
Definition expr.h:248
DataflowBlock(ffi::UnsafeInit tag, ffi::ObjectPtr< DataflowBlockNode > n)
Definition expr.h:251
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataflowBlock, BindingBlock, DataflowBlockNode)
DataflowBlock(ffi::Array< Binding > bindings, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(DataflowBlockNode)
A sub-type of the variable node used to mark dataflow variables from normal visible "function local" ...
Definition expr.h:71
static void RegisterReflection()
Definition expr.h:73
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowVar", DataflowVarNode, VarNode)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:78
Definition expr.h:82
DataflowVar(ffi::String name, ffi::Optional< Type > ty_annotation, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataflowVar, Var, DataflowVarNode)
DataflowVar(ffi::ObjectPtr< DataflowVarNode > node)
Definition expr.h:87
The extern function, which can represent packed function.
Definition expr.h:456
static void RegisterReflection()
Definition expr.h:461
ffi::String global_symbol
The name of global symbol.
Definition expr.h:459
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ExternFunc", ExternFuncNode, BaseFuncNode)
Definition expr.h:468
ExternFunc(ffi::String global_symbol, Location loc=UnknownLoc())
ExternFunc(ffi::ObjectPtr< ExternFuncNode > node)
Definition expr.h:473
TVM_DEFINE_OBJECT_REF_COW_METHOD(ExternFuncNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExternFunc, BaseFunc, ExternFuncNode)
ExternFunc(ffi::String global_symbol, Type ty, Location loc=UnknownLoc())
A Relax function.
Definition expr.h:388
FunctionNode(SeqExpr body)
Definition expr.h:390
static void RegisterReflection()
Definition expr.h:402
FunctionNode(ffi::UnsafeInit)
Definition expr.h:391
SeqExpr body
The body of the function.
Definition expr.h:396
ffi::Array< Var > params
The parameters to the function.
Definition expr.h:394
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.Function", FunctionNode, BaseFuncNode)
Type ret_ty
The return type of the function.
Definition expr.h:398
bool is_pure
Whether the function is annotated as pure or not.
Definition expr.h:400
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:411
Definition expr.h:415
Function(ffi::Array< Var > params, Expr body, ffi::Optional< Type > ret_ty, bool is_pure=true, DictAttrs attrs=DictAttrs(), Location loc=UnknownLoc())
Construct a Relax Function.
Function(ffi::ObjectPtr< FunctionNode > node)
Definition expr.h:449
static Function CreateEmpty(ffi::Array< Var > params, Type ret_ty, bool is_pure=true, DictAttrs attrs=DictAttrs(), Location loc=UnknownLoc())
Mimics the constructor but without body Expr.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Function, BaseFunc, FunctionNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(FunctionNode)
Condition expression.
Definition expr.h:332
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:356
SeqExpr false_branch
The expression evaluated when condition is false.
Definition expr.h:346
IfExprNode(Expr cond, SeqExpr true_branch, SeqExpr false_branch)
Definition expr.h:334
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.IfExpr", IfExprNode, ExprNode)
Expr cond
The condition.
Definition expr.h:342
static void RegisterReflection()
Definition expr.h:348
IfExprNode(ffi::UnsafeInit)
Definition expr.h:338
SeqExpr true_branch
The expression evaluated when condition is true.
Definition expr.h:344
Definition expr.h:360
IfExpr(Expr cond, Expr true_branch, Expr false_branch, Location loc=UnknownLoc())
The constructor.
IfExpr(ffi::ObjectPtr< IfExprNode > node)
Definition expr.h:381
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfExprNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IfExpr, Expr, IfExprNode)
Runtime-match the value to the type.
Definition expr.h:143
Expr value
The input value to match cast.
Definition expr.h:151
Type ty
The type pattern to match to.
Definition expr.h:153
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.MatchCast", MatchCastNode, BindingNode)
MatchCastNode(ffi::UnsafeInit)
Definition expr.h:147
MatchCastNode(Var var, Expr value)
Definition expr.h:145
static void RegisterReflection()
Definition expr.h:155
Managed reference to MatchCastNode.
Definition expr.h:169
MatchCast(Var var, Expr value, Type ty, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(MatchCast, Binding, MatchCastNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MatchCastNode)
A sequence of blocks followed by an expression.
Definition expr.h:263
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.SeqExpr", SeqExprNode, ExprNode)
Expr body
Definition expr.h:269
bool SEqual(const SeqExprNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition expr.h:281
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition expr.h:289
SeqExprNode(ffi::UnsafeInit)
Definition expr.h:266
static void RegisterReflection()
Definition expr.h:271
ffi::Array< BindingBlock > blocks
Definition expr.h:268
SeqExprNode(Expr body)
Definition expr.h:265
Definition expr.h:299
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqExpr, Expr, SeqExprNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqExprNode)
SeqExpr(ffi::Array< BindingBlock > blocks, Expr body, Location loc=UnknownLoc())
SeqExpr(ffi::ObjectPtr< SeqExprNode > node)
Definition expr.h:315
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
Definition expr.h:59
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeExpr, Expr, ShapeExprNode)
ShapeExpr(ffi::Array< PrimExpr > values, Location loc=UnknownLoc())
ShapeExpr(ffi::ObjectPtr< ShapeExprNode > node)
Definition expr.h:62
TVM_DEFINE_OBJECT_REF_COW_METHOD(ShapeExprNode)
Definition expr.h:177
static void RegisterReflection()
Definition expr.h:187
Expr value
The binding value.
Definition expr.h:185
VarBindingNode(Var var, Expr value)
Definition expr.h:179
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)
VarBindingNode(ffi::UnsafeInit)
Definition expr.h:181
Definition expr.h:202
TVM_DEFINE_OBJECT_REF_COW_METHOD(VarBindingNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(VarBinding, Binding, VarBindingNode)
VarBinding(Var var, Expr value, Location loc=UnknownLoc())
Copy-on-write helper macro for IR ffi::ObjectRef types.
Base expr nodes in TVM.
Function nodes.
TIR expressions.
Shared primitive construction and constant helpers.
Source locations and source-text lookup.
constexpr const char * kTirVarUpperBound
Definition expr.h:533
constexpr const char * kScoped
Definition expr.h:543
constexpr const char * kCSourceFmt
Definition expr.h:531
constexpr const char * kForcePure
Override checking purity for this function and treat as pure (is_pure must be set to true)
Definition expr.h:513
constexpr const char * kCaptureSymbolicVars
Definition expr.h:541
constexpr const char * kMemoryPlanDynamicFuncOutput
Definition expr.h:539
constexpr const char * kTirVarLowerBound
Definition expr.h:535
constexpr const char * kWorkspaceSize
The required workspace for an external function.
Definition expr.h:507
constexpr const char * kOpAttrs
Definition expr.h:523
constexpr const char * kTirNonNegativeVar
Definition expr.h:537
constexpr const char * kLibraryKernel
Definition expr.h:527
constexpr const char * kOperatorName
Definition expr.h:525
constexpr const char * kCSource
Definition expr.h:529
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:520
constexpr const char * kOpPattern
Definition expr.h:521
constexpr const char * kComposite
Treat the function as a composite operator.
Definition expr.h:503
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:501
constexpr const char * kPrimitive
Mark the function as a primitive function.
Definition expr.h:496
constexpr const char * kPartitionedFromPattern
Indicate the function was created by the Pattern Partitioning Pass.
Definition expr.h:505
GenericConst MakeTensorConst(ffi::Tensor data, ffi::Optional< Type > ty_annotation=std::nullopt, Location loc=UnknownLoc())
Construct a tensor constant, inferring shape and dtype when type is omitted.
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 attr.h:23
TVM_TIRX_DLL PrimExpr equal(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
equal
Relax types, including the richer dependent Relax type nodes.
Device-independent tensor allocation, copies, views and serialization.