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/base.h>
23#include <tvm/ffi/container/array.h>
24#include <tvm/ffi/container/map.h>
25#include <tvm/ffi/extra/structural_equal.h>
26#include <tvm/ffi/extra/structural_hash.h>
27#include <tvm/ffi/reflection/registry.h>
28#include <tvm/ir/cow.h>
29#include <tvm/ir/expr.h>
30#include <tvm/ir/function.h>
31#include <tvm/ir/location.h>
32#include <tvm/ir/prim/expr.h>
33#include <tvm/ir/prim/op.h>
34#include <tvm/relax/type.h>
35#include <tvm/runtime/tensor.h>
36
37#include <functional>
38
39namespace tvm {
40namespace relax {
41
42// Compatibility aliases. Tuple expressions are defined in the common IR.
43using ::tvm::Tuple;
44using ::tvm::TupleGetItem;
45using ::tvm::TupleGetItemObj;
46using ::tvm::TupleObj;
47
50class ShapeExprObj : public ExprObj {
51 public:
53 ffi::Array<PrimExpr> values;
54
55 static void RegisterReflection() {
56 namespace refl = tvm::ffi::reflection;
57 refl::ObjectDef<ShapeExprObj>().def_ro("values", &ShapeExprObj::values);
58 }
60};
61
62class ShapeExpr : public Expr {
63 public:
64 TVM_DLL explicit ShapeExpr(ffi::Array<PrimExpr> values, Location loc = UnknownLoc());
65 explicit ShapeExpr(ffi::ObjectPtr<ShapeExprObj> node) : Expr(std::move(node)) {}
66
69};
70
74class DataflowVarObj : public VarObj {
75 public:
76 static void RegisterReflection() {
77 namespace refl = tvm::ffi::reflection;
78 refl::ObjectDef<DataflowVarObj>();
79 }
80
81 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindFreeVar;
83};
84
85class DataflowVar : public Var {
86 public:
87 TVM_DLL explicit DataflowVar(ffi::String name, ffi::Optional<Type> ty_annotation,
88 Location loc = UnknownLoc());
89
90 explicit DataflowVar(ffi::ObjectPtr<DataflowVarObj> node) : Var(std::move(node)) {}
91
93};
94
96TVM_DLL GenericConst MakeTensorConst(ffi::Tensor data,
97 ffi::Optional<Type> ty_annotation = std::nullopt,
98 Location loc = UnknownLoc());
99
101class BindingObj : public ffi::Object {
102 public:
103 explicit BindingObj(Var var) : var(std::move(var)) {}
104 explicit BindingObj(ffi::UnsafeInit) : var(ffi::UnsafeInit{}) {}
105
109
110 static void RegisterReflection() {
111 namespace refl = tvm::ffi::reflection;
112 refl::ObjectDef<BindingObj>()
113 .def_ro("loc", &BindingObj::loc, refl::AttachFieldFlag::SEqHashIgnore())
114 // TODO(tqchen): use SEqHashDefSimple after the next pypi tvm-ffi release
115 .def_ro("var", &BindingObj::var, refl::AttachFieldFlag::SEqHashDefPattern());
116 }
117
118 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
119
120 TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.Binding", BindingObj, ffi::Object);
121};
122
123class Binding : public ffi::ObjectRef {
124 protected:
125 Binding() = default;
126
127 public:
128 explicit Binding(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
129 Binding(const Binding&) = default;
130 Binding(Binding&&) = default;
131 Binding& operator=(const Binding&) = default;
132 Binding& operator=(Binding&&) = default;
133 const BindingObj* operator->() const { return static_cast<const BindingObj*>(data_.get()); }
134 const BindingObj* get() const { return operator->(); }
135 static constexpr bool _type_is_nullable = false;
137};
138
146class MatchCastObj : public BindingObj {
147 public:
149 : BindingObj(std::move(var)), value(std::move(value)) {}
150 explicit MatchCastObj(ffi::UnsafeInit)
151 : BindingObj(ffi::UnsafeInit{}), value(ffi::UnsafeInit{}) {}
152
157
158 static void RegisterReflection() {
159 namespace refl = tvm::ffi::reflection;
160 refl::ObjectDef<MatchCastObj>()
161 .def_ro("value", &MatchCastObj::value)
162 // TODO(tqchen): use SEqHashDefSimple after the next pypi tvm-ffi release
163 .def_ro("ty", &MatchCastObj::ty, refl::AttachFieldFlag::SEqHashDefPattern());
164 }
166};
167
179
180class VarBindingObj : public BindingObj {
181 public:
183 : BindingObj(std::move(var)), value(std::move(value)) {}
184 explicit VarBindingObj(ffi::UnsafeInit)
185 : BindingObj(ffi::UnsafeInit{}), value(ffi::UnsafeInit{}) {}
186
189
190 static void RegisterReflection() {
191 namespace refl = tvm::ffi::reflection;
192 refl::ObjectDef<VarBindingObj>().def_ro("value", &VarBindingObj::value);
193 // customize the SEqual and SHash methods for better error messages
194 refl::TypeAttrDef<VarBindingObj>()
195 .def(tvm::ffi::type_attr::kSEqual.name, &VarBindingObj::SEqual)
196 .def(tvm::ffi::type_attr::kSHash.name, &VarBindingObj::SHash);
197 }
198
199 bool SEqual(const VarBindingObj* other,
200 ffi::TypedFunction<bool(AnyView, AnyView, bool, AnyView)> equal) const;
201 int64_t SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t, bool)> hash) const;
203};
204
211
212class BindingBlockObj : public ffi::Object {
213 public:
214 ffi::Array<Binding> bindings;
216
217 static void RegisterReflection() {
218 namespace refl = tvm::ffi::reflection;
219 refl::ObjectDef<BindingBlockObj>()
220 .def_ro("bindings", &BindingBlockObj::bindings)
221 .def_ro("loc", &BindingBlockObj::loc, refl::AttachFieldFlag::SEqHashIgnore(),
222 refl::DefaultValue(UnknownLoc()));
223 }
224
225 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
226 TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.BindingBlock", BindingBlockObj, ffi::Object);
227};
228
229class BindingBlock : public ffi::ObjectRef {
230 public:
231 TVM_DLL explicit BindingBlock(ffi::Array<Binding> bindings, Location loc = UnknownLoc());
232 explicit BindingBlock(ffi::UnsafeInit tag, ffi::ObjectPtr<BindingBlockObj> n)
233 : ffi::ObjectRef(tag) {
234 data_ = std::move(n);
235 }
237
239};
240
242 public:
243 static void RegisterReflection() {
244 namespace refl = tvm::ffi::reflection;
245 refl::ObjectDef<DataflowBlockObj>();
246 }
248};
249
251 public:
252 TVM_DLL explicit DataflowBlock(ffi::Array<Binding> bindings, Location loc = UnknownLoc());
253 explicit DataflowBlock(ffi::UnsafeInit tag, ffi::ObjectPtr<DataflowBlockObj> n)
254 : BindingBlock(tag) {
255 data_ = std::move(n);
256 }
259};
260
265class SeqExprObj : public ExprObj {
266 public:
267 explicit SeqExprObj(Expr body) : body(std::move(body)) {}
268 explicit SeqExprObj(ffi::UnsafeInit) : body(ffi::UnsafeInit{}) {}
269
270 ffi::Array<BindingBlock> blocks;
272
273 static void RegisterReflection() {
274 namespace refl = tvm::ffi::reflection;
275 refl::ObjectDef<SeqExprObj>()
276 .def_ro("blocks", &SeqExprObj::blocks)
277 .def_ro("body", &SeqExprObj::body);
278 refl::TypeAttrDef<SeqExprObj>()
279 .def(tvm::ffi::type_attr::kSEqual.name, &SeqExprObj::SEqual)
280 .def(tvm::ffi::type_attr::kSHash.name, &SeqExprObj::SHash);
281 }
282
283 bool SEqual(const SeqExprObj* other,
284 ffi::TypedFunction<bool(AnyView, AnyView, bool, AnyView)> equal) const {
285 // Establish mappings for symbolic variables defined by bindings before
286 // comparing their uses in the SeqExpr result type and body.
287 return equal(blocks, other->blocks, false, "blocks") && equal(ty, other->ty, false, "ty") &&
288 equal(body, other->body, false, "body");
289 }
290
291 int64_t SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t, bool)> hash) const {
292 int64_t hash_value = init_hash;
293 hash_value = hash(blocks, hash_value, false);
294 hash_value = hash(ty, hash_value, false);
295 hash_value = hash(body, hash_value, false);
296 return hash_value;
297 }
299};
300
301class SeqExpr : public Expr {
302 public:
303 /* \brief Implicit conversion constructor
304 *
305 * Relax nodes that introduce a new scope (e.g. `relax::Function`)
306 * are required to be held as SeqExpr. This implicit conversion
307 * provides allows callsites to use these member variables when the
308 * C++ compile-time type is a `relax::Expr`. For example,
309 * a transform may use `func.CopyOnWrite()->body = expr;`.
310 *
311 * If the expression is already a `relax::SeqExpr`, the same
312 * underlying `relax::SeqExprObj` is used, and no copies are made.
313 */
314 TVM_DLL SeqExpr(Expr body); // NOLINT(*)
315
316 TVM_DLL explicit SeqExpr(ffi::Array<BindingBlock> blocks, Expr body, Location loc = UnknownLoc());
317 explicit SeqExpr(ffi::ObjectPtr<SeqExprObj> node) : Expr(std::move(node)) {}
318
321};
322
334class IfExprObj : public ExprObj {
335 public:
337 : cond(std::move(cond)),
338 true_branch(std::move(true_branch)),
339 false_branch(std::move(false_branch)) {}
340 explicit IfExprObj(ffi::UnsafeInit)
341 : cond(ffi::UnsafeInit{}), true_branch(ffi::UnsafeInit{}), false_branch(ffi::UnsafeInit{}) {}
342
349
350 static void RegisterReflection() {
351 namespace refl = tvm::ffi::reflection;
352 refl::ObjectDef<IfExprObj>()
353 .def_ro("cond", &IfExprObj::cond)
354 .def_ro("true_branch", &IfExprObj::true_branch)
355 .def_ro("false_branch", &IfExprObj::false_branch);
356 }
357
358 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindDAGNode;
360};
361
362class IfExpr : public Expr {
363 public:
381 TVM_DLL IfExpr(Expr cond, Expr true_branch, Expr false_branch, Location loc = UnknownLoc());
382
383 explicit IfExpr(ffi::ObjectPtr<IfExprObj> node) : Expr(std::move(node)) {}
384
387};
388
390class FunctionObj : public BaseFuncObj {
391 public:
392 explicit FunctionObj(SeqExpr body) : body(std::move(body)) {}
393 explicit FunctionObj(ffi::UnsafeInit) : body(ffi::UnsafeInit{}) {}
394
396 ffi::Array<Var> params;
403
404 static void RegisterReflection() {
405 namespace refl = tvm::ffi::reflection;
406 refl::ObjectDef<FunctionObj>()
407 .def_ro("params", &FunctionObj::params, refl::AttachFieldFlag::SEqHashDefPattern())
408 .def_ro("body", &FunctionObj::body)
409 .def_ro("ret_ty", &FunctionObj::ret_ty)
410 .def_ro("is_pure", &FunctionObj::is_pure);
411 }
412
413 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindDAGNode;
415};
416
417class Function : public BaseFunc {
418 public:
440 TVM_DLL explicit Function(ffi::Array<Var> params, Expr body, ffi::Optional<Type> ret_ty,
441 bool is_pure = true, DictAttrs attrs = DictAttrs(),
442 Location loc = UnknownLoc());
443
448 TVM_DLL static Function CreateEmpty(ffi::Array<Var> params, Type ret_ty, bool is_pure = true,
449 DictAttrs attrs = DictAttrs(), Location loc = UnknownLoc());
450
451 explicit Function(ffi::ObjectPtr<FunctionObj> node) : BaseFunc(std::move(node)) {}
452
455};
456
459 public:
461 ffi::String global_symbol;
462
463 static void RegisterReflection() {
464 namespace refl = tvm::ffi::reflection;
465 refl::ObjectDef<ExternFuncObj>().def_ro("global_symbol", &ExternFuncObj::global_symbol);
466 }
468};
469
470class ExternFunc : public BaseFunc {
471 public:
472 TVM_DLL ExternFunc(ffi::String global_symbol, Location loc = UnknownLoc());
473 TVM_DLL ExternFunc(ffi::String global_symbol, Type ty, Location loc = UnknownLoc());
474
475 explicit ExternFunc(ffi::ObjectPtr<ExternFuncObj> node) : BaseFunc(std::move(node)) {}
476
479};
480
492TVM_DLL Expr GetShapeOf(const Expr& expr);
493
494// TODO(@sunggg): Investigate the exact usage of kComposite, kPartitionedFromPattern, and
495// kPrimitive.
496namespace attr {
504inline constexpr ffi::reflection::AttrKey<ffi::Map<ffi::String, ffi::Tensor>> kConstNameToConstant{
505 "const_name_to_constant"};
506
508inline constexpr ffi::reflection::AttrKey<bool> kPrimitive{"Primitive"};
513inline constexpr ffi::reflection::AttrKey<ffi::String> kCodegen{"Codegen"};
515inline constexpr ffi::reflection::AttrKey<ffi::String> kComposite{"Composite"};
517inline constexpr ffi::reflection::AttrKey<ffi::String> kPartitionedFromPattern{
518 "PartitionedFromPattern"};
520inline constexpr ffi::reflection::AttrKey<int64_t> kWorkspaceSize{"WorkspaceSize"};
521
522// Note: in the future, we prefer snake_case instead of CamelCase for attributes.
523// Past ones will be kept for backwards compatibility.
526inline constexpr ffi::reflection::AttrKey<bool> kForcePure{"relax.force_pure"};
527
533inline constexpr ffi::reflection::AttrKey<int64_t> kNumInput{"num_input"};
534inline constexpr ffi::reflection::AttrKey<int64_t> kOpPattern{"op_pattern"};
535
536inline constexpr ffi::reflection::AttrKey<ffi::ObjectRef> kOpAttrs{"op_attrs"};
537
538inline constexpr ffi::reflection::AttrKey<ffi::String> kOperatorName{"operator_name"};
539
540inline constexpr ffi::reflection::AttrKey<ffi::String> kLibraryKernel{"library_kernel"};
541
542inline constexpr ffi::reflection::AttrKey<ffi::String> kCSource{"c_source"};
543
544inline constexpr ffi::reflection::AttrKey<ffi::String> kCSourceFmt{"c_source_fmt"};
545
546inline constexpr ffi::reflection::AttrKey<ffi::Map<ffi::String, IntImm>> kTirVarUpperBound{
547 "tir_var_upper_bound"};
548
549inline constexpr ffi::reflection::AttrKey<ffi::Map<ffi::String, IntImm>> kTirVarLowerBound{
550 "tir_var_lower_bound"};
551
552inline constexpr ffi::reflection::AttrKey<ffi::Array<ffi::String>> kTirNonNegativeVar{
553 "tir_non_negative_var"};
554
555constexpr const char* kMemoryPlanDynamicFuncOutput = "relax.memory_plan_dynamic_func_output";
556
557inline constexpr ffi::reflection::AttrKey<ffi::Array<ffi::String>> kCaptureSymbolicVars{
558 "relax.rewrite_cuda_graph.capture_symbolic_vars"};
559
560inline constexpr ffi::reflection::AttrKey<int64_t> kScoped{"scoped"};
561
562} // namespace attr
563
564} // namespace relax
565} // namespace tvm
566
567#endif // TVM_RELAX_EXPR_H_
Base expr nodes in TVM.
Function nodes.
TIR expressions.
Shared primitive construction and constant helpers.
Device-independent tensor allocation, copies, views and serialization.
Base node of all functions.
Definition function.h:94
Managed reference to BaseFuncObj.
Definition function.h:202
Managed reference to DictAttrsObj.
Definition attrs.h:108
Base type of all the expressions.
Definition expr.h:66
Type ty
The deduced or annotated type of the expression.
Definition expr.h:80
Managed reference to ExprObj.
Definition expr.h:101
Managed reference to a generic constant.
Definition expr.h:256
Non-nullable source-location metadata.
Definition location.h:91
Managed reference to TypeObj.
Definition type.h:75
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:552
Managed reference to VarObj.
Definition expr.h:571
Definition expr.h:212
static void RegisterReflection()
Definition expr.h:217
Location loc
Definition expr.h:215
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.BindingBlock", BindingBlockObj, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:225
ffi::Array< Binding > bindings
Definition expr.h:214
Definition expr.h:229
BindingBlockObj * CopyOnWrite()
BindingBlock(ffi::Array< Binding > bindings, Location loc=UnknownLoc())
BindingBlock(ffi::UnsafeInit tag, ffi::ObjectPtr< BindingBlockObj > n)
Definition expr.h:232
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BindingBlock, ffi::ObjectRef, BindingBlockObj)
The base class of a variable binding in Relax.
Definition expr.h:101
Var var
The return variable to bound to.
Definition expr.h:108
Location loc
Definition expr.h:106
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:118
BindingObj(Var var)
Definition expr.h:103
static void RegisterReflection()
Definition expr.h:110
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.Binding", BindingObj, ffi::Object)
BindingObj(ffi::UnsafeInit)
Definition expr.h:104
Definition expr.h:123
const BindingObj * get() const
Definition expr.h:134
Binding(const Binding &)=default
static constexpr bool _type_is_nullable
Definition expr.h:135
Binding(Binding &&)=default
Binding & operator=(Binding &&)=default
const BindingObj * operator->() const
Definition expr.h:133
Binding(ffi::UnsafeInit tag)
Definition expr.h:128
Binding & operator=(const Binding &)=default
Definition expr.h:241
static void RegisterReflection()
Definition expr.h:243
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowBlock", DataflowBlockObj, BindingBlockObj)
Definition expr.h:250
DataflowBlock(ffi::Array< Binding > bindings, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(DataflowBlockObj)
DataflowBlock(ffi::UnsafeInit tag, ffi::ObjectPtr< DataflowBlockObj > n)
Definition expr.h:253
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataflowBlock, BindingBlock, DataflowBlockObj)
A sub-type of the variable node used to mark dataflow variables from normal visible "function local" ...
Definition expr.h:74
static void RegisterReflection()
Definition expr.h:76
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:81
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowVar", DataflowVarObj, VarObj)
Definition expr.h:85
DataflowVar(ffi::String name, ffi::Optional< Type > ty_annotation, Location loc=UnknownLoc())
DataflowVar(ffi::ObjectPtr< DataflowVarObj > node)
Definition expr.h:90
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataflowVar, Var, DataflowVarObj)
The extern function, which can represent packed function.
Definition expr.h:458
ffi::String global_symbol
The name of global symbol.
Definition expr.h:461
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ExternFunc", ExternFuncObj, BaseFuncObj)
static void RegisterReflection()
Definition expr.h:463
Definition expr.h:470
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExternFunc, BaseFunc, ExternFuncObj)
ExternFunc(ffi::ObjectPtr< ExternFuncObj > node)
Definition expr.h:475
ExternFunc(ffi::String global_symbol, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ExternFuncObj)
ExternFunc(ffi::String global_symbol, Type ty, Location loc=UnknownLoc())
A Relax function.
Definition expr.h:390
ffi::Array< Var > params
The parameters to the function.
Definition expr.h:396
static void RegisterReflection()
Definition expr.h:404
FunctionObj(ffi::UnsafeInit)
Definition expr.h:393
SeqExpr body
The body of the function.
Definition expr.h:398
Type ret_ty
The return type of the function.
Definition expr.h:400
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:413
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.Function", FunctionObj, BaseFuncObj)
FunctionObj(SeqExpr body)
Definition expr.h:392
bool is_pure
Whether the function is annotated as pure or not.
Definition expr.h:402
Definition expr.h:417
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.
TVM_DEFINE_OBJECT_REF_COW_METHOD(FunctionObj)
Function(ffi::ObjectPtr< FunctionObj > node)
Definition expr.h:451
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, FunctionObj)
Condition expression.
Definition expr.h:334
static void RegisterReflection()
Definition expr.h:350
SeqExpr false_branch
The expression evaluated when condition is false.
Definition expr.h:348
IfExprObj(Expr cond, SeqExpr true_branch, SeqExpr false_branch)
Definition expr.h:336
IfExprObj(ffi::UnsafeInit)
Definition expr.h:340
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.IfExpr", IfExprObj, ExprObj)
SeqExpr true_branch
The expression evaluated when condition is true.
Definition expr.h:346
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:358
Expr cond
The condition.
Definition expr.h:344
Definition expr.h:362
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IfExpr, Expr, IfExprObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfExprObj)
IfExpr(Expr cond, Expr true_branch, Expr false_branch, Location loc=UnknownLoc())
The constructor.
IfExpr(ffi::ObjectPtr< IfExprObj > node)
Definition expr.h:383
Runtime-match the value to the type.
Definition expr.h:146
MatchCastObj(Var var, Expr value)
Definition expr.h:148
MatchCastObj(ffi::UnsafeInit)
Definition expr.h:150
Expr value
The input value to match cast.
Definition expr.h:154
Type ty
The type pattern to match to.
Definition expr.h:156
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.MatchCast", MatchCastObj, BindingObj)
static void RegisterReflection()
Definition expr.h:158
Managed reference to MatchCastObj.
Definition expr.h:172
MatchCast(Var var, Expr value, Type ty, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(MatchCast, Binding, MatchCastObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MatchCastObj)
A sequence of blocks followed by an expression.
Definition expr.h:265
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition expr.h:291
bool SEqual(const SeqExprObj *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition expr.h:283
SeqExprObj(Expr body)
Definition expr.h:267
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.SeqExpr", SeqExprObj, ExprObj)
ffi::Array< BindingBlock > blocks
Definition expr.h:270
SeqExprObj(ffi::UnsafeInit)
Definition expr.h:268
static void RegisterReflection()
Definition expr.h:273
Expr body
Definition expr.h:271
Definition expr.h:301
SeqExpr(ffi::Array< BindingBlock > blocks, Expr body, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqExprObj)
SeqExpr(ffi::ObjectPtr< SeqExprObj > node)
Definition expr.h:317
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqExpr, Expr, SeqExprObj)
A shape expression which allows users to construct a shape containing PrimExpr.
Definition expr.h:50
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ShapeExpr", ShapeExprObj, ExprObj)
static void RegisterReflection()
Definition expr.h:55
ffi::Array< PrimExpr > values
Definition expr.h:53
Definition expr.h:62
ShapeExpr(ffi::ObjectPtr< ShapeExprObj > node)
Definition expr.h:65
ShapeExpr(ffi::Array< PrimExpr > values, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ShapeExprObj)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeExpr, Expr, ShapeExprObj)
Definition expr.h:180
bool SEqual(const VarBindingObj *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
static void RegisterReflection()
Definition expr.h:190
VarBindingObj(Var var, Expr value)
Definition expr.h:182
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.VarBinding", VarBindingObj, BindingObj)
Expr value
The binding value.
Definition expr.h:188
VarBindingObj(ffi::UnsafeInit)
Definition expr.h:184
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition expr.h:205
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(VarBinding, Binding, VarBindingObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(VarBindingObj)
VarBinding(Var var, Expr value, Location loc=UnknownLoc())
Copy-on-write helper macro for IR ffi::ObjectRef types.
Parent compiler symbol visibility.
Relax types, including the richer dependent Relax type nodes.
Source locations and source-text lookup.
constexpr ffi::reflection::AttrKey< ffi::String > kCSourceFmt
Definition expr.h:544
constexpr ffi::reflection::AttrKey< ffi::String > kOperatorName
Definition expr.h:538
constexpr ffi::reflection::AttrKey< int64_t > kWorkspaceSize
The required workspace for an external function.
Definition expr.h:520
constexpr ffi::reflection::AttrKey< bool > kPrimitive
Mark the function as a primitive function.
Definition expr.h:508
constexpr const char * kMemoryPlanDynamicFuncOutput
Definition expr.h:555
constexpr ffi::reflection::AttrKey< ffi::Map< ffi::String, IntImm > > kTirVarUpperBound
Definition expr.h:546
constexpr ffi::reflection::AttrKey< int64_t > kNumInput
The number of inputs of a function. If a function has the num_input attribute, the last func->params....
Definition expr.h:533
constexpr ffi::reflection::AttrKey< ffi::Map< ffi::String, IntImm > > kTirVarLowerBound
Definition expr.h:549
constexpr ffi::reflection::AttrKey< bool > kForcePure
Override checking purity for this function and treat as pure (is_pure must be set to true)
Definition expr.h:526
constexpr ffi::reflection::AttrKey< ffi::Map< ffi::String, ffi::Tensor > > kConstNameToConstant
All the named Tensors accumulated during compilation by external codegen. Generally the associated ru...
Definition expr.h:504
constexpr ffi::reflection::AttrKey< int64_t > kOpPattern
Definition expr.h:534
constexpr ffi::reflection::AttrKey< ffi::String > kComposite
Treat the function as a composite operator.
Definition expr.h:515
constexpr ffi::reflection::AttrKey< ffi::String > kCodegen
Indicate the codegen that should be used for building this function. When this is unset or set to "de...
Definition expr.h:513
constexpr ffi::reflection::AttrKey< ffi::Array< ffi::String > > kTirNonNegativeVar
Definition expr.h:552
constexpr ffi::reflection::AttrKey< ffi::String > kCSource
Definition expr.h:542
constexpr ffi::reflection::AttrKey< ffi::ObjectRef > kOpAttrs
Definition expr.h:536
constexpr ffi::reflection::AttrKey< int64_t > kScoped
Definition expr.h:560
constexpr ffi::reflection::AttrKey< ffi::String > kLibraryKernel
Definition expr.h:540
constexpr ffi::reflection::AttrKey< ffi::String > kPartitionedFromPattern
Indicate the function was created by the Pattern Partitioning Pass.
Definition expr.h:517
constexpr ffi::reflection::AttrKey< ffi::Array< ffi::String > > kCaptureSymbolicVars
Definition expr.h:557
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 analysis.h:41
TVM_TIRX_DLL PrimExpr equal(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
equal