19#ifndef TVM_TIRX_SCRIPT_IR_BUILDER_IR_H_
20#define TVM_TIRX_SCRIPT_IR_BUILDER_IR_H_
22#include <tvm/ffi/container/tuple.h>
23#include <tvm/ffi/container/variant.h>
52using tvm::ffi::Tensor;
54using tvm::ffi::Variant;
93void FuncAttrs(ffi::Map<ffi::String, ffi::Any> attrs);
121inline Var Handle(ffi::Optional<PrimType> dtype = std::nullopt,
122 ffi::String storage_scope =
"global") {
123 Type type_annotation = dtype.has_value() ?
Type(
PtrType(dtype.value(), storage_scope))
125 return tvm::Var(
"", type_annotation);
130#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName, DType) \
131 inline PrimExpr FuncName(ffi::Optional<PrimExpr> expr = std::nullopt) { \
132 PrimType dtype = DType; \
133 return expr.has_value() ? tvm::prim::cast(dtype, expr.value()) \
134 : tvm::Var("", dtype).as_or_throw<PrimExpr>(); \
137#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_SIZES(DType, Code) \
138 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##8, (PrimType(DLDataType{Code, 8, 1}))); \
139 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##16, (PrimType(DLDataType{Code, 16, 1}))); \
140 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##32, (PrimType(DLDataType{Code, 32, 1}))); \
141 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##64, (PrimType(DLDataType{Code, 64, 1})));
148#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES(FuncName, Code, Size) \
149 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x2, (PrimType(DLDataType{Code, Size, 2}))) \
150 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x4, (PrimType(DLDataType{Code, Size, 4}))); \
151 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x8, (PrimType(DLDataType{Code, Size, 8}))); \
152 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x16, (PrimType(DLDataType{Code, Size, 16}))); \
153 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x32, (PrimType(DLDataType{Code, Size, 32}))); \
154 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName##x64, (PrimType(DLDataType{Code, Size, 64})));
156#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_SIZES_LANES(DType, Code) \
157 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##8, Code, 8); \
158 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##16, Code, 16); \
159 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##32, Code, 32); \
160 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES(DType##64, Code, 64);
167#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES_FIXED_SIZE(DType, Code, Bits) \
168 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType, (PrimType(DLDataType{Code, Bits, 1}))); \
169 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##x2, (PrimType(DLDataType{Code, Bits, 2}))); \
170 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##x4, (PrimType(DLDataType{Code, Bits, 4}))); \
171 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##x8, (PrimType(DLDataType{Code, Bits, 8}))); \
172 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##x16, (PrimType(DLDataType{Code, Bits, 16}))); \
173 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##x32, (PrimType(DLDataType{Code, Bits, 32}))); \
174 TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(DType##x64, (PrimType(DLDataType{Code, Bits, 64})));
193#undef TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST
Managed reference to ExprNode.
Definition base_expr.h:359
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
static TVM_TIRX_DLL PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
static TVM_TIRX_DLL PrimType Bool(int lanes=1)
Construct a boolean type with fixed lanes.
static TVM_TIRX_DLL PtrType VoidPtrType(ffi::String storage_scope="")
Construct an opaque pointer with void element type.
Container of all statements.
Definition stmt.h:62
Managed reference to TensorStoreNode.
Definition stmt.h:335
Managed reference to TypeNode.
Definition base_expr.h:80
Managed reference to VarNode.
Definition expr.h:714
Managed reference to FunctionFrameObj.
Definition frame.h:114
Definition exec_scope.h:47
Managed reference to TensorMapTypeNode.
Definition type.h:178
Checked zero-state view over an ordinary VarNode with TensorType.
Definition expr.h:50
Shared primitive construction and constant helpers.
WhileFrame While(PrimExpr condition)
Create a while loop.
IfFrame If(PrimExpr condition)
Create an if statement.
tvm::Stmt Evaluate(Expr value)
Evaluate the input expression.
ForFrame For(ForKind kind, PrimExpr start, PrimExpr stop, ffi::Optional< PrimExpr > step=std::nullopt, ffi::Optional< PrimType > dtype=std::nullopt, ffi::Optional< ffi::Map< ffi::String, Any > > annotations=std::nullopt)
Construct a For statement of the given kind.
Var Bind(Expr value, ffi::Optional< Type > type_annotation=std::nullopt, ffi::Optional< Var > var=std::nullopt)
Create a Bind (variable binding).
ThenFrame Then()
Create a then.
ElseFrame Else()
Create an else.
ForFrame Grid(ffi::Array< ffi::Variant< PrimExpr, ffi::Tuple< PrimExpr, PrimExpr > > > extents, ffi::Optional< PrimType > dtype=std::nullopt)
The grid For statement.
tvm::Stmt Continue()
Create a continue statement.
tvm::Stmt Return(Expr value)
Create a return statement.
AssertFrame Assert(PrimExpr condition, ffi::String error_kind, ffi::Array< ffi::String > message_parts)
The assertion statement.
RegionFrame Region(Op op, ffi::Array< Expr > args, ffi::Optional< ffi::Array< Var > > body_params=std::nullopt, DictAttrs attrs=DictAttrs())
Construct a result-free region with lexical body parameters.
tvm::Stmt Break()
Create a break statement.
PrimExpr Float8E4M3(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:177
PrimExpr Float8E5M2(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:181
PrimExpr Float6E3M2FN(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:186
PrimExpr Float8E5M2FNUZ(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:182
FunctionFrame DeclFunction(bool is_private=false, bool persistent=false)
Construct a bodyless function signature using the ordinary signature operations.
Var TensorMap()
Definition ir.h:128
PrimExpr Float8E4M3FNUZ(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:180
void FuncName(ffi::String name)
The Function naming statement.
Var Handle(ffi::Optional< PrimType > dtype=std::nullopt, ffi::String storage_scope="global")
Create a TIR var that represents a pointer.
Definition ir.h:121
PrimExpr Float8E8M0FNU(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:183
PrimExpr Float6E2M3FN(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:185
void FuncAttrs(ffi::Map< ffi::String, ffi::Any > attrs)
The Function annotation statement.
FunctionFrame Function(bool is_private, bool persistent=false)
The primitive function statement.
PrimExpr Float8E3M4(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:176
PrimExpr Void(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:191
Var Arg(ffi::String name, Var var)
The Function variable arguments adding function.
PrimExpr Boolean(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:190
PrimExpr Float4E2M1FN(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:188
PrimExpr Float8E4M3B11FNUZ(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:178
Type FuncRet(Type ret_type)
The Function return type statement.
PrimExpr Float8E4M3FN(ffi::Optional< PrimExpr > expr=std::nullopt)
Definition ir.h:179
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
Device-independent tensor allocation, copies, views and serialization.
#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_SIZES_LANES(DType, Code)
Definition ir.h:156
#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST(FuncName, DType)
Definition ir.h:130
#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_SIZES(DType, Code)
Definition ir.h:137
#define TVM_TIRX_IR_BUILDER_DEF_DTYPE_CAST_LANES_FIXED_SIZE(DType, Code, Bits)
Definition ir.h:167
TIRx statements and shared statement entry header.